1010#include " math/isin.h"
1111#include " rendermodel.h"
1212#include " core/cmdlib.h"
13-
13+ # include < string.h >
1414#include " convert.h"
1515
1616// extern some vars
@@ -163,6 +163,7 @@ struct PCO_PAIR_D2
163163// -------------------------------------------------------
164164void DrawLevelDriver2 (const Vector3D& cameraPos, float cameraAngleY, const Volume& frustrumVolume)
165165{
166+ CELL_ITERATOR_CACHE iteratorCache;
166167 int i = g_cellsDrawDistance;
167168 int vloop = 0 ;
168169 int hloop = 0 ;
@@ -189,6 +190,8 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
189190 drawObjects.reserve (g_cellsDrawDistance * 2 );
190191 drawObjects.clear ();
191192
193+ CBaseLevelRegion* currentRegion = nullptr ;
194+
192195 // walk through all cells
193196 while (i >= 0 )
194197 {
@@ -201,13 +204,20 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
201204 icell.x = cell.x + hloop;
202205 icell.z = cell.z + vloop;
203206
207+ CBaseLevelRegion* reg = g_levMap->GetRegion (icell);
208+
209+ if (currentRegion != reg)
210+ memset (&iteratorCache, 0 , sizeof (iteratorCache));
211+ currentRegion = reg;
212+
204213 if ( // rightPlane < 0 &&
205214 // leftPlane > 0 &&
206215 // backPlane < farClipLimit && // check planes
207216 icell.x > -1 && icell.x < levMapDriver2->GetCellsAcross () &&
208217 icell.z > -1 && icell.z < levMapDriver2->GetCellsDown ())
209218 {
210219 CELL_ITERATOR_D2 ci;
220+ ci.cache = &iteratorCache;
211221 PACKED_CELL_OBJECT* ppco;
212222
213223 levMapDriver2->SpoolRegion (spoolContext, icell);
@@ -517,6 +527,7 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
517527// -------------------------------------------------------
518528void DrawLevelDriver1 (const Vector3D& cameraPos, float cameraAngleY, const Volume& frustrumVolume)
519529{
530+ CELL_ITERATOR_CACHE iteratorCache;
520531 CELL_ITERATOR_D1 ci;
521532 CELL_OBJECT* pco;
522533
@@ -546,6 +557,10 @@ void DrawLevelDriver1(const Vector3D& cameraPos, float cameraAngleY, const Volum
546557 drawObjects.reserve (g_cellsDrawDistance * 2 );
547558 drawObjects.clear ();
548559
560+ ci.cache = &iteratorCache;
561+
562+ CBaseLevelRegion* currentRegion = nullptr ;
563+
549564 // walk through all cells
550565 while (i >= 0 )
551566 {
@@ -558,6 +573,11 @@ void DrawLevelDriver1(const Vector3D& cameraPos, float cameraAngleY, const Volum
558573 icell.x = cell.x + hloop;
559574 icell.z = cell.z + vloop;
560575
576+ CBaseLevelRegion* reg = g_levMap->GetRegion (icell);
577+
578+ if (currentRegion != reg)
579+ memset (&iteratorCache, 0 , sizeof (iteratorCache));
580+ currentRegion = reg;
561581
562582 if (icell.x > -1 && icell.x < levMapDriver1->GetCellsAcross () &&
563583 icell.z > -1 && icell.z < levMapDriver1->GetCellsDown ())
0 commit comments