@@ -283,49 +283,45 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
283
283
284
284
struct MeshBufList
285
285
{
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;
291
286
video::SMaterial m;
292
287
std::vector<scene::IMeshBuffer*> bufs;
293
288
};
294
289
295
290
struct MeshBufListList
296
291
{
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];
298
298
299
299
void clear ()
300
300
{
301
- lists.clear ();
301
+ for (int l = 0 ; l < MAX_TILE_LAYERS; l++)
302
+ lists[l].clear ();
302
303
}
303
304
304
305
void add (scene::IMeshBuffer *buf, u8 layer)
305
306
{
307
+ // Append to the correct layer
308
+ std::vector<MeshBufList> &list = lists[layer];
306
309
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) {
311
311
// comparing a full material is quite expensive so we don't do it if
312
312
// not even first texture is equal
313
313
if (l.m .TextureLayer [0 ].Texture != m.TextureLayer [0 ].Texture )
314
314
continue ;
315
315
316
- if (l.layer != layer)
317
- continue ;
318
-
319
316
if (l.m == m) {
320
317
l.bufs .push_back (buf);
321
318
return ;
322
319
}
323
320
}
324
321
MeshBufList l;
325
- l.layer = layer;
326
322
l.m = m;
327
323
l.bufs .push_back (buf);
328
- lists .push_back (l);
324
+ list .push_back (l);
329
325
}
330
326
};
331
327
@@ -353,7 +349,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
353
349
Measuring time is very useful for long delays when the
354
350
machine is swapping a lot.
355
351
*/
356
- int time1 = time (0 );
352
+ std:: time_t time1 = time (0 );
357
353
358
354
/*
359
355
Get animation parameters
@@ -469,35 +465,32 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
469
465
}
470
466
}
471
467
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
+ }
486
484
}
487
- }
488
485
489
- MeshBufList & list = *i ;
486
+ driver-> setMaterial ( list. m ) ;
490
487
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
+ }
499
493
}
500
-
501
494
}
502
495
} // ScopeProfiler
503
496
0 commit comments