Skip to content

Commit 12aad73

Browse files
juhdanadnerzhul
authored andcommittedJun 21, 2017
Fix render order of overlays (#6008)
* Fix render order of overlays * Use C++11 loops * Fix time_t
1 parent 8daf5b5 commit 12aad73

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed
 

‎src/clientmap.cpp

+35-42
Original file line numberDiff line numberDiff line change
@@ -283,49 +283,45 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
283283

284284
struct MeshBufList
285285
{
286-
/*!
287-
* Specifies in which layer the list is.
288-
* All lists which are in a lower layer are rendered before this list.
289-
*/
290-
u8 layer;
291286
video::SMaterial m;
292287
std::vector<scene::IMeshBuffer*> bufs;
293288
};
294289

295290
struct MeshBufListList
296291
{
297-
std::vector<MeshBufList> lists;
292+
/*!
293+
* Stores the mesh buffers of the world.
294+
* The array index is the material's layer.
295+
* The vector part groups vertices by material.
296+
*/
297+
std::vector<MeshBufList> lists[MAX_TILE_LAYERS];
298298

299299
void clear()
300300
{
301-
lists.clear();
301+
for (int l = 0; l < MAX_TILE_LAYERS; l++)
302+
lists[l].clear();
302303
}
303304

304305
void add(scene::IMeshBuffer *buf, u8 layer)
305306
{
307+
// Append to the correct layer
308+
std::vector<MeshBufList> &list = lists[layer];
306309
const video::SMaterial &m = buf->getMaterial();
307-
for(std::vector<MeshBufList>::iterator i = lists.begin();
308-
i != lists.end(); ++i){
309-
MeshBufList &l = *i;
310-
310+
for (MeshBufList &l : list) {
311311
// comparing a full material is quite expensive so we don't do it if
312312
// not even first texture is equal
313313
if (l.m.TextureLayer[0].Texture != m.TextureLayer[0].Texture)
314314
continue;
315315

316-
if(l.layer != layer)
317-
continue;
318-
319316
if (l.m == m) {
320317
l.bufs.push_back(buf);
321318
return;
322319
}
323320
}
324321
MeshBufList l;
325-
l.layer = layer;
326322
l.m = m;
327323
l.bufs.push_back(buf);
328-
lists.push_back(l);
324+
list.push_back(l);
329325
}
330326
};
331327

@@ -353,7 +349,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
353349
Measuring time is very useful for long delays when the
354350
machine is swapping a lot.
355351
*/
356-
int time1 = time(0);
352+
std::time_t time1 = time(0);
357353

358354
/*
359355
Get animation parameters
@@ -469,35 +465,32 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
469465
}
470466
}
471467

472-
std::vector<MeshBufList> &lists = drawbufs.lists;
473-
474-
int timecheck_counter = 0;
475-
for (std::vector<MeshBufList>::iterator i = lists.begin();
476-
i != lists.end(); ++i) {
477-
timecheck_counter++;
478-
if (timecheck_counter > 50) {
479-
timecheck_counter = 0;
480-
int time2 = time(0);
481-
if (time2 > time1 + 4) {
482-
infostream << "ClientMap::renderMap(): "
483-
"Rendering takes ages, returning."
484-
<< std::endl;
485-
return;
468+
// Render all layers in order
469+
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
470+
std::vector<MeshBufList> &lists = drawbufs.lists[layer];
471+
472+
int timecheck_counter = 0;
473+
for (MeshBufList &list : lists) {
474+
timecheck_counter++;
475+
if (timecheck_counter > 50) {
476+
timecheck_counter = 0;
477+
std::time_t time2 = time(0);
478+
if (time2 > time1 + 4) {
479+
infostream << "ClientMap::renderMap(): "
480+
"Rendering takes ages, returning."
481+
<< std::endl;
482+
return;
483+
}
486484
}
487-
}
488485

489-
MeshBufList &list = *i;
486+
driver->setMaterial(list.m);
490487

491-
driver->setMaterial(list.m);
492-
493-
for (std::vector<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
494-
j != list.bufs.end(); ++j) {
495-
scene::IMeshBuffer *buf = *j;
496-
driver->drawMeshBuffer(buf);
497-
vertex_count += buf->getVertexCount();
498-
meshbuffer_count++;
488+
for (scene::IMeshBuffer *buf : list.bufs) {
489+
driver->drawMeshBuffer(buf);
490+
vertex_count += buf->getVertexCount();
491+
meshbuffer_count++;
492+
}
499493
}
500-
501494
}
502495
} // ScopeProfiler
503496

0 commit comments

Comments
 (0)
Please sign in to comment.