Skip to content

Commit 94bd4be

Browse files
committed
- move overlay map handling to CDriverLevelTextures, fix export bug
1 parent bc0bb4c commit 94bd4be

13 files changed

Lines changed: 225 additions & 100 deletions

File tree

DriverLevelTool/driver_routines/d2_types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ struct CELL_OBJECT {
309309

310310
//------------------------------------------------------------------------------------------------------------
311311

312+
enum SurfaceType
313+
{
314+
SurfType_Asphalt = 0,
315+
SurfType_Grass = 4,
316+
SurfType_Water = 6,
317+
SurfType_DeepWater = 9, // the default surface
318+
};
319+
312320
struct sdPlane
313321
{
314322
short surfaceType;
@@ -371,6 +379,14 @@ struct DRIVER2_JUNCTION
371379

372380
//------------------------------------------------------------------------------------------------------------
373381

382+
struct ROAD_MAP_LUMP_DATA
383+
{
384+
int width, height;
385+
int unitXMid, unitZMid;
386+
};
387+
388+
//------------------------------------------------------------------------------------------------------------
389+
374390
struct AreaDataStr {
375391
uint16 gfx_offset;
376392
uint16 model_offset;

DriverLevelTool/driver_routines/level.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111

1212
#include "level.h"
1313

14-
15-
//--------------------------------------------------------------------------------------------------------------------------
16-
17-
char* g_overlayMapData = nullptr;
18-
19-
//-------------------------------------------------------------
20-
// Loads overhead map lump
21-
//-------------------------------------------------------------
22-
void LoadOverlayMapLump(IVirtualStream* pFile, int lumpSize)
23-
{
24-
g_overlayMapData = new char[lumpSize];
25-
pFile->Read(g_overlayMapData, 1, lumpSize);
26-
}
27-
2814
//-------------------------------------------------------------
2915
// Auto-detects level format
3016
//-------------------------------------------------------------
@@ -182,12 +168,13 @@ void CDriverLevelLoader::ProcessLumps(IVirtualStream* pFile)
182168
break;
183169
case LUMP_OVERLAYMAP:
184170
DevMsg(SPEW_WARNING, "LUMP_OVERLAYMAP ofs=%d size=%d\n", pFile->Tell(), lump.size);
185-
LoadOverlayMapLump(pFile, lump.size);
171+
if(m_textures)
172+
m_textures->LoadOverlayMapLump(pFile, lump.size);
186173
break;
187174
case LUMP_PALLET:
188175
DevMsg(SPEW_WARNING, "LUMP_PALLET ofs=%d size=%d\n", pFile->Tell(), lump.size);
189176
if(m_textures)
190-
m_textures->ProcessPalletLump(pFile);
177+
m_textures->LoadPalletLump(pFile);
191178
break;
192179
case LUMP_SPOOLINFO:
193180
DevMsg(SPEW_WARNING, "LUMP_SPOOLINFO ofs=%d size=%d\n", pFile->Tell(), lump.size);
@@ -293,7 +280,6 @@ void CDriverLevelLoader::Initialize(OUT_CITYLUMP_INFO& lumpInfo, CDriverLevelTex
293280

294281
void CDriverLevelLoader::Release()
295282
{
296-
delete[] g_overlayMapData;
297283
}
298284

299285
//-------------------------------------------------------------

DriverLevelTool/driver_routines/models.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ModelRef_t* CDriverLevelModels::GetModelByIndex(int nIndex) const
5858

5959
int CDriverLevelModels::FindModelIndexByName(const char* name) const
6060
{
61-
for (int i = 0; i < MAX_MODELS && i < m_model_names.size(); i++)
61+
for (usize i = 0; i < MAX_MODELS && i < m_model_names.size(); i++)
6262
{
6363
if (!stricmp(m_model_names[i], name))
6464
return i;

DriverLevelTool/driver_routines/models.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,31 @@ enum EFaceFlags_e
4848

4949
struct ModelRef_t
5050
{
51-
ModelRef_t()
52-
{
53-
model = nullptr;
54-
userData = nullptr;
55-
baseInstance = nullptr;
56-
name = nullptr;
57-
}
51+
ModelRef_t* baseInstance{ nullptr };
5852

59-
ModelRef_t* baseInstance;
53+
const char* name{ nullptr };
54+
MODEL* model{ nullptr };
6055

61-
const char* name;
62-
MODEL* model;
56+
int index{ -1 };
57+
int size{ 0 };
6358

64-
int index;
65-
int size;
66-
67-
ushort highDetailId;
68-
ushort lowDetailId;
59+
ushort highDetailId{ 0xffff };
60+
ushort lowDetailId{ 0xffff };
6961

70-
void* userData; // might contain a hardware model pointer
62+
void* userData{ nullptr }; // might contain a hardware model pointer
7163
};
7264

7365
//------------------------------------------------------------------------------------------------------------
7466

7567
struct CarModelData_t
7668
{
77-
MODEL* cleanmodel;
78-
MODEL* dammodel;
79-
MODEL* lowmodel;
69+
MODEL* cleanmodel{ nullptr };
70+
MODEL* dammodel{ nullptr };
71+
MODEL* lowmodel{ nullptr };
8072

81-
int cleanSize;
82-
int damSize;
83-
int lowSize;
73+
int cleanSize{ 0 };
74+
int damSize{ 0 };
75+
int lowSize{ 0 };
8476
};
8577

8678
class CDriverLevelModels

DriverLevelTool/driver_routines/regions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CBaseLevelMap
106106
virtual CBaseLevelRegion* GetRegion(int regionIdx) const = 0;
107107

108108
virtual int MapHeight(const VECTOR_NOPAD& position) const = 0;
109+
virtual int FindSurface(const VECTOR_NOPAD& position, VECTOR_NOPAD& outNormal, VECTOR_NOPAD& outPoint, sdPlane** outPlane) const = 0;
109110

110111
// converters
111112
void WorldPositionToCellXZ(XZPAIR& cell, const VECTOR_NOPAD& position) const;

DriverLevelTool/driver_routines/regions_d1.cpp

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void CDriver1LevelMap::LoadSpoolInfoLump(IVirtualStream* pFile)
144144
CBaseLevelMap::LoadSpoolInfoLump(pFile);
145145

146146
// Init regions
147-
int total_regions = m_regions_across * m_regions_down;
147+
const int total_regions = m_regions_across * m_regions_down;
148148

149149
m_regions = new CDriver1LevelRegion[total_regions];
150150

@@ -158,11 +158,17 @@ CBaseLevelRegion* CDriver1LevelMap::GetRegion(const XZPAIR& cell) const
158158
const int region_x = cell.x / m_mapInfo.region_size;
159159
const int region_z = cell.z / m_mapInfo.region_size;
160160

161-
return &m_regions[region_x + region_z * m_regions_across];
161+
return GetRegion(region_x + region_z * m_regions_across);;
162162
}
163163

164164
CBaseLevelRegion* CDriver1LevelMap::GetRegion(int regionIdx) const
165165
{
166+
#if 0
167+
const int total_regions = m_regions_across * m_regions_down;
168+
169+
if (regionIdx < 0 && regionIdx >= total_regions)
170+
return nullptr;
171+
#endif
166172
return &m_regions[regionIdx];
167173
}
168174

@@ -186,7 +192,7 @@ void CDriver1LevelMap::SpoolRegion(const SPOOL_CONTEXT& ctx, int regionIdx)
186192
{
187193
CDriver1LevelRegion* region = (CDriver1LevelRegion*)GetRegion(regionIdx);
188194

189-
if (!region->m_loaded)
195+
if (region && !region->m_loaded)
190196
{
191197
if (m_regionSpoolInfoOffsets[region->m_regionNumber] != REGION_EMPTY)
192198
{
@@ -198,20 +204,47 @@ void CDriver1LevelMap::SpoolRegion(const SPOOL_CONTEXT& ctx, int regionIdx)
198204
}
199205
}
200206

207+
extern sdPlane g_defaultPlane;
208+
201209
int CDriver1LevelMap::MapHeight(const VECTOR_NOPAD& position) const
202210
{
203211
MsgWarning("UNIMPLEMENTED MapHeight for D1\n");
204212
return 0;
205213
}
206214

215+
int CDriver1LevelMap::FindSurface(const VECTOR_NOPAD& position, VECTOR_NOPAD& outNormal, VECTOR_NOPAD& outPoint, sdPlane** outPlane) const
216+
{
217+
{
218+
*outPlane = &g_defaultPlane;
219+
220+
outPoint.vx = position.vx;
221+
outPoint.vz = position.vz;
222+
outPoint.vy = 0;
223+
224+
if (*outPlane == NULL || (*outPlane)->b == 0)
225+
{
226+
outNormal.vx = 0;
227+
outNormal.vy = 4096;
228+
outNormal.vz = 0;
229+
}
230+
else
231+
{
232+
outNormal.vx = (int)(*outPlane)->a >> 2;
233+
outNormal.vy = (int)(*outPlane)->b >> 2;
234+
outNormal.vz = (int)(*outPlane)->c >> 2;
235+
}
236+
}
237+
return 4096;
238+
}
239+
207240
//-------------------------------------------------------------
208241
// returns first cell object of cell
209242
//-------------------------------------------------------------
210-
CELL_OBJECT* CDriver1LevelMap::GetFirstCop(CELL_ITERATOR_D1* iterator, int cellx, int cellz) const
243+
CELL_OBJECT* CDriver1LevelMap::GetFirstCop(CELL_ITERATOR_D1* iterator, const XZPAIR& cell) const
211244
{
212245
// lookup region
213-
const int region_x = cellx / m_mapInfo.region_size;
214-
const int region_z = cellz / m_mapInfo.region_size;
246+
const int region_x = cell.x / m_mapInfo.region_size;
247+
const int region_z = cell.z / m_mapInfo.region_size;
215248

216249
int regionIdx = region_x + region_z * m_regions_across;
217250

@@ -224,8 +257,8 @@ CELL_OBJECT* CDriver1LevelMap::GetFirstCop(CELL_ITERATOR_D1* iterator, int cellx
224257
return nullptr;
225258

226259
// get cell index on the region
227-
const int region_cell_x = cellx % m_mapInfo.region_size;
228-
const int region_cell_z = cellz % m_mapInfo.region_size;
260+
const int region_cell_x = cell.x % m_mapInfo.region_size;
261+
const int region_cell_z = cell.z % m_mapInfo.region_size;
229262

230263
// FIXME: might be incorrect
231264
int cell_index = region_cell_x + region_cell_z * m_mapInfo.region_size;
@@ -236,11 +269,11 @@ CELL_OBJECT* CDriver1LevelMap::GetFirstCop(CELL_ITERATOR_D1* iterator, int cellx
236269
return nullptr;
237270

238271
// get the packed cell data start and near cell
239-
CELL_DATA_D1& cell = region.m_cells[cell_ptr];
272+
CELL_DATA_D1& pcd = region.m_cells[cell_ptr];
240273

241-
CELL_OBJECT* pco = region.GetCellObject(cell.num & 0x3fff);
274+
CELL_OBJECT* pco = region.GetCellObject(pcd.num & 0x3fff);
242275

243-
iterator->pcd = &cell;
276+
iterator->pcd = &pcd;
244277
iterator->pco = pco;
245278

246279
return pco;

DriverLevelTool/driver_routines/regions_d1.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ class CDriver1LevelMap : public CBaseLevelMap
5353
CBaseLevelRegion* GetRegion(int regionIdx) const override;
5454

5555
int MapHeight(const VECTOR_NOPAD& position) const override;
56+
int FindSurface(const VECTOR_NOPAD& position, VECTOR_NOPAD& outNormal, VECTOR_NOPAD& outPoint, sdPlane** outPlane) const override;
5657

5758
//----------------------------------------
5859
// cell iterator
59-
CELL_OBJECT* GetFirstCop(CELL_ITERATOR_D1* iterator, int cellx, int cellz) const;
60+
CELL_OBJECT* GetFirstCop(CELL_ITERATOR_D1* iterator, const XZPAIR& cell) const;
6061
CELL_OBJECT* GetNextCop(CELL_ITERATOR_D1* iterator) const;
6162

6263
protected:

DriverLevelTool/driver_routines/regions_d2.cpp

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#define IS_CURVED_SURFACE(surfid) (((surfid) > -1) && ((surfid) & 0xFFFFE000) == 0x4000 && ((surfid) & 0x1FFF) < m_numCurves)
1616
#define IS_JUNCTION_SURFACE(surfid) (((surfid) > -1) && ((surfid) & 0xFFFFE000) == 0x2000 && ((surfid) & 0x1FFF) < m_numJunctions)
1717

18-
sdPlane g_defaultPlane = { 0, 0, 0, 0, 2048 };
19-
sdPlane g_seaPlane = { 9, 0, 16384, 0, 2048 };
18+
sdPlane g_defaultPlane = { SurfType_Asphalt, 0, 0, 0, 2048 };
19+
sdPlane g_seaPlane = { SurfType_DeepWater, 0, 16384, 0, 2048 };
2020

2121
int SdHeightOnPlane(const VECTOR_NOPAD& position, sdPlane* plane, DRIVER2_CURVE* curves)
2222
{
@@ -683,19 +683,26 @@ CBaseLevelRegion* CDriver2LevelMap::GetRegion(const XZPAIR& cell) const
683683
const int region_x = cell.x / m_mapInfo.region_size;
684684
const int region_z = cell.z / m_mapInfo.region_size;
685685

686-
return &m_regions[region_x + region_z * m_regions_across];
686+
return GetRegion(region_x + region_z * m_regions_across);
687687
}
688688

689689
CBaseLevelRegion* CDriver2LevelMap::GetRegion(int regionIdx) const
690690
{
691+
#if 0
692+
const int total_regions = m_regions_across * m_regions_down;
693+
694+
if (regionIdx < 0 && regionIdx >= total_regions)
695+
return nullptr;
696+
#endif
697+
691698
return &m_regions[regionIdx];
692699
}
693700

694701
void CDriver2LevelMap::SpoolRegion(const SPOOL_CONTEXT& ctx, const XZPAIR& cell)
695702
{
696703
CDriver2LevelRegion* region = (CDriver2LevelRegion*)GetRegion(cell);
697704

698-
if (!region->m_loaded)
705+
if (region && !region->m_loaded)
699706
{
700707
if (m_regionSpoolInfoOffsets[region->m_regionNumber] != REGION_EMPTY)
701708
{
@@ -711,7 +718,7 @@ void CDriver2LevelMap::SpoolRegion(const SPOOL_CONTEXT& ctx, int regionIdx)
711718
{
712719
CDriver2LevelRegion* region = (CDriver2LevelRegion*)GetRegion(regionIdx);
713720

714-
if (!region->m_loaded)
721+
if (region && !region->m_loaded)
715722
{
716723
if (m_regionSpoolInfoOffsets[region->m_regionNumber] != REGION_EMPTY)
717724
{
@@ -736,14 +743,54 @@ int CDriver2LevelMap::MapHeight(const VECTOR_NOPAD& position) const
736743
WorldPositionToCellXZ(cell, cellPos);
737744
CDriver2LevelRegion* region = (CDriver2LevelRegion*)GetRegion(cell);
738745

739-
sdPlane* plane = region->SdGetCell(cellPos, level, SdGetBSP);
746+
sdPlane* plane = &g_seaPlane;
747+
if (region)
748+
plane = region->SdGetCell(cellPos, level, SdGetBSP);
740749

741750
if (plane)
742751
return SdHeightOnPlane(position, plane, m_curves);
743752

744753
return 0;
745754
}
746755

756+
int CDriver2LevelMap::FindSurface(const VECTOR_NOPAD& position, VECTOR_NOPAD& outNormal, VECTOR_NOPAD& outPoint, sdPlane** outPlane) const
757+
{
758+
VECTOR_NOPAD cellPos;
759+
XZPAIR cell;
760+
int level = 0;
761+
762+
cellPos.vx = position.vx - 512; // FIXME: is that a quarter of a cell?
763+
cellPos.vy = position.vy;
764+
cellPos.vz = position.vz - 512;
765+
766+
WorldPositionToCellXZ(cell, cellPos);
767+
CDriver2LevelRegion* region = (CDriver2LevelRegion*)GetRegion(cell);
768+
769+
if (region)
770+
{
771+
*outPlane = region->SdGetCell(cellPos, level, SdGetBSP);
772+
773+
outPoint.vx = position.vx;
774+
outPoint.vz = position.vz;
775+
outPoint.vy = SdHeightOnPlane(position, *outPlane, m_curves);
776+
777+
if (*outPlane == NULL || (*outPlane)->b == 0)
778+
{
779+
outNormal.vx = 0;
780+
outNormal.vy = 4096;
781+
outNormal.vz = 0;
782+
}
783+
else
784+
{
785+
outNormal.vx = (int)(*outPlane)->a >> 2;
786+
outNormal.vy = (int)(*outPlane)->b >> 2;
787+
outNormal.vz = (int)(*outPlane)->c >> 2;
788+
}
789+
}
790+
791+
return 4096;
792+
}
793+
747794
int CDriver2LevelMap::GetRoadIndex(VECTOR_NOPAD& position) const
748795
{
749796
VECTOR_NOPAD cellPos;
@@ -915,6 +962,7 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
915962
ushort num;
916963
PACKED_CELL_OBJECT* ppco;
917964
CELL_OBJECT* co;
965+
CDriver2LevelRegion* reg = iterator->region;
918966

919967
do {
920968
CELL_DATA* celld = iterator->pcd;
@@ -932,8 +980,8 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
932980

933981
iterator->pcd = celld;
934982

935-
ppco = iterator->region->GetPackedCellObject(celld->num & 0x3fff);
936-
co = iterator->region->GetCellObject(celld->num & 0x3fff);
983+
ppco = reg->GetPackedCellObject(celld->num & 0x3fff);
984+
co = reg->GetCellObject(celld->num & 0x3fff);
937985

938986
} while (ppco->value == 0xffff && (ppco->pos.vy & 1));
939987

0 commit comments

Comments
 (0)