ref: 33f6c80e9a89f5721e2d1537589af33cdadb3149
parent: 2846ffebfc29bd997339f71f5ea6bd785e940097
author: rodri <rgl@antares-labs.eu>
date: Mon Mar 23 13:03:27 EDT 2026
change the ItemArray index data type from usize to ulong it's unrealistic to think we'll ever need more items than that.
--- a/graphics.h
+++ b/graphics.h
@@ -53,7 +53,7 @@
MAXVATTRS = 10, /* change this if your shaders require it */
/* itemarray */
- NaI = ~0ULL, /* not an index */
+ NaI = ~0UL, /* not an index */
};
typedef struct ItemArray ItemArray;
@@ -89,8 +89,8 @@
{Ref;
void *items;
- usize nitems;
- usize itemsize;
+ ulong nitems;
+ ulong itemsize;
};
struct Color
@@ -151,10 +151,10 @@
struct Vertex
{- usize p; /* position idx */
- usize n; /* surface normal idx */
- usize uv; /* texture coordinate idx */
- usize c; /* shading color idx */
+ ulong p; /* position idx */
+ ulong n; /* surface normal idx */
+ ulong uv; /* texture coordinate idx */
+ ulong c; /* shading color idx */
};
/*
@@ -204,8 +204,8 @@
struct Primitive
{int type;
- usize v[3]; /* vertex indices */
- usize tangent; /* tangent idx */
+ ulong v[3]; /* vertex indices */
+ ulong tangent; /* tangent idx */
Material *mtl;
};
@@ -222,14 +222,14 @@
ItemArray *prims;
ItemArray *materials;
- usize (*addposition)(Model*, Point3);
- usize (*addnormal)(Model*, Point3);
- usize (*addtexcoord)(Model*, Point2);
- usize (*addcolor)(Model*, Color);
- usize (*addtangent)(Model*, Point3);
- usize (*addvert)(Model*, Vertex);
- usize (*addprim)(Model*, Primitive);
- usize (*addmaterial)(Model*, Material);
+ ulong (*addposition)(Model*, Point3);
+ ulong (*addnormal)(Model*, Point3);
+ ulong (*addtexcoord)(Model*, Point2);
+ ulong (*addcolor)(Model*, Color);
+ ulong (*addtangent)(Model*, Point3);
+ ulong (*addvert)(Model*, Vertex);
+ ulong (*addprim)(Model*, Primitive);
+ ulong (*addmaterial)(Model*, Material);
Material* (*getmaterial)(Model*, char*);
};
@@ -518,10 +518,10 @@
Memimage* dupmemimage(Memimage*);
/* itemarray */
-ItemArray* mkitemarray(usize);
-usize itemarrayadd(ItemArray*, void*);
-void* itemarrayget(ItemArray*, usize);
-usize copyitemarray(ItemArray*, ItemArray*);
+ItemArray* mkitemarray(ulong);
+ulong itemarrayadd(ItemArray*, void*);
+void* itemarrayget(ItemArray*, ulong);
+ulong copyitemarray(ItemArray*, ItemArray*);
ItemArray* dupitemarray(ItemArray*, ItemArray**);
void rmitemarray(ItemArray*);
--- a/itemarray.c
+++ b/itemarray.c
@@ -9,7 +9,7 @@
#include "internal.h"
ItemArray *
-mkitemarray(usize is)
+mkitemarray(ulong is)
{ItemArray *a;
@@ -20,15 +20,18 @@
return a;
}
-usize
+ulong
itemarrayadd(ItemArray *a, void *i)
{char *p;
- usize idx;
+ ulong idx;
+ usize newlen;
idx = a->nitems;
- if(a->nitems++ % 16 == 0)
- a->items = _erealloc(a->items, (a->nitems + 15)*a->itemsize);
+ if(a->nitems++ % 16 == 0){+ newlen = (a->nitems + 15)*a->itemsize;
+ a->items = _erealloc(a->items, newlen);
+ }
p = a->items;
p += idx*a->itemsize;
memmove(p, i, a->itemsize);
@@ -36,7 +39,7 @@
}
void *
-itemarrayget(ItemArray *a, usize idx)
+itemarrayget(ItemArray *a, ulong idx)
{char *p;
@@ -48,7 +51,7 @@
return p;
}
-usize
+ulong
copyitemarray(ItemArray *s, ItemArray *d)
{usize len;
--- a/marshal.c
+++ b/marshal.c
@@ -16,7 +16,7 @@
struct Curline
{char file[256];
- usize line;
+ ulong line;
};
typedef struct Mtlentry Mtlentry;
@@ -40,7 +40,7 @@
va_list va;
char buf[ERRMAX], *bp;
- bp = seprint(buf, buf + sizeof buf, "%s:%llud ", l->file, l->line);
+ bp = seprint(buf, buf + sizeof buf, "%s:%lud ", l->file, l->line);
va_start(va, fmt);
vseprint(bp, buf + sizeof buf, fmt, va);
@@ -141,7 +141,7 @@
Biobuf *bin;
void *vp;
char *line, *f[10], *s, assets[200], buf[256];
- usize idx;
+ ulong idx;
int nf, nv, inamaterial, texfd;
n.w = T.w = 0;
@@ -363,7 +363,7 @@
idx = strtoul(f[1], nil, 10);
vp = itemarrayget(pa, idx);
if(vp == nil){- error(&curline, "no position at idx %llud", idx);
+ error(&curline, "no position at idx %lud", idx);
goto getout;
}
v.p = idx;
@@ -372,7 +372,7 @@
idx = strtoul(f[2], nil, 10);
vp = itemarrayget(na, idx);
if(vp == nil){- error(&curline, "no normal at idx %llud", idx);
+ error(&curline, "no normal at idx %lud", idx);
goto getout;
}
v.n = idx;
@@ -382,7 +382,7 @@
idx = strtoul(f[3], nil, 10);
vp = itemarrayget(ta, idx);
if(vp == nil){- error(&curline, "no texture at idx %llud", idx);
+ error(&curline, "no texture at idx %lud", idx);
goto getout;
}
v.uv = idx;
@@ -392,7 +392,7 @@
idx = strtoul(f[4], nil, 10);
vp = itemarrayget(ca, idx);
if(vp == nil){- error(&curline, "no color at idx %llud", idx);
+ error(&curline, "no color at idx %lud", idx);
goto getout;
}
v.c = idx;
@@ -415,7 +415,7 @@
vp = itemarrayget(va, idx);
if(vp == nil){novertex:
- error(&curline, "no vertex at idx %llud", idx);
+ error(&curline, "no vertex at idx %lud", idx);
goto getout;
}
P.v[0] = idx;
@@ -495,7 +495,7 @@
idx = strtoul(f[5], nil, 10);
vp = itemarrayget(Ta, idx);
if(vp == nil){- error(&curline, "no tangent at idx %llud", idx);
+ error(&curline, "no tangent at idx %lud", idx);
goto getout;
}
P.tangent = idx;
@@ -641,11 +641,11 @@
}
static int
-Bprintidx(Biobuf *b, usize idx)
+Bprintidx(Biobuf *b, ulong idx)
{if(idx == NaI)
return Bprint(b, " -");
- return Bprint(b, " %llud", idx);
+ return Bprint(b, " %lud", idx);
}
static int
@@ -653,7 +653,7 @@
{int n;
- n = Bprint(b, "v %llud", v->p);
+ n = Bprint(b, "v %lud", v->p);
n += Bprintidx(b, v->n);
n += Bprintidx(b, v->uv);
n += Bprintidx(b, v->c);
--- a/model.c
+++ b/model.c
@@ -54,49 +54,49 @@
free(mtl);
}
-static usize
+static ulong
model_addposition(Model *m, Point3 p)
{return itemarrayadd(m->positions, &p);
}
-static usize
+static ulong
model_addnormal(Model *m, Point3 n)
{return itemarrayadd(m->normals, &n);
}
-static usize
+static ulong
model_addtexcoord(Model *m, Point2 t)
{return itemarrayadd(m->texcoords, &t);
}
-static usize
+static ulong
model_addcolor(Model *m, Color c)
{return itemarrayadd(m->colors, &c);
}
-static usize
+static ulong
model_addtangent(Model *m, Point3 T)
{return itemarrayadd(m->tangents, &T);
}
-static usize
+static ulong
model_addvert(Model *m, Vertex v)
{return itemarrayadd(m->verts, &v);
}
-static usize
+static ulong
model_addprim(Model *m, Primitive P)
{return itemarrayadd(m->prims, &P);
}
-static usize
+static ulong
model_addmaterial(Model *m, Material mtl)
{assert(mtl.name != nil);
@@ -207,15 +207,15 @@
struct Reidx
{- usize old;
- usize new;
+ ulong old;
+ ulong new;
};
struct Reidxtab
{Reidx *tab;
- usize len;
- usize cap;
+ ulong len;
+ ulong cap;
};
static void
@@ -240,7 +240,7 @@
{Reidx *reidx;
Vertex *v, *vb, *ve;
- usize *attr;
+ ulong *attr;
if(t->len == 0)
return;
@@ -249,7 +249,7 @@
ve = vb + verts->nitems;
for(v = vb; v < ve; v++){- attr = (usize*)((char*)v + aoff);
+ attr = (ulong*)((char*)v + aoff);
for(reidx = t->tab; reidx < t->tab+t->len; reidx++)
if(*attr == reidx->old)
*attr = reidx->new;
@@ -283,7 +283,7 @@
{Reidx *reidx;
Primitive *P, *Pb, *Pe;
- usize i;
+ ulong i;
if(t->len == 0)
return;
@@ -305,7 +305,7 @@
{char *p1, *p2, *pb, *pe;
void *vp;
- usize nitems0, i, j;
+ ulong nitems0, i, j;
pb = a->items;
pe = pb + a->nitems*a->itemsize;
--- a/render.c
+++ b/render.c
@@ -588,7 +588,7 @@
{Vertex *v;
BVertex *dv;
- usize *sv;
+ ulong *sv;
d->type = s->type;
d->tangent = s->tangent == NaI? ZP3: *(Point3*)itemarrayget(m->tangents, s->tangent);
--
⑨