Skip to content

Commit

Permalink
Game_Interpreter calling state is now global
Browse files Browse the repository at this point in the history
Fixes issues when a parallel process alters the state
  • Loading branch information
Ghabry committed Dec 19, 2018
1 parent de9026f commit 3f5ff03
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace {
static Game_Interpreter* transition_owner = nullptr;
}

Game_Interpreter::EventCalling Game_Interpreter::event_calling = {};

Game_Interpreter::Game_Interpreter(int _depth, bool _main_flag) {
depth = _depth;
main_flag = _main_flag;
Expand Down Expand Up @@ -91,7 +93,6 @@ void Game_Interpreter::Clear() {
child_interpreter.reset();
}
list.clear();
ResetEventCalling();
}

// Is interpreter running.
Expand Down Expand Up @@ -3081,8 +3082,7 @@ void Game_Interpreter::ResetEventCalling() {
Game_Temp::battle_calling = false;
}


bool Game_Interpreter::IsImmediateCall() const {
bool Game_Interpreter::IsImmediateCall() {
return event_calling.load
|| event_calling.save
|| event_calling.name
Expand Down
26 changes: 13 additions & 13 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,37 @@ class Game_Interpreter
/**
* @return true if an immediate call is requested
*/
bool IsImmediateCall() const;
static bool IsImmediateCall();

/**
* Reset the event calling flags
*/
void ResetEventCalling();
static void ResetEventCalling();

/**
* @return true if interpreter wants to immediately call the main menu
*/
bool IsMenuCalling() const;
static bool IsMenuCalling();

/**
* @return true if interpreter wants to immediately call the save menu
*/
bool IsSaveCalling() const;
static bool IsSaveCalling();

/**
* @return true if interpreter wants to immediately call the load menu
*/
bool IsLoadCalling() const;
static bool IsLoadCalling();

/**
* @return true if interpreter wants to immediately call the name actor menu
*/
bool IsNameCalling() const;
static bool IsNameCalling();

/**
* @return true if interpreter wants to immediately call the shop menu
*/
bool IsShopCalling() const;
static bool IsShopCalling();

protected:
friend class Game_Interpreter_Map;
Expand Down Expand Up @@ -278,27 +278,27 @@ class Game_Interpreter
bool save = false;
bool load = false;
};
EventCalling event_calling = {};
static EventCalling event_calling;
};


inline bool Game_Interpreter::IsMenuCalling() const {
inline bool Game_Interpreter::IsMenuCalling() {
return event_calling.menu;
}

inline bool Game_Interpreter::IsSaveCalling() const {
inline bool Game_Interpreter::IsSaveCalling() {
return event_calling.save;
}

inline bool Game_Interpreter::IsLoadCalling() const {
inline bool Game_Interpreter::IsLoadCalling() {
return event_calling.load;
}

inline bool Game_Interpreter::IsNameCalling() const {
inline bool Game_Interpreter::IsNameCalling() {
return event_calling.name;
}

inline bool Game_Interpreter::IsShopCalling() const {
inline bool Game_Interpreter::IsShopCalling() {
return event_calling.shop;
}

Expand Down
26 changes: 12 additions & 14 deletions src/scene_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,41 +190,39 @@ void Scene_Map::Update() {
}
}

auto& interp = Game_Map::GetInterpreter();

if (!Main_Data::game_player->IsMoving() || interp.IsImmediateCall() || force_menu_calling) {
if (Main_Data::game_data.party_location.menu_calling || interp.IsMenuCalling() || force_menu_calling) {
interp.ResetEventCalling();
if (!Main_Data::game_player->IsMoving() || Game_Interpreter::IsImmediateCall() || force_menu_calling) {
if (Main_Data::game_data.party_location.menu_calling || Game_Interpreter::IsMenuCalling() || force_menu_calling) {
Game_Interpreter::ResetEventCalling();
CallMenu();
return;
}

if (interp.IsNameCalling()) {
interp.ResetEventCalling();
if (Game_Interpreter::IsNameCalling()) {
Game_Interpreter::ResetEventCalling();
CallName();
return;
}

if (interp.IsShopCalling()) {
interp.ResetEventCalling();
if (Game_Interpreter::IsShopCalling()) {
Game_Interpreter::ResetEventCalling();
CallShop();
return;
}

if (interp.IsSaveCalling()) {
interp.ResetEventCalling();
if (Game_Interpreter::IsSaveCalling()) {
Game_Interpreter::ResetEventCalling();
CallSave();
return;
}

if (interp.IsLoadCalling()) {
interp.ResetEventCalling();
if (Game_Interpreter::IsLoadCalling()) {
Game_Interpreter::ResetEventCalling();
CallLoad();
return;
}

if (Game_Temp::battle_calling) {
interp.ResetEventCalling();
Game_Interpreter::ResetEventCalling();
CallBattle();
return;
}
Expand Down

0 comments on commit 3f5ff03

Please sign in to comment.