Skip to content

Commit

Permalink
tr2: port S_ReloadLevelGraphics
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 18, 2024
1 parent d8f1737 commit b608694
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
16 changes: 8 additions & 8 deletions docs/tr2/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/tr2/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3967,7 +3967,7 @@ typedef enum {
0x0044B4B0 0x0018 +R BOOL __cdecl S_LoadLevelFile(LPCTSTR file_name, int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type);
0x0044B4D0 0x002A +R void __cdecl S_UnloadLevelFile(void);
0x0044B500 0x0014 +R void __cdecl S_AdjustTexelCoordinates(void);
0x0044B520 0x00C4 -R BOOL __cdecl S_ReloadLevelGraphics(BOOL reload_palettes, BOOL reload_tex_pages);
0x0044B520 0x00C4 +R BOOL __cdecl S_ReloadLevelGraphics(BOOL reload_palettes, BOOL reload_tex_pages);
0x0044B5F0 0x00C6 + BOOL __cdecl GF_ReadStringTable(DWORD count, char **string_table, char **string_buf, LPDWORD buf_size, HANDLE handle);
0x0044B6C0 0x06D1 + BOOL __cdecl GF_LoadFromFile(const char *file_name);
0x0044BDA0 0x006B +R bool __cdecl PlayFMV(const char *file_name);
Expand Down
1 change: 1 addition & 0 deletions src/tr2/decomp/decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,4 @@ void __cdecl S_AdjustTexelCoordinates(void);
BOOL __cdecl S_LoadLevelFile(
const char *file_name, int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type);
void __cdecl S_UnloadLevelFile(void);
BOOL __cdecl S_ReloadLevelGraphics(bool reload_palettes, bool reload_tex_pages);
38 changes: 38 additions & 0 deletions src/tr2/decomp/decomp2.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "decomp/decomp.h"
#include "game/background.h"
#include "game/hwr.h"
#include "game/inventory/common.h"
#include "game/level.h"
#include "global/funcs.h"
#include "global/vars.h"

#include <libtrx/virtual_file.h>

int32_t __cdecl CreateTexturePage(
const int32_t width, const int32_t height, LPDIRECTDRAWPALETTE palette)
{
Expand Down Expand Up @@ -563,3 +566,38 @@ void __cdecl S_UnloadLevelFile(void)
memset(g_TexturePageBuffer8, 0, sizeof(uint8_t *) * MAX_TEXTURE_PAGES);
g_TextureInfoCount = 0;
}

BOOL __cdecl S_ReloadLevelGraphics(
const bool reload_palettes, const bool reload_tex_pages)
{
if (g_LevelFileName[0] != '\0') {
VFILE *const file = VFile_CreateFromPath(g_LevelFileName);
if (file == NULL) {
return false;
}

if (reload_palettes && g_SavedAppSettings.render_mode == RM_SOFTWARE) {
VFile_SetPos(file, g_LevelFilePalettesOffset);
Level_LoadPalettes(file);

VFile_SetPos(file, g_LevelFileDepthQOffset);
Level_LoadDepthQ(file);
}

if (reload_tex_pages) {
if (g_SavedAppSettings.render_mode == RM_HARDWARE) {
HWR_FreeTexturePages();
}
VFile_SetPos(file, g_LevelFileTexPagesOffset);
Level_LoadTexturePages(file);
}

VFile_Close(file);
}

if (reload_palettes) {
Inv_InitColors();
}

return true;
}
17 changes: 6 additions & 11 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
#include <libtrx/filesystem.h>
#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/virtual_file.h>

#include <assert.h>

static void M_LoadFromFile(const char *file_name, int32_t level_num);
static void __cdecl M_LoadTexturePages(VFILE *file);
static void __cdecl M_LoadRooms(VFILE *file);
static void __cdecl M_LoadMeshBase(VFILE *file);
static void __cdecl M_LoadMeshes(VFILE *file);
Expand All @@ -36,8 +34,6 @@ static void __cdecl M_LoadStaticObjects(VFILE *file);
static void __cdecl M_LoadTextures(VFILE *file);
static void __cdecl M_LoadSprites(VFILE *file);
static void __cdecl M_LoadItems(VFILE *file);
static void __cdecl M_LoadDepthQ(VFILE *file);
static void __cdecl M_LoadPalettes(VFILE *file);
static void __cdecl M_LoadCameras(VFILE *file);
static void __cdecl M_LoadSoundEffects(VFILE *file);
static void __cdecl M_LoadBoxes(VFILE *file);
Expand All @@ -47,7 +43,7 @@ static void __cdecl M_LoadDemo(VFILE *file);
static void __cdecl M_LoadSamples(VFILE *file);
static void M_CompleteSetup(void);

static void __cdecl M_LoadTexturePages(VFILE *const file)
void __cdecl Level_LoadTexturePages(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
char *base = NULL;
Expand Down Expand Up @@ -401,7 +397,6 @@ static void __cdecl M_LoadTextures(VFILE *const file)
LOG_INFO("textures: %d", num_textures);
if (num_textures > MAX_TEXTURES) {
Shell_ExitSystem("Too many textures");
return;
}

g_TextureInfoCount = num_textures;
Expand Down Expand Up @@ -513,7 +508,7 @@ static void __cdecl M_LoadItems(VFILE *const file)
Benchmark_End(benchmark, NULL);
}

static void __cdecl M_LoadDepthQ(VFILE *const file)
void __cdecl Level_LoadDepthQ(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
for (int32_t i = 0; i < 32; i++) {
Expand Down Expand Up @@ -558,7 +553,7 @@ static void __cdecl M_LoadDepthQ(VFILE *const file)
Benchmark_End(benchmark, NULL);
}

static void __cdecl M_LoadPalettes(VFILE *const file)
void __cdecl Level_LoadPalettes(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
VFile_Read(file, g_GamePalette8, sizeof(RGB_888) * 256);
Expand Down Expand Up @@ -847,10 +842,10 @@ static void M_LoadFromFile(const char *const file_name, const int32_t level_num)
}

g_LevelFilePalettesOffset = VFile_GetPos(file);
M_LoadPalettes(file);
Level_LoadPalettes(file);

g_LevelFileTexPagesOffset = VFile_GetPos(file);
M_LoadTexturePages(file);
Level_LoadTexturePages(file);
VFile_Skip(file, 4);

M_LoadRooms(file);
Expand Down Expand Up @@ -887,7 +882,7 @@ static void M_LoadFromFile(const char *const file_name, const int32_t level_num)
M_LoadItems(file);

g_LevelFileDepthQOffset = VFile_GetPos(file);
M_LoadDepthQ(file);
Level_LoadDepthQ(file);
M_LoadCinematic(file);
M_LoadDemo(file);
M_LoadSamples(file);
Expand Down
6 changes: 6 additions & 0 deletions src/tr2/game/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

#include "global/types.h"

#include <libtrx/virtual_file.h>

void __cdecl Level_LoadPalettes(VFILE *file);
void __cdecl Level_LoadTexturePages(VFILE *file);
void __cdecl Level_LoadDepthQ(VFILE *file);

bool __cdecl Level_Load(const char *file_name, int32_t level_num);
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
#define GiantYeti_Control ((void __cdecl (*)(int16_t item_num))0x00443050)
#define Yeti_Control ((void __cdecl (*)(int16_t item_num))0x00443350)
#define ReadFileSync ((BOOL __cdecl (*)(HANDLE handle, LPVOID lpBuffer, DWORD nBytesToRead, LPDWORD lpnBytesRead, LPOVERLAPPED lpOverlapped))0x004498D0)
#define S_ReloadLevelGraphics ((BOOL __cdecl (*)(BOOL reload_palettes, BOOL reload_tex_pages))0x0044B520)
#define GetValidLevelsList ((void __cdecl (*)(REQUEST_INFO *req))0x0044C9D0)
#define CalculateWibbleTable ((void __cdecl (*)(void))0x0044D780)
#define S_GetObjectBounds ((int32_t __cdecl (*)(const BOUNDS_16 *bounds))0x00450CC0)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ static void M_DecompGeneral(const bool enable)
INJECT(enable, 0x0044B4B0, S_LoadLevelFile);
INJECT(enable, 0x0044B4D0, S_UnloadLevelFile);
INJECT(enable, 0x0044B500, S_AdjustTexelCoordinates);
INJECT(enable, 0x0044B520, S_ReloadLevelGraphics);
INJECT(enable, 0x0044C1D0, S_FindColor);
INJECT(enable, 0x0044C200, S_DrawScreenLine);
INJECT(enable, 0x0044C240, S_DrawScreenBox);
Expand Down

0 comments on commit b608694

Please sign in to comment.