Skip to content

Commit

Permalink
phase/cutscene: support photo mode
Browse files Browse the repository at this point in the history
Resolves #1672.
  • Loading branch information
rr- committed Oct 5, 2024
1 parent 323d014 commit 2c4514b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/tr1/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,18 @@ static void M_LoadCutsceneFrame(void)
g_Camera.target.y = g_CinePosition.pos.y + ref->ty;
g_Camera.target.z =
g_CinePosition.pos.z + ((c * ref->tz - s * ref->tx) >> W2V_SHIFT);

g_Camera.pos.x =
g_CinePosition.pos.x + ((s * ref->cz + c * ref->cx) >> W2V_SHIFT);
g_Camera.pos.y = g_CinePosition.pos.y + ref->cy;
g_Camera.pos.z =
g_CinePosition.pos.z + ((c * ref->cz - s * ref->cx) >> W2V_SHIFT);

g_Camera.pos.room_num =
Room_GetIndexFromPos(g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z);
g_Camera.target.room_num = Room_GetIndexFromPos(
g_Camera.target.x, g_Camera.target.y, g_Camera.target.z);

g_Camera.roll = ref->roll;
g_Camera.shift = 0;

Expand All @@ -265,6 +272,7 @@ static void M_UpdatePhotoMode(void)
if (!m_PhotoMode) {
m_OldCamera = g_Camera;
m_PhotoMode = true;
m_WorldBounds = Room_GetWorldBounds();
}

const bool axis_shift_input = g_Input.camera_up || g_Input.camera_down;
Expand Down Expand Up @@ -847,14 +855,14 @@ static void M_Shift(
void Camera_Initialise(void)
{
m_WorldBounds = Room_GetWorldBounds();
m_PhotoMode = false;
m_Roll = 0;
Camera_ResetPosition();
Camera_Update();
}

void Camera_Reset(void)
{
m_PhotoMode = false;
m_Roll = 0;
g_Camera.pos.room_num = NO_ROOM;
}

Expand Down Expand Up @@ -1047,8 +1055,8 @@ void Camera_UpdateCutscene(void)
{
const CINE_CAMERA *const ref = &g_CineCamera[g_CineFrame];

const int32_t c = Math_Cos(g_Camera.target_angle);
const int32_t s = Math_Sin(g_Camera.target_angle);
const int32_t c = Math_Cos(g_CinePosition.rot.x);
const int32_t s = Math_Sin(g_CinePosition.rot.x);
const XYZ_32 *const pos = &g_CinePosition.pos;
g_Camera.target.x = pos->x + ((ref->tx * c + ref->tz * s) >> W2V_SHIFT);
g_Camera.target.y = pos->y + ref->ty;
Expand All @@ -1059,6 +1067,11 @@ void Camera_UpdateCutscene(void)
g_Camera.roll = ref->roll;
g_Camera.shift = 0;

g_Camera.pos.room_num =
Room_GetIndexFromPos(g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z);
g_Camera.target.room_num = Room_GetIndexFromPos(
g_Camera.target.x, g_Camera.target.y, g_Camera.target.z);

Viewport_SetFOV(ref->fov);
}

Expand Down
4 changes: 2 additions & 2 deletions src/tr1/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ GameFlow_InterpretSequence(int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type)
g_CinePosition.pos.z = (int32_t)(intptr_t)seq->data;
break;
case GFS_SET_CAM_ANGLE:
g_Camera.target_angle = (int32_t)(intptr_t)seq->data;
g_CinePosition.rot.x = (int32_t)(intptr_t)seq->data;
break;
case GFS_FLIP_MAP:
Room_FlipMap();
Expand Down Expand Up @@ -1365,7 +1365,7 @@ GameFlow_StorySoFar(int32_t level_num, int32_t savegame_level)
g_CinePosition.pos.z = (int32_t)(intptr_t)seq->data;
break;
case GFS_SET_CAM_ANGLE:
g_Camera.target_angle = (int32_t)(intptr_t)seq->data;
g_CinePosition.rot.x = (int32_t)(intptr_t)seq->data;
break;
case GFS_FLIP_MAP:
Room_FlipMap();
Expand Down
4 changes: 2 additions & 2 deletions src/tr1/game/objects/creatures/cutscene_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void CutscenePlayer_Initialise(int16_t item_num)
g_CinePosition.pos.x = item->pos.x;
g_CinePosition.pos.y = item->pos.y;
g_CinePosition.pos.z = item->pos.z;
g_Camera.target_angle = 0;
g_CinePosition.rot.x = 0;
}
item->rot.y = 0;
}
Expand All @@ -29,7 +29,7 @@ void CutscenePlayer_Control(int16_t item_num)
{
ITEM *const item = &g_Items[item_num];
if (item->object_id != O_PLAYER_4) {
item->rot.y = g_Camera.target_angle;
item->rot.y = g_CinePosition.rot.x;
item->pos.x = g_CinePosition.pos.x;
item->pos.y = g_CinePosition.pos.y;
item->pos.z = g_CinePosition.pos.z;
Expand Down
31 changes: 31 additions & 0 deletions src/tr1/game/phase/phase_cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
#include "global/const.h"
#include "global/types.h"
#include "global/vars.h"
#include "game/phase/phase_photo_mode.h"

#include <libtrx/memory.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

static bool m_ExitingToPhotoMode = false;

static void M_InitialiseHair(int32_t level_num);

static void M_Start(const PHASE_CUTSCENE_ARGS *args);
Expand Down Expand Up @@ -65,6 +68,13 @@ static void M_InitialiseHair(int32_t level_num)

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

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

Output_FadeReset();

if (!Level_Initialise(args->level_num)) {
Expand Down Expand Up @@ -94,6 +104,12 @@ static void M_Start(const PHASE_CUTSCENE_ARGS *const args)

static void M_End(void)
{
if (m_ExitingToPhotoMode) {
// Need to ensure we always exit the photo mode.
Camera_Reset();
return;
}

Music_Stop();
Sound_StopAllSamples();
}
Expand Down Expand Up @@ -134,6 +150,21 @@ static PHASE_CONTROL M_Control(int32_t nframes)
Lara_Hair_Control();
Camera_UpdateCutscene();

if (g_InputDB.toggle_photo_mode) {
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;
return (PHASE_CONTROL) { .end = false };
}

g_CineFrame++;
}

Expand Down
1 change: 1 addition & 0 deletions src/tr1/game/phase/phase_cutscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdint.h>

typedef struct {
bool resume_existing;
int32_t level_num;
} PHASE_CUTSCENE_ARGS;

Expand Down

0 comments on commit 2c4514b

Please sign in to comment.