Skip to content

Commit

Permalink
gamebuf: allocate only once per game launch
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Aug 30, 2024
1 parent dd1c277 commit c257dcf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fixed `/give` console command confusing logging around mismatched items (#1463, regression from 3.0)
- fixed `/flip` console command misreporting an already enabled flipmap as off (regression from 4.0)
- fixed console commands causing improper ring shutdown with selected inventory item (#1460, regression from 3.0)
- improved level load times
- improved logs module names readability
- improved crash debug information on Windows

Expand Down
12 changes: 12 additions & 0 deletions src/game/gamebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ void GameBuf_Init(void)
m_GameAllocMemFree = MALLOC_SIZE;
}

void GameBuf_Reset(void)
{
if (m_GameMemoryPointer == NULL) {
m_GameAllocMemPointer = NULL;
m_GameAllocMemFree = 0;
return;
}

m_GameAllocMemPointer = m_GameMemoryPointer;
m_GameAllocMemFree = MALLOC_SIZE;
}

void GameBuf_Shutdown(void)
{
Memory_FreePointer(&m_GameMemoryPointer);
Expand Down
1 change: 1 addition & 0 deletions src/game/gamebuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ typedef enum GAME_BUFFER {
} GAME_BUFFER;

void GameBuf_Init(void);
void GameBuf_Reset(void);
void *GameBuf_Alloc(int32_t alloc_size, GAME_BUFFER buffer);
void GameBuf_Shutdown(void);
3 changes: 1 addition & 2 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ static size_t Level_CalculateMaxVertices(void);
static void Level_LoadFromFile(
const char *filename, int32_t level_num, bool is_demo)
{
GameBuf_Shutdown();
GameBuf_Init();
GameBuf_Reset();

MYFILE *fp = File_Open(filename, FILE_OPEN_READ);
if (!fp) {
Expand Down
1 change: 1 addition & 0 deletions src/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void Shell_Init(const char *gameflow_path)
return;
}

GameBuf_Init();
Text_Init();
Clock_Init();
Sound_Init();
Expand Down

0 comments on commit c257dcf

Please sign in to comment.