gym: move to trx

This commit is contained in:
Marcin Kurczewski 2025-04-20 16:33:33 +02:00
parent 7a4e188eaa
commit d8b83e4747
14 changed files with 135 additions and 133 deletions

123
src/libtrx/game/gym.c Normal file
View file

@ -0,0 +1,123 @@
#include "game/gym.h"
#include "game/const.h"
#include "game/game.h"
#include "game/game_flow.h"
#include "game/music.h"
#include "game/savegame.h"
#include "game/stats.h"
static bool m_IsInventoryOpenEnabled = true;
static bool m_IsAssaultTimerDisplay = false;
static bool m_IsAssaultTimerActive = false;
static uint32_t m_AssaultBestTime = -1;
static ASSAULT_STATS m_AssaultStats = {};
static bool M_StoreAssaultTime(uint32_t time);
static bool M_StoreAssaultTime(const uint32_t time)
{
int32_t insert_idx = -1;
for (int32_t i = 0; i < MAX_ASSAULT_TIMES; i++) {
if (m_AssaultStats.best_time[i] == 0
|| time < m_AssaultStats.best_time[i]) {
insert_idx = i;
break;
}
}
if (insert_idx == -1) {
return false;
}
for (int32_t i = MAX_ASSAULT_TIMES - 1; i > insert_idx; i--) {
m_AssaultStats.best_finish[i] = m_AssaultStats.best_finish[i - 1];
m_AssaultStats.best_time[i] = m_AssaultStats.best_time[i - 1];
}
m_AssaultStats.finish_count++;
m_AssaultStats.best_time[insert_idx] = time;
m_AssaultStats.best_finish[insert_idx] = m_AssaultStats.finish_count;
return true;
}
void Gym_SetInventoryOpenEnabled(const bool enabled)
{
m_IsInventoryOpenEnabled = enabled;
}
bool Gym_IsInventoryOpenEnabled(void)
{
return m_IsInventoryOpenEnabled;
}
bool Gym_IsAssaultTimerDisplay(void)
{
return m_IsAssaultTimerDisplay;
}
bool Gym_IsAssaultTimerActive(void)
{
return m_IsAssaultTimerActive;
}
ASSAULT_STATS Gym_GetAssaultStats(void)
{
return m_AssaultStats;
}
void Gym_ResetAssault(void)
{
m_IsAssaultTimerActive = false;
m_IsAssaultTimerDisplay = false;
}
void Gym_StartAssault(void)
{
RESUME_INFO *const resume = Savegame_GetCurrentInfo(Game_GetCurrentLevel());
resume->stats.timer = 0;
m_IsAssaultTimerActive = true;
m_IsAssaultTimerDisplay = true;
Stats_StartTimer();
}
void Gym_StopAssault(void)
{
m_IsAssaultTimerActive = false;
m_IsAssaultTimerDisplay = true;
}
void Gym_FinishAssault(void)
{
if (!m_IsAssaultTimerActive) {
return;
}
const RESUME_INFO *const resume =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
M_StoreAssaultTime(resume->stats.timer);
if ((int32_t)m_AssaultBestTime < 0) {
if (resume->stats.timer < 100 * LOGIC_FPS) {
// "Gosh! That was my best time yet!"
Music_Play(MX_GYM_HINT_15, MPM_ALWAYS);
m_AssaultBestTime = resume->stats.timer;
} else {
// "Congratulations! You did it! But perhaps I could've been
// faster."
Music_Play(MX_GYM_HINT_17, MPM_ALWAYS);
m_AssaultBestTime = 100 * LOGIC_FPS;
}
} else if (resume->stats.timer < m_AssaultBestTime) {
// "Gosh! That was my best time yet!"
Music_Play(MX_GYM_HINT_15, MPM_ALWAYS);
m_AssaultBestTime = resume->stats.timer;
} else if (resume->stats.timer < m_AssaultBestTime + 5 * LOGIC_FPS) {
// "Almost. Perhaps another try and I might beat it."
Music_Play(MX_GYM_HINT_16, MPM_ALWAYS);
} else {
// "Great. But nowhere near my best time."
Music_Play(MX_GYM_HINT_14, MPM_ALWAYS);
}
m_IsAssaultTimerActive = false;
}

View file

@ -10,7 +10,7 @@ typedef struct {
uint32_t finish_count; uint32_t finish_count;
} ASSAULT_STATS; } ASSAULT_STATS;
bool Gym_IsAccessible(void); extern bool Gym_IsAccessible(void);
void Gym_SetInventoryOpenEnabled(bool enabled); void Gym_SetInventoryOpenEnabled(bool enabled);
bool Gym_IsInventoryOpenEnabled(void); bool Gym_IsInventoryOpenEnabled(void);

View file

@ -1,3 +1,4 @@
#pragma once #pragma once
extern void Stats_StartTimer(void);
extern void Stats_ObserveItemsLoad(void); extern void Stats_ObserveItemsLoad(void);

View file

@ -136,6 +136,7 @@ sources = [
'game/game_string_table/priv.c', 'game/game_string_table/priv.c',
'game/game_string_table/reader.c', 'game/game_string_table/reader.c',
'game/gun/common.c', 'game/gun/common.c',
'game/gym.c',
'game/inject/common.c', 'game/inject/common.c',
'game/inject/data/anims.c', 'game/inject/data/anims.c',
'game/inject/data/meshes.c', 'game/inject/data/meshes.c',

View file

@ -12,7 +12,6 @@ int32_t Stats_GetSecrets(void);
void Stats_ComputeFinal(GF_LEVEL_TYPE level_type, FINAL_STATS *stats); void Stats_ComputeFinal(GF_LEVEL_TYPE level_type, FINAL_STATS *stats);
bool Stats_CheckAllSecretsCollected(GF_LEVEL_TYPE level_type); bool Stats_CheckAllSecretsCollected(GF_LEVEL_TYPE level_type);
void Stats_StartTimer(void);
void Stats_UpdateTimer(void); void Stats_UpdateTimer(void);
void Stats_UpdateSecrets(LEVEL_STATS *stats); void Stats_UpdateSecrets(LEVEL_STATS *stats);

View file

@ -5,7 +5,6 @@
#include "game/demo.h" #include "game/demo.h"
#include "game/effects.h" #include "game/effects.h"
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/gym.h"
#include "game/inventory.h" #include "game/inventory.h"
#include "game/item_actions.h" #include "game/item_actions.h"
#include "game/lara/cheat_keys.h" #include "game/lara/cheat_keys.h"
@ -23,6 +22,7 @@
#include "global/vars.h" #include "global/vars.h"
#include <libtrx/config.h> #include <libtrx/config.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/interpolation.h> #include <libtrx/game/interpolation.h>
bool Game_Start(const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx) bool Game_Start(const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx)

View file

@ -1,129 +1,8 @@
#include "game/gym.h"
#include "game/game.h"
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/music.h"
#include "game/savegame.h"
#include "game/stats.h"
#include "global/vars.h"
static bool m_IsInventoryOpenEnabled = true; #include <libtrx/game/gym.h>
static bool m_IsAssaultTimerDisplay = false;
static bool m_IsAssaultTimerActive = false;
static uint32_t m_AssaultBestTime = -1;
static ASSAULT_STATS m_AssaultStats = {};
static bool M_StoreAssaultTime(uint32_t time);
static bool M_StoreAssaultTime(const uint32_t time)
{
int32_t insert_idx = -1;
for (int32_t i = 0; i < MAX_ASSAULT_TIMES; i++) {
if (m_AssaultStats.best_time[i] == 0
|| time < m_AssaultStats.best_time[i]) {
insert_idx = i;
break;
}
}
if (insert_idx == -1) {
return false;
}
for (int32_t i = MAX_ASSAULT_TIMES - 1; i > insert_idx; i--) {
m_AssaultStats.best_finish[i] = m_AssaultStats.best_finish[i - 1];
m_AssaultStats.best_time[i] = m_AssaultStats.best_time[i - 1];
}
m_AssaultStats.finish_count++;
m_AssaultStats.best_time[insert_idx] = time;
m_AssaultStats.best_finish[insert_idx] = m_AssaultStats.finish_count;
return true;
}
bool Gym_IsAccessible(void) bool Gym_IsAccessible(void)
{ {
return g_GameFlow.gym_enabled && GF_GetGymLevel() != nullptr; return g_GameFlow.gym_enabled && GF_GetGymLevel() != nullptr;
} }
void Gym_SetInventoryOpenEnabled(const bool enabled)
{
m_IsInventoryOpenEnabled = enabled;
}
bool Gym_IsInventoryOpenEnabled(void)
{
return m_IsInventoryOpenEnabled;
}
bool Gym_IsAssaultTimerDisplay(void)
{
return m_IsAssaultTimerDisplay;
}
bool Gym_IsAssaultTimerActive(void)
{
return m_IsAssaultTimerActive;
}
ASSAULT_STATS Gym_GetAssaultStats(void)
{
return m_AssaultStats;
}
void Gym_ResetAssault(void)
{
m_IsAssaultTimerActive = false;
m_IsAssaultTimerDisplay = false;
}
void Gym_StartAssault(void)
{
RESUME_INFO *const resume = Savegame_GetCurrentInfo(Game_GetCurrentLevel());
resume->stats.timer = 0;
m_IsAssaultTimerActive = true;
m_IsAssaultTimerDisplay = true;
Stats_StartTimer();
}
void Gym_StopAssault(void)
{
m_IsAssaultTimerActive = false;
m_IsAssaultTimerDisplay = true;
}
void Gym_FinishAssault(void)
{
if (!m_IsAssaultTimerActive) {
return;
}
const RESUME_INFO *const resume =
Savegame_GetCurrentInfo(Game_GetCurrentLevel());
M_StoreAssaultTime(resume->stats.timer);
if ((int32_t)m_AssaultBestTime < 0) {
if (resume->stats.timer < 100 * FRAMES_PER_SECOND) {
// "Gosh! That was my best time yet!"
Music_Play(MX_GYM_HINT_15, MPM_ALWAYS);
m_AssaultBestTime = resume->stats.timer;
} else {
// "Congratulations! You did it! But perhaps I could've been
// faster."
Music_Play(MX_GYM_HINT_17, MPM_ALWAYS);
m_AssaultBestTime = 100 * FRAMES_PER_SECOND;
}
} else if (resume->stats.timer < m_AssaultBestTime) {
// "Gosh! That was my best time yet!"
Music_Play(MX_GYM_HINT_15, MPM_ALWAYS);
m_AssaultBestTime = resume->stats.timer;
} else if (
resume->stats.timer < m_AssaultBestTime + 5 * FRAMES_PER_SECOND) {
// "Almost. Perhaps another try and I might beat it."
Music_Play(MX_GYM_HINT_16, MPM_ALWAYS);
} else {
// "Great. But nowhere near my best time."
Music_Play(MX_GYM_HINT_14, MPM_ALWAYS);
}
m_IsAssaultTimerActive = false;
}

View file

@ -4,7 +4,6 @@
#include "game/demo.h" #include "game/demo.h"
#include "game/game.h" #include "game/game.h"
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/gym.h"
#include "game/input.h" #include "game/input.h"
#include "game/inventory.h" #include "game/inventory.h"
#include "game/inventory_ring/draw.h" #include "game/inventory_ring/draw.h"
@ -23,6 +22,7 @@
#include <libtrx/config.h> #include <libtrx/config.h>
#include <libtrx/game/gun/const.h> #include <libtrx/game/gun/const.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/interpolation.h> #include <libtrx/game/interpolation.h>
#include <libtrx/game/inventory_ring/priv.h> #include <libtrx/game/inventory_ring/priv.h>
#include <libtrx/game/matrix.h> #include <libtrx/game/matrix.h>

View file

@ -1,7 +1,6 @@
#include "game/item_actions.h" #include "game/item_actions.h"
#include "game/camera.h" #include "game/camera.h"
#include "game/gym.h"
#include "game/lara/hair.h" #include "game/lara/hair.h"
#include "game/random.h" #include "game/random.h"
#include "game/room.h" #include "game/room.h"
@ -12,6 +11,7 @@
#include "global/vars.h" #include "global/vars.h"
#include <libtrx/game/collision.h> #include <libtrx/game/collision.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/lara/common.h> #include <libtrx/game/lara/common.h>
#include <libtrx/utils.h> #include <libtrx/utils.h>

View file

@ -5,7 +5,6 @@
#include "game/creature.h" #include "game/creature.h"
#include "game/game.h" #include "game/game.h"
#include "game/gun/gun.h" #include "game/gun/gun.h"
#include "game/gym.h"
#include "game/input.h" #include "game/input.h"
#include "game/inventory.h" #include "game/inventory.h"
#include "game/item_actions.h" #include "game/item_actions.h"
@ -23,6 +22,7 @@
#include "game/stats.h" #include "game/stats.h"
#include "global/vars.h" #include "global/vars.h"
#include <libtrx/game/gym.h>
#include <libtrx/game/lara/const.h> #include <libtrx/game/lara/const.h>
#include <libtrx/game/math.h> #include <libtrx/game/math.h>
#include <libtrx/utils.h> #include <libtrx/utils.h>

View file

@ -5,7 +5,6 @@
#include "game/effects.h" #include "game/effects.h"
#include "game/game.h" #include "game/game.h"
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/gym.h"
#include "game/items.h" #include "game/items.h"
#include "game/lara/control.h" #include "game/lara/control.h"
#include "game/lot.h" #include "game/lot.h"
@ -29,6 +28,7 @@
#include <libtrx/filesystem.h> #include <libtrx/filesystem.h>
#include <libtrx/game/game_buf.h> #include <libtrx/game/game_buf.h>
#include <libtrx/game/game_string_table.h> #include <libtrx/game/game_string_table.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/inject.h> #include <libtrx/game/inject.h>
#include <libtrx/game/level.h> #include <libtrx/game/level.h>
#include <libtrx/game/objects/traps/movable_block.h> #include <libtrx/game/objects/traps/movable_block.h>

View file

@ -4,7 +4,6 @@
#include "game/clock.h" #include "game/clock.h"
#include "game/game.h" #include "game/game.h"
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/gym.h"
#include "game/inventory.h" #include "game/inventory.h"
#include "game/music.h" #include "game/music.h"
#include "game/objects/common.h" #include "game/objects/common.h"
@ -16,6 +15,7 @@
#include "global/vars.h" #include "global/vars.h"
#include <libtrx/config.h> #include <libtrx/config.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/matrix.h> #include <libtrx/game/matrix.h>
#include <libtrx/game/scaler.h> #include <libtrx/game/scaler.h>
#include <libtrx/utils.h> #include <libtrx/utils.h>

View file

@ -3,9 +3,8 @@
#include "global/types.h" #include "global/types.h"
#include <libtrx/game/game_flow.h> #include <libtrx/game/game_flow.h>
#include <libtrx/game/stats/types.h> #include <libtrx/game/stats.h>
void Stats_StartTimer(void);
void Stats_UpdateTimer(void); void Stats_UpdateTimer(void);
void Stats_CalculateStats(void); void Stats_CalculateStats(void);
int32_t Stats_GetSecrets(void); int32_t Stats_GetSecrets(void);

View file

@ -2,11 +2,11 @@
#include "game/game_flow.h" #include "game/game_flow.h"
#include "game/game_string.h" #include "game/game_string.h"
#include "game/gym.h"
#include "game/savegame.h" #include "game/savegame.h"
#include "game/stats.h" #include "game/stats.h"
#include <libtrx/debug.h> #include <libtrx/debug.h>
#include <libtrx/game/gym.h>
#include <libtrx/game/ui/common.h> #include <libtrx/game/ui/common.h>
#include <libtrx/game/ui/elements/anchor.h> #include <libtrx/game/ui/elements/anchor.h>
#include <libtrx/game/ui/elements/label.h> #include <libtrx/game/ui/elements/label.h>