Skip to content

Commit

Permalink
photo-mode: move to libtrx
Browse files Browse the repository at this point in the history
Resolves #2277.
  • Loading branch information
rr- committed Jan 13, 2025
1 parent 0ec2b4a commit 190fef0
Show file tree
Hide file tree
Showing 49 changed files with 316 additions and 133 deletions.
1 change: 1 addition & 0 deletions data/tr1/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@
"KEYMAP_CAMERA_DOWN": "Camera Down",
"KEYMAP_CAMERA_FORWARD": "Camera Forward",
"KEYMAP_CAMERA_LEFT": "Camera Left",
"KEYMAP_CAMERA_RESET": "Camera Reset",
"KEYMAP_CAMERA_RIGHT": "Camera Right",
"KEYMAP_CAMERA_UP": "Camera Up",
"KEYMAP_CHANGE_TARGET": "Change Target",
Expand Down
1 change: 1 addition & 0 deletions data/tr1/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"KEYMAP_CAMERA_DOWN": "Camera Down",
"KEYMAP_CAMERA_FORWARD": "Camera Forward",
"KEYMAP_CAMERA_LEFT": "Camera Left",
"KEYMAP_CAMERA_RESET": "Camera Reset",
"KEYMAP_CAMERA_RIGHT": "Camera Right",
"KEYMAP_CAMERA_UP": "Camera Up",
"KEYMAP_CHANGE_TARGET": "Change Target",
Expand Down
1 change: 1 addition & 0 deletions data/tr1/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"KEYMAP_CAMERA_DOWN": "Camera Down",
"KEYMAP_CAMERA_FORWARD": "Camera Forward",
"KEYMAP_CAMERA_LEFT": "Camera Left",
"KEYMAP_CAMERA_RESET": "Camera Reset",
"KEYMAP_CAMERA_RIGHT": "Camera Right",
"KEYMAP_CAMERA_UP": "Camera Up",
"KEYMAP_CHANGE_TARGET": "Change Target",
Expand Down
22 changes: 22 additions & 0 deletions data/tr2/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@
"HEADING_OPTION": "OPTION",
"KEYMAP_ACTION": "Action",
"KEYMAP_BACK": "Back",
"KEYMAP_CAMERA_BACK": "Camera Back",
"KEYMAP_CAMERA_DOWN": "Camera Down",
"KEYMAP_CAMERA_FORWARD": "Camera Forward",
"KEYMAP_CAMERA_LEFT": "Camera Left",
"KEYMAP_CAMERA_RESET": "Camera Reset",
"KEYMAP_CAMERA_RIGHT": "Camera Right",
"KEYMAP_CAMERA_UP": "Camera Up",
"KEYMAP_DRAW_WEAPON": "Draw Weapon",
"KEYMAP_ENTER_CONSOLE": "Dev Console",
"KEYMAP_FLY_CHEAT": "Fly Cheat",
Expand All @@ -435,11 +442,15 @@
"KEYMAP_RUN": "Run",
"KEYMAP_STEP_LEFT": "Step Left",
"KEYMAP_STEP_RIGHT": "Step Right",
"KEYMAP_TOGGLE_PHOTO_MODE": "Toggle Photo Mode",
"KEYMAP_TOGGLE_UI": "Toggle UI",
"KEYMAP_TURBO_CHEAT": "Turbo Speed",
"KEYMAP_USE_FLARE": "Flare",
"KEYMAP_WALK": "Walk",
"MISC_EXIT": "Exit",
"MISC_OFF": "Off",
"MISC_ON": "On",
"MISC_TOGGLE_HELP": "Toggle help",
"OSD_AMBIGUOUS_INPUT_2": "Ambiguous input: %s and %s",
"OSD_AMBIGUOUS_INPUT_3": "Ambiguous input: %s, %s, ...",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
Expand Down Expand Up @@ -480,6 +491,7 @@
"OSD_LOAD_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d",
"OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT": "Save slot %d is not available",
"OSD_OBJECT_NOT_FOUND": "Object not found",
"OSD_PHOTO_MODE_LAUNCHED": "Entering photo mode, press %s for help",
"OSD_PLAY_LEVEL": "Loading %s",
"OSD_POS_GET": "Level: %d (%s) Room: %d\nPosition: %.3f, %.3f, %.3f\nRotation: %.3f,%.3f,%.3f",
"OSD_POS_SET_ITEM": "Teleported to object: %s",
Expand All @@ -505,5 +517,15 @@
"PAUSE_PAUSED": "Paused",
"PAUSE_QUIT": "Quit",
"PAUSE_YES": "Yes",
"PHOTO_MODE_FOV_PROMPT": "Adjust FOV",
"PHOTO_MODE_FOV_ROLE": "Draw <+Walk>",
"PHOTO_MODE_MOVE_PROMPT": "Move camera",
"PHOTO_MODE_RESET_PROMPT": "Reset camera",
"PHOTO_MODE_ROLL_PROMPT": "Roll camera",
"PHOTO_MODE_ROLL_ROLE": "Sidestep L/R",
"PHOTO_MODE_ROTATE90_PROMPT": "Rotate 90 degrees",
"PHOTO_MODE_ROTATE_PROMPT": "Rotate camera",
"PHOTO_MODE_SNAP_PROMPT": "Take picture",
"PHOTO_MODE_TITLE": "Photo Mode",
},
}
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.8...develop) - ××××-××-××
- added Linux builds and toolchain (#1598)
- added pause dialog (#1638)
- added a photo mode feature (#2277)
- fixed showing inventory ring up/down arrows when uncalled for (#2225)
- fixed Lara never stepping backwards off a step using her right foot (#1602)
- fixed blood spawning on Lara from gunshots using incorrect positioning data (#2253)
Expand Down
1 change: 1 addition & 0 deletions docs/tr2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ game with new enhancements and features.
- free flare from underwater pickup
- drifting into walls during underwater pickups
- added a pause screen
- added a photo mode feature
- changed inventory to pause the music rather than muting it
- fixed killing the T-Rex with a grenade launcher crashing the game
- fixed secret rewards not displaying shotgun ammo
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/config/map_tr2.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CFG_INT32(g_Config, visuals.fov, 80)
CFG_BOOL(g_Config, visuals.use_pcx_fov, true)
CFG_DOUBLE(g_Config, ui.text_scale, 1.0)
CFG_DOUBLE(g_Config, ui.bar_scale, 1.0)
CFG_BOOL(g_Config, ui.enable_photo_mode_ui, true)
CFG_ENUM(g_Config, rendering.screenshot_format, SCREENSHOT_FORMAT_JPEG, SCREENSHOT_FORMAT)
CFG_ENUM(g_Config, rendering.render_mode, RM_HARDWARE, RENDER_MODE)
CFG_ENUM(g_Config, rendering.aspect_mode, AM_ANY, ASPECT_MODE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#include "game/camera/photo_mode.h"

#include "game/camera/common.h"
#include "game/camera/const.h"
#include "game/camera/enum.h"
#include "game/camera/vars.h"
#include "game/input.h"
#include "game/math.h"
#include "game/output.h"
#include "game/room.h"
#include "game/rooms.h"
#include "game/viewport.h"
#include "utils.h"

#include <libtrx/game/camera/common.h>
#include <libtrx/game/camera/vars.h>
#include <libtrx/game/math.h>
#include <libtrx/utils.h>
#if TR_VERSION == 1
// TODO: remove this call when consolidating the viewport API
extern void Output_ApplyFOV(void);
#endif

#define MIN_PHOTO_FOV 10
#define MAX_PHOTO_FOV 150
#define PHOTO_ROT_SHIFT (PHD_DEGREE * 4)
#define PHOTO_MAX_PITCH_ROLL (PHD_90 - PHD_DEGREE)
#define PHOTO_ROT_SHIFT (DEG_1 * 4)
#define PHOTO_MAX_PITCH_ROLL (DEG_90 - DEG_1)
#define PHOTO_MAX_SPEED 100

#define SHIFT_X(distance, elevation, angle) \
Expand Down Expand Up @@ -55,8 +60,12 @@ static void M_UpdatePhotoMode(void);
static void M_ResetCamera(void)
{
g_Camera = m_OldCamera;
#if TR_VERSION == 1
Viewport_SetFOV(m_OldFOV);
m_CurrentFOV = m_OldFOV / PHD_DEGREE;
#elif TR_VERSION == 2
Viewport_AlterFOV(m_OldFOV);
#endif
m_CurrentFOV = m_OldFOV / DEG_1;
}

static int32_t M_GetShiftSpeed(const int32_t val)
Expand All @@ -66,7 +75,7 @@ static int32_t M_GetShiftSpeed(const int32_t val)

static int32_t M_GetRotSpeed(void)
{
return MAX(PHD_DEGREE, M_GetShiftSpeed(PHOTO_ROT_SHIFT));
return MAX(DEG_1, M_GetShiftSpeed(PHOTO_ROT_SHIFT));
}

static void M_ShiftCamera(
Expand Down Expand Up @@ -102,7 +111,7 @@ static void M_RotateCamera(const int16_t angle, int16_t elevation)

static void M_RotateTarget(const int16_t angle)
{
const PHD_ANGLE elevation = g_Camera.target_elevation;
const int16_t elevation = g_Camera.target_elevation;
const int32_t distance = g_Camera.target_distance;
const XYZ_32 shift = {
.x = SHIFT_X(distance, elevation, angle),
Expand Down Expand Up @@ -154,10 +163,10 @@ static bool M_HandleShiftInputs(void)
bool result = false;

if (g_Input.camera_left) {
M_ShiftCamera(g_Camera.target_angle - PHD_90, 0, 0);
M_ShiftCamera(g_Camera.target_angle - DEG_90, 0, 0);
result = true;
} else if (g_Input.camera_right) {
M_ShiftCamera(g_Camera.target_angle + PHD_90, 0, 0);
M_ShiftCamera(g_Camera.target_angle + DEG_90, 0, 0);
result = true;
}

Expand All @@ -166,17 +175,17 @@ static bool M_HandleShiftInputs(void)
result = true;
} else if (g_Input.camera_back) {
M_ShiftCamera(
g_Camera.target_angle + PHD_180, g_Camera.target_elevation, 1);
g_Camera.target_angle + DEG_180, g_Camera.target_elevation, 1);
result = true;
}

if (g_Input.camera_up) {
M_ShiftCamera(
g_Camera.target_angle, g_Camera.target_elevation + PHD_90, -1);
g_Camera.target_angle, g_Camera.target_elevation + DEG_90, -1);
result = true;
} else if (g_Input.camera_down) {
M_ShiftCamera(
g_Camera.target_angle, g_Camera.target_elevation - PHD_90, -1);
g_Camera.target_angle, g_Camera.target_elevation - DEG_90, -1);
result = true;
}

Expand Down Expand Up @@ -224,7 +233,7 @@ static bool M_HandleTargetRotationInputs(void)
{
bool result = false;
if (g_InputDB.roll) {
M_RotateTarget(g_Camera.target_angle - PHD_90);
M_RotateTarget(g_Camera.target_angle - DEG_90);
result = true;
}
return result;
Expand All @@ -242,15 +251,23 @@ static bool M_HandleFOVInputs(void)
m_CurrentFOV++;
}
CLAMP(m_CurrentFOV, MIN_PHOTO_FOV, MAX_PHOTO_FOV);
Viewport_SetFOV(m_CurrentFOV * PHD_DEGREE);
#if TR_VERSION == 1
Viewport_SetFOV(m_CurrentFOV * DEG_1);
Output_ApplyFOV();
#elif TR_VERSION == 2
Viewport_AlterFOV(m_CurrentFOV * DEG_1);
#endif
return true;
}

void Camera_EnterPhotoMode(void)
{
#if TR_VERSION == 1
m_OldFOV = Viewport_GetFOV();
m_CurrentFOV = m_OldFOV / PHD_DEGREE;
#elif TR_VERSION == 2
m_OldFOV = Viewport_GetFOV(true);
#endif
m_CurrentFOV = m_OldFOV / DEG_1;
m_OldCamera = g_Camera;
g_Camera.type = CAM_PHOTO_MODE;
m_WorldBounds = Room_GetWorldBounds();
Expand All @@ -259,7 +276,11 @@ void Camera_EnterPhotoMode(void)

void Camera_ExitPhotoMode(void)
{
#if TR_VERSION == 1
Viewport_SetFOV(m_OldFOV);
#elif TR_VERSION == 2
Viewport_AlterFOV(m_OldFOV);
#endif
M_ResetCamera();
}

Expand All @@ -273,7 +294,7 @@ void Camera_UpdatePhotoMode(void)
const bool rot_target_input = g_InputDB.roll;
const bool roll_input = g_Input.step_left || g_Input.step_right;

PHD_ANGLE angles[2];
int16_t angles[2];
Math_GetVectorAngles(
g_Camera.target.x - g_Camera.pos.x, g_Camera.target.y - g_Camera.pos.y,
g_Camera.target.z - g_Camera.pos.z, angles);
Expand Down
Loading

0 comments on commit 190fef0

Please sign in to comment.