Skip to content

Commit

Permalink
Merge pull request #56 from AsPJT/feature-input-file-class
Browse files Browse the repository at this point in the history
入力ファイルを読み込むクラスを作成
  • Loading branch information
AsPJT authored Oct 2, 2023
2 parents 54264f5 + 6d1ac31 commit e8224b7
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 124 deletions.
95 changes: 95 additions & 0 deletions Library/PAX_GRAPHICA/InputFile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*##########################################################################################
PAX SAPIENTICA Library 💀🌿🌏
[Planning] 2023 As Project
[Production] 2023 As Project
[Contact Us] [email protected] https://github.com/AsPJT/PAX_SAPIENTICA
[License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/
##########################################################################################*/

#ifndef PAX_GRAPHICA_INPUT_FILE_HPP
#define PAX_GRAPHICA_INPUT_FILE_HPP

/*##########################################################################################
##########################################################################################*/

#include <fstream>
#include <string>
#include <vector>

#include <PAX_SAPIENTICA/StringExtensions.hpp>

namespace paxg {

enum class InputFileType : unsigned char {
internal_file, // 内部
external_file // 外部
};

struct InputFile {

#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
int file_handle{ 0 };
std::string pline{};
std::string pline_tmp{};
#else
std::ifstream pifs{};
std::string pline{};
#endif // PAXS_USING_DXLIB

// ファイルが読み込まれたか確認する(読み込まれていない時は true )
bool fail() const {
#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
return (file_handle == 0);
#else
return pifs.fail();
#endif // PAXS_USING_DXLIB
}

// str_ ファイルのパスの文字列
// default_path_ 基準となる根幹のパス
// type_ どこにファイルを保存するか
InputFile(const std::string& str_, const std::string& default_path_ = "", const InputFileType type_ = InputFileType::internal_file) {
#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
#ifdef __ANDROID__
file_handle = DxLib::FileRead_open(str_.c_str());
#else
file_handle = DxLib::FileRead_open(std::string(default_path_ + str_).c_str());
#endif // __ANDROID__
DxLib::FileRead_set_format(file_handle, DX_CHARCODEFORMAT_UTF8); // UTF-8 を読み込む
if (file_handle != 0) {
pline.resize(4096);
pline_tmp.resize(4096);
}
#else
pifs = std::ifstream((default_path_.size() == 0) ? str_ : default_path_ + str_); // ファイルを読み込む
#endif
}
// 1 行読み込む
bool getLine() {
#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
const int dline = DxLib::FileRead_gets(&(pline[0]), 4096, file_handle);
if (dline == -1) return false;
if (dline == 0) return false;
return true;
#else
return static_cast<bool>(std::getline(pifs, pline));
#endif // PAXS_USING_DXLIB
}
// 区切り文字で分割する
std::vector<std::string> split(const char delimiter) const {
return paxs::StringExtensions::split(pline, delimiter);
}

std::string& lineString() {
return pline;
}

};

}

#endif // !PAX_GRAPHICA_INPUT_FILE_HPP
4 changes: 2 additions & 2 deletions Library/PAX_GRAPHICA/Key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ namespace paxs {
private:
// 中央の座標を指定
Coordinate center = Coordinate(
paxs::EquirectangularDeg(paxs::Vector2<double>(135.0, 35.0)),
paxs::EquirectangularDeg(paxs::Vector2<double>(/*135.0, 35.0*/128,37)),
//paxs::Vector2(135.0, getLatitudeToMercatorY(35.0)),
200.0); // マップ座標の中央
double width = 180.0; // マップの幅
double width = 12.0; // マップの幅

// 平城京
//Coordinate center = Coordinate(135.807, 37.009/*getLatitudeToMercatorY(35)*/, 200.0); // マップ座標の中央
Expand Down
4 changes: 4 additions & 0 deletions Library/PAX_GRAPHICA/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace paxg {
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return Vec2i{ static_cast<int>(width / 2) ,static_cast<int>(height / 2) };

Expand Down Expand Up @@ -160,6 +161,7 @@ namespace paxg {
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return static_cast<int>(width);

Expand Down Expand Up @@ -188,6 +190,7 @@ namespace paxg {
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return static_cast<int>(height);

Expand Down Expand Up @@ -216,6 +219,7 @@ namespace paxg {
#else
// その他の処理 (Windows)
DxLib::GetWindowSize(&width, &height);
// DxLib::GetWindowSize(&width, &height);
#endif
return Vec2i{ static_cast<int>(width) ,static_cast<int>(height) };

Expand Down
50 changes: 8 additions & 42 deletions Library/PAX_MAHOROBA/LocationPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <PAX_SAPIENTICA/StringExtensions.hpp>
#include <PAX_SAPIENTICA/MapProjection.hpp> // 地図投影法

#include <PAX_GRAPHICA/InputFile.hpp>
#include <PAX_GRAPHICA/String.hpp>
#include <PAX_GRAPHICA/Texture.hpp>
#include <PAX_GRAPHICA/Rect.hpp>
Expand Down Expand Up @@ -114,6 +115,8 @@ namespace paxs {
inputPlace(std::string("Data/PlaceName/TohokuAynu.tsv"));
// 渤海
inputPlace(std::string("Data/PlaceName/Balhae.tsv"));
// 統一新羅
inputPlace(std::string("Data/PlaceName/UnifiedSilla.tsv"));
// 倭名類聚抄の地名
inputPlace(std::string("Data/PlaceName/WamyoRuijushoPlaceName.tsv"));
// 倭名類聚抄の地名
Expand Down Expand Up @@ -347,50 +350,13 @@ namespace paxs {
// 地名を読み込み
void inputPlace(const std::string& str_, const LocationPointEnum lpe_ = LocationPointEnum::location_point_place_name) {

#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
#ifdef __ANDROID__
const int file_handle = DxLib::FileRead_open(str_.c_str());
#else
const int file_handle = DxLib::FileRead_open(std::string(PAXS_PATH + str_).c_str());
#endif // __ANDROID__
DxLib::FileRead_set_format(file_handle, DX_CHARCODEFORMAT_UTF8);
if (file_handle == 0) return;
std::string pline{};
pline.resize(4096);
std::string pline_tmp{};
pline_tmp.resize(4096);
#else
std::ifstream pifs(PAXS_PATH + str_); // 地名を読み込む
paxg::InputFile pifs(str_, PAXS_PATH);
if (pifs.fail()) return;
std::string pline;
#endif
#ifdef PAXS_USING_DXLIB // PAXS_USING_DXLIB
while (true) {
const int dline = DxLib::FileRead_gets(&(pline[0]), 4096, file_handle);

if (dline == -1) break;
if (dline == 0) break;

// const std::string pline = std::string(pline0.c_str());
std::vector<std::string> strvec{};

std::string str_p{};
for (int i = 0, pi = 0; i <= dline; ++i) {
if (pline[i] == '\0') continue;
if (pline[i] == '\t' || i == dline) {
strvec.emplace_back(str_p);
str_p.clear();
}
else {
str_p.push_back(pline[i]);
}
}
strvec.emplace_back(str_p);
#else

// 1 行ずつ読み込み(区切りはタブ)
while (std::getline(pifs, pline)) {
std::vector<std::string> strvec = paxs::StringExtensions::split(pline, '\t');
#endif
while (pifs.getLine()) {
std::vector<std::string> strvec = pifs.split('\t');

// 格納
location_point_list.emplace_back(
strvec[0], // 漢字
Expand Down
7 changes: 7 additions & 0 deletions Library/PAX_MAHOROBA/LocationRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ namespace paxs {
TextureLocation() {
// ここに実験用のテクスチャを定義する

//// 統一新羅 朝鮮半島
//location_range_list.emplace_back("./../../../../../Data/Map/TestMap/a.png",
// 124.6,
// MapProjectionF64::equirectangularDegYToMercatorDegY(34.25),
// 129.65,
// MapProjectionF64::equirectangularDegYToMercatorDegY(39.4));

//location_range_list.emplace_back("./../../../../../Data/Map/TestMap/nara.png",
// 135.7104,
// MapProjectionF64::equirectangularDegYToMercatorDegY(34.59451),
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_MAHOROBA/MapViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace paxs {
paxs::GraphicVisualizationList& visible
) {
map_view->update(); // キーボード入力を更新
mapMapUpdate(xyz_tile_list, string_siv.menu_bar, map_view.get()); // 地図の辞書を更新
mapMapUpdate(xyz_tile_list, string_siv.menu_bar, map_view.get(), koyomi_siv.jdn.cgetDay()); // 地図の辞書を更新

if (visible["Map"]) {
// 地図上に画像を描画する
Expand Down
8 changes: 5 additions & 3 deletions Library/PAX_MAHOROBA/StringViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ namespace paxs {

if (visible["Calendar"]) {
#ifdef PAXS_USING_DXLIB
paxg::Rect{ paxg::Vec2i(rect_start_x, koyomi_font_y - 5), paxg::Vec2i(360, next_rect_start_y) }.draw();
DxLib::DrawRoundRect(rect_start_x, koyomi_font_y - 5,
rect_start_x + 360, koyomi_font_y - 5 + next_rect_start_y,
10, 10, DxLib::GetColor(255, 255, 255), TRUE);

// paxg::Rect{ paxg::Vec2i(rect_start_x, koyomi_font_y - 5), paxg::Vec2i(360, next_rect_start_y) }.draw();
// paxg::Rect{ paxg::Vec2i(rect_start_x, koyomi_font_y + next_rect_start_y + 5), paxg::Vec2i(360, next_rect_end_y) }.draw();
#endif // PAXS_USING_DXLIB

Expand Down Expand Up @@ -257,11 +261,9 @@ namespace paxs {
case paxs::cal::DateOutputType::name_and_ymd:
koyomi_font[select_language.cget()].drawTopRight(std::string(koyomi_siv.date_list[i].calendar_name[select_language.cget() + 1 /* 言語位置調整 */]),
paxg::Vec2i(static_cast<int>(koyomi_font_x), static_cast<int>(koyomi_font_y + i * (koyomi_font_size * 4 / 3))), paxg::Color(0, 0, 0));
#ifndef PAXS_USING_DXLIBa
koyomi_font[select_language.cget()].drawTopRight(reinterpret_cast<const char*>(u8""), paxg::Vec2i(static_cast<int>(int(120 * koyomi_font_size / 30.0) + koyomi_font_x), static_cast<int>(koyomi_font_y + i * (koyomi_font_size * 4 / 3))), paxg::Color(0, 0, 0));
koyomi_font[select_language.cget()].drawTopRight(reinterpret_cast<const char*>(u8""), paxg::Vec2i(static_cast<int>(int(220 * koyomi_font_size / 30.0) + koyomi_font_x), static_cast<int>(koyomi_font_y + i * (koyomi_font_size * 4 / 3))), paxg::Color(0, 0, 0));
koyomi_font[select_language.cget()].drawTopRight(reinterpret_cast<const char*>(u8""), paxg::Vec2i(static_cast<int>(int(300 * koyomi_font_size / 30.0) + koyomi_font_x), static_cast<int>(koyomi_font_y + i * (koyomi_font_size * 4 / 3))), paxg::Color(0, 0, 0));
#endif
std::visit([&](const auto& x) {
date_year = int(x.cgetYear());
date_month = int(x.cgetMonth());
Expand Down
38 changes: 30 additions & 8 deletions Library/PAX_MAHOROBA/XYZTiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <PAX_GRAPHICA/Vec2.hpp>
#include <PAX_GRAPHICA/Window.hpp>

#include <PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp>
#include <PAX_SAPIENTICA/StringExtensions.hpp>

namespace paxs {

class XYZTile {
Expand Down Expand Up @@ -60,7 +63,7 @@ namespace paxs {
std::unordered_map<std::uint_least64_t, paxg::Texture> texture{};

std::uint_least64_t textureIndex(const MapVec4D& m_) const {
return (m_.y) + (m_.x << 24) + (m_.z << 48);// +(m_.layer << 53);
return (m_.y) + (m_.x << 24) + (m_.z << 48); // +(m_.layer << 53);
}

XYZTile()
Expand Down Expand Up @@ -152,6 +155,7 @@ namespace paxs {
+ std::string(".png"));
break;
case XYZTileFileName::Z_Original:
new_saveFilePath = map_file_path_name;
new_saveFilePath = (map_file_path_name
+ std::to_string(z) + std::string("/") + map_name
+ std::string("_") + std::to_string(z)
Expand Down Expand Up @@ -186,12 +190,17 @@ namespace paxs {
#if defined(PAXS_USING_SIV3D)
// URL の記載がある場合
if (map_url_name.size() != 0) {
const s3d::URL new_url =
s3d::String(s3d::Unicode::FromUTF8(map_url_name))
+ s3d::String(U"/") + s3d::ToString(z)
+ s3d::String(U"/") + s3d::ToString((j + z_num) % z_num)
+ s3d::String(U"/") + s3d::ToString((i + z_num) % z_num)
+ s3d::String(U".png");
std::string new_path = map_url_name;
paxs::StringExtensions::replace(new_path, "{x}", std::to_string((j + z_num) % z_num));
paxs::StringExtensions::replace(new_path, "{y}", std::to_string((i + z_num) % z_num));
paxs::StringExtensions::replace(new_path, "{z}", std::to_string(z));
const s3d::URL new_url = s3d::Unicode::FromUTF8(new_path);
//const s3d::URL new_url =
// s3d::String(s3d::Unicode::FromUTF8(map_url_name))
// + s3d::String(U"/") + s3d::ToString(z)
// + s3d::String(U"/") + s3d::ToString((j + z_num) % z_num)
// + s3d::String(U"/") + s3d::ToString((i + z_num) % z_num)
// + s3d::String(U".png");
if (s3d::SimpleHTTP::Save(new_url, s3d::Unicode::FromUTF8(new_saveFilePath)).isOK()) {
// texture_list[k] = paxg::Texture{ new_saveFilePath };

Expand Down Expand Up @@ -254,12 +263,15 @@ namespace paxs {
}
}
}
void draw(const double map_view_width, const double map_view_height, const double map_view_center_x, const double map_view_center_y
void draw(const double map_view_width, const double map_view_height, const double map_view_center_x, const double map_view_center_y, const int date
)const {

// 拡大率が描画範囲外の場合はここで処理を終了
if (magnification_z < draw_min_z) return;
if (magnification_z > draw_max_z) return;
// 描画する期間じゃない場合はここで処理を終了
if (min_date != 99999999 && min_date > date) return;
if (max_date != 99999999 && max_date < date) return;
// 描画する場所がない場合は無視
if (pos_list2.size() == 0) return;

Expand Down Expand Up @@ -356,6 +368,12 @@ namespace paxs {
void setDrawMaxZ(const int max_z_) {
draw_max_z = max_z_;
}
void setMinDate(const int min_date_) {
min_date = min_date_;
}
void setMaxDate(const int max_date_) {
max_date = max_date_;
}
void setMapURL(const std::string& map_url_name_) {
map_url_name = map_url_name_;
}
Expand All @@ -366,6 +384,10 @@ namespace paxs {
map_file_path_name = map_file_path_name_;
}
private:
// 99999999 の場合は固定なし
int min_date = 99999999;
int max_date = 99999999;

// 固定された Z ( 999 の場合は固定なし )
int default_z = 999;
// 最小 Z
Expand Down
Loading

0 comments on commit e8224b7

Please sign in to comment.