mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-16 04:45:06 +00:00
Remove RenderObjectLayer::sort() and related
This commit is contained in:
parent
c4b0decc10
commit
9bb4226626
6 changed files with 0 additions and 122 deletions
|
@ -62,74 +62,6 @@ void RenderObjectLayer::setOptimizeStatic(bool opt)
|
|||
clearDisplayList();
|
||||
}
|
||||
|
||||
|
||||
void RenderObjectLayer::sort()
|
||||
{
|
||||
if (optimizeStatic && displayListValid)
|
||||
return; // Assume the order hasn't changed
|
||||
|
||||
// Compress the list before sorting to boost speed.
|
||||
const int size = renderObjects.size();
|
||||
int from, to;
|
||||
for (to = 0; to < size; to++) {
|
||||
if (!renderObjects[to])
|
||||
break;
|
||||
}
|
||||
for (from = to+1; from < size; from++) {
|
||||
if (renderObjects[from])
|
||||
{
|
||||
renderObjects[to] = renderObjects[from];
|
||||
renderObjects[to]->setIdx(to);
|
||||
to++;
|
||||
}
|
||||
}
|
||||
if (to < size)
|
||||
renderObjects[to] = 0;
|
||||
if (to != objectCount)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Objects lost in sort! (" << to << " != " << objectCount << ")";
|
||||
errorLog(os.str());
|
||||
objectCount = to;
|
||||
}
|
||||
const int count = objectCount;
|
||||
|
||||
// Save a copy of all objects' depths so we don't have to call
|
||||
// getSortDepth() in a greater-order loop.
|
||||
std::vector<float> sortDepths(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
sortDepths[i] = renderObjects[i]->getSortDepth();
|
||||
}
|
||||
|
||||
// FIXME: Just a simple selection sort for now. Is this fast enough?
|
||||
// Might need to use quicksort instead.
|
||||
for (int i = 0; i < count-1; i++)
|
||||
{
|
||||
int best = i;
|
||||
float bestDepth = sortDepths[i];
|
||||
for (int j = i+1; j < count; j++)
|
||||
{
|
||||
if (sortDepths[j] < bestDepth)
|
||||
{
|
||||
best = j;
|
||||
bestDepth = sortDepths[j];
|
||||
}
|
||||
}
|
||||
if (best != i)
|
||||
{
|
||||
RenderObject *r = renderObjects[i];
|
||||
renderObjects[i] = renderObjects[best];
|
||||
renderObjects[i]->setIdx(i);
|
||||
renderObjects[best] = r;
|
||||
renderObjects[best]->setIdx(best);
|
||||
float d = sortDepths[i];
|
||||
sortDepths[i] = sortDepths[best];
|
||||
sortDepths[best] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderObjectLayer::add(RenderObject* r)
|
||||
{
|
||||
int size = renderObjects.size();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue