Skip to content

Commit

Permalink
Merge pull request EasyRPG#3219 from florianessl/DebugExtension
Browse files Browse the repository at this point in the history
Debug Menu extensions: Display strings & interpreter stacks
  • Loading branch information
Ghabry authored Jun 5, 2024
2 parents 1f01b7b + a0ecb8d commit e544c0e
Show file tree
Hide file tree
Showing 17 changed files with 1,043 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ add_library(${PROJECT_NAME} OBJECT
src/window_input_settings.h
src/window_item.cpp
src/window_item.h
src/window_interpreter.cpp
src/window_interpreter.h
src/window_keyboard.cpp
src/window_keyboard.h
src/window_menustatus.cpp
Expand Down Expand Up @@ -453,6 +455,8 @@ add_library(${PROJECT_NAME} OBJECT
src/window_skill.h
src/window_skillstatus.cpp
src/window_skillstatus.h
src/window_stringview.cpp
src/window_stringview.h
src/window_targetstatus.cpp
src/window_targetstatus.h
src/window_teleport.cpp
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ libeasyrpg_player_a_SOURCES = \
src/window_input_settings.h \
src/window_item.cpp \
src/window_item.h \
src/window_interpreter.cpp \
src/window_interpreter.h \
src/window_keyboard.cpp \
src/window_keyboard.h \
src/window_menustatus.cpp \
Expand Down Expand Up @@ -432,6 +434,8 @@ libeasyrpg_player_a_SOURCES = \
src/window_skill.h \
src/window_skillstatus.cpp \
src/window_skillstatus.h \
src/window_stringview.cpp \
src/window_stringview.h \
src/window_targetstatus.cpp \
src/window_targetstatus.h \
src/window_teleport.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/game_commonevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::vector<lcf::rpg::EventCommand>& Game_CommonEvent::GetList() {
lcf::rpg::SaveEventExecState Game_CommonEvent::GetSaveData() {
lcf::rpg::SaveEventExecState state;
if (interpreter) {
state = interpreter->GetState();
state = interpreter->GetSaveState();
}
if (GetTrigger() == lcf::rpg::EventPage::Trigger_parallel && state.stack.empty()) {
// RPG_RT always stores an empty stack frame for parallel events.
Expand Down
2 changes: 2 additions & 0 deletions src/game_commonevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class Game_CommonEvent {

/** Interpreter for parallel common events. */
std::unique_ptr<Game_Interpreter_Map> interpreter;

friend class Scene_Debug;
};

#endif
2 changes: 1 addition & 1 deletion src/game_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ lcf::rpg::SaveMapEvent Game_Event::GetSaveData() const {
lcf::rpg::SaveEventExecState state;
if (page && page->trigger == lcf::rpg::EventPage::Trigger_parallel) {
if (interpreter) {
state = interpreter->GetState();
state = interpreter->GetSaveState();
}

if (state.stack.empty() && page->event_commands.empty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/game_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class Game_Event : public Game_EventBase {
const lcf::rpg::Event* event = nullptr;
const lcf::rpg::EventPage* page = nullptr;
std::unique_ptr<Game_Interpreter_Map> interpreter;

friend class Scene_Debug;
};

inline int Game_Event::GetNumPages() const {
Expand Down
19 changes: 13 additions & 6 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ bool Game_Interpreter::IsRunning() const {
void Game_Interpreter::Push(
std::vector<lcf::rpg::EventCommand> _list,
int event_id,
bool started_by_decision_key
bool started_by_decision_key,
int event_page_id
) {
if (_list.empty()) {
return;
Expand All @@ -118,6 +119,8 @@ void Game_Interpreter::Push(
frame.current_command = 0;
frame.triggered_by_decision_key = started_by_decision_key;
frame.event_id = event_id;
frame.maniac_event_id = event_id;
frame.maniac_event_page_id = event_page_id;

if (_state.stack.empty() && main_flag && !Game_Battle::IsBattleRunning()) {
Main_Data::game_system->ClearMessageFace();
Expand Down Expand Up @@ -274,7 +277,11 @@ void Game_Interpreter::KeyInputState::toSave(lcf::rpg::SaveEventExecState& save)
}


lcf::rpg::SaveEventExecState Game_Interpreter::GetState() const {
const lcf::rpg::SaveEventExecState& Game_Interpreter::GetState() const {
return _state;
}

lcf::rpg::SaveEventExecState Game_Interpreter::GetSaveState() {
auto save = _state;
_keyinput.toSave(save);
return save;
Expand Down Expand Up @@ -522,11 +529,11 @@ void Game_Interpreter::Update(bool reset_loop_count) {

// Setup Starting Event
void Game_Interpreter::Push(Game_Event* ev) {
Push(ev->GetList(), ev->GetId(), ev->WasStartedByDecisionKey());
Push(ev->GetList(), ev->GetId(), ev->WasStartedByDecisionKey(), ev->GetActivePage() ? ev->GetActivePage()->ID : 0);
}

void Game_Interpreter::Push(Game_Event* ev, const lcf::rpg::EventPage* page, bool triggered_by_decision_key) {
Push(page->event_commands, ev->GetId(), triggered_by_decision_key);
Push(page->event_commands, ev->GetId(), triggered_by_decision_key, page->ID);
}

void Game_Interpreter::Push(Game_CommonEvent* ev) {
Expand Down Expand Up @@ -3996,7 +4003,7 @@ bool Game_Interpreter::CommandCallEvent(lcf::rpg::EventCommand const& com) { //
return true;
}

Push(page->event_commands, event->GetId(), false);
Push(page->event_commands, event->GetId(), false, page->ID);

return true;
}
Expand Down Expand Up @@ -5104,7 +5111,7 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co

// Our implementation pushes a new frame containing the command instead of invoking it directly.
// This is incompatible to Maniacs but has a better compatibility with our code.
Push({ cmd }, GetCurrentEventId(), false);
Push({ cmd }, GetCurrentEventId(), false); //FIXME: add some new flag, so the interpreter debug view (window_interpreter) can differentiate this frame from normal ones

return true;
}
Expand Down
13 changes: 11 additions & 2 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Game_Interpreter
void Push(
std::vector<lcf::rpg::EventCommand> _list,
int _event_id,
bool started_by_decision_key = false
bool started_by_decision_key = false,
int event_page_id = 0
);
void Push(Game_Event* ev);
void Push(Game_Event* ev, const lcf::rpg::EventPage* page, bool triggered_by_decision_key);
Expand All @@ -79,12 +80,18 @@ class Game_Interpreter
virtual bool ExecuteCommand(lcf::rpg::EventCommand const& com);


/**
* Returns the interpreters current state information.
* For saving state into a save file, use GetSaveState instead.
*/
const lcf::rpg::SaveEventExecState& GetState() const;

/**
* Returns a SaveEventExecState needed for the savefile.
*
* @return interpreter commands stored in SaveEventCommands
*/
lcf::rpg::SaveEventExecState GetState() const;
lcf::rpg::SaveEventExecState GetSaveState();

/** @return Game_Character of the passed event_id */
Game_Character* GetCharacter(int event_id) const;
Expand Down Expand Up @@ -341,6 +348,8 @@ class Game_Interpreter
lcf::rpg::SaveEventExecState _state;
KeyInputState _keyinput;
AsyncOp _async_op = {};

friend class Scene_Debug;
};

inline const lcf::rpg::SaveEventExecFrame* Game_Interpreter::GetFramePtr() const {
Expand Down
2 changes: 1 addition & 1 deletion src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void Game_Map::AddEventToVariableCache(lcf::rpg::Event& ev, int var_id) {
}

void Game_Map::PrepareSave(lcf::rpg::Save& save) {
save.foreground_event_execstate = interpreter->GetState();
save.foreground_event_execstate = interpreter->GetSaveState();

save.airship_location = GetVehicle(Game_Vehicle::Airship)->GetSaveData();
save.ship_location = GetVehicle(Game_Vehicle::Ship)->GetSaveData();
Expand Down
Loading

0 comments on commit e544c0e

Please sign in to comment.