Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game flow rework (pt 6) #2381

Merged
merged 7 commits into from
Jan 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tr2/demo: simplify loading
rr- committed Jan 25, 2025

Verified

This commit was signed with the committer’s verified signature.
commit 9c996f7a070b06a8698936be181d3c2684fecd5d
48 changes: 23 additions & 25 deletions src/tr2/game/demo.c
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include "game/input.h"
#include "game/items.h"
#include "game/lara/cheat.h"
#include "game/lara/control.h"
#include "game/level.h"
#include "game/music.h"
#include "game/overlay.h"
@@ -22,6 +23,7 @@
#include <libtrx/log.h>

typedef struct {
uint32_t *demo_ptr;
GAME_FLOW_LEVEL *level;
TEXTSTRING *text;

@@ -72,12 +74,9 @@ static void M_RestoreStartInfo(M_PRIV *const p)
bool Demo_GetInput(void)
{
M_PRIV *const p = &m_Priv;
if (g_DemoCount == 0) {
if (p->demo_ptr == &g_DemoData[0]) {
m_OldDemoInputDB = (INPUT_STATE) {};
}
if (g_DemoCount >= MAX_DEMO_SIZE) {
return false;
}

union {
uint32_t any;
@@ -104,7 +103,7 @@ bool Demo_GetInput(void)
uint32_t load: 1;
// clang-format on
};
} demo_input = { .any = g_DemoPtr[g_DemoCount] };
} demo_input = { .any = *p->demo_ptr++ };

if ((int32_t)demo_input.any == -1) {
return false;
@@ -135,7 +134,6 @@ bool Demo_GetInput(void)

g_InputDB.any = g_Input.any & ~m_OldDemoInputDB.any;
m_OldDemoInputDB = g_Input;
g_DemoCount++;
return true;
}

@@ -150,40 +148,40 @@ bool Demo_Start(const int32_t level_num)

Random_SeedDraw(0xD371F947);
Random_SeedControl(0xD371F947);

if (!Level_Initialise(level_num, GFL_DEMO)) {
return false;
}

g_LevelComplete = false;
if (!g_IsDemoLoaded) {
if (g_DemoData == NULL) {
LOG_ERROR("Level '%s' has no demo data", p->level->path);
return false;
}

g_LaraItem->pos.x = g_DemoPtr[0];
g_LaraItem->pos.y = g_DemoPtr[1];
g_LaraItem->pos.z = g_DemoPtr[2];
g_LaraItem->rot.x = g_DemoPtr[3];
g_LaraItem->rot.y = g_DemoPtr[4];
g_LaraItem->rot.z = g_DemoPtr[5];
int16_t room_num = g_DemoPtr[6];
if (g_LaraItem->room_num != room_num) {
p->demo_ptr = g_DemoData;

ITEM *const lara_item = Lara_GetItem();
lara_item->pos.x = *p->demo_ptr++;
lara_item->pos.y = *p->demo_ptr++;
lara_item->pos.z = *p->demo_ptr++;
lara_item->rot.x = *p->demo_ptr++;
lara_item->rot.y = *p->demo_ptr++;
lara_item->rot.z = *p->demo_ptr++;

int16_t room_num = *p->demo_ptr++;
if (lara_item->room_num != room_num) {
Item_NewRoom(g_Lara.item_num, room_num);
}

const SECTOR *const sector = Room_GetSector(
g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z, &room_num);
g_LaraItem->floor = Room_GetHeight(
sector, g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z);
g_Lara.last_gun_type = g_DemoPtr[7];
lara_item->pos.x, lara_item->pos.y, lara_item->pos.z, &room_num);
lara_item->floor = Room_GetHeight(
sector, lara_item->pos.x, lara_item->pos.y, lara_item->pos.z);

g_DemoCount += 8;
g_Lara.last_gun_type = *p->demo_ptr++;

g_OverlayStatus = 1;
Lara_Cheat_GetStuff();
Random_SeedDraw(0xD371F947);
Random_SeedControl(0xD371F947);

g_OverlayStatus = 1;
Camera_Initialise();
Stats_StartTimer();

21 changes: 8 additions & 13 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
@@ -578,21 +578,16 @@ static void M_LoadCinematic(VFILE *const file)
static void M_LoadDemo(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
g_DemoCount = 0;

// TODO: is the allocation necessary if there's no demo data?
// TODO: do not hardcode the allocation size
g_DemoPtr = GameBuf_Alloc(36000, GBUF_DEMO_BUFFER);

const int32_t demo_size = VFile_ReadU16(file);
LOG_DEBUG("demo input size: %d", demo_size);
if (!demo_size) {
g_IsDemoLoaded = false;
const uint16_t size = VFile_ReadU16(file);
LOG_DEBUG("demo buffer size: %d", size);
if (size != 0) {
g_DemoData =
GameBuf_Alloc((size + 1) * sizeof(uint32_t), GBUF_DEMO_BUFFER);
VFile_Read(file, g_DemoData, size);
g_DemoData[size] = -1;
} else {
g_IsDemoLoaded = true;
VFile_Read(file, g_DemoPtr, demo_size);
g_DemoData = NULL;
}

Benchmark_End(benchmark, NULL);
}

1 change: 0 additions & 1 deletion src/tr2/global/const.h
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@
#define MAX_LEVELS 24
#define MAX_LEVEL_NAME_SIZE 50 // TODO: get rid of this limit
#define MAX_DEMO_FILES MAX_LEVELS
#define MAX_DEMO_SIZE 9000
#define MAX_REQUESTER_ITEMS 24
#define MAX_SAVE_SLOTS 16
#define MAX_ASSAULT_TIMES 10
1 change: 1 addition & 0 deletions src/tr2/global/enum_map.def
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_NOOP, "noop")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_START_GAME, "play_level")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_START_SAVED_GAME, "load_saved_game")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_START_CINE, "play_cutscene")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_START_DEMO, "play_demo")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_START_FMV, "play_fmv")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_EXIT_TO_TITLE, "exit_to_title")
ENUM_MAP_DEFINE(GAME_FLOW_ACTION, GF_LEVEL_COMPLETE, "level_complete")
3 changes: 1 addition & 2 deletions src/tr2/global/vars.c
Original file line number Diff line number Diff line change
@@ -118,8 +118,7 @@ int32_t g_ObjectTextureCount;
uint8_t g_LabTextureUVFlag[MAX_OBJECT_TEXTURES];
int32_t g_NumCameras;
int16_t *g_AnimTextureRanges = NULL;
uint32_t *g_DemoPtr = NULL;
int32_t g_DemoCount;
uint32_t *g_DemoData = NULL;
char g_LevelFileName[256];
uint16_t g_MusicTrackFlags[64];

3 changes: 1 addition & 2 deletions src/tr2/global/vars.h
Original file line number Diff line number Diff line change
@@ -115,8 +115,7 @@ extern int32_t g_ObjectTextureCount;
extern uint8_t g_LabTextureUVFlag[MAX_OBJECT_TEXTURES];
extern int32_t g_NumCameras;
extern int16_t *g_AnimTextureRanges;
extern uint32_t *g_DemoPtr;
extern int32_t g_DemoCount;
extern uint32_t *g_DemoData;
extern char g_LevelFileName[256];
extern uint16_t g_MusicTrackFlags[64];
extern WEAPON_INFO g_Weapons[];