Skip to content

Commit

Permalink
std::vector instead of array in vtxarray::matbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Sep 10, 2023
1 parent 70f2a33 commit 3cc0169
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/engine/render/octarender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,12 @@ namespace
va->maxvert += va->voffset;
}

va->matbuf = nullptr;
va->matbuf.clear();
va->matsurfs = matsurfs.size();
va->matmask = 0;
if(va->matsurfs)
{
va->matbuf = new materialsurface[matsurfs.size()];
std::memcpy(va->matbuf, matsurfs.data(), matsurfs.size()*sizeof(materialsurface));
va->matbuf = matsurfs;
for(materialsurface &m : matsurfs)
{
if(m.visible == MatSurf_EditOnly)
Expand Down Expand Up @@ -2397,10 +2396,6 @@ void destroyva(vtxarray *va, bool reparent)
{
delete[] va->decalelems;
}
if(va->matbuf)
{
delete[] va->matbuf;
}
delete va;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/render/octarender.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct vtxarray
GLuint vbuf, ebuf, skybuf, decalbuf; // VBOs
ushort minvert, maxvert; // DRE info
elementset *texelems, *decalelems; // List of element indices sets (range) per texture
materialsurface *matbuf; // buffer of material surfaces
std::vector<materialsurface> matbuf;
int verts,
tris,
texs,
Expand Down
7 changes: 3 additions & 4 deletions src/engine/render/stain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,10 @@ class stainrenderer

void findmaterials(vtxarray *va)
{
materialsurface *matbuf = va->matbuf;
int matsurfs = va->matsurfs;
for(int i = 0; i < matsurfs; ++i)
{
materialsurface &m = matbuf[i];
materialsurface &m = va->matbuf[i];
if(!IS_CLIPPED(m.material&MatFlag_Volume))
{
i += m.skip;
Expand All @@ -731,7 +730,7 @@ class stainrenderer
r = R[dim];
for(;;)
{
materialsurface &m = matbuf[i];
materialsurface &m = va->matbuf[i];
if(m.o[dim] >= bbmin[dim] && m.o[dim] <= bbmax[dim] &&
m.o[c] + m.csize >= bbmin[c] && m.o[c] <= bbmax[c] &&
m.o[r] + m.rsize >= bbmin[r] && m.o[r] <= bbmax[r])
Expand All @@ -743,7 +742,7 @@ class stainrenderer
{
break;
}
materialsurface &n = matbuf[i+1];
materialsurface &n = va->matbuf[i+1];
if(n.material != m.material || n.orient != m.orient)
{
break;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/world/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ void setupmaterials(int start, int len)
}
for(int i = start; i < len; i++)
{
const vtxarray *va = valist[i];
vtxarray *va = valist[i]; //only modifies va->matbuf entries of valist
materialsurface *skip = nullptr;
for(int j = 0; j < va -> matsurfs; ++j)
{
Expand Down

0 comments on commit 3cc0169

Please sign in to comment.