1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#pragma once
#include "openvic-simulation/modifier/Modifier.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
namespace OpenVic {
struct TerrainTypeManager;
// Using HasColour rather than HasIdentifierAndColour to avoid needing virtual inheritance
// (extending Modifier is more useful than extending HasIdentifierAndColour).
struct TerrainType : Modifier, HasColour {
friend struct TerrainTypeManager;
private:
ModifierValue PROPERTY(modifier);
const bool PROPERTY(is_water);
TerrainType(std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_modifier, bool new_is_water);
public:
TerrainType(TerrainType&&) = default;
};
struct TerrainTypeMapping : HasIdentifier {
friend struct TerrainTypeManager;
using index_t = uint8_t;
private:
TerrainType const& PROPERTY(type);
std::vector<index_t> PROPERTY(terrain_indices);
const index_t PROPERTY(priority);
const bool PROPERTY(has_texture);
TerrainTypeMapping(
std::string_view new_identifier, TerrainType const& new_type, std::vector<index_t>&& new_terrain_indicies,
index_t new_priority, bool new_has_texture
);
public:
TerrainTypeMapping(TerrainTypeMapping&&) = default;
};
struct TerrainTypeManager {
private:
using terrain_type_mappings_map_t = ordered_map<TerrainTypeMapping::index_t, size_t>;
IdentifierRegistry<TerrainType> IDENTIFIER_REGISTRY(terrain_type);
IdentifierRegistry<TerrainTypeMapping> IDENTIFIER_REGISTRY(terrain_type_mapping);
terrain_type_mappings_map_t terrain_type_mappings_map;
TerrainTypeMapping::index_t terrain_texture_limit = 0, terrain_texture_count = 0;
NodeTools::node_callback_t _load_terrain_type_categories(ModifierManager const& modifier_manager);
bool _load_terrain_type_mapping(std::string_view key, ast::NodeCPtr value);
public:
bool add_terrain_type(std::string_view identifier, colour_t colour, ModifierValue&& values, bool is_water);
bool add_terrain_type_mapping(
std::string_view identifier, TerrainType const* type, std::vector<TerrainTypeMapping::index_t>&& terrain_indicies,
TerrainTypeMapping::index_t priority, bool has_texture
);
TerrainTypeMapping const* get_terrain_type_mapping_for(TerrainTypeMapping::index_t idx) const;
TerrainTypeMapping::index_t get_terrain_texture_limit() const;
bool load_terrain_types(ModifierManager const& modifier_manager, ast::NodeCPtr root);
};
}
|