From c94a06477fc3930e8f8f2e5f971fc4b5b838ea0d Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 6 Jun 2024 21:49:59 +0100 Subject: Separated out MapmodeManager --- src/openvic-simulation/map/Map.cpp | 66 -------------------------------------- 1 file changed, 66 deletions(-) (limited to 'src/openvic-simulation/map/Map.cpp') diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 8f6471e..11b940f 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -1,6 +1,5 @@ #include "Map.hpp" -#include #include #include @@ -12,23 +11,6 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -using namespace OpenVic::colour_literals; - -Mapmode::Mapmode( - std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func -) : HasIdentifier { new_identifier }, index { new_index }, colour_func { new_colour_func } { - assert(colour_func != nullptr); -} - -const Mapmode Mapmode::ERROR_MAPMODE { - "mapmode_error", 0, [](Map const& map, ProvinceInstance const& province) -> base_stripe_t { - return { 0xFFFF0000_argb, colour_argb_t::null() }; - } -}; - -Mapmode::base_stripe_t Mapmode::get_base_stripe_colours(Map const& map, ProvinceInstance const& province) const { - return colour_func ? colour_func(map, province) : colour_argb_t::null(); -} Map::Map() : dims { 0, 0 }, max_provinces { ProvinceDefinition::MAX_INDEX }, selected_province { nullptr }, @@ -427,54 +409,6 @@ ProvinceDefinition::index_t Map::get_selected_province_index() const { : ProvinceDefinition::NULL_INDEX; } -bool Map::add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func) { - if (identifier.empty()) { - Logger::error("Invalid mapmode identifier - empty!"); - return false; - } - if (colour_func == nullptr) { - Logger::error("Mapmode colour function is null for identifier: ", identifier); - return false; - } - return mapmodes.add_item({ identifier, mapmodes.size(), colour_func }); -} - -bool Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const { - if (target == nullptr) { - Logger::error("Mapmode colour target pointer is null!"); - return false; - } - - bool ret = true; - Mapmode const* mapmode = mapmodes.get_item_by_index(index); - if (mapmode == nullptr) { - // Not an error if mapmodes haven't yet been loaded, - // e.g. if we want to allocate the province colour - // texture before mapmodes are loaded. - if (!(mapmodes.empty() && index == 0)) { - Logger::error("Invalid mapmode index: ", index); - ret = false; - } - mapmode = &Mapmode::ERROR_MAPMODE; - } - - Mapmode::base_stripe_t* target_stripes = reinterpret_cast(target); - - target_stripes[ProvinceDefinition::NULL_INDEX] = colour_argb_t::null(); - - if (province_instances_are_locked()) { - for (ProvinceInstance const& province : province_instances.get_items()) { - target_stripes[province.get_province_definition().get_index()] = mapmode->get_base_stripe_colours(*this, province); - } - } else { - for (size_t index = ProvinceDefinition::NULL_INDEX + 1; index <= get_province_definition_count(); ++index) { - target_stripes[index] = colour_argb_t::null(); - } - } - - return ret; -} - bool Map::reset(BuildingTypeManager const& building_type_manager) { if (!province_definitions_are_locked()) { Logger::error("Cannot reset map - province consts are not locked!"); -- cgit v1.2.3-56-ga3b1