Skip to content

Commit dc5dffa

Browse files
committed
- implement Havana secret base cell iterator tricks
1 parent afd78e8 commit dc5dffa

4 files changed

Lines changed: 63 additions & 20 deletions

File tree

DriverLevelTool/driver_routines/regions_d2.cpp

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ CELL_DATA* CDriver2LevelRegion::GetCellData(int num) const
314314
}
315315

316316
// cell iterator
317-
PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR* iterator, int cellNumber) const
317+
PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR_D2* iterator, int cellNumber) const
318318
{
319319
ushort cell_ptr = m_cellPointers[cellNumber];
320320

@@ -341,14 +341,32 @@ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR* iterator,
341341
iterator->nearCell.z = (cellz - (mapInfo.cells_down / 2))* mapInfo.cell_size;
342342

343343
// get the packed cell data start and near cell
344-
CELL_DATA& cell = m_cells[cell_ptr];
344+
CELL_DATA* cell = &m_cells[cell_ptr];
345345

346-
if (cell.num & 0x4000) // FIXME: other objects are flagged with 0x8000 etc
347-
return nullptr;
346+
int drawValue = iterator->drawValue;
348347

349-
PACKED_CELL_OBJECT* ppco = GetCellObject(cell.num & 0x3fff);
348+
if(drawValue != -1)
349+
{
350+
if (drawValue == 0)
351+
{
352+
if (cell->num & 0x4000)
353+
return nullptr;
354+
}
355+
else
356+
{
357+
cell++;
358+
while (cell->num != (drawValue | 0x4000))
359+
{
360+
if (cell->num & 0x8000)
361+
return nullptr;
362+
363+
cell++;
364+
}
365+
}
366+
}
350367

351-
iterator->pcd = &cell;
368+
PACKED_CELL_OBJECT* ppco = GetCellObject(cell->num & 0x3fff);
369+
iterator->pcd = cell;
352370

353371
if (ppco->value == 0xffff && (ppco->pos.vy & 1))
354372
ppco = ((CDriver2LevelMap*)m_owner)->GetNextPackedCop(iterator);
@@ -527,7 +545,7 @@ int CDriver2LevelMap::MapHeight(const VECTOR_NOPAD& position) const
527545
//-------------------------------------------------------------
528546
// returns first cell object of cell
529547
//-------------------------------------------------------------
530-
PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR* iterator, int cellx, int cellz) const
548+
PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterator, int cellx, int cellz) const
531549
{
532550
// lookup region
533551
const int region_x = cellx / m_mapInfo.region_size;
@@ -560,14 +578,33 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR* iterator,
560578
iterator->nearCell.z = (cellz - (m_mapInfo.cells_down / 2)) * m_mapInfo.cell_size;
561579

562580
// get the packed cell data start and near cell
563-
CELL_DATA& cell = region.m_cells[cell_ptr];
581+
CELL_DATA* cell = &region.m_cells[cell_ptr];
564582

565-
if (cell.num & 0x4000) // FIXME: other objects are flagged with 0x8000 etc
566-
return nullptr;
583+
int drawValue = iterator->drawValue;
584+
585+
if (drawValue != -1)
586+
{
587+
if (drawValue == 0)
588+
{
589+
if (cell->num & 0x4000)
590+
return nullptr;
591+
}
592+
else
593+
{
594+
cell++;
595+
while (cell->num != (drawValue | 0x4000))
596+
{
597+
if (cell->num & 0x8000)
598+
return nullptr;
599+
600+
cell++;
601+
}
602+
}
603+
}
567604

568-
PACKED_CELL_OBJECT* ppco = region.GetCellObject(cell.num & 0x3fff);
605+
PACKED_CELL_OBJECT* ppco = region.GetCellObject(cell->num & 0x3fff);
569606

570-
iterator->pcd = &cell;
607+
iterator->pcd = cell;
571608

572609
if (ppco->value == 0xffff && (ppco->pos.vy & 1))
573610
ppco = GetNextPackedCop(iterator);
@@ -580,7 +617,7 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR* iterator,
580617
//-------------------------------------------------------------
581618
// iterates cell objects
582619
//-------------------------------------------------------------
583-
PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR* iterator) const
620+
PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterator) const
584621
{
585622
ushort num;
586623
PACKED_CELL_OBJECT* ppco;
@@ -592,7 +629,7 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR* iterator)
592629
iterator->pcd++;
593630
num = iterator->pcd->num;
594631

595-
if (num & 0x4000) // FIXME: other objects are flagged with 0x8000 etc
632+
if (iterator->drawValue != -1 && num & 0x4000)
596633
return nullptr;
597634

598635
ppco = iterator->region->GetCellObject(num & 0x3fff);

DriverLevelTool/driver_routines/regions_d2.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
class CDriver2LevelRegion;
1111
class CDriver2LevelMap;
1212

13-
struct CELL_ITERATOR
13+
struct CELL_ITERATOR_D2
1414
{
15+
CELL_ITERATOR_D2()
16+
{
17+
drawValue = -1;
18+
}
19+
1520
CDriver2LevelRegion* region;
1621
CELL_DATA* pcd;
1722
PACKED_CELL_OBJECT* ppco;
1823
XZPAIR nearCell;
24+
int drawValue;
1925
};
2026

2127
typedef short* (*sdBspCallback)(sdNode* node, XZPAIR* pos);
@@ -35,7 +41,7 @@ class CDriver2LevelRegion : public CBaseLevelRegion
3541
CELL_DATA* GetCellData(int num) const;
3642

3743
// cell iterator
38-
PACKED_CELL_OBJECT* StartIterator(CELL_ITERATOR* iterator, int cellNumber) const;
44+
PACKED_CELL_OBJECT* StartIterator(CELL_ITERATOR_D2* iterator, int cellNumber) const;
3945

4046
sdPlane* SdGetCell(const VECTOR_NOPAD& position, int& sdLevel, sdBspCallback bspWalker) const;
4147

@@ -82,8 +88,8 @@ class CDriver2LevelMap : public CBaseLevelMap
8288

8389
//----------------------------------------
8490
// cell iterator
85-
PACKED_CELL_OBJECT* GetFirstPackedCop(CELL_ITERATOR* iterator, int cellx, int cellz) const;
86-
PACKED_CELL_OBJECT* GetNextPackedCop(CELL_ITERATOR* iterator) const;
91+
PACKED_CELL_OBJECT* GetFirstPackedCop(CELL_ITERATOR_D2* iterator, int cellx, int cellz) const;
92+
PACKED_CELL_OBJECT* GetNextPackedCop(CELL_ITERATOR_D2* iterator) const;
8793
static bool UnpackCellObject(CELL_OBJECT& co, PACKED_CELL_OBJECT* pco, const XZPAIR& nearCell);
8894

8995
protected:

DriverLevelTool/exporter/export_regions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ 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 iterator;
130+
CELL_ITERATOR_D2 iterator;
131131
PACKED_CELL_OBJECT* pco = region->StartIterator(&iterator, i);
132132

133133
if (!pco)

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
148148
icell.x > -1 && icell.x < levMapDriver2->GetCellsAcross() &&
149149
icell.z > -1 && icell.z < levMapDriver2->GetCellsDown())
150150
{
151-
CELL_ITERATOR ci;
151+
CELL_ITERATOR_D2 ci;
152152
PACKED_CELL_OBJECT* ppco;
153153

154154
levMapDriver2->SpoolRegion(spoolContext, icell);

0 commit comments

Comments
 (0)