Skip to content

Commit

Permalink
inventory: fix improper ring shutdown
Browse files Browse the repository at this point in the history
Resolves #1460.
  • Loading branch information
rr- committed Aug 29, 2024
1 parent e7a02ad commit 07555b7
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- fixed holstering pistols hiding the gun meshes 1 frame too early (#1449, regression from 0.6)
- fixed Lara's sliding animation sometimes being interrupted by a stumble (#1452, regression from 4.3)
- fixed cameras with glide values sometimes moving in the wrong direction (#1451, regression from 4.3)
- fixed console commands causing improper ring shutdown with selected inventory item (#1460, regression from 3.0)
- improved logs module names readability
- improved crash debug information on Windows

Expand Down
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include "config_map.h"
#include "game/input.h"
#include "game/music.h"
#include "game/requester.h"
#include "game/sound.h"
#include "global/const.h"
#include "global/enum_str.h"
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/config/config_file.h>
#include <libtrx/filesystem.h>
Expand Down Expand Up @@ -293,6 +295,8 @@ bool Config_Read(void)
Input_CheckConflicts(CM_CONTROLLER, g_Config.input.cntlr_layout);
Music_SetVolume(g_Config.music_volume);
Sound_SetMasterVolume(g_Config.sound_volume);
Requester_Shutdown(&g_SavegameRequester);
Requester_Init(&g_SavegameRequester, g_Config.maximum_save_slots);
return result;
}

Expand Down
15 changes: 15 additions & 0 deletions src/game/inventory/inventory_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ void Inv_Ring_Active(INVENTORY_ITEM *inv_item)
}
}

void Inv_Ring_ResetItem(INVENTORY_ITEM *const inv_item)
{
inv_item->drawn_meshes = inv_item->which_meshes;
inv_item->current_frame = 0;
inv_item->goal_frame = inv_item->current_frame;
inv_item->pt_xrot = 0;
inv_item->x_rot = 0;
inv_item->y_rot = 0;
inv_item->ytrans = 0;
inv_item->ztrans = 0;
if (inv_item->object_number == O_PASSPORT_OPTION) {
inv_item->object_number = O_PASSPORT_CLOSED;
}
}

void Inv_Ring_GetView(RING_INFO *ring, XYZ_32 *view_pos, XYZ_16 *view_rot)
{
PHD_ANGLE angles[2];
Expand Down
1 change: 1 addition & 0 deletions src/game/inventory/inventory_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void Inv_Ring_InitHeader(RING_INFO *ring);
void Inv_Ring_RemoveHeader(RING_INFO *ring);
void Inv_Ring_RemoveAllText(void);
void Inv_Ring_Active(INVENTORY_ITEM *inv_item);
void Inv_Ring_ResetItem(INVENTORY_ITEM *inv_item);

void Inv_Ring_GetView(RING_INFO *ring, XYZ_32 *view_pos, XYZ_16 *view_rot);
void Inv_Ring_Light(RING_INFO *ring);
Expand Down
3 changes: 1 addition & 2 deletions src/game/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
#include "global/types.h"

void Option_DoInventory(INVENTORY_ITEM *inv_item);
void Option_Init(void);
void Option_Shutdown(void);
void Option_Shutdown(INVENTORY_ITEM *inv_item);
34 changes: 28 additions & 6 deletions src/game/option/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,36 @@

static CONTROL_MODE m_ControlMode = CM_PICK;

void Option_Init(void)
void Option_Shutdown(INVENTORY_ITEM *inv_item)
{
Option_PassportInit();
}
switch (inv_item->object_number) {
case O_PASSPORT_OPTION:
Option_Passport_Shutdown();
break;

void Option_Shutdown(void)
{
Option_PassportShutdown();
case O_MAP_OPTION:
Option_Compass_Shutdown();
break;

case O_DETAIL_OPTION:
Option_Graphics_Shutdown();
break;

case O_SOUND_OPTION:
Option_Sound_Shutdown();
break;

case O_CONTROL_OPTION:
if (m_ControlMode == CM_PICK) {
Option_ControlPick_Shutdown();
} else {
Option_Control_Shutdown();
}
break;

default:
break;
}
}

void Option_DoInventory(INVENTORY_ITEM *inv_item)
Expand Down
18 changes: 14 additions & 4 deletions src/game/option/option_compass.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ static void Option_Compass_InitText(void)
}
}

static void Option_Compass_ShutdownText(void)
{
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
}

void Option_Compass(INVENTORY_ITEM *inv_item)
{
if (g_Config.enable_compass_stats) {
Expand Down Expand Up @@ -131,11 +139,13 @@ void Option_Compass(INVENTORY_ITEM *inv_item)
}

if (g_InputDB.menu_confirm || g_InputDB.menu_back) {
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
Option_Compass_ShutdownText();
inv_item->goal_frame = inv_item->frames_total - 1;
inv_item->anim_direction = 1;
}
}

void Option_Compass_Shutdown(void)
{
Option_Compass_ShutdownText();
}
1 change: 1 addition & 0 deletions src/game/option/option_compass.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include "global/types.h"

void Option_Compass(INVENTORY_ITEM *inv_item);
void Option_Compass_Shutdown(void);
5 changes: 5 additions & 0 deletions src/game/option/option_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,8 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode)

return mode;
}

void Option_Control_Shutdown(void)
{
Option_Control_ShutdownText();
}
1 change: 1 addition & 0 deletions src/game/option/option_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include <stdbool.h>

CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode);
void Option_Control_Shutdown(void);
5 changes: 5 additions & 0 deletions src/game/option/option_control_pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ CONTROL_MODE Option_ControlPick(void)

return CM_PICK;
}

void Option_ControlPick_Shutdown(void)
{
Option_ControlPick_ShutdownText();
}
1 change: 1 addition & 0 deletions src/game/option/option_control_pick.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include "global/types.h"

CONTROL_MODE Option_ControlPick(void);
void Option_ControlPick_Shutdown(void);
37 changes: 18 additions & 19 deletions src/game/option/option_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ static void Option_Graphics_MenuUp(void);
static void Option_Graphics_MenuDown(void);
static void Option_Graphics_InitText(void);
static void Option_Graphics_UpdateText(void);
static void Option_Graphics_Shutdown(void);
static void Option_Graphics_UpdateArrows(
GRAPHICS_OPTION_NAME option_name, TEXTSTRING value_text, bool more_up,
bool more_down);
Expand Down Expand Up @@ -248,24 +247,6 @@ static void Option_Graphics_UpdateText(void)
}
}

static void Option_Graphics_Shutdown(void)
{
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
for (int i = 0; i < OPTION_NUMBER_OF; i++) {
Text_Remove(m_GraphicsMenu.option_texts[i]);
m_GraphicsMenu.option_texts[i] = NULL;
Text_Remove(m_GraphicsMenu.value_texts[i]);
m_GraphicsMenu.value_texts[i] = NULL;
}
m_IsTextInit = false;
m_HideArrowLeft = false;
m_HideArrowRight = false;
Option_Graphics_InitMenu();
}

static void Option_Graphics_UpdateArrows(
GRAPHICS_OPTION_NAME option_name, TEXTSTRING value_text, bool more_up,
bool more_down)
Expand Down Expand Up @@ -666,3 +647,21 @@ void Option_Graphics(INVENTORY_ITEM *inv_item)
Config_Write();
}
}

void Option_Graphics_Shutdown(void)
{
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
for (int i = 0; i < OPTION_NUMBER_OF; i++) {
Text_Remove(m_GraphicsMenu.option_texts[i]);
m_GraphicsMenu.option_texts[i] = NULL;
Text_Remove(m_GraphicsMenu.value_texts[i]);
m_GraphicsMenu.value_texts[i] = NULL;
}
m_IsTextInit = false;
m_HideArrowLeft = false;
m_HideArrowRight = false;
Option_Graphics_InitMenu();
}
1 change: 1 addition & 0 deletions src/game/option/option_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include "global/types.h"

void Option_Graphics(INVENTORY_ITEM *inv_item);
void Option_Graphics_Shutdown(void);
22 changes: 13 additions & 9 deletions src/game/option/option_passport.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ REQUEST_INFO g_SavegameRequester = {
.items = NULL,
};

static void Option_Passport_InitRequesters(void);
static void Option_Passport_InitText(void);
static void Option_Passport_ShutdownText(void);
static void Option_Passport_Close(INVENTORY_ITEM *inv_item);
Expand All @@ -113,18 +114,12 @@ static void Option_Passport_Restart(INVENTORY_ITEM *inv_item);
static void Option_Passport_FlipRight(INVENTORY_ITEM *inv_item);
static void Option_Passport_FlipLeft(INVENTORY_ITEM *inv_item);

void Option_Passport_Init(void)
void Option_Passport_InitRequesters(void)
{
Requester_Init(&g_SavegameRequester, g_Config.maximum_save_slots);
Requester_Init(&m_SelectLevelRequester, g_GameFlow.level_count + 1);
Requester_Init(&m_NewGameRequester, MAX_GAME_MODES);
}

void Option_Passport_Shutdown(void)
{
Requester_Shutdown(&g_SavegameRequester);
Requester_Shutdown(&m_SelectLevelRequester);
Requester_Shutdown(&m_NewGameRequester);
Requester_Init(&m_SelectLevelRequester, g_GameFlow.level_count + 1);
Requester_Init(&m_NewGameRequester, MAX_GAME_MODES);
}

static void Option_Passport_InitText(void)
Expand Down Expand Up @@ -595,6 +590,7 @@ static void Option_Passport_FlipLeft(INVENTORY_ITEM *inv_item)
void Option_Passport(INVENTORY_ITEM *inv_item)
{
if (!m_IsTextInit) {
Option_Passport_InitRequesters();
Text_Remove(g_InvItemText[IT_NAME]);
g_InvItemText[IT_NAME] = NULL;
Text_Remove(g_InvRingText);
Expand Down Expand Up @@ -690,3 +686,11 @@ void Option_Passport(INVENTORY_ITEM *inv_item)
Option_Passport_Close(inv_item);
}
}

void Option_Passport_Shutdown(void)
{
Option_Passport_ShutdownText();
Requester_Shutdown(&m_SelectLevelRequester);
Requester_Shutdown(&m_NewGameRequester);
Requester_Shutdown(&g_SavegameRequester);
}
1 change: 0 additions & 1 deletion src/game/option/option_passport.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
#include "global/types.h"

void Option_Passport(INVENTORY_ITEM *inv_item);
void Option_Passport_Init(void);
void Option_Passport_Shutdown(void);
13 changes: 9 additions & 4 deletions src/game/option/option_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ void Option_Sound(INVENTORY_ITEM *inv_item)
}

if (g_InputDB.menu_confirm || g_InputDB.menu_back) {
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
Option_Sound_Shutdown();
}
}

void Option_Sound_Shutdown(void)
{
for (int i = 0; i < TEXT_NUMBER_OF; i++) {
Text_Remove(m_Text[i]);
m_Text[i] = NULL;
}
}
1 change: 1 addition & 0 deletions src/game/option/option_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include "global/types.h"

void Option_Sound(INVENTORY_ITEM *inv_item);
void Option_Sound_Shutdown(void);
16 changes: 7 additions & 9 deletions src/game/phase/phase_inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,11 @@ static void Inv_Construct(void)
}

for (int i = 0; i < g_InvMainObjects; i++) {
INVENTORY_ITEM *inv_item = g_InvMainList[i];
inv_item->drawn_meshes = inv_item->which_meshes;
inv_item->current_frame = 0;
inv_item->goal_frame = inv_item->current_frame;
inv_item->y_rot = 0;
Inv_Ring_ResetItem(g_InvMainList[i]);
}

for (int i = 0; i < g_InvOptionObjects; i++) {
INVENTORY_ITEM *inv_item = g_InvOptionList[i];
inv_item->current_frame = 0;
inv_item->goal_frame = 0;
inv_item->y_rot = 0;
Inv_Ring_ResetItem(g_InvOptionList[i]);
}

g_InvMainCurrent = 0;
Expand Down Expand Up @@ -1109,6 +1102,11 @@ static GAMEFLOW_COMMAND Phase_Inventory_Control(int32_t nframes)

static void Phase_Inventory_End(void)
{
INVENTORY_ITEM *const inv_item = m_Ring.list[m_Ring.current_object];
if (inv_item != NULL) {
Option_Shutdown(inv_item);
}

Inv_Destroy();
if (g_Config.enable_buffering) {
g_OldInputDB.any = 0;
Expand Down
14 changes: 9 additions & 5 deletions src/game/requester.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ void Requester_Shutdown(REQUEST_INFO *req)
Requester_ClearTextstrings(req);

Memory_FreePointer(&req->heading_text);
for (int i = 0; i < req->max_items; i++) {
Memory_FreePointer(&req->items[i].content_text);
if (req->items != NULL) {
for (int i = 0; i < req->max_items; i++) {
Memory_FreePointer(&req->items[i].content_text);
}
}
Memory_FreePointer(&req->items);
}
Expand All @@ -66,9 +68,11 @@ void Requester_ClearTextstrings(REQUEST_INFO *req)
Text_Remove(req->moredown);
req->moredown = NULL;

for (int i = 0; i < req->max_items; i++) {
Text_Remove(req->items[i].content);
req->items[i].content = NULL;
if (req->items != NULL) {
for (int i = 0; i < req->max_items; i++) {
Text_Remove(req->items[i].content);
req->items[i].content = NULL;
}
}

req->items_used = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ void Shell_Init(const char *gameflow_path)
return;
}

Option_Init();
Savegame_ScanSavedGames();
Savegame_HighlightNewestSlot();

Expand All @@ -151,7 +150,6 @@ void Shell_Shutdown(void)
Sound_Shutdown();
Music_Shutdown();
Savegame_Shutdown();
Option_Shutdown();
Console_Shutdown();
Log_Shutdown();
}
Expand Down
2 changes: 1 addition & 1 deletion subprojects/libtrx

0 comments on commit 07555b7

Please sign in to comment.