mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-25 13:41:05 +00:00
- use std::sort to sort the draw lists to avoid having to go through global variables.
This commit is contained in:
parent
5d94af913a
commit
6641d65237
1 changed files with 22 additions and 42 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
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();
|
||||
for(count=0,n=head;n;n=n->next) sortspritelist.Push(n);
|
||||
gd=this;
|
||||
qsort(&sortspritelist[0],sortspritelist.Size(),sizeof(SortNode *),CompareSprite);
|
||||
std::sort(sortspritelist.begin(), sortspritelist.end(), [=](SortNode *a, SortNode *b)
|
||||
{
|
||||
return CompareSprites(a, b);
|
||||
});
|
||||
|
||||
for(i=0;i<sortspritelist.Size();i++)
|
||||
{
|
||||
sortspritelist[i]->next=NULL;
|
||||
|
@ -908,38 +900,20 @@ void GLDrawList::DrawDecals()
|
|||
// 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()
|
||||
{
|
||||
if (drawitems.Size() > 1)
|
||||
{
|
||||
sortinfo=this;
|
||||
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), diwcmp);
|
||||
std::sort(drawitems.begin(), drawitems.end(), [=](const GLDrawItem &a, const GLDrawItem &b) -> int
|
||||
{
|
||||
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)
|
||||
{
|
||||
sortinfo=this;
|
||||
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), difcmp);
|
||||
std::sort(drawitems.begin(), drawitems.end(), [=](const GLDrawItem &a, const GLDrawItem &b)
|
||||
{
|
||||
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
|
||||
// are expensive to create and delete.
|
||||
//
|
||||
// Note: If multithreading gets used, this class needs synchronization.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FDrawInfo *FDrawInfoList::GetNew()
|
||||
|
|
Loading…
Reference in a new issue