Tilemap: Optimize scanrow z ordering
This commit is contained in:
parent
0f4a9930de
commit
99cfe9aefd
|
@ -59,6 +59,24 @@ void Scene::insert(SceneElement &element)
|
|||
elements.append(element.link);
|
||||
}
|
||||
|
||||
void Scene::insertAfter(SceneElement &element, SceneElement &after)
|
||||
{
|
||||
IntruListLink<SceneElement> *iter;
|
||||
|
||||
for (iter = &after.link; iter != elements.end(); iter = iter->next)
|
||||
{
|
||||
SceneElement *e = iter->data;
|
||||
|
||||
if (element < *e)
|
||||
{
|
||||
elements.insertBefore(element.link, *iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
elements.append(element.link);
|
||||
}
|
||||
|
||||
void Scene::reinsert(SceneElement &element)
|
||||
{
|
||||
elements.remove(element.link);
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
|
||||
protected:
|
||||
void insert(SceneElement &element);
|
||||
void insertAfter(SceneElement &element, SceneElement &after);
|
||||
void reinsert(SceneElement &element);
|
||||
|
||||
/* Notify all elements that geometry has changed */
|
||||
|
|
|
@ -230,7 +230,7 @@ struct ScanRow : public ViewportElement
|
|||
void drawInt();
|
||||
|
||||
void initUpdateZ();
|
||||
void finiUpdateZ();
|
||||
void finiUpdateZ(ScanRow *prev);
|
||||
};
|
||||
|
||||
struct TilemapPrivate
|
||||
|
@ -1005,11 +1005,21 @@ struct TilemapPrivate
|
|||
|
||||
void updateZOrder()
|
||||
{
|
||||
if (elem.scanrows.isEmpty())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < elem.scanrows.count(); ++i)
|
||||
elem.scanrows[i]->initUpdateZ();
|
||||
|
||||
for (int i = 0; i < elem.scanrows.count(); ++i)
|
||||
elem.scanrows[i]->finiUpdateZ();
|
||||
ScanRow *prev = elem.scanrows.first();
|
||||
prev->finiUpdateZ(0);
|
||||
|
||||
for (int i = 1; i < elem.scanrows.count(); ++i)
|
||||
{
|
||||
ScanRow *row = elem.scanrows[i];
|
||||
row->finiUpdateZ(prev);
|
||||
prev = row;
|
||||
}
|
||||
}
|
||||
|
||||
void prepare()
|
||||
|
@ -1186,10 +1196,13 @@ void ScanRow::initUpdateZ()
|
|||
unlink();
|
||||
}
|
||||
|
||||
void ScanRow::finiUpdateZ()
|
||||
void ScanRow::finiUpdateZ(ScanRow *prev)
|
||||
{
|
||||
z = 32 * (index+1) - p->offset.y;
|
||||
|
||||
if (prev)
|
||||
scene->insertAfter(*this, *prev);
|
||||
else
|
||||
scene->insert(*this);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue