aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-12 18:56:14 +0200
committer Hop311 <hop3114@gmail.com>2023-08-12 18:56:14 +0200
commitfe74604d96d1d28b811ebe45d1d06356cf79bc6f (patch)
treef57c608c657681666c29e28bf1283833767cb7ea
parent4c43951e70aaa2e7265d3b3f3c4964c048b9328d (diff)
string_view changes + general cleanup
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/GameSingleton.cpp2
-rw-r--r--extension/src/GameSingleton.hpp2
-rw-r--r--extension/src/LoadGameCompatibility.cpp80
-rw-r--r--extension/src/LoadGameOpenVic.cpp12
-rw-r--r--game/src/Game/Autoload/GuiScale.gd10
-rw-r--r--game/src/Game/GameStart.gd9
-rw-r--r--game/src/Game/GameStart.tscn3
-rw-r--r--game/src/Game/LoadingScreen.gd10
-rw-r--r--game/src/Game/Menu/OptionMenu/GuiScaleSelector.gd2
-rw-r--r--game/src/Game/Theme/PieChart/PieChart.gd14
11 files changed, 66 insertions, 78 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 538e7dc4ec44c4d09a6a654f10229e6392653a5
+Subproject d3c6ff1809b88b4c99163402f30b6d10c787510
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index baf4d44..7fc713a 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -9,7 +9,7 @@
using namespace godot;
using namespace OpenVic;
-TerrainVariant::TerrainVariant(std::string const& new_identfier,
+TerrainVariant::TerrainVariant(const std::string_view new_identfier,
colour_t new_colour, Ref<Image> const& new_image)
: HasIdentifierAndColour { new_identfier, new_colour, true },
image { new_image } {}
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index c4e90e0..cd8cdd0 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -12,7 +12,7 @@ namespace OpenVic {
private:
const godot::Ref<godot::Image> image;
- TerrainVariant(std::string const& new_identfier, colour_t new_colour,
+ TerrainVariant(const std::string_view new_identfier, colour_t new_colour,
godot::Ref<godot::Image> const& new_image);
public:
static constexpr size_t MAX_INDEX = 1 << (8 * sizeof(Map::terrain_t));
diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp
index ddde5b8..71435a4 100644
--- a/extension/src/LoadGameCompatibility.cpp
+++ b/extension/src/LoadGameCompatibility.cpp
@@ -17,57 +17,57 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co
Error err = FileAccess::get_open_error();
if (err != OK || file.is_null()) {
UtilityFunctions::push_error("Failed to load compatibility mode province identifier file: ", file_path);
- return err == OK ? FAILED : err;
- }
-
- int line_number = 0;
- while (!file->eof_reached()) {
- const PackedStringArray line = file->get_csv_line(";");
- line_number++;
+ if (err == OK) err = FAILED;
+ } else {
+ int line_number = 0;
+ while (!file->eof_reached()) {
+ const PackedStringArray line = file->get_csv_line(";");
+ line_number++;
- if (line.is_empty() || (line.size() == 1 && line[0].is_empty()))
- continue;
+ if (line.is_empty() || (line.size() == 1 && line[0].is_empty()))
+ continue;
- if (line_number < 2) continue; // skip header line
- index_t id = NULL_INDEX;
- colour_t colour = NULL_COLOUR;
- if (line.size() > 0) {
- if (line[0].is_empty()) {
- id = game_manager.map.get_province_count() + 1;
- } else if (line[0].is_valid_int()) {
- const int64_t val = line[0].to_int();
- if (val > NULL_INDEX && val <= MAX_INDEX) id = val;
- }
- for (int i = 1; i < 4; ++i) {
- if (line.size() > i) {
- if (line[i].is_valid_int()) {
- const int64_t int_val = line[i].to_int();
- if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
- colour = (colour << 8) | int_val;
- continue;
- }
- } else if (line[i].is_valid_float()) {
- const double double_val = line[i].to_float();
- if (std::trunc(double_val) == double_val) {
- const int64_t int_val = double_val;
+ if (line_number < 2) continue; // skip header line
+ index_t id = NULL_INDEX;
+ colour_t colour = NULL_COLOUR;
+ if (line.size() > 0) {
+ if (line[0].is_empty()) {
+ id = game_manager.map.get_province_count() + 1;
+ } else if (line[0].is_valid_int()) {
+ const int64_t val = line[0].to_int();
+ if (val > NULL_INDEX && val <= MAX_INDEX) id = val;
+ }
+ for (int i = 1; i < 4; ++i) {
+ if (line.size() > i) {
+ if (line[i].is_valid_int()) {
+ const int64_t int_val = line[i].to_int();
if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
colour = (colour << 8) | int_val;
continue;
}
+ } else if (line[i].is_valid_float()) {
+ const double double_val = line[i].to_float();
+ if (std::trunc(double_val) == double_val) {
+ const int64_t int_val = double_val;
+ if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
+ colour = (colour << 8) | int_val;
+ continue;
+ }
+ }
}
}
+ colour = NULL_COLOUR;
+ break;
}
- colour = NULL_COLOUR;
- break;
}
+ if (id == NULL_INDEX || colour == NULL_COLOUR) {
+ UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
+ err = FAILED;
+ continue;
+ }
+ static const std::string province_prefix = "PROV";
+ if (game_manager.map.add_province(province_prefix + std::to_string(id), colour) != SUCCESS) err = FAILED;
}
- if (id == NULL_INDEX || colour == NULL_COLOUR) {
- UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
- err = FAILED;
- continue;
- }
- static const std::string province_prefix = "PROV";
- if (game_manager.map.add_province(province_prefix + std::to_string(id), colour) != SUCCESS) err = FAILED;
}
game_manager.map.lock_provinces();
return err;
diff --git a/extension/src/LoadGameOpenVic.cpp b/extension/src/LoadGameOpenVic.cpp
index 27fb265..627578f 100644
--- a/extension/src/LoadGameOpenVic.cpp
+++ b/extension/src/LoadGameOpenVic.cpp
@@ -157,7 +157,11 @@ Error GameSingleton::_parse_region_entry(String const& identifier, Variant const
UtilityFunctions::push_error("Invalid province list for region \"", identifier, "\": ", entry);
return FAILED;
}
- return ERR(game_manager.map.add_region(godot_to_std_string(identifier), province_identifiers));
+ std::vector<std::string_view> province_identifier_views;
+ for (std::string const& str : province_identifiers) {
+ province_identifier_views.push_back(str);
+ }
+ return ERR(game_manager.map.add_region(godot_to_std_string(identifier), province_identifier_views));
}
Error GameSingleton::_load_region_file(String const& file_path) {
@@ -271,7 +275,7 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
// 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) err = FAILED;
+ terrain_image->get_data().ptr(), terrain_variant_map, true) != SUCCESS) err = 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
@@ -364,8 +368,8 @@ Error GameSingleton::_parse_good_entry(String const& identifier, Variant const&
if (var_overseas_maintenance.get_type() == Variant::BOOL) overseas_maintenance = var_overseas_maintenance;
else UtilityFunctions::push_error("Invalid good overseas maintenance bool value for ", identifier, ": ", var_overseas_maintenance);
- return ERR(game_manager.good_manager.add_good(godot_to_std_string(identifier), godot_to_std_string(category),
- colour, base_price, default_available, tradeable, currency, overseas_maintenance));
+ return ERR(game_manager.good_manager.add_good(godot_to_std_string(identifier), colour, godot_to_std_string(category),
+ base_price, default_available, tradeable, currency, overseas_maintenance));
}
Error GameSingleton::_load_goods(String const& defines_path, String const& icons_dir_path) {
diff --git a/game/src/Game/Autoload/GuiScale.gd b/game/src/Game/Autoload/GuiScale.gd
index afd73df..d364ff5 100644
--- a/game/src/Game/Autoload/GuiScale.gd
+++ b/game/src/Game/Autoload/GuiScale.gd
@@ -26,7 +26,7 @@ func _ready():
func has_guiscale(guiscale_value : float) -> bool:
return guiscale_value in _guiscales
-
+
func add_guiscale(guiscale_value: float, guiscale_name: StringName=&"") -> bool:
if has_guiscale(guiscale_value): return true
var scale_dict := { value = guiscale_value }
@@ -39,24 +39,24 @@ func add_guiscale(guiscale_value: float, guiscale_name: StringName=&"") -> bool:
return false
_guiscales[guiscale_value] = scale_dict
return true
-
+
#returns floats
func get_guiscale_value_list() -> Array:
var list := _guiscales.keys()
list.sort_custom(func(a, b): return a > b)
return list
-
+
func get_guiscale_display_name(guiscale_value : float) -> StringName:
return _guiscales.get(guiscale_value, {display_name = &"unknown gui scale"}).display_name
func get_current_guiscale() -> float:
return get_tree().root.content_scale_factor
-
+
func set_guiscale(guiscale:float) -> void:
print("New GUI scale: %f" % guiscale)
if not has_guiscale(guiscale):
push_warning("Setting GUI Scale to non-standard value %sx" % [guiscale])
get_tree().root.content_scale_factor = guiscale
-
+
func reset_guiscale() -> void:
set_guiscale(get_current_guiscale())
diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd
index 995541f..bfbbfb1 100644
--- a/game/src/Game/GameStart.gd
+++ b/game/src/Game/GameStart.gd
@@ -49,12 +49,3 @@ func _initialize_game() -> void:
func _on_splash_container_splash_end():
loading_screen.show()
-
-func _on_loading_screen_load_started():
- Events.Loader.startup_load_begun.emit()
-
-func _on_loading_screen_load_changed(percentage : float) -> void:
- Events.Loader.startup_load_changed.emit(percentage)
-
-func _on_loading_screen_load_ended():
- Events.Loader.startup_load_ended.emit()
diff --git a/game/src/Game/GameStart.tscn b/game/src/Game/GameStart.tscn
index f16daa3..189e72f 100644
--- a/game/src/Game/GameStart.tscn
+++ b/game/src/Game/GameStart.tscn
@@ -51,8 +51,5 @@ stream = ExtResource("5_8euyy")
autoplay = true
expand = true
-[connection signal="load_changed" from="LoadingScreen" to="." method="_on_loading_screen_load_changed"]
-[connection signal="load_ended" from="LoadingScreen" to="." method="_on_loading_screen_load_ended"]
-[connection signal="load_started" from="LoadingScreen" to="." method="_on_loading_screen_load_started"]
[connection signal="splash_end" from="SplashContainer" to="." method="_on_splash_container_splash_end"]
[connection signal="finished" from="SplashContainer/SplashVideo" to="SplashContainer" method="_on_splash_startup_finished"]
diff --git a/game/src/Game/LoadingScreen.gd b/game/src/Game/LoadingScreen.gd
index 3cbf199..d953d20 100644
--- a/game/src/Game/LoadingScreen.gd
+++ b/game/src/Game/LoadingScreen.gd
@@ -1,9 +1,5 @@
extends Control
-signal load_started()
-signal load_changed(percentage : float)
-signal load_ended()
-
@export var quote_file_path : String = "res://common/quotes.txt"
@export_subgroup("Nodes")
@@ -24,7 +20,7 @@ func start_loading_screen(thread_safe_function : Callable) -> void:
thread.wait_to_finish()
thread.start(thread_safe_function)
- load_started.emit()
+ Events.Loader.startup_load_begun.emit()
func try_update_loading_screen(percent_complete: float, quote_should_change = false):
# forces the function to behave as if deferred
@@ -34,9 +30,9 @@ func try_update_loading_screen(percent_complete: float, quote_should_change = fa
quote_label.text = quotes[randi() % quotes.size()]
if is_equal_approx(percent_complete, 100):
thread.wait_to_finish()
- load_ended.emit()
+ Events.Loader.startup_load_ended.emit()
else:
- load_changed.emit(percent_complete)
+ Events.Loader.startup_load_changed.emit(percent_complete)
func _ready():
if Engine.is_editor_hint(): return
diff --git a/game/src/Game/Menu/OptionMenu/GuiScaleSelector.gd b/game/src/Game/Menu/OptionMenu/GuiScaleSelector.gd
index 4dd86e1..42be5e0 100644
--- a/game/src/Game/Menu/OptionMenu/GuiScaleSelector.gd
+++ b/game/src/Game/Menu/OptionMenu/GuiScaleSelector.gd
@@ -32,7 +32,7 @@ func _sync_guiscales(to_select : float = GuiScale.get_current_guiscale()) -> voi
if selected == -1:
selected = default_selected
-
+
func _setup_button():
if default_value <= 0:
default_value = ProjectSettings.get_setting("display/window/stretch/scale")
diff --git a/game/src/Game/Theme/PieChart/PieChart.gd b/game/src/Game/Theme/PieChart/PieChart.gd
index b06dacf..94366c7 100644
--- a/game/src/Game/Theme/PieChart/PieChart.gd
+++ b/game/src/Game/Theme/PieChart/PieChart.gd
@@ -111,8 +111,8 @@ func sort_slices() -> void:
func _ready():
if not Engine.is_editor_hint():
- const size : int = 256
- _pie_chart_image = Image.create(size, size, false, Image.FORMAT_RGBA8)
+ const image_size : int = 256
+ _pie_chart_image = Image.create(image_size, image_size, false, Image.FORMAT_RGBA8)
texture = ImageTexture.create_from_image(_pie_chart_image)
_recalculate()
@@ -160,11 +160,11 @@ func _on_mouse_exited():
# is hovered over. Returns a boolean on whether the tooltip was handled.
func _handle_tooltip(pos : Vector2) -> bool:
# Is it within the circle?
- var radius := size.x / 2.0
- var center := Vector2(radius, radius)
+ var real_radius := size.x / 2.0
+ var center := Vector2(real_radius, real_radius)
var distance := center.distance_to(pos)
- var real_donut_inner_radius : float = radius * donut_inner_radius
- if distance <= radius and (not donut or distance >= real_donut_inner_radius):
+ var real_donut_inner_radius : float = real_radius * donut_inner_radius
+ if distance <= real_radius and (not donut or distance >= real_donut_inner_radius):
if _slice_order.is_empty():
_rich_tooltip.text = "PIECHART_TOOLTIP_NO_DATA"
else:
@@ -189,7 +189,7 @@ func _handle_tooltip(pos : Vector2) -> bool:
# Create a list of all the values and percentages
# with the hovered one highlighted
func _create_tooltip(labelHovered : String) -> String:
- var slice_tooltips : PackedStringArray
+ var slice_tooltips : PackedStringArray = []
for label in _slice_order:
var slice : SliceData = _slices.get(label)
var percent := _format_percent(slice.percentage)