From c34756e5f2770cce3dcc274b8e3e8f422f9e1ea0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 8 Dec 2022 18:42:42 +0100 Subject: [PATCH] - cleanup of voxel init code. The voxreserve array was never properly set up so it is gone now. nextvoxid now gets set right before loading .def files. --- source/core/defparser.cpp | 15 ++++++--------- source/core/rendering/hw_voxels.h | 3 --- source/core/textures/tilesetbuilder.cpp | 5 +++++ source/core/textures/tilesetbuilder.h | 1 + source/games/blood/src/tile.cpp | 1 - source/games/sw/src/scrip2.cpp | 3 --- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/source/core/defparser.cpp b/source/core/defparser.cpp index bcd43a7e9..69dfc1123 100644 --- a/source/core/defparser.cpp +++ b/source/core/defparser.cpp @@ -855,21 +855,20 @@ static int lastvoxid = -1; void parseDefineVoxel(FScanner& sc, FScriptPosition& pos) { sc.MustGetString(); - while (nextvoxid < MAXVOXELS && voxreserve[nextvoxid]) nextvoxid++; - if (nextvoxid == MAXVOXELS) + if (tbuild->nextvoxid == MAXVOXELS) { pos.Message(MSG_ERROR, "Maximum number of voxels (%d) already defined.", MAXVOXELS); return; } - if (voxDefine(nextvoxid, sc.String)) + if (voxDefine(tbuild->nextvoxid, sc.String)) { pos.Message(MSG_ERROR, "Unable to load voxel file \"%s\"", sc.String); return; } - lastvoxid = nextvoxid++; + lastvoxid = tbuild->nextvoxid++; } //=========================================================================== @@ -908,20 +907,18 @@ void parseVoxel(FScanner& sc, FScriptPosition& pos) if (!sc.GetString(fn)) return; - while (nextvoxid < MAXVOXELS && voxreserve[nextvoxid]) nextvoxid++; - - if (nextvoxid == MAXVOXELS) + if (tbuild->nextvoxid == MAXVOXELS) { pos.Message(MSG_ERROR, "Maximum number of voxels (%d) already defined.", MAXVOXELS); error = true; } - else if (voxDefine(nextvoxid, fn)) + else if (voxDefine(tbuild->nextvoxid, fn)) { pos.Message(MSG_ERROR, "Unable to load voxel file \"%s\"", fn.GetChars()); error = true; } - int lastvoxid = nextvoxid++; + int lastvoxid = tbuild->nextvoxid++; if (sc.StartBraces(&blockend)) return; while (!sc.FoundEndBrace(blockend)) diff --git a/source/core/rendering/hw_voxels.h b/source/core/rendering/hw_voxels.h index ffc5d58f6..a897d92e8 100644 --- a/source/core/rendering/hw_voxels.h +++ b/source/core/rendering/hw_voxels.h @@ -22,9 +22,6 @@ extern float voxscale[]; extern voxmodel_t* voxmodels[MAXVOXELS]; extern FixedBitArray voxrotate; -inline int32_t nextvoxid; -inline FixedBitArrayvoxreserve; - void voxInit(); void voxClear(); int voxDefine(int voxindex, const char* filename); diff --git a/source/core/textures/tilesetbuilder.cpp b/source/core/textures/tilesetbuilder.cpp index 517306fe2..fa65cd773 100644 --- a/source/core/textures/tilesetbuilder.cpp +++ b/source/core/textures/tilesetbuilder.cpp @@ -100,6 +100,11 @@ CCMD(tilecrc) static void LoadDefinitions(TilesetBuildInfo& info) { + for (unsigned i = 0; i < info.tile.Size(); i++) + { + if (info.tile[i].extinfo.tiletovox > info.nextvoxid) info.nextvoxid = info.tile[i].extinfo.tiletovox; + } + info.nextvoxid++; const char* defsfile = G_DefFile(); FString razedefsfile = defsfile; razedefsfile.Substitute(".def", "-raze.def"); diff --git a/source/core/textures/tilesetbuilder.h b/source/core/textures/tilesetbuilder.h index 596b8c452..da0c08b9e 100644 --- a/source/core/textures/tilesetbuilder.h +++ b/source/core/textures/tilesetbuilder.h @@ -22,6 +22,7 @@ struct TilesetBuildInfo TArray tile; unsigned maxtileofart; TArray > aliases; + int32_t nextvoxid; void addName(const char* name, int index) { aliases.Push(std::make_pair(name, index)); diff --git a/source/games/blood/src/tile.cpp b/source/games/blood/src/tile.cpp index 13ef9c089..99a4c4521 100644 --- a/source/games/blood/src/tile.cpp +++ b/source/games/blood/src/tile.cpp @@ -86,7 +86,6 @@ void GameInterface::LoadTextureInfo(TilesetBuildInfo& info) { info.tile[i].extinfo.tiletovox = voxindex; } - if (nextvoxid <= voxindex) nextvoxid = voxindex + 1; } } hFile = fileSystem.OpenFileReader("SHADE.DAT"); diff --git a/source/games/sw/src/scrip2.cpp b/source/games/sw/src/scrip2.cpp index 1f3ccb5a9..ceef3be8f 100644 --- a/source/games/sw/src/scrip2.cpp +++ b/source/games/sw/src/scrip2.cpp @@ -220,9 +220,6 @@ void LoadKVXFromScript(TilesetBuildInfo& info, const char* filename) { info.tile[lTile].extinfo.tiletovox = lNumber; } - - if (lNumber >= nextvoxid) // JBF: so voxels in the def file append to the list - nextvoxid = lNumber + 1; } while (script_p < scriptend_p);