From dbd2495bdb6be97d773bf302a9be91618b709765 Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 8 Jul 2024 09:40:48 -0300 Subject: [PATCH] Remove platforminit.hpp --- framework/CMakeLists.txt | 2 +- framework/platform-dx/impl.cpp | 5 -- framework/platform-dx/init.cpp | 1 - framework/platform-dx/mouse.cpp | 1 - inc/xna/graphics/sprite.hpp | 48 +++++++++++- inc/xna/input/keyboard.hpp | 10 +-- inc/xna/input/mouse.hpp | 10 +-- inc/xna/platform/dx.hpp | 96 ++++++++++------------- inc/xna/platform/init.hpp | 46 ----------- inc/xna/platforminit.hpp | 13 --- inc/xna/xna.hpp | 17 +++- samples/01_blank/xna.cpp | 1 + samples/02_PlatfformerStarterKit/game.cpp | 1 + 13 files changed, 115 insertions(+), 136 deletions(-) delete mode 100644 framework/platform-dx/impl.cpp delete mode 100644 inc/xna/platform/init.hpp delete mode 100644 inc/xna/platforminit.hpp diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 49fdda3..4541fb7 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -40,7 +40,7 @@ add_library (Xn65 STATIC "platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp" -"platform-dx/impl.cpp") +) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20) diff --git a/framework/platform-dx/impl.cpp b/framework/platform-dx/impl.cpp deleted file mode 100644 index 6d7f0cb..0000000 --- a/framework/platform-dx/impl.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "xna/platform/dx.hpp" - -namespace xna { - -} \ No newline at end of file diff --git a/framework/platform-dx/init.cpp b/framework/platform-dx/init.cpp index 01db842..80eb404 100644 --- a/framework/platform-dx/init.cpp +++ b/framework/platform-dx/init.cpp @@ -1,4 +1,3 @@ -#include "xna/platform/init.hpp" #include "xna/csharp/type.hpp" #include "xna/content/readers/graphics.hpp" #include "xna/content/readers/audio.hpp" diff --git a/framework/platform-dx/mouse.cpp b/framework/platform-dx/mouse.cpp index abd6b7d..6a11b5b 100644 --- a/framework/platform-dx/mouse.cpp +++ b/framework/platform-dx/mouse.cpp @@ -1,4 +1,3 @@ -#include "xna/input/mouse.hpp" #include "xna/platform/dx.hpp" namespace xna { diff --git a/inc/xna/graphics/sprite.hpp b/inc/xna/graphics/sprite.hpp index b21c456..3bfb2d0 100644 --- a/inc/xna/graphics/sprite.hpp +++ b/inc/xna/graphics/sprite.hpp @@ -1,11 +1,11 @@ #ifndef XNA_GRAPHICS_SPRITE_HPP #define XNA_GRAPHICS_SPRITE_HPP -#include "../default.hpp" -#include "../common/numerics.hpp" #include "../common/color.hpp" -#include +#include "../common/numerics.hpp" +#include "../default.hpp" #include "../graphics/gresource.hpp" +#include namespace xna { //Enables a group of sprites to be drawn using the same settings. @@ -13,7 +13,47 @@ namespace xna { public: SpriteBatch(sptr const& device); - //Begins a sprite batch operation. + //Begins a sprite batch operation. + void Begin( + std::optional sortMode, + uptr blendState, + uptr samplerState, + uptr depthStencil, + uptr rasterizerState, + uptr effect, + Matrix const& transformMatrix = Matrix::Identity() + ) { + Begin( + !sortMode.has_value() ? SpriteSortMode::Deferred : sortMode.value(), + blendState.get(), + samplerState.get(), + depthStencil.get(), + rasterizerState.get(), + effect.get(), + transformMatrix + ); + } + + void Begin( + std::optional sortMode, + sptr blendState, + sptr samplerState, + sptr depthStencil, + sptr rasterizerState, + sptr effect, + Matrix const& transformMatrix = Matrix::Identity() + ) { + Begin( + !sortMode.has_value() ? SpriteSortMode::Deferred : sortMode.value(), + blendState.get(), + samplerState.get(), + depthStencil.get(), + rasterizerState.get(), + effect.get(), + transformMatrix + ); + } + void Begin( SpriteSortMode sortMode = SpriteSortMode::Deferred, BlendState* blendState = nullptr, diff --git a/inc/xna/input/keyboard.hpp b/inc/xna/input/keyboard.hpp index 7957664..67fd58b 100644 --- a/inc/xna/input/keyboard.hpp +++ b/inc/xna/input/keyboard.hpp @@ -219,16 +219,16 @@ namespace xna { public: //Returns the current keyboard or Chatpad state. static KeyboardState GetState(); - static bool IsConnected(); - - Keyboard() = delete; - Keyboard(Keyboard&) = delete; - Keyboard(Keyboard&&) = delete; + static bool IsConnected(); private: friend class Game; static void Initialize(); + Keyboard() = default; + Keyboard(Keyboard&) = default; + Keyboard(Keyboard&&) = default; + public: struct PlatformImplementation; inline static uptr impl = nullptr; diff --git a/inc/xna/input/mouse.hpp b/inc/xna/input/mouse.hpp index 2f8277f..8686291 100644 --- a/inc/xna/input/mouse.hpp +++ b/inc/xna/input/mouse.hpp @@ -24,16 +24,16 @@ namespace xna { static bool IsConnected(); static bool IsVisible(); static void IsVisible(bool value); - static void ResetScrollWheel(); - - Mouse() = delete; - Mouse(Mouse&) = delete; - Mouse(Mouse&&) = delete; + static void ResetScrollWheel(); private: friend class Game; static void Initialize(); + Mouse() = default; + Mouse(Mouse&) = default; + Mouse(Mouse&&) = default; + public: struct PlatformImplementation; inline static uptr impl = nullptr; diff --git a/inc/xna/platform/dx.hpp b/inc/xna/platform/dx.hpp index 321acc8..0a0752a 100644 --- a/inc/xna/platform/dx.hpp +++ b/inc/xna/platform/dx.hpp @@ -1,9 +1,7 @@ #ifndef XNA_PLATFORMDX_DX_HPP #define XNA_PLATFORMDX_DX_HPP -//--------------------------------// -// DX INCLUDES -//--------------------------------// +//---------------- DX INCLUDES ----------------// //DirectX #if defined(_XBOX_ONE) && defined(_TITLE) @@ -48,55 +46,19 @@ #include #include -//--------------------------------// -// USINGS -//--------------------------------// +//---------------- USINGS ----------------// template using comptr = Microsoft::WRL::ComPtr; -//--------------------------------// -// OTHERS INCLUDES -//--------------------------------// +//---------------- INCLUDES ----------------// -#include "../default.hpp" -#include "../exception.hpp" -#include "../graphics/blendstate.hpp" -#include "../graphics/adapter.hpp" -#include "../graphics/device.hpp" -#include "../graphics/adapter.hpp" -#include "../graphics/blendstate.hpp" -#include "../graphics/depthstencilstate.hpp" -#include "../graphics/displaymode.hpp" -#include "../graphics/sprite.hpp" -#include "../graphics/effect.hpp" -#include "../graphics/samplerstate.hpp" -#include "../input/gamepad.hpp" -#include "../input/keyboard.hpp" -#include "../input/mouse.hpp" -#include "../graphics/rasterizerstate.hpp" -#include "../graphics/presentparams.hpp" -#include "../graphics/swapchain.hpp" -#include "../graphics/texture.hpp" -#include "../graphics/rendertarget.hpp" -#include "../game/window.hpp" -#include "../audio/audioengine.hpp" -#include "../audio/soundeffect.hpp" -#include "../graphics/viewport.hpp" -#include "../common/color.hpp" -#include "../game/game.hpp" -#include -#include -#include +#include "../xna.hpp" -//--------------------------------// -// CLASSES -//--------------------------------// +//---------------- CLASSES ----------------// namespace xna { - //==============================================// - //================ DXHELPERS ================// - //==============================================// + //---------------- HELPERS ----------------// struct DxHelpers { static constexpr DirectX::XMVECTOR VectorToDx(Vector2 const& value) { @@ -378,12 +340,43 @@ namespace xna { static constexpr TextureAddressMode TextureAddresModeToXna(D3D11_TEXTURE_ADDRESS_MODE value) { return static_cast(value - 1); } + }; + + struct PlatformInit { + static void Init() { + InitRegisteredTypes(); + InitActivadors(); + } + + static void InitRegisteredTypes(); + static void InitActivadors(); + + private: + template + static void insertRegisteredReader(String const& readerName) { + const auto reader = typeof(); + //Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader }); + Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader }); + Type::NameOfRegisteredTypes.insert({ "Microsoft.Xna.Framework.Content." + readerName, reader }); + } + + template + static void insertRegisteredReader(String const& readerName, String const& microsoftNameFullName) { + const auto reader = typeof(); + //Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader }); + Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader }); + Type::NameOfRegisteredTypes.insert({ microsoftNameFullName, reader }); + } + + template + static void insertActivadorReader() { + ContentTypeReaderActivador::SetActivador(typeof(), []() -> sptr { + auto obj = snew(); + return reinterpret_pointer_cast(obj); + }); + } }; - - //==============================================// - //================ STEPTIMER ================// - //==============================================// - + // Helper class for animation and simulation timing. class StepTimer { @@ -561,10 +554,7 @@ namespace xna { uint64_t m_targetElapsedTicks; }; - - //==============================================// - //================ IMPL ================// - //==============================================// + //---------------- IMPL ----------------// struct SpriteFont::PlatformImplementation { uptr _dxSpriteFont{ nullptr }; diff --git a/inc/xna/platform/init.hpp b/inc/xna/platform/init.hpp deleted file mode 100644 index b047fe9..0000000 --- a/inc/xna/platform/init.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef XNA_PLATFORM_INIT_HPP -#define XNA_PLATFORM_INIT_HPP - -#include "../default.hpp" -#include "../csharp/type.hpp" -#include "../content/typereadermanager.hpp" -#include "../platforminit.hpp" - -namespace xna { - struct PlatformInit { - static void Init() { - InitRegisteredTypes(); - InitActivadors(); - } - - static void InitRegisteredTypes(); - static void InitActivadors(); - - private: - template - static void insertRegisteredReader(String const& readerName) { - const auto reader = typeof(); - //Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader }); - Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader }); - Type::NameOfRegisteredTypes.insert({ "Microsoft.Xna.Framework.Content." + readerName, reader }); - } - - template - static void insertRegisteredReader(String const& readerName, String const& microsoftNameFullName) { - const auto reader = typeof(); - //Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader }); - Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader }); - Type::NameOfRegisteredTypes.insert({ microsoftNameFullName, reader }); - } - - template - static void insertActivadorReader() { - ContentTypeReaderActivador::SetActivador(typeof(), []() -> sptr { - auto obj = snew(); - return reinterpret_pointer_cast(obj); - }); - } - }; -} - -#endif \ No newline at end of file diff --git a/inc/xna/platforminit.hpp b/inc/xna/platforminit.hpp deleted file mode 100644 index 10071c6..0000000 --- a/inc/xna/platforminit.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef XNA_PLATFORMINIT_HPP -#define XNA_PLATFORMINIT_HPP - -namespace xna { - //Exposes functions that must be implemented by the platform - struct Platform { - //Initialization function, which must be implemented by the platform, - //and be called before the game is executed - static void Init(); - }; -} - -#endif \ No newline at end of file diff --git a/inc/xna/xna.hpp b/inc/xna/xna.hpp index a0f08a8..1bc4cbb 100644 --- a/inc/xna/xna.hpp +++ b/inc/xna/xna.hpp @@ -1,3 +1,6 @@ +#ifndef XNA_XNA_HPP +#define XNA_XNA_HPP + #define NOMINMAX #include "audio/audioengine.hpp" #include "audio/soundeffect.hpp" @@ -44,10 +47,20 @@ #include "graphics/texture.hpp" #include "graphics/vertexposition.hpp" #include "graphics/viewport.hpp" +#include "graphics/effect.hpp" #include "helpers.hpp" #include "input/gamepad.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" -#include "platforminit.hpp" #include "types.hpp" -#include "platform/dx.hpp" \ No newline at end of file + +namespace xna { + //Exposes functions that must be implemented by the platform + struct Platform { + //Initialization function, which must be implemented by the platform, + //and be called before the game is executed + static void Init(); + }; +} + +#endif \ No newline at end of file diff --git a/samples/01_blank/xna.cpp b/samples/01_blank/xna.cpp index c14c086..2c8bd9a 100644 --- a/samples/01_blank/xna.cpp +++ b/samples/01_blank/xna.cpp @@ -2,6 +2,7 @@ // #include "xna/xna.hpp" +#include "xna/platform/dx.hpp" using namespace std; using namespace xna; diff --git a/samples/02_PlatfformerStarterKit/game.cpp b/samples/02_PlatfformerStarterKit/game.cpp index d7ee920..2f2c343 100644 --- a/samples/02_PlatfformerStarterKit/game.cpp +++ b/samples/02_PlatfformerStarterKit/game.cpp @@ -2,6 +2,7 @@ // #include "xna/xna.hpp" +#include "xna/platform/dx.hpp" #include "player.hpp" #include "enemy.hpp" #include "level.hpp"