Decompile mapGlobalVariablesInit

This commit is contained in:
Alexander Batalov 2022-09-15 18:16:46 +03:00
parent 980b40dcdd
commit 1d05bac7a1
1 changed files with 25 additions and 10 deletions

View File

@ -50,6 +50,7 @@ static void mapMakeMapsDirectory();
static void isoWindowRefreshRect(Rect* rect);
static void isoWindowRefreshRectGame(Rect* rect);
static void isoWindowRefreshRectMapper(Rect* rect);
static int mapGlobalVariablesInit(int count);
static void mapGlobalVariablesFree();
static void mapLocalVariablesFree();
static void _map_place_dude_and_mouse();
@ -819,18 +820,13 @@ static int mapLoad(File* stream)
gMapHeader.localVariablesCount = 0;
}
error = "Error loading global vars";
mapGlobalVariablesFree();
if (gMapHeader.globalVariablesCount != 0) {
gMapGlobalVars = (int*)internal_malloc(sizeof(*gMapGlobalVars) * gMapHeader.globalVariablesCount);
if (gMapGlobalVars == NULL) {
error = "Error allocating global vars";
// NOTE: Uninline.
if (mapGlobalVariablesInit(gMapHeader.globalVariablesCount) != 0) {
goto err;
}
gMapGlobalVarsLength = gMapHeader.globalVariablesCount;
}
error = "Error loading global vars";
if (fileReadInt32List(stream, gMapGlobalVars, gMapGlobalVarsLength) != 0) {
goto err;
}
@ -1500,6 +1496,25 @@ static void isoWindowRefreshRectMapper(Rect* rect)
_obj_render_post_roof(&clampedDirtyRect, gElevation);
}
// NOTE: Inlined.
//
// 0x483FE4
static int mapGlobalVariablesInit(int count)
{
mapGlobalVariablesFree();
if (count != 0) {
gMapGlobalVars = (int*)internal_malloc(sizeof(*gMapGlobalVars) * count);
if (gMapGlobalVars == NULL) {
return -1;
}
}
gMapGlobalVarsLength = count;
return 0;
}
// 0x484038
static void mapGlobalVariablesFree()
{