diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 12fe1c7b57..57e03237de 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -450,6 +450,7 @@ void Game_Interpreter::Update(bool reset_loop_count) { // 10 per second Main_Data::game_variables->Set(_keyinput.time_variable, (_keyinput.wait_frames * 10) / Game_Clock::GetTargetGameFps()); + Game_Map::SetNeedRefreshForVarChange(_keyinput.time_variable); } _keyinput.wait = false; } @@ -2287,9 +2288,7 @@ bool Game_Interpreter::CommandMemorizeLocation(lcf::rpg::EventCommand const& com Main_Data::game_variables->Set(var_map_id, Game_Map::GetMapId()); Main_Data::game_variables->Set(var_x, player->GetX()); Main_Data::game_variables->Set(var_y, player->GetY()); - Game_Map::SetNeedRefreshForVarChange(var_map_id); - Game_Map::SetNeedRefreshForVarChange(var_x); - Game_Map::SetNeedRefreshForVarChange(var_y); + Game_Map::SetNeedRefreshForVarChange({var_map_id, var_x, var_y}); return true; } diff --git a/src/game_map.cpp b/src/game_map.cpp index 26c9c4f237..b9cbe26bf8 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -17,6 +17,7 @@ // Headers #include +#include #include #include #include @@ -72,8 +73,8 @@ namespace { std::vector passages_up; std::vector events; std::vector common_events; - std::unordered_map> events_cache_by_switch; - std::unordered_map> events_cache_by_variable; + std::unordered_map events_cache_by_switch; + std::unordered_map events_cache_by_variable; std::unique_ptr map; @@ -378,19 +379,11 @@ void Game_Map::SetupCommon() { } void Game_Map::AddEventToSwitchCache(lcf::rpg::Event& ev, int switch_id) { - if (events_cache_by_switch.find(switch_id) == events_cache_by_switch.end()) { - std::unique_ptr cache = std::make_unique(); - events_cache_by_switch[switch_id] = std::move(cache); - } - events_cache_by_switch[switch_id]->AddEvent(ev); + events_cache_by_switch[switch_id].AddEvent(ev); } void Game_Map::AddEventToVariableCache(lcf::rpg::Event& ev, int var_id) { - if (events_cache_by_variable.find(var_id) == events_cache_by_variable.end()) { - std::unique_ptr cache = std::make_unique(); - events_cache_by_variable[var_id] = std::move(cache); - } - events_cache_by_variable[var_id]->AddEvent(ev); + events_cache_by_variable[var_id].AddEvent(ev); } void Game_Map::PrepareSave(lcf::rpg::Save& save) { @@ -1544,7 +1537,8 @@ void Game_Map::SetPositionY(int y, bool reset_panorama) { } bool Game_Map::GetNeedRefresh() { - if (Player::game_config.patch_anti_lag_switch.Get() && Main_Data::game_switches->Get(Player::game_config.patch_anti_lag_switch.Get())) { + int anti_lag_switch = Player::game_config.patch_anti_lag_switch.Get(); + if (anti_lag_switch > 0 && Main_Data::game_switches->Get(anti_lag_switch)) { return false; } @@ -1555,13 +1549,12 @@ void Game_Map::SetNeedRefresh(bool refresh) { need_refresh = refresh; } - void MapEventCache::AddEvent(lcf::rpg::Event& ev) { - for (const auto& ev2 : events) { - if (ev.ID == ev2.ID) - return; + auto id = ev.ID; + + if (std::find(event_ids.begin(), event_ids.end(), id) == event_ids.end()) { + event_ids.emplace_back(id); } - events.emplace_back(ev); } void Game_Map::SetNeedRefreshForSwitchChange(int switch_id) { @@ -1578,6 +1571,18 @@ void Game_Map::SetNeedRefreshForVarChange(int var_id) { SetNeedRefresh(true); } +void Game_Map::SetNeedRefreshForSwitchChange(std::initializer_list switch_ids) { + for (auto switch_id: switch_ids) { + SetNeedRefreshForSwitchChange(switch_id); + } +} + +void Game_Map::SetNeedRefreshForVarChange(std::initializer_list var_ids) { + for (auto var_id: var_ids) { + SetNeedRefreshForVarChange(var_id); + } +} + std::vector& Game_Map::GetPassagesDown() { return passages_down; } diff --git a/src/game_map.h b/src/game_map.h index 4a6b41f230..e9ea966e28 100644 --- a/src/game_map.h +++ b/src/game_map.h @@ -20,6 +20,7 @@ // Headers #include +#include #include #include #include @@ -47,38 +48,38 @@ struct BattleArgs; constexpr int SCREEN_TILE_SIZE = 256; class MapUpdateAsyncContext { - public: - MapUpdateAsyncContext() = default; - - static MapUpdateAsyncContext FromCommonEvent(int ce, AsyncOp aop); - static MapUpdateAsyncContext FromMapEvent(int ce, AsyncOp aop); - static MapUpdateAsyncContext FromForegroundEvent(AsyncOp aop); - static MapUpdateAsyncContext FromMessage(AsyncOp aop); - - AsyncOp GetAsyncOp() const; - - int GetParallelCommonEvent() const; - int GetParallelMapEvent() const; - - bool IsForegroundEvent() const; - bool IsParallelCommonEvent() const; - bool IsParallelMapEvent() const; - bool IsMessage() const; - bool IsActive() const; - private: - AsyncOp async_op = {}; - int common_event = 0; - int map_event = 0; - bool foreground_event = false; - bool message = false; +public: + MapUpdateAsyncContext() = default; + + static MapUpdateAsyncContext FromCommonEvent(int ce, AsyncOp aop); + static MapUpdateAsyncContext FromMapEvent(int ce, AsyncOp aop); + static MapUpdateAsyncContext FromForegroundEvent(AsyncOp aop); + static MapUpdateAsyncContext FromMessage(AsyncOp aop); + + AsyncOp GetAsyncOp() const; + + int GetParallelCommonEvent() const; + int GetParallelMapEvent() const; + + bool IsForegroundEvent() const; + bool IsParallelCommonEvent() const; + bool IsParallelMapEvent() const; + bool IsMessage() const; + bool IsActive() const; +private: + AsyncOp async_op = {}; + int common_event = 0; + int map_event = 0; + bool foreground_event = false; + bool message = false; }; class MapEventCache { - public: - void AddEvent(lcf::rpg::Event& ev); +public: + void AddEvent(lcf::rpg::Event& ev); - private: - std::vector events; +private: + std::vector event_ids; }; /** @@ -689,6 +690,8 @@ namespace Game_Map { void SetNeedRefreshForSwitchChange(int switch_id); void SetNeedRefreshForVarChange(int var_id); + void SetNeedRefreshForSwitchChange(std::initializer_list switch_ids); + void SetNeedRefreshForVarChange(std::initializer_list var_ids); void AddEventToSwitchCache(lcf::rpg::Event& ev, int switch_id); void AddEventToVariableCache(lcf::rpg::Event& ev, int var_id);