aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp10
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp31
2 files changed, 32 insertions, 9 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index d01f6ff..f99417f 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -280,8 +280,7 @@ bool Dataloader::_load_interface_files(UIManager& ui_manager) const {
return ui_manager.load_gfx_file(parse_defines(file).get_file_node());
}
);
- ui_manager.lock_sprites();
- ui_manager.lock_fonts();
+ ui_manager.lock_gfx_registries();
/* Hard-coded GUI file names, might be replaced with a dynamic system but everything should still be loaded on startup. */
static const std::vector<std::string_view> gui_files {
@@ -513,12 +512,14 @@ bool Dataloader::_load_history(GameManager& game_manager, bool unused_history_fi
{
/* Country History */
CountryHistoryManager& country_history_manager = game_manager.get_history_manager().get_country_manager();
+ DeploymentManager& deployment_manager = game_manager.get_military_manager().get_deployment_manager();
static constexpr std::string_view country_history_directory = "history/countries";
const path_vector_t country_history_files =
lookup_basic_indentifier_prefixed_files_in_dir(country_history_directory, ".txt");
country_history_manager.reserve_more_country_histories(country_history_files.size());
+ deployment_manager.reserve_more_deployments(country_history_files.size());
ret &= apply_to_files(
country_history_files,
@@ -541,11 +542,6 @@ bool Dataloader::_load_history(GameManager& game_manager, bool unused_history_fi
);
country_history_manager.lock_country_histories();
- }
-
- {
- DeploymentManager& deployment_manager = game_manager.get_military_manager().get_deployment_manager();
-
deployment_manager.lock_deployments();
if (deployment_manager.get_missing_oob_file_count() > 0) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index c41c09e..0bb4d5b 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -443,9 +443,17 @@ namespace OpenVic {
};
}
+ /* By default this will only allow an optional to be set once. Set allow_overwrite
+ * to true to allow multiple assignments, with the last taking precedence. */
template<typename T>
- Callback<T const&> auto assign_variable_callback_pointer(std::optional<T const*>& var) {
- return [&var](T const& val) -> bool {
+ Callback<T const&> auto assign_variable_callback_pointer_opt(
+ std::optional<T const*>& var, bool allow_overwrite = false
+ ) {
+ return [&var, allow_overwrite](T const& val) -> bool {
+ if (!allow_overwrite && var.has_value()) {
+ Logger::error("Canoot assign pointer value to already-initialised optional!");
+ return false;
+ }
var = &val;
return true;
};
@@ -506,5 +514,24 @@ namespace OpenVic {
return warn;
};
}
+
+ /* Often used for rotations which must be negated due to OpenVic's coordinate system being orientated
+ * oppositely to Vic2's. */
+ template<typename T = fixed_point_t>
+ constexpr Callback<T> auto negate_callback(Callback<T> auto callback) {
+ return [callback](T val) -> bool {
+ return callback(-val);
+ };
+ }
+
+ /* Often used for map-space coordinates which must have their y-coordinate flipped due to OpenVic using the
+ * top-left of the map as the origin as opposed Vic2 using the bottom-left. */
+ template<typename T>
+ constexpr Callback<vec2_t<T>> auto flip_y_callback(Callback<vec2_t<T>> auto callback, T height) {
+ return [callback, height](vec2_t<T> val) -> bool {
+ val.y = height - val.y;
+ return callback(val);
+ };
+ }
}
}