Skip to content

Commit

Permalink
Workaround keyinput_variable being uint8_t
Browse files Browse the repository at this point in the history
Works around EasyRPG/liblcf#155
Also emulates EasyRPG#1674
  • Loading branch information
fmatthew5876 committed Apr 6, 2019
1 parent de3df57 commit c10109f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/game_interpreter.cpp
Expand Up @@ -76,6 +76,7 @@ void Game_Interpreter::Clear() {
waiting_battle_anim = false;
continuation = NULL; // function to execute to resume command
wait_messages = false; // wait if message window is visible
keyinput_var = 0;
keyinput_time = 0;
_state = {};
}
Expand Down Expand Up @@ -110,6 +111,16 @@ void Game_Interpreter::Setup(
}
}


RPG::SaveEventExecState Game_Interpreter::GetState() const {
auto save = _state;
// FIXME: There is an RPG_RT bug where keyinput_variable is uint8_t
// which we currently have to emulate. So this assignment truncates.
save.keyinput_variable = keyinput_var;
return save;
}


void Game_Interpreter::SetupWait(int duration) {
if (duration == 0) {
// 0.0 waits 1 frame
Expand Down Expand Up @@ -199,7 +210,7 @@ void Game_Interpreter::Update(bool reset_loop_count) {

if (_state.keyinput_wait) {
const int key = ProcessKeyInputProc();
Game_Variables.Set(_state.keyinput_variable, key);
Game_Variables.Set(keyinput_var, key);
Game_Map::SetNeedRefresh(Game_Map::Refresh_Map);
if (key == 0) {
break;
Expand Down Expand Up @@ -2485,7 +2496,7 @@ bool Game_Interpreter::CommandKeyInputProc(RPG::EventCommand const& com) { // co
keyinput_time = 0;

_state.keyinput_wait = wait;
_state.keyinput_variable = com.parameters[0];
keyinput_var = com.parameters[0];
_state.keyinput_all_directions = 0;
_state.keyinput_decision = 0;
_state.keyinput_cancel = 0;
Expand Down Expand Up @@ -2547,7 +2558,7 @@ bool Game_Interpreter::CommandKeyInputProc(RPG::EventCommand const& com) { // co
}

int key = ProcessKeyInputProc();
Game_Variables.Set(_state.keyinput_variable, key);
Game_Variables.Set(keyinput_var, key);
Game_Map::SetNeedRefresh(Game_Map::Refresh_Map);

return true;
Expand Down
7 changes: 2 additions & 5 deletions src/game_interpreter.h
Expand Up @@ -76,7 +76,7 @@ class Game_Interpreter
*
* @return interpreter commands stored in SaveEventCommands
*/
const RPG::SaveEventExecState& GetState() const;
RPG::SaveEventExecState GetState() const;

protected:
friend class Game_Interpreter_Map;
Expand All @@ -96,6 +96,7 @@ class Game_Interpreter
bool main_flag;

int loop_count;
int keyinput_var = 0;
int keyinput_time = 0;
bool wait_messages;

Expand Down Expand Up @@ -243,10 +244,6 @@ class Game_Interpreter
RPG::SaveEventExecState _state;
};

inline const RPG::SaveEventExecState& Game_Interpreter::GetState() const {
return _state;
}

inline const RPG::SaveEventExecFrame* Game_Interpreter::GetFrame() const {
return !_state.stack.empty() ? &_state.stack.back() : nullptr;
}
Expand Down
3 changes: 3 additions & 0 deletions src/game_interpreter_map.cpp
Expand Up @@ -51,6 +51,9 @@
void Game_Interpreter_Map::SetState(const RPG::SaveEventExecState& save) {
Clear();
_state = save;
// FIXME: There is an RPG_RT bug where keyinput_variable is uint8_t
// which we currently have to emulate. So this assignment truncates.
keyinput_var = _state.keyinput_variable;
}

void Game_Interpreter_Map::OnMapChange() {
Expand Down

0 comments on commit c10109f

Please sign in to comment.