Skip to content

Commit

Permalink
2018.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
schombert committed Apr 3, 2018
1 parent c7a43c3 commit 3fd2226
Show file tree
Hide file tree
Showing 16 changed files with 2,243 additions and 77 deletions.
20 changes: 20 additions & 0 deletions Open V2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "triggers", "triggers\trigge
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "triggers_gtests", "triggers_gtests\triggers_gtests.vcxproj", "{855B0C1D-D3A5-4C7F-95AA-1B6CEA2AD387}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "variables", "variables\variables.vcxproj", "{90316E63-9CE3-4D2B-80AC-440903861B0D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "variables_gtests", "variables_gtests\variables_gtests.vcxproj", "{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -621,6 +625,22 @@ Global
{855B0C1D-D3A5-4C7F-95AA-1B6CEA2AD387}.Release|x64.Build.0 = Release|x64
{855B0C1D-D3A5-4C7F-95AA-1B6CEA2AD387}.Release|x86.ActiveCfg = Release|Win32
{855B0C1D-D3A5-4C7F-95AA-1B6CEA2AD387}.Release|x86.Build.0 = Release|Win32
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Debug|x64.ActiveCfg = Debug|x64
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Debug|x64.Build.0 = Debug|x64
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Debug|x86.ActiveCfg = Debug|Win32
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Debug|x86.Build.0 = Debug|Win32
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Release|x64.ActiveCfg = Release|x64
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Release|x64.Build.0 = Release|x64
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Release|x86.ActiveCfg = Release|Win32
{90316E63-9CE3-4D2B-80AC-440903861B0D}.Release|x86.Build.0 = Release|Win32
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Debug|x64.ActiveCfg = Debug|x64
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Debug|x64.Build.0 = Debug|x64
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Debug|x86.ActiveCfg = Debug|Win32
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Debug|x86.Build.0 = Debug|Win32
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Release|x64.ActiveCfg = Release|x64
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Release|x64.Build.0 = Release|x64
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Release|x86.ActiveCfg = Release|Win32
{C9FE84DF-4891-4A3D-AF04-3FFDF081211C}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 7 additions & 3 deletions common/shared_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace technologies {
using tech_subcategory_tag = tag_type<uint8_t, std::true_type, std::integral_constant<size_t, 72649>>;
using tech_tag = tag_type<uint16_t, std::true_type, std::integral_constant<size_t, 72650>>;
using invention_tag = tag_type<uint16_t, std::true_type, std::integral_constant<size_t, 72651>>;
using tech_school_tag = tag_type<uint8_t, std::true_type, std::integral_constant<size_t, 72652>>;
}

namespace ideologies {
Expand Down Expand Up @@ -95,8 +94,13 @@ namespace text_data {
using text_tag = tag_type<uint16_t, std::true_type, std::integral_constant<size_t, 342678>>;
}

template<typename tag_type, typename T, typename U>
inline tag_type tag_from_text(const boost::container::flat_map<text_data::text_tag, tag_type, T, U>& map, text_data::text_tag t) {
namespace variables {
using national_variable_tag = tag_type<uint16_t, std::true_type, std::integral_constant<size_t, 4745824>>;
using global_variable_tag = tag_type<uint16_t, std::true_type, std::integral_constant<size_t, 4745826>>;
}

template<typename tag_type, typename index_type, typename T, typename U>
inline tag_type tag_from_text(const boost::container::flat_map<index_type, tag_type, T, U>& map, index_type t) {
const auto f = map.find(t);
if (f != map.cend())
return f->second;
Expand Down
4 changes: 3 additions & 1 deletion scenario/scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "provinces\\provinces.h"
#include "technologies\\technologies.h"
#include "text_data\\text_data.h"
#include "variables\\variables.h"

namespace scenario {
class scenario_manager {
Expand All @@ -22,9 +23,10 @@ namespace scenario {
modifiers::modifiers_manager modifiers_m;
provinces::province_manager province_m;
technologies::technologies_manager technology_m;
variables::variables_manager variables_m;

text_data::text_sequences& text_m;

scenario_manager(text_data::text_sequences& tm) : text_m(tm) {}
};
}
}
20 changes: 10 additions & 10 deletions technologies/technologies.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#include "technologies.h"
#include "Parsers\\parsers.hpp"
#include "object_parsing\\object_parsing.hpp"
#include "modifiers\\modifiers.h"

namespace technologies {
struct parsing_environment{
text_handle_lookup text_lookup;
tech_file_handler file_handler;

technologies_manager& manager;
modifiers::modifiers_manager& mod_manager;

parsed_data main_file_parse_tree;
std::vector<std::pair<tech_category_tag, parsed_data>> tech_files_parse_trees;
std::vector<parsed_data> inventions_parse_trees;

parsing_environment(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m) :
text_lookup(tl), file_handler(fh), manager(m) {
parsing_environment(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m, modifiers::modifiers_manager& mm) :
text_lookup(tl), file_handler(fh), manager(m), mod_manager(mm) {
}
};

parsing_state::parsing_state(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m) :
impl(std::make_unique<parsing_environment>(tl, fh, m)) {}
parsing_state::parsing_state(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m, modifiers::modifiers_manager& mm) :
impl(std::make_unique<parsing_environment>(tl, fh, m, mm)) {}
parsing_state::~parsing_state() {}

parsing_state::parsing_state(parsing_state&& o) noexcept : impl(std::move(o.impl)) {}
Expand Down Expand Up @@ -100,10 +102,7 @@ namespace technologies {

void add_school(const token_and_type& t) {
const auto name = env.text_lookup(t.start, t.end);
const auto new_st = env.manager.tech_schools.emplace_back();
auto& s = env.manager.tech_schools[new_st];
s.id = new_st;
s.name = name;
const auto new_st = env.mod_manager.fetch_unique_national_modifier(name);
env.manager.named_tech_school_index.emplace(name, new_st);
}
};
Expand Down Expand Up @@ -227,9 +226,10 @@ namespace technologies {
technologies_manager& tech_manager,
std::vector<token_group>& parse_results,
const text_handle_lookup& text_function,
const tech_file_handler& file_function) {
const tech_file_handler& file_function,
modifiers::modifiers_manager& mod_manager) {

parsing_environment e(text_function, file_function, tech_manager);
parsing_environment e(text_function, file_function, tech_manager, mod_manager);
if (parse_results.size() > 0)
parse_object<technologies_file, tech_pre_parsing_domain>(&parse_results[0], &parse_results[0] + parse_results.size(), e);
}
Expand Down
18 changes: 8 additions & 10 deletions technologies/technologies.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "concurrency_tools\\concurrency_tools.h"
#include "text_data\\text_data.h"

namespace modifiers {
class modifiers_manager;
}

namespace technologies {
struct technology_category {
text_data::text_tag name;
Expand All @@ -34,25 +38,18 @@ namespace technologies {
invention_tag id;
};

struct tech_school {
text_data::text_tag name;

tech_school_tag id;
};

class technologies_manager {
public:
boost::container::flat_map<text_data::text_tag, tech_category_tag> named_category_index;
boost::container::flat_map<text_data::text_tag, tech_subcategory_tag> named_subcategory_index;
boost::container::flat_map<text_data::text_tag, tech_tag> named_technology_index;
boost::container::flat_map<text_data::text_tag, tech_school_tag> named_tech_school_index;
boost::container::flat_map<text_data::text_tag, modifiers::national_modifier_tag> named_tech_school_index;
boost::container::flat_map<text_data::text_tag, invention_tag> named_invention_index;


tagged_vector<technology_category, tech_category_tag> technology_categories;
tagged_vector<technology_subcategory, tech_subcategory_tag> technology_subcategories;
tagged_vector<technology, tech_tag> technologies_container;
tagged_vector<tech_school, tech_school_tag> tech_schools;
tagged_vector<invention, invention_tag> inventions;
};

Expand All @@ -66,15 +63,16 @@ namespace technologies {
technologies_manager& tech_manager,
std::vector<token_group>& parse_results,
const text_handle_lookup& text_function,
const tech_file_handler& file_function);
const tech_file_handler& file_function,
modifiers::modifiers_manager& mm);

struct parsing_environment;

class parsing_state {
public:
std::unique_ptr<parsing_environment> impl;

parsing_state(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m);
parsing_state(const text_handle_lookup& tl, const tech_file_handler& fh, technologies_manager& m, modifiers::modifiers_manager& mm);
parsing_state(parsing_state&&) noexcept;
~parsing_state();
};
Expand Down
5 changes: 5 additions & 0 deletions technologies/technologies.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
<ItemGroup>
<ClCompile Include="technologies.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\modifiers\modifiers.vcxproj">
<Project>{54477a39-7934-4c4a-9744-17399338af31}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
36 changes: 21 additions & 15 deletions technologies_gtests/technologies_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "technologies\\technologies.h"
#include "gtest/gtest.h"
#include "fake_fs\\fake_fs.h"
#include "modifiers\\modifiers.h"

#define RANGE(x) (x), (x) + (sizeof((x))/sizeof((x)[0])) - 1

Expand Down Expand Up @@ -137,14 +138,15 @@ TEST(technologies_tests, pre_parse_tech_file) {

std::vector<token_group> results;
technologies_manager manager;
modifiers::modifiers_manager mm;

parse_pdx_file(results, fake_tech_file, fake_tech_file + sizeof(fake_tech_file) - 1);
pre_parse_main_technology_file(manager, results, fake_text_handle_lookup(), make_fake_tech_file_parse(count_sub_files));
pre_parse_main_technology_file(manager, results, fake_text_handle_lookup(), make_fake_tech_file_parse(count_sub_files), mm);

EXPECT_EQ(2, count_sub_files);
EXPECT_EQ(2ui64, manager.technology_categories.size());
EXPECT_EQ(4ui64, manager.technology_subcategories.size());
EXPECT_EQ(1ui64, manager.tech_schools.size());
EXPECT_EQ(1ui64, manager.named_tech_school_index.size());

EXPECT_EQ(tech_category_tag(0), manager.technology_categories[tech_category_tag(0)].id);
EXPECT_EQ(tech_category_tag(1), manager.technology_categories[tech_category_tag(1)].id);
Expand All @@ -161,29 +163,31 @@ TEST(technologies_tests, pre_parse_tech_file) {
EXPECT_EQ(4ui64, manager.named_subcategory_index.size());
EXPECT_EQ(1ui64, manager.named_tech_school_index.size());

EXPECT_EQ(tech_school_tag(0), manager.tech_schools[tech_school_tag(0)].id);
const auto fr = manager.named_tech_school_index[manager.tech_schools[tech_school_tag(0)].name];
EXPECT_EQ(fr, tech_school_tag(0));
EXPECT_EQ(modifiers::national_modifier_tag(0), mm.national_modifiers[modifiers::national_modifier_tag(0)].id);
const auto fr = manager.named_tech_school_index[mm.national_modifiers[modifiers::national_modifier_tag(0)].name];
EXPECT_EQ(modifiers::national_modifier_tag(0), fr);
}

TEST(technologies_tests, pre_parse_schools) {
int count_sub_files = 0;

std::vector<token_group> results;
technologies_manager manager;
modifiers::modifiers_manager mm;

parse_pdx_file(results, fake_tech_file_b, fake_tech_file_b + sizeof(fake_tech_file_b) - 1);
pre_parse_main_technology_file(manager, results, fake_text_handle_lookup(), make_fake_tech_file_parse(count_sub_files));
pre_parse_main_technology_file(manager, results, fake_text_handle_lookup(), make_fake_tech_file_parse(count_sub_files), mm);

EXPECT_EQ(2ui64, manager.tech_schools.size());
EXPECT_EQ(2ui64, mm.national_modifiers.size());
EXPECT_EQ(2ui64, mm.named_national_modifiers_index.size());
EXPECT_EQ(2ui64, manager.named_tech_school_index.size());

EXPECT_EQ(tech_school_tag(0), manager.tech_schools[tech_school_tag(0)].id);
EXPECT_EQ(tech_school_tag(1), manager.tech_schools[tech_school_tag(1)].id);
const auto fr = manager.named_tech_school_index[manager.tech_schools[tech_school_tag(0)].name];
EXPECT_EQ(fr, tech_school_tag(0));
const auto frb = manager.named_tech_school_index[manager.tech_schools[tech_school_tag(1)].name];
EXPECT_EQ(frb, tech_school_tag(1));
EXPECT_EQ(modifiers::national_modifier_tag(0), mm.national_modifiers[modifiers::national_modifier_tag(0)].id);
EXPECT_EQ(modifiers::national_modifier_tag(1), mm.national_modifiers[modifiers::national_modifier_tag(1)].id);
const auto fr = manager.named_tech_school_index[mm.national_modifiers[modifiers::national_modifier_tag(0)].name];
EXPECT_EQ(fr, modifiers::national_modifier_tag(0));
const auto frb = manager.named_tech_school_index[mm.national_modifiers[modifiers::national_modifier_tag(1)].name];
EXPECT_EQ(frb, modifiers::national_modifier_tag(1));
}

TEST(technologies_tests, pre_parse_techs_test) {
Expand All @@ -193,10 +197,11 @@ TEST(technologies_tests, pre_parse_techs_test) {
f.set_root(RANGE(u"F:"));

technologies_manager manager;
modifiers::modifiers_manager mm;

const auto tech_dir = f.get_root().get_directory(u"\\technologies");

parsing_state state(fake_text_handle_lookup(), make_subfile_perparse_handler(tech_dir), manager);
parsing_state state(fake_text_handle_lookup(), make_subfile_perparse_handler(tech_dir), manager, mm);

pre_parse_technologies(state, f.get_root());

Expand All @@ -212,10 +217,11 @@ TEST(technologies_tests, pre_parse_inventions_test) {
f.set_root(RANGE(u"F:"));

technologies_manager manager;
modifiers::modifiers_manager mm;

const auto tech_dir = f.get_root().get_directory(u"\\technologies");

parsing_state state(fake_text_handle_lookup(), make_subfile_perparse_handler(tech_dir), manager);
parsing_state state(fake_text_handle_lookup(), make_subfile_perparse_handler(tech_dir), manager, mm);

pre_parse_inventions(state, f.get_root());

Expand Down
Loading

0 comments on commit 3fd2226

Please sign in to comment.