Skip to content

Commit c057a2d

Browse files
committed
- LevelTool: fix object duplication when exporting and drawing
1 parent 4494421 commit c057a2d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

DriverLevelTool/exporter/export_regions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ int ExportRegionDriver1(CDriver1LevelRegion* region, IVirtualStream* levelFileSt
6060
if (g_export_worldUnityScript)
6161
levelFileStream->Print("// Region %d\n", region->GetNumber());
6262

63+
CELL_ITERATOR_CACHE cache;
64+
6365
// walk through all cell data
6466
for(int i = 0; i < mapInfo.region_size * mapInfo.region_size; i++)
6567
{
6668
CELL_ITERATOR_D1 iterator;
69+
iterator.cache = &cache;
6770
CELL_OBJECT* co = region->StartIterator(&iterator, i);
6871

6972
if (!co)
@@ -124,10 +127,15 @@ int ExportRegionDriver2(CDriver2LevelRegion* region, IVirtualStream* levelFileSt
124127
if (g_export_worldUnityScript)
125128
levelFileStream->Print("// Region %d\n", region->GetNumber());
126129

130+
CELL_ITERATOR_CACHE cache;
131+
127132
// walk through all cell data
128133
for (int i = 0; i < mapInfo.region_size * mapInfo.region_size; i++)
129134
{
135+
136+
130137
CELL_ITERATOR_D2 ci;
138+
ci.cache = &cache;
131139

132140
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i);
133141

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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
//-------------------------------------------------------
164164
void 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
//-------------------------------------------------------
518528
void 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

Comments
 (0)