Skip to content

Commit

Permalink
phase/demo: support photo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 5, 2024
1 parent 7ff8214 commit 323d014
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
33 changes: 25 additions & 8 deletions src/tr1/game/phase/phase_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "global/const.h"
#include "global/types.h"
#include "global/vars.h"
#include "game/phase/phase_photo_mode.h"

#include <libtrx/memory.h>
#include <libtrx/utils.h>
Expand Down Expand Up @@ -55,7 +56,7 @@ static uint32_t *m_DemoPtr = NULL;
static bool M_ProcessInput(void);
static int32_t M_ChooseLevel(void);

static void M_Start(const void *args);
static void M_Start(const PHASE_DEMO_ARGS *args);
static void M_End(void);
static PHASE_CONTROL M_Run(int32_t nframes);
static PHASE_CONTROL M_FadeOut(void);
Expand Down Expand Up @@ -117,8 +118,18 @@ static int32_t M_ChooseLevel(void)
return level_num;
}

static void M_Start(const void *const args)
static void M_Start(const PHASE_DEMO_ARGS *const args)
{
m_DemoModeText = Text_Create(0, -16, GS(MISC_DEMO_MODE));
Text_Flash(m_DemoModeText, 1, 20);
Text_AlignBottom(m_DemoModeText, 1);
Text_CentreH(m_DemoModeText, 1);

if (args != NULL && args->resume_existing) {
// The demo is already playing and it's to be resumed.
return;
}

m_DemoLevel = M_ChooseLevel();

if (m_DemoLevel == -1) {
Expand Down Expand Up @@ -164,11 +175,6 @@ static void M_Start(const void *const args)
g_Config.target_mode = TLM_FULL;
g_Config.fix_bear_ai = false;

m_DemoModeText = Text_Create(0, -16, GS(MISC_DEMO_MODE));
Text_Flash(m_DemoModeText, 1, 20);
Text_AlignBottom(m_DemoModeText, 1);
Text_CentreH(m_DemoModeText, 1);

if (!Level_Initialise(m_DemoLevel)) {
Shell_ExitSystem("Unable to initialize level");
}
Expand Down Expand Up @@ -256,7 +262,18 @@ static PHASE_CONTROL M_Run(int32_t nframes)
g_Input = m_OldInput;
Input_Update();
Shell_ProcessInput();
if (g_InputDB.any) {
if (g_InputDB.toggle_photo_mode) {
PHASE_DEMO_ARGS *const demo_args =
Memory_Alloc(sizeof(PHASE_DEMO_ARGS));
demo_args->resume_existing = true;

PHASE_PHOTO_MODE_ARGS *const args =
Memory_Alloc(sizeof(PHASE_PHOTO_MODE_ARGS));
args->phase_to_return_to = PHASE_DEMO;
args->phase_arg = demo_args;
Phase_Set(PHASE_PHOTO_MODE, args);
return (PHASE_CONTROL) { .end = false };
} else if (g_InputDB.any) {
m_State = STATE_FADE_OUT;
goto end;
}
Expand Down
4 changes: 4 additions & 0 deletions src/tr1/game/phase/phase_demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

#include "game/phase/phase.h"

typedef struct {
bool resume_existing;
} PHASE_DEMO_ARGS;

extern PHASER g_DemoPhaser;
7 changes: 6 additions & 1 deletion src/tr1/game/phase/phase_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "global/const.h"
#include "global/types.h"
#include "global/vars.h"
#include "game/phase/phase_photo_mode.h"

#include <libtrx/memory.h>
#include <libtrx/utils.h>
Expand Down Expand Up @@ -108,7 +109,11 @@ static PHASE_CONTROL M_Control(int32_t nframes)
Phase_Set(PHASE_PAUSE, NULL);
return (PHASE_CONTROL) { .end = false };
} else if (g_InputDB.toggle_photo_mode) {
Phase_Set(PHASE_PHOTO_MODE, NULL);
PHASE_PHOTO_MODE_ARGS *const args =
Memory_Alloc(sizeof(PHASE_PHOTO_MODE_ARGS));
args->phase_to_return_to = PHASE_GAME;
args->phase_arg = NULL;
Phase_Set(PHASE_PHOTO_MODE, args);
return (PHASE_CONTROL) { .end = false };
} else {
Item_Control();
Expand Down
14 changes: 10 additions & 4 deletions src/tr1/game/phase/phase_photo_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <libtrx/game/console/common.h>
#include <libtrx/game/game_string.h>

#include <assert.h>
#include <stdio.h>

#define MIN_PHOTO_FOV 10
Expand All @@ -29,18 +30,22 @@ typedef enum {
static bool m_OldUIState;
static int32_t m_OldFOV;
static int32_t m_CurrentFOV;
static PHASE_PHOTO_MODE_ARGS m_Args;

static PHOTO_STATUS m_Status = PS_NONE;
static UI_WIDGET *m_PhotoMode = NULL;

static void M_Start(const void *args);
static void M_Start(const PHASE_PHOTO_MODE_ARGS *args);
static void M_End(void);
static PHASE_CONTROL M_Control(int32_t nframes);
static void M_Draw(void);
static void M_AdjustFOV(void);

static void M_Start(const void *const args)
static void M_Start(const PHASE_PHOTO_MODE_ARGS *const args)
{
assert(args != NULL);
m_Args = *args;

m_Status = PS_NONE;
g_OldInputDB = g_Input;
m_OldUIState = g_Config.ui.enable_ui;
Expand Down Expand Up @@ -91,7 +96,8 @@ static PHASE_CONTROL M_Control(int32_t nframes)
Shell_ProcessInput();

if (g_InputDB.toggle_photo_mode || g_InputDB.option) {
Phase_Set(PHASE_GAME, NULL);
Phase_Set(m_Args.phase_to_return_to, m_Args.phase_arg);
return (PHASE_CONTROL) { .end = false };
} else if (g_InputDB.action) {
m_Status = PS_ACTIVE;
} else {
Expand Down Expand Up @@ -141,7 +147,7 @@ static void M_Draw(void)
}

PHASER g_PhotoModePhaser = {
.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_photo_mode.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_PHOTO_MODE_ARGS;

extern PHASER g_PhotoModePhaser;

0 comments on commit 323d014

Please sign in to comment.