diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 6175eea..ff4eb05 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -31,7 +31,7 @@ add_executable (xna WIN32 "platform/keyboard-dx.cpp" "platform/mouse-dx.cpp" "platform/gamepad-dx.cpp" -"common/vectors.cpp" + "platform/soundeffect-dx.cpp" "platform/displaymode-dx.cpp" "platform/presentparameters-dx.cpp" @@ -51,7 +51,7 @@ add_executable (xna WIN32 "common/quaternion.cpp" "common/collision.cpp" "common/gjk.cpp" - ) + "common/numerics.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET xna PROPERTY CXX_STANDARD 20) diff --git a/framework/common/vectors.cpp b/framework/common/numerics.cpp similarity index 98% rename from framework/common/vectors.cpp rename to framework/common/numerics.cpp index f7b5ffc..512d38f 100644 --- a/framework/common/vectors.cpp +++ b/framework/common/numerics.cpp @@ -1,4 +1,4 @@ -#include "common/vectors.hpp" +#include "common/numerics.hpp" #include "common/matrix.hpp" #include "common/quaternion.hpp" @@ -27,14 +27,14 @@ namespace xna { bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) { - if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength + if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength || sourceArrayLength < sourceIndex + length || destinationArrayLength < destinationIndex + length) return false; for (size_t i = 0; i < length; ++i) { - const auto& source = sourceArray[sourceIndex + i]; + const auto& source = sourceArray[sourceIndex + i]; destinationArray[destinationIndex + i].X = (source.X * matrix.M11 + source.Y * matrix.M21) + matrix.M41; - destinationArray[destinationIndex + i].Y = (source.X * matrix.M12 + source.Y * matrix.M22) + matrix.M42; + destinationArray[destinationIndex + i].Y = (source.X * matrix.M12 + source.Y * matrix.M22) + matrix.M42; } return true; @@ -68,7 +68,7 @@ namespace xna { return TransformNormal(sourceArray.data(), sourceArray.size(), matrix, destinationArray.data(), destinationArray.size()); } - + bool Vector2::TransformNormal(Vector2 const* sourceArray, size_t sourceArrayLength, size_t sourceIndex, Matrix const& matrix, Vector2* destinationArray, size_t destinationArrayLength, size_t destinationIndex, size_t length) { if (!sourceArray || !destinationArray || destinationArrayLength < sourceArrayLength || sourceArrayLength < sourceIndex + length || destinationArrayLength < destinationIndex + length) @@ -78,7 +78,7 @@ namespace xna { { const auto& source = sourceArray[sourceIndex + i]; destinationArray[destinationIndex].X = (source.X * matrix.M11 + source.Y * matrix.M21); - destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22); + destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22); } return true; @@ -144,12 +144,12 @@ namespace xna { const auto b = rxy - rwz; const auto c = rxy + rwz; const auto d = 1.0f - rxx - rzz; - + for (size_t i = 0; i < length; ++i) { const auto& source = sourceArray[sourceIndex = i]; - destinationArray[destinationIndex].X = source.X * a + source.Y* b; - destinationArray[destinationIndex].Y = source.X * c +source.Y * d; + destinationArray[destinationIndex].X = source.X * a + source.Y * b; + destinationArray[destinationIndex].Y = source.X * c + source.Y * d; ++sourceIndex; ++destinationIndex; } @@ -163,7 +163,7 @@ namespace xna { destinationArray.resize(sourceArray.size()); return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length); - } + } bool Vector3::Transform(Vector3 const* sourceArray, size_t sourceArrayLength, Matrix const& matrix, Vector3* destinationArray, size_t destinationLength) { @@ -428,7 +428,7 @@ namespace xna { const auto num19 = num9 - num5; const auto num20 = num11 + num4; const auto num21 = 1.0f - num7 - num10; - + for (size_t index = 0; index < sourceLength; ++index) { const auto& source = sourceArray[index]; @@ -494,4 +494,4 @@ namespace xna { return Transform(sourceArray.data(), sourceArray.size(), sourceIndex, rotation, destinationArray.data(), destinationArray.size(), destinationIndex, length); } -} \ No newline at end of file +} diff --git a/inc/common/collision.hpp b/inc/common/collision.hpp index 8ebc624..9d75f84 100644 --- a/inc/common/collision.hpp +++ b/inc/common/collision.hpp @@ -2,7 +2,7 @@ #define XNA_COMMON_SHAPES_HPP #include "default.hpp" -#include "vectors.hpp" +#include "numerics.hpp" #include "matrix.hpp" #include "quaternion.hpp" #include "gjk.hpp" diff --git a/inc/common/curve.hpp b/inc/common/curve.hpp index c2f28a3..24c39c7 100644 --- a/inc/common/curve.hpp +++ b/inc/common/curve.hpp @@ -115,7 +115,7 @@ namespace xna { std::vector Keys; private: - friend class Curve; + friend struct Curve; float TimeRange{ 0.0F }; float InvTimeRange{ 0.0F }; diff --git a/inc/common/gjk.hpp b/inc/common/gjk.hpp index a857579..4bba55b 100644 --- a/inc/common/gjk.hpp +++ b/inc/common/gjk.hpp @@ -2,7 +2,7 @@ #define XNA_COMMON_GDK_HPP #include "default.hpp" -#include "vectors.hpp" +#include "numerics.hpp" #include "math.hpp" namespace xna { diff --git a/inc/common/matrix.hpp b/inc/common/matrix.hpp index 3da4588..519a7af 100644 --- a/inc/common/matrix.hpp +++ b/inc/common/matrix.hpp @@ -3,7 +3,7 @@ #include "../default.hpp" #include "math.hpp" -#include "vectors.hpp" +#include "numerics.hpp" namespace xna { struct Matrix { diff --git a/inc/common/vectors.hpp b/inc/common/numerics.hpp similarity index 90% rename from inc/common/vectors.hpp rename to inc/common/numerics.hpp index 01e6cae..cd69b4b 100644 --- a/inc/common/vectors.hpp +++ b/inc/common/numerics.hpp @@ -5,6 +5,126 @@ #include "../default.hpp" namespace xna { + struct Point { + Int X{ 0 }; + Int Y{ 0 }; + + constexpr Point() = default; + + constexpr Point(const Int& X, const Int& Y) + : X(X), Y(Y) {} + + constexpr bool operator==(const Point& other) const { + return X == other.X && Y == other.Y; + } + }; + + struct Rectangle { + Int X{ 0 }; + Int Y{ 0 }; + Int Width{ 0 }; + Int Height{ 0 }; + + constexpr Rectangle() = default; + + constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height) : + X(X), Y(Y), Width(Width), Height(Height) {} + + constexpr bool operator==(const Rectangle& other) const { + return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y; + } + + constexpr Int Left() const { return X; } + constexpr Int Right() const { return X + Width; } + constexpr Int Top() const { return Y; } + constexpr Int Bottom() const { return Y + Height; } + + constexpr Point Location() const { return { X, Y }; } + constexpr void Location(Point const& p) { + X = p.X; + Y = p.Y; + } + + constexpr Point Center() const { return { X + Width / 2, Y + Height / 2 }; } + + constexpr static Rectangle Empty() { return {}; } + + constexpr bool IsEmpty() const { return Width == 0 && Height == 0 && X == 0 && Y == 0; } + + constexpr void Offset(Point const& amount) { + X += amount.X; + Y += amount.Y; + } + + constexpr void Offset(Int x, Int y) { + X += x; + Y += y; + } + + constexpr void Inflate(Int horizontalAmount, Int verticalAmount) { + X -= horizontalAmount; + Y -= verticalAmount; + Width += horizontalAmount * 2; + Height += verticalAmount * 2; + } + + constexpr bool Contains(Int x, Int y) const { + return X <= x && x < X + Width && Y <= y && y < Y + Height; + } + + constexpr bool Contains(Point const& value) const { + return X <= value.X && value.X < X + Width && Y <= value.Y && value.Y < Y + Height; + } + + constexpr bool Contains(Rectangle const& value) const { + return X <= value.X && value.X + value.Width <= X + Width && Y <= value.Y && value.Y + value.Height <= Y + Height; + } + + constexpr bool Intersects(Rectangle const& value) const { + return value.X < X + Width && X < value.X + value.Width && value.Y < Y + Height && Y < value.Y + value.Height; + } + + constexpr static Rectangle Intersect(Rectangle const& value1, Rectangle const& value2) { + const auto left1 = value1.Left(); + const auto left2 = value2.Left(); + const auto bottom1 = value1.Bottom(); + const auto bottom2 = value2.Bottom(); + const auto maxX = value1.X > value2.X ? value1.X : value2.X; + const auto maxY = value1.Y > value2.Y ? value1.Y : value2.Y; + const auto maxl = left1 < left2 ? left1 : left2; + const auto maxb = bottom1 < bottom2 ? bottom1 : bottom2; + + Rectangle rectangle{}; + + if (maxl > maxX && maxb > maxY) { + rectangle.X = maxX; + rectangle.Y = maxY; + rectangle.Width = maxl - maxX; + rectangle.Height = maxb - maxY; + } + + return rectangle; + } + + constexpr static Rectangle Union(Rectangle const& value1, Rectangle const& value2) { + const auto left1 = value1.Left(); + const auto left2 = value2.Left(); + const auto bottom1 = value1.Bottom(); + const auto bottom2 = value2.Bottom(); + const auto minX = value1.X < value2.X ? value1.X : value2.X; + const auto miny = value1.Y < value2.Y ? value1.Y : value2.Y; + const auto maxl = left1 > left2 ? left1 : left2; + const auto maxb = bottom1 > bottom2 ? bottom1 : bottom2; + + Rectangle rectangle; + rectangle.X = minX; + rectangle.Y = miny; + rectangle.Width = maxl - minX; + rectangle.Height = maxb - miny; + return rectangle; + } + }; + struct Vector2 { float X{ 0 }; float Y{ 0 }; diff --git a/inc/common/packedvalue.hpp b/inc/common/packedvalue.hpp index 53de09b..24e24bc 100644 --- a/inc/common/packedvalue.hpp +++ b/inc/common/packedvalue.hpp @@ -2,7 +2,7 @@ #define CXNA_COMMON_PACKEDVECTOR_HPP #include "../default.hpp" -#include "vectors.hpp" +#include "numerics.hpp" #include namespace xna { diff --git a/inc/common/point.hpp b/inc/common/point.hpp deleted file mode 100644 index a37d8ec..0000000 --- a/inc/common/point.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef XNA_COMMON_POINT_HPP -#define XNA_COMMON_POINT_HPP - -#include "../types.hpp" - -namespace xna { - -} - -#endif \ No newline at end of file diff --git a/inc/common/quaternion.hpp b/inc/common/quaternion.hpp index 5cb2e91..6bba8d7 100644 --- a/inc/common/quaternion.hpp +++ b/inc/common/quaternion.hpp @@ -1,7 +1,7 @@ #ifndef XNA_COMMON_QUATERNION_HPP #define XNA_COMMON_QUATERNION_HPP -#include "vectors.hpp" +#include "numerics.hpp" namespace xna { struct Quaternion { diff --git a/inc/common/rectangle.hpp b/inc/common/rectangle.hpp deleted file mode 100644 index c884c55..0000000 --- a/inc/common/rectangle.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef XNA_COMMON_RECTANGLE_HPP -#define XNA_COMMON_RECTANGLE_HPP - -#include "../types.hpp" - -namespace xna { - struct Point { - Int X{ 0 }; - Int Y{ 0 }; - - constexpr Point() = default; - - constexpr Point(const Int& X, const Int& Y) - : X(X), Y(Y) {} - - constexpr bool operator==(const Point& other) const { - return X == other.X && Y == other.Y; - } - }; - - struct Rectangle { - Int X{ 0 }; - Int Y{ 0 }; - Int Width{ 0 }; - Int Height{ 0 }; - - constexpr Rectangle() = default; - - constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height): - X(X), Y(Y), Width(Width), Height(Height) {} - - constexpr bool operator==(const Rectangle& other) const { - return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y; - } - - constexpr Int Left() const { return X; } - constexpr Int Right() const { return X + Width; } - constexpr Int Top() const { return Y; } - constexpr Int Bottom() const { return Y + Height; } - - constexpr Point Location() const { return { X, Y }; } - constexpr void Location(Point const& p) { - X = p.X; - Y = p.Y; - } - - constexpr Point Center() const { return { X + Width / 2, Y + Height / 2 }; } - - constexpr static Rectangle Empty() { return {}; } - - constexpr bool IsEmpty() const { return Width == 0 && Height == 0 && X == 0 && Y == 0; } - - constexpr void Offset(Point const& amount) { - X += amount.X; - Y += amount.Y; - } - - constexpr void Offset(Int x, Int y) { - X += x; - Y += y; - } - - constexpr void Inflate(Int horizontalAmount, Int verticalAmount) { - X -= horizontalAmount; - Y -= verticalAmount; - Width += horizontalAmount * 2; - Height += verticalAmount * 2; - } - - constexpr bool Contains(Int x, Int y) const { - return X <= x && x < X + Width && Y <= y && y < Y + Height; - } - - constexpr bool Contains(Point const& value) const { - return X <= value.X && value.X < X + Width && Y <= value.Y && value.Y < Y + Height; - } - - constexpr bool Contains(Rectangle const& value) const { - return X <= value.X && value.X + value.Width <= X + Width && Y <= value.Y && value.Y + value.Height <= Y + Height; - } - - constexpr bool Intersects(Rectangle const& value) const { - return value.X < X + Width && X < value.X + value.Width && value.Y < Y + Height && Y < value.Y + value.Height; - } - - constexpr static Rectangle Intersect(Rectangle const& value1, Rectangle const& value2) { - const auto left1 = value1.Left(); - const auto left2 = value2.Left(); - const auto bottom1 = value1.Bottom(); - const auto bottom2 = value2.Bottom(); - const auto maxX = value1.X > value2.X ? value1.X : value2.X; - const auto maxY = value1.Y > value2.Y ? value1.Y : value2.Y; - const auto maxl = left1 < left2 ? left1 : left2; - const auto maxb = bottom1 < bottom2 ? bottom1 : bottom2; - - Rectangle rectangle{}; - - if (maxl > maxX && maxb > maxY) { - rectangle.X = maxX; - rectangle.Y = maxY; - rectangle.Width = maxl - maxX; - rectangle.Height = maxb - maxY; - } - - return rectangle; - } - - constexpr static Rectangle Union(Rectangle const& value1, Rectangle const& value2) { - const auto left1 = value1.Left(); - const auto left2 = value2.Left(); - const auto bottom1 = value1.Bottom(); - const auto bottom2 = value2.Bottom(); - const auto minX = value1.X < value2.X ? value1.X : value2.X; - const auto miny = value1.Y < value2.Y ? value1.Y : value2.Y; - const auto maxl = left1 > left2 ? left1 : left2; - const auto maxb = bottom1 > bottom2 ? bottom1 : bottom2; - - Rectangle rectangle; - rectangle.X = minX; - rectangle.Y = miny; - rectangle.Width = maxl - minX; - rectangle.Height = maxb - miny; - return rectangle; - } - }; -} - -#endif \ No newline at end of file diff --git a/inc/content/defaultreaders.hpp b/inc/content/defaultreaders.hpp index 376bb58..f886a25 100644 --- a/inc/content/defaultreaders.hpp +++ b/inc/content/defaultreaders.hpp @@ -5,8 +5,7 @@ #include "../default.hpp" #include "../common/color.hpp" #include "../common/matrix.hpp" -#include "../common/point.hpp" -#include "../common/rectangle.hpp" +#include "../common/numerics.hpp" #include "../csharp/timespan.hpp" namespace xna { diff --git a/inc/content/reader.hpp b/inc/content/reader.hpp index f953d5f..060ab5a 100644 --- a/inc/content/reader.hpp +++ b/inc/content/reader.hpp @@ -4,7 +4,7 @@ #include "../common/color.hpp" #include "../common/matrix.hpp" #include "../common/quaternion.hpp" -#include "../common/vectors.hpp" +#include "../common/numerics.hpp" #include "../csharp/binary.hpp" #include "../csharp/type.hpp" #include "../default.hpp" diff --git a/inc/game/window.hpp b/inc/game/window.hpp index 023b728..163cfb0 100644 --- a/inc/game/window.hpp +++ b/inc/game/window.hpp @@ -2,7 +2,7 @@ #define XNA_GAME_WINDOW_HPP #include "../enums.hpp" -#include "../common/rectangle.hpp" +#include "../common/numerics.hpp" namespace xna { class IGameWindow { diff --git a/inc/graphics/vertexposition.hpp b/inc/graphics/vertexposition.hpp index 5594702..3f03aad 100644 --- a/inc/graphics/vertexposition.hpp +++ b/inc/graphics/vertexposition.hpp @@ -1,7 +1,7 @@ #ifndef XNA_GRAPHICS_VERTEXPOSITION_HPP #define XNA_GRAPHICS_VERTEXPOSITION_HPP -#include "../common/vectors.hpp" +#include "../common/numerics.hpp" #include "../common/color.hpp" #include "../default.hpp" diff --git a/inc/input/gamepad.hpp b/inc/input/gamepad.hpp index c59373f..0c55f6c 100644 --- a/inc/input/gamepad.hpp +++ b/inc/input/gamepad.hpp @@ -2,7 +2,7 @@ #define XNA_INPUT_GAMEPAD_HPP #include "../default.hpp" -#include "../common/vectors.hpp" +#include "../common/numerics.hpp" namespace xna { struct IGamePadTriggers { diff --git a/inc/platform-dx/spritebatch-dx.hpp b/inc/platform-dx/spritebatch-dx.hpp index 7404df5..7f25a92 100644 --- a/inc/platform-dx/spritebatch-dx.hpp +++ b/inc/platform-dx/spritebatch-dx.hpp @@ -2,8 +2,7 @@ #define XNA_PLATFORM_SPRITEBATCH_DX_HPP #include "../common/color.hpp" -#include "../common/rectangle.hpp" -#include "../common/vectors.hpp" +#include "../common/numerics.hpp" #include "../graphics/spritebatch.hpp" #include "../graphics/viewport.hpp" #include "SpriteBatch.h" diff --git a/inc/platform-dx/spritefont-dx.hpp b/inc/platform-dx/spritefont-dx.hpp index 14d00df..eaa51ea 100644 --- a/inc/platform-dx/spritefont-dx.hpp +++ b/inc/platform-dx/spritefont-dx.hpp @@ -2,7 +2,7 @@ #define XNA_PLATFORM_SPRITEFONT_DX_HPP #include "../graphics/spritefont.hpp" -#include "../common/vectors.hpp" +#include "../common/numerics.hpp" #include "SpriteFont.h" #include "device-dx.hpp" diff --git a/inc/platform-dx/texture-dx.hpp b/inc/platform-dx/texture-dx.hpp index 8bfb433..b0d5309 100644 --- a/inc/platform-dx/texture-dx.hpp +++ b/inc/platform-dx/texture-dx.hpp @@ -1,7 +1,7 @@ #ifndef XNA_PLATFORM_TEXTURE_DX_HPP #define XNA_PLATFORM_TEXTURE_DX_HPP -#include "../common/rectangle.hpp" +#include "../common/numerics.hpp" #include "../graphics/gresource.hpp" #include "../graphics/texture.hpp" #include "dxheaders.hpp" diff --git a/inc/xna.hpp b/inc/xna.hpp index d55d385..7c99015 100644 --- a/inc/xna.hpp +++ b/inc/xna.hpp @@ -10,11 +10,9 @@ #include "common/math.hpp" #include "common/matrix.hpp" #include "common/packedvalue.hpp" -#include "common/point.hpp" #include "common/quaternion.hpp" -#include "common/rectangle.hpp" +#include "common/numerics.hpp" #include "common/collision.hpp" -#include "common/vectors.hpp" #include "content/defaultreaders.hpp" #include "content/manager.hpp" #include "content/reader.hpp"