Skip to content

Commit

Permalink
Region system PR review changes
Browse files Browse the repository at this point in the history
Fixes errors or oversights with the region system for the PR review
  • Loading branch information
mothbeanie committed Nov 3, 2024
1 parent 81485a9 commit 94b903a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
10 changes: 0 additions & 10 deletions desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,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));
Expand Down
7 changes: 6 additions & 1 deletion desktop_version/src/GraphicsResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions desktop_version/src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ mapclass::mapclass(void)
roomtexton = false;

nexttowercolour_set = false;

currentregion = 0;
SDL_zeroa(region);
}

static char roomname_static[SCREEN_WIDTH_CHARS];
Expand Down Expand Up @@ -2291,21 +2294,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();
}
}
}

Expand All @@ -2316,4 +2329,4 @@ void mapclass::changeregion(int id)
currentregion = id;
cl.generatecustomminimap();
}
}
}
4 changes: 2 additions & 2 deletions desktop_version/src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ class mapclass
int cursorstate, cursordelay;

//Region system
struct regionstruct
struct Region
{
bool isvalid;
int rx;
int ry;
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);
Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,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;
Expand Down

0 comments on commit 94b903a

Please sign in to comment.