diff --git a/includes/xna/common/color.hpp b/includes/xna/common/color.hpp index 8738ed3..fbea764 100644 --- a/includes/xna/common/color.hpp +++ b/includes/xna/common/color.hpp @@ -1,18 +1,18 @@ #ifndef XNA_COMMON_COLOR_HPP #define XNA_COMMON_COLOR_HPP -#include "../default.hpp" #include "packedvalue.hpp" +#include namespace xna { //Represents a four-component color using red, green, blue, and alpha data. - struct Color : public IPackedVector, public IPackedVectorT { + struct Color : public IPackedVector, public IPackedVectorT { constexpr Color() = default; - constexpr Color(Uint packedValue) + constexpr Color(uint32_t packedValue) : _packedValue(packedValue) {} - constexpr Color(Int r, Int g, Int b, Int a = 255U) { + constexpr Color(int32_t r, int32_t g, int32_t b, int32_t a = 255U) { if (((r | g | b | a) & -256) != 0) { r = ClampToByte32(r); @@ -25,7 +25,7 @@ namespace xna { b <<= 16; a <<= 24; - _packedValue = static_cast(r | g | b | a); + _packedValue = static_cast(r | g | b | a); } Color(float r, float g, float b, float a = 1.0F); @@ -38,12 +38,12 @@ namespace xna { static Color FromNonPremultiplied(Vector4 const& vector); //Converts a non-premultipled alpha color to a color that contains premultiplied alpha. - static Color FromNonPremultiplied(Int r, Int g, Int b, Int a); + static Color FromNonPremultiplied(int32_t r, int32_t g, int32_t b, int32_t a); //Gets a three-component vector representation for this object. constexpr Vector3 ToVector3() const { Vector3 vector3; - const auto byteMax = static_cast(ByteMaxValue); + const auto byteMax = static_cast(ByteMaxValue); vector3.X = PackUtils::UnpackUNorm(byteMax, _packedValue); vector3.Y = PackUtils::UnpackUNorm(byteMax, _packedValue >> 8); vector3.Z = PackUtils::UnpackUNorm(byteMax, _packedValue >> 16); @@ -53,7 +53,7 @@ namespace xna { //Gets a four-component vector representation for this object. constexpr virtual Vector4 ToVector4() const override { Vector4 vector4; - const auto byteMax = static_cast(ByteMaxValue); + const auto byteMax = static_cast(ByteMaxValue); vector4.X = PackUtils::UnpackUNorm(byteMax, _packedValue); vector4.Y = PackUtils::UnpackUNorm(byteMax, _packedValue >> 8); vector4.Z = PackUtils::UnpackUNorm(byteMax, _packedValue >> 16); @@ -62,52 +62,52 @@ namespace xna { } //Gets or sets the red component value of this Color. - constexpr Byte R() const { - return static_cast(_packedValue); + constexpr uint8_t R() const { + return static_cast(_packedValue); } //Gets or sets the red component value of this Color. - constexpr void R(Byte value) { - _packedValue = _packedValue & (UintMaxValue - 255) | static_cast(value); + constexpr void R(uint8_t value) { + _packedValue = _packedValue & (UintMaxValue - 255) | static_cast(value); } //Gets or sets the green component value of this Color. - constexpr Byte G() const { - return static_cast(_packedValue >> 8); + constexpr uint8_t G() const { + return static_cast(_packedValue >> 8); } //Gets or sets the green component value of this Color. - constexpr void G(Byte value) { - _packedValue = (static_cast(_packedValue) & -65281 | static_cast(value) << 8); + constexpr void G(uint8_t value) { + _packedValue = (static_cast(_packedValue) & -65281 | static_cast(value) << 8); } //Gets or sets the blue component value of this Color. - constexpr Byte B() const { - return static_cast(_packedValue >> 16); + constexpr uint8_t B() const { + return static_cast(_packedValue >> 16); } //Gets or sets the blue component value of this Color. - constexpr void B(Byte value) { - _packedValue = (static_cast(_packedValue) & -16711681 | static_cast(value) << 16); + constexpr void B(uint8_t value) { + _packedValue = (static_cast(_packedValue) & -16711681 | static_cast(value) << 16); } //Gets or sets the alpha component value. - constexpr Byte A() const { - return static_cast(_packedValue >> 24); + constexpr uint8_t A() const { + return static_cast(_packedValue >> 24); } //Gets or sets the alpha component value. - constexpr void A(Byte value) { - _packedValue = (static_cast(_packedValue) & 16777215 | static_cast(value) << 24); + constexpr void A(uint8_t value) { + _packedValue = (static_cast(_packedValue) & 16777215 | static_cast(value) << 24); } //Gets or sets the current color as a packed value. - virtual constexpr Uint PackedValue() const override { + virtual constexpr uint32_t PackedValue() const override { return _packedValue; } //Gets or sets the current color as a packed value. - virtual constexpr void PackedValue(Uint const& value) override { + virtual constexpr void PackedValue(uint32_t const& value) override { _packedValue = value; } @@ -116,19 +116,19 @@ namespace xna { //Multiply each color component by the scale factor. static constexpr Color Multiply(Color const& value, float scale) { - const Uint r = value.R(); - const Uint g = value.G(); - const Uint b = value.B(); - const Uint a = value.A(); + const uint32_t r = value.R(); + const uint32_t g = value.G(); + const uint32_t b = value.B(); + const uint32_t a = value.A(); scale *= 65536.0f; - const Uint num5 = scale >= 0.0F ? (scale <= 16777215.0F ? static_cast(scale) : 16777215U) : 0U; + const uint32_t num5 = scale >= 0.0F ? (scale <= 16777215.0F ? static_cast(scale) : 16777215U) : 0U; - Uint r1 = r * num5 >> 16; - Uint g1 = g * num5 >> 16; - Uint b1 = b * num5 >> 16; - Uint a1 = a * num5 >> 16; + uint32_t r1 = r * num5 >> 16; + uint32_t g1 = g * num5 >> 16; + uint32_t b1 = b * num5 >> 16; + uint32_t a1 = a * num5 >> 16; if (r1 > ByteMaxValue) r1 = ByteMaxValue; @@ -142,13 +142,13 @@ namespace xna { if (a1 > ByteMaxValue) a1 = ByteMaxValue; - const auto r2 = static_cast(r1); - const auto g2 = static_cast(g1); - const auto b2 = static_cast(b1); - const auto a2 = static_cast(a1); + const auto r2 = static_cast(r1); + const auto g2 = static_cast(g1); + const auto b2 = static_cast(b1); + const auto a2 = static_cast(a1); Color color; - color._packedValue = static_cast(r2 | g2 << 8 | b2 << 16 | a2 << 24); + color._packedValue = static_cast(r2 | g2 << 8 | b2 << 16 | a2 << 24); return color; } @@ -160,21 +160,24 @@ namespace xna { return Color::Multiply(value, scale); } - constexpr operator Uint() const { - return _packedValue; + constexpr operator uint32_t() const { + return _packedValue; } private: - Uint _packedValue{ 0 }; + uint32_t _packedValue{ 0 }; - static constexpr Int ClampToByte32(Int value) noexcept { + static constexpr int32_t ClampToByte32(int32_t value) noexcept { if (value < 0) return 0; return value > ByteMaxValue ? ByteMaxValue : value; } - static Uint PackHelper(float vectorX, float vectorY, float vectorZ, float vectorW); + static uint32_t PackHelper(float vectorX, float vectorY, float vectorZ, float vectorW); + + static constexpr uint8_t ByteMaxValue = (std::numeric_limits::max)(); + static constexpr uint32_t UintMaxValue = (std::numeric_limits::max)(); }; struct Colors { @@ -315,7 +318,7 @@ namespace xna { static constexpr Color Turquoise{ Color(4291878976U) }; static constexpr Color Violet{ Color(4293821166U) }; static constexpr Color Wheat{ Color(4289978101U) }; - static constexpr Color White{ Color(UintMaxValue) }; + static constexpr Color White{ Color((std::numeric_limits::max)()) }; static constexpr Color WhiteSmoke{ Color(4294309365U) }; static constexpr Color Yellow{ Color(4278255615U) }; static constexpr Color YellowGreen{ Color(4281519514U) }; diff --git a/includes/xna/common/packedvalue.hpp b/includes/xna/common/packedvalue.hpp index 306b0e1..65c548b 100644 --- a/includes/xna/common/packedvalue.hpp +++ b/includes/xna/common/packedvalue.hpp @@ -1,7 +1,6 @@ #ifndef CXNA_COMMON_PACKEDVECTOR_HPP #define CXNA_COMMON_PACKEDVECTOR_HPP -#include "../default.hpp" #include "numerics.hpp" #include @@ -19,17 +18,17 @@ namespace xna { struct PackUtils { - static constexpr float UnpackUNorm(Uint bitmask, Uint value) { + static constexpr float UnpackUNorm(uint32_t bitmask, uint32_t value) { value &= bitmask; return static_cast(value) / static_cast(bitmask); } - static constexpr float UnpackSNorm(Uint bitmask, Uint value) { + static constexpr float UnpackSNorm(uint32_t bitmask, uint32_t value) { const auto num1 = (bitmask + 1U) >> 1; - const auto ivalue = static_cast(value); - const auto inum1 = static_cast(num1); - const auto ibitmask = static_cast(bitmask); + const auto ivalue = static_cast(value); + const auto inum1 = static_cast(num1); + const auto ibitmask = static_cast(bitmask); if ((ivalue & inum1) != 0) { if ((ivalue & ibitmask) == inum1) @@ -42,13 +41,13 @@ namespace xna { const auto num2 = static_cast(bitmask >> 1); - return static_cast(value) / num2; + return static_cast(value) / num2; } - static Uint PackUnsigned(float bitmask, float value); - static Uint PackSigned(Uint bitmask, float value); - static Uint PackUNorm(float bitmask, float value); - static Uint PackSNorm(Uint bitmask, float value); + static uint32_t PackUnsigned(float bitmask, float value); + static uint32_t PackSigned(uint32_t bitmask, float value); + static uint32_t PackUNorm(float bitmask, float value); + static uint32_t PackSNorm(uint32_t bitmask, float value); static double ClampAndRound(float value, float min, float max); }; } diff --git a/sources/framework/CMakeLists.txt b/sources/framework/CMakeLists.txt index 426434b..65c899e 100644 --- a/sources/framework/CMakeLists.txt +++ b/sources/framework/CMakeLists.txt @@ -6,7 +6,6 @@ add_library (Xn65 STATIC "csharp/stream.cpp" "csharp/binary.cpp" - "game/component.cpp" "game/servicecontainer.cpp" "content/manager.cpp" diff --git a/sources/framework/common/color.cpp b/sources/framework/common/color.cpp index 9257296..c0d0fdc 100644 --- a/sources/framework/common/color.cpp +++ b/sources/framework/common/color.cpp @@ -23,7 +23,7 @@ namespace xna { return color; } - Color Color::FromNonPremultiplied(Int r, Int g, Int b, Int a) { + Color Color::FromNonPremultiplied(int32_t r, int32_t g, int32_t b, int32_t a) { r = ClampToByte32(r * a / ByteMaxValue); g = ClampToByte32(g * a / ByteMaxValue); b = ClampToByte32(b * a / ByteMaxValue); @@ -33,33 +33,33 @@ namespace xna { a <<= 24; Color color; - color._packedValue = static_cast(r | g | b | a); + color._packedValue = static_cast(r | g | b | a); return color; } Color Color::Lerp(Color const& value1, Color const& value2, float amount) { - const Int r1 = value1.R(); - const Int g1 = value1.G(); - const Int b1 = value1.B(); - const Int a1 = value1.A(); - const Int r2 = value2.R(); - const Int g2 = value2.G(); - const Int b2 = value2.B(); - const Int a2 = value2.A(); + const int32_t r1 = value1.R(); + const int32_t g1 = value1.G(); + const int32_t b1 = value1.B(); + const int32_t a1 = value1.A(); + const int32_t r2 = value2.R(); + const int32_t g2 = value2.G(); + const int32_t b2 = value2.B(); + const int32_t a2 = value2.A(); - const auto bitmask = static_cast(PackUtils::PackUNorm(65536.0f, amount)); + const auto bitmask = static_cast(PackUtils::PackUNorm(65536.0f, amount)); - const Int r = r1 + ((r2 - r1) * bitmask >> 16); - const Int g = g1 + ((g2 - g1) * bitmask >> 16); - const Int b = b1 + ((b2 - b1) * bitmask >> 16); - const Int a = a1 + ((a2 - a1) * bitmask >> 16); + const int32_t r = r1 + ((r2 - r1) * bitmask >> 16); + const int32_t g = g1 + ((g2 - g1) * bitmask >> 16); + const int32_t b = b1 + ((b2 - b1) * bitmask >> 16); + const int32_t a = a1 + ((a2 - a1) * bitmask >> 16); Color color; - color._packedValue = static_cast(r | g << 8 | b << 16 | a << 24); + color._packedValue = static_cast(r | g << 8 | b << 16 | a << 24); return color; } - Uint Color::PackHelper(float vectorX, float vectorY, float vectorZ, float vectorW) { + uint32_t Color::PackHelper(float vectorX, float vectorY, float vectorZ, float vectorW) { const auto byteMax = static_cast(ByteMaxValue); const auto x = PackUtils::PackUNorm(byteMax, vectorX); const auto y = PackUtils::PackUNorm(byteMax, vectorY) << 8; diff --git a/sources/framework/common/packedvalue.cpp b/sources/framework/common/packedvalue.cpp index 8af9a28..e01b652 100644 --- a/sources/framework/common/packedvalue.cpp +++ b/sources/framework/common/packedvalue.cpp @@ -1,26 +1,26 @@ #include "xna/common/packedvalue.hpp" namespace xna { - Uint PackUtils::PackUnsigned(float bitmask, float value) { - return static_cast(ClampAndRound(value, 0.0f, bitmask)); + uint32_t PackUtils::PackUnsigned(float bitmask, float value) { + return static_cast(ClampAndRound(value, 0.0f, bitmask)); } - Uint PackUtils::PackSigned(Uint bitmask, float value) { + uint32_t PackUtils::PackSigned(uint32_t bitmask, float value) { const auto max = static_cast(bitmask >> 1); const auto min = -max - 1.0F; - return static_cast(ClampAndRound(value, min, max)) & bitmask; + return static_cast(ClampAndRound(value, min, max)) & bitmask; } - Uint PackUtils::PackUNorm(float bitmask, float value) { + uint32_t PackUtils::PackUNorm(float bitmask, float value) { value *= bitmask; - return static_cast(ClampAndRound(value, 0.0f, bitmask)); + return static_cast(ClampAndRound(value, 0.0f, bitmask)); } - Uint PackUtils::PackSNorm(Uint bitmask, float value) { + uint32_t PackUtils::PackSNorm(uint32_t bitmask, float value) { const auto max = static_cast(bitmask >> 1); value *= max; - return static_cast(ClampAndRound(value, -max, max)) & bitmask; + return static_cast(ClampAndRound(value, -max, max)) & bitmask; } double PackUtils::ClampAndRound(float value, float min, float max) {