diff --git a/Library/PAX_GRAPHICA/Circle.hpp b/Library/PAX_GRAPHICA/Circle.hpp index 31259cca9..77a0d9fa6 100644 --- a/Library/PAX_GRAPHICA/Circle.hpp +++ b/Library/PAX_GRAPHICA/Circle.hpp @@ -21,24 +21,25 @@ #include #endif -#include #include +#include + namespace paxg { struct Circle { #if defined(PAXS_USING_SIV3D) s3d::Circle circle; - constexpr Circle(const float x, const float y, const float r) : circle(x, y, r) {} - constexpr Circle(const paxg::Vec2i& pos, const float r) : circle(pos.x(), pos.y(), r) {} - constexpr Circle(const paxg::Vec2& pos, const float r) : circle(static_cast(pos.x()), static_cast(pos.y()), r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : circle(pos.x, pos.y, r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : circle(pos.x, pos.y, r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : circle(static_cast(pos.x), static_cast(pos.y), r) {} constexpr operator s3d::Circle() const { return circle; } #else float x, y, r; - constexpr Circle(const float x, const float y, const float r) : x(x), y(y), r(r) {} - constexpr Circle(const paxg::Vec2i& pos, const float r) : x(static_cast(pos.x())), y(static_cast(pos.y())), r(r) {} - constexpr Circle(const paxg::Vec2& pos, const float r) : x(static_cast(pos.x())), y(static_cast(pos.y())), r(r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : x(static_cast(pos.x)), y(static_cast(pos.y)), r(r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : x(pos.x), y(pos.y), r(r) {} + constexpr Circle(const paxs::Vector2& pos, const float r) : x(static_cast(pos.x)), y(static_cast(pos.y)), r(r) {} #endif void draw() const { #if defined(PAXS_USING_SIV3D) diff --git a/Library/PAX_GRAPHICA/implementations/DxLibTextureImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp similarity index 62% rename from Library/PAX_GRAPHICA/implementations/DxLibTextureImpl.hpp rename to Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp index a047694cb..d3c428c5b 100644 --- a/Library/PAX_GRAPHICA/implementations/DxLibTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibTextureImpl.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -115,28 +115,28 @@ namespace paxg { DxLib::DrawGraph(0, 0, texture, TRUE); } - void drawAt(const Vec2f& pos) const override { + void drawAt(const paxs::Vector2& pos) const override { DxLib::DrawGraph( - static_cast(pos.x() - (cachedWidth / 2.0f)), - static_cast(pos.y() - (cachedHeight / 2.0f)), + pos.x - (cachedWidth / 2), + pos.y - (cachedHeight / 2), texture, TRUE); } - void drawAt(const Vec2i& pos) const override { + void drawAt(const paxs::Vector2& pos) const override { DxLib::DrawGraph( - pos.x() - (cachedWidth / 2), - pos.y() - (cachedHeight / 2), + static_cast(pos.x - (cachedWidth / 2.0f)), + static_cast(pos.y - (cachedHeight / 2.0f)), texture, TRUE); } - void resizedDrawAt(const Vec2i& resize, const Vec2i& pos) const override { + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { DxLib::DrawExtendGraph( - pos.x() - (resize.x() / 2), pos.y() - (resize.y() / 2), - pos.x() + (resize.x() / 2), pos.y() + (resize.y() / 2), + pos.x, pos.y, + pos.x + resize.x, pos.y + resize.y, texture, TRUE); } - void resizedDrawAt(int resize, const Vec2i& pos) const override { + void resizedDraw(int resize, const paxs::Vector2& pos) const override { // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 const float scale_x = static_cast(resize) / cachedWidth; const float scale_y = static_cast(resize) / cachedHeight; @@ -146,45 +146,30 @@ namespace paxg { const int new_height = static_cast(cachedHeight * scale); DxLib::DrawExtendGraph( - pos.x() - (new_width / 2), pos.y() - (new_height / 2), - pos.x() + (new_width / 2), pos.y() + (new_height / 2), + pos.x, pos.y, + pos.x + new_width, pos.y + new_height, texture, TRUE); } - void resizedDrawAt(const Vec2f& resize, const Vec2f& pos) const override { + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { DxLib::DrawExtendGraph( - static_cast(pos.x() - (resize.x() / 2)), - static_cast(pos.y() - (resize.y() / 2)), - static_cast(pos.x() + (resize.x() / 2)), - static_cast(pos.y() + (resize.y() / 2)), + static_cast(pos.x), static_cast(pos.y), + static_cast(pos.x + resize.x), static_cast(pos.y + resize.y), texture, TRUE); } - void resizedDrawAt(int resize, const Vec2f& pos) const override { - // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 - const float scale_x = static_cast(resize) / cachedWidth; - const float scale_y = static_cast(resize) / cachedHeight; - const float scale = (scale_x < scale_y) ? scale_x : scale_y; - - const float new_width = cachedWidth * scale; - const float new_height = cachedHeight * scale; - - DxLib::DrawExtendGraph( - static_cast(pos.x() - (new_width / 2.0f)), - static_cast(pos.y() - (new_height / 2.0f)), - static_cast(pos.x() + (new_width / 2.0f)), - static_cast(pos.y() + (new_height / 2.0f)), - texture, TRUE); + void resizedDraw(int resize, const paxs::Vector2& pos) const override { + resizedDraw(resize, paxs::Vector2(pos)); } - void resizedDraw(const Vec2i& resize, const Vec2i& pos) const override { + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { DxLib::DrawExtendGraph( - pos.x(), pos.y(), - pos.x() + resize.x(), pos.y() + resize.y(), + pos.x - (resize.x / 2), pos.y - (resize.y / 2), + pos.x + (resize.x / 2), pos.y + (resize.y / 2), texture, TRUE); } - void resizedDraw(int resize, const Vec2i& pos) const override { + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 const float scale_x = static_cast(resize) / cachedWidth; const float scale_y = static_cast(resize) / cachedHeight; @@ -194,31 +179,22 @@ namespace paxg { const int new_height = static_cast(cachedHeight * scale); DxLib::DrawExtendGraph( - pos.x(), pos.y(), - pos.x() + new_width, pos.y() + new_height, + pos.x - (new_width / 2), pos.y - (new_height / 2), + pos.x + (new_width / 2), pos.y + (new_height / 2), texture, TRUE); } - void resizedDraw(const Vec2f& resize, const Vec2f& pos) const override { + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { DxLib::DrawExtendGraph( - static_cast(pos.x()), static_cast(pos.y()), - static_cast(pos.x() + resize.x()), static_cast(pos.y() + resize.y()), + static_cast(pos.x - (resize.x / 2)), + static_cast(pos.y - (resize.y / 2)), + static_cast(pos.x + (resize.x / 2)), + static_cast(pos.y + (resize.y / 2)), texture, TRUE); } - void resizedDraw(int resize, const Vec2f& pos) const override { - // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 - const float scale_x = static_cast(resize) / cachedWidth; - const float scale_y = static_cast(resize) / cachedHeight; - const float scale = (scale_x < scale_y) ? scale_x : scale_y; - - const float new_width = cachedWidth * scale; - const float new_height = cachedHeight * scale; - - DxLib::DrawExtendGraph( - static_cast(pos.x()), static_cast(pos.y()), - static_cast(pos.x() + new_width), static_cast(pos.y() + new_height), - texture, TRUE); + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { + resizedDrawAt(resize, paxs::Vector2(pos)); } }; diff --git a/Library/PAX_GRAPHICA/implementations/DxLibWindowImpl.hpp b/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp similarity index 89% rename from Library/PAX_GRAPHICA/implementations/DxLibWindowImpl.hpp rename to Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp index c39af2867..f17780c56 100644 --- a/Library/PAX_GRAPHICA/implementations/DxLibWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/DxLib/DxLibWindowImpl.hpp @@ -22,7 +22,7 @@ #include #endif // PAXS_PLATFORM_WINDOWS -#include +#include #include #include @@ -131,11 +131,7 @@ namespace paxg { cacheDirty = false; } - void setPosition(int, int) override { - // DxLib does not support window position control - } - - void setPosition(const Vec2i&) override { + void setPosition(const paxs::Vector2&) override { // DxLib does not support window position control } @@ -179,26 +175,14 @@ namespace paxg { // DxLib does not support mouse cursor visibility control } - void setMouseCursorGrabbed(bool) override { - // DxLib does not support mouse cursor grabbing - } - void setMouseCursor(const std::string&) override { // DxLib does not support mouse cursor setting } - void setMousePosition(int, int) override { + void setMousePosition(const paxs::Vector2&) override { // DxLib does not support mouse position setting } - void setMousePosition(const Vec2i&) override { - // DxLib does not support mouse position setting - } - - void setKeyRepeat(bool) override { - // DxLib does not support key repeat control - } - void setBackgroundColor(const Color color) override { DxLib::SetBackgroundColor(color.r, color.g, color.b); } @@ -215,9 +199,9 @@ namespace paxg { DxLib::SetWindowStyleMode(decorated ? 1 : 8); // 1: 通常ウィンドウ, 8: 枠なし } - Vec2i center() const override { + paxs::Vector2 center() const override { updateCache(); - return Vec2i{cachedWidth / 2, cachedHeight / 2}; + return paxs::Vector2{cachedWidth / 2, cachedHeight / 2}; } int width() const override { @@ -230,14 +214,14 @@ namespace paxg { return cachedHeight; } - Vec2i size() const override { + paxs::Vector2 size() const override { updateCache(); - return Vec2i{cachedWidth, cachedHeight}; + return paxs::Vector2{cachedWidth, cachedHeight}; } - Vec2i getMousePosition() const override { + paxs::Vector2 getMousePosition() const override { // DxLib does not support mouse position query - return Vec2i(0, 0); + return paxs::Vector2(0, 0); } bool hasFocus() const override { @@ -259,6 +243,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_DXLIB) +#endif // PAXS_USING_DXLIB #endif // !PAX_GRAPHICA_DXLIB_WINDOW_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/RenderTextureImpl.hpp b/Library/PAX_GRAPHICA/Interface/RenderTextureImpl.hpp similarity index 100% rename from Library/PAX_GRAPHICA/RenderTextureImpl.hpp rename to Library/PAX_GRAPHICA/Interface/RenderTextureImpl.hpp diff --git a/Library/PAX_GRAPHICA/TextureImpl.hpp b/Library/PAX_GRAPHICA/Interface/TextureImpl.hpp similarity index 56% rename from Library/PAX_GRAPHICA/TextureImpl.hpp rename to Library/PAX_GRAPHICA/Interface/TextureImpl.hpp index 3ac2656f6..1092699c2 100644 --- a/Library/PAX_GRAPHICA/TextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Interface/TextureImpl.hpp @@ -15,8 +15,8 @@ #include #include -#include +#include #include namespace paxg { @@ -31,18 +31,19 @@ namespace paxg { virtual int height() const = 0; virtual void draw() const = 0; - virtual void drawAt(const paxg::Vec2f& pos) const = 0; - virtual void drawAt(const paxg::Vec2i& pos) const = 0; - - virtual void resizedDrawAt(const paxg::Vec2i& resize, const paxg::Vec2i& pos) const = 0; - virtual void resizedDrawAt(int resize, const paxg::Vec2i& pos) const = 0; - virtual void resizedDrawAt(const paxg::Vec2f& resize, const paxg::Vec2f& pos) const = 0; - virtual void resizedDrawAt(int resize, const paxg::Vec2f& pos) const = 0; - - virtual void resizedDraw(const paxg::Vec2i& resize, const paxg::Vec2i& pos) const = 0; - virtual void resizedDraw(int resize, const paxg::Vec2i& pos) const = 0; - virtual void resizedDraw(const paxg::Vec2f& resize, const paxg::Vec2f& pos) const = 0; - virtual void resizedDraw(int resize, const paxg::Vec2f& pos) const = 0; + + virtual void drawAt(const paxs::Vector2& pos) const = 0; + virtual void drawAt(const paxs::Vector2& pos) const = 0; + + virtual void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDraw(int resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDraw(int resize, const paxs::Vector2& pos) const = 0; + + virtual void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDrawAt(int resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const = 0; + virtual void resizedDrawAt(int resize, const paxs::Vector2& pos) const = 0; protected: // Helper to convert SVG paths to PNG diff --git a/Library/PAX_GRAPHICA/WindowImpl.hpp b/Library/PAX_GRAPHICA/Interface/WindowImpl.hpp similarity index 75% rename from Library/PAX_GRAPHICA/WindowImpl.hpp rename to Library/PAX_GRAPHICA/Interface/WindowImpl.hpp index 25e9e6ed1..79640c4fb 100644 --- a/Library/PAX_GRAPHICA/WindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Interface/WindowImpl.hpp @@ -15,7 +15,8 @@ #include #include -#include + +#include namespace paxg { @@ -36,28 +37,24 @@ namespace paxg { virtual void setTitle(const std::string& title) = 0; virtual void setSize(int width, int height) = 0; - virtual void setPosition(int x, int y) = 0; - virtual void setPosition(const Vec2i& pos) = 0; + virtual void setPosition(const paxs::Vector2& pos) = 0; virtual void setIcon(const std::string& path) = 0; virtual void setVisible(bool visible) = 0; virtual void setVSync(bool vsync) = 0; virtual void setFPS(int fps) = 0; virtual void setMouseCursorVisible(bool visible) = 0; - virtual void setMouseCursorGrabbed(bool grabbed) = 0; virtual void setMouseCursor(const std::string& path) = 0; - virtual void setMousePosition(int x, int y) = 0; - virtual void setMousePosition(const Vec2i& pos) = 0; - virtual void setKeyRepeat(bool repeat) = 0; - virtual void setBackgroundColor(const paxg::Color color) = 0; - virtual void setLetterbox(const paxg::Color color) = 0; + virtual void setMousePosition(const paxs::Vector2& pos) = 0; + virtual void setBackgroundColor(paxg::Color color) = 0; + virtual void setLetterbox(paxg::Color color) = 0; virtual void setResizable(bool resizable) = 0; virtual void setDecorated(bool decorated) = 0; - virtual paxg::Vec2i center() const = 0; + virtual paxs::Vector2 center() const = 0; virtual int width() const = 0; virtual int height() const = 0; - virtual paxg::Vec2i size() const = 0; - virtual paxg::Vec2i getMousePosition() const = 0; + virtual paxs::Vector2 size() const = 0; + virtual paxs::Vector2 getMousePosition() const = 0; virtual bool hasFocus() const = 0; virtual void clear() = 0; diff --git a/Library/PAX_GRAPHICA/Mock.hpp b/Library/PAX_GRAPHICA/Mock.hpp deleted file mode 100644 index 246d71a19..000000000 --- a/Library/PAX_GRAPHICA/Mock.hpp +++ /dev/null @@ -1,511 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023-2024 As Project - [Production] 2023-2024 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_GRAPHICA_MOCK_HPP -#define PAX_GRAPHICA_MOCK_HPP - -#include -#include - -namespace s3d -{ - using String = std::u32string; - using int32 = int; - using FilePath = String; - using URL = String; - - struct Vec2; - - struct Point - { - std::size_t x, y; - Point() : x(0), y(0) {} - Point(std::size_t _x, std::size_t _y) : x(_x), y(_y) {} - Point operator+([[maybe_unused]] const Point& p) const { return Point(); } - Point operator-([[maybe_unused]] const Point& p) const { return Point(); } - Point operator*([[maybe_unused]] double d) const { return Point(); } - Point movedBy([[maybe_unused]] int x_, [[maybe_unused]] int y_) const { return Point(); } - Point movedBy([[maybe_unused]] const Point& p) const { return Point(); } - Point operator +([[maybe_unused]] const Vec2& p) const { return Point(); } - }; - - enum class Palette - { - White - , Black - , Orange - , Gray - , Skyblue - }; - - enum class BlendState - { - MaxAlpha - }; - - using Size = Vec2; - - struct Vec2 - { - double x{}, y{}; - Vec2() {} - Vec2(int, int) {} - Vec2(double _x, double _y) : x(_x), y(_y) {} - Vec2 operator*([[maybe_unused]] double d) const { return Vec2(); } - Point movedBy([[maybe_unused]] int x_, [[maybe_unused]] int y_) const { return Point(); } - Vec2 operator +([[maybe_unused]] const Size& p) const { return Vec2(); } - }; - - std::array step(std::size_t v) { return std::array{v}; } - - namespace Arg { - Vec2 bottomCenter; - Vec2 topCenter; - Vec2 topRight; - Vec2 bottomLeft; - } - - class ColorF - { - public: - double r, g, b, a; - ColorF removeSRGBCurve() const { return *this; } - }; - - class Color - { - public: - unsigned char r, g, b, a; - Color() : r(0), g(0), b(0), a(255) {} - Color(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a = 255) : r(_r), g(_g), b(_b), a(_a) {} - operator ColorF() const { return ColorF(); } - }; - - struct Rect - { - std::size_t x{}, y{}, w{}, h{}; - Rect() {} - Rect(int, int, int, int) {} - Rect(Point, int, double) {} - Rect(int, int, int) {} - Rect(Point, std::size_t, std::size_t) {} - Rect(Point, Size) {} - Point pos; - Size size; - static int value_type([[maybe_unused]] std::size_t x_) { return 0; } - bool leftClicked() const { return false; } - void draw() const {} - void draw([[maybe_unused]] Palette p) const {} - void draw([[maybe_unused]] const Color& color) const {} - void drawFrame([[maybe_unused]] int x_, [[maybe_unused]] int y_, [[maybe_unused]] Palette p) const {} - void drawFrame([[maybe_unused]] int x_, [[maybe_unused]] int y_, [[maybe_unused]] ColorF p) const {} - bool mouseOver() const { return false; } - Rect drawShadow([[maybe_unused]] Point p, [[maybe_unused]] int x_, [[maybe_unused]] int y_) const { return Rect(); } - void setPos([[maybe_unused]] Point p) {} - }; - - class Line - { - public: - int x, y, w, h; - Line() : x(0), y(0), w(0), h(0) {} - Line(int x_, int y_, int w_, int h_) : x(x_), y(y_), w(w_), h(h_) {} - void draw([[maybe_unused]] double w_, [[maybe_unused]] ColorF c_) const {} - }; - - enum class TextureDesc - { - MippedSRGB - }; - - class Model - { - public: - String path; - Model() {} - Model([[maybe_unused]] const String& path_) {} - static void RegisterDiffuseTextures([[maybe_unused]] Model model, [[maybe_unused]] TextureDesc t) {} - }; - - class Image - { - public: - String path; - Image() {} - Image([[maybe_unused]] const String& path) {} - String mirror() const { return path; } - }; - - class Graphics - { - public: - static void SetBackground([[maybe_unused]] const ColorF& color) {} - static void Set3DRenderState() {} - }; - - class Vec3 - { - public: - float x, y, z; - Vec3() : x(0), y(0), z(0) {} - Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} - }; - - class DebugCamera3D - { - public: - Size size; - double d; - Vec3 eye; - }; - - class Graphics3D - { - public: - static void SetGlobalAmbientColor([[maybe_unused]] const ColorF& color) {} - static void SetSunColor([[maybe_unused]] const ColorF& color) {} - static void SetCameraTransform([[maybe_unused]] DebugCamera3D camera) {} - static Size GetRenderTargetSize() { return Size(); } - static void Flush() {} - }; - - class Scene - { - public: - static int Width() { return 0; } - static int Height() { return 0; } - static Vec2 Center() { return Vec2(); } - static s3d::Size Size() { return s3d::Size(); } - static void SetBackground([[maybe_unused]] s3d::Color color) {} - static void SetLetterbox([[maybe_unused]] s3d::Color color) {} - }; - - class Key - { - public: - static bool Down() { return false; } - static bool Press() { return false; } - static bool Up() { return false; } - }; - - class Input - { - public: - static bool pressed() { return false; } - }; - - Input input; - - String ToString([[maybe_unused]] int n) { return String(); } - - Input KeyW = Input(); - Input KeyA = Input(); - Input KeyS = Input(); - Input KeyD = Input(); - Input KeyQ = Input(); - Input KeyE = Input(); - Input KeyLeft = Input(); - Input KeyRight = Input(); - Input KeyUp = Input(); - Input KeyDown = Input(); - - enum WindowStyle - { - Frameless - , Sizable - }; - - class Window - { - public: - static void SetTitle([[maybe_unused]] const String& title) {} - static void Resize([[maybe_unused]] const int w, [[maybe_unused]] const int h) {} - static void SetStyle([[maybe_unused]] const WindowStyle style) {} - }; - - class System - { - public: - static bool Update() { return true; } - static void LaunchBrowser(String) {} - }; - - struct Circle - { - Vec2 center; - int radius; - Circle() : center(), radius(0) {} - Circle(Vec2 _center, int _radius) : center(_center), radius(_radius) {} - }; - - int Max([[maybe_unused]] int a, [[maybe_unused]] int b) { return 0; } - - class FontMethod - { - public: - FontMethod() {} - static FontMethod SDF; - }; - FontMethod FontMethod::SDF = FontMethod(); - - class Font - { - public: - FontMethod method{}; - int w{}; - String path{}; - Font operator()([[maybe_unused]] String path_) const { return Font(); } - Font region() const { return Font(); } - int height() const { return 0; } - void drawAt([[maybe_unused]] Vec2 p, [[maybe_unused]] String s) const {} - void drawAt([[maybe_unused]] Vec2 p, [[maybe_unused]] double a, [[maybe_unused]] double b, [[maybe_unused]] Palette pa) const {} - void draw([[maybe_unused]] Vec2 p, [[maybe_unused]] String s, [[maybe_unused]] Palette pa) const {} - void draw([[maybe_unused]] Vec2 p, [[maybe_unused]] Vec2 s, [[maybe_unused]] Palette pa) const {} - void draw([[maybe_unused]] Vec2 p, [[maybe_unused]] Palette pa) const {} - void draw([[maybe_unused]] Point p, [[maybe_unused]] Palette pa) const {} - void draw([[maybe_unused]] Vec2 p, [[maybe_unused]] double a, [[maybe_unused]] double b, [[maybe_unused]] ColorF c) const {} - void setBufferThickness([[maybe_unused]] int n) {} - Font operator ()([[maybe_unused]] String s1, [[maybe_unused]] std::size_t n1, - [[maybe_unused]] String s2, [[maybe_unused]] std::size_t n2, - [[maybe_unused]] String s3, [[maybe_unused]] std::size_t n3) const { - return Font(); - } - }; - - class Mouse - { - public: - static Vec2 Pos() { return Vec2(); } - }; - - class Texture - { - public: - [[maybe_unused]] String path; - Texture() {} - Texture([[maybe_unused]] const String& path_) {} - Texture resized([[maybe_unused]] const int w, [[maybe_unused]] const int h) const { return Texture(); } - Texture resized([[maybe_unused]] const double s) const { return Texture(); } - void draw([[maybe_unused]] Vec2 p) const {} - void draw([[maybe_unused]] int n, [[maybe_unused]] double d) const {} - void drawAt([[maybe_unused]] Vec2 p) const {} - void drawAt([[maybe_unused]] double x, [[maybe_unused]] double y) const {} - int width() const { return 0; } - int height() const { return 0; } - bool operator !() const { return true; } - operator bool() const { return true; } - }; - - using URL = String; - - struct Triangle - { - [[maybe_unused]] double p1; - [[maybe_unused]] double p2; - [[maybe_unused]] double p3; - [[maybe_unused]] double p4; - void draw([[maybe_unused]] Palette p) const {} - }; - - struct Ellipse - { - Vec2 center; - int a; - int b; - Ellipse() : center(), a(0), b(0) {} - Ellipse(Vec2 _center, int _a, int _b) : center(_center), a(_a), b(_b) {} - }; - - class Sound - { - public: - Sound() {} - Sound([[maybe_unused]] const std::string& path) {} - bool play() { return true; } - bool stop() { return true; } - bool isPlaying() { return false; } - }; - - class Unicode - { - public: - static String FromUTF8([[maybe_unused]] const std::string& utf8) { return String(); } - }; - - enum class TextureFormat - { - R8G8B8A8_Unorm_SRGB - }; - - enum class HasDepth - { - Yes - }; - - class Quaternion - { - public: - double x, y, z, w; - static Quaternion RotateX([[maybe_unused]] double angle) { return Quaternion(); } - static Quaternion RotateY([[maybe_unused]] double angle) { return Quaternion(); } - Quaternion operator *([[maybe_unused]] const Quaternion& q) const { return Quaternion(); } - }; - - class Sphere - { - public: - double x, y, z, r; - void draw([[maybe_unused]] Quaternion q, [[maybe_unused]] Texture t) {} - }; - - class MSRenderTexture - { - public: - Size size{}; - TextureFormat format{}; - HasDepth hasDepth{}; - - MSRenderTexture clear([[maybe_unused]] const ColorF& color) const { return MSRenderTexture(); } - void resolve() {} - void draw([[maybe_unused]] double x, [[maybe_unused]] double y) {} - }; - - class ScopedRenderTarget3D - { - public: - MSRenderTexture texture; - }; - - enum class RasterizerState - { - SolidCullNone - }; - - class ScopedRenderStates3D - { - public: - RasterizerState rasterizerState; - }; - - enum class SamplerState - { - ClampNearest - , ClampLinear - }; - - class RenderTexture - { - public: - RenderTexture() {} - RenderTexture(int) {} - RenderTexture(const Size&, ColorF) {} - int size() const { return 0; } - RenderTexture clear(ColorF) { return RenderTexture(); } - void draw(ColorF) {} - }; - - class ScopedRenderStates2D - { - public: - SamplerState samplerState{}; - ScopedRenderStates2D() {} - ScopedRenderStates2D(SamplerState) {} - ScopedRenderStates2D(BlendState) {} - }; - - class ScopedRenderTarget2D - { - public: - ScopedRenderTarget2D() {} - ScopedRenderTarget2D(RenderTexture) {} - }; - - class TextStyle - { - public: - static Vec2 Outline([[maybe_unused]] int n, [[maybe_unused]] double d, [[maybe_unused]] Palette p) { return Vec2(); } - static Vec2 Outline([[maybe_unused]] int n, [[maybe_unused]] double d, [[maybe_unused]] ColorF p) { return Vec2(); } - }; - - class SimpleHTTP - { - public: - static SimpleHTTP Save(URL /*url*/, Texture /*texture*/) { return SimpleHTTP(); } - bool isOK() { return true; } - }; - - template - class Array - { - public: - Type& operator []([[maybe_unused]] int n) { return dummyData; } // non-const version - const Type& operator []([[maybe_unused]] int n) const { return dummyData; } - int size() const { return 0; } - template - void emplace_back([[maybe_unused]] Args&&... args) {} - private: - Type dummyData; - - }; - - class Mat3x2 - { - public: - static Mat3x2 Translate(int, int) { return Mat3x2(); } - }; - - class Transformer2D - { - public: - Transformer2D() {} - Transformer2D(const Mat3x2&) {} - }; - - class RoundRect : public Rect - { - public: - RoundRect() {} - RoundRect(int, int, int, int, int) {} - void draw(ColorF) {} - void draw() {} - }; - - class Shader - { - public: - static void GaussianBlur(RenderTexture, RenderTexture, RenderTexture) {} - }; - - class SimpleGUI - { - public: - static bool Button(String, Vec2) { return false; } - }; - - namespace detail - { - class Console_impl - { - public: - void open() {} - }; - } - - class Spline2D - { - public: - Spline2D() {} - Spline2D(const Array&) {} - void draw(int, Color) {} - }; -} - -#endif // !PAX_GRAPHICA_MOCK_HPP diff --git a/Library/PAX_GRAPHICA/implementations/NullRenderTextureImpl.hpp b/Library/PAX_GRAPHICA/Null/NullRenderTextureImpl.hpp similarity index 96% rename from Library/PAX_GRAPHICA/implementations/NullRenderTextureImpl.hpp rename to Library/PAX_GRAPHICA/Null/NullRenderTextureImpl.hpp index fecf55761..16695b36f 100644 --- a/Library/PAX_GRAPHICA/implementations/NullRenderTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Null/NullRenderTextureImpl.hpp @@ -12,7 +12,7 @@ #ifndef PAX_GRAPHICA_NULL_RENDER_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_NULL_RENDER_TEXTURE_IMPL_HPP -#include +#include namespace paxg { diff --git a/Library/PAX_GRAPHICA/implementations/NullTextureImpl.hpp b/Library/PAX_GRAPHICA/Null/NullTextureImpl.hpp similarity index 57% rename from Library/PAX_GRAPHICA/implementations/NullTextureImpl.hpp rename to Library/PAX_GRAPHICA/Null/NullTextureImpl.hpp index 9d4439e44..00e6ff083 100644 --- a/Library/PAX_GRAPHICA/implementations/NullTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Null/NullTextureImpl.hpp @@ -13,7 +13,7 @@ #define PAX_GRAPHICA_NULL_TEXTURE_IMPL_HPP #include -#include +#include namespace paxg { @@ -30,18 +30,19 @@ namespace paxg { int height() const override { return 0; } void draw() const override {} - void drawAt(const Vec2f&) const override {} - void drawAt(const Vec2i&) const override {} - - void resizedDrawAt(const Vec2i&, const Vec2i&) const override {} - void resizedDrawAt(int, const Vec2i&) const override {} - void resizedDrawAt(const Vec2f&, const Vec2f&) const override {} - void resizedDrawAt(int, const Vec2f&) const override {} - - void resizedDraw(const Vec2i&, const Vec2i&) const override {} - void resizedDraw(int, const Vec2i&) const override {} - void resizedDraw(const Vec2f&, const Vec2f&) const override {} - void resizedDraw(int, const Vec2f&) const override {} + + void drawAt(const paxs::Vector2&) const override {} + void drawAt(const paxs::Vector2&) const override {} + + void resizedDraw(const paxs::Vector2&, const paxs::Vector2&) const override {} + void resizedDraw(int, const paxs::Vector2&) const override {} + void resizedDraw(const paxs::Vector2&, const paxs::Vector2&) const override {} + void resizedDraw(int, const paxs::Vector2&) const override {} + + void resizedDrawAt(const paxs::Vector2&, const paxs::Vector2&) const override {} + void resizedDrawAt(int, const paxs::Vector2&) const override {} + void resizedDrawAt(const paxs::Vector2&, const paxs::Vector2&) const override {} + void resizedDrawAt(int, const paxs::Vector2&) const override {} }; } // namespace paxg diff --git a/Library/PAX_GRAPHICA/implementations/NullWindowImpl.hpp b/Library/PAX_GRAPHICA/Null/NullWindowImpl.hpp similarity index 76% rename from Library/PAX_GRAPHICA/implementations/NullWindowImpl.hpp rename to Library/PAX_GRAPHICA/Null/NullWindowImpl.hpp index 14f2d41f0..529d2743f 100644 --- a/Library/PAX_GRAPHICA/implementations/NullWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Null/NullWindowImpl.hpp @@ -12,7 +12,7 @@ #ifndef PAX_GRAPHICA_NULL_WINDOW_IMPL_HPP #define PAX_GRAPHICA_NULL_WINDOW_IMPL_HPP -#include +#include namespace paxg { @@ -24,28 +24,24 @@ namespace paxg { void setTitle(const std::string&) override {} void setSize(int, int) override {} - void setPosition(int, int) override {} - void setPosition(const Vec2i&) override {} + void setPosition(const paxs::Vector2&) override {} void setIcon(const std::string&) override {} void setVisible(bool) override {} void setVSync(bool) override {} void setFPS(int) override {} void setMouseCursorVisible(bool) override {} - void setMouseCursorGrabbed(bool) override {} void setMouseCursor(const std::string&) override {} - void setMousePosition(int, int) override {} - void setMousePosition(const Vec2i&) override {} - void setKeyRepeat(bool) override {} + void setMousePosition(const paxs::Vector2&) override {} void setBackgroundColor(const Color) override {} void setLetterbox(const Color) override {} void setResizable(bool) override {} void setDecorated(bool) override {} - Vec2i center() const override { return Vec2i{}; } + paxs::Vector2 center() const override { return {0, 0}; } int width() const override { return 1; } int height() const override { return 1; } - Vec2i size() const override { return Vec2i{}; } - Vec2i getMousePosition() const override { return Vec2i(0, 0); } + paxs::Vector2 size() const override { return {0, 0}; } + paxs::Vector2 getMousePosition() const override { return {0, 0}; } bool hasFocus() const override { return false; } void clear() override {} diff --git a/Library/PAX_GRAPHICA/Rect.hpp b/Library/PAX_GRAPHICA/Rect.hpp index f551394fa..3975a7cfc 100644 --- a/Library/PAX_GRAPHICA/Rect.hpp +++ b/Library/PAX_GRAPHICA/Rect.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -36,9 +35,9 @@ namespace paxg { s3d::RectF rect{}; constexpr Rect() = default; constexpr Rect(const float x, const float y, const float w, const float h) : rect(x, y, w, h) {} - constexpr Rect(const Vec2i& pos, const Vec2i& size) : rect(pos.x(), pos.y(), size.x(), size.y()) {} - constexpr Rect(const Vec2i& pos, const float w, const float h) : rect(pos.x(), pos.y(), w, h) {} - constexpr Rect(const float x, const float y, const Vec2i& size) : rect(x, y, size.x(), size.y()) {} + constexpr Rect(const paxs::Vector2& pos, const paxs::Vector2& size) : rect(pos.x, pos.y, size.x, size.y) {} + constexpr Rect(const paxs::Vector2& pos, const float w, const float h) : rect(pos.x, pos.y, w, h) {} + constexpr Rect(const float x, const float y, const paxs::Vector2& size) : rect(x, y, size.x, size.y) {} constexpr Rect(const paxs::Rect& r) : rect(static_cast(r.x()), static_cast(r.y()), static_cast(r.width()), static_cast(r.height())) {} constexpr operator s3d::RectF() const { return rect; } void setX(const float x_) { rect.x = x_; } @@ -49,8 +48,8 @@ namespace paxg { float y() const { return static_cast(rect.y); } float w() const { return static_cast(rect.w); } float h() const { return static_cast(rect.h); } - Vec2i pos() const { return Vec2i(static_cast(rect.x), static_cast(rect.y)); } - Vec2i size() const { return Vec2i(static_cast(rect.w), static_cast(rect.h)); } + paxs::Vector2 pos() const { return { static_cast(rect.x), static_cast(rect.y) }; } + paxs::Vector2 size() const { return { static_cast(rect.w), static_cast(rect.h) }; } void setPos(const float x_, const float y_) { rect.x = x_; rect.y = y_; @@ -79,9 +78,9 @@ namespace paxg { sf::RectangleShape rect{}; constexpr Rect() = default; Rect(const float x, const float y, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition({ x, y }); } - Rect(const sf::Vector2i& pos, const sf::Vector2i& size) : rect(sf::Vector2f(static_cast(size.x), static_cast(size.y))) { rect.setPosition({ static_cast(pos.x), static_cast(pos.y) }); } - Rect(const sf::Vector2i& pos, const float w, const float h) : rect(sf::Vector2f(w, h)) { rect.setPosition({ static_cast(pos.x), static_cast(pos.y) }); } - Rect(const float x, const float y, const sf::Vector2i& size) : rect(sf::Vector2f(static_cast(size.x), static_cast(size.y))) { rect.setPosition({ x, y }); } + Rect(const paxs::Vector2& pos, const paxs::Vector2& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition({pos.x, pos.y }); } + Rect(const paxs::Vector2& 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 paxs::Vector2& size) : rect(sf::Vector2f(size.x, size.y)) { rect.setPosition({ x, y }); } Rect(const paxs::Rect& r) : rect(sf::Vector2f(static_cast(r.width()), static_cast(r.height()))) { rect.setPosition({ static_cast(r.x()), static_cast(r.y()) }); } operator sf::RectangleShape() const { return rect; } void setX(const float x_) { rect.setPosition({ x_, rect.getPosition().y }); } @@ -92,8 +91,8 @@ namespace paxg { 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(rect.getPosition().x), static_cast(rect.getPosition().y)); } - Vec2i size() const { return Vec2i(static_cast(rect.getSize().x), static_cast(rect.getSize().y)); } + paxs::Vector2 pos() const { return paxs::Vector2(rect.getPosition().x, rect.getPosition().y); } + paxs::Vector2 size() const { return paxs::Vector2(rect.getSize().x, 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({ static_cast(pos_.x()), static_cast(pos_.y()) }); } @@ -106,48 +105,47 @@ namespace paxg { return contains(static_cast(pos.x), static_cast(pos.y)); } #else - float x0{}, y0{}, w0{}, h0{}; + paxs::Vector2 pos_{0.0f, 0.0f}; + paxs::Vector2 size_{0.0f, 0.0f}; constexpr Rect() = default; constexpr Rect(const float x, const float y, const float w, const float h) : - x0(x), y0(y), w0(w), h0(h) {} - constexpr Rect(const Vec2i& pos, const Vec2i& size) - : x0(static_cast(pos.x())), y0(static_cast(pos.y())), - w0(static_cast(size.x())), h0(static_cast(size.y())) {} - constexpr Rect(const Vec2i& pos, const float w, const float h) : - x0(static_cast(pos.x())), y0(static_cast(pos.y())), w0(w), h0(h) {} - constexpr Rect(const float x, const float y, const Vec2i& size) - : x0(x), y0(y), w0(static_cast(size.x())), h0(static_cast(size.y())) {} - constexpr Rect(const paxs::Rect& r) : - x0(static_cast(r.x())), y0(static_cast(r.y())), w0(static_cast(r.width())), h0(static_cast(r.height())) {} - void setX(const float x_) { x0 = x_; } - void setY(const float y_) { y0 = y_; } - void setW(const float w_) { w0 = w_; } - void setH(const float h_) { h0 = h_; } - float x() const { return x0; } - float y() const { return y0; } - float w() const { return w0; } - float h() const { return h0; } - Vec2i pos() const { return Vec2i(static_cast(x0), static_cast(y0)); } - Vec2i size() const { return Vec2i(static_cast(w0), static_cast(h0)); } + pos_{x, y}, size_{w, h} {} + constexpr Rect(const paxs::Vector2& pos, const paxs::Vector2& size) + : pos_{pos}, size_{size} {} + constexpr Rect(const paxs::Vector2& pos, const float w, const float h) : + pos_{pos}, size_{w, h} {} + constexpr Rect(const float x, const float y, const paxs::Vector2& size) + : pos_{x, y}, size_{size} {} + constexpr Rect(const paxs::Rect& r) + : pos_{ static_cast(r.x()), static_cast(r.y()) }, + size_{ static_cast(r.width()), static_cast(r.height()) } {} + void setX(const float x_) { pos_.x = x_; } + void setY(const float y_) { pos_.y = y_; } + void setW(const float w_) { size_.x = w_; } + void setH(const float h_) { size_.y = h_; } + float x() const { return pos_.x; } + float y() const { return pos_.y; } + float w() const { return size_.x; } + float h() const { return size_.y; } + paxs::Vector2 pos() const { return pos_; } + paxs::Vector2 size() const { return size_; } void setPos(const float x_, const float y_) { - x0 = x_; - y0 = y_; + pos_.x = x_; + pos_.y = y_; } void setSize(const float w_, const float h_) { - w0 = w_; - h0 = h_; + size_.x = w_; + size_.y = h_; } - void setPos(const Vec2i& pos_) { - x0 = static_cast(pos_.x()); - y0 = static_cast(pos_.y()); + void setPos(const paxs::Vector2& pos) { + pos_ = paxs::Vector2{ pos }; } - void setSize(const Vec2i& size_) { - w0 = static_cast(size_.x()); - h0 = static_cast(size_.y()); + void setSize(const paxs::Vector2& size) { + size_ = paxs::Vector2{ size }; } bool contains(const float x_, const float y_) const { - return x0 <= x_ && x_ <= x0 + w0 && - y0 <= y_ && y_ <= y0 + h0; + return (pos_.x <= x_) && (x_ <= (pos_.x + size_.x)) && + (pos_.y <= y_) && (y_ <= (pos_.y + size_.y)); } bool contains(const paxs::Vector2& pos) const { return contains(static_cast(pos.x), static_cast(pos.y)); @@ -160,7 +158,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) DxLib::DrawBox( - static_cast(x0), static_cast(y0), static_cast(x0 + w0), static_cast(y0 + h0), + static_cast(pos_.x), static_cast(pos_.y), static_cast(pos_.x + size_.x), static_cast(pos_.y + size_.y), DxLib::GetColor(255, 255, 255), TRUE); #elif defined(PAXS_USING_SFML) @@ -176,7 +174,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) void draw(const paxg::Color& c_) const { DxLib::DrawBox( - static_cast(x0), static_cast(y0), static_cast(x0 + w0), static_cast(y0 + h0), + static_cast(pos_.x), static_cast(pos_.y), static_cast(pos_.x + size_.x), static_cast(pos_.y + size_.y), DxLib::GetColor(c_.r, c_.g, c_.b), TRUE); } #elif defined(PAXS_USING_SFML) @@ -234,10 +232,10 @@ namespace paxg { DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha); DxLib::DrawBox( - static_cast(x0 + offset.x() + i), - static_cast(y0 + offset.y() + i), - static_cast(x0 + w0 + i), - static_cast(y0 + h0 + i), + static_cast(pos_.x + offset.x() + i), + static_cast(pos_.y + offset.y() + i), + static_cast(pos_.x + size_.x + i), + static_cast(pos_.y + size_.y + i), DxLib::GetColor(0, 0, 0), TRUE ); @@ -258,7 +256,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) DxLib::DrawBox( - static_cast(x0 - w0 / 2), static_cast(y0 - h0 / 2), static_cast(x0 + w0 / 2), static_cast(y0 + h0 / 2), + static_cast(pos_.x - size_.x / 2), static_cast(pos_.y - size_.y / 2), static_cast(pos_.x + size_.x / 2), static_cast(pos_.y + size_.y / 2), DxLib::GetColor(255, 255, 255), TRUE); #elif defined(PAXS_USING_SFML) @@ -274,7 +272,7 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) void drawAt(const paxg::Color& c_) const { DxLib::DrawBox( - static_cast(x0 - w0 / 2), static_cast(y0 - h0 / 2), static_cast(x0 + w0 / 2), static_cast(y0 + h0 / 2), + static_cast(pos_.x - size_.x / 2), static_cast(pos_.y - size_.y / 2), static_cast(pos_.x + size_.x / 2), static_cast(pos_.y + size_.y / 2), DxLib::GetColor(c_.r, c_.g, c_.b), TRUE); } #elif defined(PAXS_USING_SFML) @@ -295,20 +293,20 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) void drawFrame(const double inner_thickness, const double outer_thickness, const paxg::Color& color_) const { DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + inner_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + inner_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 + h0 - inner_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y + size_.y - inner_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 - outer_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + inner_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x - outer_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + inner_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); DxLib::DrawBox( - static_cast(x0 + w0 - inner_thickness), static_cast(y0 - outer_thickness), - static_cast(x0 + w0 + outer_thickness), static_cast(y0 + h0 + outer_thickness), + static_cast(pos_.x + size_.x - inner_thickness), static_cast(pos_.y - outer_thickness), + static_cast(pos_.x + size_.x + outer_thickness), static_cast(pos_.y + size_.y + outer_thickness), DxLib::GetColor(color_.r, color_.g, color_.b), TRUE); } @@ -351,7 +349,8 @@ namespace paxg { #elif defined(PAXS_USING_DXLIB) int mx = 0, my = 0; DxLib::GetMousePoint(&mx, &my); - return (mx >= x0 && my >= y0 && mx < x0 + w0 && my < y0 + h0); + return (mx >= pos_.x && my >= pos_.y && + mx < pos_.x + size_.x && my < pos_.y + size_.y); #elif defined(PAXS_USING_SFML) return rect.getGlobalBounds().contains( diff --git a/Library/PAX_GRAPHICA/RenderTexture.hpp b/Library/PAX_GRAPHICA/RenderTexture.hpp index 44573892d..d4d5cdf82 100644 --- a/Library/PAX_GRAPHICA/RenderTexture.hpp +++ b/Library/PAX_GRAPHICA/RenderTexture.hpp @@ -15,11 +15,12 @@ #include #include -#include -#include +#include #if defined(PAXS_USING_SIV3D) -#include +#include +#else +#include #endif namespace paxg { @@ -31,6 +32,15 @@ namespace paxg { private: std::shared_ptr impl; + template + void createImpl(Args&&... args) { +#if defined(PAXS_USING_SIV3D) + impl = std::make_shared(std::forward(args)...); +#else + impl = std::make_shared(std::forward(args)...); +#endif + } + public: /// @brief Default constructor (creates empty render texture without implementation) /// @brief デフォルトコンストラクタ(実装を持たない空の状態で初期化、遅延初期化用) @@ -43,21 +53,13 @@ namespace paxg { /// @param size Size as Vector2 /// @param color Color as ColorF RenderTexture(const paxs::Vector2& size, const ColorF& color) { -#if defined(PAXS_USING_SIV3D) - impl = std::make_shared(size.x, size.y, color.r, color.g, color.b, color.a); -#else - impl = std::make_shared(size.x, size.y, color.r, color.g, color.b, color.a); -#endif + createImpl(size.x, size.y, color.r, color.g, color.b, color.a); } /// @brief Constructor with size only /// @param size Size as Vector2 explicit RenderTexture(const paxs::Vector2& size) { -#if defined(PAXS_USING_SIV3D) - impl = std::make_shared(size.x, size.y); -#else - impl = std::make_shared(size.x, size.y); -#endif + createImpl(size.x, size.y); } /// @brief Get the size of the render texture diff --git a/Library/PAX_GRAPHICA/implementations/SFMLTextureImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp similarity index 61% rename from Library/PAX_GRAPHICA/implementations/SFMLTextureImpl.hpp rename to Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp index 8be12f84f..7677a8c05 100644 --- a/Library/PAX_GRAPHICA/implementations/SFMLTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLTextureImpl.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -75,29 +75,28 @@ namespace paxg { paxg::Window::window().draw(sprite); } - void drawAt(const Vec2f& pos) const override { + void drawAt(const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setPosition({ pos.x() - (width() / 2.0f), pos.y() - (height() / 2.0f) }); + sprite.setPosition({ static_cast(pos.x - (width() / 2)), + static_cast(pos.y - (height() / 2)) }); paxg::Window::window().draw(sprite); } - void drawAt(const Vec2i& pos) const override { + void drawAt(const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setPosition({ static_cast(pos.x() - (width() / 2)), - static_cast(pos.y() - (height() / 2)) }); + sprite.setPosition({ pos.x - (width() / 2.0f), pos.y - (height() / 2.0f) }); paxg::Window::window().draw(sprite); } - void resizedDrawAt(const Vec2i& resize, const Vec2i& pos) const override { + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setScale({ static_cast(resize.x()) / texture.getSize().x, - static_cast(resize.y()) / texture.getSize().y }); - sprite.setPosition({ static_cast(pos.x() - (resize.x() / 2)), - static_cast(pos.y() - (resize.y() / 2)) }); + sprite.setScale({ static_cast(resize.x) / texture.getSize().x, + static_cast(resize.y) / texture.getSize().y }); + sprite.setPosition({ static_cast(pos.x), static_cast(pos.y) }); paxg::Window::window().draw(sprite); } - void resizedDrawAt(int resize, const Vec2i& pos) const override { + void resizedDraw(int resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 @@ -106,23 +105,18 @@ namespace paxg { float scale = std::min(scale_x, scale_y); sprite.setScale({ scale, scale }); - // スケーリング後の実際の幅と高さでセンタリングする - float new_width = static_cast(width()) * scale; - float new_height = static_cast(height()) * scale; - - sprite.setPosition({ static_cast(pos.x()) - (new_width / 2.0f), - static_cast(pos.y()) - (new_height / 2.0f) }); + sprite.setPosition({ static_cast(pos.x), static_cast(pos.y) }); paxg::Window::window().draw(sprite); } - void resizedDrawAt(const Vec2f& resize, const Vec2f& pos) const override { + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setScale({ resize.x() / texture.getSize().x, resize.y() / texture.getSize().y }); - sprite.setPosition({ pos.x() - (resize.x() / 2), pos.y() - (resize.y() / 2) }); + sprite.setScale({ resize.x / texture.getSize().x, resize.y / texture.getSize().y }); + sprite.setPosition({ pos.x, pos.y }); paxg::Window::window().draw(sprite); } - void resizedDrawAt(int resize, const Vec2f& pos) const override { + void resizedDraw(int resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 @@ -131,44 +125,31 @@ namespace paxg { float scale = std::min(scale_x, scale_y); sprite.setScale({ scale, scale }); - // スケーリング後の実際の幅と高さでセンタリングする - float new_width = static_cast(width()) * scale; - float new_height = static_cast(height()) * scale; - - sprite.setPosition({ pos.x() - (new_width / 2.0f), - pos.y() - (new_height / 2.0f) }); + sprite.setPosition({ pos.x, pos.y }); paxg::Window::window().draw(sprite); } - void resizedDraw(const Vec2i& resize, const Vec2i& pos) const override { + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setScale({ static_cast(resize.x()) / texture.getSize().x, - static_cast(resize.y()) / texture.getSize().y }); - sprite.setPosition({ static_cast(pos.x()), static_cast(pos.y()) }); + sprite.setScale({ static_cast(resize.x) / texture.getSize().x, + static_cast(resize.y) / texture.getSize().y }); + sprite.setPosition({ static_cast(pos.x - (resize.x / 2)), + static_cast(pos.y - (resize.y / 2)) }); paxg::Window::window().draw(sprite); } - void resizedDraw(int resize, const Vec2i& pos) const override { - sf::Sprite sprite(texture); - - // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 - float scale_x = static_cast(resize) / texture.getSize().x; - float scale_y = static_cast(resize) / texture.getSize().y; - float scale = std::min(scale_x, scale_y); - sprite.setScale({ scale, scale }); - - sprite.setPosition({ static_cast(pos.x()), static_cast(pos.y()) }); - paxg::Window::window().draw(sprite); + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { + resizedDrawAt(resize, paxs::Vector2(pos)); } - void resizedDraw(const Vec2f& resize, const Vec2f& pos) const override { + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); - sprite.setScale({ resize.x() / texture.getSize().x, resize.y() / texture.getSize().y }); - sprite.setPosition({ pos.x(), pos.y() }); + sprite.setScale({ resize.x / texture.getSize().x, resize.y / texture.getSize().y }); + sprite.setPosition({ pos.x - (resize.x / 2), pos.y - (resize.y / 2) }); paxg::Window::window().draw(sprite); } - void resizedDraw(int resize, const Vec2f& pos) const override { + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { sf::Sprite sprite(texture); // アスペクト比を維持して 'resize x resize' に収めるスケールを計算 @@ -177,7 +158,12 @@ namespace paxg { float scale = std::min(scale_x, scale_y); sprite.setScale({ scale, scale }); - sprite.setPosition({ pos.x(), pos.y() }); + // スケーリング後の実際の幅と高さでセンタリングする + float new_width = static_cast(width()) * scale; + float new_height = static_cast(height()) * scale; + + sprite.setPosition({ pos.x - (new_width / 2.0f), + pos.y - (new_height / 2.0f) }); paxg::Window::window().draw(sprite); } diff --git a/Library/PAX_GRAPHICA/implementations/SFMLWindowImpl.hpp b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp similarity index 83% rename from Library/PAX_GRAPHICA/implementations/SFMLWindowImpl.hpp rename to Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp index bd38a8119..0f40fd5e3 100644 --- a/Library/PAX_GRAPHICA/implementations/SFMLWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/SFML/SFMLWindowImpl.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -28,7 +28,6 @@ namespace paxg { private: sf::RenderWindow m_window; paxg::Color backgroundColor{145, 190, 240}; - bool m_isDecorated = true; std::string m_title = "PAX SAPIENTICA Library"; int m_width = paxs::AppConst::default_window_size.x; int m_height = paxs::AppConst::default_window_size.y; @@ -85,12 +84,8 @@ namespace paxg { m_window.setSize(sf::Vector2u(width, height)); } - void setPosition(int x, int y) override { - m_window.setPosition(sf::Vector2i(x, y)); - } - - void setPosition(const Vec2i& pos) override { - m_window.setPosition(sf::Vector2i(pos.x(), pos.y())); + void setPosition(const paxs::Vector2& pos) override { + m_window.setPosition(sf::Vector2i(pos.x, pos.y)); } void setIcon(const std::string& path) override { @@ -118,10 +113,6 @@ namespace paxg { m_window.setMouseCursorVisible(visible); } - void setMouseCursorGrabbed(bool grabbed) override { - m_window.setMouseCursorGrabbed(grabbed); - } - void setMouseCursor(const std::string& path) override { sf::Image image; if (!image.loadFromFile(path)) @@ -131,16 +122,8 @@ namespace paxg { m_window.setMouseCursor(cursor); } - void setMousePosition(int x, int y) override { - sf::Mouse::setPosition(sf::Vector2i(x, y), m_window); - } - - void setMousePosition(const Vec2i& pos) override { - sf::Mouse::setPosition(sf::Vector2i(pos.x(), pos.y()), m_window); - } - - void setKeyRepeat(bool repeat) override { - m_window.setKeyRepeatEnabled(repeat); + void setMousePosition(const paxs::Vector2& pos) override { + sf::Mouse::setPosition(sf::Vector2i(pos.x, pos.y), m_window); } void setBackgroundColor(const Color color) override { @@ -169,8 +152,8 @@ namespace paxg { // the desired style from the beginning (in constructor or init()) } - paxg::Vec2i center() const override { - return paxg::Vec2i{static_cast(m_window.getSize().x / 2), static_cast(m_window.getSize().y / 2)}; + paxs::Vector2 center() const override { + return paxs::Vector2{static_cast(m_window.getSize().x / 2), static_cast(m_window.getSize().y / 2)}; } int width() const override { @@ -181,13 +164,13 @@ namespace paxg { return static_cast(m_window.getSize().y); } - paxg::Vec2i size() const override { - return paxg::Vec2i{static_cast(m_window.getSize().x), static_cast(m_window.getSize().y)}; + paxs::Vector2 size() const override { + return paxs::Vector2{static_cast(m_window.getSize().x), static_cast(m_window.getSize().y)}; } - paxg::Vec2i getMousePosition() const override { + paxs::Vector2 getMousePosition() const override { auto pos = sf::Mouse::getPosition(m_window); - return paxg::Vec2i{pos.x, pos.y}; + return paxs::Vector2{pos.x, pos.y}; } bool hasFocus() const override { @@ -215,6 +198,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_SFML) +#endif // PAXS_USING_SFML #endif // !PAX_GRAPHICA_SFML_WINDOW_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/implementations/Siv3DRenderTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp similarity index 98% rename from Library/PAX_GRAPHICA/implementations/Siv3DRenderTextureImpl.hpp rename to Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp index 597198c7e..ffdfb7cf6 100644 --- a/Library/PAX_GRAPHICA/implementations/Siv3DRenderTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImpl.hpp @@ -12,7 +12,7 @@ #ifndef PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP #define PAX_GRAPHICA_SIV3D_RENDER_TEXTURE_IMPL_HPP -#include +#include #if defined(PAXS_USING_SIV3D) #include diff --git a/Library/PAX_GRAPHICA/implementations/Siv3DTextureImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp similarity index 54% rename from Library/PAX_GRAPHICA/implementations/Siv3DTextureImpl.hpp rename to Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp index e74987501..64299353e 100644 --- a/Library/PAX_GRAPHICA/implementations/Siv3DTextureImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DTextureImpl.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include namespace paxg { @@ -52,44 +52,44 @@ namespace paxg { texture.draw(); } - void drawAt(const paxg::Vec2f& pos) const override { - texture.drawAt(pos.x(), pos.y()); + void drawAt(const paxs::Vector2& pos) const override { + texture.drawAt(pos.x, pos.y); } - void drawAt(const paxg::Vec2i& pos) const override { - texture.drawAt(pos.x(), pos.y()); + void drawAt(const paxs::Vector2& pos) const override { + texture.drawAt(pos.x, pos.y); } - void resizedDrawAt(const paxg::Vec2i& resize, const paxg::Vec2i& pos) const override { - texture.resized(resize.x(), resize.y()).drawAt(pos.x(), pos.y()); + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { + texture.resized(resize.x, resize.y).draw(pos.x, pos.y); } - void resizedDrawAt(int resize, const paxg::Vec2i& pos) const override { - texture.resized(resize).drawAt(pos.x(), pos.y()); + void resizedDraw(int resize, const paxs::Vector2& pos) const override { + texture.resized(resize).draw(pos.x, pos.y); } - void resizedDrawAt(const paxg::Vec2f& resize, const paxg::Vec2f& pos) const override { - texture.resized(resize.x(), resize.y()).drawAt(pos.x(), pos.y()); + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { + texture.resized(resize.x, resize.y).draw(pos.x, pos.y); } - void resizedDrawAt(int resize, const paxg::Vec2f& pos) const override { - texture.resized(resize).drawAt(pos.x(), pos.y()); + void resizedDraw(int resize, const paxs::Vector2& pos) const override { + texture.resized(resize).draw(pos.x, pos.y); } - void resizedDraw(const paxg::Vec2i& resize, const paxg::Vec2i& pos) const override { - texture.resized(resize.x(), resize.y()).draw(pos.x(), pos.y()); + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { + texture.resized(resize.x, resize.y).drawAt(pos.x, pos.y); } - void resizedDraw(int resize, const paxg::Vec2i& pos) const override { - texture.resized(resize).draw(pos.x(), pos.y()); + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { + texture.resized(resize).drawAt(pos.x, pos.y); } - void resizedDraw(const paxg::Vec2f& resize, const paxg::Vec2f& pos) const override { - texture.resized(resize.x(), resize.y()).draw(pos.x(), pos.y()); + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const override { + texture.resized(resize.x, resize.y).drawAt(pos.x, pos.y); } - void resizedDraw(int resize, const paxg::Vec2f& pos) const override { - texture.resized(resize).draw(pos.x(), pos.y()); + void resizedDrawAt(int resize, const paxs::Vector2& pos) const override { + texture.resized(resize).drawAt(pos.x, pos.y); } const s3d::Texture& getNativeTexture() const { return texture; } diff --git a/Library/PAX_GRAPHICA/implementations/Siv3DWindowImpl.hpp b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp similarity index 74% rename from Library/PAX_GRAPHICA/implementations/Siv3DWindowImpl.hpp rename to Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp index 6465b1b9a..45cf63ab0 100644 --- a/Library/PAX_GRAPHICA/implementations/Siv3DWindowImpl.hpp +++ b/Library/PAX_GRAPHICA/Siv3D/Siv3DWindowImpl.hpp @@ -16,7 +16,7 @@ #include -#include +#include namespace paxg { @@ -39,12 +39,8 @@ namespace paxg { s3d::Window::Resize(width, height); } - void setPosition(int x, int y) override { - s3d::Window::SetPos(x, y); - } - - void setPosition(const Vec2i& pos) override { - s3d::Window::SetPos(static_cast(pos.x()), static_cast(pos.y())); + void setPosition(const paxs::Vector2& pos) override { + s3d::Window::SetPos(static_cast(pos.x), static_cast(pos.y)); } void setIcon(const std::string& /*path*/) override { @@ -68,24 +64,12 @@ namespace paxg { // Siv3D does not support mouse cursor visibility control } - void setMouseCursorGrabbed(bool) override { - // Siv3D does not support mouse cursor grabbing - } - void setMouseCursor(const std::string& path) override { s3d::Cursor::RequestStyle(s3d::Unicode::FromUTF8(path)); } - void setMousePosition(int x, int y) override { - s3d::Cursor::SetPos(x, y); - } - - void setMousePosition(const Vec2i& pos) override { - s3d::Cursor::SetPos(static_cast(pos.x()), static_cast(pos.y())); - } - - void setKeyRepeat(bool) override { - // Siv3D does not support key repeat control + void setMousePosition(const paxs::Vector2& pos) override { + s3d::Cursor::SetPos(static_cast(pos.x), static_cast(pos.y)); } void setBackgroundColor(const Color color) override { @@ -112,8 +96,8 @@ namespace paxg { } } - Vec2i center() const override { - return Vec2i(s3d::Scene::Center().x, s3d::Scene::Center().y); + paxs::Vector2 center() const override { + return paxs::Vector2(s3d::Scene::Center().x, s3d::Scene::Center().y); } int width() const override { @@ -124,12 +108,12 @@ namespace paxg { return s3d::Scene::Height(); } - Vec2i size() const override { - return Vec2i(s3d::Scene::Width(), s3d::Scene::Height()); + paxs::Vector2 size() const override { + return paxs::Vector2(s3d::Scene::Width(), s3d::Scene::Height()); } - Vec2i getMousePosition() const override { - return Vec2i(static_cast(s3d::Cursor::PosF().x), + paxs::Vector2 getMousePosition() const override { + return paxs::Vector2(static_cast(s3d::Cursor::PosF().x), static_cast(s3d::Cursor::PosF().y)); } @@ -152,6 +136,6 @@ namespace paxg { } // namespace paxg -#endif // defined(PAXS_USING_SIV3D) +#endif // PAXS_USING_SIV3D #endif // !PAX_GRAPHICA_SIV3D_WINDOW_IMPL_HPP diff --git a/Library/PAX_GRAPHICA/Texture.hpp b/Library/PAX_GRAPHICA/Texture.hpp index ffc61360e..af0b066e1 100644 --- a/Library/PAX_GRAPHICA/Texture.hpp +++ b/Library/PAX_GRAPHICA/Texture.hpp @@ -15,18 +15,18 @@ #include #if defined(PAXS_USING_SIV3D) -#include +#include #elif defined(PAXS_USING_DXLIB) -#include +#include #elif defined(PAXS_USING_SFML) -#include +#include #else -#include +#include #endif #include #include -#include +#include namespace paxg { @@ -86,64 +86,77 @@ namespace paxg { return impl ? impl->height() : 0; } + /// @brief 左上隅を基準に描画 void draw() const { if (impl) impl->draw(); } - void drawAt(const Vec2f& pos) const { + /// @brief 中心を基準に描画 + void drawAt(const paxs::Vector2& pos) const { if (impl) impl->drawAt(pos); } - void drawAt(const Vec2i& pos) const { + /// @brief 中心を基準に描画 + void drawAt(const paxs::Vector2& pos) const { if (impl) impl->drawAt(pos); } - void resizedDrawAt(const Vec2i& resize, const Vec2i& pos) const { - if (impl) impl->resizedDrawAt(resize, pos); + /// @brief 中心を基準に描画 + void drawAt(const paxs::Vector2& pos) const { + if (impl) impl->drawAt(paxs::Vector2(pos)); } - void resizedDrawAt(int resize, const Vec2i& pos) const { - if (impl) impl->resizedDrawAt(resize, pos); + /// @brief 左上隅を基準に描画(リサイズ付き) + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDraw(resize, pos); } - void resizedDrawAt(const Vec2f& resize, const Vec2f& pos) const { - if (impl) impl->resizedDrawAt(resize, pos); + /// @brief 左上隅を基準に描画(リサイズ付き) + void resizedDraw(int resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDraw(resize, pos); } - void resizedDrawAt(int resize, const Vec2f& pos) const { - if (impl) impl->resizedDrawAt(resize, pos); + /// @brief 左上隅を基準に描画(リサイズ付き) + void resizedDraw(const paxs::Vector2& resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDraw(resize, pos); } - // Template overloads for Vec2 - void drawAt(const Vec2& pos) const { - if (impl) impl->drawAt(Vec2f{static_cast(pos.x()), static_cast(pos.y())}); + /// @brief 左上隅を基準に描画(リサイズ付き) + void resizedDraw(int resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDraw(resize, pos); } - void resizedDrawAt(int resize, const Vec2& pos) const { - if (impl) impl->resizedDrawAt(resize, Vec2f{static_cast(pos.x()), static_cast(pos.y())}); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt(resize, pos); } - void resizedDrawAt(const Vec2& resize, const Vec2& pos) const { - if (impl) impl->resizedDrawAt( - Vec2f{static_cast(resize.x()), static_cast(resize.y())}, - Vec2f{static_cast(pos.x()), static_cast(pos.y())} - ); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(int resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt(resize, pos); } - void resizedDraw(const Vec2i& resize, const Vec2i& pos) const { - if (impl) impl->resizedDraw(resize, pos); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt(resize, pos); } - void resizedDraw(int resize, const Vec2i& pos) const { - if (impl) impl->resizedDraw(resize, pos); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(int resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt(resize, pos); } - void resizedDraw(const Vec2f& resize, const Vec2f& pos) const { - if (impl) impl->resizedDraw(resize, pos); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(int resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt(resize, paxs::Vector2(pos)); } - void resizedDraw(int resize, const Vec2f& pos) const { - if (impl) impl->resizedDraw(resize, pos); + /// @brief 中心を基準に描画(リサイズ付き) + void resizedDrawAt(const paxs::Vector2& resize, const paxs::Vector2& pos) const { + if (impl) impl->resizedDrawAt( + paxs::Vector2(resize), + paxs::Vector2(pos) + ); } #if defined(PAXS_USING_SIV3D) diff --git a/Library/PAX_GRAPHICA/Window.hpp b/Library/PAX_GRAPHICA/Window.hpp index 96bda385d..5770575cf 100644 --- a/Library/PAX_GRAPHICA/Window.hpp +++ b/Library/PAX_GRAPHICA/Window.hpp @@ -18,16 +18,16 @@ #include #if defined(PAXS_USING_SIV3D) -#include +#include #elif defined(PAXS_USING_DXLIB) -#include +#include #elif defined(PAXS_USING_SFML) -#include +#include #else -#include +#include #endif -#include +#include namespace paxg { @@ -80,11 +80,7 @@ namespace paxg { getImpl().setSize(width, height); } - static void setPosition(int x, int y) { - getImpl().setPosition(x, y); - } - - static void setPosition(const paxg::Vec2i& pos) { + static void setPosition(const paxs::Vector2& pos) { getImpl().setPosition(pos); } @@ -110,26 +106,14 @@ namespace paxg { getImpl().setMouseCursorVisible(visible); } - static void setMouseCursorGrabbed(bool grabbed) { - getImpl().setMouseCursorGrabbed(grabbed); - } - static void setMouseCursor(const std::string& path) { getImpl().setMouseCursor(path); } - static void setMousePosition(int x, int y) { - getImpl().setMousePosition(x, y); - } - - static void setMousePosition(const paxg::Vec2i& pos) { + static void setMousePosition(const paxs::Vector2& pos) { getImpl().setMousePosition(pos); } - static void setKeyRepeat(bool repeat) { - getImpl().setKeyRepeat(repeat); - } - static void setBackgroundColor(const paxg::Color color) { getImpl().setBackgroundColor(color); } @@ -148,7 +132,7 @@ namespace paxg { getImpl().setDecorated(decorated); } - static paxg::Vec2i center() { + static paxs::Vector2 center() { return getImpl().center(); } @@ -160,17 +144,16 @@ namespace paxg { return getImpl().height(); } - static paxg::Vec2i size() { + static paxs::Vector2 size() { return getImpl().size(); } /// @brief Get window size (alias for size() to match Siv3D Scene::Size()) static paxs::Vector2 Size() { - auto s = getImpl().size(); - return paxs::Vector2(s.x(), s.y()); + return getImpl().size(); } - static paxg::Vec2i getMousePosition() { + static paxs::Vector2 getMousePosition() { return getImpl().getMousePosition(); } diff --git a/Library/PAX_MAHOROBA/Core/Application.hpp b/Library/PAX_MAHOROBA/Core/Application.hpp index c21f5d565..d1dd8213e 100644 --- a/Library/PAX_MAHOROBA/Core/Application.hpp +++ b/Library/PAX_MAHOROBA/Core/Application.hpp @@ -73,7 +73,7 @@ class Application { Fonts().getFont(FontProfiles::ui_medium) ); - // 非同期初期化を開始 + // 非同期初期化を開始 (Phase 1: 描画APIを使わない処理のみ) init_loading_handle_ = startAsyncTask([this](ProgressToken& token) { // Localesシステムを初期化(時間がかかる処理) // 進捗範囲: 0.05 ~ 0.65 @@ -88,59 +88,9 @@ class Application { token.setMessage("Creating ApplicationEventHandler..."); this->event_handler_ = std::make_unique(*this->app_state_); - // InputManager作成(入力処理統合) + // Phase 1完了 token.setProgress(0.7f); - token.setMessage("Creating InputManager..."); - this->input_manager_ = std::make_unique(); - - // AppComponentManager作成(コンポーネント統合管理) - token.setProgress(0.75f); - token.setMessage("Creating AppComponentManager..."); - this->component_manager_ = std::make_unique(*this->app_state_); - - // 入力ハンドラー作成と登録 - token.setProgress(0.8f); - token.setMessage("Creating input handlers..."); - this->map_viewport_input_handler_ = std::make_unique( - this->app_state_->getMapViewportForInputHandler() - ); - this->ui_input_handler_ = std::make_unique(); - -#ifdef PAXS_DEVELOPMENT - this->debug_input_handler_ = std::make_unique( - &this->component_manager_->getDebugLayer() - ); -#endif - - // InputManagerに入力ハンドラーを登録 - token.setProgress(0.85f); - token.setMessage("Registering input handlers..."); - this->input_manager_->registerHandler(this->map_viewport_input_handler_.get()); - this->input_manager_->registerHandler(this->ui_input_handler_.get()); -#ifdef PAXS_DEVELOPMENT - this->input_manager_->registerHandler(this->debug_input_handler_.get()); -#endif - - // AppComponentManagerが内部のウィジェット/ハンドラーを登録 - token.setProgress(0.9f); - token.setMessage("Registering widgets..."); - this->component_manager_->registerToInputHandlers( - *this->ui_input_handler_, - this->input_manager_->getInputRouter() - ); - -#ifdef PAXS_DEVELOPMENT - // デバッグコンソールにカスタムコマンドを登録 - token.setProgress(0.95f); - token.setMessage("Registering debug commands..."); - DebugConsoleCommandRegistry::registerAllCommands( - this->component_manager_->getDebugLayer().getConsole(), - *this->app_state_ - ); -#endif - - token.setProgress(1.0f); - token.setMessage("Initialization complete!"); + token.setMessage("Phase 1 complete. Waiting for Phase 2 on main thread..."); return true; }); } @@ -195,6 +145,53 @@ class Application { std::unique_ptr loading_texture_; ///< ローディング画面の画像 / Loading screen texture int last_window_width_ = 0; ///< 前回のウィンドウ幅 / Last window width int last_window_height_ = 0; ///< 前回のウィンドウ高さ / Last window height + bool phase1_completed_ = false; ///< Phase1完了フラグ / Phase1 completion flag + bool phase2_completed_ = false; ///< Phase2完了フラグ / Phase2 completion flag + + /// @brief Phase 2の初期化を実行(メインスレッドで実行、描画APIを使用) + /// @brief Execute Phase 2 initialization (runs on main thread, uses drawing APIs) + void performPhase2Initialization() { + // InputManager作成(paxg::Window::width/height()を使用) + this->input_manager_ = std::make_unique(); + + // AppComponentManager作成(paxg::Window, paxg::Font, paxg::Textureを使用) + this->component_manager_ = std::make_unique(*this->app_state_); + + // 入力ハンドラー作成と登録 + this->map_viewport_input_handler_ = std::make_unique( + this->app_state_->getMapViewportForInputHandler() + ); + this->ui_input_handler_ = std::make_unique(); + +#ifdef PAXS_DEVELOPMENT + this->debug_input_handler_ = std::make_unique( + &this->component_manager_->getDebugLayer() + ); +#endif + + // InputManagerに入力ハンドラーを登録 + this->input_manager_->registerHandler(this->map_viewport_input_handler_.get()); + this->input_manager_->registerHandler(this->ui_input_handler_.get()); +#ifdef PAXS_DEVELOPMENT + this->input_manager_->registerHandler(this->debug_input_handler_.get()); +#endif + + // AppComponentManagerが内部のウィジェット/ハンドラーを登録 + this->component_manager_->registerToInputHandlers( + *this->ui_input_handler_, + this->input_manager_->getInputRouter() + ); + +#ifdef PAXS_DEVELOPMENT + // デバッグコンソールにカスタムコマンドを登録 + DebugConsoleCommandRegistry::registerAllCommands( + this->component_manager_->getDebugLayer().getConsole(), + *this->app_state_ + ); +#endif + + phase2_completed_ = true; + } /// @brief 初期化中の更新処理 void updateInitializingMode() { @@ -228,15 +225,16 @@ class Application { const float scale_y = static_cast(window_height) / texture_height; const float scale = (scale_x > scale_y) ? scale_x : scale_y; - const int scaled_width = static_cast(texture_width * scale); - const int scaled_height = static_cast(texture_height * scale); + const paxs::Vector2 scaled_size = paxs::Vector2{ + static_cast(texture_width * scale), + static_cast(texture_height * scale) + }; // 中央配置の座標を計算 - const int pos_x = (window_width - scaled_width) / 2; - const int pos_y = (window_height - scaled_height) / 2; + const paxs::Vector2 pos{(window_width - scaled_size.x) / 2, (window_height - scaled_size.y) / 2}; // ローディング画像をリサイズして描画 - loading_texture_->resizedDraw(paxg::Vec2i{scaled_width, scaled_height}, paxg::Vec2i{pos_x, pos_y}); + loading_texture_->resizedDraw(scaled_size, pos); } // 進捗バーを描画 @@ -244,29 +242,43 @@ class Application { init_progress_bar_->render(); } - // 2. ロード状態の更新(ロード完了のチェック) + // 2. ロード状態の更新(Phase 1完了 -> Phase 2実行 -> 完了チェック) // 描画後にチェックすることで、最後のフレームが確実に表示される - if (init_loading_handle_.isValid() && init_loading_handle_.isFinished()) { + if (init_loading_handle_.isValid() && init_loading_handle_.isFinished() && !phase1_completed_) { + // Phase 1が完了した const bool* result = init_loading_handle_.getResult(); if ((result != nullptr) && *result) { - // 初期化成功 - アプリケーション状態をRunningに変更 - app_state_->updateInitializationComplete(); - - // ローディング画面終了 - paxs::PaxSapienticaInit::endLoadingScreen(); + phase1_completed_ = true; - // 進捗バーとローディング画像をクリア - init_progress_bar_.reset(); - loading_texture_.reset(); + // Phase 2をメインスレッドで実行(描画APIを使用するため) + // 進捗バーのメッセージを更新 + if (init_progress_bar_) { + // Phase 2開始を示すためダミーのLoadingHandleを更新 + // 実際の進捗は手動で管理 + } + performPhase2Initialization(); } else { - // 初期化失敗 + // Phase 1初期化失敗 if (init_loading_handle_.hasError()) { - PAXS_ERROR("Application initialization failed"); + PAXS_ERROR("Application initialization Phase 1 failed"); } } } + // Phase 2完了後、アプリケーション状態をRunningに変更 + if (phase1_completed_ && phase2_completed_) { + // 初期化成功 - アプリケーション状態をRunningに変更 + app_state_->updateInitializationComplete(); + + // ローディング画面終了 + paxs::PaxSapienticaInit::endLoadingScreen(); + + // 進捗バーとローディング画像をクリア + init_progress_bar_.reset(); + loading_texture_.reset(); + } + // 3. タッチ入力の状態更新 paxg::TouchInput::updateState(); } diff --git a/Library/PAX_MAHOROBA/Core/InitLogo.hpp b/Library/PAX_MAHOROBA/Core/InitLogo.hpp index 9fbd68481..894a8d9d5 100644 --- a/Library/PAX_MAHOROBA/Core/InitLogo.hpp +++ b/Library/PAX_MAHOROBA/Core/InitLogo.hpp @@ -115,7 +115,7 @@ namespace paxs { const int new_y = (window_height - scaled_height) / 2; // 画像をリサイズして描画 - loading_texture.resizedDraw(paxg::Vec2i{scaled_width, scaled_height}, paxg::Vec2i{new_x, new_y}); + loading_texture.resizedDraw(paxs::Vector2{scaled_width, scaled_height}, paxs::Vector2{new_x, new_y}); // 画面を更新 #ifdef PAXS_USING_SFML paxg::Window::display(); diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp index 0e0b53716..318ff4ad8 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/GenomeFeature.hpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -118,8 +117,7 @@ class GenomeFeature : public MapFeature, // 表示サイズの計算(zoom適用) cached_display_size_ = static_cast(data_.overall_length / 2 * data_.zoom); - // テクスチャサイズを描画時のサイズに合わせる(MapFeatureRenderer.hppと同じ) - // 描画時は resizedDrawAt(display_size) を使用するため、当たり判定もdisplay_sizeに合わせる + // テクスチャサイズを描画時のサイズに合わせる cached_texture_size_ = Vector2(cached_display_size_, cached_display_size_); visible_ = true; @@ -167,10 +165,10 @@ class GenomeFeature : public MapFeature, return MapContentHitTester::testMultiplePositions( mouse_pos.x, mouse_pos.y, cached_screen_positions_, - [texture_size, text_size](int mouse_x, int mouse_y, const paxg::Vec2& pos) { + [texture_size, text_size](int mouse_x, int mouse_y, const paxs::Vector2& pos) { // テクスチャの矩形判定(中心から描画) const Rect texture_rect = Rect::fromCenter( - Vector2(static_cast(pos.x()), static_cast(pos.y())), + Vector2(pos), texture_size ); if (texture_rect.contains(mouse_x, mouse_y)) { @@ -181,9 +179,9 @@ class GenomeFeature : public MapFeature, // text_pos.y = pos.y() - display_size / 2 - 5(アイコンの上部から少し離す) // drawBottomCenterなので、そこから上にtext_heightの範囲 if (text_size.x > 0 && text_size.y > 0) { - const int text_bottom_y = static_cast(pos.y()) - (texture_size.y / 2) - 5; // テキスト下端 + const int text_bottom_y = static_cast(pos.y) - (texture_size.y / 2) - 5; // テキスト下端 const Rect text_rect = Rect::fromCenter( - Vector2(static_cast(pos.x()), text_bottom_y - (text_size.y / 2)), + Vector2(static_cast(pos.x), text_bottom_y - (text_size.y / 2)), text_size ); if (text_rect.contains(mouse_x, mouse_y)) { diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/GeographicFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/GeographicFeature.hpp index 6498c470e..e205dd63a 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/GeographicFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/GeographicFeature.hpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -120,8 +119,7 @@ class GeographicFeature : public MapFeature, // 表示サイズの計算(zoom適用) cached_display_size_ = static_cast(data_.overall_length / 2 * data_.zoom); - // テクスチャサイズを描画時のサイズに合わせる(MapFeatureRenderer.hppと同じ) - // 描画時は resizedDrawAt(display_size) を使用するため、当たり判定もdisplay_sizeに合わせる + // テクスチャサイズを描画時のサイズに合わせる cached_texture_size_ = Vector2(cached_display_size_, cached_display_size_); visible_ = true; @@ -153,10 +151,10 @@ class GeographicFeature : public MapFeature, return MapContentHitTester::testMultiplePositions( mouse_pos.x, mouse_pos.y, cached_screen_positions_, - [texture_size](int mouse_x, int mouse_y, const paxg::Vec2& pos) { + [texture_size](int mouse_x, int mouse_y, const paxs::Vector2& pos) { // テクスチャの矩形判定(中心から描画) const Rect texture_rect = Rect::fromCenter( - Vector2(static_cast(pos.x()), static_cast(pos.y())), + Vector2(pos), texture_size ); return texture_rect.contains(mouse_x, mouse_y); diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/Model3DFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/Model3DFeature.hpp index 1b0e2882b..f497e41c9 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/Model3DFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/Model3DFeature.hpp @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -111,7 +110,7 @@ class Model3DFeature : public MapFeature { return MapContentHitTester::testMultiplePositions( mouse_pos.x, mouse_pos.y, cached_screen_positions_, - [hit_radius](int mx, int my, const paxg::Vec2& pos) { + [hit_radius](int mx, int my, const paxs::Vector2& pos) { return MapContentHitTester::circleHitTest(mx, my, pos, hit_radius); } ); diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp index e34ba4836..1aaf781d1 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/PersonFeature.hpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -117,8 +116,8 @@ class PersonFeature : public MapFeature, // 表示サイズの計算(人物は常に通常サイズで表示) cached_display_size_ = 60; - // テクスチャサイズを描画時のサイズに合わせる(MapFeatureRenderer.hppと同じ) - // 描画時は resizedDrawAt(120) を使用するため、当たり判定は70×110 + // テクスチャサイズを描画時のサイズに合わせる + // 当たり判定は70×110 cached_texture_size_ = Vector2(70, 110); visible_ = true; @@ -165,10 +164,10 @@ class PersonFeature : public MapFeature, // 3つのスクリーン座標でヒット判定(テクスチャ + テキスト) return MapContentHitTester::testMultiplePositions( mouse_pos.x, mouse_pos.y, cached_screen_positions_, - [texture_size, text_size](int mx, int my, const paxg::Vec2& pos) { + [texture_size, text_size](int mx, int my, const paxs::Vector2& pos) { // テクスチャの矩形判定(中心から描画) const Rect texture_rect = Rect::fromCenter( - Vector2(static_cast(pos.x()), static_cast(pos.y())), + Vector2(pos), texture_size ); if (texture_rect.contains(mx, my)) { @@ -178,9 +177,9 @@ class PersonFeature : public MapFeature, // draw_font_pos = {x, y - 60}から描画されるため、 // 実際のテキスト位置は pos.y() - 60 から text_height の範囲 if (text_size.x > 0 && text_size.y > 0) { - const int text_y = static_cast(pos.y()) - 60; // テクスチャの上部(MapFeatureRenderer参照) + const int text_y = static_cast(pos.y) - 60; // テクスチャの上部(MapFeatureRenderer参照) const Rect text_rect( - static_cast(pos.x()) - (text_size.x / 2), + static_cast(pos.x) - (text_size.x / 2), text_y, text_size.x, text_size.y diff --git a/Library/PAX_MAHOROBA/Map/Content/Feature/PlaceNameFeature.hpp b/Library/PAX_MAHOROBA/Map/Content/Feature/PlaceNameFeature.hpp index 80e8b7e9e..c5ad459da 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Feature/PlaceNameFeature.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Feature/PlaceNameFeature.hpp @@ -15,8 +15,6 @@ #include #include -#include - #include #include #include @@ -160,11 +158,11 @@ class PlaceNameFeature : public MapFeature, return MapContentHitTester::testMultiplePositions( mouse_pos.x, mouse_pos.y, cached_screen_positions_, - [text_size](int mouse_x, int mouse_y, const paxg::Vec2& pos) { + [text_size](int mouse_x, int mouse_y, const paxs::Vector2& pos) { // テキストの矩形判定: drawAtは横方向中央、縦方向上を基準に描画 const Rect text_rect( - static_cast(pos.x()) - (text_size.x / 2), - static_cast(pos.y()), + static_cast(pos.x) - (text_size.x / 2), + static_cast(pos.y), text_size.x, text_size.y ); diff --git a/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp b/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp index fe7dccae5..cdc827324 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Renderer/GeometryRenderer.hpp @@ -60,17 +60,17 @@ class GeometryRenderer { static bool drawTexture( const UnorderedMap& texture_map, std::uint_least32_t texture_key, - const paxg::Vec2& draw_pos, + const paxs::Vector2& draw_pos, int size ) { if (texture_key == 0) { return false; } - auto iter = texture_map.find(texture_key); - if (iter == texture_map.end()) { + const auto* const ptr = texture_map.try_get(texture_key); + if (ptr == nullptr) { return false; } - iter->second.resizedDrawAt(size, draw_pos); + ptr->resizedDrawAt(size, draw_pos); return true; } }; diff --git a/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp b/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp index 265b7025d..8c89d6f8d 100644 --- a/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Content/Renderer/MapFeatureRenderer.hpp @@ -110,7 +110,7 @@ class MapFeatureRenderer : public GeometryRenderer { } // テキスト位置(肖像画の上部) - const paxg::Vec2 draw_font_pos = paxg::Vec2{ draw_pos.x(), draw_pos.y() - 60 }; + const paxg::Vec2 draw_font_pos = paxg::Vec2{ draw_pos.x, draw_pos.y - 60 }; const std::string name = feature.getName(); if (!name.empty()) { @@ -139,28 +139,27 @@ class MapFeatureRenderer : public GeometryRenderer { // 各スクリーン座標で描画(経度ラップ対応) for (const auto& draw_pos : screen_positions) { // テクスチャを取得(親のテクスチャをフォールバック) - // Note: GeographicFeature は LocationPoint を使用しているため、親のテクスチャ情報は含まれていない - // 将来的には LocationPointGroup への参照も保持する必要があるかもしれない const std::uint_least32_t place_tex = data.texture_key; - if (!texture_map.contains(place_tex)) continue; - - const auto& texture = texture_map.at(place_tex); + const auto* const texture_ptr = texture_map.try_get(place_tex); + if (texture_ptr == nullptr) { + continue; + } // draw_countが1の場合は通常描画 if (draw_count == 1) { - texture.resizedDrawAt(display_size, draw_pos); + texture_ptr->resizedDrawAt(display_size, draw_pos); } else { // draw_countが2以上の場合は横に複数並べて描画(中央揃え) constexpr int spacing = 4; // テクスチャ間の間隔 const int total_width = (draw_count - 1) * spacing; - const int start_x = static_cast(draw_pos.x()) - total_width / 2; + const int start_x = static_cast(draw_pos.x) - total_width / 2; for (int i = 0; i < draw_count; ++i) { - const paxg::Vec2 draw_item_pos{ + const paxs::Vector2 draw_item_pos{ static_cast(start_x + i * spacing), - draw_pos.y() + draw_pos.y }; - texture.resizedDrawAt(display_size, draw_item_pos); + texture_ptr->resizedDrawAt(display_size, draw_item_pos); } } } @@ -238,8 +237,8 @@ class MapFeatureRenderer : public GeometryRenderer { if (!name.empty()) { // テクスチャの上部に名前を描画 const paxg::Vec2 text_pos = paxg::Vec2{ - draw_pos.x(), - draw_pos.y() - (display_size / 2) - 5 // アイコンの上部から少し離す + draw_pos.x, + draw_pos.y - (display_size / 2) - 5 // アイコンの上部から少し離す }; font->drawBottomCenter(name, text_pos, paxg::Color(0, 0, 0)); } diff --git a/Library/PAX_MAHOROBA/Map/Core/MapAssetRegistry.hpp b/Library/PAX_MAHOROBA/Map/Core/MapAssetRegistry.hpp index fe1ff2dcb..67442a928 100644 --- a/Library/PAX_MAHOROBA/Map/Core/MapAssetRegistry.hpp +++ b/Library/PAX_MAHOROBA/Map/Core/MapAssetRegistry.hpp @@ -89,8 +89,7 @@ class MapAssetRegistry { /// @param key ハッシュキー / Hash key /// @return テクスチャへのポインタ(存在しない場合nullptr) / Pointer to texture (nullptr if not found) const paxg::Texture* getTexture(std::uint_least32_t key) const { - const auto iterator = merged_textures_.find(key); - return (iterator != merged_textures_.end()) ? &iterator->second : nullptr; + return merged_textures_.try_get(key); } /// @brief ハッシュキーからテクスチャを取得(参照) @@ -102,14 +101,6 @@ class MapAssetRegistry { return merged_textures_.at(key); } - /// @brief テクスチャが存在するかチェック - /// @brief Check if texture exists - /// @param key ハッシュキー / Hash key - /// @return 存在する場合true / True if exists - bool contains(std::uint_least32_t key) const { - return merged_textures_.contains(key); - } - /// @brief 統合マップを取得 /// @brief Get merged map /// @return 統合されたテクスチャマップへの参照 / Reference to merged texture map diff --git a/Library/PAX_MAHOROBA/Map/Core/MapCoordinateConverter.hpp b/Library/PAX_MAHOROBA/Map/Core/MapCoordinateConverter.hpp index 3122830cf..592fbe29c 100644 --- a/Library/PAX_MAHOROBA/Map/Core/MapCoordinateConverter.hpp +++ b/Library/PAX_MAHOROBA/Map/Core/MapCoordinateConverter.hpp @@ -12,7 +12,6 @@ #ifndef PAX_MAHOROBA_MAP_COORDINATE_CONVERTER_HPP #define PAX_MAHOROBA_MAP_COORDINATE_CONVERTER_HPP -#include #include #include @@ -79,19 +78,19 @@ struct MapCoordinateConverter { /// @param map_view_size ビューポートサイズ / Viewport size /// @param map_view_center ビューポート中心 / Viewport center /// @return スクリーン座標 / Screen position - static paxg::Vec2 toScreenPos( + static paxs::Vector2 toScreenPos( const Vector2& mercator_pos, const Vector2& map_view_size, const Vector2& map_view_center ) { // EPSG:3857(Webメルカトル) 座標をスクリーン座標に変換 - return paxg::Vec2( + return { (mercator_pos.x - (map_view_center.x - map_view_size.x / 2)) / map_view_size.x * double(paxg::Window::width()), double(paxg::Window::height()) - ((mercator_pos.y - (map_view_center.y - map_view_size.y / 2)) / map_view_size.y * double(paxg::Window::height())) - ); + }; } }; diff --git a/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp b/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp index be9c81e38..f179376f1 100644 --- a/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Simulation/SettlementRenderer.hpp @@ -138,7 +138,7 @@ namespace paxs { if (!isInViewport(coordinate, map_view_size, map_view_center)) continue; // 描画位置 - const paxg::Vec2 draw_pos = MapCoordinateConverter::toScreenPos( + const paxs::Vector2 draw_pos = MapCoordinateConverter::toScreenPos( coordinate, map_view_size, map_view_center diff --git a/Library/PAX_MAHOROBA/Map/Tile/TileRenderer.hpp b/Library/PAX_MAHOROBA/Map/Tile/TileRenderer.hpp index 02463e88a..be1456146 100644 --- a/Library/PAX_MAHOROBA/Map/Tile/TileRenderer.hpp +++ b/Library/PAX_MAHOROBA/Map/Tile/TileRenderer.hpp @@ -108,7 +108,7 @@ namespace paxs { const Vector2 start_cell = tile.getStartCell(); const Vector2 end_cell = tile.getEndCell(); - paxg::Vec2f tile_size = paxg::Vec2f( + paxs::Vector2 tile_size = paxs::Vector2( static_cast((360.0 / z_num) / map_view_size.x * static_cast(paxg::Window::width())), static_cast((360.0 / z_num) / map_view_size.y * static_cast(paxg::Window::height())) ); @@ -122,7 +122,7 @@ namespace paxs { (360.0 - i * 360.0 / z_num) - 180.0 }; texture->resizedDraw(tile_size, - paxg::Vec2f( + paxs::Vector2( static_cast((map_pos.x - (map_view_center.x - map_view_size.x / 2)) / map_view_size.x * double(paxg::Window::width())), static_cast(double(paxg::Window::height()) - ((map_pos.y - (map_view_center.y - map_view_size.y / 2)) / map_view_size.y * double(paxg::Window::height()))) )); @@ -234,17 +234,17 @@ namespace paxs { // 各行を個別に描画 const int line_height = font_size + 2; // 行間を2px追加 - font->draw("X:" + std::to_string(j2), paxg::Vec2i(text_x, text_y), paxg::Color{ 0, 0, 0 }); + font->draw("X:" + std::to_string(j2), paxs::Vector2(text_x, text_y), paxg::Color{ 0, 0, 0 }); text_y += line_height; - font->draw("Y:" + std::to_string(i2), paxg::Vec2i(text_x, text_y), paxg::Color{ 0, 0, 0 }); + font->draw("Y:" + std::to_string(i2), paxs::Vector2(text_x, text_y), paxg::Color{ 0, 0, 0 }); text_y += line_height; - font->draw("Z:" + std::to_string(z), paxg::Vec2i(text_x, text_y), paxg::Color{ 0, 0, 0 }); + font->draw("Z:" + std::to_string(z), paxs::Vector2(text_x, text_y), paxg::Color{ 0, 0, 0 }); text_y += line_height; font->draw("L:" + std::to_string(static_cast(40075016.68 / (1 << z))), - paxg::Vec2i(text_x, text_y), paxg::Color{ 0, 0, 0 }); + paxs::Vector2(text_x, text_y), paxg::Color{ 0, 0, 0 }); } } } diff --git a/Library/PAX_MAHOROBA/Map/Tile/TileRepository.hpp b/Library/PAX_MAHOROBA/Map/Tile/TileRepository.hpp index b946281df..7b93c9f32 100644 --- a/Library/PAX_MAHOROBA/Map/Tile/TileRepository.hpp +++ b/Library/PAX_MAHOROBA/Map/Tile/TileRepository.hpp @@ -31,10 +31,7 @@ namespace paxs { private: // 項目の ID を返す static std::size_t getMenuIndexMap(const paxs::UnorderedMap& menu, const std::uint_least32_t& str_) { - // Key が登録されていたら Key の中身(添え字)を返す - const auto iterator = menu.find(str_); - return iterator != menu.end() ? iterator->second : - SIZE_MAX; // 登録されていない場合は最大値を返す + return menu.value_or(str_, SIZE_MAX); } public: diff --git a/Library/PAX_MAHOROBA/Rendering/FontSystem.hpp b/Library/PAX_MAHOROBA/Rendering/FontSystem.hpp index 5fdda3f47..c429d545c 100644 --- a/Library/PAX_MAHOROBA/Rendering/FontSystem.hpp +++ b/Library/PAX_MAHOROBA/Rendering/FontSystem.hpp @@ -84,14 +84,6 @@ namespace paxs { profiles_.emplace(name, FontProfile( size, buffer_thickness )); } - /// @brief プロファイルが存在するか確認 - /// @brief Check if profile exists - /// @param name プロファイル名 / Profile name - /// @return 存在すれば true / true if exists - [[nodiscard]] bool hasProfile(const std::string& name) const { - return profiles_.contains(name); - } - /// @brief デフォルトプロファイルの登録 /// @brief Register default profiles void registerDefaultProfiles() { @@ -239,11 +231,12 @@ namespace paxs { /// @param profile_name プロファイル名 / Profile name /// @return フォントへのポインタ、失敗時は nullptr / Pointer to font, nullptr on failure paxg::Font* getFont(std::uint_least32_t language_key, const std::string& profile_name) { - if (!hasProfile(profile_name)) { + const auto* const profile_ptr = profiles_.try_get(profile_name); + if (profile_ptr == nullptr) { + PAXS_WARNING("FontSystem::getFont - Profile not found: " + profile_name); return nullptr; } - const auto& profile = profiles_.at(profile_name); - return getFont(language_key, profile.size, profile.buffer_thickness); + return getFont(language_key, profile_ptr->size, profile_ptr->buffer_thickness); } /// @brief 現在の選択言語でフォントを取得(サイズとバッファー厚を直接指定) diff --git a/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp b/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp index cd6881512..f0d59e09f 100644 --- a/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp +++ b/Library/PAX_MAHOROBA/UI/Calendar/CalendarContent.hpp @@ -313,13 +313,28 @@ namespace paxs { break; case paxs::cal::DateOutputType::name_and_value: { - if (text_str != nullptr) (*one_font).drawTopRight(*text_str, - paxg::Vec2i(static_cast(ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + if (text_str != nullptr) { + (*one_font).drawTopRight(*text_str, + paxs::Vector2( + static_cast(ui_layout_.koyomi_font_en_x), + static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3)) + ), + paxg::Color(0, 0, 0) + ); + } } + std::visit([&](const auto& x) { - date_day = int(x.getDay()); + date_day = static_cast(x.getDay()); }, koyomi_.date_list[i].date); - (*one_font).drawTopRight(std::to_string(date_day), paxg::Vec2i(static_cast(int(315 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), static_cast(ui_layout_.koyomi_font_en_y + i * (paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3))), paxg::Color(0, 0, 0)); + + (*one_font).drawTopRight( + std::to_string(date_day), + paxs::Vector2( + static_cast((315 * paxg::FontConfig::KOYOMI_FONT_SIZE / 30.0) + ui_layout_.koyomi_font_en_x), + static_cast(ui_layout_.koyomi_font_en_y + (i * paxg::FontConfig::KOYOMI_FONT_SIZE * 4 / 3)) + ), + paxg::Color(0, 0, 0)); break; default: break; diff --git a/Library/PAX_MAHOROBA/UI/Debug/DebugConsole.hpp b/Library/PAX_MAHOROBA/UI/Debug/DebugConsole.hpp index 71986df4a..e57015306 100644 --- a/Library/PAX_MAHOROBA/UI/Debug/DebugConsole.hpp +++ b/Library/PAX_MAHOROBA/UI/Debug/DebugConsole.hpp @@ -114,7 +114,7 @@ class DebugConsole { .draw(paxg::Color(40, 40, 40, 255)); font_text->draw("Debug Console", - paxg::Vec2i(CONSOLE_MARGIN_X + CONSOLE_PADDING, CONSOLE_MARGIN_Y + 5), + paxs::Vector2(CONSOLE_MARGIN_X + CONSOLE_PADDING, CONSOLE_MARGIN_Y + 5), paxg::Color(0, 0, 0)); // フィルターボタン描画 @@ -151,7 +151,7 @@ class DebugConsole { const paxg::Color text_color = getLevelColor(item.level); font_text->draw(item.display_text, - paxg::Vec2i(CONSOLE_MARGIN_X + CONSOLE_PADDING, current_y), + paxs::Vector2(CONSOLE_MARGIN_X + CONSOLE_PADDING, current_y), text_color); current_y += LINE_HEIGHT; @@ -162,7 +162,7 @@ class DebugConsole { const std::string scroll_info = "Scroll: " + std::to_string(scroll_offset_) + " / " + std::to_string(filtered_indices.size() - max_lines); font_text->draw(scroll_info, - paxg::Vec2i(CONSOLE_MARGIN_X + console_width - 200, CONSOLE_MARGIN_Y + 5), + paxs::Vector2(CONSOLE_MARGIN_X + console_width - 200, CONSOLE_MARGIN_Y + 5), paxg::Color(150, 150, 150)); } @@ -170,7 +170,7 @@ class DebugConsole { const std::string count_info = "Showing: " + std::to_string(filtered_indices.size()) + " / " + std::to_string(log_history_.size()); font_text->draw(count_info, - paxg::Vec2i(CONSOLE_MARGIN_X + console_width - 200, CONSOLE_MARGIN_Y + 25), + paxs::Vector2(CONSOLE_MARGIN_X + console_width - 200, CONSOLE_MARGIN_Y + 25), paxg::Color(0, 0, 0)); #ifdef PAXS_DEVELOPMENT @@ -187,7 +187,7 @@ class DebugConsole { // プロンプト記号 ">" font_text->draw("> ", - paxg::Vec2i(CONSOLE_MARGIN_X + CONSOLE_PADDING + 5, input_y + 5), + paxs::Vector2(CONSOLE_MARGIN_X + CONSOLE_PADDING + 5, input_y + 5), paxg::Color(0, 0, 0)); // 入力テキスト(カーソル位置にアンダースコアを挿入) @@ -196,7 +196,7 @@ class DebugConsole { display_text.insert(cursor_position_, "_"); } font_text->draw(display_text, - paxg::Vec2i(CONSOLE_MARGIN_X + CONSOLE_PADDING + 25, input_y + 5), + paxs::Vector2(CONSOLE_MARGIN_X + CONSOLE_PADDING + 25, input_y + 5), paxg::Color(0, 0, 0)); #endif } @@ -394,7 +394,7 @@ class DebugConsole { paxg::Rect(x, y, FILTER_BUTTON_WIDTH, FILTER_BUTTON_HEIGHT).draw(bg_color); // ボタンテキスト - font->draw(label, paxg::Vec2i(x + 10, y + 3), text_color); + font->draw(label, paxs::Vector2(x + 10, y + 3), text_color); } public: diff --git a/Library/PAX_MAHOROBA/UI/Debug/DebugNotificationManager.hpp b/Library/PAX_MAHOROBA/UI/Debug/DebugNotificationManager.hpp index 535a37f19..e986072ec 100644 --- a/Library/PAX_MAHOROBA/UI/Debug/DebugNotificationManager.hpp +++ b/Library/PAX_MAHOROBA/UI/Debug/DebugNotificationManager.hpp @@ -91,12 +91,12 @@ class DebugNotificationManager { // アイコン描画 font_icon->draw(getLevelIcon(item.level), - paxg::Vec2i(static_cast(item.panel_rect.x() + 10), static_cast(item.panel_rect.y() + 15)), + paxs::Vector2(static_cast(item.panel_rect.x() + 10), static_cast(item.panel_rect.y() + 15)), getLevelIconColor(item.level)); // メッセージテキスト描画 font_text->draw(item.display_text, - paxg::Vec2i(static_cast(item.panel_rect.x() + ICON_SIZE + 20), static_cast(item.panel_rect.y() + 10)), + paxs::Vector2(static_cast(item.panel_rect.x() + ICON_SIZE + 20), static_cast(item.panel_rect.y() + 10)), paxg::Color(40, 40, 40)); // 閉じるボタン描画 @@ -104,7 +104,7 @@ class DebugNotificationManager { ? paxg::Color(200, 50, 50) : paxg::Color(150, 150, 150); font_icon->draw("×", - paxg::Vec2i(item.close_button_rect.x() + 5, item.close_button_rect.y() + 5), + paxs::Vector2(item.close_button_rect.x() + 5, item.close_button_rect.y() + 5), close_color); } } diff --git a/Library/PAX_MAHOROBA/UI/Debug/DebugPerformanceMonitor.hpp b/Library/PAX_MAHOROBA/UI/Debug/DebugPerformanceMonitor.hpp index ff867c0d8..6000d677c 100644 --- a/Library/PAX_MAHOROBA/UI/Debug/DebugPerformanceMonitor.hpp +++ b/Library/PAX_MAHOROBA/UI/Debug/DebugPerformanceMonitor.hpp @@ -130,7 +130,7 @@ class DebugPerformanceMonitor { case DisplayMode::Flat: mode_text = "[Flat]"; break; } font_text->draw("Performance Monitor " + mode_text, - paxg::Vec2i(pos.x + PADDING, pos.y + PADDING), + paxs::Vector2(pos.x + PADDING, pos.y + PADDING), paxg::Color(0, 0, 0)); // FPS情報(常に表示) @@ -138,11 +138,11 @@ class DebugPerformanceMonitor { const paxg::Color fps_color = getFPSColor(fps_); font_text->draw("FPS: " + formatDouble(fps_, 1), - paxg::Vec2i(pos.x + PADDING, text_y), + paxs::Vector2(pos.x + PADDING, text_y), fps_color); font_text->draw("Frame Time: " + formatDouble(frame_time_ms_, 2) + " ms", - paxg::Vec2i(pos.x + PADDING, text_y + 20), + paxs::Vector2(pos.x + PADDING, text_y + 20), paxg::Color(0, 0, 0)); // モードに応じた描画 @@ -261,7 +261,7 @@ class DebugPerformanceMonitor { } font_text->draw("Min: " + formatDouble(min_fps, 1) + " / Max: " + formatDouble(max_fps, 1), - paxg::Vec2i(pos.x + PADDING, content_y), + paxs::Vector2(pos.x + PADDING, content_y), paxg::Color(0, 0, 0)); } @@ -272,13 +272,13 @@ class DebugPerformanceMonitor { // グラフの目盛り font_text->draw("60", - paxg::Vec2i(pos.x + PADDING - 20, graph_y), + paxs::Vector2(pos.x + PADDING - 20, graph_y), paxg::Color(100, 100, 100)); font_text->draw("30", - paxg::Vec2i(pos.x + PADDING - 20, graph_y + GRAPH_HEIGHT / 2), + paxs::Vector2(pos.x + PADDING - 20, graph_y + GRAPH_HEIGHT / 2), paxg::Color(100, 100, 100)); font_text->draw("0", - paxg::Vec2i(pos.x + PADDING - 20, graph_y + GRAPH_HEIGHT), + paxs::Vector2(pos.x + PADDING - 20, graph_y + GRAPH_HEIGHT), paxg::Color(100, 100, 100)); } @@ -324,7 +324,7 @@ class DebugPerformanceMonitor { paxg::Color text_color = getTimeColor(scope_data->current_time_ms); font_text->draw(text, - paxg::Vec2i(pos_x + indent, current_y), + paxs::Vector2(pos_x + indent, current_y), text_color); current_y += LINE_HEIGHT; @@ -372,7 +372,7 @@ class DebugPerformanceMonitor { paxg::Color text_color = getTimeColor(scope_data->current_time_ms); font_text->draw(text, - paxg::Vec2i(pos.x + PADDING, current_y), + paxs::Vector2(pos.x + PADDING, current_y), text_color); current_y += LINE_HEIGHT; diff --git a/Library/PAX_MAHOROBA/UI/Feature/FeatureInfoPanel.hpp b/Library/PAX_MAHOROBA/UI/Feature/FeatureInfoPanel.hpp index d6abd1e0d..92de0f86b 100644 --- a/Library/PAX_MAHOROBA/UI/Feature/FeatureInfoPanel.hpp +++ b/Library/PAX_MAHOROBA/UI/Feature/FeatureInfoPanel.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -208,11 +207,11 @@ namespace paxs { }; for (const auto& col : known_columns) { - const auto iterator = extra_data_.find(col.data_hash); - if (iterator != extra_data_.end()) { + const auto* const ptr = extra_data_.try_get(col.data_hash); + if (ptr != nullptr) { const std::string* label = Fonts().getLocalesText(feature_info_domain_hash, col.label_key); if (label) { - total_lines += calculateTextLines(*label + ": " + iterator->second, max_text_width); + total_lines += calculateTextLines(*label + ": " + *ptr, max_text_width); } } } @@ -280,7 +279,7 @@ namespace paxs { // 残りが全て1行に収まる font->draw( remaining_text.c_str(), - paxg::Vec2i(bounds.x(), bounds.y() + line_height * current_line++), + paxs::Vector2{bounds.x(), bounds.y() + line_height * current_line++}, color ); break; @@ -305,7 +304,7 @@ namespace paxs { std::string line_text = remaining_text.substr(0, actual_split); font->draw( line_text.c_str(), - paxg::Vec2i(bounds.x(), bounds.y() + line_height * current_line++), + paxs::Vector2{bounds.x(), bounds.y() + line_height * current_line++}, color ); @@ -406,7 +405,7 @@ namespace paxs { if (title_text) { font->draw( *title_text, - paxg::Vec2i(text_x, text_y + line_height * current_line++), + paxs::Vector2{text_x, text_y + line_height * current_line++}, paxg::Color(0, 0, 0) ); } @@ -461,12 +460,11 @@ namespace paxs { }; for (const auto& col : known_columns) { - const auto iterator = extra_data_.find(col.data_hash); - if (iterator != extra_data_.end()) { + const auto* const ptr = extra_data_.try_get(col.data_hash); + if (ptr != nullptr) { const std::string* label = Fonts().getLocalesText(feature_info_domain_hash, col.label_key); if (label) { - const std::string display_text = *label + ": " + iterator->second; - + const std::string display_text = *label + ": " + *ptr; drawWrappedText( font, display_text, diff --git a/Library/PAX_MAHOROBA/UI/LoadingProgressBar.hpp b/Library/PAX_MAHOROBA/UI/LoadingProgressBar.hpp index c8ba38a82..b284f8b90 100644 --- a/Library/PAX_MAHOROBA/UI/LoadingProgressBar.hpp +++ b/Library/PAX_MAHOROBA/UI/LoadingProgressBar.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -124,13 +123,13 @@ namespace paxs { // パーセンテージをバーの中央に描画 / Draw percentage in center of bar const int text_x = x_ + (width_ / 2); const int text_y = y_ + (height_ / 2); - font_->drawAt(percent_text, paxg::Vec2i{text_x, text_y}, text_color_); + font_->drawAt(percent_text, paxs::Vector2{text_x, text_y}, text_color_); // メッセージをバーの下に描画 / Draw message below bar if (!message.empty()) { const int msg_x = x_ + (width_ / 2); const int msg_y = y_ + height_ + 20; - font_->drawAt(message, paxg::Vec2i{msg_x, msg_y}, text_color_); + font_->drawAt(message, paxs::Vector2{msg_x, msg_y}, text_color_); } } @@ -140,7 +139,7 @@ namespace paxs { const std::string error_text = "Error occurred during loading"; const int error_x = x_ + (width_ / 2); const int error_y = y_ + height_ + 50; - font_->drawAt(error_text, paxg::Vec2i{error_x, error_y}, paxg::Color{255, 50, 50, 255}); + font_->drawAt(error_text, paxs::Vector2{error_x, error_y}, paxg::Color{255, 50, 50, 255}); } } } diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/DropDownMenu.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/DropDownMenu.hpp index 41d241ca2..dd26c22af 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/DropDownMenu.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/DropDownMenu.hpp @@ -51,7 +51,7 @@ namespace paxs { // 描画定数 static constexpr float arrow_radius = 8.0f; static constexpr float arrow_rotation_pi = 3.15f; // π radians (down) ずれるので少し大きめに - static constexpr paxg::Vec2i shadow_offset{ 1, 1 }; + static constexpr paxs::Vector2 shadow_offset{ 1, 1 }; static constexpr int shadow_blur_radius = 4; static constexpr int shadow_spread = 1; @@ -68,7 +68,7 @@ namespace paxs { // レイアウト paxg::Rect rect; - paxg::Vec2i padding{ default_padding_x, default_padding_y }; + paxs::Vector2 padding{ default_padding_x, default_padding_y }; float all_rect_width{}; // 全ての項目の文字幅 // 状態 @@ -86,12 +86,12 @@ namespace paxs { const std::span items_key_, std::uint_least8_t font_size_, std::uint_least8_t font_buffer_thickness_size_, - const paxg::Vec2i& pos_ = { 0, 0 }) + const paxs::Vector2& pos_ = { 0, 0 }) { items_key = items_key_; font_size = font_size_; font_buffer_thickness_size = font_buffer_thickness_size_; - rect = paxg::Rect{ static_cast(pos_.x()), static_cast(pos_.y()), 0, 0 }; + rect = paxg::Rect{ static_cast(pos_.x), static_cast(pos_.y), 0, 0 }; updateLanguage(); @@ -116,7 +116,7 @@ namespace paxs { rect.setH(static_cast(font_size) * 2.f); } else { - const float height = static_cast(((*one_font).height()) + padding.y() * 2); + const float height = static_cast(((*one_font).height()) + padding.y * 2); rect.setH(height); } @@ -137,8 +137,8 @@ namespace paxs { } } - rect.setW(rect.w() + (padding.x() * 2 + down_button_size)); - all_rect_width += (padding.x() * 2 + down_button_size); + rect.setW(rect.w() + (padding.x * 2 + down_button_size)); + all_rect_width += (padding.x * 2 + down_button_size); // チェックマークの幅を追加 all_rect_width += checkmark_width; @@ -154,8 +154,8 @@ namespace paxs { /// @brief 入力処理( EventHandlingResult handleEvent(const MouseEvent& event) override { - paxg::Vec2i pos = rect.pos(); - pos.setY((int)(pos.y() + rect.h())); + paxs::Vector2 pos = rect.pos(); + pos.y += rect.h(); for (std::size_t i = 1; i < items_key.size(); ++i) { const paxg::Rect item_rect{ pos, all_rect_width, rect.h() }; @@ -174,7 +174,7 @@ namespace paxs { visible_ = false; return EventHandlingResult::Handled(); } - pos.setY((int)(pos.y() + rect.h())); + pos.y += rect.h(); } return EventHandlingResult::NotHandled(); } @@ -191,7 +191,7 @@ namespace paxs { // 下向き三角形を描画 static constexpr paxg::TriangleShape down_arrow_shape(arrow_radius, arrow_rotation_pi); - const float center_x = static_cast(rect.x() + rect.w() - down_button_size / 2.0 - padding.x()); + const float center_x = static_cast(rect.x() + rect.w() - down_button_size / 2.0 - padding.x); const float center_y = static_cast(rect.y() + rect.h() / 2.0); paxg::Triangle triangle(center_x, center_y, down_arrow_shape); triangle.draw(paxg::Color{ 0, 0, 0 }); @@ -255,18 +255,18 @@ namespace paxs { /// @brief 項目の状態を取得(キー指定) bool getIsItems(const std::uint_least32_t key) const { - if (!item_index_key.contains(key)) { + const std::size_t* const index_ptr = item_index_key.try_get(key); + if (index_ptr == nullptr) { PAXS_WARNING("DropDownMenu: Key not found in item_index_key."); return true; } - const std::size_t index = item_index_key.at(key); // キーで取得する場合、インデックスは既に正しい位置を指しているので // ヘッダー(インデックス0)を参照している場合のみスキップ - if (index == 0) { + if (*index_ptr == 0) { return true; // ヘッダー自体は常にtrue } - if (index < is_items.size()) { - return is_items[index]; + if (*index_ptr < is_items.size()) { + return is_items[*index_ptr]; } return is_items.front(); } @@ -277,11 +277,13 @@ namespace paxs { PAXS_WARNING("DropDownMenu: No items to check for key."); return true; // データがない場合 } - if (!item_index_key.contains(key)) { + + const std::size_t* const index_ptr = item_index_key.try_get(key); + if (index_ptr == nullptr) { PAXS_WARNING("DropDownMenu: Key not found in item_index_key."); return true; // 引数の Key が存在しない場合 } - return getIsItems(item_index_key.at(key)); + return getIsItems(*index_ptr); } bool isHitHeader(int x, int y) const { @@ -297,21 +299,21 @@ namespace paxs { // ヘッダーは親(MenuSystem)が判定するのでここでは見ない - paxg::Vec2i pos = rect.pos(); - pos.setY((int)(pos.y() + rect.h())); + paxs::Vector2 pos = rect.pos(); + pos.y += rect.h(); for (std::size_t i = 1; i < items_key.size(); ++i) { const paxg::Rect item_rect{ pos, all_rect_width, rect.h() }; if (item_rect.contains((float)mouse_pos.x, (float)mouse_pos.y)) { return true; } - pos.setY((int)(pos.y() + rect.h())); + pos.y += rect.h(); } return false; } void setPos(const Vector2& pos) override { - rect.setPos(paxg::Vec2i(pos.x, pos.y)); + rect.setPos(pos); } Rect getRect() const override { return { @@ -349,14 +351,14 @@ namespace paxs { (*one_font).draw( *str, - paxg::Vec2i(static_cast(rect.x() + padding.x()), static_cast(rect.y() + padding.y())), + paxs::Vector2(static_cast(rect.x()) + padding.x, static_cast(rect.y()) + padding.y), paxg::Color{ 0, 0, 0 }); } /// @brief ドロップダウンリストを描画(チェックマーク付き) void drawDropdownList() const { - paxg::Vec2i pos = rect.pos(); - pos.setY(static_cast(pos.y() + rect.h())); + paxs::Vector2 pos = rect.pos(); + pos.y += rect.h(); // 最初の項目(ヘッダー)をスキップ const std::size_t display_item_count = items_key.size() - 1; @@ -374,14 +376,14 @@ namespace paxs { // チェックマークを描画(ONの場合のみ) if (i < is_items.size() && is_items[i]) { - const int check_x = pos.x() + checkmark_x_offset; + const int check_x = pos.x + checkmark_x_offset; // シンプルなチェックマーク "✓" を描画 paxg::Font* check_font = Fonts().getFont(font_size, font_buffer_thickness_size); if (check_font != nullptr) { (*check_font).draw( reinterpret_cast(u8"✓"), - paxg::Vec2i(check_x, pos.y() + padding.y()), + paxs::Vector2(check_x, pos.y + padding.y), paxg::Color{ 0, 0, 0 }); } } @@ -392,9 +394,9 @@ namespace paxs { (*one_font).draw( *i_str, - paxg::Vec2i(pos.x() + padding.x() + checkmark_width, pos.y() + padding.y()), + paxs::Vector2(pos.x + padding.x + checkmark_width, pos.y + padding.y), paxg::Color{ 0, 0, 0 }); - pos.setY(static_cast(pos.y() + rect.h())); + pos.y += rect.h(); } back_rect.drawFrame(1, 0, paxg::Color{ 128, 128, 128 }); diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp index 3bcfbcf71..680e3f05e 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/GitHubButton.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp index e7f5b73a3..14979e1c8 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/MenuBar.hpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -43,7 +42,7 @@ namespace paxs { public: MenuBar(const paxs::FeatureVisibilityManager& visible_manager) : language_selector_(paxs::MurMur3::calcHash("Language"), - paxg::Vec2i{ 3000, 0 }, + paxs::Vector2{ 3000, 0 }, paxs::PulldownDisplayType::SelectedValue, true ) { diff --git a/Library/PAX_MAHOROBA/UI/MenuBar/MenuSystem.hpp b/Library/PAX_MAHOROBA/UI/MenuBar/MenuSystem.hpp index bc0644e76..fdccb1372 100644 --- a/Library/PAX_MAHOROBA/UI/MenuBar/MenuSystem.hpp +++ b/Library/PAX_MAHOROBA/UI/MenuBar/MenuSystem.hpp @@ -69,11 +69,11 @@ namespace paxs { start_x += menu_list.back().getRect().width(); } menu_list_key.emplace(menu_type_, menu_list.size()); - menu_list.emplace_back(paxs::DropDownMenu( + menu_list.emplace_back( items_key_, font_size_, font_buffer_thickness_size_, - paxg::Vec2i{ start_x, 0 })); + paxs::Vector2{ start_x, 0 }); layout(); } diff --git a/Library/PAX_MAHOROBA/UI/Pulldown.hpp b/Library/PAX_MAHOROBA/UI/Pulldown.hpp index 531b34528..dc800dca0 100644 --- a/Library/PAX_MAHOROBA/UI/Pulldown.hpp +++ b/Library/PAX_MAHOROBA/UI/Pulldown.hpp @@ -57,7 +57,7 @@ namespace paxs { const std::uint_least32_t domain_hash{}; // ドメイン名のハッシュ値 size_t index = 0; - paxg::Vec2i padding{ default_padding_x, default_padding_y }; + paxs::Vector2 padding{ default_padding_x, default_padding_y }; float all_rect_x{}; // 全ての項目の文字幅 bool is_open = false; @@ -99,7 +99,7 @@ namespace paxs { rect.setH(static_cast(paxg::FontConfig::PULLDOWN_FONT_SIZE) * 2.f); } else { - const float height = static_cast(((*one_font).height()) + (padding.y() * 2)); + const float height = static_cast(((*one_font).height()) + (padding.y * 2)); rect.setH(height); } @@ -142,8 +142,8 @@ namespace paxs { } } // プルダウンの幅を設定 - rect.setW(rect.w() + (padding.x() * 2 + down_button_size)); - all_rect_x += (padding.x() * 2 + down_button_size); + rect.setW(rect.w() + (padding.x * 2 + down_button_size)); + all_rect_x += (padding.x * 2 + down_button_size); #ifdef PAXS_USING_DXLIB #ifdef PAXS_PLATFORM_ANDROID @@ -211,9 +211,7 @@ namespace paxs { // ドロップダウン項目(開いている場合) if (is_open) { - paxg::Vec2i pos = paxg::Vec2i( - rect_x, - rect_y + rect_h); + paxs::Vector2 pos{static_cast(rect_x), static_cast(rect_y + rect_h)}; for (std::size_t i = 0; i < items_key.size(); ++i) { const paxg::Rect rect_tmp{ pos, rect.w(), rect.h() }; int rtx = static_cast(rect_tmp.x()); @@ -223,7 +221,7 @@ namespace paxs { if (event.pos.x >= rtx && event.pos.x < rtx + rtw && event.pos.y >= rty && event.pos.y < rty + rth) { return EventHandlingResult::Handled(); } - pos.setY(pos.y() + rect_h); + pos.y += rect_h; } } } @@ -243,9 +241,7 @@ namespace paxs { // ドロップダウン項目をクリック(開いている場合) if (is_open) { - paxg::Vec2i pos = paxg::Vec2i( - rect_x, - rect_y + rect_h); + paxs::Vector2 pos{static_cast(rect_x), static_cast(rect_y + rect_h)}; for (std::size_t i = 0; i < items_key.size(); ++i) { const paxg::Rect rect_tmp{ pos, rect.w(), rect.h() }; int rtx = static_cast(rect_tmp.x()); @@ -271,7 +267,7 @@ namespace paxs { return EventHandlingResult::Handled(); } } - pos.setY(pos.y() + rect_h); + pos.y += rect_h; } } } @@ -294,12 +290,12 @@ namespace paxs { // 三角形を描画(下向き▼) static constexpr paxg::TriangleShape down_arrow_shape(arrow_radius, arrow_rotation_pi); - const float center_x = static_cast(rect.x() + rect.w() - down_button_size / 2.0 - padding.x()); + const float center_x = static_cast(rect.x() + rect.w() - down_button_size / 2.0 - padding.x); const float center_y = static_cast(rect.y() + rect.h() / 2.0); paxg::Triangle triangle(center_x, center_y, down_arrow_shape); triangle.draw(paxg::Color{ 0, 0, 0 }); - paxg::Vec2i pos = rect.pos(); + paxs::Vector2 pos = rect.pos(); const std::uint_least32_t select_key = (is_one_font ? items_key[item_index] : Fonts().getSelectedLanguageKey()); @@ -319,7 +315,8 @@ namespace paxs { // 文字を描画 (*one_font).draw( *str, - paxg::Vec2i(pos.x() + padding.x(), pos.y() + padding.y()), paxg::Color{ 0, 0, 0 }); + paxs::Vector2(pos) + padding, + paxg::Color{ 0, 0, 0 }); } else { const std::string* str0 = nullptr; @@ -333,10 +330,11 @@ namespace paxs { // 文字を描画 (*one_font).draw( *str0, - paxg::Vec2i(pos.x() + padding.x(), pos.y() + padding.y()), paxg::Color{ 0, 0, 0 }); + paxs::Vector2(pos) + padding, + paxg::Color{ 0, 0, 0 }); } - pos.setY(static_cast(pos.y() + rect.h())); + pos.y += rect.h(); if (!is_open) return; // 四角形を描画 @@ -366,8 +364,10 @@ namespace paxs { // 文字を描画 (*one_font).draw( *i_str, - paxg::Vec2i(pos.x() + padding.x(), pos.y() + padding.y()), paxg::Color{ 0, 0, 0 }); - pos.setY(static_cast(pos.y() + rect.h())); + paxs::Vector2(pos) + padding, + paxg::Color{ 0, 0, 0 } + ); + pos.y += rect.h(); } // ふちを描画 back_rect.drawFrame(1, 0, paxg::Color{ 128, 128, 128 }); @@ -392,9 +392,9 @@ namespace paxs { PAXS_WARNING("Pulldown::getIsItemsKey: No items available."); return true; // データがない場合 } - const auto iterator = item_index_key.find(key); - if (iterator == item_index_key.end()) return true; // 引数の Key が存在しない場合 - return getIsItems(iterator->second); + const auto* const ptr = item_index_key.try_get(key); + if (ptr == nullptr) return true; // 引数の Key が存在しない場合 + return getIsItems(*ptr); } std::uint_least32_t getKey() const { return items_key[index]; } @@ -418,16 +418,15 @@ namespace paxs { if (is_open) { // ドロップダウン項目の幅は all_rect_x(全項目中の最大幅) const float item_width = all_rect_x; - paxg::Vec2i pos = paxg::Vec2i( - static_cast(header_rect.x()), - static_cast(header_rect.y() + header_rect.h())); + paxs::Vector2 pos{header_rect.x(), + header_rect.y() + header_rect.h()}; for (std::size_t i = 0; i < items_key.size(); ++i) { const paxg::Rect item_rect{ pos, item_width, header_rect.h() }; if (item_rect.contains(mouse_pos)) { return true; } - pos.setY(static_cast(pos.y() + header_rect.h())); + pos.y += header_rect.h(); } } @@ -435,7 +434,7 @@ namespace paxs { } void setPos(const Vector2& pos) override { - rect.setPos(paxg::Vec2i(pos.x, pos.y)); + rect.setPos(pos); } Rect getRect() const override { return { diff --git a/Library/PAX_MAHOROBA/UI/Simulation/SettlementStatusPanel.hpp b/Library/PAX_MAHOROBA/UI/Simulation/SettlementStatusPanel.hpp index cf6841761..74b76eba4 100644 --- a/Library/PAX_MAHOROBA/UI/Simulation/SettlementStatusPanel.hpp +++ b/Library/PAX_MAHOROBA/UI/Simulation/SettlementStatusPanel.hpp @@ -13,7 +13,6 @@ #define PAX_MAHOROBA_UI_SETTLEMENT_STATUS_PANEL_HPP #include -#include #include #include diff --git a/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp b/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp index 2744486c9..773150aaa 100644 --- a/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp +++ b/Library/PAX_MAHOROBA/UI/Simulation/SimulationPanel.hpp @@ -156,7 +156,7 @@ namespace paxs { #endif simulation_pulldown( paxs::MurMur3::calcHash("SimulationModels"), - paxg::Vec2i{3000, 0}, + paxs::Vector2{3000, 0}, paxs::PulldownDisplayType::SelectedValue, false ) diff --git a/Library/PAX_MAHOROBA/UI/Simulation/SimulationStatsWidget.hpp b/Library/PAX_MAHOROBA/UI/Simulation/SimulationStatsWidget.hpp index 2cc5ef93f..42aa24927 100644 --- a/Library/PAX_MAHOROBA/UI/Simulation/SimulationStatsWidget.hpp +++ b/Library/PAX_MAHOROBA/UI/Simulation/SimulationStatsWidget.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -65,13 +64,13 @@ namespace paxs { if (population_label != nullptr) { font->draw( *population_label + ": ", - paxg::Vec2i(pos_.x, pos_.y + (line_height_ * current_line)), + paxs::Vector2{pos_.x, pos_.y + (line_height_ * current_line)}, paxg::Color(0, 0, 0) ); } font->draw( std::to_string(simulation_manager_.getPopulation()), - paxg::Vec2i(pos_.x + label_width_, pos_.y + (line_height_ * current_line++)), + paxs::Vector2{pos_.x + label_width_, pos_.y + (line_height_ * current_line++)}, paxg::Color(0, 0, 0) ); @@ -80,13 +79,13 @@ namespace paxs { if (settlements_label != nullptr) { font->draw( *settlements_label + ": ", - paxg::Vec2i(pos_.x, pos_.y + (line_height_ * current_line)), + paxs::Vector2{pos_.x, pos_.y + (line_height_ * current_line)}, paxg::Color(0, 0, 0) ); } font->draw( std::to_string(simulation_manager_.getSettlementCount()), - paxg::Vec2i(pos_.x + label_width_, pos_.y + (line_height_ * current_line++)), + paxs::Vector2{pos_.x + label_width_, pos_.y + (line_height_ * current_line++)}, paxg::Color(0, 0, 0) ); @@ -95,13 +94,13 @@ namespace paxs { if (migration_label != nullptr) { font->draw( *migration_label + ": ", - paxg::Vec2i(pos_.x, pos_.y + (line_height_ * current_line)), + paxs::Vector2{pos_.x, pos_.y + (line_height_ * current_line)}, paxg::Color(0, 0, 0) ); } font->draw( std::to_string(simulation_manager_.getMigrationCount()), - paxg::Vec2i(pos_.x + label_width_, pos_.y + (line_height_ * current_line++)), + paxs::Vector2{pos_.x + label_width_, pos_.y + (line_height_ * current_line++)}, paxg::Color(0, 0, 0) ); @@ -110,7 +109,7 @@ namespace paxs { if (tfr_label != nullptr) { font->draw( *tfr_label + ": ", - paxg::Vec2i(pos_.x, pos_.y + (line_height_ * current_line)), + paxs::Vector2{pos_.x, pos_.y + (line_height_ * current_line)}, paxg::Color(0, 0, 0) ); } @@ -119,7 +118,7 @@ namespace paxs { oss << std::fixed << std::setprecision(2) << simulation_manager_.getTotalFertilityRate(); font->draw( oss.str(), - paxg::Vec2i(pos_.x + label_width_, pos_.y + (line_height_ * current_line++)), + paxs::Vector2{pos_.x + label_width_, pos_.y + (line_height_ * current_line++)}, paxg::Color(0, 0, 0) ); } diff --git a/Library/PAX_MAHOROBA/UI/Widget/IconButton.hpp b/Library/PAX_MAHOROBA/UI/Widget/IconButton.hpp index 6a326f829..604803758 100644 --- a/Library/PAX_MAHOROBA/UI/Widget/IconButton.hpp +++ b/Library/PAX_MAHOROBA/UI/Widget/IconButton.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include @@ -38,7 +37,9 @@ namespace paxs { loadIconTextures(); } if (!icon_textures.isSuccessfullyLoaded()) return; - if (!icon_textures.contains(icon_texture_path_hash)) return; + + const paxg::Texture* const icon_texture_ptr = icon_textures.try_get(icon_texture_path_hash); + if (icon_texture_ptr == nullptr) return; // ボタン状態に応じた背景を描画(3pxのマージン付き) constexpr int margin = 3; @@ -64,9 +65,7 @@ namespace paxs { } // アイコンを描画 - icon_textures.at(icon_texture_path_hash).resizedDraw(rect.width(), - paxg::Vec2i{ rect.x(), rect.y() } - ); + icon_texture_ptr->resizedDraw(rect.width(), rect.position()); is_hovered = false; is_pressed = false; @@ -89,10 +88,10 @@ namespace paxs { Rect getRect() const override { return rect; } const char* getName() const override { return name; } bool isVisible() const override { return true; } - void setPos(const Vector2& pos) override { rect.position = pos; } + void setPos(const Vector2& pos) override { rect.pos_ = pos; } protected: - void setSize(const Vector2& size) { rect.size = size; } + void setSize(const Vector2& size) { rect.sz_ = size; } private: const std::uint_least32_t icon_texture_path_hash; diff --git a/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp b/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp index d9dcd4a91..f296ed1d1 100644 --- a/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp +++ b/Library/PAX_MAHOROBA/UI/Widget/UIPanelBackground.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/Library/PAX_SAPIENTICA/Core/Type/Rect.hpp b/Library/PAX_SAPIENTICA/Core/Type/Rect.hpp index f969ac7bc..2f5d104e2 100644 --- a/Library/PAX_SAPIENTICA/Core/Type/Rect.hpp +++ b/Library/PAX_SAPIENTICA/Core/Type/Rect.hpp @@ -20,36 +20,38 @@ namespace paxs { /// @brief 矩形を表すクラス(位置とサイズ) template struct Rect { - Vector2 position{}; // 左上の座標 (x, y) / Top-left position (x, y) - Vector2 size{}; // サイズ (width, height) / Size (width, height) + Vector2 pos_{}; // 左上の座標 (x, y) / Top-left position (x, y) + Vector2 sz_{}; // サイズ (width, height) / Size (width, height) constexpr Rect() noexcept = default; constexpr Rect(T x, T y, T width, T height) noexcept - : position(x, y), size(width, height) {} + : pos_(x, y), sz_(width, height) {} constexpr Rect(const Vector2& pos, const Vector2& sz) noexcept - : position(pos), size(sz) {} + : pos_(pos), sz_(sz) {} // Getters - [[nodiscard]] constexpr T x() const noexcept { return position.x; } - [[nodiscard]] constexpr T y() const noexcept { return position.y; } - [[nodiscard]] constexpr T width() const noexcept { return size.x; } - [[nodiscard]] constexpr T height() const noexcept { return size.y; } + [[nodiscard]] constexpr T x() const noexcept { return pos_.x; } + [[nodiscard]] constexpr T y() const noexcept { return pos_.y; } + [[nodiscard]] constexpr T width() const noexcept { return sz_.x; } + [[nodiscard]] constexpr T height() const noexcept { return sz_.y; } + [[nodiscard]] constexpr Vector2 position() const noexcept { return pos_; } + [[nodiscard]] constexpr Vector2 size() const noexcept { return sz_; } // Computed properties - [[nodiscard]] constexpr T left() const noexcept { return position.x; } - [[nodiscard]] constexpr T top() const noexcept { return position.y; } - [[nodiscard]] constexpr T right() const noexcept { return position.x + size.x; } - [[nodiscard]] constexpr T bottom() const noexcept { return position.y + size.y; } + [[nodiscard]] constexpr T left() const noexcept { return pos_.x; } + [[nodiscard]] constexpr T top() const noexcept { return pos_.y; } + [[nodiscard]] constexpr T right() const noexcept { return pos_.x + sz_.x; } + [[nodiscard]] constexpr T bottom() const noexcept { return pos_.y + sz_.y; } - [[nodiscard]] constexpr Vector2 topLeft() const noexcept { return position; } + [[nodiscard]] constexpr Vector2 topLeft() const noexcept { return pos_; } [[nodiscard]] constexpr Vector2 topRight() const noexcept { return Vector2(right(), top()); } [[nodiscard]] constexpr Vector2 bottomLeft() const noexcept { return Vector2(left(), bottom()); } [[nodiscard]] constexpr Vector2 bottomRight() const noexcept { return Vector2(right(), bottom()); } [[nodiscard]] constexpr Vector2 center() const noexcept { - return Vector2(position.x + (size.x / 2), position.y + (size.y / 2)); + return Vector2(pos_.x + (sz_.x / 2), pos_.y + (sz_.y / 2)); } // Point containment check @@ -77,10 +79,10 @@ namespace paxs { /// @brief マージン付き矩形を作成 [[nodiscard]] constexpr Rect expanded(T margin) const noexcept { return Rect( - position.x - margin, - position.y - margin, - size.x + (margin * 2), - size.y + (margin * 2) + pos_.x - margin, + pos_.y - margin, + sz_.x + (margin * 2), + sz_.y + (margin * 2) ); } @@ -114,10 +116,10 @@ namespace paxs { template [[nodiscard]] Rect toType() const noexcept { return Rect( - static_cast(position.x), - static_cast(position.y), - static_cast(size.x), - static_cast(size.y) + static_cast(pos_.x), + static_cast(pos_.y), + static_cast(sz_.x), + static_cast(sz_.y) ); } }; diff --git a/Library/PAX_SAPIENTICA/Core/Type/UnorderedMap.hpp b/Library/PAX_SAPIENTICA/Core/Type/UnorderedMap.hpp index 97a5e2c7e..81f3cea7f 100644 --- a/Library/PAX_SAPIENTICA/Core/Type/UnorderedMap.hpp +++ b/Library/PAX_SAPIENTICA/Core/Type/UnorderedMap.hpp @@ -136,7 +136,6 @@ namespace paxs { return map_.find(key) != map_.end(); } - /// @brief 要素を検索 iterator find(const Key& key) { return map_.find(key); diff --git a/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp b/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp index 68ac8480c..7fdbc27f5 100644 --- a/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp +++ b/Library/PAX_SAPIENTICA/Core/Type/Vector2.hpp @@ -82,6 +82,11 @@ namespace paxs { return *this; } + template + explicit constexpr operator Vector2() const noexcept { + return Vector2(static_cast(x), static_cast(y)); + } + auto operator<=>(const Vector2& v) const noexcept = default; /// @brief Get the length of the vector /// @brief べクトルの長さを取得。 diff --git a/Library/PAX_SAPIENTICA/Geography/Coordinate/WrappedScreenPositions.hpp b/Library/PAX_SAPIENTICA/Geography/Coordinate/WrappedScreenPositions.hpp index f2df0c02a..5d2491c7f 100644 --- a/Library/PAX_SAPIENTICA/Geography/Coordinate/WrappedScreenPositions.hpp +++ b/Library/PAX_SAPIENTICA/Geography/Coordinate/WrappedScreenPositions.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include namespace paxs { @@ -34,12 +34,16 @@ struct WrappedScreenPositions { /// @brief 3つのスクリーン座標(-360°, 0°, +360°) /// @brief Three screen positions (-360°, 0°, +360°) - std::array, POSITION_COUNT> positions; + std::array, POSITION_COUNT> positions; /// @brief 有効な座標を持つかどうか(clear()で無効化、toScreenPositions()で有効化) /// @brief Whether this holds valid positions (invalidated by clear(), validated by toScreenPositions()) bool is_valid = false; + /// @brief デフォルトコンストラクタ + /// @brief Default constructor + WrappedScreenPositions() noexcept {} + // ========== イテレータサポート(既存コードとの互換性) ========== // Iterator support (for compatibility with existing code) @@ -51,11 +55,11 @@ struct WrappedScreenPositions { // ========== 配列的アクセス ========== // Array-like access - const paxg::Vec2& operator[](std::size_t i) const noexcept { + const paxs::Vector2& operator[](std::size_t i) const noexcept { return positions[i]; } - paxg::Vec2& operator[](std::size_t i) noexcept { + paxs::Vector2& operator[](std::size_t i) noexcept { return positions[i]; } diff --git a/Library/PAX_SAPIENTICA/IO/Data/KeyValueTSV.hpp b/Library/PAX_SAPIENTICA/IO/Data/KeyValueTSV.hpp index ae4274b2c..09f23d687 100644 --- a/Library/PAX_SAPIENTICA/IO/Data/KeyValueTSV.hpp +++ b/Library/PAX_SAPIENTICA/IO/Data/KeyValueTSV.hpp @@ -35,17 +35,13 @@ namespace paxs { // 項目の ID を返す std::size_t inputPathGetMenuIndex(const paxs::UnorderedMap& menu, const std::uint_least32_t& str_) { - const auto iterator = menu.find(str_); - return iterator != menu.end() ? iterator->second : SIZE_MAX; + return menu.value_or(str_, SIZE_MAX); } public: void emplace(const std::uint_least32_t key_, const Value& value_) { path_list.emplace(key_, value_); } - bool contains(const std::uint_least32_t key_) const { - return path_list.contains(key_); - } UnorderedMap& get() { return path_list; @@ -126,12 +122,10 @@ namespace paxs { return path_list.at(key_); } - /// @brief 要素にアクセス、存在しない場合はデフォルト値のコピーを返す - Value getOrDefault(std::uint_least32_t key_) const { - const auto iterator = path_list.find(key_); - return iterator != path_list.end() ? iterator->second : Value{}; + /// @brief 要素にアクセス、存在しない場合は nullptr を返す + const Value* try_get(std::uint_least32_t key_) const { + return path_list.try_get(key_); } - }; } diff --git a/Library/PAX_SAPIENTICA/IO/Data/TsvTable.hpp b/Library/PAX_SAPIENTICA/IO/Data/TsvTable.hpp index 0af8e4478..4530884ee 100644 --- a/Library/PAX_SAPIENTICA/IO/Data/TsvTable.hpp +++ b/Library/PAX_SAPIENTICA/IO/Data/TsvTable.hpp @@ -151,8 +151,7 @@ namespace paxs { /// @param column_key Column key (MurMur3 hash) / カラムキー(MurMur3ハッシュ) /// @return Column index, or SIZE_MAX if not found / カラムインデックス、見つからない場合はSIZE_MAX std::size_t getColumnIndex(const std::uint_least32_t column_key) const { - const auto iterator = header_map_.find(column_key); - return (iterator != header_map_.end()) ? iterator->second : SIZE_MAX; + return header_map_.value_or(column_key, SIZE_MAX); } /// @brief Get cell value by row and column index diff --git a/Library/PAX_SAPIENTICA/Map/LocationPoint.hpp b/Library/PAX_SAPIENTICA/Map/LocationPoint.hpp index 6b99fff4b..cc34ee0ff 100644 --- a/Library/PAX_SAPIENTICA/Map/LocationPoint.hpp +++ b/Library/PAX_SAPIENTICA/Map/LocationPoint.hpp @@ -59,8 +59,8 @@ namespace paxs { /// @brief 追加カラムの値を取得(ハッシュ値で直接アクセス) /// @brief Get extra column value by hash std::string getExtraData(std::uint_least32_t column_hash) const { - const auto iterator = extra_data.find(column_hash); - return (iterator != extra_data.end()) ? iterator->second : ""; + const auto* const ptr = extra_data.try_get(column_hash); + return (ptr != nullptr) ? *ptr : ""; } /// @brief 追加カラムが存在するか確認(ハッシュ値) diff --git a/Library/PAX_SAPIENTICA/Map/Tile/TileCache.hpp b/Library/PAX_SAPIENTICA/Map/Tile/TileCache.hpp index 7d454b3f0..8e7ca4b9b 100644 --- a/Library/PAX_SAPIENTICA/Map/Tile/TileCache.hpp +++ b/Library/PAX_SAPIENTICA/Map/Tile/TileCache.hpp @@ -138,13 +138,12 @@ namespace paxs { /// @param key エンコードされたキー /// @return テクスチャへのポインタ(存在しない場合はnullptr) const TextureType* getTextureConst(std::uint_least64_t key) const { - const auto iterator = cache_map_.find(key); - if (iterator == cache_map_.end()) return nullptr; - - const CacheEntry& entry = iterator->second; - if (!entry.texture.has_value()) return nullptr; + const auto* const ptr = cache_map_.try_get(key); + if (ptr == nullptr || !ptr->texture.has_value()) { + return nullptr; + } - return &(entry.texture.value()); + return &(ptr->texture.value()); } /// @brief 指定座標のテクスチャを取得(const版、LRU更新なし) diff --git a/Library/PAX_SAPIENTICA/Simulation/Config/SimulationConst.hpp b/Library/PAX_SAPIENTICA/Simulation/Config/SimulationConst.hpp index cb7372796..daf1859ba 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Config/SimulationConst.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Config/SimulationConst.hpp @@ -219,9 +219,9 @@ namespace paxs { private: template void stoiFunc(KeyValueTSV& key_value_tsv_, const std::uint_least32_t key_, Func_&& func_) { - const std::string str = key_value_tsv_.getOrDefault(key_); - if (str.size() == 0) return; - func_(str); + const auto* const ptr = key_value_tsv_.try_get(key_); + if (ptr == nullptr || ptr->size() == 0) return; + func_(*ptr); } public: diff --git a/Library/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulator.hpp index d81be59d7..337380563 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulator.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulator.hpp @@ -759,7 +759,7 @@ namespace paxs { Live& live = (*live_list)[district_id]; while (live.live_probabilities.size() > 0 && // 集落を配置し切るまで - district_population_map.find(district_id) != district_population_map.end() // 地区が残っている間 + district_population_map.contains(district_id) // 地区が残っている間 ) { if (step_count == 0) { if (progress_reporter_ != nullptr) { @@ -778,19 +778,16 @@ namespace paxs { const int live_probability_index = live_probability_dist(gen); const Vector2 live_position = Vector2::from(live.habitable_land_positions[live_probability_index]); - auto district_population_it = district_population_map.find(district_id); - if (district_population_it == district_population_map.end()) { - live.live_probabilities[live_probability_index] = live.live_probabilities.back(); - live.live_probabilities.pop_back(); - live.habitable_land_positions[live_probability_index] = live.habitable_land_positions.back(); - live.habitable_land_positions.pop_back(); + auto* const district_population_ptr = district_population_map.try_get(district_id); + if (district_population_ptr == nullptr) { + PAXS_WARNING("District population not found. District ID: " + std::to_string(district_id)); continue; } // 配置する集落の人口を決定 paxs::District district = japan_provinces->getDistrict(district_id); int settlement_population = std::uniform_int_distribution<>(district.settlement_pop_min, district.settlement_pop_max)(gen); - settlement_population = (std::min)(settlement_population, static_cast(district_population_it->second)); + settlement_population = (std::min)(settlement_population, static_cast(*district_population_ptr)); // 集落をグリッドに配置 Vector2 grid_position = live_position / SimulationConstants::getInstance().cell_group_length; @@ -816,9 +813,9 @@ namespace paxs { } // 地区の人口を減らす - district_population_it->second -= settlement_population; - if (district_population_it->second == 0) { - district_population_map.erase(district_population_it); + *district_population_ptr -= settlement_population; + if (*district_population_ptr == 0) { + district_population_map.erase(district_id); } if (step_count == 0) { population_sum += settlement_population; diff --git a/Library/PAX_SAPIENTICA/System/AppConfig.hpp b/Library/PAX_SAPIENTICA/System/AppConfig.hpp index c922d95c8..289281a15 100644 --- a/Library/PAX_SAPIENTICA/System/AppConfig.hpp +++ b/Library/PAX_SAPIENTICA/System/AppConfig.hpp @@ -52,11 +52,12 @@ namespace paxs { } [[nodiscard]] std::string getSettingPath(const std::uint_least32_t key) const { - if (!data_settings.contains(key)) { + const std::string* const setting_ptr = data_settings.try_get(key); + if (setting_ptr == nullptr) { PAXS_WARNING("Data settings key " + std::to_string(key) + " not found."); return std::string{}; } - return data_settings.at(key); + return *setting_ptr; } template void ifSettingExists(const std::uint_least32_t key, Func_&& func) const { @@ -90,10 +91,11 @@ namespace paxs { // @brief 指定したキーのデータ設定が存在しているか [[nodiscard]] bool hasDataSettings(const std::uint_least32_t key_) const { - if (!data_settings.contains(key_)) { + const std::string* const setting_ptr = data_settings.try_get(key_); + if (setting_ptr == nullptr) { return false; } - return (data_settings.at(key_).size() != 0); + return (setting_ptr->size() != 0); } /// @brief TSVファイルから key-value ペアを全て読み込む @@ -167,7 +169,8 @@ namespace paxs { if (!loadAllKeyValueTSV(file_path, temp_map)) { return std::string{}; } - return temp_map.contains(target_key) ? temp_map.at(target_key) : std::string{}; + const std::string* const value_ptr = temp_map.try_get(target_key); + return (value_ptr != nullptr) ? *value_ptr : std::string{}; } }; diff --git a/Library/PAX_SAPIENTICA/System/EventBus.hpp b/Library/PAX_SAPIENTICA/System/EventBus.hpp index a1e816f1f..dd3aeba46 100644 --- a/Library/PAX_SAPIENTICA/System/EventBus.hpp +++ b/Library/PAX_SAPIENTICA/System/EventBus.hpp @@ -129,9 +129,9 @@ class EventBus { }; std::unique_lock lock(mutex_); // 書き込みロック - auto it = subscribers_.find(type_id); - if (it != subscribers_.end()) { - it->second.emplace_back(HandlerEntry{next_handler_id_++, wrapper}); + auto* const ptr = subscribers_.try_get(type_id); + if (ptr != nullptr) { + ptr->emplace_back(HandlerEntry{next_handler_id_++, wrapper}); } else { std::vector handlers; handlers.emplace_back(HandlerEntry{next_handler_id_++, wrapper}); @@ -157,9 +157,9 @@ class EventBus { handler(static_cast(event)); }; - auto it = subscribers_.find(type_id); - if (it != subscribers_.end()) { - it->second.emplace_back(HandlerEntry{handler_id, wrapper}); + auto* const ptr = subscribers_.try_get(type_id); + if (ptr != nullptr) { + ptr->emplace_back(HandlerEntry{handler_id, wrapper}); } else { std::vector handlers; handlers.emplace_back(HandlerEntry{handler_id, wrapper}); @@ -178,15 +178,14 @@ class EventBus { } std::unique_lock lock(mutex_); // 書き込みロック - auto it = subscribers_.find(handle.type_id); - if (it != subscribers_.end()) { - auto& handlers = it->second; - handlers.erase( - std::remove_if(handlers.begin(), handlers.end(), + auto* const ptr = subscribers_.try_get(handle.type_id); + if (ptr != nullptr) { + ptr->erase( + std::remove_if(ptr->begin(), ptr->end(), [handler_id = handle.handler_id](const HandlerEntry& entry) { return entry.id == handler_id; }), - handlers.end() + ptr->end() ); } } @@ -202,9 +201,9 @@ class EventBus { const std::type_index type_id(typeid(EventType)); std::shared_lock lock(mutex_); // 読み取りロック - const auto iterator = subscribers_.find(type_id); - if (iterator != subscribers_.end()) { - for (const auto& entry : iterator->second) { + const auto* const ptr = subscribers_.try_get(type_id); + if (ptr != nullptr) { + for (const auto& entry : *ptr) { entry.handler(event); } } @@ -231,9 +230,9 @@ class EventBus { const Event& event_ref = *event; const std::type_index type_id(typeid(event_ref)); - const auto iterator = subscribers_.find(type_id); - if (iterator != subscribers_.end()) { - for (const auto& entry : iterator->second) { + const auto* const ptr = subscribers_.try_get(type_id); + if (ptr != nullptr) { + for (const auto& entry : *ptr) { entry.handler(event_ref); } } @@ -252,8 +251,8 @@ class EventBus { const std::type_index type_id(typeid(EventType)); std::shared_lock lock(mutex_); // 読み取りロック - const auto iterator = subscribers_.find(type_id); - return iterator != subscribers_.end() ? iterator->second.size() : 0; + const auto* const ptr = subscribers_.try_get(type_id); + return ptr != nullptr ? ptr->size() : 0; } /// @brief キューのサイズを取得(デバッグ用) diff --git a/Library/PAX_SAPIENTICA/System/FeatureVisibilityManager.hpp b/Library/PAX_SAPIENTICA/System/FeatureVisibilityManager.hpp index 75673e49c..8cd90b1d6 100644 --- a/Library/PAX_SAPIENTICA/System/FeatureVisibilityManager.hpp +++ b/Library/PAX_SAPIENTICA/System/FeatureVisibilityManager.hpp @@ -47,9 +47,9 @@ namespace paxs { /// @brief 指定した機能の可視状態を反転(ハッシュ値版) /// @param feature_id 機能ID(ハッシュ値) void toggle(const std::uint_least32_t& feature_id) { - auto iterator = visible_features.find(feature_id); - if (iterator != visible_features.end()) { - iterator->second = !iterator->second; + auto* const ptr = visible_features.try_get(feature_id); + if (ptr != nullptr) { + *ptr = !*ptr; } } @@ -66,12 +66,12 @@ namespace paxs { /// @param is_visible 可視状態 /// @return 値が変更されたらtrue bool setVisibility(const std::uint_least32_t& feature_id, const bool is_visible) { - auto iterator = visible_features.find(feature_id); - if (iterator != visible_features.end()) { - if (iterator->second == is_visible) { + auto* const ptr = visible_features.try_get(feature_id); + if (ptr != nullptr) { + if (*ptr == is_visible) { return false; // 変更なし } - iterator->second = is_visible; + *ptr = is_visible; return true; // 変更あり } // 要素が存在しない場合は新規追加 @@ -93,8 +93,7 @@ namespace paxs { /// @param feature_id 機能ID(ハッシュ値) /// @return 可視状態(登録されていない場合はtrue) [[nodiscard]] bool isVisible(const std::uint_least32_t& feature_id) const { - const auto iterator = visible_features.find(feature_id); - return iterator != visible_features.end() ? iterator->second : true; + return visible_features.value_or(feature_id, true); } /// @brief 指定した機能の可視状態を取得(enum版) diff --git a/Library/PAX_SAPIENTICA/System/Locales.hpp b/Library/PAX_SAPIENTICA/System/Locales.hpp index cf68d763b..2717f3dae 100644 --- a/Library/PAX_SAPIENTICA/System/Locales.hpp +++ b/Library/PAX_SAPIENTICA/System/Locales.hpp @@ -81,18 +81,6 @@ namespace paxs { /// @brief Mapping from (domain key + text key + locale key) to text paxs::UnorderedMap text_dictionary_; - /// @brief ロケールキーからロケール名を取得 - /// @brief Get locale name from locale key - /// @param locale_key ロケールキー / Locale key - /// @return ロケール名、見つからない場合は空文字列 / Locale name, empty string if not found - std::string getLocaleNameFromKey(std::uint_least32_t locale_key) const { - const auto iterator = locale_key_to_name_.find(locale_key); - if (iterator != locale_key_to_name_.end()) { - return iterator->second; - } - return std::string{}; - } - /// @brief ファイルからロケールデータを読み込む /// @brief Load locale data from file /// @param domain_name ドメイン名 / Domain name @@ -181,7 +169,7 @@ namespace paxs { /// @brief Get domain name from file path using domain.tsv /// @param file_path ファイルパス / File path /// @return ドメイン名、見つからない場合は空文字列 / Domain name, empty string if not found - std::string getDomainNameFromPath(const std::string& file_path) { + static std::string getDomainNameFromPath(const std::string& file_path) { // ファイルパスからディレクトリパスを抽出 const std::size_t last_slash = file_path.find_last_of("/\\"); if (last_slash == std::string::npos) { @@ -217,9 +205,9 @@ namespace paxs { // マッピングから取得 const UnorderedMap& entries = kv_tsv.get(); - const auto it = entries.find(dir_name_hash); - if (it != entries.end()) { - return it->second; + const auto* const ptr = entries.try_get(dir_name_hash); + if (ptr != nullptr) { + return *ptr; } return std::string{}; @@ -288,7 +276,7 @@ namespace paxs { } // 進捗を報告 - if (progress_reporter_ && total_files > 0) { + if ((progress_reporter_ != nullptr) && total_files > 0) { const float progress = progress_start + (progress_end - progress_start) * (static_cast(file_count) / static_cast(total_files)); const std::string message = "Loading " + domain_name + "/" + locale_name + ".tsv (" + std::to_string(file_count + 1) + "/" + std::to_string(total_files) + ")"; progress_reporter_->reportProgress(progress, message); @@ -310,7 +298,7 @@ namespace paxs { : progress_reporter_(reporter) { // ロケールリスト読み込み(進捗の10%) - if (progress_reporter_) { + if (progress_reporter_ != nullptr) { progress_reporter_->reportProgress(progress_start, "Loading locale list..."); } loadLocaleList(); @@ -320,7 +308,7 @@ namespace paxs { const float files_end = progress_end; loadAllDomains(files_start, files_end); - if (progress_reporter_) { + if (progress_reporter_ != nullptr) { progress_reporter_->reportProgress(progress_end, "Locales initialized"); } } @@ -341,24 +329,28 @@ namespace paxs { // 指定されたロケールでテキストを検索 const CombinedKey combined_key{domain_name_hash, text_key_hash, locale_key}; - const auto iterator = text_dictionary_.find(combined_key); - if (iterator != text_dictionary_.end()) { - return &(iterator->second); + const auto* const ptr = text_dictionary_.try_get(combined_key); + if (ptr != nullptr) { + return ptr; } const std::uint_least32_t default_locale_key_ = getDefaultLocaleKey(); if (locale_key == default_locale_key_) { // 指定されたロケールが見つからない場合の警告 if (!suppress_warning) { - const std::string locale_name = getLocaleNameFromKey(locale_key); - PAXS_WARNING("[Locales::getStringPtr] Text key NOT found in locale '" + locale_name + "' - falling back to default locale"); + const std::string* const locale_name = locale_key_to_name_.try_get(locale_key); + if (locale_name == nullptr) { + PAXS_WARNING("[Locales::getStringPtr] Text key NOT found in locale (unknown) - falling back to default locale"); + return nullptr; + } + PAXS_WARNING("[Locales::getStringPtr] Text key NOT found in locale (" + *locale_name + ") - falling back to default locale"); return nullptr; } } // フォールバック処理:en-USで再検索 const CombinedKey fallback_key(domain_name_hash, text_key_hash, default_locale_key_); - const auto fallback_text_it = text_dictionary_.find(fallback_key); - if (fallback_text_it == text_dictionary_.end()) { + const auto* const fallback_text_ptr = text_dictionary_.try_get(fallback_key); + if (fallback_text_ptr == nullptr) { // テキストキー自体が登録されていない if (!suppress_warning) { PAXS_WARNING("[Locales::getStringPtr] Text key NOT found in default locale (en-US) - returning nullptr"); @@ -366,7 +358,7 @@ namespace paxs { return nullptr; } - return &(fallback_text_it->second); + return fallback_text_ptr; } /// @brief 登録されているロケール一覧を取得 diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibTextureImplIncludeTest.cpp new file mode 100644 index 000000000..29e9e97d1 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibWindowImplIncludeTest.cpp new file mode 100644 index 000000000..5be73f8f9 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/DxLib/DxLibWindowImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/RenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/RenderTextureImplIncludeTest.cpp new file mode 100644 index 000000000..5e5f319fa --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/RenderTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TextureImplIncludeTest.cpp new file mode 100644 index 000000000..d8a562ad0 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/TextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/WindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/WindowImplIncludeTest.cpp new file mode 100644 index 000000000..841f640d8 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Interface/WindowImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/MockIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/MockIncludeTest.cpp deleted file mode 100644 index d59fcdb4b..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/MockIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullRenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullRenderTextureImplIncludeTest.cpp new file mode 100644 index 000000000..02f77a011 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullRenderTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullTextureImplIncludeTest.cpp new file mode 100644 index 000000000..1c3c13f31 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullWindowImplIncludeTest.cpp new file mode 100644 index 000000000..7e9a6def3 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Null/NullWindowImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/RenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/RenderTextureImplIncludeTest.cpp deleted file mode 100644 index 8e02a5ee5..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/RenderTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLTextureImplIncludeTest.cpp new file mode 100644 index 000000000..b54910c6f --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLWindowImplIncludeTest.cpp new file mode 100644 index 000000000..f0d8a34d2 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/SFML/SFMLWindowImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImplIncludeTest.cpp new file mode 100644 index 000000000..31492919d --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DRenderTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DTextureImplIncludeTest.cpp new file mode 100644 index 000000000..dea00e6c4 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DTextureImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DWindowImplIncludeTest.cpp new file mode 100644 index 000000000..b95e81e93 --- /dev/null +++ b/Projects/IncludeTest/source/PAX_GRAPHICA/Siv3D/Siv3DWindowImplIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/TextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/TextureImplIncludeTest.cpp deleted file mode 100644 index e43960034..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/TextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/WindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/WindowImplIncludeTest.cpp deleted file mode 100644 index 65508a1b3..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/WindowImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibTextureImplIncludeTest.cpp deleted file mode 100644 index 686cc0244..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibWindowImplIncludeTest.cpp deleted file mode 100644 index fb1522433..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/DxLibWindowImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullRenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullRenderTextureImplIncludeTest.cpp deleted file mode 100644 index 839a0270d..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullRenderTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullTextureImplIncludeTest.cpp deleted file mode 100644 index 93e8c281b..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullWindowImplIncludeTest.cpp deleted file mode 100644 index 721df79ff..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/NullWindowImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLTextureImplIncludeTest.cpp deleted file mode 100644 index b6ec0d7e0..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLWindowImplIncludeTest.cpp deleted file mode 100644 index dc75a4f54..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/SFMLWindowImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DRenderTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DRenderTextureImplIncludeTest.cpp deleted file mode 100644 index 3e798e080..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DRenderTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DTextureImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DTextureImplIncludeTest.cpp deleted file mode 100644 index 611511ecc..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DTextureImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DWindowImplIncludeTest.cpp b/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DWindowImplIncludeTest.cpp deleted file mode 100644 index 5f5e51682..000000000 --- a/Projects/IncludeTest/source/PAX_GRAPHICA/implementations/Siv3DWindowImplIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} diff --git a/Projects/IntegrationTest/Source/WindowTest.cpp b/Projects/IntegrationTest/Source/WindowTest.cpp index 4c910434b..7207bdfc3 100644 --- a/Projects/IntegrationTest/Source/WindowTest.cpp +++ b/Projects/IntegrationTest/Source/WindowTest.cpp @@ -44,6 +44,6 @@ int main() { while (paxg::Window::update()) { rect.draw(); circle.draw(); - texture.drawAt(paxg::Vec2i(200, 200)); + texture.drawAt(paxs::Vector2(200, 200)); } } diff --git a/Projects/UnitTest/Source/PAX_GRAPHICA/TextureUnitTest.cpp b/Projects/UnitTest/Source/PAX_GRAPHICA/TextureUnitTest.cpp index 815a35d31..f28103a6e 100644 --- a/Projects/UnitTest/Source/PAX_GRAPHICA/TextureUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_GRAPHICA/TextureUnitTest.cpp @@ -128,8 +128,8 @@ TEST(TextureUnitTest, DrawMethodsSafe) { // These should not crash even with invalid texture ASSERT_NO_THROW(texture.draw()); - ASSERT_NO_THROW(texture.drawAt(paxg::Vec2f(0.0f, 0.0f))); - ASSERT_NO_THROW(texture.drawAt(paxg::Vec2i(0, 0))); + ASSERT_NO_THROW(texture.drawAt(paxs::Vector2(0.0f, 0.0f))); + ASSERT_NO_THROW(texture.drawAt(paxs::Vector2(0, 0))); } // Test resized draw methods don't crash with invalid texture @@ -137,15 +137,15 @@ TEST(TextureUnitTest, ResizedDrawMethodsSafe) { paxg::Texture texture; // These should not crash even with invalid texture - ASSERT_NO_THROW(texture.resizedDrawAt(paxg::Vec2i(100, 100), paxg::Vec2i(0, 0))); - ASSERT_NO_THROW(texture.resizedDrawAt(2, paxg::Vec2i(0, 0))); - ASSERT_NO_THROW(texture.resizedDrawAt(paxg::Vec2f(2.0f, 2.0f), paxg::Vec2f(0.0f, 0.0f))); - ASSERT_NO_THROW(texture.resizedDrawAt(2, paxg::Vec2f(0.0f, 0.0f))); - - ASSERT_NO_THROW(texture.resizedDraw(paxg::Vec2i(100, 100), paxg::Vec2i(0, 0))); - ASSERT_NO_THROW(texture.resizedDraw(2, paxg::Vec2i(0, 0))); - ASSERT_NO_THROW(texture.resizedDraw(paxg::Vec2f(2.0f, 2.0f), paxg::Vec2f(0.0f, 0.0f))); - ASSERT_NO_THROW(texture.resizedDraw(2, paxg::Vec2f(0.0f, 0.0f))); + ASSERT_NO_THROW(texture.resizedDrawAt(paxs::Vector2(100, 100), paxs::Vector2(0, 0))); + ASSERT_NO_THROW(texture.resizedDrawAt(2, paxs::Vector2(0, 0))); + ASSERT_NO_THROW(texture.resizedDrawAt(paxs::Vector2(2.0f, 2.0f), paxs::Vector2(0.0f, 0.0f))); + ASSERT_NO_THROW(texture.resizedDrawAt(2, paxs::Vector2(0.0f, 0.0f))); + + ASSERT_NO_THROW(texture.resizedDraw(paxs::Vector2(100, 100), paxs::Vector2(0, 0))); + ASSERT_NO_THROW(texture.resizedDraw(2, paxs::Vector2(0, 0))); + ASSERT_NO_THROW(texture.resizedDraw(paxs::Vector2(2.0f, 2.0f), paxs::Vector2(0.0f, 0.0f))); + ASSERT_NO_THROW(texture.resizedDraw(2, paxs::Vector2(0.0f, 0.0f))); } #if defined(PAXS_USING_SIV3D) diff --git a/Projects/UnitTest/Source/PAX_SAPIENTICA/IO/Data/TsvTableUnitTest.cpp b/Projects/UnitTest/Source/PAX_SAPIENTICA/IO/Data/TsvTableUnitTest.cpp index 2f8cab3e8..3008361ff 100644 --- a/Projects/UnitTest/Source/PAX_SAPIENTICA/IO/Data/TsvTableUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_SAPIENTICA/IO/Data/TsvTableUnitTest.cpp @@ -216,9 +216,9 @@ TEST_F(TsvTableTest, GetHeaderMap) { paxs::TsvTable table(test_file_path); const auto& map = table.getHeaderMap(); EXPECT_EQ(3u, map.size()); - EXPECT_TRUE(map.find(paxs::MurMur3::calcHash("key")) != map.end()); - EXPECT_TRUE(map.find(paxs::MurMur3::calcHash("value")) != map.end()); - EXPECT_TRUE(map.find(paxs::MurMur3::calcHash("count")) != map.end()); + EXPECT_TRUE(map.contains(paxs::MurMur3::calcHash("key"))); + EXPECT_TRUE(map.contains(paxs::MurMur3::calcHash("value"))); + EXPECT_TRUE(map.contains(paxs::MurMur3::calcHash("count"))); } // Test with BOM diff --git a/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Entity/SettlementUnitTest.cpp b/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Entity/SettlementUnitTest.cpp index 75c65ec7e..cf55131c6 100644 --- a/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Entity/SettlementUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Entity/SettlementUnitTest.cpp @@ -20,11 +20,32 @@ // Settlement クラスの基本的なテスト -TEST(SettlementUnitTest, Construction) { +// Test Fixture: environment を共有することでテスト高速化 +class SettlementUnitTest : public ::testing::Test { +protected: + // 全テストで共有される environment(SetUpTestSuiteで1回だけ初期化) + static std::shared_ptr shared_environment; + static paxs::KanakumaLifeSpan shared_life_span; + + // テストスイート全体の初期化(最初に1回だけ実行) + static void SetUpTestSuite() { + shared_environment = std::make_shared(); + } + + // テストスイート全体の終了処理 + static void TearDownTestSuite() { + shared_environment.reset(); + } +}; + +// 静的メンバの定義 +std::shared_ptr SettlementUnitTest::shared_environment; +paxs::KanakumaLifeSpan SettlementUnitTest::shared_life_span; + +TEST_F(SettlementUnitTest, Construction) { std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // IDが正しく設定されていることを確認 EXPECT_EQ(settlement.getId(), 1); @@ -33,11 +54,10 @@ TEST(SettlementUnitTest, Construction) { EXPECT_EQ(settlement.getPopulation(), 0); } -TEST(SettlementUnitTest, AddAgent) { +TEST_F(SettlementUnitTest, AddAgent) { std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // エージェントを追加 paxs::SettlementAgent agent(1, 0, 100, paxs::Genome(), 0, 0, 0); @@ -47,11 +67,10 @@ TEST(SettlementUnitTest, AddAgent) { EXPECT_EQ(settlement.getPopulation(), 1); } -TEST(SettlementUnitTest, Position) { +TEST_F(SettlementUnitTest, Position) { std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Vector2 pos(100, 200); settlement.setPosition(pos); @@ -59,11 +78,10 @@ TEST(SettlementUnitTest, Position) { EXPECT_EQ(settlement.getPosition(), pos); } -TEST(SettlementUnitTest, ClearAgents) { +TEST_F(SettlementUnitTest, ClearAgents) { std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // エージェントを複数追加 for (int i = 0; i < 5; ++i) { @@ -79,11 +97,10 @@ TEST(SettlementUnitTest, ClearAgents) { EXPECT_EQ(settlement.getPopulation(), 0); } -TEST(SettlementUnitTest, GetPopulationWeight) { +TEST_F(SettlementUnitTest, GetPopulationWeight) { std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 農耕民を追加 paxs::SettlementAgent farming_agent(1, 0, 100, paxs::Genome(), 100, 0, 0); @@ -102,11 +119,10 @@ TEST(SettlementUnitTest, GetPopulationWeight) { // Death Logic Tests // ======================================== -TEST(SettlementUnitTest, Death_RemovesAgentsWhoExceedLifespan) { +TEST_F(SettlementUnitTest, Death_RemovesAgentsWhoExceedLifespan) { // Given: 集落と寿命が尽きるエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome genome; genome.setYDNA(1); // Male @@ -131,11 +147,10 @@ TEST(SettlementUnitTest, Death_RemovesAgentsWhoExceedLifespan) { EXPECT_EQ(settlement.getAgents()[0].getId(), 2); } -TEST(SettlementUnitTest, Death_IncrementsAge) { +TEST_F(SettlementUnitTest, Death_IncrementsAge) { // Given: 集落と若いエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome genome; genome.setYDNA(1); @@ -151,11 +166,10 @@ TEST(SettlementUnitTest, Death_IncrementsAge) { EXPECT_EQ(settlement.getAgents()[0].getAgeInt(), initial_age + 1); } -TEST(SettlementUnitTest, Death_DivorcesPartnerWhenAgentDies) { +TEST_F(SettlementUnitTest, Death_DivorcesPartnerWhenAgentDies) { // Given: 既婚のカップルがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome female_genome, male_genome; female_genome.setYDNA(0); // Female @@ -189,12 +203,10 @@ TEST(SettlementUnitTest, Death_DivorcesPartnerWhenAgentDies) { // Birth Logic Tests // ======================================== -TEST(SettlementUnitTest, Birth_CreatesChildWhenBirthIntervalReachesZero) { +TEST_F(SettlementUnitTest, Birth_CreatesChildWhenBirthIntervalReachesZero) { // Given: 出産間隔カウントが1の妊娠中の女性 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); - paxs::KanakumaLifeSpan life_span; + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome mother_genome, father_genome; mother_genome.setMtDNA(10); @@ -210,7 +222,7 @@ TEST(SettlementUnitTest, Birth_CreatesChildWhenBirthIntervalReachesZero) { EXPECT_EQ(settlement.getPopulation(), 1); // When: 出産処理を実行 - settlement.preUpdate(life_span); + settlement.preUpdate(shared_life_span); // Then: 子供が追加される(確率的に死産でなければ) // Note: 死産率により失敗する可能性があるため、どちらも正常 @@ -218,12 +230,10 @@ TEST(SettlementUnitTest, Birth_CreatesChildWhenBirthIntervalReachesZero) { EXPECT_TRUE(settlement.getPopulation() == 1 || settlement.getPopulation() == 2); } -TEST(SettlementUnitTest, Birth_DecrementsBirthIntervalCount) { +TEST_F(SettlementUnitTest, Birth_DecrementsBirthIntervalCount) { // Given: 出産間隔カウントが5の女性 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); - paxs::KanakumaLifeSpan life_span; + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome genome; genome.setYDNA(0); // Female @@ -234,18 +244,16 @@ TEST(SettlementUnitTest, Birth_DecrementsBirthIntervalCount) { EXPECT_EQ(settlement.getAgents()[0].getBirthIntervalCount(), 5); // When: 出産処理を実行 - settlement.preUpdate(life_span); + settlement.preUpdate(shared_life_span); // Then: カウントが減少 EXPECT_EQ(settlement.getAgents()[0].getBirthIntervalCount(), 4); } -TEST(SettlementUnitTest, Birth_ChildInheritsGenomeFromParents) { +TEST_F(SettlementUnitTest, Birth_ChildInheritsGenomeFromParents) { // Given: 既婚の女性(カウント1) std::mt19937 gen(54321); // Different seed for better randomness - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); - paxs::KanakumaLifeSpan life_span; + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome mother_genome, father_genome; mother_genome.setMtDNA(10); @@ -260,7 +268,7 @@ TEST(SettlementUnitTest, Birth_ChildInheritsGenomeFromParents) { settlement.addAgent(mother); // When: 出産処理を実行 - settlement.preUpdate(life_span); + settlement.preUpdate(shared_life_span); // Then: 子供が生まれた場合、母のmtDNAを継承 if (settlement.getPopulation() > 1) { @@ -268,12 +276,10 @@ TEST(SettlementUnitTest, Birth_ChildInheritsGenomeFromParents) { } } -TEST(SettlementUnitTest, Birth_ChildInheritsCultureFromParents) { +TEST_F(SettlementUnitTest, Birth_ChildInheritsCultureFromParents) { // Given: 農耕文化を持つ既婚カップル std::mt19937 gen(11111); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); - paxs::KanakumaLifeSpan life_span; + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome mother_genome, father_genome; mother_genome.setYDNA(0); @@ -288,7 +294,7 @@ TEST(SettlementUnitTest, Birth_ChildInheritsCultureFromParents) { // When: 出産処理を実行(複数回試行して確実に出産させる) for (int i = 0; i < 10 && settlement.getPopulation() == 1; ++i) { settlement.getAgents()[0].setBirthIntervalCount(1); - settlement.preUpdate(life_span); + settlement.preUpdate(shared_life_span); } // Then: 子供が生まれた場合、両親の農耕文化の平均を継承 @@ -303,11 +309,10 @@ TEST(SettlementUnitTest, Birth_ChildInheritsCultureFromParents) { // Agent Management Tests // ======================================== -TEST(SettlementUnitTest, DeleteAgent_RemovesSpecificAgent) { +TEST_F(SettlementUnitTest, DeleteAgent_RemovesSpecificAgent) { // Given: 複数のエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome genome; paxs::SettlementAgent agent1(1, 20, 100, genome, 0, 0, 0); @@ -327,11 +332,10 @@ TEST(SettlementUnitTest, DeleteAgent_RemovesSpecificAgent) { EXPECT_EQ(settlement.getPopulation(), 2); } -TEST(SettlementUnitTest, GetAgent_ReturnsCorrectAgent) { +TEST_F(SettlementUnitTest, GetAgent_ReturnsCorrectAgent) { // Given: 複数のエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Genome genome; // 年齢はステップ単位で指定 @@ -349,11 +353,10 @@ TEST(SettlementUnitTest, GetAgent_ReturnsCorrectAgent) { EXPECT_EQ(retrieved.getAgeInt(), 30); // ステップ単位で比較 } -TEST(SettlementUnitTest, ResizeAgents_ChangesPopulation) { +TEST_F(SettlementUnitTest, ResizeAgents_ChangesPopulation) { // Given: エージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 5; ++i) { settlement.addAgent(paxs::SettlementAgent(i, 20, 100, paxs::Genome(), 0, 0, 0)); @@ -372,11 +375,10 @@ TEST(SettlementUnitTest, ResizeAgents_ChangesPopulation) { // Position Management Tests // ======================================== -TEST(SettlementUnitTest, SetPosition_UpdatesOldPosition) { +TEST_F(SettlementUnitTest, SetPosition_UpdatesOldPosition) { // Given: 座標を持つ集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::Vector2 initial_pos(100, 200); settlement.setPosition(initial_pos); @@ -390,11 +392,10 @@ TEST(SettlementUnitTest, SetPosition_UpdatesOldPosition) { EXPECT_EQ(settlement.getOldPosition(), initial_pos); } -TEST(SettlementUnitTest, ClearOldPosition_ResetsOldPositionData) { +TEST_F(SettlementUnitTest, ClearOldPosition_ResetsOldPositionData) { // Given: 座標履歴を持つ集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); settlement.setPosition(paxs::Vector2(100, 200)); settlement.setPosition(paxs::Vector2(150, 250)); @@ -412,11 +413,10 @@ TEST(SettlementUnitTest, ClearOldPosition_ResetsOldPositionData) { // Population Weight Tests // ======================================== -TEST(SettlementUnitTest, GetPopulationWeight_WithMixedCultures_CalculatesCorrectly) { +TEST_F(SettlementUnitTest, GetPopulationWeight_WithMixedCultures_CalculatesCorrectly) { // Given: 異なる生業文化を持つエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 農耕文化レベル100のエージェント3人 for (int i = 0; i < 3; ++i) { @@ -436,11 +436,10 @@ TEST(SettlementUnitTest, GetPopulationWeight_WithMixedCultures_CalculatesCorrect EXPECT_LT(weight, 1000.0); // 妥当な範囲内 } -TEST(SettlementUnitTest, GetPopulationWeight_WithNoAgents_ReturnsZero) { +TEST_F(SettlementUnitTest, GetPopulationWeight_WithNoAgents_ReturnsZero) { // Given: エージェントがいない集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // When: 人口重みを計算 double weight = settlement.getPopulationWeight(); @@ -453,11 +452,10 @@ TEST(SettlementUnitTest, GetPopulationWeight_WithNoAgents_ReturnsZero) { // Language Tests // ======================================== -TEST(SettlementUnitTest, GetLanguage_ReturnsZeroWhenNoAgents) { +TEST_F(SettlementUnitTest, GetLanguage_ReturnsZeroWhenNoAgents) { // Given: エージェントがいない集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // When: 言語を取得 std::uint_least8_t language = settlement.getLanguage(); @@ -466,11 +464,10 @@ TEST(SettlementUnitTest, GetLanguage_ReturnsZeroWhenNoAgents) { EXPECT_EQ(language, 0); } -TEST(SettlementUnitTest, GetLanguage_ReturnsMostFrequentLanguage) { +TEST_F(SettlementUnitTest, GetLanguage_ReturnsMostFrequentLanguage) { // Given: 複数の言語を持つエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 言語5のエージェントを3人追加 for (int i = 0; i < 3; ++i) { @@ -491,11 +488,10 @@ TEST(SettlementUnitTest, GetLanguage_ReturnsMostFrequentLanguage) { EXPECT_EQ(language, 5); } -TEST(SettlementUnitTest, GetLanguage_HandlesTieBreaking) { +TEST_F(SettlementUnitTest, GetLanguage_HandlesTieBreaking) { // Given: 同数の異なる言語を持つエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 言語3のエージェントを2人 for (int i = 0; i < 2; ++i) { @@ -516,11 +512,10 @@ TEST(SettlementUnitTest, GetLanguage_HandlesTieBreaking) { EXPECT_TRUE(language == 3 || language == 7); } -TEST(SettlementUnitTest, GetLanguage_WorksWithSingleAgent) { +TEST_F(SettlementUnitTest, GetLanguage_WorksWithSingleAgent) { // Given: 1人のエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::SettlementAgent agent(1, 20, 100, paxs::Genome(), 0, 0, 42); settlement.addAgent(agent); @@ -532,11 +527,10 @@ TEST(SettlementUnitTest, GetLanguage_WorksWithSingleAgent) { EXPECT_EQ(language, 42); } -TEST(SettlementUnitTest, GetLanguage_WorksWithAllSameLanguage) { +TEST_F(SettlementUnitTest, GetLanguage_WorksWithAllSameLanguage) { // Given: 全員が同じ言語を話す集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 言語15のエージェントを10人追加 for (int i = 0; i < 10; ++i) { @@ -555,11 +549,10 @@ TEST(SettlementUnitTest, GetLanguage_WorksWithAllSameLanguage) { // SNP Tests // ======================================== -TEST(SettlementUnitTest, GetSNP_ReturnsCorrectAverage) { +TEST_F(SettlementUnitTest, GetSNP_ReturnsCorrectAverage) { // Given: 異なるSNP値を持つエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // SNP=128のエージェントを3人 for (int i = 0; i < 3; ++i) { @@ -585,11 +578,10 @@ TEST(SettlementUnitTest, GetSNP_ReturnsCorrectAverage) { EXPECT_NEAR(snp, 0.7012, 0.001); } -TEST(SettlementUnitTest, GetSNP_WithAllSameSNP) { +TEST_F(SettlementUnitTest, GetSNP_WithAllSameSNP) { // Given: 全員同じSNP値 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // SNP=200のエージェントを5人 for (int i = 0; i < 5; ++i) { @@ -606,11 +598,10 @@ TEST(SettlementUnitTest, GetSNP_WithAllSameSNP) { EXPECT_NEAR(snp, 200.0 / 255.0, 0.001); } -TEST(SettlementUnitTest, GetSNP_WithZeroSNP) { +TEST_F(SettlementUnitTest, GetSNP_WithZeroSNP) { // Given: 全員SNP=0 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 3; ++i) { paxs::Genome genome; @@ -626,11 +617,10 @@ TEST(SettlementUnitTest, GetSNP_WithZeroSNP) { EXPECT_EQ(snp, 0.0); } -TEST(SettlementUnitTest, GetSNP_WithMaxSNP) { +TEST_F(SettlementUnitTest, GetSNP_WithMaxSNP) { // Given: 全員SNP=255(最大値) std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 3; ++i) { paxs::Genome genome; @@ -650,11 +640,10 @@ TEST(SettlementUnitTest, GetSNP_WithMaxSNP) { // Farming Population Tests // ======================================== -TEST(SettlementUnitTest, GetFarmingPopulation_CountsCorrectly) { +TEST_F(SettlementUnitTest, GetFarmingPopulation_CountsCorrectly) { // Given: 農耕民と狩猟採集民の混在 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 農耕民5人(farming > 0) for (int i = 0; i < 5; ++i) { @@ -675,11 +664,10 @@ TEST(SettlementUnitTest, GetFarmingPopulation_CountsCorrectly) { EXPECT_EQ(farming_pop, 5); } -TEST(SettlementUnitTest, GetFarmingPopulation_WithAllFarmers) { +TEST_F(SettlementUnitTest, GetFarmingPopulation_WithAllFarmers) { // Given: 全員農耕民 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 10; ++i) { paxs::SettlementAgent agent(i, 20, 100, paxs::Genome(), 50, 0, 0); @@ -689,11 +677,10 @@ TEST(SettlementUnitTest, GetFarmingPopulation_WithAllFarmers) { EXPECT_EQ(settlement.getFarmingPopulation(), 10); } -TEST(SettlementUnitTest, GetFarmingPopulation_WithNoFarmers) { +TEST_F(SettlementUnitTest, GetFarmingPopulation_WithNoFarmers) { // Given: 全員狩猟採集民 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 7; ++i) { paxs::SettlementAgent agent(i, 20, 100, paxs::Genome(), 0, 100, 0); @@ -703,11 +690,10 @@ TEST(SettlementUnitTest, GetFarmingPopulation_WithNoFarmers) { EXPECT_EQ(settlement.getFarmingPopulation(), 0); } -TEST(SettlementUnitTest, GetFarmingPopulation_WithNoAgents) { +TEST_F(SettlementUnitTest, GetFarmingPopulation_WithNoAgents) { // Given: エージェントがいない集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); EXPECT_EQ(settlement.getFarmingPopulation(), 0); } @@ -716,11 +702,10 @@ TEST(SettlementUnitTest, GetFarmingPopulation_WithNoAgents) { // MtDNA Tests // ======================================== -TEST(SettlementUnitTest, GetMostMtDNA_ReturnsAverage) { +TEST_F(SettlementUnitTest, GetMostMtDNA_ReturnsAverage) { // Given: 異なるmtDNA値を持つエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // mtDNA=10のエージェントを3人 for (int i = 0; i < 3; ++i) { @@ -745,11 +730,10 @@ TEST(SettlementUnitTest, GetMostMtDNA_ReturnsAverage) { EXPECT_EQ(mtdna, 14); } -TEST(SettlementUnitTest, GetMostMtDNA_WithSameMtDNA) { +TEST_F(SettlementUnitTest, GetMostMtDNA_WithSameMtDNA) { // Given: 全員同じmtDNA std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 5; ++i) { paxs::Genome genome; @@ -761,11 +745,10 @@ TEST(SettlementUnitTest, GetMostMtDNA_WithSameMtDNA) { EXPECT_EQ(settlement.getMostMtDNA(), 15); } -TEST(SettlementUnitTest, GetMostMtDNA_WithZeroMtDNA) { +TEST_F(SettlementUnitTest, GetMostMtDNA_WithZeroMtDNA) { // Given: 全員mtDNA=0 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 3; ++i) { paxs::Genome genome; @@ -781,11 +764,10 @@ TEST(SettlementUnitTest, GetMostMtDNA_WithZeroMtDNA) { // Divide Tests // ======================================== -TEST(SettlementUnitTest, Divide_SplitsAgentsInHalf) { +TEST_F(SettlementUnitTest, Divide_SplitsAgentsInHalf) { // Given: 10人のエージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 10; ++i) { paxs::SettlementAgent agent(i, 20, 100, paxs::Genome(), 0, 0, 0); @@ -800,11 +782,10 @@ TEST(SettlementUnitTest, Divide_SplitsAgentsInHalf) { EXPECT_EQ(new_settlement.getPopulation(), 5); } -TEST(SettlementUnitTest, Divide_CreatesNewSettlement) { +TEST_F(SettlementUnitTest, Divide_CreatesNewSettlement) { // Given: エージェントがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 6; ++i) { paxs::SettlementAgent agent(i, 20, 100, paxs::Genome(), 0, 0, 0); @@ -818,11 +799,10 @@ TEST(SettlementUnitTest, Divide_CreatesNewSettlement) { EXPECT_NE(settlement.getId(), new_settlement.getId()); } -TEST(SettlementUnitTest, Divide_WithOddNumberOfAgents) { +TEST_F(SettlementUnitTest, Divide_WithOddNumberOfAgents) { // Given: 奇数人のエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 7; ++i) { paxs::SettlementAgent agent(i, 20, 100, paxs::Genome(), 0, 0, 0); @@ -838,11 +818,10 @@ TEST(SettlementUnitTest, Divide_WithOddNumberOfAgents) { EXPECT_EQ(settlement.getPopulation() + new_settlement.getPopulation(), 7); } -TEST(SettlementUnitTest, Divide_KeepsMarriedCouplesTogether) { +TEST_F(SettlementUnitTest, Divide_KeepsMarriedCouplesTogether) { // Given: 既婚カップルがいる集落 std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); // 夫婦3組 + 独身4人 = 10人 for (int i = 0; i < 3; ++i) { @@ -890,11 +869,10 @@ TEST(SettlementUnitTest, Divide_KeepsMarriedCouplesTogether) { checkCouplesInSettlement(new_settlement); } -TEST(SettlementUnitTest, Divide_WithTwoAgents) { +TEST_F(SettlementUnitTest, Divide_WithTwoAgents) { // Given: 2人のエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::SettlementAgent agent1(1, 20, 100, paxs::Genome(), 0, 0, 0); paxs::SettlementAgent agent2(2, 20, 100, paxs::Genome(), 0, 0, 0); @@ -909,11 +887,10 @@ TEST(SettlementUnitTest, Divide_WithTwoAgents) { EXPECT_EQ(new_settlement.getPopulation(), 1); } -TEST(SettlementUnitTest, Divide_WithSingleAgent) { +TEST_F(SettlementUnitTest, Divide_WithSingleAgent) { // Given: 1人のエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); paxs::SettlementAgent agent(1, 20, 100, paxs::Genome(), 0, 0, 0); settlement.addAgent(agent); @@ -926,11 +903,10 @@ TEST(SettlementUnitTest, Divide_WithSingleAgent) { EXPECT_EQ(new_settlement.getPopulation(), 1); } -TEST(SettlementUnitTest, Divide_PreservesAgentData) { +TEST_F(SettlementUnitTest, Divide_PreservesAgentData) { // Given: 特定のデータを持つエージェント std::mt19937 gen(12345); - auto environment = std::make_shared(); - paxs::Settlement settlement(1, gen, environment); + paxs::Settlement settlement(1, gen, shared_environment); for (int i = 0; i < 4; ++i) { paxs::Genome genome; diff --git a/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulatorUnitTest.cpp b/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulatorUnitTest.cpp index e2100de30..b3325a21b 100644 --- a/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulatorUnitTest.cpp +++ b/Projects/UnitTest/Source/PAX_SAPIENTICA/Simulation/Manager/SettlementSimulatorUnitTest.cpp @@ -11,10 +11,6 @@ #include -#include -#include -#include - #include #include #include @@ -25,22 +21,48 @@ class SettlementSimulatorUnitTest : public ::testing::Test { protected: - void SetUp() override { + // 全テストで共有される初期化済みシミュレータ(SetUpTestSuiteで1回だけ初期化) + static std::unique_ptr shared_initialized_simulator; + static std::string shared_model_name; + static std::string shared_map_list_path; + static std::string shared_japan_provinces_path; + static unsigned shared_seed; + + // テストスイート全体の初期化(最初に1回だけ実行) + static void SetUpTestSuite() { // モデル名を設定 - model_name = "Sample"; + shared_model_name = "Sample"; // SimulationConstantsの初期化 - paxs::SimulationConstants::getInstance(model_name).init(model_name); + paxs::SimulationConstants::getInstance(shared_model_name).init(shared_model_name); // パスを生成(実際のシミュレーションと同じ方法) - map_list_path = paxs::AppConfig::getInstance().getSettingPath(paxs::MurMur3::calcHash("SimulationXYZTiles")); - japan_provinces_path = paxs::AppConfig::getInstance().getSettingPath(paxs::MurMur3::calcHash("SimulationProvincesPath")); + shared_map_list_path = paxs::AppConfig::getInstance().getSettingPath(paxs::MurMur3::calcHash("SimulationXYZTiles")); + shared_japan_provinces_path = paxs::AppConfig::getInstance().getSettingPath(paxs::MurMur3::calcHash("SimulationProvincesPath")); - paxs::StringUtils::replace(map_list_path, "Sample", model_name); - paxs::StringUtils::replace(japan_provinces_path, "Sample", model_name); + paxs::StringUtils::replace(shared_map_list_path, "Sample", shared_model_name); + paxs::StringUtils::replace(shared_japan_provinces_path, "Sample", shared_model_name); // テスト用のシミュレーションシードを固定 - seed = 12345; + shared_seed = 12345; + + // 初期化済みシミュレータを作成(読み取り専用テスト用) + shared_initialized_simulator = std::make_unique( + shared_map_list_path, shared_japan_provinces_path, shared_seed); + shared_initialized_simulator->init(); + } + + // テストスイート全体の終了処理 + static void TearDownTestSuite() { + shared_initialized_simulator.reset(); + } + + void SetUp() override { + // 各テストで使用するローカル変数(互換性のため残す) + model_name = shared_model_name; + map_list_path = shared_map_list_path; + japan_provinces_path = shared_japan_provinces_path; + seed = shared_seed; } std::string model_name; @@ -49,21 +71,19 @@ class SettlementSimulatorUnitTest : public ::testing::Test { unsigned seed; }; -TEST_F(SettlementSimulatorUnitTest, Construction) { - // Given: パラメータを指定してシミュレータを作成 - paxs::SettlementSimulator simulator(map_list_path, japan_provinces_path, seed); - - // Then: シミュレータが正常に構築される - EXPECT_EQ(simulator.cgetPopulationNum(), 0); - EXPECT_EQ(simulator.cgetSettlement(), 0); -} +// 静的メンバの定義 +std::unique_ptr SettlementSimulatorUnitTest::shared_initialized_simulator; +std::string SettlementSimulatorUnitTest::shared_model_name; +std::string SettlementSimulatorUnitTest::shared_map_list_path; +std::string SettlementSimulatorUnitTest::shared_japan_provinces_path; +unsigned SettlementSimulatorUnitTest::shared_seed; TEST_F(SettlementSimulatorUnitTest, SetEnvironment) { - // Given: 空のシミュレータ + // Given: 空のシミュレータ(setEnvironmentのテストなので新規作成) paxs::SettlementSimulator simulator; // When: 環境を設定 - EXPECT_NO_THROW(simulator.setEnvironment(map_list_path, japan_provinces_path, seed)); + EXPECT_NO_THROW(simulator.setEnvironment(shared_map_list_path, shared_japan_provinces_path, shared_seed)); // Then: 正常に設定される EXPECT_EQ(simulator.cgetPopulationNum(), 0); @@ -73,85 +93,14 @@ TEST_F(SettlementSimulatorUnitTest, SetEnvironment) { // RandomizeSettlements Tests // ======================================== -/** - * @brief randomizeSettlements()の動作を検証するテスト - * - * このテストは固定シードで2回実行し、集落配置が決定論的であることを確認します。 - * リファクタリング前後で同じ結果が得られることを保証します。 - */ -TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_Deterministic) { - // Given: 同じシードで2つのシミュレータを作成 - paxs::SettlementSimulator simulator1(map_list_path, japan_provinces_path, seed); - paxs::SettlementSimulator simulator2(map_list_path, japan_provinces_path, seed); - - // When: 両方を初期化 - simulator1.init(); - simulator2.init(); - - // Then: 同じ人口と集落数が生成される - EXPECT_EQ(simulator1.cgetPopulationNum(), simulator2.cgetPopulationNum()); - EXPECT_EQ(simulator1.cgetSettlement(), simulator2.cgetSettlement()); - - // 集落の詳細も一致することを確認 - const auto& grids1 = simulator1.cgetSettlementGrids(); - const auto& grids2 = simulator2.cgetSettlementGrids(); - - EXPECT_EQ(grids1.size(), grids2.size()); -} - -/** - * @brief randomizeSettlements()で配置されたエージェントの詳細を検証 - * - * 固定シードでエージェントの属性(年齢、ゲノム、文化)が再現可能であることを確認 - */ -TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_AgentDetailsReproducible) { - // Given: 同じシードで2つのシミュレータを作成 - const unsigned test_seed = 54321; - paxs::SettlementSimulator simulator1(map_list_path, japan_provinces_path, test_seed); - paxs::SettlementSimulator simulator2(map_list_path, japan_provinces_path, test_seed); - - // When: 初期化 - simulator1.init(); - simulator2.init(); - - // Then: 各集落のエージェント詳細が一致 - const auto& grids1 = simulator1.cgetSettlementGrids(); - const auto& grids2 = simulator2.cgetSettlementGrids(); - - // 集落グリッド数が一致 - ASSERT_EQ(grids1.size(), grids2.size()); - - // 各グリッドの集落を比較 - for (const auto& [key, grid1] : grids1) { - const auto* grid2_ptr = grids2.try_get(key); - ASSERT_NE(grid2_ptr, nullptr) << "Grid key " << key << " not found in simulator2"; - - const auto& settlements1 = grid1.cgetSettlements(); - const auto& settlements2 = grid2_ptr->cgetSettlements(); - - EXPECT_EQ(settlements1.size(), settlements2.size()) - << "Settlement count mismatch in grid " << key; - - // 各集落のエージェント数を確認 - for (std::size_t i = 0; i < settlements1.size() && i < settlements2.size(); ++i) { - EXPECT_EQ(settlements1[i].getPopulation(), settlements2[i].getPopulation()) - << "Population mismatch in settlement " << i << " of grid " << key; - } - } -} - /** * @brief 渡来人配置のテスト * * randomizeSettlements()が渡来フラグで正しく動作することを確認 */ TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_ImmigrationFlag) { - // Given: シミュレータを作成 - paxs::SettlementSimulator simulator(map_list_path, japan_provinces_path, seed); - - // When: 初期化(在地人配置) - simulator.init(); - const std::size_t initial_population = simulator.cgetPopulationNum(); + // Given: 初期化済みシミュレータを使用 + const std::size_t initial_population = shared_initialized_simulator->cgetPopulationNum(); // Then: 初期人口が設定される EXPECT_GT(initial_population, 0) << "Initial population should be greater than 0"; @@ -163,14 +112,10 @@ TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_ImmigrationFlag) { * 集落が可住地にのみ配置されることを確認 */ TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_OnlyOnHabitableLand) { - // Given: シミュレータを作成 - paxs::SettlementSimulator simulator(map_list_path, japan_provinces_path, seed); - - // When: 初期化 - simulator.init(); + // Given: 初期化済みシミュレータを使用 // Then: 全ての集落が有効な位置にある - const auto& grids = simulator.cgetSettlementGrids(); + const auto& grids = shared_initialized_simulator->cgetSettlementGrids(); for (const auto& [key, grid] : grids) { for (const auto& settlement : grid.cgetSettlements()) { // 人口が0より大きい @@ -183,56 +128,3 @@ TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_OnlyOnHabitableLand) { } } } - -/** - * @brief 異なるシードで異なる結果が生成されることを確認 - */ -TEST_F(SettlementSimulatorUnitTest, RandomizeSettlements_DifferentSeedsDifferentResults) { - // Given: 異なるシードで2つのシミュレータを作成 - paxs::SettlementSimulator simulator1(map_list_path, japan_provinces_path, 12345); - paxs::SettlementSimulator simulator2(map_list_path, japan_provinces_path, 67890); - - // When: 両方を初期化 - simulator1.init(); - simulator2.init(); - - // Then: 人口は同じ設定値だが、集落の詳細配置は異なる可能性が高い - // (ただし、テストデータや設定によっては偶然一致する可能性もあるため、 - //  ここでは基本的な検証のみ行う) - - // 両方とも集落が生成されている - EXPECT_GT(simulator1.cgetSettlement(), 0); - EXPECT_GT(simulator2.cgetSettlement(), 0); -} - -// ======================================== -// Population Calculation Tests -// ======================================== - -TEST_F(SettlementSimulatorUnitTest, CalcPop_UpdatesPopulationAndSettlementCount) { - // Given: 初期化されたシミュレータ - paxs::SettlementSimulator simulator(map_list_path, japan_provinces_path, seed); - simulator.init(); - - // When: 人口計算を実行 - const std::size_t pop_before = simulator.cgetPopulationNum(); - const std::size_t settlement_before = simulator.cgetSettlement(); - - simulator.calcPop(); - - // Then: 人口と集落数が計算される(この場合、変化なし) - EXPECT_EQ(simulator.cgetPopulationNum(), pop_before); - EXPECT_EQ(simulator.cgetSettlement(), settlement_before); -} - -// ======================================== -// Migration Count Tests -// ======================================== - -TEST_F(SettlementSimulatorUnitTest, GetMigrationCount_InitiallyZero) { - // Given: 新しいシミュレータ - paxs::SettlementSimulator simulator(map_list_path, japan_provinces_path, seed); - - // Then: 渡来数は0 - EXPECT_EQ(simulator.getMigrationCount(), 0); -}