Skip to content

Commit d8a3afa

Browse files
authored
Merge pull request #5 from OpenDriver2/level_viewer
Rewrite of LEV file loaders, addition of Level viewer and complete world exporting
2 parents 091a184 + 3ad0f06 commit d8a3afa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+10848
-1646
lines changed

.appveyor/AfterBuild.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set config=Debug:Release
44
for %%c in (%config::= %) do (
55
cd %project_folder%\DriverLevelTool\bin\%%c
6+
copy %windows_sdl2_dir%\lib\x86\SDL2.dll SDL2.dll /Y
67

78
xcopy /e /v %data_folder% .\ /Y
89
7z a "DriverLevelTool_%%c.zip" ".\*"

.appveyor/Build.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
cd %project_folder%
44

5+
set SDL2_DIR=%windows_sdl2_dir%
6+
57
premake5 vs2019
68

79
set config=Debug:Release

.appveyor/Install.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
appveyor DownloadFile %windows_premake_url% -FileName premake5.zip
44
7z x premake5.zip -o%project_folder% -aoa
5+
6+
appveyor DownloadFile %windows_sdl2_url% -FileName SDL2.zip
7+
7z x SDL2.zip -o%dependency_folder%

.appveyor/Install.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ cd "$APPVEYOR_BUILD_FOLDER"
88
curl "$linux_premake_url" -Lo premake5.tar.gz
99
tar xvf premake5.tar.gz
1010

11+
sudo apt-get update
12+
1113
sudo apt-get install -qq \
12-
g++-multilib -y
14+
libsdl2-dev \
15+
g++-multilib -y \
1316

Driver2CutsceneTool/cutscene_tool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void PackCutsceneFile(const char* foldername)
326326

327327
// shrink size
328328
repsizes[i] -= sizeof(PLAYBACKCAMERA) * MAX_REPLAY_CAMERAS;
329-
MsgAccept("\Shinking '%s', now %d bytes\n", folderPath, repsizes[i]);
329+
MsgAccept("\tShrinking '%s', now %d bytes\n", folderPath, repsizes[i]);
330330
}
331331
}
332332
else
@@ -434,8 +434,8 @@ void PackCutsceneFile(const char* foldername)
434434
void PrintCommandLineArguments()
435435
{
436436
MsgInfo("Example usage:\n");
437-
MsgInfo("\tDriverCutsceneTool -unpack CUT2.R\n");
438-
MsgInfo("\tDriverCutsceneTool -pack CUT2\n");
437+
MsgInfo("\tDriver2CutsceneTool -unpack CUT2.R\n");
438+
MsgInfo("\tDriver2CutsceneTool -pack CUT2\n");
439439
}
440440

441441
int main(int argc, char** argv)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <math.h>
2+
3+
#include <malloc.h>
4+
#include "core/VirtualStream.h"
5+
#include "core/cmdlib.h"
6+
#include "math/dktypes.h"
7+
#include "util/image.h"
8+
#include "util/util.h"
9+
#include <string>
10+
#include <DriverLevelTool/driver_routines/d2_types.h>
11+
12+
//----------------------------------------------------
13+
14+
void CompileMissionBlk(const char* filename)
15+
{
16+
}
17+
18+
void DecompileMissionBlk(const char* filename, int missionNumber)
19+
{
20+
if (missionNumber <= 0) // decompile all
21+
{
22+
23+
}
24+
}
25+
26+
//-----------------------------------------------------
27+
28+
void PrintCommandLineArguments()
29+
{
30+
MsgInfo("Example usage:\n");
31+
MsgInfo("\tDriver2MissionTool -decompile MISSIONS.BLK [mission_number]\n");
32+
MsgInfo("\tDriver2MissionTool -compile <mission_script_name.d2ms>\n");
33+
}
34+
35+
int main(int argc, char** argv)
36+
{
37+
#ifdef _WIN32
38+
Install_ConsoleSpewFunction();
39+
#endif
40+
41+
Msg("---------------\nDriverMissionTool - Driver 2 mission decompiler\n---------------\n\n");
42+
43+
if (argc <= 1)
44+
{
45+
PrintCommandLineArguments();
46+
return -1;
47+
}
48+
49+
for (int i = 0; i < argc; i++)
50+
{
51+
if (!stricmp(argv[i], "-compile"))
52+
{
53+
if (i + 1 <= argc)
54+
CompileMissionBlk(argv[i + 1]);
55+
else
56+
MsgWarning("-compile must have an argument!");
57+
}
58+
else if (!stricmp(argv[i], "-decompile"))
59+
{
60+
if (i + 1 <= argc)
61+
DecompileMissionBlk(argv[i + 1], atoi(argv[i + 2]));
62+
else
63+
MsgWarning("-decompile must have at least one argument!");
64+
}
65+
}
66+
67+
return 0;
68+
}

Driver2MissionTool/premake5.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- premake5.lua
2+
3+
project "Driver2MissionTool"
4+
kind "ConsoleApp"
5+
language "C++"
6+
compileas "C++"
7+
targetdir "bin/%{cfg.buildcfg}"
8+
9+
files {
10+
"**.cpp",
11+
"**.h",
12+
}
13+
14+
filter "system:linux"
15+
buildoptions {
16+
"-Wno-narrowing",
17+
"-fpermissive",
18+
"-m32"
19+
}
20+
21+
linkoptions {
22+
"-m32"
23+
}
24+
25+
filter "configurations:Debug"
26+
targetsuffix "_dbg"
27+
symbols "On"
28+
29+
filter "configurations:Release"
30+
optimize "Full"
31+

DriverLevelTool/driver_level.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "model_compiler/compiler.h"
66
#include "util/util.h"
7+
#include "viewer/viewer.h"
78

89
bool g_export_carmodels = false;
910
bool g_export_models = false;
@@ -133,6 +134,7 @@ void PrintCommandLineArguments()
133134
const char* argumentsMessage =
134135
"Example: DriverLevelTool <command> [arguments]\n\n\n"
135136
" -lev <filename.LEV> \t: Specify level file you want to input\n\n"
137+
" -viewer \t: Enables level file viewer\n\n"
136138
" -format <n> \t: Specify level format. 1 = Driver 1, 2 = Driver 2 Demo (alpha 1.6), 3 = Driver 2 Retail\n\n"
137139
" -textures <1/0> \t: Export textures (TGA)\n\n"
138140
" -models <1/0> \t: Export models (OBJ\n\n"
@@ -162,11 +164,15 @@ int main(int argc, char* argv[])
162164
}
163165

164166
bool generate_denting = false;
165-
bool do_main_routine = true;
167+
int main_routine = 1;
166168

167169
for (int i = 1; i < argc; i++)
168170
{
169-
if (!stricmp(argv[i], "-format"))
171+
if (!stricmp(argv[i], "-viewer"))
172+
{
173+
main_routine = 2;
174+
}
175+
else if (!stricmp(argv[i], "-format"))
170176
{
171177
g_format = (ELevelFormat)atoi(argv[i + 1]);
172178
i++;
@@ -213,7 +219,7 @@ int main(int argc, char* argv[])
213219
else if (!stricmp(argv[i], "-dmodel2obj"))
214220
{
215221
ConvertDModelFileToOBJ(argv[i + 1], argv[i + 2]);
216-
do_main_routine = false;
222+
main_routine = 0;
217223
i += 2;
218224
}
219225
else if (!stricmp(argv[i], "-denting"))
@@ -223,7 +229,7 @@ int main(int argc, char* argv[])
223229
else if (!stricmp(argv[i], "-compiledmodel"))
224230
{
225231
CompileOBJModelToDMODEL(argv[i + 1], argv[i + 2], generate_denting);
226-
do_main_routine = false;
232+
main_routine = 0;
227233
generate_denting = false; // disable denting compiler after it's job done
228234
i += 2;
229235
}
@@ -241,8 +247,10 @@ int main(int argc, char* argv[])
241247
return 0;
242248
}
243249

244-
if(do_main_routine)
250+
if (main_routine == 1)
245251
ProcessLevFile(g_levname.c_str());
252+
else if (main_routine == 2)
253+
ViewerMain(g_levname.c_str());
246254

247255
return 0;
248256
}

DriverLevelTool/driver_level.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
// extern some vars
2323
extern IVirtualStream* g_levStream;
2424

25+
extern CDriverLevelTextures g_levTextures;
26+
extern CDriverLevelModels g_levModels;
27+
extern CBaseLevelMap* g_levMap;
28+
2529
//----------------------------------------------------------
2630

2731
void ExportDMODELToOBJ(MODEL* model, const char* model_name, int model_index, int modelSize);
2832
void WriteMODELToObjStream(IVirtualStream* pStream, MODEL* model, int modelSize, int model_index, const char* name_prefix,
2933
bool debugInfo = true,
3034
const Matrix4x4& translation = identity4(),
31-
int* first_v = NULL,
32-
int* first_t = NULL,
33-
RegionModels_t* regModels = NULL);
35+
int* first_v = nullptr,
36+
int* first_t = nullptr,
37+
RegionModels_t* regModels = nullptr);
3438

3539
//----------------------------------------------------------
3640
// main functions

DriverLevelTool/driver_routines/d2_types.h

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ typedef struct dlevinfo_t
6363
//------------------------------------------------------------------------------------------------------------
6464

6565
struct OUT_CELL_FILE_HEADER {
66-
int cells_across; // size=0, offset=0
67-
int cells_down; // size=0, offset=4
68-
int cell_size; // size=0, offset=8
66+
int cells_across;
67+
int cells_down;
68+
int cell_size;
6969

70-
int num_regions; // size=0, offset=12
71-
int region_size; // size=0, offset=16
70+
int num_regions;
71+
int region_size;
7272

73-
int num_cell_objects; // size=0, offset=20
74-
int num_cell_data; // size=0, offset=24
73+
int num_cell_objects;
74+
int num_cell_data;
7575

76-
int ambient_light_level; // size=0, offset=28
77-
struct VECTOR_NOPAD light_source; // size=12, offset=32
76+
int ambient_light_level;
77+
VECTOR_NOPAD light_source;
7878
};
7979

8080
//------------------------------------------------------------------------------------------------------------
@@ -192,6 +192,7 @@ struct POLYGT4
192192
CVECTOR color;
193193
};
194194

195+
#if 0
195196
enum ModelFlags1 // collision flags?
196197
{
197198
everything = 1,
@@ -231,6 +232,31 @@ enum ModelFlags2 // effect flags?
231232
dontKnow15 = 16384, // ??? again: many sidewalks, some grass
232233
sidewalk = 32768
233234
};
235+
#else
236+
enum ModelShapeFlags
237+
{
238+
SHAPE_FLAG_SMASH_QUIET = 0x8,
239+
SHAPE_FLAG_NOCOLLIDE = 0x10,
240+
SHAPE_FLAG_SUBSURFACE = 0x80, // grass, dirt, water
241+
SHAPE_FLAG_ALLEYWAY = 0x400, // alleyway
242+
SHAPE_FLAG_SMASH_SPRITE = 0x4000,
243+
};
244+
245+
enum ModelFlags2
246+
{
247+
MODEL_FLAG_ANIMOBJ = 0x1,
248+
MODEL_FLAG_MEDIAN = 0x20,
249+
MODEL_FLAG_ALLEY = 0x80,
250+
MODEL_FLAG_HASROOF = 0x100,
251+
MODEL_FLAG_NOCOL_200 = 0x200,
252+
MODEL_FLAG_BARRIER = 0x400,
253+
MODEL_FLAG_SMASHABLE = 0x800,
254+
MODEL_FLAG_LAMP = 0x1000,
255+
MODEL_FLAG_TREE = 0x2000,
256+
MODEL_FLAG_GRASS = 0x4000,
257+
MODEL_FLAG_SIDEWALK = 0x8000,
258+
};
259+
#endif
234260

235261
struct MODEL
236262
{
@@ -259,6 +285,11 @@ struct MODEL
259285
}
260286

261287
SVECTOR* pNormal(int i) const
288+
{
289+
return (SVECTOR*)(((ubyte*)this) + normals) + i;
290+
}
291+
292+
SVECTOR* pPointNormal(int i) const
262293
{
263294
return (SVECTOR *)(((ubyte *)this) + point_normals) + i;
264295
}
@@ -332,4 +363,19 @@ struct Spool {
332363

333364
#define REGION_EMPTY (0xFFFF)
334365

366+
struct PALLET_INFO
367+
{
368+
int palette;
369+
int texnum;
370+
int tpage;
371+
int clut_number;
372+
};
373+
374+
struct PALLET_INFO_D1
375+
{
376+
int palette;
377+
int texnum;
378+
int tpage;
379+
};
380+
335381
#endif

0 commit comments

Comments
 (0)