Skip to content

Commit 55bbba7

Browse files
committed
- added "Display hidden objects" option
- fixed export
1 parent 81f0361 commit 55bbba7

9 files changed

Lines changed: 91 additions & 71 deletions

File tree

DriverLevelTool/driver_routines/regions_d2.cpp

Lines changed: 20 additions & 24 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_D2* iterator, int cellNumber) const
317+
PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR_D2* iterator, int cellNumber, int cellLevel) const
318318
{
319319
ushort cell_ptr = m_cellPointers[cellNumber];
320320

@@ -343,8 +343,6 @@ 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 cellLevel = iterator->cellLevel;
347-
348346
if (cellLevel == 0)
349347
{
350348
if (cell->num & 0x4000)
@@ -544,11 +542,11 @@ int CDriver2LevelMap::MapHeight(const VECTOR_NOPAD& position) const
544542
//-------------------------------------------------------------
545543
// returns first cell object of cell
546544
//-------------------------------------------------------------
547-
PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterator, int cellx, int cellz) const
545+
PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterator, const XZPAIR& cell, int cellLevel) const
548546
{
549547
// lookup region
550-
const int region_x = cellx / m_mapInfo.region_size;
551-
const int region_z = cellz / m_mapInfo.region_size;
548+
const int region_x = cell.x / m_mapInfo.region_size;
549+
const int region_z = cell.z / m_mapInfo.region_size;
552550

553551
int regionIdx = region_x + region_z * m_regions_across;
554552

@@ -561,8 +559,8 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
561559
return nullptr;
562560

563561
// get cell index on the region
564-
const int region_cell_x = cellx % m_mapInfo.region_size;
565-
const int region_cell_z = cellz % m_mapInfo.region_size;
562+
const int region_cell_x = cell.x % m_mapInfo.region_size;
563+
const int region_cell_z = cell.z % m_mapInfo.region_size;
566564

567565
// FIXME: might be incorrect
568566
int cell_index = region_cell_x + region_cell_z * m_mapInfo.region_size;
@@ -573,36 +571,34 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
573571
return nullptr;
574572

575573
// get the near cell cPosition in the world
576-
iterator->nearCell.x = (cellx - (m_mapInfo.cells_across / 2)) * m_mapInfo.cell_size;
577-
iterator->nearCell.z = (cellz - (m_mapInfo.cells_down / 2)) * m_mapInfo.cell_size;
574+
iterator->nearCell.x = (cell.x - (m_mapInfo.cells_across / 2)) * m_mapInfo.cell_size;
575+
iterator->nearCell.z = (cell.z - (m_mapInfo.cells_down / 2)) * m_mapInfo.cell_size;
578576

579577
// get the packed cell data start and near cell
580-
CELL_DATA* cell = &region.m_cells[cell_ptr];
581-
582-
int cellLevel = iterator->cellLevel;
578+
CELL_DATA* celld = &region.m_cells[cell_ptr];
583579

584580
if (cellLevel == 0)
585581
{
586-
if (cell->num & 0x4000)
582+
if (celld->num & 0x4000)
587583
return nullptr;
588584
}
589585
else
590586
{
591-
ushort num = cell->num;
592-
cell++;
587+
ushort num = celld->num;
588+
celld++;
593589
while (num != (cellLevel | 0x4000))
594590
{
595-
if (cell->num & 0x8000)
591+
if (celld->num & 0x8000)
596592
return nullptr;
597593

598-
num = cell->num;
599-
cell++;
594+
num = celld->num;
595+
celld++;
600596
}
601597
}
602598

603-
PACKED_CELL_OBJECT* ppco = region.GetCellObject(cell->num & 0x3fff);
599+
PACKED_CELL_OBJECT* ppco = region.GetCellObject(celld->num & 0x3fff);
604600

605-
iterator->pcd = cell;
601+
iterator->pcd = celld;
606602

607603
if (ppco->value == 0xffff && (ppco->pos.vy & 1))
608604
ppco = GetNextPackedCop(iterator);
@@ -620,8 +616,6 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
620616
ushort num;
621617
PACKED_CELL_OBJECT* ppco;
622618

623-
int cellLevel = iterator->cellLevel;
624-
625619
do {
626620
if (iterator->pcd->num & 0x8000)
627621
return nullptr;
@@ -652,7 +646,9 @@ bool CDriver2LevelMap::UnpackCellObject(CELL_OBJECT& co, PACKED_CELL_OBJECT* pco
652646
co.pos.vx = nearCell.x + (((pco->pos.vx - nearCell.x) << 0x10) >> 0x10);
653647
co.pos.vz = nearCell.z + (((pco->pos.vz - nearCell.z) << 0x10) >> 0x10);
654648

655-
co.pos.vy = (pco->pos.vy << 0x10) >> 0x11;
649+
// cell height should be negated
650+
co.pos.vy = -((pco->pos.vy << 0x10) >> 0x11);
651+
656652
co.yang = pco->value & 0x3f;
657653
co.type = (pco->value >> 6) | ((pco->pos.vy & 1) << 10);
658654

DriverLevelTool/driver_routines/regions_d2.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@ class CDriver2LevelRegion;
1111
class CDriver2LevelMap;
1212

1313
struct CELL_ITERATOR_D2
14-
{
15-
CELL_ITERATOR_D2()
16-
{
17-
cellLevel = 0;
18-
}
19-
14+
{
2015
CDriver2LevelRegion* region;
2116
CELL_DATA* pcd;
2217
PACKED_CELL_OBJECT* ppco;
2318
XZPAIR nearCell;
24-
int cellLevel;
2519
};
2620

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

4337
// cell iterator
44-
PACKED_CELL_OBJECT* StartIterator(CELL_ITERATOR_D2* iterator, int cellNumber) const;
38+
PACKED_CELL_OBJECT* StartIterator(CELL_ITERATOR_D2* iterator, int cellNumber, int cellLevel) const;
4539

4640
sdPlane* SdGetCell(const VECTOR_NOPAD& position, int& sdLevel, sdBspCallback bspWalker) const;
4741

@@ -88,7 +82,7 @@ class CDriver2LevelMap : public CBaseLevelMap
8882

8983
//----------------------------------------
9084
// cell iterator
91-
PACKED_CELL_OBJECT* GetFirstPackedCop(CELL_ITERATOR_D2* iterator, int cellx, int cellz) const;
85+
PACKED_CELL_OBJECT* GetFirstPackedCop(CELL_ITERATOR_D2* iterator, const XZPAIR& cell, int cellLevel) const;
9286
PACKED_CELL_OBJECT* GetNextPackedCop(CELL_ITERATOR_D2* iterator) const;
9387
static bool UnpackCellObject(CELL_OBJECT& co, PACKED_CELL_OBJECT* pco, const XZPAIR& nearCell);
9488

DriverLevelTool/exporter/export_regions.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,26 @@ int ExportRegionDriver2(CDriver2LevelRegion* region, IVirtualStream* levelFileSt
128128
for (int i = 0; i < mapInfo.region_size * mapInfo.region_size; i++)
129129
{
130130
CELL_ITERATOR_D2 ci;
131-
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i);
132131

133-
if (!pco)
134-
continue;
135-
136-
while (pco)
132+
for (int i = 0; i < 20; i++)
137133
{
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;
134+
int cellLevel;
135+
if (i == 19)
136+
cellLevel = 100; // 100 is the special slot for event object placement
137+
else
138+
cellLevel = i;
144139

140+
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i, cellLevel);
141+
142+
if (!pco)
143+
continue;
144+
145+
while (pco)
146+
{
145147
CELL_OBJECT co;
146148
CDriver2LevelMap::UnpackCellObject(co, pco, ci.nearCell);
147149

148-
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * -EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
150+
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
149151
float cellRotationRad = co.yang / 64.0f * PI_F * 2.0f;
150152

151153
ModelRef_t* ref = g_levModels.GetModelByIndex(co.type);

DriverLevelTool/viewer/camera.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

2+
23
#include "driver_level.h"
34
#include "gl_renderer.h"
45
#include "renderheightmap.h"
56
#include "rendermodel.h"
6-
#include "math/psx_math_types.h"
7+
78
#include "math/Volume.h"
89

10+
#include "convert.h"
11+
912
extern bool g_displayHeightMap;
1013

1114
const float Z_NEAR = 0.01f;
@@ -49,10 +52,7 @@ void UpdateCameraMovement(float deltaTime, float speedModifier)
4952

5053
g_cameraPosition += g_cameraVelocity * deltaTime;
5154

52-
VECTOR_NOPAD cameraPosition;
53-
cameraPosition.vx = g_cameraPosition.x * ONE_F;
54-
cameraPosition.vy = g_cameraPosition.y * ONE_F;
55-
cameraPosition.vz = g_cameraPosition.z * ONE_F;
55+
VECTOR_NOPAD cameraPosition = ToFixedVector(g_cameraPosition);
5656

5757
int height = g_levMap->MapHeight(cameraPosition);
5858

DriverLevelTool/viewer/convert.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CONVERT_H
2+
#define CONVERT_H
3+
4+
#include "math/psx_math_types.h"
5+
#include "math/Vector.h"
6+
7+
inline Vector3D FromFixedVector(const VECTOR_NOPAD& vec)
8+
{
9+
return Vector3D(vec.vx / ONE_F, vec.vy / ONE_F, vec.vz / ONE_F);
10+
}
11+
12+
inline VECTOR_NOPAD ToFixedVector(const Vector3D& vec)
13+
{
14+
return { (int)(vec.x * ONE_F), (int)(vec.y * ONE_F), (int)(vec.z * ONE_F) };
15+
}
16+
17+
#endif // CONVERT_H

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "debug_overlay.h"
12
#include "gl_renderer.h"
23

34
#include "core/VirtualStream.h"
@@ -9,6 +10,8 @@
910

1011
#include "rendermodel.h"
1112

13+
#include "convert.h"
14+
1215
// extern some vars
1316
extern String g_levname;
1417
extern String g_levname_moddir;
@@ -23,6 +26,7 @@ extern FILE* g_levFile;
2326
extern bool g_nightMode;
2427
extern bool g_displayCollisionBoxes;
2528
extern bool g_displayHeightMap;
29+
extern bool g_displayAllCellLevels;
2630
extern bool g_noLod;
2731
extern int g_cellsDrawDistance;
2832

@@ -67,6 +71,7 @@ struct PCO_PAIR_D2
6771
{
6872
PACKED_CELL_OBJECT* pco;
6973
XZPAIR nearCell;
74+
bool editorEvent;
7075
};
7176

7277
//-------------------------------------------------------
@@ -86,10 +91,7 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
8691
g_drawnModels = 0;
8792
g_drawnPolygons = 0;
8893

89-
VECTOR_NOPAD cameraPosition;
90-
cameraPosition.vx = cameraPos.x * ONE_F;
91-
cameraPosition.vy = cameraPos.y * ONE_F;
92-
cameraPosition.vz = cameraPos.z * ONE_F;
94+
VECTOR_NOPAD cameraPosition = ToFixedVector(cameraPos);
9395

9496
CDriver2LevelMap* levMapDriver2 = (CDriver2LevelMap*)g_levMap;
9597
CFileStream spoolStream(g_levFile);
@@ -151,30 +153,34 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
151153
CELL_ITERATOR_D2 ci;
152154
PACKED_CELL_OBJECT* ppco;
153155

154-
for (int i = 0; i < 20; i++)
156+
levMapDriver2->SpoolRegion(spoolContext, icell);
157+
158+
for (int i = 0; i < (g_displayAllCellLevels ? 20 : 1); i++)
155159
{
160+
int cellLevel;
161+
156162
if (i == 19)
157-
ci.cellLevel = 100; // 100 is the special slot for event object placement
163+
cellLevel = 100; // 100 is the special slot for event object placement
158164
else
159-
ci.cellLevel = i;
160-
161-
levMapDriver2->SpoolRegion(spoolContext, icell);
162-
163-
ppco = levMapDriver2->GetFirstPackedCop(&ci, icell.x, icell.z);
165+
cellLevel = i;
164166

165-
g_drawnCells++;
167+
ppco = levMapDriver2->GetFirstPackedCop(&ci, icell, cellLevel);
166168

167169
// walk each cell object in cell
168170
while (ppco)
169171
{
170172
PCO_PAIR_D2 pair;
171173
pair.nearCell = ci.nearCell;
172174
pair.pco = ppco;
175+
pair.editorEvent = cellLevel == 100;
173176

174177
drawObjects.append(pair);
175178

176179
ppco = levMapDriver2->GetNextPackedCop(&ci);
177180
}
181+
182+
if(ppco)
183+
g_drawnCells++;
178184
}
179185
}
180186
}
@@ -242,7 +248,7 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
242248
continue;
243249
}
244250

245-
Vector3D absCellPosition(co.pos.vx * RENDER_SCALING, co.pos.vy * -RENDER_SCALING, co.pos.vz * RENDER_SCALING);
251+
Vector3D absCellPosition = FromFixedVector(co.pos);
246252

247253
float distanceFromCamera = lengthSqr(absCellPosition - cameraPos);
248254

@@ -315,10 +321,7 @@ void DrawLevelDriver1(const Vector3D& cameraPos, float cameraAngleY, const Volum
315321
g_drawnModels = 0;
316322
g_drawnPolygons = 0;
317323

318-
VECTOR_NOPAD cameraPosition;
319-
cameraPosition.vx = cameraPos.x * ONE_F;
320-
cameraPosition.vy = cameraPos.y * ONE_F;
321-
cameraPosition.vz = cameraPos.z * ONE_F;
324+
VECTOR_NOPAD cameraPosition = ToFixedVector(cameraPos);
322325

323326
CDriver1LevelMap* levMapDriver1 = (CDriver1LevelMap*)g_levMap;
324327
CFileStream spoolStream(g_levFile);
@@ -410,7 +413,7 @@ void DrawLevelDriver1(const Vector3D& cameraPos, float cameraAngleY, const Volum
410413
continue;
411414
}
412415

413-
Vector3D absCellPosition(pco->pos.vx * RENDER_SCALING, pco->pos.vy * -RENDER_SCALING, pco->pos.vz * RENDER_SCALING);
416+
Vector3D absCellPosition = FromFixedVector(pco->pos);
414417
float distanceFromCamera = lengthSqr(absCellPosition - cameraPos);
415418

416419
ModelRef_t* ref = GetModelCheckLods(pco->type, distanceFromCamera);

DriverLevelTool/viewer/rendermodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <assert.h>
88

9+
#include "convert.h"
10+
911
#define MODEL_VERTEX_SHADER \
1012
" attribute vec4 a_position_tu;\n"\
1113
" attribute vec4 a_normal_tv;\n"\
@@ -419,8 +421,8 @@ void CRenderModel::DrawModelCollisionBox(ModelRef_t* ref, const VECTOR_NOPAD& po
419421
ref = ref->baseInstance;
420422

421423
float objRotationRad = -rotation / 64.0f * PI_F * 2.0f;
422-
Vector3D offset(position.vx / ONE_F, -position.vy / ONE_F, position.vz / ONE_F);
423424

425+
Vector3D offset = FromFixedVector(position);
424426
Matrix4x4 world = translate(offset) * rotateY4(objRotationRad);
425427

426428
// add collision box drawing

DriverLevelTool/viewer/viewer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool g_quit = false;
3333
bool g_nightMode = false;
3434
bool g_displayCollisionBoxes = false;
3535
bool g_displayHeightMap = false;
36+
bool g_displayAllCellLevels = true;
3637
bool g_noLod = false;
3738

3839
int g_cellsDrawDistance = 441;
@@ -491,6 +492,9 @@ void DisplayUI()
491492
if (ImGui::MenuItem("Display heightmap", nullptr, g_displayHeightMap))
492493
g_displayHeightMap ^= 1;
493494

495+
if (ImGui::MenuItem("Display hidden objects", nullptr, g_displayAllCellLevels))
496+
g_displayAllCellLevels ^= 1;
497+
494498
ImGui::Separator();
495499

496500
if (ImGui::MenuItem("Reset camera", nullptr, g_noLod))

0 commit comments

Comments
 (0)