Tilemap: Optimize scanrow z ordering

This commit is contained in:
Jonas Kulla 2013-10-13 12:58:56 +02:00
parent 0f4a9930de
commit 99cfe9aefd
3 changed files with 37 additions and 5 deletions

View File

@ -59,6 +59,24 @@ void Scene::insert(SceneElement &element)
elements.append(element.link); 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) void Scene::reinsert(SceneElement &element)
{ {
elements.remove(element.link); elements.remove(element.link);

View File

@ -51,6 +51,7 @@ public:
protected: protected:
void insert(SceneElement &element); void insert(SceneElement &element);
void insertAfter(SceneElement &element, SceneElement &after);
void reinsert(SceneElement &element); void reinsert(SceneElement &element);
/* Notify all elements that geometry has changed */ /* Notify all elements that geometry has changed */

View File

@ -230,7 +230,7 @@ struct ScanRow : public ViewportElement
void drawInt(); void drawInt();
void initUpdateZ(); void initUpdateZ();
void finiUpdateZ(); void finiUpdateZ(ScanRow *prev);
}; };
struct TilemapPrivate struct TilemapPrivate
@ -1005,11 +1005,21 @@ struct TilemapPrivate
void updateZOrder() void updateZOrder()
{ {
if (elem.scanrows.isEmpty())
return;
for (int i = 0; i < elem.scanrows.count(); ++i) for (int i = 0; i < elem.scanrows.count(); ++i)
elem.scanrows[i]->initUpdateZ(); elem.scanrows[i]->initUpdateZ();
for (int i = 0; i < elem.scanrows.count(); ++i) ScanRow *prev = elem.scanrows.first();
elem.scanrows[i]->finiUpdateZ(); prev->finiUpdateZ(0);
for (int i = 1; i < elem.scanrows.count(); ++i)
{
ScanRow *row = elem.scanrows[i];
row->finiUpdateZ(prev);
prev = row;
}
} }
void prepare() void prepare()
@ -1186,11 +1196,14 @@ void ScanRow::initUpdateZ()
unlink(); unlink();
} }
void ScanRow::finiUpdateZ() void ScanRow::finiUpdateZ(ScanRow *prev)
{ {
z = 32 * (index+1) - p->offset.y; z = 32 * (index+1) - p->offset.y;
scene->insert(*this); if (prev)
scene->insertAfter(*this, *prev);
else
scene->insert(*this);
} }
void Tilemap::Autotiles::set(int i, Bitmap *bitmap) void Tilemap::Autotiles::set(int i, Bitmap *bitmap)