From 7de81128dfc85f0dafe070d2ab310466f0f9c710 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 12:30:36 +0200 Subject: [PATCH 01/23] testgen: prepare for test generation --- .gitignore | 3 +++ Makefile => MakefileGCC | 0 Source/diablo.cpp | 5 +++++ SourceT/gen_tests.cpp | 6 ++++++ SourceT/gen_tests.h | 6 ++++++ types.h | 2 +- 6 files changed, 21 insertions(+), 1 deletion(-) rename Makefile => MakefileGCC (100%) create mode 100644 SourceT/gen_tests.cpp create mode 100644 SourceT/gen_tests.h diff --git a/.gitignore b/.gitignore index 97e810c1d..fcfdd7fcf 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ devilution-comparer comparer-config.toml +# MPQ archives +*.mpq + # ELF object file. *.o diff --git a/Makefile b/MakefileGCC similarity index 100% rename from Makefile rename to MakefileGCC diff --git a/Source/diablo.cpp b/Source/diablo.cpp index ade09cc6a..bf15bb300 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -7,6 +7,8 @@ #include "../3rdParty/Storm/Source/storm.h" #include "../DiabloUI/diabloui.h" +#include "gen_tests.h" + HWND ghMainWnd; int glMid1Seed[NUMLEVELS]; int glMid2Seed[NUMLEVELS]; @@ -259,6 +261,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi char szFileName[MAX_PATH]; BOOL bNoEvent; + gen_tests(); + return 0; + hInst = hInstance; #ifndef DEBUGGER diablo_reload_process(hInstance); diff --git a/SourceT/gen_tests.cpp b/SourceT/gen_tests.cpp new file mode 100644 index 000000000..39a061840 --- /dev/null +++ b/SourceT/gen_tests.cpp @@ -0,0 +1,6 @@ +#include +#include + +void gen_tests() { + printf("hello world\n"); +} diff --git a/SourceT/gen_tests.h b/SourceT/gen_tests.h new file mode 100644 index 000000000..6ec59f7e5 --- /dev/null +++ b/SourceT/gen_tests.h @@ -0,0 +1,6 @@ +#ifndef __GEN_TESTS_H__ +#define __GEN_TESTS_H__ + +void gen_tests(); + +#endif // #ifndef __GEN_TESTS_H__ diff --git a/types.h b/types.h index 6553268dc..d5129d399 100644 --- a/types.h +++ b/types.h @@ -52,7 +52,7 @@ // If defined, use copy protection [Default -> Defined] #if !defined(_DEBUG) && !defined(SPAWN) -#define COPYPROT +//#define COPYPROT #endif // If defined, don't reload for debuggers [Default -> Undefined] From cb22e7762fb3383702f5966c2b783832fe8b6807 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 12:36:24 +0200 Subject: [PATCH 02/23] testgen: rename MakefileVC to Makefile --- MakefileVC => Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename MakefileVC => Makefile (100%) diff --git a/MakefileVC b/Makefile similarity index 100% rename from MakefileVC rename to Makefile From 3976dfc3152133e323b2d0d20df0fe4e2e7b5f19 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 12:39:58 +0200 Subject: [PATCH 03/23] testgen: add testgen build to Makefile --- Makefile | 10 +++++++--- Source/diablo.cpp | 4 ++-- SourceT/gen_tests.h | 6 ------ SourceT/{gen_tests.cpp => testgen.cpp} | 2 +- SourceT/testgen.h | 6 ++++++ 5 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 SourceT/gen_tests.h rename SourceT/{gen_tests.cpp => testgen.cpp} (78%) create mode 100644 SourceT/testgen.h diff --git a/Makefile b/Makefile index 0c768814a..e59211b7d 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ else endif CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs +CFLAGS+=/I ./SourceT LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no ifeq ($(SPAWN),1) @@ -62,8 +63,11 @@ DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp Source/render. DIABLO_SRC += Source/render.cpp OBJS=$(DIABLO_SRC:.cpp=.obj) -Diablo.exe: main_files diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib - $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib +TESTGEN_SRC=SourceT/testgen.cpp +TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.obj) + +Diablo.exe: main_files $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib + $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib DiabloUI/diabloui.lib: make -C DiabloUI @@ -85,6 +89,6 @@ diablo.res: Diablo.rc $(RC) /i $(VC6_INC_DIR) /l 0x409 /fo $@ $< clean: - @$(RM) -v $(OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch + @$(RM) -v $(OBJS) $(TESTGEN_OBJS) vc60.idb vc60.pdb Diablo.pdb Diablo.pch .PHONY: clean all diff --git a/Source/diablo.cpp b/Source/diablo.cpp index bf15bb300..9e520c237 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -7,7 +7,7 @@ #include "../3rdParty/Storm/Source/storm.h" #include "../DiabloUI/diabloui.h" -#include "gen_tests.h" +#include "testgen.h" HWND ghMainWnd; int glMid1Seed[NUMLEVELS]; @@ -261,7 +261,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi char szFileName[MAX_PATH]; BOOL bNoEvent; - gen_tests(); + testgen(); return 0; hInst = hInstance; diff --git a/SourceT/gen_tests.h b/SourceT/gen_tests.h deleted file mode 100644 index 6ec59f7e5..000000000 --- a/SourceT/gen_tests.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __GEN_TESTS_H__ -#define __GEN_TESTS_H__ - -void gen_tests(); - -#endif // #ifndef __GEN_TESTS_H__ diff --git a/SourceT/gen_tests.cpp b/SourceT/testgen.cpp similarity index 78% rename from SourceT/gen_tests.cpp rename to SourceT/testgen.cpp index 39a061840..ae6ba8eef 100644 --- a/SourceT/gen_tests.cpp +++ b/SourceT/testgen.cpp @@ -1,6 +1,6 @@ #include #include -void gen_tests() { +void testgen() { printf("hello world\n"); } diff --git a/SourceT/testgen.h b/SourceT/testgen.h new file mode 100644 index 000000000..4d3caf77d --- /dev/null +++ b/SourceT/testgen.h @@ -0,0 +1,6 @@ +#ifndef __TESTGEN_H__ +#define __TESTGEN_H__ + +void testgen(); + +#endif // #ifndef __TESTGEN_H__ From 3599bd3bd5849530cb0a87850ebf97a469dc411c Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 14:10:11 +0200 Subject: [PATCH 04/23] testgen: add test case for drlg_l1 Note, SHA1 hash of testdata/tiles_123.bin is correct for input seed 123. 12a0410904ebf2507b6b7017f0ae191ae476686b --- .gitignore | 6 ++++ Makefile | 2 +- MakefileGCC | 7 ++-- SourceT/testgen.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index fcfdd7fcf..526057188 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ # macOS .DS_Store +# Error files. +*.ERR + # CodeLite .CodeLite *.project @@ -18,6 +21,9 @@ comparer-config.toml # MPQ archives *.mpq +# Generated test data. +testdata + # ELF object file. *.o diff --git a/Makefile b/Makefile index e59211b7d..6f12f0840 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ else VC6_LINK = wine $(VC6_BIN_DIR)/link.exe endif -CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs +CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /I Source/ /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs CFLAGS+=/I ./SourceT LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no diff --git a/MakefileGCC b/MakefileGCC index fee594b36..e0c05e221 100644 --- a/MakefileGCC +++ b/MakefileGCC @@ -14,7 +14,7 @@ endif # static_cast(reinterpret_cast(ptr)) # instead of # (NEW_TYPE)(ptr) -CXXFLAGS=-fpermissive -Wno-write-strings +CXXFLAGS=-g -fpermissive -Wno-write-strings -I./Source -I./SourceT CPPFLAGS=-MMD -MF $*.d LDLIBS=-lgdi32 -lversion -ldiabloui -lstorm LDFLAGS=-L./ -static-libgcc -mwindows @@ -28,10 +28,13 @@ debug: devilution.exe DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp, $(wildcard Source/*.cpp))) OBJS=$(DIABLO_SRC:.cpp=.o) +TESTGEN_SRC=SourceT/testgen.cpp +TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.o) + PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp) PKWARE_OBJS=$(PKWARE_SRC:.cpp=.o) -devilution.exe: $(OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib +devilution.exe: $(OBJS) $(TESTGEN_OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib $(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS) diabres.o: Diablo.rc diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index ae6ba8eef..0b35f3209 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -1,6 +1,82 @@ #include #include -void testgen() { - printf("hello world\n"); +#include "diablo.h" + +void write_file(char *path, void *buf, int size); + +// drlg_l1.cpp + +void gen_drlg_l1_tests(void) { + printf("gen_drlg_l1_tests\n"); + + // pre. + BYTE in_dlvl = 1; + BYTE in_dtype = DTYPE_CATHEDRAL; + BYTE in_quest_id = QTYPE_INVALID; + DWORD in_seed = 123; + // extra. + int in_entry = 0; + BYTE in_max_players = 1; // single + + // Load MPQ archives. + init_archives(); + + // Load level graphics. + //*gendung.DType = g.dtype; + leveltype = in_dtype; + //diablo.LoadLevelGraphics(); + LoadLvlGFX(); + + // Establish pre-conditions. + //*gendung.DLvl = g.dlvl; + currlevel = in_dlvl; + //*multi.MaxPlayers = 1; + gbMaxPlayers = in_max_players; + //for i := range quests.Quests { + // quests.Quests[i].ID = quests.QuestID(i); + // quests.Quests[i].Active = false; + //} + for (int quest_id = 0; quest_id < MAXQUESTS; quest_id++) { + quests[quest_id]._qtype = quest_id; + quests[quest_id]._qactive = false; + } + //*gendung.IsQuestLevel = false; + setlevel = false; + //if g.questID != quests.Invalid { + // quests.Quests[g.questID].Active = true; + // quests.Quests[g.questID].DLvl = g.dlvl; + //} + if (in_quest_id != QTYPE_INVALID) { + quests[in_quest_id]._qlevel = in_dlvl; + quests[in_quest_id]._qactive = true; + } + + // Generate dungeon based on the given seed. + //l1.CreateDungeon(g.seed, 0); + + CreateL5Dungeon(in_seed, in_entry); + + char path[MAX_PATH]; + sprintf(path, "testdata/tiles_%d.bin", in_seed); + write_file(path, dungeon, sizeof(dungeon)); +} + +void testgen() +{ + printf("testgen\n"); + gen_drlg_l1_tests(); +} + +void write_file(char *path, void *buf, int size) { + FILE *f = fopen(path, "wb"); + if (f == NULL) { + fprintf(stderr, "unable to create file %s", path); + exit(1); + } + if (fwrite(buf, 1, size, f) != size) { + fprintf(stderr, "unable to write to file %s", path); + exit(1); + } + fclose(f); } From 2e590037032e0cd8a58c9b37d11da263c0db5476 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 14:20:14 +0200 Subject: [PATCH 05/23] testgen: dump test data for dungeon pieces, arches and transparency of drlg_l1 --- SourceT/testgen.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 0b35f3209..c7521cc75 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -57,9 +57,26 @@ void gen_drlg_l1_tests(void) { CreateL5Dungeon(in_seed, in_entry); - char path[MAX_PATH]; - sprintf(path, "testdata/tiles_%d.bin", in_seed); - write_file(path, dungeon, sizeof(dungeon)); + // Dump pre-dungeon tiles. + char output_path[MAX_PATH]; + //sprintf(output_path, "testdata/pre-tiles_%d.bin", in_seed); + //write_file(output_path, pdungeon, sizeof(pdungeon)); + + // Dump tiles. + sprintf(output_path, "testdata/tiles_%d.bin", in_seed); + write_file(output_path, dungeon, sizeof(dungeon)); + + // Dungeon dungeon pieces. + sprintf(output_path, "testdata/dpieces_%d.bin", in_seed); + write_file(output_path, dPiece, sizeof(dPiece)); + + // Dungeon arches. + sprintf(output_path, "testdata/arches_%d.bin", in_seed); + write_file(output_path, dArch, sizeof(dArch)); + + // Dungeon transparency. + sprintf(output_path, "testdata/transparency_%d.bin", in_seed); + write_file(output_path, dTransVal, sizeof(dTransVal)); } void testgen() From 26d2addb8f0fc6cf5f21d2d24aca4536e4f5082d Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 15:30:09 +0200 Subject: [PATCH 06/23] testgen: add table for test cases --- SourceT/testgen.cpp | 138 +++++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 59 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index c7521cc75..4dbf9ff90 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -10,11 +10,27 @@ void write_file(char *path, void *buf, int size); void gen_drlg_l1_tests(void) { printf("gen_drlg_l1_tests\n"); - // pre. - BYTE in_dlvl = 1; - BYTE in_dtype = DTYPE_CATHEDRAL; - BYTE in_quest_id = QTYPE_INVALID; - DWORD in_seed = 123; + typedef struct { + // meta. + char *dungeon_name; + // pre. + BYTE dlvl; + BYTE dtype; + BYTE quest_id; + DWORD seed; + } Golden; + + // Golden test cases. + Golden golden[] = { + { + "Cathedral", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_INVALID, // quest_id + 123 // seed + } + }; + // extra. int in_entry = 0; BYTE in_max_players = 1; // single @@ -22,61 +38,65 @@ void gen_drlg_l1_tests(void) { // Load MPQ archives. init_archives(); - // Load level graphics. - //*gendung.DType = g.dtype; - leveltype = in_dtype; - //diablo.LoadLevelGraphics(); - LoadLvlGFX(); - - // Establish pre-conditions. - //*gendung.DLvl = g.dlvl; - currlevel = in_dlvl; - //*multi.MaxPlayers = 1; - gbMaxPlayers = in_max_players; - //for i := range quests.Quests { - // quests.Quests[i].ID = quests.QuestID(i); - // quests.Quests[i].Active = false; - //} - for (int quest_id = 0; quest_id < MAXQUESTS; quest_id++) { - quests[quest_id]._qtype = quest_id; - quests[quest_id]._qactive = false; - } - //*gendung.IsQuestLevel = false; - setlevel = false; - //if g.questID != quests.Invalid { - // quests.Quests[g.questID].Active = true; - // quests.Quests[g.questID].DLvl = g.dlvl; - //} - if (in_quest_id != QTYPE_INVALID) { - quests[in_quest_id]._qlevel = in_dlvl; - quests[in_quest_id]._qactive = true; + for (int i = 0; i < sizeof(golden)/sizeof(Golden); i++) { + Golden g = golden[i]; + + // Load level graphics. + //*gendung.DType = g.dtype; + leveltype = g.dtype; + //diablo.LoadLevelGraphics(); + LoadLvlGFX(); + + // Establish pre-conditions. + //*gendung.DLvl = g.dlvl; + currlevel = g.dlvl; + //*multi.MaxPlayers = 1; + gbMaxPlayers = in_max_players; + //for i := range quests.Quests { + // quests.Quests[i].ID = quests.QuestID(i); + // quests.Quests[i].Active = false; + //} + for (int quest_id = 0; quest_id < MAXQUESTS; quest_id++) { + quests[quest_id]._qtype = quest_id; + quests[quest_id]._qactive = false; + } + //*gendung.IsQuestLevel = false; + setlevel = false; + //if g.questID != quests.Invalid { + // quests.Quests[g.questID].Active = true; + // quests.Quests[g.questID].DLvl = g.dlvl; + //} + if (g.quest_id != QTYPE_INVALID) { + quests[g.quest_id]._qlevel = g.dlvl; + quests[g.quest_id]._qactive = true; + } + + // Generate dungeon based on the given seed. + //l1.CreateDungeon(g.seed, 0); + + CreateL5Dungeon(g.seed, in_entry); + + // Dump pre-dungeon tiles. + char output_path[MAX_PATH]; + //sprintf(output_path, "testdata/pre-tiles_%d.bin", g.seed); + //write_file(output_path, pdungeon, sizeof(pdungeon)); + + // Dump tiles. + sprintf(output_path, "testdata/tiles_%d.bin", g.seed); + write_file(output_path, dungeon, sizeof(dungeon)); + + // Dungeon dungeon pieces. + sprintf(output_path, "testdata/dpieces_%d.bin", g.seed); + write_file(output_path, dPiece, sizeof(dPiece)); + + // Dungeon arches. + sprintf(output_path, "testdata/arches_%d.bin", g.seed); + write_file(output_path, dArch, sizeof(dArch)); + + // Dungeon transparency. + sprintf(output_path, "testdata/transparency_%d.bin", g.seed); + write_file(output_path, dTransVal, sizeof(dTransVal)); } - - // Generate dungeon based on the given seed. - //l1.CreateDungeon(g.seed, 0); - - CreateL5Dungeon(in_seed, in_entry); - - // Dump pre-dungeon tiles. - char output_path[MAX_PATH]; - //sprintf(output_path, "testdata/pre-tiles_%d.bin", in_seed); - //write_file(output_path, pdungeon, sizeof(pdungeon)); - - // Dump tiles. - sprintf(output_path, "testdata/tiles_%d.bin", in_seed); - write_file(output_path, dungeon, sizeof(dungeon)); - - // Dungeon dungeon pieces. - sprintf(output_path, "testdata/dpieces_%d.bin", in_seed); - write_file(output_path, dPiece, sizeof(dPiece)); - - // Dungeon arches. - sprintf(output_path, "testdata/arches_%d.bin", in_seed); - write_file(output_path, dArch, sizeof(dArch)); - - // Dungeon transparency. - sprintf(output_path, "testdata/transparency_%d.bin", in_seed); - write_file(output_path, dTransVal, sizeof(dTransVal)); } void testgen() From dde50c3ef8a20a9ae5384db5a3eec29763b87b0a Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 16:07:58 +0200 Subject: [PATCH 07/23] testgen: add more test cases for drlg_l1 --- SourceT/testgen.cpp | 73 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 4dbf9ff90..e56c37f98 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -7,7 +7,8 @@ void write_file(char *path, void *buf, int size); // drlg_l1.cpp -void gen_drlg_l1_tests(void) { +void gen_drlg_l1_tests(void) +{ printf("gen_drlg_l1_tests\n"); typedef struct { @@ -23,29 +24,66 @@ void gen_drlg_l1_tests(void) { // Golden test cases. Golden golden[] = { { - "Cathedral", // dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_INVALID, // quest_id - 123 // seed - } + "Cathedral", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_INVALID, // quest_id + 123, // seed + }, + { + "Cathedral (fix corners)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_INVALID, // quest_id + 35, // seed + }, + { + "The Butcher", // dungeon_name + questlist[QTYPE_BUTCH]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_BUTCH, // quest_id + 123, // seed + }, + { + "Poisoned Water Supply", // dungeon_name + questlist[QTYPE_PW]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_PW, // quest_id + 123, // seed + }, + { + "Ogden's Sign", // dungeon_name + questlist[QTYPE_BOL]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_BOL, // quest_id + 123, // seed + }, }; // extra. - int in_entry = 0; + int in_entry = 0; BYTE in_max_players = 1; // single // Load MPQ archives. init_archives(); - for (int i = 0; i < sizeof(golden)/sizeof(Golden); i++) { + // Load level graphics. + //diablo.LoadLevelGraphics(); + leveltype = DTYPE_CATHEDRAL; + LoadLvlGFX(); // TODO: only load level graphics once per dtype. + + for (int i = 0; i < sizeof(golden) / sizeof(Golden); i++) { Golden g = golden[i]; - // Load level graphics. + // Reset globals. + memset(pdungeon, 0, sizeof(pdungeon)); + memset(dungeon, 0, sizeof(dungeon)); + memset(dPiece, 0, sizeof(dPiece)); + memset(dArch, 0, sizeof(dArch)); + memset(dTransVal, 0, sizeof(dTransVal)); + //*gendung.DType = g.dtype; leveltype = g.dtype; - //diablo.LoadLevelGraphics(); - LoadLvlGFX(); // Establish pre-conditions. //*gendung.DLvl = g.dlvl; @@ -82,19 +120,19 @@ void gen_drlg_l1_tests(void) { //write_file(output_path, pdungeon, sizeof(pdungeon)); // Dump tiles. - sprintf(output_path, "testdata/tiles_%d.bin", g.seed); + sprintf(output_path, "testdata/tiles_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); write_file(output_path, dungeon, sizeof(dungeon)); // Dungeon dungeon pieces. - sprintf(output_path, "testdata/dpieces_%d.bin", g.seed); + sprintf(output_path, "testdata/dpieces_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); write_file(output_path, dPiece, sizeof(dPiece)); // Dungeon arches. - sprintf(output_path, "testdata/arches_%d.bin", g.seed); + sprintf(output_path, "testdata/arches_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); write_file(output_path, dArch, sizeof(dArch)); // Dungeon transparency. - sprintf(output_path, "testdata/transparency_%d.bin", g.seed); + sprintf(output_path, "testdata/transparency_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); write_file(output_path, dTransVal, sizeof(dTransVal)); } } @@ -105,7 +143,8 @@ void testgen() gen_drlg_l1_tests(); } -void write_file(char *path, void *buf, int size) { +void write_file(char *path, void *buf, int size) +{ FILE *f = fopen(path, "wb"); if (f == NULL) { fprintf(stderr, "unable to create file %s", path); From 5d0e48d71de716fa0f480568831055911fc8b684 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 21:18:27 +0200 Subject: [PATCH 08/23] move Makefile back to MakefileVC --- Makefile => MakefileVC | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Makefile => MakefileVC (100%) diff --git a/Makefile b/MakefileVC similarity index 100% rename from Makefile rename to MakefileVC From 3545d9d46c198ac5aa009ac4f0bcecf6e4ec5f16 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 21:18:42 +0200 Subject: [PATCH 09/23] move MakefileGCC back to Makefile --- MakefileGCC => Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename MakefileGCC => Makefile (100%) diff --git a/MakefileGCC b/Makefile similarity index 100% rename from MakefileGCC rename to Makefile From 8bf78a9d776d7067a9f7829ab2fed1bf18d34f0e Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 21:38:34 +0200 Subject: [PATCH 10/23] testgen: add TESTGEN define to use WinMain of SourceT/main.cpp --- Makefile | 8 +++++++- MakefileVC | 10 ++++++++-- Source/diablo.cpp | 7 ++----- SourceT/main.cpp | 9 +++++++++ SourceT/testgen.cpp | 2 +- gen_tests.sh | 8 ++++++++ 6 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 SourceT/main.cpp create mode 100755 gen_tests.sh diff --git a/Makefile b/Makefile index e0c05e221..624142880 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ LDFLAGS=-L./ -static-libgcc -mwindows all: devilution.exe +testgen: CXXFLAGS += -DTESTGEN -Wno-narrowing +testgen: testgen.exe + debug: CXXFLAGS += -D_DEBUG debug: CPPFLAGS += -D_DEBUG debug: devilution.exe @@ -34,7 +37,10 @@ TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.o) PKWARE_SRC=$(wildcard 3rdParty/PKWare/*.cpp) PKWARE_OBJS=$(PKWARE_SRC:.cpp=.o) -devilution.exe: $(OBJS) $(TESTGEN_OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib +devilution.exe: $(OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib + $(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS) + +testgen.exe: $(OBJS) $(TESTGEN_OBJS) $(PKWARE_OBJS) diabres.o diabloui.lib storm.lib $(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS) diabres.o: Diablo.rc diff --git a/MakefileVC b/MakefileVC index 6f12f0840..53efdc58f 100644 --- a/MakefileVC +++ b/MakefileVC @@ -55,6 +55,9 @@ endif all: Diablo.exe +testgen: CFLAGS += /D "TESTGEN" +testgen: testgen.exe + debug: CFLAGS += /D "_DEBUG" debug: Diablo.exe @@ -63,10 +66,13 @@ DIABLO_SRC=$(sort $(filter-out Source/_asm.cpp Source/_render.cpp Source/render. DIABLO_SRC += Source/render.cpp OBJS=$(DIABLO_SRC:.cpp=.obj) -TESTGEN_SRC=SourceT/testgen.cpp +TESTGEN_SRC=$(sort $(wildcard SourceT/*.cpp)) TESTGEN_OBJS=$(TESTGEN_SRC:.cpp=.obj) -Diablo.exe: main_files $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib +Diablo.exe: main_files diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib + $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib + +testgen.exe: main_files $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib 3rdParty/PKWare/pkware.lib $(VC_LINK) /OUT:$@ $(LINKFLAGS) $(OBJS) $(TESTGEN_OBJS) diablo.res DiabloUI/diabloui.lib 3rdParty/Storm/storm.lib kernel32.lib user32.lib gdi32.lib advapi32.lib shell32.lib version.lib 3rdParty/PKWare/pkware.lib DiabloUI/diabloui.lib: diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 9e520c237..a7aeee644 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -7,8 +7,6 @@ #include "../3rdParty/Storm/Source/storm.h" #include "../DiabloUI/diabloui.h" -#include "testgen.h" - HWND ghMainWnd; int glMid1Seed[NUMLEVELS]; int glMid2Seed[NUMLEVELS]; @@ -254,6 +252,7 @@ BOOL diablo_get_not_running() * @param lpCmdLine The command line for the application * @param nCmdShow Initial window state */ +#ifndef TESTGEN int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HINSTANCE hInst; @@ -261,9 +260,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi char szFileName[MAX_PATH]; BOOL bNoEvent; - testgen(); - return 0; - hInst = hInstance; #ifndef DEBUGGER diablo_reload_process(hInstance); @@ -334,6 +330,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi return FALSE; } +#endif void diablo_parse_flags(char *args) { diff --git a/SourceT/main.cpp b/SourceT/main.cpp new file mode 100644 index 000000000..b3155d297 --- /dev/null +++ b/SourceT/main.cpp @@ -0,0 +1,9 @@ +#include "testgen.h" + +#include "diablo.h" + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + ghInst = hInstance; + testgen(); + return 0; +} diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index e56c37f98..db8e81211 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -75,7 +75,7 @@ void gen_drlg_l1_tests(void) for (int i = 0; i < sizeof(golden) / sizeof(Golden); i++) { Golden g = golden[i]; - // Reset globals. + // Reset globals (not needed). memset(pdungeon, 0, sizeof(pdungeon)); memset(dungeon, 0, sizeof(dungeon)); memset(dPiece, 0, sizeof(dPiece)); diff --git a/gen_tests.sh b/gen_tests.sh new file mode 100755 index 000000000..e2efc551a --- /dev/null +++ b/gen_tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "Building testgen.exe" +make -f MakefileVC testgen + +echo "Writing test cases to testdata/" +mkdir -p testdata +wine testgen.exe From e41b800e58aa361bb449cb3c07747bdeb8e70f2b Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 21:45:07 +0200 Subject: [PATCH 11/23] testgen: use TESTGEN to handle testgen.exe specific changes --- Makefile | 4 ++-- MakefileVC | 5 ++--- types.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 624142880..82c07fa93 100644 --- a/Makefile +++ b/Makefile @@ -14,14 +14,14 @@ endif # static_cast(reinterpret_cast(ptr)) # instead of # (NEW_TYPE)(ptr) -CXXFLAGS=-g -fpermissive -Wno-write-strings -I./Source -I./SourceT +CXXFLAGS=-fpermissive -Wno-write-strings CPPFLAGS=-MMD -MF $*.d LDLIBS=-lgdi32 -lversion -ldiabloui -lstorm LDFLAGS=-L./ -static-libgcc -mwindows all: devilution.exe -testgen: CXXFLAGS += -DTESTGEN -Wno-narrowing +testgen: CXXFLAGS += -DTESTGEN -I./SourceT -Wno-narrowing testgen: testgen.exe debug: CXXFLAGS += -D_DEBUG diff --git a/MakefileVC b/MakefileVC index 53efdc58f..c008ab29a 100644 --- a/MakefileVC +++ b/MakefileVC @@ -37,8 +37,7 @@ else VC6_LINK = wine $(VC6_BIN_DIR)/link.exe endif -CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /I Source/ /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs -CFLAGS+=/I ./SourceT +CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /Gr /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fp"Diablo.pch" /YX /Gm /Zi /FAs LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no ifeq ($(SPAWN),1) @@ -55,7 +54,7 @@ endif all: Diablo.exe -testgen: CFLAGS += /D "TESTGEN" +testgen: CFLAGS += /D "TESTGEN" /I ./Source /I ./SourceT testgen: testgen.exe debug: CFLAGS += /D "_DEBUG" diff --git a/types.h b/types.h index d5129d399..b5a69d400 100644 --- a/types.h +++ b/types.h @@ -51,8 +51,8 @@ #endif // If defined, use copy protection [Default -> Defined] -#if !defined(_DEBUG) && !defined(SPAWN) -//#define COPYPROT +#if !defined(_DEBUG) && !defined(SPAWN) && !defined(TESTGEN) +#define COPYPROT #endif // If defined, don't reload for debuggers [Default -> Undefined] From 8f30306f4544d3b1c7221d1bbdbc75b85604da1e Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Sat, 12 Oct 2019 21:46:59 +0200 Subject: [PATCH 12/23] clean testgen objects --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82c07fa93..08e1be4f6 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,6 @@ storm.dll: # $(error Please copy storm.dll (version 1.09[b]) here) clean: - @$(RM) -v $(OBJS) $(OBJS:.o=.d) $(PKWARE_OBJS) $(PKWARE_OBJS:.o=d) diabres.o storm.lib diabloui.lib devilution.exe + @$(RM) -v $(OBJS) $(TESTGEN_OBJS) $(OBJS:.o=.d) $(PKWARE_OBJS) $(PKWARE_OBJS:.o=d) diabres.o storm.lib diabloui.lib devilution.exe .PHONY: clean all From 55ecd405ee60a13d6fa9d666f6d3694090141199 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Mon, 23 Mar 2020 23:44:14 +0100 Subject: [PATCH 13/23] testgen: add test case for Skeleton King's Lair --- SourceT/testgen.cpp | 92 +++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index db8e81211..b981fa1eb 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -7,8 +7,7 @@ void write_file(char *path, void *buf, int size); // drlg_l1.cpp -void gen_drlg_l1_tests(void) -{ +void gen_drlg_l1_tests(void) { printf("gen_drlg_l1_tests\n"); typedef struct { @@ -19,44 +18,58 @@ void gen_drlg_l1_tests(void) BYTE dtype; BYTE quest_id; DWORD seed; + BYTE setlvl; } Golden; // Golden test cases. Golden golden[] = { { - "Cathedral", // dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_INVALID, // quest_id - 123, // seed + "Cathedral", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_INVALID, // quest_id + 123, // seed + 0, // setlvl }, { - "Cathedral (fix corners)", // dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_INVALID, // quest_id - 35, // seed + "Cathedral (fix corners)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_INVALID, // quest_id + 35, // seed + 0, // setlvl }, { - "The Butcher", // dungeon_name - questlist[QTYPE_BUTCH]._qdlvl, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_BUTCH, // quest_id - 123, // seed + "The Butcher", // dungeon_name + questlist[QTYPE_BUTCH]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_BUTCH, // quest_id + 123, // seed + 0, // setlvl }, { - "Poisoned Water Supply", // dungeon_name - questlist[QTYPE_PW]._qdlvl, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_PW, // quest_id - 123, // seed + "Poisoned Water Supply", // dungeon_name + questlist[QTYPE_PW]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_PW, // quest_id + 123, // seed + 0, // setlvl }, { - "Ogden's Sign", // dungeon_name - questlist[QTYPE_BOL]._qdlvl, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_BOL, // quest_id - 123, // seed + "Ogden's Sign", // dungeon_name + questlist[QTYPE_BOL]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_BOL, // quest_id + 123, // seed + 0, // setlvl + }, + { + "Skeleton King's Lair", // dungeon_name + questlist[QTYPE_KING]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + QTYPE_KING, // quest_id + 123, // seed + SL_SKELKING, // setlvl }, }; @@ -99,7 +112,12 @@ void gen_drlg_l1_tests(void) quests[quest_id]._qactive = false; } //*gendung.IsQuestLevel = false; - setlevel = false; + if (g.setlvl != 0) { + setlevel = true; + setlvlnum = g.setlvl; + } else { + setlevel = false; + } //if g.questID != quests.Invalid { // quests.Quests[g.questID].Active = true; // quests.Quests[g.questID].DLvl = g.dlvl; @@ -120,31 +138,33 @@ void gen_drlg_l1_tests(void) //write_file(output_path, pdungeon, sizeof(pdungeon)); // Dump tiles. - sprintf(output_path, "testdata/tiles_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); + sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_tiles.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); + printf("creating '%s'\n", output_path); write_file(output_path, dungeon, sizeof(dungeon)); // Dungeon dungeon pieces. - sprintf(output_path, "testdata/dpieces_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); + sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_dpieces.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); + printf("creating '%s'\n", output_path); write_file(output_path, dPiece, sizeof(dPiece)); // Dungeon arches. - sprintf(output_path, "testdata/arches_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); + sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_arches.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); + printf("creating '%s'\n", output_path); write_file(output_path, dArch, sizeof(dArch)); // Dungeon transparency. - sprintf(output_path, "testdata/transparency_dlvl=%d,quest_id=%d,seed=%d.bin", g.dlvl, g.quest_id, g.seed); + sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_transparency.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); + printf("creating '%s'\n", output_path); write_file(output_path, dTransVal, sizeof(dTransVal)); } } -void testgen() -{ +void testgen() { printf("testgen\n"); gen_drlg_l1_tests(); } -void write_file(char *path, void *buf, int size) -{ +void write_file(char *path, void *buf, int size) { FILE *f = fopen(path, "wb"); if (f == NULL) { fprintf(stderr, "unable to create file %s", path); From 3eeba0b14bd0e5ad9f79b2888bb630c7407dd1d3 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Mon, 23 Mar 2020 23:57:47 +0100 Subject: [PATCH 14/23] testgen: fix build after rebasing on master --- SourceT/main.cpp | 2 +- SourceT/testgen.cpp | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/SourceT/main.cpp b/SourceT/main.cpp index b3155d297..1e3e4d88c 100644 --- a/SourceT/main.cpp +++ b/SourceT/main.cpp @@ -1,6 +1,6 @@ #include "testgen.h" -#include "diablo.h" +#include "all.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ghInst = hInstance; diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index b981fa1eb..ba4b5ca10 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -1,12 +1,14 @@ #include #include -#include "diablo.h" +#include "all.h" void write_file(char *path, void *buf, int size); // drlg_l1.cpp +#define Q_INVALID -1 + void gen_drlg_l1_tests(void) { printf("gen_drlg_l1_tests\n"); @@ -27,7 +29,7 @@ void gen_drlg_l1_tests(void) { "Cathedral", // dungeon_name 1, // dlvl DTYPE_CATHEDRAL, // dtype - QTYPE_INVALID, // quest_id + Q_INVALID, // quest_id 123, // seed 0, // setlvl }, @@ -35,39 +37,39 @@ void gen_drlg_l1_tests(void) { "Cathedral (fix corners)", // dungeon_name 1, // dlvl DTYPE_CATHEDRAL, // dtype - QTYPE_INVALID, // quest_id + Q_INVALID, // quest_id 35, // seed 0, // setlvl }, { "The Butcher", // dungeon_name - questlist[QTYPE_BUTCH]._qdlvl, // dlvl + questlist[Q_BUTCHER]._qdlvl, // dlvl DTYPE_CATHEDRAL, // dtype - QTYPE_BUTCH, // quest_id + Q_BUTCHER, // quest_id 123, // seed 0, // setlvl }, { "Poisoned Water Supply", // dungeon_name - questlist[QTYPE_PW]._qdlvl, // dlvl + questlist[Q_PWATER]._qdlvl, // dlvl DTYPE_CATHEDRAL, // dtype - QTYPE_PW, // quest_id + Q_PWATER, // quest_id 123, // seed 0, // setlvl }, { - "Ogden's Sign", // dungeon_name - questlist[QTYPE_BOL]._qdlvl, // dlvl - DTYPE_CATHEDRAL, // dtype - QTYPE_BOL, // quest_id - 123, // seed - 0, // setlvl + "Ogden's Sign", // dungeon_name + questlist[Q_LTBANNER]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_LTBANNER, // quest_id + 123, // seed + 0, // setlvl }, { "Skeleton King's Lair", // dungeon_name - questlist[QTYPE_KING]._qdlvl, // dlvl + questlist[Q_SKELKING]._qdlvl, // dlvl DTYPE_CATHEDRAL, // dtype - QTYPE_KING, // quest_id + Q_SKELKING, // quest_id 123, // seed SL_SKELKING, // setlvl }, @@ -92,7 +94,7 @@ void gen_drlg_l1_tests(void) { memset(pdungeon, 0, sizeof(pdungeon)); memset(dungeon, 0, sizeof(dungeon)); memset(dPiece, 0, sizeof(dPiece)); - memset(dArch, 0, sizeof(dArch)); + memset(dSpecial, 0, sizeof(dSpecial)); memset(dTransVal, 0, sizeof(dTransVal)); //*gendung.DType = g.dtype; @@ -122,7 +124,7 @@ void gen_drlg_l1_tests(void) { // quests.Quests[g.questID].Active = true; // quests.Quests[g.questID].DLvl = g.dlvl; //} - if (g.quest_id != QTYPE_INVALID) { + if (g.quest_id != Q_INVALID) { quests[g.quest_id]._qlevel = g.dlvl; quests[g.quest_id]._qactive = true; } @@ -150,7 +152,7 @@ void gen_drlg_l1_tests(void) { // Dungeon arches. sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_arches.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); printf("creating '%s'\n", output_path); - write_file(output_path, dArch, sizeof(dArch)); + write_file(output_path, dSpecial, sizeof(dSpecial)); // Dungeon transparency. sprintf(output_path, "testdata/dlvl=%d,quest_id=%d,seed=%d,setlvl=%d_transparency.bin", g.dlvl, g.quest_id, g.seed, g.setlvl); From e2e688ea8b8f97ed92780b19e48bcc6536e74cb2 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 24 Mar 2020 00:05:32 +0100 Subject: [PATCH 15/23] testgen: set setlvlnum to zero when not in a set level --- SourceT/testgen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index ba4b5ca10..573b683d6 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -119,6 +119,7 @@ void gen_drlg_l1_tests(void) { setlvlnum = g.setlvl; } else { setlevel = false; + setlvlnum = 0; // none } //if g.questID != quests.Invalid { // quests.Quests[g.questID].Active = true; From cbe5638706892b64eef21d9b898c070d0815fd5a Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 24 Mar 2020 00:47:01 +0100 Subject: [PATCH 16/23] testgen: add broken seed 7281 This seed generates a dungeon with an opening into nothing at the end of the map. --- SourceT/testgen.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 573b683d6..2af2092c0 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -33,6 +33,14 @@ void gen_drlg_l1_tests(void) { 123, // seed 0, // setlvl }, + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 7281, // seed + 0, // setlvl + }, { "Cathedral (fix corners)", // dungeon_name 1, // dlvl From adcdb4531fa8b02ae65a0b9fb0f03bd0f831f20c Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Tue, 24 Mar 2020 00:48:16 +0100 Subject: [PATCH 17/23] cmd/viewdun: add viewdun tool to convert TILES.BIN to DUN Also, add dump_dun.sh script to convert DUN file to TMX format. --- cmd/viewdun/main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++ dump_dun.sh | 12 +++++++++ 2 files changed, 71 insertions(+) create mode 100644 cmd/viewdun/main.go create mode 100755 dump_dun.sh diff --git a/cmd/viewdun/main.go b/cmd/viewdun/main.go new file mode 100644 index 000000000..71eed095a --- /dev/null +++ b/cmd/viewdun/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "bytes" + "encoding/binary" + "flag" + "io/ioutil" + "log" + + "github.com/pkg/errors" +) + +func main() { + flag.Parse() + for _, tileIDBinPath := range flag.Args() { + tileIDMap, err := genDun(tileIDBinPath) + if err != nil { + log.Fatalf("%+v", err) + } + dunPath := tileIDBinPath + ".dun" + if err := dumpDun(dunPath, tileIDMap); err != nil { + log.Fatalf("%+v", err) + } + } +} + +func genDun(tileIDBinPath string) (*[40][40]uint8, error) { + buf, err := ioutil.ReadFile(tileIDBinPath) + if err != nil { + return nil, errors.WithStack(err) + } + r := bytes.NewReader(buf) + tileIDMap := new([40][40]byte) + if err := binary.Read(r, binary.LittleEndian, tileIDMap); err != nil { + return nil, errors.WithStack(err) + } + return tileIDMap, nil +} + +func dumpDun(dunPath string, tileIDMap *[40][40]uint8) error { + const ( + width = 40 + height = 40 + ) + buf := make([]uint16, 0) + buf = append(buf, width) + buf = append(buf, height) + for y := 0; y < 40; y++ { + for x := 0; x < 40; x++ { + buf = append(buf, uint16(tileIDMap[x][y])) + } + } + b := &bytes.Buffer{} + binary.Write(b, binary.LittleEndian, buf) + if err := ioutil.WriteFile(dunPath, b.Bytes(), 0644); err != nil { + return errors.WithStack(err) + } + return nil +} diff --git a/dump_dun.sh b/dump_dun.sh new file mode 100755 index 000000000..160a8b6fe --- /dev/null +++ b/dump_dun.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +TILES_BIN_NAME=dlvl=1,quest_id=255,seed=7281,setlvl=0_tiles.bin +TILES_BIN_PATH=testdata/${TILES_BIN_NAME} +DUN_NAME=${TILES_BIN_NAME/.bin/.bin.dun} +DUN_FROM=testdata/${DUN_NAME} +DUN_TO=testdata/levels/l1data/${DUN_NAME} + +./cmd/viewdun/viewdun ${TILES_BIN_PATH} +mkdir -p testdata/levels/l1data +mv ${DUN_FROM} ${DUN_TO} +dun_dump ${DUN_TO} From 4a463fcbf1b39566d712c391b0d4dd829f3e7f18 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 15:42:35 +0100 Subject: [PATCH 18/23] d1/l1: add test case for entrance to Skeleton King's Lair In other words, this test case checks that "Levels/L1Data/SKngDO.DUN" is loaded correctly on dungeon level 3. This raises test case coverage of d1/l1 from 88.3% to 88.6%. --- SourceT/testgen.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 2af2092c0..eeb7514d1 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -7,6 +7,7 @@ void write_file(char *path, void *buf, int size); // drlg_l1.cpp +#define SL_NONE 0 #define Q_INVALID -1 void gen_drlg_l1_tests(void) { @@ -31,7 +32,7 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_INVALID, // quest_id 123, // seed - 0, // setlvl + SL_NONE, // setlvl }, { "Cathedral (broken seed)",// dungeon_name @@ -39,7 +40,7 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_INVALID, // quest_id 7281, // seed - 0, // setlvl + SL_NONE, // setlvl }, { "Cathedral (fix corners)", // dungeon_name @@ -47,7 +48,7 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_INVALID, // quest_id 35, // seed - 0, // setlvl + SL_NONE, // setlvl }, { "The Butcher", // dungeon_name @@ -55,7 +56,7 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_BUTCHER, // quest_id 123, // seed - 0, // setlvl + SL_NONE, // setlvl }, { "Poisoned Water Supply", // dungeon_name @@ -63,7 +64,7 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_PWATER, // quest_id 123, // seed - 0, // setlvl + SL_NONE, // setlvl }, { "Ogden's Sign", // dungeon_name @@ -71,7 +72,15 @@ void gen_drlg_l1_tests(void) { DTYPE_CATHEDRAL, // dtype Q_LTBANNER, // quest_id 123, // seed - 0, // setlvl + SL_NONE, // setlvl + }, + { + "Skeleton King's Lair (entrance)", // dungeon_name + questlist[Q_SKELKING]._qdlvl, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_SKELKING, // quest_id + 123, // seed + SL_NONE, // setlvl }, { "Skeleton King's Lair", // dungeon_name From 02c214f0c2a63f7f12f3ffb3d0b4d6c867c158a0 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 16:45:17 +0100 Subject: [PATCH 19/23] testgen: replace dump_dun.sh script with equivalent Makefile This helps track when TMX maps need to be regenerated based on time stmaps. --- MakefileTestgen | 29 +++++++++++++++++++++++++++++ dump_dun.sh | 12 ------------ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 MakefileTestgen delete mode 100755 dump_dun.sh diff --git a/MakefileTestgen b/MakefileTestgen new file mode 100644 index 000000000..3491bda96 --- /dev/null +++ b/MakefileTestgen @@ -0,0 +1,29 @@ +#TILES_BIN_NAME=dlvl=3,quest_id=12,seed=123,setlvl=0_tiles.bin +#TILES_BIN_PATH=testdata/${TILES_BIN_NAME} +#DUN_NAME=${TILES_BIN_NAME/.bin/.bin.dun} +#DUN_FROM=testdata/${DUN_NAME} +#DUN_TO=testdata/levels/l1data/${DUN_NAME} + +TILES_BIN=$(wildcard testdata/*_tiles.bin) +DUN_FROM=$(TILES_BIN:.bin=.bin.dun) +DUN_TO=$(subst testdata/,testdata/levels/l1data/,$(DUN_FROM)) + +all: $(DUN_TO) _dump_/_tilesets_ + +testdata/%.bin.dun: testdata/%.bin + ./cmd/viewdun/viewdun $< + +testdata/levels/l1data/%.bin.dun: testdata/%.bin.dun + mkdir -p testdata/levels/l1data + mv $< $@ + dun_dump -tilesets=false $@ + +_dump_/_tilesets_: + @echo "This step creates the tilesets and parses a dummy DUN file. It is expected to fail as the dummy file does not exist." + dun_dump -tilesets=true dummy + +clean: + $(RM) -v $(DUN_TO) + $(RM) -v $(DUN_FROM) + $(RM) -r -v _dump_/_tilesets_ + $(RM) -r -v _dump_/_dungeons_ diff --git a/dump_dun.sh b/dump_dun.sh deleted file mode 100755 index 160a8b6fe..000000000 --- a/dump_dun.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -TILES_BIN_NAME=dlvl=1,quest_id=255,seed=7281,setlvl=0_tiles.bin -TILES_BIN_PATH=testdata/${TILES_BIN_NAME} -DUN_NAME=${TILES_BIN_NAME/.bin/.bin.dun} -DUN_FROM=testdata/${DUN_NAME} -DUN_TO=testdata/levels/l1data/${DUN_NAME} - -./cmd/viewdun/viewdun ${TILES_BIN_PATH} -mkdir -p testdata/levels/l1data -mv ${DUN_FROM} ${DUN_TO} -dun_dump ${DUN_TO} From 64425bcf6656230a021a453bc42453b4a8a1e3b2 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 17:03:37 +0100 Subject: [PATCH 20/23] testgen: invoke LoadSetMap for instead CreateL5Dungeon of set levels --- SourceT/testgen.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index eeb7514d1..67719d122 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -130,14 +130,16 @@ void gen_drlg_l1_tests(void) { quests[quest_id]._qtype = quest_id; quests[quest_id]._qactive = false; } + //*gendung.IsQuestLevel = false; - if (g.setlvl != 0) { + if (g.setlvl != SL_NONE) { setlevel = true; setlvlnum = g.setlvl; } else { setlevel = false; - setlvlnum = 0; // none + setlvlnum = SL_NONE; } + //if g.questID != quests.Invalid { // quests.Quests[g.questID].Active = true; // quests.Quests[g.questID].DLvl = g.dlvl; @@ -150,7 +152,11 @@ void gen_drlg_l1_tests(void) { // Generate dungeon based on the given seed. //l1.CreateDungeon(g.seed, 0); - CreateL5Dungeon(g.seed, in_entry); + if (g.setlvl != SL_NONE) { + LoadSetMap(); + } else { + CreateL5Dungeon(g.seed, in_entry); + } // Dump pre-dungeon tiles. char output_path[MAX_PATH]; From 5ad5ee88ac40c36dcd248e5c67a485d3551d254d Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 22:20:01 +0100 Subject: [PATCH 21/23] testgen: add more broken seeds Add all broken seeds from https://github.com/sanctuary/graphics/tree/master/l1/broken d1/l1 test coverage is now at 91%. --- SourceT/testgen.cpp | 49 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 67719d122..cdc9aac4f 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -34,14 +34,6 @@ void gen_drlg_l1_tests(void) { 123, // seed SL_NONE, // setlvl }, - { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 7281, // seed - SL_NONE, // setlvl - }, { "Cathedral (fix corners)", // dungeon_name 1, // dlvl @@ -90,6 +82,47 @@ void gen_drlg_l1_tests(void) { 123, // seed SL_SKELKING, // setlvl }, + // Broken seeds. + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 2588, // seed + SL_NONE, // setlvl + }, + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 4743, // seed + SL_NONE, // setlvl + }, + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 7281, // seed + SL_NONE, // setlvl + }, + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 9345, // seed + SL_NONE, // setlvl + }, + { + "Cathedral (broken seed)",// dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 15236, // seed + SL_NONE, // setlvl + }, }; // extra. From 4ee568d5b74f8036cefb258cfbb82e78bcc80748 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 22:21:21 +0100 Subject: [PATCH 22/23] testgen: format source code --- SourceT/testgen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index cdc9aac4f..97a0b5a98 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -120,7 +120,7 @@ void gen_drlg_l1_tests(void) { 1, // dlvl DTYPE_CATHEDRAL, // dtype Q_INVALID, // quest_id - 15236, // seed + 15236, // seed SL_NONE, // setlvl }, }; From bad2361db13950a4e059359b3183db9d6495fbcc Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Wed, 25 Mar 2020 22:27:10 +0100 Subject: [PATCH 23/23] testdata: add 1666 seed This takes d1/l1 test coverage from 91% to 91.3%. --- SourceT/testgen.cpp | 69 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/SourceT/testgen.cpp b/SourceT/testgen.cpp index 97a0b5a98..0ddbc9c40 100644 --- a/SourceT/testgen.cpp +++ b/SourceT/testgen.cpp @@ -84,44 +84,53 @@ void gen_drlg_l1_tests(void) { }, // Broken seeds. { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 2588, // seed - SL_NONE, // setlvl + "Cathedral (broken seed)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 2588, // seed + SL_NONE, // setlvl }, { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 4743, // seed - SL_NONE, // setlvl + "Cathedral (broken seed)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 4743, // seed + SL_NONE, // setlvl + }, + { + "Cathedral (broken seed)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 7281, // seed + SL_NONE, // setlvl }, { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 7281, // seed - SL_NONE, // setlvl + "Cathedral (broken seed)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 9345, // seed + SL_NONE, // setlvl }, { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 9345, // seed - SL_NONE, // setlvl + "Cathedral (broken seed)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 15236, // seed + SL_NONE, // setlvl }, + // extra { - "Cathedral (broken seed)",// dungeon_name - 1, // dlvl - DTYPE_CATHEDRAL, // dtype - Q_INVALID, // quest_id - 15236, // seed - SL_NONE, // setlvl + "Cathedral (666)", // dungeon_name + 1, // dlvl + DTYPE_CATHEDRAL, // dtype + Q_INVALID, // quest_id + 1666, // seed + SL_NONE, // setlvl }, };