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 11) #2418

Merged
merged 11 commits into from
Feb 1, 2025
2 changes: 0 additions & 2 deletions data/tr1/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@
{"type": "loading_screen", "path": "data/images/peru.webp", "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "load_level"},
{"type": "play_level"},
{"type": "level_stats"},
{"type": "level_complete"},
],
},
Expand All @@ -436,7 +435,6 @@
{"type": "loading_screen", "path": "data/images/peru.webp", "fade_in_time": 1.0, "fade_out_time": 1.0},
{"type": "load_level"},
{"type": "play_level"},
{"type": "level_stats"},
{"type": "level_complete"},
],
},
Expand Down
7 changes: 5 additions & 2 deletions src/libtrx/engine/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ typedef struct {
} M_STATE;

static int64_t m_AudioCallbackTime;
static SDL_AudioDeviceID m_AudioDevice;
static SDL_AudioDeviceID m_AudioDevice = 0;

static int M_PacketQueuePutPrivate(M_PACKET_QUEUE *q, AVPacket *pkt)
{
Expand Down Expand Up @@ -778,10 +778,13 @@ static void M_StreamComponentClose(M_STATE *is, int stream_index)
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
M_DecoderAbort(&is->auddec, &is->sampq);
SDL_CloseAudioDevice(m_AudioDevice);
M_DecoderShutdown(&is->auddec);
swr_free(&is->swr_ctx);
av_freep(&is->audio_buf1);
if (m_AudioDevice > 0) {
SDL_CloseAudioDevice(m_AudioDevice);
m_AudioDevice = 0;
}
is->audio_buf1_size = 0;
is->audio_buf = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion src/libtrx/include/libtrx/game/game_flow/sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ GF_COMMAND GF_EnterPhotoMode(void);
GF_COMMAND GF_PauseGame(void);
GF_COMMAND GF_ShowInventory(INVENTORY_MODE inv_mode);
GF_COMMAND GF_ShowInventoryKeys(GAME_OBJECT_ID receptacle_type_id);
GF_COMMAND GF_RunTitle(void);
GF_COMMAND GF_RunDemo(int32_t demo_num);
GF_COMMAND GF_RunCutscene(int32_t cutscene_num);
GF_COMMAND GF_RunGame(const GF_LEVEL *level, GF_SEQUENCE_CONTEXT seq_ctx);

GF_COMMAND GF_DoFrontendSequence(void);
GF_COMMAND GF_TitleSequence(void);
GF_COMMAND GF_DoDemoSequence(int32_t demo_num);
GF_COMMAND GF_DoCutsceneSequence(int32_t cutscene_num);

Expand Down
9 changes: 2 additions & 7 deletions src/tr1/game/cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/debug.h>
#include <libtrx/memory.h>

#include <stdint.h>

static void M_InitialiseLara(const GF_LEVEL *level);

static void M_InitialiseLara(const GF_LEVEL *const level)
Expand Down Expand Up @@ -60,11 +59,7 @@ static void M_InitialiseLara(const GF_LEVEL *const level)
bool Cutscene_Start(const int32_t level_num)
{
const GF_LEVEL *const level = GF_GetLevel(GFLT_CUTSCENES, level_num);
if (GF_GetCurrentLevel()->num != level_num) {
if (!Level_Initialise(level)) {
return false;
}
}
ASSERT(GF_GetCurrentLevel() == level);

M_InitialiseLara(level);

Expand Down
51 changes: 6 additions & 45 deletions src/tr1/game/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#include "game/phase.h"
#include "game/random.h"
#include "game/room.h"
#include "game/savegame.h"
#include "game/shell.h"
#include "game/sound.h"
#include "global/vars.h"

#include <libtrx/config.h>
#include <libtrx/debug.h>
#include <libtrx/log.h>

#define MODIFY_CONFIG() \
Expand All @@ -37,7 +39,6 @@ typedef struct {
uint32_t *demo_ptr;
const GF_LEVEL *level;
CONFIG old_config;
RESUME_INFO old_resume_info;
TEXTSTRING *text;
} M_PRIV;

Expand All @@ -46,8 +47,6 @@ static M_PRIV m_Priv;

static void M_PrepareConfig(M_PRIV *const p);
static void M_RestoreConfig(M_PRIV *const p);
static void M_PrepareResumeInfo(M_PRIV *const p);
static void M_RestoreResumeInfo(M_PRIV *const p);
static bool M_ProcessInput(M_PRIV *const p);

static void M_PrepareConfig(M_PRIV *const p)
Expand All @@ -67,36 +66,6 @@ static void M_RestoreConfig(M_PRIV *const p)
MODIFY_CONFIG();
}

static void M_PrepareResumeInfo(M_PRIV *const p)
{
RESUME_INFO *const resume_info = GF_GetResumeInfo(p->level);
p->old_resume_info = *resume_info;
resume_info->flags.available = 1;
resume_info->flags.costume = 0;
resume_info->num_medis = 0;
resume_info->num_big_medis = 0;
resume_info->num_scions = 0;
resume_info->flags.got_pistols = 1;
resume_info->flags.got_shotgun = 0;
resume_info->flags.got_magnums = 0;
resume_info->flags.got_uzis = 0;
resume_info->pistol_ammo = 1000;
resume_info->shotgun_ammo = 0;
resume_info->magnum_ammo = 0;
resume_info->uzi_ammo = 0;
resume_info->gun_status = LGS_ARMLESS;
resume_info->equipped_gun_type = LGT_PISTOLS;
resume_info->holsters_gun_type = LGT_PISTOLS;
resume_info->back_gun_type = LGT_UNARMED;
resume_info->lara_hitpoints = LARA_MAX_HITPOINTS;
}

static void M_RestoreResumeInfo(M_PRIV *const p)
{
RESUME_INFO *const resume_info = GF_GetResumeInfo(p->level);
*resume_info = p->old_resume_info;
}

static bool M_ProcessInput(M_PRIV *const p)
{
union {
Expand Down Expand Up @@ -160,9 +129,10 @@ bool Demo_Start(const int32_t level_num)
{
M_PRIV *const p = &m_Priv;
p->level = GF_GetLevel(GFLT_DEMOS, level_num);
ASSERT(p->level != nullptr);
ASSERT(GF_GetCurrentLevel() == p->level);

M_PrepareConfig(p);
M_PrepareResumeInfo(p);

// Remember old inputs in case the demo was forcefully started with some
// keys pressed. In that case, it should only be stopped if the user
Expand All @@ -171,12 +141,6 @@ bool Demo_Start(const int32_t level_num)

Interpolation_Remember();

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

if (!Level_Initialise(p->level)) {
return false;
}
if (g_DemoData == nullptr) {
LOG_ERROR("Level '%s' has no demo data", p->level->path);
return false;
Expand Down Expand Up @@ -224,7 +188,6 @@ void Demo_End(void)
{
M_PRIV *const p = &m_Priv;
M_RestoreConfig(p);
M_RestoreResumeInfo(p);
Text_Remove(p->text);
p->text = nullptr;
g_GameInfo.showing_demo = false;
Expand All @@ -234,7 +197,6 @@ void Demo_Pause(void)
{
M_PRIV *const p = &m_Priv;
M_RestoreConfig(p);
M_RestoreResumeInfo(p);
Text_Hide(p->text, true);
g_GameInfo.showing_demo = false;
}
Expand All @@ -243,7 +205,6 @@ void Demo_Unpause(void)
{
M_PRIV *const p = &m_Priv;
M_PrepareConfig(p);
M_PrepareResumeInfo(p);
Text_Hide(p->text, false);
g_GameInfo.showing_demo = true;
}
Expand Down Expand Up @@ -283,7 +244,7 @@ GF_COMMAND Demo_Control(void)

if (g_LevelComplete || g_InputDB.menu_confirm || g_InputDB.menu_back) {
return (GF_COMMAND) {
.action = GF_LEVEL_COMPLETE,
.action = GF_EXIT_TO_TITLE,
.param = p->level->num,
};
}
Expand All @@ -292,7 +253,7 @@ GF_COMMAND Demo_Control(void)

if (!M_ProcessInput(p)) {
return (GF_COMMAND) {
.action = GF_LEVEL_COMPLETE,
.action = GF_EXIT_TO_TITLE,
.param = p->level->num,
};
}
Expand Down
81 changes: 4 additions & 77 deletions src/tr1/game/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,82 +69,6 @@ void Game_ProcessInput(void)
}
}

GF_COMMAND Game_Stop_Legacy(void)
{
Sound_StopAll();
Music_Stop();
const GF_LEVEL *const current_level = Game_GetCurrentLevel();
const GF_LEVEL *const next_level = GF_GetLevelAfter(current_level);
Savegame_PersistGameToCurrentInfo(current_level);

if (current_level == GF_GetLastLevel()) {
g_Config.profile.new_game_plus_unlock = true;
Config_Write();
g_GameInfo.bonus_level_unlock =
Stats_CheckAllSecretsCollected(GFL_NORMAL);
}

// play specific level
if (g_LevelComplete && g_GameInfo.select_level_num != -1) {
if (current_level != nullptr) {
Savegame_CarryCurrentInfoToNextLevel(
current_level,
GF_GetLevel(GFLT_MAIN, g_GameInfo.select_level_num));
}
return (GF_COMMAND) {
.action = GF_SELECT_GAME,
.param = g_GameInfo.select_level_num,
};
}

// carry info to the next level
if (next_level != nullptr) {
// TODO: this should be moved to GFS_LEVEL_COMPLETE handler, probably
Savegame_CarryCurrentInfoToNextLevel(current_level, next_level);
Savegame_ApplyLogicToCurrentInfo(next_level);
}

// normal level completion
if (g_LevelComplete) {
// TODO: why is this made unavailable?
GF_GetResumeInfo(current_level)->flags.available = 0;
return (GF_COMMAND) {
.action = GF_LEVEL_COMPLETE,
.param = g_GameInfo.select_level_num,
};
}

if (g_GameInfo.passport_selection == PASSPORT_MODE_LOAD_GAME) {
return (GF_COMMAND) {
.action = GF_START_SAVED_GAME,
.param = g_GameInfo.select_save_slot,
};
} else if (g_GameInfo.passport_selection == PASSPORT_MODE_SELECT_LEVEL) {
return (GF_COMMAND) {
.action = GF_SELECT_GAME,
.param = g_GameInfo.select_level_num,
};
} else if (g_GameInfo.passport_selection == PASSPORT_MODE_STORY_SO_FAR) {
return (GF_COMMAND) {
.action = GF_STORY_SO_FAR,
.param = g_GameInfo.select_save_slot,
};
} else if (g_GameInfo.passport_selection == PASSPORT_MODE_RESTART) {
return (GF_COMMAND) {
.action = GF_RESTART_GAME,
.param = current_level->num,
};
} else if (g_GameInfo.passport_selection == PASSPORT_MODE_NEW_GAME) {
Savegame_InitCurrentInfo();
return (GF_COMMAND) {
.action = GF_START_GAME,
.param = GF_GetFirstLevel()->num,
};
} else {
return (GF_COMMAND) { .action = GF_EXIT_TO_TITLE };
}
}

bool Game_Start(const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx)
{
Game_SetCurrentLevel(level);
Expand All @@ -162,6 +86,7 @@ bool Game_Start(const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx)

void Game_End(void)
{
Savegame_PersistGameToCurrentInfo(Game_GetCurrentLevel());
}

void Game_Suspend(void)
Expand Down Expand Up @@ -190,7 +115,9 @@ GF_COMMAND Game_Control(const bool demo_mode)

Lara_Cheat_Control();
if (g_LevelComplete) {
return Game_Stop_Legacy();
Sound_StopAll();
Music_Stop();
return (GF_COMMAND) { .action = GF_LEVEL_COMPLETE };
}

Input_Update();
Expand Down
22 changes: 0 additions & 22 deletions src/tr1/game/game_flow/common.c

This file was deleted.

4 changes: 0 additions & 4 deletions src/tr1/game/game_flow/common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#pragma once

#include "global/types.h"

#include <libtrx/game/game_flow/common.h>

RESUME_INFO *GF_GetResumeInfo(const GF_LEVEL *level);
Loading