Skip to content

Commit

Permalink
phase_pause: add the ability to pause during cutscenes (#1746)
Browse files Browse the repository at this point in the history
Resolves #1673.
  • Loading branch information
walkawayy authored Oct 25, 2024
1 parent c3bff3a commit 25cf965
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.5.1...develop) - ××××-××-××
- added support for wading, similar to TR2+ (#1537)
- added the ability to pause during cutscenes (#1673)
- fixed missing pushblock SFX in Natla's Mines (#1714)
- fixed crash reports not working in certain circumstances (#1738)
- fixed missing trapdoor triggers in City of Khamoon (#1744)
Expand Down
30 changes: 20 additions & 10 deletions src/tr1/game/phase/phase_cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "game/level.h"
#include "game/music.h"
#include "game/output.h"
#include "game/phase/phase_pause.h"
#include "game/phase/phase_photo_mode.h"
#include "game/shell.h"
#include "game/sound.h"
Expand All @@ -25,7 +26,7 @@
#include <stddef.h>
#include <stdint.h>

static bool m_ExitingToPhotoMode = false;
static bool m_PauseCutscene = false;

static void M_InitialiseHair(int32_t level_num);

Expand Down Expand Up @@ -69,7 +70,7 @@ static void M_InitialiseHair(int32_t level_num)

static void M_Start(const PHASE_CUTSCENE_ARGS *const args)
{
m_ExitingToPhotoMode = false;
m_PauseCutscene = false;

// The cutscene is already playing and it's to be resumed.
if (args->resume_existing) {
Expand Down Expand Up @@ -106,7 +107,7 @@ static void M_Start(const PHASE_CUTSCENE_ARGS *const args)

static void M_End(void)
{
if (m_ExitingToPhotoMode) {
if (m_PauseCutscene) {
return;
}

Expand Down Expand Up @@ -152,18 +153,27 @@ static PHASE_CONTROL M_Control(int32_t nframes)

g_CineFrame++;

if (g_InputDB.toggle_photo_mode) {
if (g_InputDB.toggle_photo_mode || g_InputDB.pause) {
PHASE_CUTSCENE_ARGS *const cutscene_args =
Memory_Alloc(sizeof(PHASE_CUTSCENE_ARGS));
cutscene_args->resume_existing = true;
cutscene_args->level_num = g_CurrentLevel;

PHASE_PHOTO_MODE_ARGS *const args =
Memory_Alloc(sizeof(PHASE_PHOTO_MODE_ARGS));
args->phase_to_return_to = PHASE_CUTSCENE;
args->phase_arg = cutscene_args;
Phase_Set(PHASE_PHOTO_MODE, args);
m_ExitingToPhotoMode = true;
if (g_InputDB.toggle_photo_mode) {
PHASE_PHOTO_MODE_ARGS *const args =
Memory_Alloc(sizeof(PHASE_PHOTO_MODE_ARGS));
args->phase_to_return_to = PHASE_CUTSCENE;
args->phase_arg = cutscene_args;
Phase_Set(PHASE_PHOTO_MODE, args);
} else if (g_InputDB.pause) {
PHASE_PAUSE_ARGS *const args =
Memory_Alloc(sizeof(PHASE_PAUSE_ARGS));
args->phase_to_return_to = PHASE_CUTSCENE;
args->phase_arg = cutscene_args;
Phase_Set(PHASE_PAUSE, args);
}

m_PauseCutscene = true;
return (PHASE_CONTROL) { .end = false };
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/tr1/game/phase/phase_pause.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef enum {

static STATE m_PauseState = STATE_DEFAULT;
static bool m_IsTextReady = false;

static PHASE_PAUSE_ARGS m_Args;
static TEXTSTRING *m_PausedText = NULL;

static REQUEST_INFO m_PauseRequester = {
Expand All @@ -55,7 +55,7 @@ static void M_UpdateText(void);
static int32_t M_DisplayRequester(
const char *header, const char *option1, const char *option2,
int16_t requested);
static void M_Start(const void *args);
static void M_Start(const PHASE_PAUSE_ARGS *args);
static void M_End(void);
static PHASE_CONTROL M_Control(int32_t nframes);
static void M_Draw(void);
Expand Down Expand Up @@ -108,8 +108,15 @@ static int32_t M_DisplayRequester(
return select;
}

static void M_Start(const void *const args)
static void M_Start(const PHASE_PAUSE_ARGS *const args)
{
if (args != NULL) {
m_Args = *args;
} else {
m_Args.phase_to_return_to = PHASE_GAME;
m_Args.phase_arg = NULL;
}

g_OldInputDB = g_Input;

Overlay_HideGameInfo();
Expand Down Expand Up @@ -145,7 +152,7 @@ static PHASE_CONTROL M_Control(int32_t nframes)
if (g_InputDB.pause) {
Music_Unpause();
Sound_UnpauseAll();
Phase_Set(PHASE_GAME, NULL);
Phase_Set(m_Args.phase_to_return_to, m_Args.phase_arg);
} else if (g_InputDB.option) {
m_PauseState = STATE_ASK;
}
Expand All @@ -157,7 +164,7 @@ static PHASE_CONTROL M_Control(int32_t nframes)
if (choice == 1) {
Music_Unpause();
Sound_UnpauseAll();
Phase_Set(PHASE_GAME, NULL);
Phase_Set(m_Args.phase_to_return_to, m_Args.phase_arg);
} else if (choice == 2) {
m_PauseState = STATE_CONFIRM;
}
Expand All @@ -175,7 +182,7 @@ static PHASE_CONTROL M_Control(int32_t nframes)
} else if (choice == 2) {
Music_Unpause();
Sound_UnpauseAll();
Phase_Set(PHASE_GAME, NULL);
Phase_Set(m_Args.phase_to_return_to, m_Args.phase_arg);
}
break;
}
Expand All @@ -194,7 +201,7 @@ static void M_Draw(void)
}

PHASER g_PausePhaser = {
.start = M_Start,
.start = (PHASER_START)M_Start,
.end = M_End,
.control = M_Control,
.draw = M_Draw,
Expand Down
5 changes: 5 additions & 0 deletions src/tr1/game/phase/phase_pause.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

#include "game/phase/phase.h"

typedef struct {
PHASE phase_to_return_to;
void *phase_arg;
} PHASE_PAUSE_ARGS;

extern PHASER g_PausePhaser;

0 comments on commit 25cf965

Please sign in to comment.