Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory ring work #2228

Merged
merged 18 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/tr2/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@
"CONTROL_CUSTOM_2": "User Keys 2",
"CONTROL_CUSTOM_3": "User Keys 3",
"CONTROL_DEFAULT_KEYS": "Default Keys",
"HEADING_GAME_OVER": "GAME OVER",
"HEADING_INVENTORY": "INVENTORY",
"HEADING_ITEMS": "ITEMS",
"HEADING_OPTION": "OPTION",
"KEYMAP_ACTION": "Action",
"KEYMAP_BACK": "Back",
"KEYMAP_DRAW_WEAPON": "Draw Weapon",
Expand Down
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.8...develop) - ××××-××-××
- added Linux builds and toolchain (#1598)
- fixed showing inventory ring up/down arrows when uncalled for (#2225)
- fixed Lara activating triggers one frame too early (#2205, regression from 0.7)
- fixed Lara never stepping backwards off a step using her right foot (#1602)

Expand Down
6 changes: 3 additions & 3 deletions src/libtrx/game/console/cmd/pos.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx)
lara_item->pos.x / (float)WALL_L,
lara_item->pos.y / (float)WALL_L,
lara_item->pos.z / (float)WALL_L,
lara_item->rot.x * 360.0f / (float)PHD_ONE,
lara_item->rot.y * 360.0f / (float)PHD_ONE,
lara_item->rot.z * 360.0f / (float)PHD_ONE);
lara_item->rot.x * 360.0f / (float)DEG_360,
lara_item->rot.y * 360.0f / (float)DEG_360,
lara_item->rot.z * 360.0f / (float)DEG_360);
// clang-format on

return CR_SUCCESS;
Expand Down
45 changes: 45 additions & 0 deletions src/libtrx/game/interpolation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "game/interpolation.h"

#include "config.h"

#include <stdint.h>

static bool m_IsEnabled = true;
static double m_Rate = 0.0;

static int32_t M_GetFPS(void)
{
#if TR_VERSION == 1
return g_Config.rendering.fps;
#elif TR_VERSION == 2
return 30;
#endif
}

bool Interpolation_IsEnabled(void)
{
return m_IsEnabled && M_GetFPS() == 60;
}

void Interpolation_Disable(void)
{
m_IsEnabled = false;
}

void Interpolation_Enable(void)
{
m_IsEnabled = true;
}

double Interpolation_GetRate(void)
{
if (!Interpolation_IsEnabled()) {
return 1.0;
}
return m_Rate;
}

void Interpolation_SetRate(double rate)
{
m_Rate = rate;
}
82 changes: 82 additions & 0 deletions src/libtrx/game/inventory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "game/inventory.h"

#include "game/inventory_ring/vars.h"
#include "game/objects/vars.h"

bool Inv_AddItemNTimes(const GAME_OBJECT_ID object_id, const int32_t qty)
{
bool result = false;
Expand All @@ -8,3 +11,82 @@ bool Inv_AddItemNTimes(const GAME_OBJECT_ID object_id, const int32_t qty)
}
return result;
}

GAME_OBJECT_ID Inv_GetItemOption(const GAME_OBJECT_ID object_id)
{
if (Object_IsObjectType(object_id, g_InvObjects)) {
return object_id;
}
return Object_GetCognate(object_id, g_ItemToInvObjectMap);
}

void Inv_InsertItem(INVENTORY_ITEM *const inv_item)
{
INV_RING_SOURCE *const source =
&g_InvRing_Source[inv_item->inv_pos < 100 ? RT_MAIN : RT_KEYS];

int32_t n;
for (n = 0; n < source->count; n++) {
if (source->items[n]->inv_pos > inv_item->inv_pos) {
break;
}
}

for (int32_t i = source->count; i > n - 1; i--) {
source->items[i + 1] = source->items[i];
source->qtys[i + 1] = source->qtys[i];
}
source->items[n] = inv_item;
source->qtys[n] = 1;
source->count++;
}

bool Inv_RemoveItem(const GAME_OBJECT_ID object_id)
{
const GAME_OBJECT_ID inv_object_id = Inv_GetItemOption(object_id);
for (RING_TYPE ring_type = 0; ring_type < RT_NUMBER_OF; ring_type++) {
INV_RING_SOURCE *const source = &g_InvRing_Source[ring_type];
for (int32_t i = 0; i < source->count; i++) {
if (source->items[i]->object_id == inv_object_id) {
source->qtys[i]--;
if (source->qtys[i] == 0) {
source->count--;
for (int32_t j = i; j < source->count; j++) {
source->items[j] = source->items[j + 1];
source->qtys[j] = source->qtys[j + 1];
}
}
return true;
}
}
}
return false;
}

int32_t Inv_RequestItem(const GAME_OBJECT_ID object_id)
{
const GAME_OBJECT_ID inv_object_id = Inv_GetItemOption(object_id);
for (RING_TYPE ring_type = 0; ring_type < RT_NUMBER_OF; ring_type++) {
INV_RING_SOURCE *const source = &g_InvRing_Source[ring_type];
for (int32_t i = 0; i < source->count; i++) {
if (source->items[i]->object_id == inv_object_id) {
return source->qtys[i];
}
}
}
return 0;
}

void Inv_ClearSelection(void)
{
g_InvRing_Source[RT_MAIN].current = 0;
g_InvRing_Source[RT_KEYS].current = 0;
}

void Inv_RemoveAllItems(void)
{
// leave only the first item, which is the compass / stopwatch
g_InvRing_Source[RT_MAIN].count = 1;
g_InvRing_Source[RT_KEYS].count = 0;
Inv_ClearSelection();
}
Loading
Loading