- use std::sort to sort the draw lists to avoid having to go through global variables.

This commit is contained in:
Christoph Oelckers 2018-04-02 20:10:51 +02:00
parent 5d94af913a
commit 6641d65237

View file

@ -605,17 +605,6 @@ inline int GLDrawList::CompareSprites(SortNode * a,SortNode * b)
else return (i_compatflags & COMPATF_SPRITESORT)? s1->index-s2->index : s2->index-s1->index; else return (i_compatflags & COMPATF_SPRITESORT)? s1->index-s2->index : s2->index-s1->index;
} }
//==========================================================================
//
//
//
//==========================================================================
static GLDrawList * gd;
int CompareSprite(const void * a,const void * b)
{
return gd->CompareSprites(*(SortNode**)a,*(SortNode**)b);
}
//========================================================================== //==========================================================================
// //
// //
@ -633,8 +622,11 @@ SortNode * GLDrawList::SortSpriteList(SortNode * head)
sortspritelist.Clear(); sortspritelist.Clear();
for(count=0,n=head;n;n=n->next) sortspritelist.Push(n); for(count=0,n=head;n;n=n->next) sortspritelist.Push(n);
gd=this; std::sort(sortspritelist.begin(), sortspritelist.end(), [=](SortNode *a, SortNode *b)
qsort(&sortspritelist[0],sortspritelist.Size(),sizeof(SortNode *),CompareSprite); {
return CompareSprites(a, b);
});
for(i=0;i<sortspritelist.Size();i++) for(i=0;i<sortspritelist.Size();i++)
{ {
sortspritelist[i]->next=NULL; sortspritelist[i]->next=NULL;
@ -908,38 +900,20 @@ void GLDrawList::DrawDecals()
// Sorting the drawitems first by texture and then by light level. // Sorting the drawitems first by texture and then by light level.
// //
//========================================================================== //==========================================================================
static GLDrawList * sortinfo;
static int diwcmp (const void *a, const void *b)
{
const GLDrawItem * di1 = (const GLDrawItem *)a;
GLWall * w1=&sortinfo->walls[di1->index];
const GLDrawItem * di2 = (const GLDrawItem *)b;
GLWall * w2=&sortinfo->walls[di2->index];
if (w1->gltexture != w2->gltexture) return w1->gltexture - w2->gltexture;
return ((w1->flags & 3) - (w2->flags & 3));
}
static int difcmp (const void *a, const void *b)
{
const GLDrawItem * di1 = (const GLDrawItem *)a;
GLFlat * w1=&sortinfo->flats[di1->index];
const GLDrawItem * di2 = (const GLDrawItem *)b;
GLFlat* w2=&sortinfo->flats[di2->index];
return w1->gltexture - w2->gltexture;
}
void GLDrawList::SortWalls() void GLDrawList::SortWalls()
{ {
if (drawitems.Size() > 1) if (drawitems.Size() > 1)
{ {
sortinfo=this; std::sort(drawitems.begin(), drawitems.end(), [=](const GLDrawItem &a, const GLDrawItem &b) -> int
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), diwcmp); {
GLWall * w1 = &walls[a.index];
GLWall * w2 = &walls[b.index];
if (w1->gltexture != w2->gltexture) return w1->gltexture - w2->gltexture;
return ((w1->flags & 3) - (w2->flags & 3));
});
} }
} }
@ -947,8 +921,12 @@ void GLDrawList::SortFlats()
{ {
if (drawitems.Size() > 1) if (drawitems.Size() > 1)
{ {
sortinfo=this; std::sort(drawitems.begin(), drawitems.end(), [=](const GLDrawItem &a, const GLDrawItem &b)
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), difcmp); {
GLFlat * w1 = &flats[a.index];
GLFlat* w2 = &flats[b.index];
return w1->gltexture - w2->gltexture;
});
} }
} }
@ -988,6 +966,8 @@ void GLDrawList::AddSprite(GLSprite * sprite)
// Try to reuse the lists as often as possible as they contain resources that // Try to reuse the lists as often as possible as they contain resources that
// are expensive to create and delete. // are expensive to create and delete.
// //
// Note: If multithreading gets used, this class needs synchronization.
//
//========================================================================== //==========================================================================
FDrawInfo *FDrawInfoList::GetNew() FDrawInfo *FDrawInfoList::GetNew()