Skip to content

Commit e21ccbb

Browse files
authored
Merge pull request #673 from OpenVicProject/refactor/core-portable
Refactor porting classes to core/portable path
2 parents b7d7ee2 + c44123b commit e21ccbb

28 files changed

+118
-118
lines changed

src/headless/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
260260
SPDLOG_INFO("===== Ranking system test... =====");
261261
if (game_manager.get_instance_manager()) {
262262
const auto print_ranking_list = [ //
263-
](std::string_view title, OpenVic::utility::forwardable_span<CountryInstance* const> countries) -> void {
263+
](std::string_view title, OpenVic::forwardable_span<CountryInstance* const> countries) -> void {
264264
memory::string countries_str;
265265
for (CountryInstance* country : countries) {
266266
countries_str += fmt::format(
@@ -278,7 +278,7 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
278278
CountryInstanceManager const& country_instance_manager =
279279
game_manager.get_instance_manager()->get_country_instance_manager();
280280

281-
OpenVic::utility::forwardable_span<CountryInstance* const> great_powers = country_instance_manager.get_great_powers();
281+
OpenVic::forwardable_span<CountryInstance* const> great_powers = country_instance_manager.get_great_powers();
282282
print_ranking_list("Great Powers", great_powers);
283283
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
284284
print_ranking_list("All countries", country_instance_manager.get_total_ranking());
File renamed without changes.

src/openvic-simulation/utility/ForwardableSpan.hpp renamed to src/openvic-simulation/core/portable/ForwardableSpan.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <ranges>
1010
#include <type_traits>
1111

12-
#include "openvic-simulation/types/BasicIterator.hpp"
1312
#include "openvic-simulation/core/Typedefs.hpp"
13+
#include "openvic-simulation/types/BasicIterator.hpp"
1414

15-
namespace OpenVic::utility::_detail::forwardable_span {
15+
namespace OpenVic::_detail::forwardable_span {
1616
static constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();
1717

1818
template<class T, std::size_t Extent = dynamic_extent>
@@ -347,7 +347,7 @@ namespace OpenVic::utility::_detail::forwardable_span {
347347
span(Range&&) -> span<std::remove_reference_t<std::ranges::range_reference_t<Range&>>>;
348348
}
349349

350-
namespace OpenVic::utility {
350+
namespace OpenVic {
351351
static constexpr std::size_t dynamic_extent = _detail::forwardable_span::dynamic_extent;
352352

353353
template<class T, std::size_t Extent = dynamic_extent>
@@ -357,37 +357,37 @@ namespace OpenVic::utility {
357357
namespace std {
358358
namespace ranges {
359359
template<typename T, std::size_t Extent>
360-
inline constexpr bool enable_borrowed_range<OpenVic::utility::forwardable_span<T, Extent>> = true;
360+
inline constexpr bool enable_borrowed_range<OpenVic::forwardable_span<T, Extent>> = true;
361361

362362
template<typename T, std::size_t Extent>
363-
inline constexpr bool enable_view<OpenVic::utility::forwardable_span<T, Extent>> = true;
363+
inline constexpr bool enable_view<OpenVic::forwardable_span<T, Extent>> = true;
364364
}
365365

366366
template<typename T, size_t Extent>
367-
[[nodiscard]] inline OpenVic::utility::forwardable_span<
367+
[[nodiscard]] inline OpenVic::forwardable_span<
368368
const std::byte, Extent == dynamic_extent ? dynamic_extent : Extent * sizeof(T)>
369-
as_bytes(OpenVic::utility::forwardable_span<T, Extent> sp) {
369+
as_bytes(OpenVic::forwardable_span<T, Extent> sp) {
370370
auto data = reinterpret_cast<const std::byte*>(sp.data());
371371
auto size = sp.size_bytes();
372372
constexpr std::size_t extent = Extent == dynamic_extent ? dynamic_extent : Extent * sizeof(T);
373-
return OpenVic::utility::forwardable_span<const std::byte, extent> { data, size };
373+
return OpenVic::forwardable_span<const std::byte, extent> { data, size };
374374
}
375375

376376
template<typename T, size_t Extent>
377377
requires(!std::is_const_v<T>)
378-
inline OpenVic::utility::forwardable_span<std::byte, Extent == dynamic_extent ? dynamic_extent : Extent * sizeof(T)>
379-
as_writable_bytes [[nodiscard]] (OpenVic::utility::forwardable_span<T, Extent> sp) {
378+
inline OpenVic::forwardable_span<std::byte, Extent == dynamic_extent ? dynamic_extent : Extent * sizeof(T)>
379+
as_writable_bytes [[nodiscard]] (OpenVic::forwardable_span<T, Extent> sp) {
380380
auto data = reinterpret_cast<std::byte*>(sp.data());
381381
auto size = sp.size_bytes();
382382
constexpr std::size_t extent = Extent == dynamic_extent ? dynamic_extent : Extent * sizeof(T);
383-
return OpenVic::utility::forwardable_span<std::byte, extent> { data, size };
383+
return OpenVic::forwardable_span<std::byte, extent> { data, size };
384384
}
385385
}
386386

387387
#else
388388
#include <span>
389389

390-
namespace OpenVic::utility {
390+
namespace OpenVic {
391391
template<class T, std::size_t Extent = std::dynamic_extent>
392392
using forwardable_span = std::span<T, Extent>;
393393
}

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ void CountryInstance::after_sell(void* actor, SellResult const& sell_result, mem
19241924

19251925
void CountryInstance::country_tick_before_map(
19261926
IndexedFlatMap<GoodDefinition, char>& reusable_goods_mask,
1927-
utility::forwardable_span<
1927+
forwardable_span<
19281928
memory::vector<fixed_point_t>,
19291929
VECTORS_FOR_COUNTRY_TICK
19301930
> reusable_vectors,
@@ -2048,7 +2048,7 @@ void CountryInstance::calculate_government_good_needs() {
20482048

20492049
void CountryInstance::manage_national_stockpile(
20502050
IndexedFlatMap<GoodDefinition, char>& reusable_goods_mask,
2051-
utility::forwardable_span<
2051+
forwardable_span<
20522052
memory::vector<fixed_point_t>,
20532053
VECTORS_FOR_COUNTRY_TICK
20542054
> reusable_vectors,

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ namespace OpenVic {
623623

624624
void manage_national_stockpile(
625625
IndexedFlatMap<GoodDefinition, char>& reusable_goods_mask,
626-
utility::forwardable_span<
626+
forwardable_span<
627627
memory::vector<fixed_point_t>,
628628
VECTORS_FOR_COUNTRY_TICK
629629
> reusable_vectors,
@@ -661,7 +661,7 @@ namespace OpenVic {
661661
void update_gamestate(const Date today, MapInstance& map_instance);
662662
void country_tick_before_map(
663663
IndexedFlatMap<GoodDefinition, char>& reusable_goods_mask,
664-
utility::forwardable_span<
664+
forwardable_span<
665665
memory::vector<fixed_point_t>,
666666
VECTORS_FOR_COUNTRY_TICK
667667
> reusable_vectors,

src/openvic-simulation/country/CountryInstanceDeps.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "openvic-simulation/types/Date.hpp"
44
#include "openvic-simulation/types/UnitBranchType.hpp"
5-
#include "openvic-simulation/utility/ForwardableSpan.hpp"
5+
#include "openvic-simulation/core/portable/ForwardableSpan.hpp"
66

77
namespace OpenVic {
88
struct BuildingType;
@@ -27,28 +27,28 @@ namespace OpenVic {
2727
struct UnitTypeManager;
2828

2929
struct CountryInstanceDeps {
30-
utility::forwardable_span<const BuildingType> building_types;
30+
forwardable_span<const BuildingType> building_types;
3131
CountryDefines const& country_defines;
3232
CountryRelationManager& country_relations_manager;
33-
utility::forwardable_span<const Crime> crimes;
33+
forwardable_span<const Crime> crimes;
3434
Date fallback_date_for_never_completing_research;
3535
DiplomacyDefines const& diplomacy_defines;
3636
EconomyDefines const& economy_defines;
37-
utility::forwardable_span<const Invention> inventions;
38-
utility::forwardable_span<const Ideology> ideologies;
37+
forwardable_span<const Invention> inventions;
38+
forwardable_span<const Ideology> ideologies;
3939
GameRulesManager const& game_rules_manager;
40-
utility::forwardable_span<const GoodInstance> good_instances;
40+
forwardable_span<const GoodInstance> good_instances;
4141
GoodInstanceManager& good_instance_manager;
42-
utility::forwardable_span<const GovernmentType> government_types;
42+
forwardable_span<const GovernmentType> government_types;
4343
MarketInstance& market_instance;
4444
MilitaryDefines const& military_defines;
4545
ModifierEffectCache const& modifier_effect_cache;
46-
utility::forwardable_span<const PopType> pop_types;
47-
utility::forwardable_span<const ReformGroup> reforms;
48-
utility::forwardable_span<const RegimentType> regiment_types;
49-
utility::forwardable_span<const ShipType> ship_types;
50-
utility::forwardable_span<const Strata> stratas;
51-
utility::forwardable_span<const Technology> technologies;
46+
forwardable_span<const PopType> pop_types;
47+
forwardable_span<const ReformGroup> reforms;
48+
forwardable_span<const RegimentType> regiment_types;
49+
forwardable_span<const ShipType> ship_types;
50+
forwardable_span<const Strata> stratas;
51+
forwardable_span<const Technology> technologies;
5252
UnitTypeManager const& unit_type_manager;
5353
};
5454
}

src/openvic-simulation/country/CountryInstanceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CountryInstanceManager::CountryInstanceManager(
1818
CountryInstanceDeps const& country_instance_deps,
1919
GoodInstanceManager const& new_good_instance_manager,
2020
PopsDefines const& new_pop_defines,
21-
utility::forwardable_span<const PopType> pop_type_keys,
21+
forwardable_span<const PopType> pop_type_keys,
2222
ThreadPool& new_thread_pool
2323
) : thread_pool { new_thread_pool },
2424
country_definition_manager { new_country_definition_manager },

src/openvic-simulation/country/CountryInstanceManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace OpenVic {
4949
CountryInstanceDeps const& country_instance_deps,
5050
GoodInstanceManager const& new_good_instance_manager,
5151
PopsDefines const& new_pop_defines,
52-
utility::forwardable_span<const PopType> pop_type_keys,
52+
forwardable_span<const PopType> pop_type_keys,
5353
ThreadPool& new_thread_pool
5454
);
5555

src/openvic-simulation/economy/GoodInstance.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ namespace OpenVic {
4141
GameRulesManager const& game_rules_manager
4242
);
4343

44-
constexpr OpenVic::utility::forwardable_span<GoodInstance> get_good_instances() {
44+
constexpr forwardable_span<GoodInstance> get_good_instances() {
4545
return good_instance_by_definition.get_values();
4646
}
4747

48-
constexpr OpenVic::utility::forwardable_span<const GoodInstance> get_good_instances() const {
48+
constexpr forwardable_span<const GoodInstance> get_good_instances() const {
4949
return good_instance_by_definition.get_values();
5050
}
5151
GoodInstance* get_good_instance_by_identifier(std::string_view identifier);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "openvic-simulation/utility/ForwardableSpan.hpp"
3+
#include "openvic-simulation/core/portable/ForwardableSpan.hpp"
44

55
namespace OpenVic {
66
struct EconomyDefines;
@@ -9,7 +9,7 @@ namespace OpenVic {
99

1010
struct ArtisanalProducerDeps {
1111
EconomyDefines const& economy_defines;
12-
utility::forwardable_span<const GoodDefinition> good_keys;
12+
forwardable_span<const GoodDefinition> good_keys;
1313
ModifierEffectCache const& modifier_effect_cache;
1414
};
1515
}

0 commit comments

Comments
 (0)