Skip to content

Commit 81f0361

Browse files
committed
- exporter to include hidden cell objects
1 parent dc5dffa commit 81f0361

4 files changed

Lines changed: 87 additions & 72 deletions

File tree

DriverLevelTool/driver_routines/regions_d2.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,24 @@ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR_D2* iterato
343343
// get the packed cell data start and near cell
344344
CELL_DATA* cell = &m_cells[cell_ptr];
345345

346-
int drawValue = iterator->drawValue;
346+
int cellLevel = iterator->cellLevel;
347347

348-
if(drawValue != -1)
348+
if (cellLevel == 0)
349349
{
350-
if (drawValue == 0)
350+
if (cell->num & 0x4000)
351+
return nullptr;
352+
}
353+
else
354+
{
355+
ushort num = cell->num;
356+
cell++;
357+
while (num != (cellLevel | 0x4000))
351358
{
352-
if (cell->num & 0x4000)
359+
if (cell->num & 0x8000)
353360
return nullptr;
354-
}
355-
else
356-
{
361+
362+
num = cell->num;
357363
cell++;
358-
while (cell->num != (drawValue | 0x4000))
359-
{
360-
if (cell->num & 0x8000)
361-
return nullptr;
362-
363-
cell++;
364-
}
365364
}
366365
}
367366

@@ -580,25 +579,24 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
580579
// get the packed cell data start and near cell
581580
CELL_DATA* cell = &region.m_cells[cell_ptr];
582581

583-
int drawValue = iterator->drawValue;
582+
int cellLevel = iterator->cellLevel;
584583

585-
if (drawValue != -1)
584+
if (cellLevel == 0)
585+
{
586+
if (cell->num & 0x4000)
587+
return nullptr;
588+
}
589+
else
586590
{
587-
if (drawValue == 0)
591+
ushort num = cell->num;
592+
cell++;
593+
while (num != (cellLevel | 0x4000))
588594
{
589-
if (cell->num & 0x4000)
595+
if (cell->num & 0x8000)
590596
return nullptr;
591-
}
592-
else
593-
{
594-
cell++;
595-
while (cell->num != (drawValue | 0x4000))
596-
{
597-
if (cell->num & 0x8000)
598-
return nullptr;
599597

600-
cell++;
601-
}
598+
num = cell->num;
599+
cell++;
602600
}
603601
}
604602

@@ -622,19 +620,20 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
622620
ushort num;
623621
PACKED_CELL_OBJECT* ppco;
624622

623+
int cellLevel = iterator->cellLevel;
624+
625625
do {
626626
if (iterator->pcd->num & 0x8000)
627627
return nullptr;
628628

629629
iterator->pcd++;
630630
num = iterator->pcd->num;
631631

632-
if (iterator->drawValue != -1 && num & 0x4000)
632+
if(num & 0x4000) // start of new list
633633
return nullptr;
634634

635635
ppco = iterator->region->GetCellObject(num & 0x3fff);
636-
if (!ppco)
637-
return nullptr;
636+
638637
} while (ppco->value == 0xffff && (ppco->pos.vy & 1));
639638

640639
iterator->ppco = ppco;

DriverLevelTool/driver_routines/regions_d2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ struct CELL_ITERATOR_D2
1414
{
1515
CELL_ITERATOR_D2()
1616
{
17-
drawValue = -1;
17+
cellLevel = 0;
1818
}
1919

2020
CDriver2LevelRegion* region;
2121
CELL_DATA* pcd;
2222
PACKED_CELL_OBJECT* ppco;
2323
XZPAIR nearCell;
24-
int drawValue;
24+
int cellLevel;
2525
};
2626

2727
typedef short* (*sdBspCallback)(sdNode* node, XZPAIR* pos);

DriverLevelTool/exporter/export_regions.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,48 +127,56 @@ int ExportRegionDriver2(CDriver2LevelRegion* region, IVirtualStream* levelFileSt
127127
// walk through all cell data
128128
for (int i = 0; i < mapInfo.region_size * mapInfo.region_size; i++)
129129
{
130-
CELL_ITERATOR_D2 iterator;
131-
PACKED_CELL_OBJECT* pco = region->StartIterator(&iterator, i);
130+
CELL_ITERATOR_D2 ci;
131+
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i);
132132

133133
if (!pco)
134134
continue;
135135

136136
while (pco)
137137
{
138-
CELL_OBJECT co;
139-
CDriver2LevelMap::UnpackCellObject(co, pco, iterator.nearCell);
140-
141-
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * -EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
142-
float cellRotationRad = co.yang / 64.0f * PI_F * 2.0f;
138+
for (int i = 0; i < 20; i++)
139+
{
140+
if (i == 19)
141+
ci.cellLevel = 100; // 100 is the special slot for event object placement
142+
else
143+
ci.cellLevel = i;
143144

144-
ModelRef_t* ref = g_levModels.GetModelByIndex(co.type);
145+
CELL_OBJECT co;
146+
CDriver2LevelMap::UnpackCellObject(co, pco, ci.nearCell);
145147

146-
if (ref)
147-
{
148-
if (g_export_worldUnityScript)
149-
{
150-
String modelName = strlen(ref->name) > 0 ? String::fromCString(ref->name) : String::fromPrintf("MOD_%d", ref->index);
148+
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * -EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
149+
float cellRotationRad = co.yang / 64.0f * PI_F * 2.0f;
151150

152-
float cellRotationDeg = RAD2DEG(cellRotationRad) + 180;
151+
ModelRef_t* ref = g_levModels.GetModelByIndex(co.type);
153152

154-
levelFileStream->Print("var reg%d_o%d = Instantiate(%s, new Vector3(%gf,%gf,%gf), Quaternion.Euler(0.0f,%gf,0.0f)) as GameObject;\n",
155-
region->GetNumber(), numRegionObjects, (char*)modelName, absCellPosition.x, absCellPosition.y, absCellPosition.z, -cellRotationDeg);
156-
}
157-
else
153+
if (ref)
158154
{
159-
// transform objects and save
160-
Matrix4x4 transform = translate(absCellPosition);
161-
transform = transform * rotateY4(cellRotationRad) * scale4(1.0f, 1.0f, 1.0f);
162-
163-
WriteMODELToObjStream(levelFileStream, ref->model, ref->size, co.type,
164-
String::fromPrintf("reg%d", region->GetNumber()),
165-
false, transform, &lobj_first_v, &lobj_first_t);
155+
if (g_export_worldUnityScript)
156+
{
157+
String modelName = strlen(ref->name) > 0 ? String::fromCString(ref->name) : String::fromPrintf("MOD_%d", ref->index);
158+
159+
float cellRotationDeg = RAD2DEG(cellRotationRad) + 180;
160+
161+
levelFileStream->Print("var reg%d_o%d = Instantiate(%s, new Vector3(%gf,%gf,%gf), Quaternion.Euler(0.0f,%gf,0.0f)) as GameObject;\n",
162+
region->GetNumber(), numRegionObjects, (char*)modelName, absCellPosition.x, absCellPosition.y, absCellPosition.z, -cellRotationDeg);
163+
}
164+
else
165+
{
166+
// transform objects and save
167+
Matrix4x4 transform = translate(absCellPosition);
168+
transform = transform * rotateY4(cellRotationRad) * scale4(1.0f, 1.0f, 1.0f);
169+
170+
WriteMODELToObjStream(levelFileStream, ref->model, ref->size, co.type,
171+
String::fromPrintf("reg%d", region->GetNumber()),
172+
false, transform, &lobj_first_v, &lobj_first_t);
173+
}
166174
}
167-
}
168175

169-
numRegionObjects++;
176+
numRegionObjects++;
170177

171-
pco = levMapDriver2->GetNextPackedCop(&iterator);
178+
pco = levMapDriver2->GetNextPackedCop(&ci);
179+
}
172180
}
173181
}
174182

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,30 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
151151
CELL_ITERATOR_D2 ci;
152152
PACKED_CELL_OBJECT* ppco;
153153

154-
levMapDriver2->SpoolRegion(spoolContext, icell);
154+
for (int i = 0; i < 20; i++)
155+
{
156+
if (i == 19)
157+
ci.cellLevel = 100; // 100 is the special slot for event object placement
158+
else
159+
ci.cellLevel = i;
160+
161+
levMapDriver2->SpoolRegion(spoolContext, icell);
155162

156-
ppco = levMapDriver2->GetFirstPackedCop(&ci, icell.x, icell.z);
163+
ppco = levMapDriver2->GetFirstPackedCop(&ci, icell.x, icell.z);
157164

158-
g_drawnCells++;
165+
g_drawnCells++;
159166

160-
// walk each cell object in cell
161-
while (ppco)
162-
{
163-
PCO_PAIR_D2 pair;
164-
pair.nearCell = ci.nearCell;
165-
pair.pco = ppco;
167+
// walk each cell object in cell
168+
while (ppco)
169+
{
170+
PCO_PAIR_D2 pair;
171+
pair.nearCell = ci.nearCell;
172+
pair.pco = ppco;
166173

167-
drawObjects.append(pair);
174+
drawObjects.append(pair);
168175

169-
ppco = levMapDriver2->GetNextPackedCop(&ci);
176+
ppco = levMapDriver2->GetNextPackedCop(&ci);
177+
}
170178
}
171179
}
172180
}

0 commit comments

Comments
 (0)