-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
game-flow: move common bits to libtrx
- Loading branch information
Showing
20 changed files
with
333 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,56 @@ | ||
#include "game/game_flow/sequencer.h" | ||
|
||
#include "config.h" | ||
#include "game/inventory_ring/control.h" | ||
#include "game/objects/vars.h" | ||
#include "game/phase.h" | ||
#include "debug.h" | ||
#include "enum_map.h" | ||
#include "game/game_flow/sequencer_priv.h" | ||
|
||
GF_COMMAND GF_EnterPhotoMode(void) | ||
GF_COMMAND GF_InterpretSequence( | ||
const GF_LEVEL *const level, GF_SEQUENCE_CONTEXT seq_ctx, | ||
void *const seq_ctx_arg) | ||
{ | ||
PHASE *const subphase = Phase_PhotoMode_Create(); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(subphase); | ||
Phase_PhotoMode_Destroy(subphase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_PauseGame(void) | ||
{ | ||
PHASE *const subphase = Phase_Pause_Create(); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(subphase); | ||
Phase_Pause_Destroy(subphase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_ShowInventory(const INVENTORY_MODE mode) | ||
{ | ||
PHASE *const phase = Phase_Inventory_Create(mode); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(phase); | ||
Phase_Inventory_Destroy(phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_ShowInventoryKeys(const GAME_OBJECT_ID receptacle_type_id) | ||
{ | ||
if (g_Config.gameplay.enable_auto_item_selection) { | ||
const GAME_OBJECT_ID object_id = Object_GetCognateInverse( | ||
receptacle_type_id, g_KeyItemToReceptacleMap); | ||
InvRing_SetRequestedObjectID(object_id); | ||
ASSERT(level != nullptr); | ||
LOG_DEBUG( | ||
"running sequence for level=%d type=%d seq_ctx=%d", level->num, | ||
level->type, seq_ctx); | ||
|
||
GF_PreSequenceHook(); | ||
|
||
GF_COMMAND gf_cmd = { .action = GF_EXIT_TO_TITLE }; | ||
|
||
const GF_SEQUENCE *const sequence = &level->sequence; | ||
for (int32_t i = 0; i < sequence->length; i++) { | ||
const GF_SEQUENCE_EVENT *const event = &sequence->events[i]; | ||
LOG_DEBUG( | ||
"event type=%s(%d) data=0x%x", | ||
ENUM_MAP_TO_STRING(GF_SEQUENCE_EVENT_TYPE, event->type), | ||
event->type, event->data); | ||
|
||
if (GF_ShouldSkipSequenceEvent(level, event)) { | ||
continue; | ||
} | ||
|
||
// Handle the event | ||
if (event->type < GFS_NUMBER_OF | ||
&& GF_GetSequenceEventHandler(event->type) != nullptr) { | ||
gf_cmd = GF_GetSequenceEventHandler(event->type)( | ||
level, event, seq_ctx, seq_ctx_arg); | ||
LOG_DEBUG( | ||
"event type=%s(%d) data=0x%x finished, result: action=%s, " | ||
"param=%d", | ||
ENUM_MAP_TO_STRING(GF_SEQUENCE_EVENT_TYPE, event->type), | ||
event->type, event->data, | ||
ENUM_MAP_TO_STRING(GF_ACTION, gf_cmd.action), gf_cmd.param); | ||
if (gf_cmd.action != GF_NOOP) { | ||
return gf_cmd; | ||
} | ||
} | ||
|
||
// Update sequence context if necessary | ||
seq_ctx = GF_SwitchSequenceContext(event, seq_ctx); | ||
} | ||
return GF_ShowInventory(INV_KEYS_MODE); | ||
} | ||
|
||
GF_COMMAND GF_RunDemo(const int32_t demo_num) | ||
{ | ||
PHASE *const demo_phase = Phase_Demo_Create(demo_num); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(demo_phase); | ||
Phase_Demo_Destroy(demo_phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_RunCutscene(const int32_t cutscene_num) | ||
{ | ||
PHASE *const cutscene_phase = Phase_Cutscene_Create(cutscene_num); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(cutscene_phase); | ||
Phase_Cutscene_Destroy(cutscene_phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_RunGame( | ||
const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx) | ||
{ | ||
PHASE *const phase = Phase_Game_Create(level, seq_ctx); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(phase); | ||
Phase_Game_Destroy(phase); | ||
LOG_DEBUG( | ||
"sequence finished: action=%s param=%d", | ||
ENUM_MAP_TO_STRING(GF_ACTION, gf_cmd.action), gf_cmd.param); | ||
return gf_cmd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "config.h" | ||
#include "game/demo.h" | ||
#include "game/game_flow/common.h" | ||
#include "game/game_flow/sequencer.h" | ||
#include "game/game_flow/vars.h" | ||
#include "game/inventory_ring/control.h" | ||
#include "game/objects/vars.h" | ||
#include "game/phase.h" | ||
#include "log.h" | ||
|
||
GF_COMMAND GF_EnterPhotoMode(void) | ||
{ | ||
PHASE *const subphase = Phase_PhotoMode_Create(); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(subphase); | ||
Phase_PhotoMode_Destroy(subphase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_PauseGame(void) | ||
{ | ||
PHASE *const subphase = Phase_Pause_Create(); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(subphase); | ||
Phase_Pause_Destroy(subphase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_ShowInventory(const INVENTORY_MODE mode) | ||
{ | ||
PHASE *const phase = Phase_Inventory_Create(mode); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(phase); | ||
Phase_Inventory_Destroy(phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_ShowInventoryKeys(const GAME_OBJECT_ID receptacle_type_id) | ||
{ | ||
if (g_Config.gameplay.enable_auto_item_selection) { | ||
const GAME_OBJECT_ID object_id = Object_GetCognateInverse( | ||
receptacle_type_id, g_KeyItemToReceptacleMap); | ||
InvRing_SetRequestedObjectID(object_id); | ||
} | ||
return GF_ShowInventory(INV_KEYS_MODE); | ||
} | ||
|
||
GF_COMMAND GF_RunDemo(const int32_t demo_num) | ||
{ | ||
PHASE *const demo_phase = Phase_Demo_Create(demo_num); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(demo_phase); | ||
Phase_Demo_Destroy(demo_phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_RunCutscene(const int32_t cutscene_num) | ||
{ | ||
PHASE *const cutscene_phase = Phase_Cutscene_Create(cutscene_num); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(cutscene_phase); | ||
Phase_Cutscene_Destroy(cutscene_phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_RunGame( | ||
const GF_LEVEL *const level, const GF_SEQUENCE_CONTEXT seq_ctx) | ||
{ | ||
PHASE *const phase = Phase_Game_Create(level, seq_ctx); | ||
const GF_COMMAND gf_cmd = PhaseExecutor_Run(phase); | ||
Phase_Game_Destroy(phase); | ||
return gf_cmd; | ||
} | ||
|
||
GF_COMMAND GF_DoFrontendSequence(void) | ||
{ | ||
if (g_GameFlow.title_level == nullptr) { | ||
return (GF_COMMAND) { .action = GF_NOOP }; | ||
} | ||
return GF_InterpretSequence(g_GameFlow.title_level, GFSC_NORMAL, nullptr); | ||
} | ||
|
||
GF_COMMAND GF_DoDemoSequence(int32_t demo_num) | ||
{ | ||
demo_num = Demo_ChooseLevel(demo_num); | ||
if (demo_num < 0) { | ||
return (GF_COMMAND) { .action = GF_NOOP }; | ||
} | ||
const GF_LEVEL *const level = GF_GetLevel(GFLT_DEMOS, demo_num); | ||
if (level == nullptr) { | ||
LOG_ERROR("Missing demo: %d", demo_num); | ||
return (GF_COMMAND) { .action = GF_NOOP }; | ||
} | ||
return GF_InterpretSequence(level, GFSC_NORMAL, nullptr); | ||
} | ||
|
||
GF_COMMAND GF_DoCutsceneSequence(const int32_t cutscene_num) | ||
{ | ||
const GF_LEVEL *const level = GF_GetLevel(GFLT_CUTSCENES, cutscene_num); | ||
if (level == nullptr) { | ||
LOG_ERROR("Missing cutscene: %d", cutscene_num); | ||
return (GF_COMMAND) { .action = GF_NOOP }; | ||
} | ||
return GF_InterpretSequence(level, GFSC_NORMAL, nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
extern void GF_PreSequenceHook(void); | ||
extern GF_SEQUENCE_CONTEXT GF_SwitchSequenceContext( | ||
const GF_SEQUENCE_EVENT *event, GF_SEQUENCE_CONTEXT seq_ctx); | ||
extern bool GF_ShouldSkipSequenceEvent( | ||
const GF_LEVEL *level, const GF_SEQUENCE_EVENT *event); | ||
extern GF_COMMAND ( | ||
*GF_GetSequenceEventHandler(GF_SEQUENCE_EVENT_TYPE event_type))( | ||
const GF_LEVEL *, const GF_SEQUENCE_EVENT *, GF_SEQUENCE_CONTEXT, void *); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.