Skip to content

Commit

Permalink
Merge pull request #51 from AsPJT/feature/fix-sfml-error
Browse files Browse the repository at this point in the history
fix: SFML関連のエラーを修正
  • Loading branch information
guinpen98 authored Sep 26, 2023
2 parents c8cdcd1 + eca4340 commit 1ff1b7f
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 102 deletions.
84 changes: 44 additions & 40 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
[submodule "ExternalLibrary/googletest"]
path = ExternalLibrary/googletest
url = https://github.com/google/googletest.git
branch = main
path = ExternalLibrary/googletest
url = https://github.com/google/googletest.git
branch = main
[submodule "ExternalLibrary/stb"]
path = ExternalLibrary/stb
url = https://github.com/nothings/stb.git
branch = master
path = ExternalLibrary/stb
url = https://github.com/nothings/stb.git
branch = master
[submodule "Data/3DModel/KofunOBJ"]
path = Data/3DModel/KofunOBJ
url = https://github.com/Asukana/KofunOBJ.git
branch = main
path = Data/3DModel/KofunOBJ
url = https://github.com/Asukana/KofunOBJ.git
branch = main
[submodule "Data/Map/XYZTile/Elevation/Data/Elevation"]
path = Data/Map/XYZTile/Elevation/Data/Elevation
url = https://github.com/Asukana/Elevation.git
branch = main
path = Data/Map/XYZTile/Elevation/Data/Elevation
url = https://github.com/Asukana/Elevation.git
branch = main
[submodule "Data/Map/XYZTile/IPCC/Image/IPCC"]
path = Data/Map/XYZTile/IPCC/Image/IPCC
url = https://github.com/Asukana/IPCC.git
branch = main
path = Data/Map/XYZTile/IPCC/Image/IPCC
url = https://github.com/Asukana/IPCC.git
branch = main
[submodule "Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakes"]
path = Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakes
url = https://github.com/Asukana/RiversAndLakes.git
branch = main
path = Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakes
url = https://github.com/Asukana/RiversAndLakes.git
branch = main
[submodule "Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakesBW"]
path = Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakesBW
url = https://github.com/Asukana/RiversAndLakesBW.git
branch = main
path = Data/Map/XYZTile/RiversAndLakes/Image/RiversAndLakesBW
url = https://github.com/Asukana/RiversAndLakesBW.git
branch = main
[submodule "Data/Map/XYZTile/RyoseikokuData/Data/RyoseikokuData20230626"]
path = Data/Map/XYZTile/RyoseikokuData/Data/RyoseikokuData20230626
url = https://github.com/Asukana/RyoseikokuData20230626.git
branch = main
path = Data/Map/XYZTile/RyoseikokuData/Data/RyoseikokuData20230626
url = https://github.com/Asukana/RyoseikokuData20230626.git
branch = main
[submodule "Data/Map/XYZTile/RyoseikokuData/Data/JapanRegionData20230918"]
path = Data/Map/XYZTile/RyoseikokuData/Data/JapanRegionData20230918
url = https://github.com/Asukana/JapanRegionData20230918.git
branch = main
[submodule "Data/Map/XYZTile/Slope/Image/Slope"]
path = Data/Map/XYZTile/Slope/Image/Slope
url = https://github.com/Asukana/Slope.git
branch = main
path = Data/Map/XYZTile/RyoseikokuData/Data/JapanRegionData20230918
url = https://github.com/Asukana/JapanRegionData20230918.git
branch = main
[submodule "Data/Map/XYZTile/Slope/Data/SlopeData20230514"]
path = Data/Map/XYZTile/Slope/Data/SlopeData20230514
url = https://github.com/Asukana/SlopeData20230514.git
branch = main
path = Data/Map/XYZTile/Slope/Data/SlopeData20230514
url = https://github.com/Asukana/SlopeData20230514.git
branch = main
[submodule "Data/Map/XYZTile/Slope/Image/Slope"]
path = Data/Map/XYZTile/Slope/Image/Slope
url = https://github.com/Asukana/Slope.git
branch = main
[submodule "Data/Map/XYZTile/Slope/Image/SlopePale20230920"]
path = Data/Map/XYZTile/Slope/Image/SlopePale20230920
url = https://github.com/Asukana/SlopePale20230920.git
branch = main
[submodule "Data/Map/XYZTile/Soil/Image/Soil"]
path = Data/Map/XYZTile/Soil/Image/Soil
url = https://github.com/Asukana/Soil.git
branch = main
path = Data/Map/XYZTile/Soil/Image/Soil
url = https://github.com/Asukana/Soil.git
branch = main
[submodule "Data/Map/XYZTile/Temperature/Image/SoilTemperature"]
path = Data/Map/XYZTile/Temperature/Image/SoilTemperature
url = https://github.com/Asukana/SoilTemperature.git
branch = main
path = Data/Map/XYZTile/Temperature/Image/SoilTemperature
url = https://github.com/Asukana/SoilTemperature.git
branch = main
1 change: 1 addition & 0 deletions Data/Map/XYZTile/Slope/Image/SlopePale20230920
Submodule SlopePale20230920 added at 5ae172
1 change: 1 addition & 0 deletions ExternalLibrary/cpp-httplib
Submodule cpp-httplib added at 67f6ff
2 changes: 1 addition & 1 deletion Library/PAX_GRAPHICA/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#if defined(PAXS_USING_SIV3D)
#include <Siv3D/Color.hpp>
#elif defined(PAXS_USING_SFML)
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics.hpp>
#elif defined(PAXS_USING_DXLIB)
#include <DxLib.h>
#endif
Expand Down
46 changes: 17 additions & 29 deletions Library/PAX_GRAPHICA/Rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,20 @@ namespace paxg {
Rect(const sf::Vector2i& pos, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition(pos.x, pos.y); }
Rect(const float x, const float y, const sf::Vector2i& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition(x, y); }
operator sf::RectangleShape() const { return rect; }
void setX(const float x_) { rect.x = x_; }
void setY(const float y_) { rect.y = y_; }
void setW(const float w_) { rect.w = w_; }
void setH(const float h_) { rect.h = h_; }
float x() const { return rect.x; }
float y() const { return rect.y; }
float w() const { return rect.w; }
float h() const { return rect.h; }
Vec2i pos() const { return Vec2i(rect.x, rect.y); }
Vec2i size() const { return Vec2i(rect.w, rect.h); }
void setPos(const float x_, const float y_) {
rect.x = x_;
rect.y = y_;
}
void setSize(const float w_, const float h_) {
rect.w = w_;
rect.h = h_;
}
void setPos(const Vec2i& pos_) {
rect.x = pos_.x();
rect.y = pos_.y();
}
void setSize(const Vec2i& size_) {
rect.w = size_.x();
rect.h = size_.y();
}
void setX(const float x_) { rect.setPosition(x_, rect.getPosition().y); }
void setY(const float y_) { rect.setPosition(rect.getPosition().x, y_); }
void setW(const float w_) { rect.setSize(sf::Vector2f(w_, rect.getSize().y)); }
void setH(const float h_) { rect.setSize(sf::Vector2f(rect.getSize().x, h_)); }
float x() const { return rect.getPosition().x; }
float y() const { return rect.getPosition().y; }
float w() const { return rect.getSize().x; }
float h() const { return rect.getSize().y; }
Vec2i pos() const { return Vec2i(static_cast<int>(rect.getPosition().x), static_cast<int>(rect.getPosition().y)); }
Vec2i size() const { return Vec2i(static_cast<int>(rect.getSize().x), static_cast<int>(rect.getSize().y)); }
void setPos(const float x_, const float y_) { rect.setPosition(x_, y_); }
void setSize(const float w_, const float h_) { rect.setSize(sf::Vector2f(w_, h_)); }
void setPos(const Vec2i& pos_) { rect.setPosition(pos_.x(), pos_.y()); }
void setSize(const Vec2i& size_) { rect.setSize(sf::Vector2f(size_.x(), size_.y())); }
#else
float x0{}, y0{}, w0{}, h0{};
constexpr Rect() = default;
Expand Down Expand Up @@ -155,7 +143,7 @@ namespace paxg {
#if defined(PAXS_USING_SIV3D)
rect.draw(c_.color);
#elif defined(PAXS_USING_SFML)
Window::window.draw(c_);
Window::window.draw(rect);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(
static_cast<int>(x0), static_cast<int>(y0), static_cast<int>(x0 + w0), static_cast<int>(y0 + h0),
Expand All @@ -177,7 +165,7 @@ namespace paxg {
#if defined(PAXS_USING_SIV3D)
// rect.draw(c_.color);
#elif defined(PAXS_USING_SFML)
Window::window.draw(c_);
Window::window.draw(rect);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(
static_cast<int>(x0 - w0 / 2), static_cast<int>(y0 - h0 / 2), static_cast<int>(x0 + w0 / 2), static_cast<int>(y0 + h0 / 2),
Expand All @@ -189,7 +177,7 @@ namespace paxg {
#if defined(PAXS_USING_SIV3D)
rect.drawFrame(inner_thickness, outer_thickness, color_.color);
#elif defined(PAXS_USING_SFML)
Window::window.draw(color_);
Window::window.draw(rect);
#elif defined(PAXS_USING_DXLIB)
DxLib::DrawBox(
static_cast<int>(x0 - outer_thickness), static_cast<int>(y0 - outer_thickness),
Expand Down
33 changes: 25 additions & 8 deletions Library/PAX_GRAPHICA/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <PAX_GRAPHICA/IDrawable.hpp>
#include <PAX_GRAPHICA/Image.hpp>
#include <PAX_GRAPHICA/Window.hpp>
#include <PAX_SAPIENTICA/Logger.hpp>
#include <PAX_SAPIENTICA/StringExtensions.hpp>

namespace paxg {

Expand All @@ -44,9 +46,24 @@ namespace paxg {
#elif defined(PAXS_USING_SFML)
sf::Texture texture{};
Texture(const paxg::Image& image) { texture.loadFromImage(image); }
Texture(const paxg::String& path) { texture.loadFromFile(path); }
Texture(const std::string& path) {
texture.loadFromFile(static_cast<paxg::String>(path));
Texture(const paxg::String& path) {
// svgの場合は読み込めないので、pngに拡張子を変換する
std::string path_str = path.string;
paxs::StringExtensions::replace(path_str, ".svg", ".png");

if(!texture.loadFromFile(path_str)) {
paxs::Logger logger("Save/warning_log.txt");
logger.log(paxs::Logger::Level::PAX_WARNING, __FILE__, __LINE__, "Failed to load texture: " + path.string);
}
}
Texture(std::string path) {
// svgの場合は読み込めないので、pngに拡張子を変換する
paxs::StringExtensions::replace(path, ".svg", ".png");

if(!texture.loadFromFile(static_cast<paxg::String>(path))) {
paxs::Logger logger("Save/warning_log.txt");
logger.log(paxs::Logger::Level::PAX_WARNING, __FILE__, __LINE__, "Failed to load texture: " + path);
}
}
operator sf::Texture() const { return texture; }
#elif defined(PAXS_USING_DXLIB)
Expand Down Expand Up @@ -126,7 +143,7 @@ namespace paxg {
DxLib::DrawGraph(pos.x() - (width() / 2), pos.y() - (height() / 2), texture, TRUE);
#elif defined(PAXS_USING_SFML)
sf::Sprite sprite(texture);
sprite.setPosition(pos);
sprite.setPosition(static_cast<float>(pos.x()), static_cast<float>(pos.y()));
paxg::Window::window.draw(sprite);
#endif
}
Expand Down Expand Up @@ -193,7 +210,7 @@ namespace paxg {
pos.x() + resize.x(), pos.y() + resize.y(),
texture, TRUE);
#elif defined(PAXS_USING_SFML)
draw(pos);
drawAt(pos);
#endif
}
void resizedDraw(const int resize, const paxg::Vec2i& pos) const
Expand All @@ -206,7 +223,7 @@ namespace paxg {
pos.x() + resize, pos.y() + resize,
texture, TRUE);
#elif defined(PAXS_USING_SFML)
draw(pos);
drawAt(pos);
#endif
}
void resizedDraw(const paxg::Vec2f& resize, const paxg::Vec2f& pos) const
Expand All @@ -219,7 +236,7 @@ namespace paxg {
pos.x() + resize.x(), pos.y() + resize.y(),
texture, TRUE);
#elif defined(PAXS_USING_SFML)
draw(pos);
drawAt(pos);
#endif
}
void resizedDraw(const int resize, const paxg::Vec2f& pos) const
Expand All @@ -232,7 +249,7 @@ namespace paxg {
pos.x() + resize, pos.y() + resize,
texture, TRUE);
#elif defined(PAXS_USING_SFML)
draw(pos);
drawAt(pos);
#endif
}
};
Expand Down
2 changes: 1 addition & 1 deletion Library/PAX_GRAPHICA/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace paxg {

namespace Window {
#ifdef PAXS_USING_SFML
sf::RenderWindow window;
sf::RenderWindow window(sf::VideoMode(1920, 1080), "PAX SAPIENTICA Library");
#endif // PAXS_USING_SFML

void Init(int width, int height, const std::string& title) {
Expand Down
12 changes: 6 additions & 6 deletions Library/PAX_SAPIENTICA/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace paxs {
/// @brief The level of the log.
/// @brief ログのレベル。
enum class Level {
INFO, // 情報を示すメッセージ(警告やエラー以外)
WARNING, // 警告メッセージ
PAX_INFO, // 情報を示すメッセージ(警告やエラー以外)
PAX_WARNING, // 警告メッセージ
PAX_ERROR // エラーメッセージ
};

Expand Down Expand Up @@ -75,15 +75,15 @@ namespace paxs {
void log(const Level level, const std::string& filename, const int line, const std::string& message) noexcept {
const std::string current_time = currentDateTime();
file << "[" << current_time << "] ";

switch(level) {
case Level::INFO:
case Level::PAX_INFO:
file << "[INFO]: ";
break;
case Level::WARNING:
case Level::PAX_WARNING:
file << "[WARNING]: ";
break;
case Level::PAX_ERROR:
case Level::PAX_ERROR:
file << "[ERROR]: ";
break;
}
Expand Down
20 changes: 10 additions & 10 deletions Library/PAX_SAPIENTICA/Simulation/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace paxs {
catch (const std::exception&) {
Logger logger("Save/error_log.txt");
const std::string message = "Failed to load data: " + file_path;
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, message);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, message);
throw std::runtime_error(message);
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ namespace paxs {
file_names = File::getFileNames(file_path);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File not found: " + file_path);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File not found: " + file_path);
throw;
}

Expand All @@ -118,7 +118,7 @@ namespace paxs {
if(file_names.size() == 0) {
Logger logger("Save/error_log.txt");
const std::string message = "File not found: " + file_path;
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, message);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, message);
throw std::runtime_error(message);
}

Expand All @@ -130,7 +130,7 @@ namespace paxs {
} else {
Logger logger("Save/error_log.txt");
const std::string message = "File type is invalid: " + file_names[0];
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, message);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, message);
throw std::runtime_error(message);
}
}
Expand All @@ -149,7 +149,7 @@ namespace paxs {
xyz_position = getXAndYFromFileName(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
++file_count;
continue;
}
Expand All @@ -165,7 +165,7 @@ namespace paxs {
file = File::readFile(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
++file_count;
continue;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace paxs {
xyz_position = getXAndYFromFileName(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
++file_count;
continue;
}
Expand All @@ -234,7 +234,7 @@ namespace paxs {
file = File::readFile(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
++file_count;
continue;
}
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace paxs {
xyz_position = getXAndYFromFileName(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File name is invalid: " + file_name);
++file_count;
continue;
}
Expand All @@ -285,7 +285,7 @@ namespace paxs {
file = File::readFile(file_name);
} catch (const std::exception&) {
Logger logger("Save/error_log.txt");
logger.log(Logger::Level::WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
logger.log(Logger::Level::PAX_WARNING, __FILE__, __LINE__, "File is not found: " + file_name);
++file_count;
continue;
}
Expand Down
Loading

0 comments on commit 1ff1b7f

Please sign in to comment.