Skip to content

Commit

Permalink
upd: sim
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Dec 30, 2023
1 parent ec9656b commit 1bcf7f8
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 55 deletions.
6 changes: 3 additions & 3 deletions Library/PAX_GRAPHICA/Circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ namespace paxg {
}
#elif defined(PAXS_USING_DXLIB)
void draw(const paxg::Color& c_) const {
//DxLib::DrawBox(
// static_cast<int>(x0), static_cast<int>(y0), static_cast<int>(x0 + w0), static_cast<int>(y0 + h0),
// DxLib::GetColor(c_.r, c_.g, c_.b), TRUE);
DxLib::DrawCircle(
static_cast<int>(x), static_cast<int>(y), static_cast<int>(r),
DxLib::GetColor(c_.r, c_.g, c_.b), TRUE);
}
#elif defined(PAXS_USING_SFML)
void draw(const paxg::Color&) const {
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_GRAPHICA/Key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace paxs {
private:
// 中央の座標を指定
Coordinate center = Coordinate(
paxs::EquirectangularDeg(paxs::Vector2<double>(/*135.0, 35.0*/128, 37)),
paxs::EquirectangularDeg(paxs::Vector2<double>(135, 35)), // 韓国 128, 37
//paxs::Vector2(135.0, getLatitudeToMercatorY(35.0)),
200.0); // マップ座標の中央
double width = 12.0; // マップの幅
Expand Down
8 changes: 4 additions & 4 deletions Library/PAX_GRAPHICA/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace paxg {
// Linux 専用処理
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
DxLib::GetDrawScreenSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return Vec2i{ static_cast<int>(width / 2) ,static_cast<int>(height / 2) };
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace paxg {
// Linux 専用処理
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
DxLib::GetDrawScreenSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return static_cast<int>(width);
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace paxg {
// Linux 専用処理
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
DxLib::GetDrawScreenSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return static_cast<int>(height);
Expand Down Expand Up @@ -226,7 +226,7 @@ namespace paxg {
// Linux 専用処理
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
DxLib::GetDrawScreenSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return Vec2i{ static_cast<int>(width) ,static_cast<int>(height) };
Expand Down
11 changes: 5 additions & 6 deletions Library/PAX_MAHOROBA/Calendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace paxs {

bool move_forward_in_time = true; // デバッグ false; // 時間を進めるか
bool go_back_in_time = false; // 時間を戻すか
bool is_agent_update = true; // エージェントの更新をするか
bool is_agent_update = false; // エージェントの更新をするか

public:
/*##########################################################################################
Expand Down Expand Up @@ -184,23 +184,22 @@ namespace paxs {
// 時間を進めている場合(逆行していない場合)
if (move_forward_in_time) {
if (jdn.cgetDay() != (std::numeric_limits<int>::max)()) {
jdn += 365.2425;//(0.8 / 30.0); //(365.2425 / 12.0);//1.0;// ユリウス日を繰り上げ(次の日にする)
jdn += (365.2425 / 12.0);//365.2425;//(0.8 / 30.0); //1.0;// ユリウス日を繰り上げ(次の日にする)
calcDate(); // 日付計算
}
//jdn += 365; // ユリウス日を繰り上げ(次の日にする)
#ifdef PAXS_USING_SIMULATOR
// エージェント機能テスト
//
// エージェント機能
if (is_agent_update && simulator.get() != nullptr) {
simulator->step(); // シミュレーションを 1 ステップ実行する
steps.getDay()++; // ステップ数を増やす
return_bool = true;
}
#endif
}
// 時間を逆行している場合
else if (go_back_in_time) {
if (jdn.cgetDay() != (std::numeric_limits<int>::max)()) {
jdn -= 365.24252;//(0.8 / 30.0); //(365.2425 / 12.0);//1.0;// ユリウス日を繰り上げ(次の日にする)
jdn -= (365.2425 / 12.0);//365.24252;//(0.8 / 30.0); //1.0;// ユリウス日を繰り上げ(次の日にする)
calcDate(); // 日付計算
}
}
Expand Down
9 changes: 2 additions & 7 deletions Library/PAX_MAHOROBA/MapViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ namespace paxs {
const SelectLanguage& select_language,
const paxs::KoyomiSiv3D& koyomi_siv,
paxs::StringViewerSiv3D& string_siv,
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator, // コンパイル時の分岐により使わない場合あり
#ifndef PAXS_USING_SIMULATOR
[[maybe_unused]]
#endif
const paxs::Vector2<int>& start_position, // コンパイル時の分岐により使わない場合あり
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator,
const paxs::Vector2<int>& start_position,
paxs::GraphicVisualizationList& visible,
std::size_t& pop_num, // 人口数
std::size_t& sat_num // 集落数
Expand All @@ -110,14 +107,12 @@ namespace paxs {

// 地図上に画像を描画する
texture_location->update(map_view->getCenterX(), map_view->getCenterY(), map_view->getWidth(), map_view->getHeight());
#ifdef PAXS_USING_SIMULATOR
if (agent_location.get() != nullptr && simulator.get() != nullptr) {
agent_location->draw(koyomi_siv.jdn.cgetDay(), simulator->getSettlementGrids(), start_position, map_view->getWidth(), map_view->getHeight(), map_view->getCenterX(), map_view->getCenterY(),
pop_num,
sat_num
);
}
#endif

#ifdef PAXS_USING_SIV3D
//// 線の描画
Expand Down
69 changes: 40 additions & 29 deletions Library/PAX_MAHOROBA/StringViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
texture_dictionary.emplace(MurMur3::calcHash("texture_stop"), paxg::Texture{ path + "Data/MenuIcon/stop.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_playback"), paxg::Texture{ path + "Data/MenuIcon/playback.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_reverse_playback"), paxg::Texture{ path + "Data/MenuIcon/reverse-playback.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_1step"), paxg::Texture{ path + "Data/MenuIcon/1Step.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_delete_agent_data"), paxg::Texture{ path + "Data/MenuIcon/DeleteAgentData.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_delete_geographic_data"), paxg::Texture{ path + "Data/MenuIcon/DeleteGeographicData.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_load_agent_data"), paxg::Texture{ path + "Data/MenuIcon/LoadAgentData.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_load_agent_data2"), paxg::Texture{ path + "Data/MenuIcon/LoadAgentData2.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_load_geographic_data"), paxg::Texture{ path + "Data/MenuIcon/LoadGeographicData.svg" });
texture_dictionary.emplace(MurMur3::calcHash("texture_load_geographic_data2"), paxg::Texture{ path + "Data/MenuIcon/LoadGeographicData2.svg" });
}

//koyomi_font = setFont(koyomi_font_size, path8, 2);
Expand Down Expand Up @@ -223,18 +230,9 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
const paxs::Language& language_text,
std::unique_ptr<paxs::SettlementSimulator<int>>& simulator, // コンパイル時の分岐により使わない場合あり
std::unique_ptr<paxs::SettlementSimulator<int>>& old_simulator, // コンパイル時の分岐により使わない場合あり
#ifndef PAXS_USING_SIMULATOR
[[maybe_unused]]
#endif
const paxs::Vector2<int>& start_position, // コンパイル時の分岐により使わない場合あり
#ifndef PAXS_USING_SIMULATOR
[[maybe_unused]]
#endif
const paxs::Vector2<int>& end_position, // コンパイル時の分岐により使わない場合あり
#ifndef PAXS_USING_SIMULATOR
[[maybe_unused]]
#endif
const std::string& path8, // コンパイル時の分岐により使わない場合あり
const paxs::Vector2<int>& start_position,
const paxs::Vector2<int>& end_position,
const std::string& path8,
paxs::TouchManager& tm_,
paxs::KoyomiSiv3D& koyomi_siv,
paxs::GraphicVisualizationList& visible,
Expand Down Expand Up @@ -264,17 +262,7 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
const int arrow_time_icon_size = 24; // 時間操作アイコンの大きさ
const int time_icon_size = 40; // 時間操作アイコンの大きさ
int icon_const_start_x = 360;
#ifdef PAXS_USING_DXLIB
#ifndef __ANDROID__
const int dx_move_x = 400; // 描画ライブラリごとに位置の調整
#else
const int dx_move_x = 0; // 描画ライブラリごとに位置の調整
#endif
koyomi_font_x -= dx_move_x;
koyomi_font_en_x -= dx_move_x;
rect_start_x -= dx_move_x;
icon_const_start_x += dx_move_x;
#endif // PAXS_USING_DXLIB

int icon_start_x = icon_const_start_x;

int sum_icon_height = arrow_time_icon_size + time_icon_size * 2;
Expand Down Expand Up @@ -723,8 +711,10 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
// simulator = old_simulator;
//}

if (s3d::SimpleGUI::Button(U"Init", s3d::Vec2{ 10, 60 })) {

texture_dictionary.at(MurMur3::calcHash("texture_load_geographic_data2")).resizedDraw(
time_icon_size, paxg::Vec2i(paxg::Window::width() - 360, 400));
if (tm_.get(paxg::Rect{ paxg::Vec2i(paxg::Window::width() - 360, 400), paxg::Vec2i(time_icon_size, time_icon_size) }.leftClicked())) {
// if (s3d::SimpleGUI::Button(U"Sim Init (CUI)", s3d::Vec2{ 10, 60 })) {
const std::string map_list_path = path8 + "Data/Simulation/MapList.tsv";
const std::string japan_provinces_path = path8 + "Data/Simulation/Japan200-725";
paxs::Vector2<int> init_start_position(861, 381);
Expand All @@ -743,12 +733,33 @@ MurMur3::calcHash("en-US"), MurMur3::calcHash("ja-JP"), MurMur3::calcHash("zh-TW
//simulator_.init();
koyomi_siv.steps.setDay(0); // ステップ数を 0 にする
koyomi_siv.is_agent_update = false;

koyomi_siv.move_forward_in_time = false; // 一時停止
koyomi_siv.go_back_in_time = false;
}
if (s3d::SimpleGUI::Button(U"Start", s3d::Vec2{ 110, 60 })) {
koyomi_siv.is_agent_update = true;
if (!koyomi_siv.is_agent_update) {
// シミュレーションを再生
texture_dictionary.at(MurMur3::calcHash("texture_playback")).resizedDraw(
time_icon_size, paxg::Vec2i(paxg::Window::width() - 300, 400));
if (tm_.get(paxg::Rect{ paxg::Vec2i(paxg::Window::width() - 300, 400), paxg::Vec2i(time_icon_size, time_icon_size) }.leftClicked())) {
// if (s3d::SimpleGUI::Button(U"Sim Start", s3d::Vec2{ 190, 60 })) {
koyomi_siv.is_agent_update = true;

koyomi_siv.move_forward_in_time = true; // 再生
koyomi_siv.go_back_in_time = false;
}
}
if (s3d::SimpleGUI::Button(U"Stop", s3d::Vec2{ 210, 60 })) {
koyomi_siv.is_agent_update = false;
else {
// シミュレーションを停止
texture_dictionary.at(MurMur3::calcHash("texture_stop")).resizedDraw(
time_icon_size, paxg::Vec2i(paxg::Window::width() - 300, 400));
if (tm_.get(paxg::Rect{ paxg::Vec2i(paxg::Window::width() - 300, 400), paxg::Vec2i(time_icon_size, time_icon_size) }.leftClicked())) {
// if (s3d::SimpleGUI::Button(U"Sim Stop", s3d::Vec2{ 330, 60 })) {
koyomi_siv.is_agent_update = false;

koyomi_siv.move_forward_in_time = false; // 一時停止
koyomi_siv.go_back_in_time = false;
}
}
//if (koyomi_siv.is_agent_update && simulator.get() != nullptr) {
// simulator->run(1);
Expand Down
4 changes: 2 additions & 2 deletions Library/PAX_SAPIENTICA/RandomSelector.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*##########################################################################################
/*##########################################################################################
PAX SAPIENTICA Library 💀🌿🌏
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace paxs {
/// @param num_elements_2 The number of elements to select from the second vector.
/// @return A vector of selected elements.
std::vector<std::pair<std::size_t, std::size_t>> select(const std::size_t num_elements_1, const std::size_t num_elements_2) {
const std::size_t num_elements = std::min(num_elements_1, num_elements_2);
const std::size_t num_elements = (std::min)(num_elements_1, num_elements_2);

std::vector<std::pair<std::size_t, std::size_t>> result;
std::unordered_set<std::size_t> used_indices_1;
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_SAPIENTICA/Simulation/Settlement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace paxs {
const std::uint_least32_t set_lifespan = kanakuma_life_span.setAdultLifeSpan(set_gender, *gen);

std::uniform_int_distribution<> lifespan_dist{
std::min(18 * steps_per_year + 1, static_cast<int>(set_lifespan - 1)),
(std::min)(18 * steps_per_year + 1, static_cast<int>(set_lifespan - 1)),
static_cast<int>(set_lifespan - 1) }; // 性別の乱数分布

agents.emplace_back(Agent(
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ namespace paxs {
// 配置する集落の人口を決定
paxs::Ryoseikoku ryoseikoku = japan_provinces->cgetRyoseikoku(ryoseikoku_id);
int settlement_population = std::uniform_int_distribution<>(ryoseikoku.settlement_population_min_ad200, ryoseikoku.settlement_population_max_ad200)(gen);
settlement_population = std::min(settlement_population, static_cast<int>(ryoseikoku_population_it->second));
settlement_population = (std::min)(settlement_population, static_cast<int>(ryoseikoku_population_it->second));

// 集落をグリッドに配置
Vector2 grid_position = live_position / grid_length;
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_SAPIENTICA/UniqueIdentification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace paxs {
/// @brief Generate a unique id.
/// @brief ユニークなIDを生成する。
static IdType generate() {
if (counter == std::numeric_limits<IdType>::max()) {
if (counter == (std::numeric_limits<IdType>::max)()) {
PAXS_WARNING("The counter has reached the maximum value. Resetting the counter.");
reset();
}
Expand Down

0 comments on commit 1bcf7f8

Please sign in to comment.