aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/src/Checksum.hpp4
-rw-r--r--extension/src/GameSingleton.cpp79
-rw-r--r--extension/src/GameSingleton.hpp2
-rw-r--r--extension/src/LoadLocalisation.cpp4
-rw-r--r--extension/src/MapMesh.cpp16
-rw-r--r--extension/src/openvic2/Date.cpp20
-rw-r--r--extension/src/openvic2/Date.hpp10
-rw-r--r--extension/src/openvic2/GameAdvancementHook.cpp17
-rw-r--r--extension/src/openvic2/GameAdvancementHook.hpp14
-rw-r--r--extension/src/openvic2/GameManager.cpp3
-rw-r--r--extension/src/openvic2/GameManager.hpp2
-rw-r--r--extension/src/openvic2/Good.hpp29
-rw-r--r--extension/src/openvic2/Logger.hpp46
-rw-r--r--extension/src/openvic2/Types.cpp4
-rw-r--r--extension/src/openvic2/Types.hpp9
-rw-r--r--extension/src/openvic2/map/Building.cpp10
-rw-r--r--extension/src/openvic2/map/Building.hpp14
-rw-r--r--extension/src/openvic2/map/Map.cpp12
-rw-r--r--extension/src/openvic2/map/Map.hpp9
-rw-r--r--extension/src/openvic2/map/Province.cpp9
-rw-r--r--extension/src/openvic2/map/Province.hpp1
-rw-r--r--extension/src/openvic2/map/Region.cpp2
-rw-r--r--extension/src/openvic2/map/Region.hpp3
-rw-r--r--extension/src/register_types.cpp2
24 files changed, 193 insertions, 128 deletions
diff --git a/extension/src/Checksum.hpp b/extension/src/Checksum.hpp
index 717910e..a0b1504 100644
--- a/extension/src/Checksum.hpp
+++ b/extension/src/Checksum.hpp
@@ -6,7 +6,7 @@ namespace OpenVic2 {
class Checksum : public godot::Object {
GDCLASS(Checksum, godot::Object)
- //BEGIN BOILERPLATE
+ // BEGIN BOILERPLATE
inline static Checksum* _checksum = nullptr;
protected:
@@ -25,7 +25,7 @@ namespace OpenVic2 {
ERR_FAIL_COND(_checksum != this);
_checksum = nullptr;
}
- //END BOILERPLATE
+ // END BOILERPLATE
inline godot::String get_checksum_text() {
return godot::String("1234abcd");
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index 3476ac5..56f7ac5 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -1,8 +1,8 @@
#include "GameSingleton.hpp"
-#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/classes/json.hpp>
+#include <godot_cpp/variant/utility_functions.hpp>
#include "openvic2/Logger.hpp"
@@ -58,7 +58,8 @@ GameSingleton* GameSingleton::get_singleton() {
/* REQUIREMENTS:
* MAP-21, MAP-25
*/
-GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_updated"); } }, terrain_variants{ "terrain variants" } {
+GameSingleton::GameSingleton() : game_manager { [this]() { emit_signal("state_updated"); } },
+ terrain_variants { "terrain variants" } {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
@@ -69,21 +70,25 @@ GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_upd
static constexpr colour_t LOW_ALPHA_VALUE = to_alpha_value(0.2f);
using mapmode_t = std::pair<std::string, Mapmode::colour_func_t>;
const std::vector<mapmode_t> mapmodes = {
- { "mapmode_terrain", [](Map const&, Province const& province) -> colour_t {
- return LOW_ALPHA_VALUE | (province.is_water() ? 0x4287F5 : 0x0D7017);
- } },
- { "mapmode_province", [](Map const&, Province const& province) -> colour_t {
- return HIGH_ALPHA_VALUE | province.get_colour();
- } },
- { "mapmode_region", [](Map const&, Province const& province) -> colour_t {
- Region const* region = province.get_region();
- if (region != nullptr) return (0xCC << 24) | region->get_colour();
- return NULL_COLOUR;
- } },
- { "mapmode_index", [](Map const& map, Province const& province) -> colour_t {
- const uint8_t f = static_cast<float>(province.get_index()) / static_cast<float>(map.get_province_count()) * 255.0f;
- return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f;
- } }
+ { "mapmode_terrain",
+ [](Map const&, Province const& province) -> colour_t {
+ return LOW_ALPHA_VALUE | (province.is_water() ? 0x4287F5 : 0x0D7017);
+ } },
+ { "mapmode_province",
+ [](Map const&, Province const& province) -> colour_t {
+ return HIGH_ALPHA_VALUE | province.get_colour();
+ } },
+ { "mapmode_region",
+ [](Map const&, Province const& province) -> colour_t {
+ Region const* region = province.get_region();
+ if (region != nullptr) return (0xCC << 24) | region->get_colour();
+ return NULL_COLOUR;
+ } },
+ { "mapmode_index",
+ [](Map const& map, Province const& province) -> colour_t {
+ const uint8_t f = static_cast<float>(province.get_index()) / static_cast<float>(map.get_province_count()) * 255.0f;
+ return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f;
+ } }
};
for (mapmode_t const& mapmode : mapmodes)
game_manager.map.add_mapmode(mapmode.first, mapmode.second);
@@ -96,7 +101,6 @@ GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_upd
for (building_type_t const& type : building_types)
game_manager.building_manager.add_building_type(std::get<0>(type), std::get<1>(type), std::get<2>(type));
game_manager.building_manager.lock_building_types();
-
}
GameSingleton::~GameSingleton() {
@@ -125,7 +129,7 @@ static Error _load_json_file(String const& file_description, String const& file_
return err;
}
-using parse_json_entry_func_t = std::function<godot::Error (godot::String const&, godot::Variant const&)>;
+using parse_json_entry_func_t = std::function<godot::Error(godot::String const&, godot::Variant const&)>;
static Error _parse_json_dictionary_file(String const& file_description, String const& file_path,
String const& identifier_prefix, parse_json_entry_func_t parse_entry) {
@@ -172,8 +176,7 @@ static colour_t _parse_colour(Variant const& var) {
}
return colour;
}
- }
- else if (type == Variant::STRING) {
+ } else if (type == Variant::STRING) {
String const& colour_string = var;
if (colour_string.is_valid_hex_number()) {
const int64_t colour_int = colour_string.hex_to_int();
@@ -214,8 +217,7 @@ Error GameSingleton::_parse_region_entry(String const& identifier, Variant const
if (type == Variant::STRING) {
String const& province_string = province_var;
province_identifiers.push_back(province_string.utf8().get_data());
- }
- else {
+ } else {
UtilityFunctions::push_error("Invalid province identifier for region \"", identifier, "\": ", entry);
err = FAILED;
}
@@ -238,7 +240,9 @@ Error GameSingleton::load_region_file(String const& file_path) {
}
TerrainVariant::TerrainVariant(std::string const& new_identfier, colour_t new_colour, Ref<Image> const& new_image)
- : HasIdentifier(new_identfier), HasColour(new_colour), image(new_image) {}
+ : HasIdentifier(new_identfier),
+ HasColour(new_colour),
+ image(new_image) {}
Ref<Image> TerrainVariant::get_image() const { return image; }
@@ -329,12 +333,14 @@ Error GameSingleton::load_map_images(String const& province_image_path, String c
// Generate interleaved province and terrain ID image
if (game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y, province_image->get_data().ptr(),
- terrain_image->get_data().ptr(), terrain_variant_map) != SUCCESS) return FAILED;
+ terrain_image->get_data().ptr(), terrain_variant_map) != SUCCESS) return FAILED;
static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF;
// For each dimension of the image, this finds the small number of equal subdivisions required get the individual texture dims under GPU_DIM_LIMIT
- for (int i = 0; i < 2; ++i) for (image_subdivisions[i] = 1;
- province_dims[i] / image_subdivisions[i] > GPU_DIM_LIMIT || province_dims[i] % image_subdivisions[i] != 0; ++image_subdivisions[i]);
+ for (int i = 0; i < 2; ++i)
+ for (image_subdivisions[i] = 1;
+ province_dims[i] / image_subdivisions[i] > GPU_DIM_LIMIT || province_dims[i] % image_subdivisions[i] != 0; ++image_subdivisions[i])
+ ;
Map::shape_pixel_t const* province_shape_data = game_manager.map.get_province_shape_image().data();
const Vector2i divided_dims = province_dims / image_subdivisions;
@@ -383,8 +389,7 @@ Error GameSingleton::load_water_province_file(String const& file_path) {
UtilityFunctions::push_error("Invalid water province JSON: root has type ",
Variant::get_type_name(type), " (expected Array)");
err = FAILED;
- }
- else {
+ } else {
Array const& array = json_var;
for (int64_t idx = 0; idx < array.size(); ++idx) {
Variant const& entry = array[idx];
@@ -409,11 +414,14 @@ int32_t GameSingleton::get_province_index_from_uv_coords(Vector2 const& coords)
return game_manager.map.get_province_index_at(x_mod_w, y_mod_h);
}
-#define KEY(x) static const StringName x##_key = #x;
+#define KEY(x) static const StringName x##_key = #x
Dictionary GameSingleton::get_province_info_from_index(int32_t index) const {
Province const* province = game_manager.map.get_province_by_index(index);
if (province == nullptr) return {};
- KEY(province) KEY(region) KEY(life_rating) KEY(buildings)
+ KEY(province);
+ KEY(region);
+ KEY(life_rating);
+ KEY(buildings);
Dictionary ret;
ret[province_key] = province->get_identifier().c_str();
@@ -428,7 +436,12 @@ Dictionary GameSingleton::get_province_info_from_index(int32_t index) const {
Array buildings_array;
buildings_array.resize(buildings.size());
for (size_t idx = 0; idx < buildings.size(); ++idx) {
- KEY(building) KEY(level) KEY(expansion_state) KEY(start_date) KEY(end_date) KEY(expansion_progress)
+ KEY(building);
+ KEY(level);
+ KEY(expansion_state);
+ KEY(start_date);
+ KEY(end_date);
+ KEY(expansion_progress);
Dictionary building_dict;
Building const& building = buildings[idx];
@@ -507,7 +520,7 @@ int32_t GameSingleton::get_mapmode_count() const {
String GameSingleton::get_mapmode_identifier(int32_t index) const {
Mapmode const* mapmode = game_manager.map.get_mapmode_by_index(index);
if (mapmode != nullptr) return mapmode->get_identifier().c_str();
- return String{};
+ return String {};
}
Error GameSingleton::set_mapmode(godot::String const& identifier) {
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index 80b2d95..21ca2d1 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -9,6 +9,7 @@ namespace OpenVic2 {
struct TerrainVariant : HasIdentifier, HasColour {
private:
const godot::Ref<godot::Image> image;
+
public:
TerrainVariant(std::string const& new_identfier, colour_t new_colour,
godot::Ref<godot::Image> const& new_image);
@@ -36,6 +37,7 @@ namespace OpenVic2 {
godot::Error _parse_region_entry(godot::String const& identifier, godot::Variant const& entry);
godot::Error _parse_terrain_entry(godot::String const& identifier, godot::Variant const& entry);
void _tick();
+
protected:
static void _bind_methods();
diff --git a/extension/src/LoadLocalisation.cpp b/extension/src/LoadLocalisation.cpp
index 8698bb2..789a476 100644
--- a/extension/src/LoadLocalisation.cpp
+++ b/extension/src/LoadLocalisation.cpp
@@ -1,9 +1,9 @@
#include "LoadLocalisation.hpp"
-#include <godot_cpp/variant/utility_functions.hpp>
-#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/classes/dir_access.hpp>
+#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/classes/translation_server.hpp>
+#include <godot_cpp/variant/utility_functions.hpp>
using namespace godot;
using namespace OpenVic2;
diff --git a/extension/src/MapMesh.cpp b/extension/src/MapMesh.cpp
index 6d94973..84149b9 100644
--- a/extension/src/MapMesh.cpp
+++ b/extension/src/MapMesh.cpp
@@ -69,8 +69,8 @@ int32_t MapMesh::get_subdivide_depth() const {
}
AABB MapMesh::get_core_aabb() const {
- const Vector3 size{ aspect_ratio, 0.0f, 1.0f };
- return AABB{ size * -0.5f, size };
+ const Vector3 size { aspect_ratio, 0.0f, 1.0f };
+ return AABB { size * -0.5f, size };
}
bool MapMesh::is_valid_uv_coord(godot::Vector2 const& uv) const {
@@ -96,15 +96,15 @@ Array MapMesh::_create_mesh_array() const {
uvs.resize(vertex_count);
indices.resize(indice_count);
- static const Vector3 normal{ 0.0f, 1.0f, 0.0f };
- const Size2 uv_size{ 1.0f + 2.0f * repeat_proportion, 1.0f };
- const Size2 size{ aspect_ratio * uv_size.x, uv_size.y }, start_pos = size * -0.5f;
+ static const Vector3 normal { 0.0f, 1.0f, 0.0f };
+ const Size2 uv_size { 1.0f + 2.0f * repeat_proportion, 1.0f };
+ const Size2 size { aspect_ratio * uv_size.x, uv_size.y }, start_pos = size * -0.5f;
int32_t point_index = 0, thisrow = 0, prevrow = 0, indice_index = 0;
- Vector2 subdivide_step{ 1.0f / (subdivide_w + 1.0f) , 1.0f / (subdivide_d + 1.0f) };
- Vector3 point{ 0.0f, 0.0f, start_pos.y };
+ Vector2 subdivide_step { 1.0f / (subdivide_w + 1.0f), 1.0f / (subdivide_d + 1.0f) };
+ Vector3 point { 0.0f, 0.0f, start_pos.y };
Vector2 point_step = subdivide_step * size;
- Vector2 uv{}, uv_step = subdivide_step * uv_size;
+ Vector2 uv {}, uv_step = subdivide_step * uv_size;
for (int32_t j = 0; j <= subdivide_d + 1; ++j) {
point.x = start_pos.x;
diff --git a/extension/src/openvic2/Date.cpp b/extension/src/openvic2/Date.cpp
index ed800d5..11e4b36 100644
--- a/extension/src/openvic2/Date.cpp
+++ b/extension/src/openvic2/Date.cpp
@@ -1,13 +1,13 @@
#include "Date.hpp"
-#include <cctype>
#include <algorithm>
+#include <cctype>
#include "Logger.hpp"
using namespace OpenVic2;
-Timespan::Timespan(day_t value) : days{value} {}
+Timespan::Timespan(day_t value) : days { value } {}
bool Timespan::operator<(Timespan other) const { return days < other.days; };
bool Timespan::operator>(Timespan other) const { return days > other.days; };
@@ -67,14 +67,14 @@ Timespan Date::_dateToTimespan(year_t year, month_t month, day_t day) {
return year * DAYS_IN_YEAR + DAYS_UP_TO_MONTH[month - 1] + day - 1;
}
-Date::Date(Timespan total_days) : timespan{ total_days } {
+Date::Date(Timespan total_days) : timespan { total_days } {
if (timespan < 0) {
Logger::error("Invalid timespan for date: ", timespan, " (cannot be negative)");
timespan = 0;
}
}
-Date::Date(year_t year, month_t month, day_t day) : timespan{ _dateToTimespan(year, month, day) } {}
+Date::Date(year_t year, month_t month, day_t day) : timespan { _dateToTimespan(year, month, day) } {}
Date::year_t Date::getYear() const {
return static_cast<Timespan::day_t>(timespan) / DAYS_IN_YEAR;
@@ -89,7 +89,6 @@ Date::day_t Date::getDay() const {
return days_in_year - DAYS_UP_TO_MONTH[days_in_year / 32] + 1;
}
-
bool Date::operator<(Date other) const { return timespan < other.timespan; };
bool Date::operator>(Date other) const { return timespan > other.timespan; };
bool Date::operator<=(Date other) const { return timespan <= other.timespan; };
@@ -129,7 +128,7 @@ Date::operator std::string() const {
}
std::ostream& OpenVic2::operator<<(std::ostream& out, Date date) {
- return out << (int) date.getYear() << '.' << (int) date.getMonth() << '.' << (int) date.getDay();
+ return out << (int)date.getYear() << '.' << (int)date.getMonth() << '.' << (int)date.getDay();
}
// Parsed from string of the form YYYY.MM.DD
@@ -139,17 +138,20 @@ Date Date::from_string(std::string const& date) {
day_t day = 1;
size_t first_pos = 0;
- while (first_pos < date.length() && std::isdigit(date[first_pos++]));
+ while (first_pos < date.length() && std::isdigit(date[first_pos++]))
+ ;
year = atoi(date.substr(0, first_pos).c_str());
if (first_pos < date.length()) {
if (date[first_pos] == '.') {
size_t second_pos = first_pos + 1;
- while (second_pos < date.length() && std::isdigit(date[second_pos++]));
+ while (second_pos < date.length() && std::isdigit(date[second_pos++]))
+ ;
month = atoi(date.substr(first_pos, second_pos - first_pos).c_str());
if (second_pos < date.length()) {
if (date[second_pos] == '.') {
size_t third_pos = second_pos + 1;
- while (third_pos < date.length() && std::isdigit(date[third_pos++]));
+ while (third_pos < date.length() && std::isdigit(date[third_pos++]))
+ ;
day = atoi(date.substr(second_pos, third_pos - second_pos).c_str());
if (third_pos < date.length())
Logger::error("Unexpected string \"", date.substr(third_pos), "\" at the end of date ", date);
diff --git a/extension/src/openvic2/Date.hpp b/extension/src/openvic2/Date.hpp
index b19602b..b7b45a3 100644
--- a/extension/src/openvic2/Date.hpp
+++ b/extension/src/openvic2/Date.hpp
@@ -1,15 +1,17 @@
#pragma once
#include <cstdint>
-#include <string>
#include <ostream>
+#include <string>
namespace OpenVic2 {
// A relative period between points in time, measured in days
struct Timespan {
using day_t = int64_t;
+
private:
day_t days;
+
public:
Timespan(day_t value = 0);
@@ -33,7 +35,7 @@ namespace OpenVic2 {
explicit operator double() const;
explicit operator std::string() const;
};
- std::ostream& operator<< (std::ostream& out, Timespan timespan);
+ std::ostream& operator<<(std::ostream& out, Timespan timespan);
// Represents an in-game date
// Note: Current implementation does not account for leap-years, or dates before Year 0
@@ -46,11 +48,13 @@ namespace OpenVic2 {
static constexpr Timespan::day_t DAYS_IN_YEAR = 365;
static constexpr Timespan::day_t DAYS_IN_MONTH[MONTHS_IN_YEAR] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static constexpr Timespan::day_t DAYS_UP_TO_MONTH[MONTHS_IN_YEAR] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
+
private:
// Number of days since Jan 1st, Year 0
Timespan timespan;
static Timespan _dateToTimespan(year_t year, month_t month, day_t day);
+
public:
// The Timespan is considered to be the number of days since Jan 1st, Year 0
Date(Timespan total_days);
@@ -79,5 +83,5 @@ namespace OpenVic2 {
// Parsed from string of the form YYYY.MM.DD
static Date from_string(std::string const& date);
};
- std::ostream& operator<< (std::ostream& out, Date date);
+ std::ostream& operator<<(std::ostream& out, Date date);
}
diff --git a/extension/src/openvic2/GameAdvancementHook.cpp b/extension/src/openvic2/GameAdvancementHook.cpp
index d90b7b1..a68f55c 100644
--- a/extension/src/openvic2/GameAdvancementHook.cpp
+++ b/extension/src/openvic2/GameAdvancementHook.cpp
@@ -3,15 +3,18 @@
using namespace OpenVic2;
const std::vector<std::chrono::milliseconds> GameAdvancementHook::GAME_SPEEDS = {
- std::chrono::milliseconds{ 4000 },
- std::chrono::milliseconds{ 3000 },
- std::chrono::milliseconds{ 2000 },
- std::chrono::milliseconds{ 1000 },
- std::chrono::milliseconds{ 100 },
- std::chrono::milliseconds{ 1 } };
+ std::chrono::milliseconds { 4000 },
+ std::chrono::milliseconds { 3000 },
+ std::chrono::milliseconds { 2000 },
+ std::chrono::milliseconds { 1000 },
+ std::chrono::milliseconds { 100 },
+ std::chrono::milliseconds { 1 }
+};
GameAdvancementHook::GameAdvancementHook(AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused, speed_t startingSpeed)
- : triggerFunction{ tickFunction }, refreshFunction{ updateFunction }, isPaused{ startPaused } {
+ : triggerFunction { tickFunction },
+ refreshFunction { updateFunction },
+ isPaused { startPaused } {
lastPolledTime = std::chrono::high_resolution_clock::now();
setSimulationSpeed(startingSpeed);
}
diff --git a/extension/src/openvic2/GameAdvancementHook.hpp b/extension/src/openvic2/GameAdvancementHook.hpp
index 07f8414..1fe7737 100644
--- a/extension/src/openvic2/GameAdvancementHook.hpp
+++ b/extension/src/openvic2/GameAdvancementHook.hpp
@@ -5,25 +5,25 @@
#include <vector>
namespace OpenVic2 {
- //Conditionally advances game with provided behaviour
- //Class governs game speed and pause state
+ // Conditionally advances game with provided behaviour
+ // Class governs game speed and pause state
class GameAdvancementHook {
- public:
+ public:
using AdvancementFunction = std::function<void()>;
using RefreshFunction = std::function<void()>;
using speed_t = int8_t;
- //Minimum number of miliseconds before the simulation advances
+ // Minimum number of miliseconds before the simulation advances
static const std::vector<std::chrono::milliseconds> GAME_SPEEDS;
- private:
+ private:
std::chrono::time_point<std::chrono::high_resolution_clock> lastPolledTime;
- //A function pointer that advances the simulation, intended to be a capturing lambda or something similar. May need to be reworked later
+ // A function pointer that advances the simulation, intended to be a capturing lambda or something similar. May need to be reworked later
AdvancementFunction triggerFunction;
RefreshFunction refreshFunction;
speed_t currentSpeed;
- public:
+ public:
bool isPaused;
GameAdvancementHook(AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused = true, speed_t startingSpeed = 0);
diff --git a/extension/src/openvic2/GameManager.cpp b/extension/src/openvic2/GameManager.cpp
index 58e40bb..036e610 100644
--- a/extension/src/openvic2/GameManager.cpp
+++ b/extension/src/openvic2/GameManager.cpp
@@ -5,7 +5,8 @@
using namespace OpenVic2;
GameManager::GameManager(state_updated_func_t state_updated_callback)
- : clock{ [this]() { tick(); }, [this]() { update_state(); } }, state_updated{ state_updated_callback } {}
+ : clock { [this]() { tick(); }, [this]() { update_state(); } },
+ state_updated { state_updated_callback } {}
void GameManager::set_needs_update() {
needs_update = true;
diff --git a/extension/src/openvic2/GameManager.hpp b/extension/src/openvic2/GameManager.hpp
index 70e98bd..32183e3 100644
--- a/extension/src/openvic2/GameManager.hpp
+++ b/extension/src/openvic2/GameManager.hpp
@@ -10,6 +10,7 @@ namespace OpenVic2 {
Map map;
BuildingManager building_manager;
GameAdvancementHook clock;
+
private:
Date today;
state_updated_func_t state_updated;
@@ -18,6 +19,7 @@ namespace OpenVic2 {
void set_needs_update();
void update_state();
void tick();
+
public:
GameManager(state_updated_func_t state_updated_callback);
diff --git a/extension/src/openvic2/Good.hpp b/extension/src/openvic2/Good.hpp
index 378bbc4..1e2bd5e 100644
--- a/extension/src/openvic2/Good.hpp
+++ b/extension/src/openvic2/Good.hpp
@@ -4,18 +4,23 @@
namespace OpenVic2 {
class Good : HasIdentifier {
- public:
- std::string category;
- price_t cost;
- std::string colour;
- bool isAvailable;
- bool isTradable;
- bool isMoney;
- bool hasOverseasPenalty;
+ public:
+ std::string category;
+ price_t cost;
+ std::string colour;
+ bool isAvailable;
+ bool isTradable;
+ bool isMoney;
+ bool hasOverseasPenalty;
- Good(Good&&) = default;
- Good(std::string const& identifier,std::string const& category, price_t cost, std::string const& colour,
- bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty) : HasIdentifier(identifier),
- category(category), cost(cost), colour(colour), isAvailable(isAvailable), isMoney(isMoney), hasOverseasPenalty(hasOverseasPenalty) {};
+ Good(Good&&) = default;
+ Good(std::string const& identifier, std::string const& category, price_t cost, std::string const& colour,
+ bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty) : HasIdentifier(identifier),
+ category(category),
+ cost(cost),
+ colour(colour),
+ isAvailable(isAvailable),
+ isMoney(isMoney),
+ hasOverseasPenalty(hasOverseasPenalty) {};
};
}
diff --git a/extension/src/openvic2/Logger.hpp b/extension/src/openvic2/Logger.hpp
index 624df29..d097cc6 100644
--- a/extension/src/openvic2/Logger.hpp
+++ b/extension/src/openvic2/Logger.hpp
@@ -8,76 +8,80 @@
namespace OpenVic2 {
- #ifndef __cpp_lib_source_location
- #include <string>
- //Implementation of std::source_location for compilers that do not support it
- //Note: uses non-standard extensions that are supported by Clang, GCC, and MSVC
- //https://clang.llvm.org/docs/LanguageExtensions.html#source-location-builtins
- //https://stackoverflow.com/a/67970107
+#ifndef __cpp_lib_source_location
+#include <string>
+ // Implementation of std::source_location for compilers that do not support it
+ // Note: uses non-standard extensions that are supported by Clang, GCC, and MSVC
+ // https://clang.llvm.org/docs/LanguageExtensions.html#source-location-builtins
+ // https://stackoverflow.com/a/67970107
class source_location {
std::string _file;
int _line;
std::string _function;
- public:
- source_location(std::string f, int l, std::string n) : _file(f), _line(l), _function(n) {}
+ public:
+ source_location(std::string f, int l, std::string n) : _file(f),
+ _line(l),
+ _function(n) {}
static source_location current(std::string f = __builtin_FILE(), int l = __builtin_LINE(), std::string n = __builtin_FUNCTION()) {
return source_location(f, l, n);
}
inline char const* file_name() const { return _file.c_str(); }
- inline int line() const {return _line; }
+ inline int line() const { return _line; }
inline char const* function_name() const { return _function.c_str(); }
};
- #endif
+#endif
class Logger {
using log_func_t = std::function<void(std::string&&)>;
- #ifdef __cpp_lib_source_location
+#ifdef __cpp_lib_source_location
using source_location = std::source_location;
- #else
+#else
using source_location = OpenVic2::source_location;
- #endif
+#endif
static log_func_t info_func, error_func;
static char const* get_filename(char const* filepath);
- template <typename... Ts>
+ template<typename... Ts>
struct log {
log(log_func_t log_func, Ts&&... ts, const source_location& location) {
if (log_func) {
std::stringstream stream;
- stream << std::endl << get_filename(location.file_name()) << "(" << location.line() << ") `" << location.function_name() << "`: ";
+ stream << std::endl
+ << get_filename(location.file_name()) << "(" << location.line() << ") `" << location.function_name() << "`: ";
((stream << std::forward<Ts>(ts)), ...);
stream << std::endl;
log_func(stream.str());
}
}
};
+
public:
static void set_info_func(log_func_t log_func);
static void set_error_func(log_func_t log_func);
- template <typename... Ts>
+ template<typename... Ts>
struct info {
info(Ts&&... ts, const source_location& location = source_location::current()) {
- log<Ts...>{ info_func, std::forward<Ts>(ts)..., location };
+ log<Ts...> { info_func, std::forward<Ts>(ts)..., location };
}
};
- template <typename... Ts>
+ template<typename... Ts>
info(Ts&&...) -> info<Ts...>;
- template <typename... Ts>
+ template<typename... Ts>
struct error {
error(Ts&&... ts, const source_location& location = source_location::current()) {
- log<Ts...>{ error_func, std::forward<Ts>(ts)..., location };
+ log<Ts...> { error_func, std::forward<Ts>(ts)..., location };
}
};
- template <typename... Ts>
+ template<typename... Ts>
error(Ts&&...) -> error<Ts...>;
};
}
diff --git a/extension/src/openvic2/Types.cpp b/extension/src/openvic2/Types.cpp
index f51ad7c..58fee7b 100644
--- a/extension/src/openvic2/Types.cpp
+++ b/extension/src/openvic2/Types.cpp
@@ -1,12 +1,12 @@
#include "Types.hpp"
#include <cassert>
-#include <sstream>
#include <iomanip>
+#include <sstream>
using namespace OpenVic2;
-HasIdentifier::HasIdentifier(std::string const& new_identifier) : identifier{ new_identifier } {
+HasIdentifier::HasIdentifier(std::string const& new_identifier) : identifier { new_identifier } {
assert(!identifier.empty());
}
diff --git a/extension/src/openvic2/Types.hpp b/extension/src/openvic2/Types.hpp
index e4a0e2d..a01bae4 100644
--- a/extension/src/openvic2/Types.hpp
+++ b/extension/src/openvic2/Types.hpp
@@ -1,9 +1,9 @@
#pragma once
-#include <vector>
-#include <cstdint>
#include <algorithm>
+#include <cstdint>
#include <map>
+#include <vector>
#include "Logger.hpp"
@@ -37,8 +37,10 @@ namespace OpenVic2 {
*/
class HasIdentifier {
const std::string identifier;
+
protected:
HasIdentifier(std::string const& new_identifier);
+
public:
HasIdentifier(HasIdentifier const&) = delete;
HasIdentifier(HasIdentifier&&) = default;
@@ -53,8 +55,10 @@ namespace OpenVic2 {
*/
class HasColour {
const colour_t colour;
+
protected:
HasColour(colour_t const new_colour);
+
public:
HasColour(HasColour const&) = delete;
HasColour(HasColour&&) = default;
@@ -80,6 +84,7 @@ namespace OpenVic2 {
std::vector<T> items;
bool locked = false;
identifier_index_map_t identifier_index_map;
+
public:
IdentifierRegistry(std::string const& new_name) : name(new_name) {}
return_t add_item(T&& item) {
diff --git a/extension/src/openvic2/map/Building.cpp b/extension/src/openvic2/map/Building.cpp
index 1e26873..a2694b9 100644
--- a/extension/src/openvic2/map/Building.cpp
+++ b/extension/src/openvic2/map/Building.cpp
@@ -7,7 +7,8 @@
using namespace OpenVic2;
-Building::Building(BuildingType const& new_type) : HasIdentifier{ new_type.get_identifier() }, type{ new_type } {}
+Building::Building(BuildingType const& new_type) : HasIdentifier { new_type.get_identifier() },
+ type { new_type } {}
bool Building::_can_expand() const {
return level < type.get_max_level();
@@ -74,8 +75,9 @@ void Building::tick(Date const& today) {
}
}
-BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) :
- HasIdentifier{ new_identifier }, max_level{ new_max_level }, build_time{ new_build_time } {
+BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) : HasIdentifier { new_identifier },
+ max_level { new_max_level },
+ build_time { new_build_time } {
assert(new_max_level >= 0);
assert(build_time >= 0);
}
@@ -88,7 +90,7 @@ Timespan BuildingType::get_build_time() const {
return build_time;
}
-BuildingManager::BuildingManager() : building_types{ "building types" } {}
+BuildingManager::BuildingManager() : building_types { "building types" } {}
return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) {
if (identifier.empty()) {
diff --git a/extension/src/openvic2/map/Building.hpp b/extension/src/openvic2/map/Building.hpp
index 78d08ae..492cbc6 100644
--- a/extension/src/openvic2/map/Building.hpp
+++ b/extension/src/openvic2/map/Building.hpp
@@ -2,8 +2,8 @@
#include <vector>
-#include "../Types.hpp"
#include "../Date.hpp"
+#include "../Types.hpp"
namespace OpenVic2 {
struct Province;
@@ -19,7 +19,13 @@ namespace OpenVic2 {
using level_t = int8_t;
- enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding };
+ enum class ExpansionState {
+ CannotExpand,
+ CanExpand,
+ Preparing,
+ Expanding
+ };
+
private:
BuildingType const& type;
level_t level = 0;
@@ -30,6 +36,7 @@ namespace OpenVic2 {
Building(BuildingType const& new_type);
bool _can_expand() const;
+
public:
Building(Building&&) = default;
@@ -49,11 +56,13 @@ namespace OpenVic2 {
struct BuildingType : HasIdentifier {
friend struct BuildingManager;
+
private:
const Building::level_t max_level;
const Timespan build_time;
BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time);
+
public:
BuildingType(BuildingType&&) = default;
@@ -64,6 +73,7 @@ namespace OpenVic2 {
struct BuildingManager {
private:
IdentifierRegistry<BuildingType> building_types;
+
public:
BuildingManager();
diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp
index 1f44c43..f920ccc 100644
--- a/extension/src/openvic2/map/Map.cpp
+++ b/extension/src/openvic2/map/Map.cpp
@@ -8,7 +8,9 @@
using namespace OpenVic2;
Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func)
- : HasIdentifier{ new_identifier }, index{ new_index }, colour_func{ new_colour_func } {
+ : HasIdentifier { new_identifier },
+ index { new_index },
+ colour_func { new_colour_func } {
assert(colour_func != nullptr);
}
@@ -20,7 +22,9 @@ colour_t Mapmode::get_colour(Map const& map, Province const& province) const {
return colour_func ? colour_func(map, province) : NULL_COLOUR;
}
-Map::Map() : provinces{ "provinces" }, regions{ "regions" }, mapmodes{ "mapmodes" } {}
+Map::Map() : provinces { "provinces" },
+ regions { "regions" },
+ mapmodes { "mapmodes" } {}
return_t Map::add_province(std::string const& identifier, colour_t colour) {
if (provinces.get_item_count() >= MAX_INDEX) {
@@ -35,7 +39,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) {
Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour));
return FAILURE;
}
- Province new_province{ static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour };
+ Province new_province { static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour };
const index_t index = get_index_from_colour(colour);
if (index != NULL_INDEX) {
Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string());
@@ -78,7 +82,7 @@ return_t Map::add_region(std::string const& identifier, std::vector<std::string>
Logger::error("Invalid region identifier - empty!");
return FAILURE;
}
- Region new_region{ identifier };
+ Region new_region { identifier };
return_t ret = SUCCESS;
for (std::string const& province_identifier : province_identifiers) {
Province* province = get_province_by_identifier(province_identifier);
diff --git a/extension/src/openvic2/map/Map.hpp b/extension/src/openvic2/map/Map.hpp
index cb8dcb1..4fc97c9 100644
--- a/extension/src/openvic2/map/Map.hpp
+++ b/extension/src/openvic2/map/Map.hpp
@@ -9,13 +9,15 @@ namespace OpenVic2 {
struct Mapmode : HasIdentifier {
friend struct Map;
- using colour_func_t = std::function<colour_t (Map const&, Province const&)>;
+ using colour_func_t = std::function<colour_t(Map const&, Province const&)>;
using index_t = size_t;
+
private:
const index_t index;
const colour_func_t colour_func;
Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func);
+
public:
index_t get_index() const;
colour_t get_colour(Map const& map, Province const& province) const;
@@ -28,12 +30,12 @@ namespace OpenVic2 {
using terrain_t = uint8_t;
using terrain_variant_map_t = std::map<colour_t, terrain_t>;
- #pragma pack(push, 1)
+#pragma pack(push, 1)
struct shape_pixel_t {
index_t index;
terrain_t terrain;
};
- #pragma pack(pop)
+#pragma pack(pop)
private:
using colour_index_map_t = std::map<colour_t, index_t>;
@@ -48,6 +50,7 @@ namespace OpenVic2 {
colour_index_map_t colour_index_map;
index_t get_index_from_colour(colour_t colour) const;
+
public:
Map();
diff --git a/extension/src/openvic2/map/Province.cpp b/extension/src/openvic2/map/Province.cpp
index b3d455b..79f3ddd 100644
--- a/extension/src/openvic2/map/Province.cpp
+++ b/extension/src/openvic2/map/Province.cpp
@@ -1,13 +1,15 @@
#include "Province.hpp"
#include <cassert>
-#include <sstream>
#include <iomanip>
+#include <sstream>
using namespace OpenVic2;
-Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) :
- HasIdentifier{ new_identifier }, HasColour{ new_colour }, index{ new_index }, buildings{ "buildings" } {
+Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) : HasIdentifier { new_identifier },
+ HasColour { new_colour },
+ index { new_index },
+ buildings { "buildings" } {
assert(index != NULL_INDEX);
assert(new_colour != NULL_COLOUR);
}
@@ -59,7 +61,6 @@ std::string Province::to_string() const {
void Province::update_state(Date const& today) {
for (Building& building : buildings.get_items())
building.update_state(today);
-
}
void Province::tick(Date const& today) {
diff --git a/extension/src/openvic2/map/Province.hpp b/extension/src/openvic2/map/Province.hpp
index 9b07fc1..dd1742c 100644
--- a/extension/src/openvic2/map/Province.hpp
+++ b/extension/src/openvic2/map/Province.hpp
@@ -22,6 +22,7 @@ namespace OpenVic2 {
IdentifierRegistry<Building> buildings;
Province(index_t new_index, std::string const& new_identifier, colour_t new_colour);
+
public:
Province(Province&&) = default;
diff --git a/extension/src/openvic2/map/Region.cpp b/extension/src/openvic2/map/Region.cpp
index da0dfdd..bd87479 100644
--- a/extension/src/openvic2/map/Region.cpp
+++ b/extension/src/openvic2/map/Region.cpp
@@ -16,7 +16,7 @@ std::set<Province*> const& ProvinceSet::get_provinces() const {
return provinces;
}
-Region::Region(std::string const& new_identifier) : HasIdentifier{ new_identifier } {}
+Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
colour_t Region::get_colour() const {
if (provinces.empty()) return 0xFF0000;
diff --git a/extension/src/openvic2/map/Region.hpp b/extension/src/openvic2/map/Region.hpp
index 3920dfc..8f1af70 100644
--- a/extension/src/openvic2/map/Region.hpp
+++ b/extension/src/openvic2/map/Region.hpp
@@ -9,6 +9,7 @@ namespace OpenVic2 {
struct ProvinceSet {
protected:
std::set<Province*> provinces;
+
public:
size_t get_province_count() const;
bool contains_province(Province const* province) const;
@@ -20,8 +21,10 @@ namespace OpenVic2 {
*/
struct Region : HasIdentifier, ProvinceSet {
friend struct Map;
+
private:
Region(std::string const& new_identifier);
+
public:
Region(Region&&) = default;
diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp
index b99f1a8..8ef89ec 100644
--- a/extension/src/register_types.cpp
+++ b/extension/src/register_types.cpp
@@ -3,8 +3,8 @@
#include <godot_cpp/classes/engine.hpp>
#include "Checksum.hpp"
-#include "LoadLocalisation.hpp"
#include "GameSingleton.hpp"
+#include "LoadLocalisation.hpp"
#include "MapMesh.hpp"
using namespace godot;