Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/openvic-simulation/InstanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/console/ConsoleInstance.hpp"
#include "openvic-simulation/misc/GameAction.hpp"
#include "openvic-simulation/utility/Logger.hpp"

using namespace OpenVic;
Expand Down Expand Up @@ -96,7 +97,7 @@ InstanceManager::InstanceManager(
},
simulation_clock {
[this]() -> void {
queue_game_action(game_action_type_t::GAME_ACTION_TICK, {});
queue_game_action<tick_argument_t>();
},
[this]() -> void {
execute_game_actions();
Expand Down Expand Up @@ -335,17 +336,12 @@ void InstanceManager::update_modifier_sums() {
);
}

bool InstanceManager::queue_game_action(game_action_type_t type, game_action_argument_t&& argument) {
bool InstanceManager::queue_game_action(game_action_t&& game_action) {
if (currently_executing_game_actions) {
spdlog::error_s("Attempted to queue a game action while already executing game actions!");
return false;
}

if (type >= game_action_type_t::MAX_GAME_ACTION) {
spdlog::critical_s("Invalid game action type {}", static_cast<uint64_t>(type));
return false;
}

game_action_queue.emplace_back(type, std::move(argument));
game_action_queue.emplace_back(std::move(game_action));
return true;
}
17 changes: 14 additions & 3 deletions src/openvic-simulation/InstanceManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include <utility>

#include <function2/function2.hpp>

#include "openvic-simulation/console/ConsoleInstance.hpp"
#include "openvic-simulation/country/CountryInstanceManager.hpp"
#include "openvic-simulation/country/CountryInstanceDeps.hpp"
Expand All @@ -21,8 +25,6 @@
#include "openvic-simulation/utility/ThreadPool.hpp"
#include "openvic-simulation/utility/Containers.hpp"

#include <function2/function2.hpp>

namespace OpenVic {

struct DefinitionManager;
Expand Down Expand Up @@ -97,6 +99,15 @@ namespace OpenVic {

bool set_today_and_update(Date new_today);

bool queue_game_action(game_action_type_t type, game_action_argument_t&& argument);
template<typename T, typename... Args>
bool queue_game_action(Args&&... args) {
return queue_game_action(
game_action_t(
std::in_place_type<T>,
std::forward<Args>(args)...
)
);
}
bool queue_game_action(game_action_t&& game_action);
};
}
6 changes: 3 additions & 3 deletions src/openvic-simulation/map/ProvinceInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ bool ProvinceInstance::remove_core(CountryInstance& core_to_remove, bool warn) {
return true;
}

bool ProvinceInstance::expand_building(size_t building_index) {
BuildingInstance* building = buildings.get_item_by_index(building_index);
bool ProvinceInstance::expand_building(building_type_index_t building_type_index) {
BuildingInstance* building = buildings.get_item_by_index(type_safe::get(building_type_index));
if (building == nullptr) {
spdlog::error_s(
"Trying to expand non-existent building index {} in province {}",
building_index, *this
building_type_index, *this
);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/map/ProvinceInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace OpenVic {
return owner == nullptr;
}

bool expand_building(size_t building_index);
bool expand_building(building_type_index_t building_type_index);

bool add_pop(Pop&& pop);
bool add_pop_vec(
Expand Down
Loading