Skip to content

Commit

Permalink
fix: code
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Mar 10, 2024
2 parents fd53d0f + 1605f70 commit 3327e60
Show file tree
Hide file tree
Showing 27 changed files with 99 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake-all-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake-All-Build
name: CMakeAllBuild

on:
push:
Expand All @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Checkout submodules
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cmake-unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake-Unit-Test
name: CMakeUnitTest

on:
push:
Expand All @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Checkout submodules
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: cppcheck
name: Cppcheck

on: [pull_request]

Expand All @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup cppcheck
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generate-doxygen.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate-Doxygen
name: GenerateDoxygen

on:
push:
Expand All @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Doxygen and Graphviz
run: sudo apt-get install doxygen graphviz
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reviewdog-cpplint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Reviewdog-cpplint
name: ReviewdogCpplint

on: [pull_request]

Expand All @@ -8,7 +8,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: cpplint
uses: reviewdog/action-cpplint@b6c13159b10435813edfddea9e1cd02157544f45
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_MAHOROBA/Calendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace paxs {

bool update(
#ifdef PAXS_USING_SIMULATOR
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator // コンパイル時の分岐により使わない場合あり
std::unique_ptr<paxs::SettlementSimulator>& simulator // コンパイル時の分岐により使わない場合あり
#endif
) {
bool return_bool = false;
Expand Down
4 changes: 2 additions & 2 deletions Library/PAX_MAHOROBA/Main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace paxs {
paxs::Graphics3DModel g3d_model; // 3D モデル

#ifdef PAXS_USING_SIMULATOR
std::unique_ptr<paxs::SettlementSimulator<int>> simulator{};
std::unique_ptr<paxs::SettlementSimulator> simulator{};

SimulationRange sr;
// シミュレーションの範囲を設定
Expand All @@ -138,7 +138,7 @@ namespace paxs {

tm.init(); // タッチ判定を初期化
#ifdef PAXS_USING_SIV3D
const s3d::ScopedRenderStates2D sampler{ s3d::SamplerState::ClampNearest }; // 画像の拡大縮小の方式を設定
const s3d::ScopedRenderStates2D sampler{ s3d::SamplerState::ClampNearest }; // 画像の拡大縮小の方式を設定
#endif
/*##########################################################################################
更新処理関連
Expand Down
4 changes: 2 additions & 2 deletions Library/PAX_MAHOROBA/MapViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace paxs {
class MapViewerSiv3D {
public:


std::unique_ptr<TextureLocation> texture_location; // 地図上に描画する画像の一覧
#ifdef PAXS_USING_SIV3D
s3d::Array<s3d::Vec2> route1, route2; // 線の情報を格納
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace paxs {
const paxs::KoyomiSiv3D& koyomi_siv,
paxs::StringViewerSiv3D& string_siv,
#ifdef PAXS_USING_SIMULATOR
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator,
std::unique_ptr<paxs::SettlementSimulator>& simulator,
std::size_t& pop_num, // 人口数
std::size_t& sat_num, // 集落数
#endif
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_MAHOROBA/PersonLocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace paxs {
class PersonNameLocation {
public:
#ifdef PAXS_USING_SIMULATOR
void update(const std::vector<paxs::Agent<int>>& agents, const paxs::Vector2<int>& start_position) {
void update(const std::vector<paxs::Agent>& agents, const paxs::Vector2<paxs::GridType>& start_position) {
// エージェントの設定を更新
location_point_list_list.resize(0);
std::vector<PersonLocationPoint> person_location_list{}; // 地物の一覧
Expand Down
6 changes: 3 additions & 3 deletions Library/PAX_MAHOROBA/StringViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace paxs {
private:
#ifdef PAXS_USING_SIMULATOR
void simulation(
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator, // コンパイル時の分岐により使わない場合あり
std::unique_ptr<paxs::SettlementSimulator>& simulator, // コンパイル時の分岐により使わない場合あり
paxs::TouchManager& tm_,
paxs::KoyomiSiv3D& koyomi_siv,
int debug_start_y
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace paxs {
#endif

std::random_device seed_gen;
simulator = std::make_unique<paxs::SettlementSimulator<int>>(
simulator = std::make_unique<paxs::SettlementSimulator>(
map_list_path, japan_provinces_path,
seed_gen());
simulator->init();
Expand Down Expand Up @@ -327,7 +327,7 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
const SelectLanguage& select_language,
const paxs::Language& language_text,
#ifdef PAXS_USING_SIMULATOR
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator, // コンパイル時の分岐により使わない場合あり
std::unique_ptr<paxs::SettlementSimulator>& simulator, // コンパイル時の分岐により使わない場合あり
std::size_t& pop_num, // 人口数
std::size_t& sat_num, // 集落数
#endif
Expand Down
1 change: 0 additions & 1 deletion Library/PAX_SAPIENTICA/MapUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace paxs {
* @brief メルカトル座標に変換
* @return Mercator Coordinate
*/
template <typename GridType>
static paxs::Vector2<double> convertToMercatorCoordinate(const paxs::Vector2<GridType>& start_position, const paxs::Vector2<GridType>& position, const int z) noexcept {
const double n = std::pow(2, z);
const double pixel_sum = pixel_size * n;
Expand Down
14 changes: 6 additions & 8 deletions Library/PAX_SAPIENTICA/Simulation/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ namespace paxs {

/// @brief A class that represents an agent.
/// @brief エージェントを表すクラス
template <typename GridType>
class Agent : public Object<GridType> {
class Agent : public Object {
public:
using Vector2 = paxs::Vector2<GridType>;
using Environment = paxs::Environment<GridType>;

constexpr explicit Agent(const std::uint_least32_t id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen,
explicit Agent(const std::uint_least32_t id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen,
const std::uint_least32_t age, const std::uint_least32_t life_span, const std::shared_ptr<Environment> env) noexcept
: Object<GridType>(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {}
: Object(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {}

/// @brief Move the agent.
/// @brief エージェントを移動させる
Expand Down Expand Up @@ -118,7 +116,7 @@ namespace paxs {

/// @brief Get the agent's age.
/// @brief エージェントの年齢を取得する
constexpr float getAge() const noexcept { return age / static_cast<float>(SimulationConstants::getInstance()->steps_per_year); }
float getAge() const noexcept { return age / static_cast<float>(SimulationConstants::getInstance()->steps_per_year); }

/// @brief Increment the agent's age.
/// @brief エージェントの年齢をインクリメントする
Expand All @@ -136,8 +134,8 @@ namespace paxs {
/// @brief エージェントの性別を取得する
constexpr std::uint_least8_t getGender() const noexcept { return gender; }

constexpr bool operator==(const Agent& a) const noexcept {
return Object<GridType>::operator==(a) &&
bool operator==(const Agent& a) const noexcept {
return Object::operator==(a) &&
gender == a.gender &&
age == a.age &&
life_span == a.life_span &&
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_SAPIENTICA/Simulation/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace paxs {

/// @brief A class that holds data required for simulation.
/// @brief シミュレーションに必要なデータを保持するクラス
template <typename DataType, typename GridType>
template <typename DataType>
class Data {
public:
using Vector2 = paxs::Vector2<GridType>;
Expand Down
19 changes: 9 additions & 10 deletions Library/PAX_SAPIENTICA/Simulation/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ namespace paxs {

/// @brief A class that manages data required for simulation.
/// @brief シミュレーションに必要なデータを管理するクラス
template <typename GridType>
class Environment {
public:
using Vector2 = paxs::Vector2<GridType>;

using DataVariant = std::variant<Data<std::uint_least8_t, GridType>, Data<std::uint_least32_t, GridType>, Data<float, GridType>, Data<std::int_least16_t, GridType>>;
using DataVariant = std::variant<Data<std::uint_least8_t>, Data<std::uint_least32_t>, Data<float>, Data<std::int_least16_t>>;

/// @brief Start position of the simulation.
/// @brief シミュレーションデータのマップ
std::unordered_map<std::uint_least32_t, std::unique_ptr<DataVariant>> data_map;

constexpr explicit Environment() noexcept = default;
explicit Environment() noexcept = default;
explicit Environment(const std::string& setting_file_path) noexcept {
std::vector<std::vector<std::string>> settings;

Expand Down Expand Up @@ -89,16 +88,16 @@ namespace paxs {
const std::uint_least32_t key = MurMur3::calcHash(settings[i][key_column].size(), settings[i][key_column].c_str());
const std::string& key_str = settings[i][key_column];
if (data_type == MurMur3::calcHash("u8")) {
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::uint_least8_t, GridType>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::uint_least8_t>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
}
else if (data_type == MurMur3::calcHash("u32")) {
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::uint_least32_t, GridType>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::uint_least32_t>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
}
else if (data_type == MurMur3::calcHash("f32")) {
data_map.emplace(key, std::make_unique<DataVariant>(Data<float, GridType>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
data_map.emplace(key, std::make_unique<DataVariant>(Data<float>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
}
else if (data_type == MurMur3::calcHash("s16")) {
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::int_least16_t, GridType>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
data_map.emplace(key, std::make_unique<DataVariant>(Data<std::int_least16_t>(settings[i][file_path_column], key_str, std::stoi(settings[i][z_column]))));
}
else {
PAXS_WARNING("data_type is not found in " + setting_file_path);
Expand All @@ -117,13 +116,13 @@ namespace paxs {
PAXS_ERROR(message);
throw std::runtime_error(message);
}
return std::get<Data<U, GridType>>(*data_map.at(key)).getValue(position);
return std::get<Data<U>>(*data_map.at(key)).getValue(position);
}

/// @brief Get the land position list.
/// @brief 陸の位置リストの取得
constexpr void getLandPositions(std::vector<std::uint64_t>& keys) const {
std::get<Data<std::uint_least8_t, GridType>>(*data_map.at(MurMur3::calcHash("gbank"))).getKeys(keys);
void getLandPositions(std::vector<std::uint64_t>& keys) const {
std::get<Data<std::uint_least8_t>>(*data_map.at(MurMur3::calcHash("gbank"))).getKeys(keys);
}

/// @brief Is it possible to live?
Expand Down
7 changes: 3 additions & 4 deletions Library/PAX_SAPIENTICA/Simulation/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ namespace paxs {

/// @brief Class that represents an object.
/// @brief オブジェクトを表すクラス
template <typename GridType>
class Object {
public:
using Vector2 = paxs::Vector2<GridType>;

constexpr explicit Object(const std::uint_least32_t id, const std::string& name, const Vector2& position) noexcept
explicit Object(const std::uint_least32_t id, const std::string& name, const Vector2& position) noexcept
: id(id), name(name), position(position) {}

/// @brief Get the object's id. オブジェクトのIDを取得
Expand All @@ -54,11 +53,11 @@ namespace paxs {

/// @brief Get the mercator coordinate from the XYZTile coordinate.
/// @brief 座標をメルカトル座標で取得
constexpr paxs::Vector2<double> getLocation(const paxs::Vector2<int>& start_position, const int z) const noexcept {
paxs::Vector2<double> getLocation(const paxs::Vector2<int>& start_position, const int z) const noexcept {
return MapUtility::convertToMercatorCoordinate(start_position, position, z);
}

constexpr bool operator==(const paxs::Object<GridType>& a) const noexcept {
bool operator==(const paxs::Object& a) const noexcept {
return a.position == position && a.id == id && a.name == name;
}

Expand Down
11 changes: 4 additions & 7 deletions Library/PAX_SAPIENTICA/Simulation/Settlement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ namespace paxs {
constexpr float sigma_x_sqrt_2_x_pi = sigma * sqrt_2_x_pi;
}

template <typename GridType>
class Settlement {
public:
using Environment = paxs::Environment<GridType>;
using Vector2 = paxs::Vector2<GridType>;
using Object = paxs::Object<GridType>;
using Agent = paxs::SettlementAgent<GridType>;
using Agent = paxs::SettlementAgent;

constexpr explicit Settlement(const std::uint_least32_t id, std::mt19937& gen_, const std::shared_ptr<Environment> env) noexcept : id(id), gen(&gen_), environment(env) {}
explicit Settlement(const std::uint_least32_t id, std::mt19937& gen_, const std::shared_ptr<Environment> env) noexcept : id(id), gen(&gen_), environment(env) {}

/// @brief Get the uuid.
/// @brief idを取得
Expand Down Expand Up @@ -156,11 +153,11 @@ namespace paxs {

/// @brief Get the agents.
/// @brief エージェントを取得
std::vector<Agent>& getAgents() const noexcept { return agents; }
std::vector<Agent>& getAgents() noexcept { return agents; }

/// @brief Get the agents.
/// @brief エージェントを取得
constexpr const std::vector<Agent> cgetAgents() const noexcept { return agents; }
const std::vector<Agent> cgetAgents() const noexcept { return agents; }

/// @brief Marriage.
/// @brief 婚姻
Expand Down
5 changes: 2 additions & 3 deletions Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ namespace paxs {

/// @brief A class that represents an agent.
/// @brief エージェントを表すクラス
template <typename GridType>
class SettlementAgent {
public:

SettlementAgent() = default;

constexpr explicit SettlementAgent(const std::uint_least64_t id, const std::uint_least32_t& name_id, const std::uint_least8_t gen,
explicit SettlementAgent(const std::uint_least64_t id, const std::uint_least32_t& name_id, const std::uint_least8_t gen,
const std::uint_least32_t age, const std::uint_least32_t life_span) noexcept
: id(id), name_id(name_id), gender(gen), age(age), life_span(life_span) {}

Expand All @@ -51,7 +50,7 @@ namespace paxs {

/// @brief Get the agent's age.
/// @brief エージェントの年齢を取得する
constexpr float getAge() const noexcept { return age / static_cast<float>(SimulationConstants::getInstance()->steps_per_year); }
float getAge() const noexcept { return age / static_cast<float>(SimulationConstants::getInstance()->steps_per_year); }

constexpr std::uint_least32_t getAgeInt() const noexcept { return age; }

Expand Down
3 changes: 0 additions & 3 deletions Library/PAX_SAPIENTICA/Simulation/SettlementGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
namespace paxs {

/// @brief 特定のグリッドに属する集落を管理するクラス
template <typename GridType>
class SettlementGrid {
public:
using Environment = paxs::Environment<GridType>;
using Vector2 = paxs::Vector2<GridType>;
using Settlement = paxs::Settlement<GridType>;

SettlementGrid() = default;

Expand Down
10 changes: 3 additions & 7 deletions Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@

namespace paxs {

template <typename GridType>
class SettlementSimulator {
public:
using Agent = paxs::SettlementAgent<GridType>;
using Environment = paxs::Environment<GridType>;
using Settlement = paxs::Settlement<GridType>;
using SettlementGrid = paxs::SettlementGrid<GridType>;
using Agent = paxs::SettlementAgent;
using Vector2 = paxs::Vector2<GridType>;

constexpr explicit SettlementSimulator() = default;
explicit SettlementSimulator() = default;

explicit SettlementSimulator(const std::string& map_list_path, const std::string& japan_provinces_path, const unsigned seed = 0) noexcept :
environment(std::make_unique<Environment>(map_list_path)), gen(seed) {
Expand All @@ -57,7 +53,7 @@ namespace paxs {
/// @brief 環境を設定
void setEnvironment(const std::string& map_list_path, const std::string& japan_provinces_path, const int z, const unsigned seed = 0) noexcept {
environment.reset();
environment = std::make_unique<Environment>(map_list_path, z);
environment = std::make_unique<Environment>(map_list_path);

gen = std::mt19937(seed);

Expand Down
Loading

0 comments on commit 3327e60

Please sign in to comment.