diff --git a/includes/xna/content/manager.hpp b/includes/xna/content/manager.hpp index ec70e7d..9486312 100644 --- a/includes/xna/content/manager.hpp +++ b/includes/xna/content/manager.hpp @@ -39,10 +39,10 @@ namespace xna { template auto Load(String const& assetName) { if (assetName.empty()) { - return XnaHelper::ReturnDefaultOrNull(); + return misc::ReturnDefaultOrNull(); } - if constexpr (XnaHelper::is_shared_ptr::value) { + if constexpr (misc::is_shared_ptr::value) { if (loadedAssets.contains(assetName)) { auto& voidAsset = loadedAssets[assetName]; @@ -54,7 +54,7 @@ namespace xna { const auto obj2 = ReadAsset(assetName); - if constexpr (XnaHelper::is_shared_ptr::value) { + if constexpr (misc::is_shared_ptr::value) { if(obj2) loadedAssets.emplace( assetName, obj2 ); @@ -79,7 +79,7 @@ namespace xna { auto input = OpenStream(assetName); if (!input) - return XnaHelper::ReturnDefaultOrNull(); + return misc::ReturnDefaultOrNull(); const auto _this = shared_from_this(); auto contentReader = ContentReader::Create(_this, input, assetName); diff --git a/includes/xna/content/reader.hpp b/includes/xna/content/reader.hpp index ff4b3f7..76d85b8 100644 --- a/includes/xna/content/reader.hpp +++ b/includes/xna/content/reader.hpp @@ -104,7 +104,7 @@ namespace xna { const auto num = Read7BitEncodedInt(); if (num == 0) { - XnaHelper::ReturnDefaultOrNull(); + misc::ReturnDefaultOrNull(); } const auto index = num - 1; @@ -133,7 +133,7 @@ namespace xna { Exception::Throw(Exception::NOT_IMPLEMENTED); } - return XnaHelper::ReturnDefaultOrNull(); + return misc::ReturnDefaultOrNull(); } template diff --git a/includes/xna/content/typereadermanager.hpp b/includes/xna/content/typereadermanager.hpp index 71324d4..3302980 100644 --- a/includes/xna/content/typereadermanager.hpp +++ b/includes/xna/content/typereadermanager.hpp @@ -56,7 +56,7 @@ namespace xna { if (existingInstance.has_value() && !(existingInstance.type() == typeid(T))) throw std::runtime_error("ContentTypeReader::Read: bad xbn, wrong type."); - auto existingInstance1 = XnaHelper::ReturnDefaultOrNull(); + auto existingInstance1 = misc::ReturnDefaultOrNull(); auto obj = Read(input, existingInstance1); return obj; } diff --git a/includes/xna/csharp/type.hpp b/includes/xna/csharp/type.hpp index de2eaa6..853b946 100644 --- a/includes/xna/csharp/type.hpp +++ b/includes/xna/csharp/type.hpp @@ -1,7 +1,7 @@ #ifndef XNA_CSHARP_TYPE_HPP #define XNA_CSHARP_TYPE_HPP -#include "../helpers.hpp" +#include "misc.hpp" #include "../exception.hpp" #include #include @@ -21,11 +21,11 @@ namespace xna { constexpr size_t GetHashCode() const { size_t seed = 0; - XnaHelper::HashCombine(seed, fullName); - XnaHelper::HashCombine(seed, isClass); - XnaHelper::HashCombine(seed, isEnum); - XnaHelper::HashCombine(seed, isValueType); - XnaHelper::HashCombine(seed, isPrimitive); + misc::HashCombine(seed, fullName); + misc::HashCombine(seed, isClass); + misc::HashCombine(seed, isEnum); + misc::HashCombine(seed, isValueType); + misc::HashCombine(seed, isPrimitive); return seed; } diff --git a/includes/xna/default.hpp b/includes/xna/default.hpp index 7608349..77dba3d 100644 --- a/includes/xna/default.hpp +++ b/includes/xna/default.hpp @@ -16,7 +16,7 @@ #include "enumerations.hpp" #include "exception.hpp" -#include "helpers.hpp" +#include "misc.hpp" namespace xna { diff --git a/includes/xna/enumerations.hpp b/includes/xna/enumerations.hpp index 06d1ff9..d636101 100644 --- a/includes/xna/enumerations.hpp +++ b/includes/xna/enumerations.hpp @@ -123,14 +123,7 @@ namespace xna { DiscardContents, PreserveContents, PlatformContents - }; - - enum class SpriteEffects { - None = 0, - FlipHorizontally = 1, - FlipVertically = 2, - Both = FlipHorizontally | FlipVertically - }; + }; constexpr int SURFACE_FORMAT_COUNT = 19; } diff --git a/includes/xna/framework.hpp b/includes/xna/framework.hpp index fd43a6f..eacb4d0 100644 --- a/includes/xna/framework.hpp +++ b/includes/xna/framework.hpp @@ -49,7 +49,6 @@ #include "graphics/texture.hpp" #include "graphics/vertexposition.hpp" #include "graphics/viewport.hpp" -#include "helpers.hpp" #include "input/gamepad.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" diff --git a/includes/xna/graphics/sprite.hpp b/includes/xna/graphics/sprite.hpp index 47525c2..bceb7d9 100644 --- a/includes/xna/graphics/sprite.hpp +++ b/includes/xna/graphics/sprite.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace xna { //Defines sprite sort-rendering options. @@ -31,6 +32,21 @@ namespace xna { FrontToBack, }; + enum class SpriteEffects { + None = 0, + FlipHorizontally = 1, + FlipVertically = 2, + Both = FlipHorizontally | FlipVertically + }; + + class BlendState; + class SamplerState; + class DepthStencilState; + class RasterizerState; + class Effect; + class Texture2D; + class SpriteFont; + struct SpriteBatchImplementation; //Enables a group of sprites to be drawn using the same settings. @@ -159,11 +175,11 @@ namespace xna { std::shared_ptr const& texture, std::vector const& glyphs, std::vector const& cropping, - std::vector const& charMap, + std::vector const& charMap, int32_t lineSpacing, float spacing, std::vector const& kerning, - std::optional const& defaultCharacter); + std::optional const& defaultCharacter); // Returns the width and height of a string. Vector2 MeasureString(std::string const& text, bool ignoreWhiteSpace = true); @@ -171,9 +187,9 @@ namespace xna { Vector2 MeasureString(std::wstring const& text, bool ignoreWhiteSpace = true); //Gets or sets the default character for the font. - Char DefaultCharacter() const; + char16_t DefaultCharacter() const; //Gets or sets the default character for the font. - void DefaultCharacter(Char value); + void DefaultCharacter(char16_t value); //Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text int32_t LineSpacing() const; //Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text diff --git a/includes/xna/graphics/texture.hpp b/includes/xna/graphics/texture.hpp index 19de646..d9525ce 100644 --- a/includes/xna/graphics/texture.hpp +++ b/includes/xna/graphics/texture.hpp @@ -51,11 +51,11 @@ namespace xna { void SetData(int32_t level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount); //Loads texture data from a stream. - static P_Texture2D FromStream(GraphicsDevice& device, std::shared_ptr const& stream); + static std::shared_ptr FromStream(GraphicsDevice& device, std::shared_ptr const& stream); //Loads texture data from a file. - static P_Texture2D FromStream(GraphicsDevice& device, std::string const& fileName); + static std::shared_ptr FromStream(GraphicsDevice& device, std::string const& fileName); //Loads texture data from a data. - static P_Texture2D FromStream(GraphicsDevice& device, std::vector const& data); + static std::shared_ptr FromStream(GraphicsDevice& device, std::vector const& data); void Initialize(); diff --git a/includes/xna/helpers.hpp b/includes/xna/helpers.hpp deleted file mode 100644 index 46fe92e..0000000 --- a/includes/xna/helpers.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef XNA_HELPERS_HPP -#define XNA_HELPERS_HPP - -#include "default.hpp" - -namespace xna { - //Class for helper functions - struct XnaHelper { - - // - // Smart Pointer Comparator - // - - template struct is_shared_ptr : std::false_type {}; - template struct is_shared_ptr> : std::true_type {}; - template struct is_weak_ptr : std::false_type {}; - template struct is_weak_ptr> : std::true_type {}; - template struct is_unique_ptr : std::false_type {}; - template struct is_unique_ptr> : std::true_type {}; - - //Returns true if the type is a smart pointer - template - static constexpr bool IsSmartPoint() { - return is_shared_ptr::value || is_unique_ptr::value || is_weak_ptr::value; - } - - //Convert a string to wstring - static inline std::wstring ToWString(const std::string& str) - { - std::wstring wstr; - size_t size; - wstr.resize(str.length()); - mbstowcs_s(&size, &wstr[0], wstr.size() + 1, str.c_str(), str.size()); - return wstr; - } - - //Convert a wstring to string - static inline std::string ToString(const std::wstring& wstr) - { - std::string str; - size_t size; - str.resize(wstr.length()); - wcstombs_s(&size, &str[0], str.size() + 1, wstr.c_str(), wstr.size()); - return str; - } - - //Returns a hash reporting input values - template - static constexpr void HashCombine(std::size_t& seed, const T& v) { - std::hash hasher; - seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } - - //Returns null if the type is a smart pointer or default value if the type has a default constructor. - //Throws an exception if the object cannot be created - template - static inline auto ReturnDefaultOrNull(const std::source_location location = std::source_location::current()) { - if constexpr (IsSmartPoint()) - return (T)nullptr; - else if constexpr (std::is_default_constructible::value) - return T(); - else - Exception::Throw(Exception::UNABLE_TO_BUILD_OBJECT, location); - } - }; -} - -#endif \ No newline at end of file diff --git a/sources/framework-dx/adapter.cpp b/sources/framework-dx/adapter.cpp index 41afe0f..630ec8d 100644 --- a/sources/framework-dx/adapter.cpp +++ b/sources/framework-dx/adapter.cpp @@ -28,7 +28,7 @@ namespace xna { DXGI_ADAPTER_DESC1 desc{}; pAdapter->GetDesc1(&desc); - adp->description = XnaHelper::ToString(desc.Description); + adp->description = misc::ToString(desc.Description); adp->deviceId = static_cast(desc.DeviceId); adp->isDefault = true; adp->revision = static_cast(desc.Revision); @@ -68,7 +68,7 @@ namespace xna { DXGI_ADAPTER_DESC1 desc{}; pAdapter->GetDesc1(&desc); - adp->description = XnaHelper::ToString(desc.Description); + adp->description = misc::ToString(desc.Description); adp->deviceId = static_cast(desc.DeviceId); adp->isDefault = count == 0; adp->revision = static_cast(desc.Revision); @@ -253,7 +253,7 @@ namespace xna { DXGI_OUTPUT_DESC outputDesc; pOutput->GetDesc(&outputDesc); - deviceName = XnaHelper::ToString(outputDesc.DeviceName); + deviceName = misc::ToString(outputDesc.DeviceName); monitorHandle = reinterpret_cast(outputDesc.Monitor); } } diff --git a/sources/framework-dx/soundeffect.cpp b/sources/framework-dx/soundeffect.cpp index 5da1386..6bb5276 100644 --- a/sources/framework-dx/soundeffect.cpp +++ b/sources/framework-dx/soundeffect.cpp @@ -16,7 +16,7 @@ namespace xna { if (!AudioEngine::impl || !AudioEngine::impl->_dxAudioEngine) return; - const auto file = XnaHelper::ToWString(fileName); + const auto file = misc::ToWString(fileName); impl->_dxSoundEffect = unew(AudioEngine::impl->_dxAudioEngine.get(), file.c_str()); } diff --git a/sources/framework-dx/texture.cpp b/sources/framework-dx/texture.cpp index e771964..7fde8d3 100644 --- a/sources/framework-dx/texture.cpp +++ b/sources/framework-dx/texture.cpp @@ -231,7 +231,7 @@ namespace xna { auto _this = device.shared_from_this(); auto texture2d = snew(_this); comptr resource = nullptr; - auto wstr = XnaHelper::ToWString(fileName); + auto wstr = misc::ToWString(fileName); HRESULT result = DirectX::CreateWICTextureFromFile( device.Implementation->Device.Get(),