From 54b2aaae96827449e86698254030f8d3250555e3 Mon Sep 17 00:00:00 2001 From: mothbeanie Date: Sun, 3 Nov 2024 15:20:33 -0800 Subject: [PATCH] Region system PR review changes Fixes errors or oversights with the region system for the PR review --- desktop_version/src/Game.cpp | 10 ---------- desktop_version/src/GraphicsResources.cpp | 7 ++++++- desktop_version/src/Map.cpp | 19 ++++++++++++++++--- desktop_version/src/Map.h | 4 ++-- desktop_version/src/Script.cpp | 2 ++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 0a587d21..6114a446 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -229,16 +229,6 @@ void Game::init(void) customcol=0; - map.currentregion = 0; - for (size_t i = 0; i < SDL_arraysize(map.region); i++) - { - map.region[i].isvalid = false; - map.region[i].rx = 0; - map.region[i].ry = 0; - map.region[i].rx2 = 0; - map.region[i].ry2 = 0; - } - SDL_memset(crewstats, false, sizeof(crewstats)); SDL_memset(ndmresultcrewstats, false, sizeof(ndmresultcrewstats)); SDL_memset(besttimes, -1, sizeof(besttimes)); diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index 279ee8b1..8d13f8df 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -447,7 +447,7 @@ void GraphicsResources::init(void) EnumHandle handle = {}; const char* item; - char full_item[73]; + char full_item[64]; while ((item = FILESYSTEM_enumerateAssets("graphics", &handle)) != NULL) { if (SDL_strncmp(item, "region", 6) != 0) @@ -456,6 +456,11 @@ void GraphicsResources::init(void) } char* end; int i = SDL_strtol(&item[6], &end, 10); + // make sure the region id is actually in bounds! + if (i < 1 || i > 400) + { + continue; + } if (item == end || SDL_strcmp(end, ".png") != 0) { continue; diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 3c28a070..826384bf 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -87,6 +87,9 @@ mapclass::mapclass(void) roomtexton = false; nexttowercolour_set = false; + + currentregion = 0; + SDL_zeroa(region); } static char roomname_static[SCREEN_WIDTH_CHARS]; @@ -2301,21 +2304,31 @@ MapRenderData mapclass::get_render_data(void) void mapclass::setregion(int id, int rx, int ry, int rx2, int ry2) { - if (INBOUNDS_ARR(id, region)) + if (INBOUNDS_ARR(id, region) && id > 0) { region[id].isvalid = true; region[id].rx = SDL_clamp(rx, 0, cl.mapwidth - 1); region[id].ry = SDL_clamp(ry, 0, cl.mapheight - 1); region[id].rx2 = SDL_clamp(rx2, 0, cl.mapwidth - 1); region[id].ry2 = SDL_clamp(ry2, 0, cl.mapheight - 1); + + if (id == currentregion) + { + cl.generatecustomminimap(); + } } } void mapclass::removeregion(int id) { - if (INBOUNDS_ARR(id, region)) + if (INBOUNDS_ARR(id, region) && id > 0) { SDL_zero(region[id]); + + if (id == currentregion) + { + cl.generatecustomminimap(); + } } } @@ -2326,4 +2339,4 @@ void mapclass::changeregion(int id) currentregion = id; cl.generatecustomminimap(); } -} \ No newline at end of file +} diff --git a/desktop_version/src/Map.h b/desktop_version/src/Map.h index fa2f3533..b025916e 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -213,7 +213,7 @@ public: int cursorstate, cursordelay; //Region system - struct regionstruct + struct Region { bool isvalid; int rx; @@ -221,7 +221,7 @@ public: int rx2; int ry2; }; - struct regionstruct region[401]; + struct Region region[401]; void setregion(int id, int rx, int ry, int rx2, int ry2); void removeregion(int id); void changeregion(int id); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 84f388ef..6a75d560 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -3275,6 +3275,8 @@ void scriptclass::hardreset(void) SDL_memset(map.roomdeaths, 0, sizeof(map.roomdeaths)); SDL_memset(map.roomdeathsfinal, 0, sizeof(map.roomdeathsfinal)); map.resetmap(); + map.currentregion = 0; + SDL_zeroa(map.region); //entityclass obj.nearelephant = false; obj.upsetmode = false;