diff --git a/.gitignore b/.gitignore index f77b8e8c..43cbec43 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Xmake.Custom.props Xmake.Custom.targets build src/CoreLib/VersionData.hpp +vsxmake*/ # Game binaries Assets/* @@ -45,6 +46,7 @@ Makefile *.VC.opendb *.VC.db* *.leu +*.vsidx # VS Code .vscode diff --git a/include/ClientLib/Camera.hpp b/include/ClientLib/Camera.hpp index 864285fa..d6ac0308 100644 --- a/include/ClientLib/Camera.hpp +++ b/include/ClientLib/Camera.hpp @@ -9,11 +9,16 @@ #include #include +#include #include #include #include -#include -#include +#include + +namespace Nz +{ + class EnttWorld; +} namespace bw { @@ -24,7 +29,7 @@ namespace bw class BURGWAR_CLIENTLIB_API Camera : public Nz::HandledObject { public: - Camera(Ndk::World& world, Nz::RenderTarget* renderTarget, bool perspective); + Camera(Nz::EnttWorld& world, std::shared_ptr renderTarget, bool perspective); Camera(const Camera&) = delete; Camera(Camera&&) = delete; ~Camera() = default; @@ -59,10 +64,12 @@ namespace bw private: void UpdateProjection(); void UpdateZoomFactor(); + void UpdateZoomFactor(const Nz::Vector2ui& newRenderTargetSize); NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_onTargetSizeChanged); - Ndk::EntityOwner m_cameraEntity; + Nz::Vector3f m_offset; + EntityOwner m_cameraEntity; bool m_isPerspective; float m_projectedDepth; float m_invFovTan; diff --git a/include/ClientLib/Chatbox.hpp b/include/ClientLib/Chatbox.hpp index 17485b1f..e2e634fd 100644 --- a/include/ClientLib/Chatbox.hpp +++ b/include/ClientLib/Chatbox.hpp @@ -8,14 +8,13 @@ #define BURGWAR_CLIENTLIB_CHATBOX_HPP #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include namespace bw @@ -37,7 +36,7 @@ namespace bw using Item = std::variant; - Chatbox(const Logger& logger, Nz::RenderTarget* rt, Ndk::Canvas* canvas); + Chatbox(const Logger& logger, const Nz::RenderTarget& renderTarget, Nz::Canvas* canvas); Chatbox(const Chatbox&) = delete; Chatbox(Chatbox&&) = delete; ~Chatbox(); @@ -60,15 +59,15 @@ namespace bw NazaraSignal(OnChatMessage, const std::string& /*message*/); private: - void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget); + void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget, const Nz::Vector2ui& newSize); void Refresh(); NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_onTargetChangeSizeSlot); std::vector> m_chatLines; - Ndk::ScrollAreaWidget* m_chatboxScrollArea; - Ndk::RichTextAreaWidget* m_chatBox; - Ndk::TextAreaWidget* m_chatEnteringBox; + Nz::RichTextAreaWidget* m_chatBox; + Nz::ScrollAreaWidget* m_chatboxScrollArea; + Nz::TextAreaWidget* m_chatEnteringBox; const Logger& m_logger; }; } diff --git a/include/ClientLib/ClientAssetStore.hpp b/include/ClientLib/ClientAssetStore.hpp index 56aa3009..ddd01110 100644 --- a/include/ClientLib/ClientAssetStore.hpp +++ b/include/ClientLib/ClientAssetStore.hpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace bw { @@ -23,14 +23,14 @@ namespace bw void Clear() override; - const Nz::ModelRef& GetModel(const std::string& modelPath) const; - const Nz::SoundBufferRef& GetSoundBuffer(const std::string& soundPath) const; - const Nz::TextureRef& GetTexture(const std::string& texturePath) const; + const std::shared_ptr& GetModel(const std::string& modelPath) const; + const std::shared_ptr& GetSoundBuffer(const std::string& soundPath) const; + const std::shared_ptr& GetTexture(const std::string& texturePath) const; private: - mutable tsl::hopscotch_map m_models; - mutable tsl::hopscotch_map m_soundBuffers; - mutable tsl::hopscotch_map m_textures; + mutable tsl::hopscotch_map> m_models; + mutable tsl::hopscotch_map> m_soundBuffers; + mutable tsl::hopscotch_map> m_textures; }; } diff --git a/include/ClientLib/ClientConsole.hpp b/include/ClientLib/ClientConsole.hpp index 92ddd392..4fd278bc 100644 --- a/include/ClientLib/ClientConsole.hpp +++ b/include/ClientLib/ClientConsole.hpp @@ -20,7 +20,7 @@ namespace bw class BURGWAR_CLIENTLIB_API ClientConsole : public Console { public: - ClientConsole(const Logger& logger, Nz::RenderTarget* window, Ndk::Canvas* canvas, std::shared_ptr scriptingLibrary, const std::shared_ptr& scriptDir); + ClientConsole(const Logger& logger, const Nz::RenderTarget& renderTarget, Nz::Canvas* canvas, std::shared_ptr scriptingLibrary, const std::shared_ptr& scriptDir); ClientConsole(const ClientConsole&) = delete; ClientConsole(ClientConsole&&) = delete; ~ClientConsole() = default; diff --git a/include/ClientLib/ClientEditorLayer.hpp b/include/ClientLib/ClientEditorLayer.hpp index 6569f5aa..a0485ec6 100644 --- a/include/ClientLib/ClientEditorLayer.hpp +++ b/include/ClientLib/ClientEditorLayer.hpp @@ -10,8 +10,13 @@ #include #include #include -#include -#include +#include +#include + +namespace Nz +{ + class EnttSystemGraph; +} namespace bw { @@ -20,17 +25,20 @@ namespace bw public: ClientEditorLayer(SharedMatch& match, LayerIndex layerIndex); ClientEditorLayer(const ClientEditorLayer&) = delete; - ClientEditorLayer(ClientEditorLayer&&) noexcept = default; + ClientEditorLayer(ClientEditorLayer&&) = delete; ~ClientEditorLayer() = default; - virtual void FrameUpdate(float elapsedTime); - virtual void PreFrameUpdate(float elapsedTime); - virtual void PostFrameUpdate(float elapsedTime); - - void TickUpdate(float elapsedTime) override; + virtual void FrameUpdate(Nz::Time elapsedTime); + virtual void PreFrameUpdate(Nz::Time elapsedTime); + virtual void PostFrameUpdate(Nz::Time elapsedTime); ClientEditorLayer& operator=(const ClientEditorLayer&) = delete; ClientEditorLayer& operator=(ClientEditorLayer&&) = delete; + + private: + Nz::EnttSystemGraph m_frameSystemGraph; + Nz::EnttSystemGraph m_preFrameSystemGraph; + Nz::EnttSystemGraph m_postFrameSystemGraph; }; } diff --git a/include/ClientLib/ClientLayer.hpp b/include/ClientLib/ClientLayer.hpp index e2bd79e3..41ff7972 100644 --- a/include/ClientLib/ClientLayer.hpp +++ b/include/ClientLib/ClientLayer.hpp @@ -7,8 +7,9 @@ #ifndef BURGWAR_CLIENTLIB_CLIENTLAYER_HPP #define BURGWAR_CLIENTLIB_CLIENTLAYER_HPP -#include -#include +#include +#include +#include #include #include #include @@ -30,7 +31,7 @@ namespace bw public: ClientLayer(ClientMatch& match, LayerIndex layerIndex, const Nz::Color& backgroundColor); ClientLayer(const ClientLayer&) = delete; - ClientLayer(ClientLayer&&) noexcept; + ClientLayer(ClientLayer&&) = delete; ~ClientLayer(); inline void Disable(); @@ -50,7 +51,7 @@ namespace bw bool IsEnabled() const override; inline bool IsPredictionEnabled() const; - void PostFrameUpdate(float elapsedTime) override; + void PostFrameUpdate(Nz::Time elapsedTime) override; ClientLayerEntity& RegisterEntity(ClientLayerEntity layerEntity); ClientLayerSound& RegisterSound(ClientLayerSound layerEntity); @@ -91,7 +92,7 @@ namespace bw ClientLayerEntity layerEntity; - NazaraSlot(Ndk::Entity, OnEntityDestruction, onDestruction); + NazaraSlot(DestructionWatcherComponent, OnDestruction, onDestruction); }; struct SoundData diff --git a/include/ClientLib/ClientLayerEntity.hpp b/include/ClientLib/ClientLayerEntity.hpp index 0d67feb9..0f010961 100644 --- a/include/ClientLib/ClientLayerEntity.hpp +++ b/include/ClientLib/ClientLayerEntity.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,7 +31,7 @@ namespace bw class BURGWAR_CLIENTLIB_API ClientLayerEntity final : public LayerVisualEntity { public: - ClientLayerEntity(ClientLayer& layer, const Ndk::EntityHandle& entity, Nz::UInt32 serverEntityId, EntityId uniqueId); + ClientLayerEntity(ClientLayer& layer, entt::handle entity, Nz::UInt32 serverEntityId, EntityId uniqueId); ClientLayerEntity(const ClientLayerEntity&) = delete; ClientLayerEntity(ClientLayerEntity&& entity) noexcept = default; ~ClientLayerEntity(); @@ -72,7 +72,7 @@ namespace bw struct DebugEntityIdData { - Nz::TextSpriteRef entityIdSprite; + std::shared_ptr entityIdSprite; }; struct HealthData @@ -80,8 +80,8 @@ namespace bw float spriteWidth; Nz::UInt16 currentHealth; Nz::UInt16 maxHealth; - Nz::SpriteRef healthSprite; - Nz::SpriteRef lostHealthSprite; + std::shared_ptr healthSprite; + std::shared_ptr lostHealthSprite; }; std::unique_ptr m_ghostEntity; diff --git a/include/ClientLib/ClientLayerSound.hpp b/include/ClientLib/ClientLayerSound.hpp index 7790bd88..b8ad3025 100644 --- a/include/ClientLib/ClientLayerSound.hpp +++ b/include/ClientLib/ClientLayerSound.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -36,15 +36,15 @@ namespace bw inline ClientLayerSound(ClientLayerSound&& entity) noexcept; ~ClientLayerSound() = default; - float GetSoundDuration(std::size_t soundIndex) const; + Nz::Time GetSoundDuration(std::size_t soundIndex) const; LayerIndex GetLayerIndex() const; inline Nz::Vector2f GetPosition() const; - std::size_t PlaySound(const Nz::SoundBufferRef& soundBuffer, bool isLooping, bool isSpatialized); + std::size_t PlaySound(const std::shared_ptr& soundBuffer, bool isLooping, bool isSpatialized); void StopSound(std::size_t soundIndex); - bool Update(float elapsedTime); + bool Update(Nz::Time elapsedTime); inline void UpdatePosition(const Nz::Vector2f& position); @@ -60,9 +60,9 @@ namespace bw struct PlayingSound { - Nz::SoundBufferRef soundBuffer; - float currentOffset = 0.f; - float duration = 0.f; + std::shared_ptr soundBuffer; + Nz::Time currentOffset = Nz::Time::Zero(); + Nz::Time duration = Nz::Time::Zero(); bool isLooping; bool isSpatialized; }; diff --git a/include/ClientLib/ClientMatch.hpp b/include/ClientLib/ClientMatch.hpp index 7f526b0a..107d8405 100644 --- a/include/ClientLib/ClientMatch.hpp +++ b/include/ClientLib/ClientMatch.hpp @@ -26,12 +26,13 @@ #include #include #include -#include +#include #include -#include +#include #include -#include -#include +#include +#include +#include #include #include #include @@ -41,7 +42,7 @@ namespace bw { - class ClientEditorApp; + class ClientEditorAppComponent; class Camera; class ClientGamemode; class ClientSession; @@ -54,7 +55,7 @@ namespace bw friend ClientSession; public: - ClientMatch(ClientEditorApp& burgApp, Nz::RenderWindow* window, Nz::RenderTarget* renderTarget, Ndk::Canvas* canvas, ClientSession& session, const Packets::AuthSuccess& authSuccess, const Packets::MatchData& matchData); + ClientMatch(ClientEditorAppComponent& burgApp, Nz::Window* window, std::shared_ptr renderTarget, Nz::Canvas* canvas, Nz::EnttWorld& renderWorld, ClientSession& session, const Packets::AuthSuccess& authSuccess, const Packets::MatchData& matchData); ClientMatch(const ClientMatch&) = delete; ClientMatch(ClientMatch&&) = delete; ~ClientMatch(); @@ -65,13 +66,13 @@ namespace bw Nz::UInt64 EstimateServerTick() const; - void ForEachEntity(std::function func) override; + void ForEachEntity(Nz::FunctionRef func) override; template void ForEachPlayer(F&& func); inline Nz::UInt16 GetActiveLayer(); inline AnimationManager& GetAnimationManager(); inline ClientAssetStore& GetAssetStore(); - inline ClientEditorApp& GetApplication(); + inline ClientEditorAppComponent& GetApplication(); inline Camera& GetCamera(); inline const Camera& GetCamera() const; inline ClientSession& GetClientSession(); @@ -85,29 +86,29 @@ namespace bw inline std::size_t GetLocalPlayerCount() const; inline const PlayerInputData& GetLocalPlayerInputs(std::size_t localPlayerIndex) const; const NetworkStringStore& GetNetworkStringStore() const override; - inline ParticleRegistry& GetParticleRegistry(); - inline const ParticleRegistry& GetParticleRegistry() const; + //inline ParticleRegistry& GetParticleRegistry(); + //inline const ParticleRegistry& GetParticleRegistry() const; inline ClientPlayer* GetPlayerByIndex(Nz::UInt16 playerIndex); - inline Ndk::World& GetRenderWorld(); + inline Nz::EnttWorld& GetRenderWorld(); std::shared_ptr GetSharedGamemode() const override; ClientWeaponStore& GetWeaponStore() override; const ClientWeaponStore& GetWeaponStore() const override; void InitDebugGhosts(); - void LoadAssets(std::shared_ptr assetDir); - void LoadScripts(const std::shared_ptr& scriptDir); + void LoadAssets(std::shared_ptr assetDir); + void LoadScripts(const std::shared_ptr& scriptDir); inline void Quit(); void RegisterEntity(EntityId uniqueId, ClientLayerEntityHandle entity); - - const Ndk::EntityHandle& RetrieveEntityByUniqueId(EntityId uniqueId) const override; - EntityId RetrieveUniqueIdByEntity(const Ndk::EntityHandle& entity) const override; + + entt::handle RetrieveEntityByUniqueId(EntityId uniqueId) const override; + EntityId RetrieveUniqueIdByEntity(entt::handle entity) const override; void UnregisterEntity(EntityId uniqueId); - bool Update(float elapsedTime); + bool Update(Nz::Time elapsedTime); ClientMatch& operator=(const ClientMatch&) = delete; ClientMatch& operator=(ClientMatch&&) = delete; @@ -141,7 +142,7 @@ namespace bw void BindEscapeMenu(); void BindPackets(); - void BindSignals(ClientEditorApp& burgApp, Nz::RenderWindow* window, Ndk::Canvas* canvas); + void BindSignals(ClientEditorAppComponent& burgApp, Nz::Window* window, Nz::Canvas* canvas); void HandleChatMessage(const Packets::ChatMessage& packet); void HandleConsoleAnswer(const Packets::ConsoleAnswer& packet); void HandleEntityCreated(ClientLayer* layer, ClientLayerEntity& entity); @@ -181,7 +182,7 @@ namespace bw { struct Weapon { - Ndk::EntityHandle entity; + entt::entity entity; Nz::UInt8 category; }; @@ -213,7 +214,7 @@ namespace bw struct WeaponData { - Ndk::EntityHandle entity; + entt::entity entity; bool isAttacking; }; @@ -258,15 +259,16 @@ namespace bw }; NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_onRenderTargetSizeChange); - NazaraSlot(Nz::EventHandler, OnGainedFocus, m_onGainedFocus); - NazaraSlot(Nz::EventHandler, OnLostFocus, m_onLostFocus); - NazaraSlot(Ndk::Canvas, OnUnhandledKeyPressed, m_onUnhandledKeyPressed); - NazaraSlot(Ndk::Canvas, OnUnhandledKeyReleased, m_onUnhandledKeyReleased); + NazaraSlot(Nz::WindowEventHandler, OnGainedFocus, m_onGainedFocus); + NazaraSlot(Nz::WindowEventHandler, OnLostFocus, m_onLostFocus); + NazaraSlot(Nz::Canvas, OnUnhandledKeyPressed, m_onUnhandledKeyPressed); + NazaraSlot(Nz::Canvas, OnUnhandledKeyReleased, m_onUnhandledKeyReleased); NazaraSlot(ClientLayer, OnEntityCreated, m_onEntityCreated); NazaraSlot(ClientLayer, OnEntityDelete, m_onEntityDelete); typename Nz::Signal::ConnectionGuard m_nicknameUpdateSlot; + std::shared_ptr m_renderTarget; std::optional m_assetStore; std::optional m_entityStore; std::optional m_weaponStore; @@ -274,7 +276,7 @@ namespace bw std::optional m_remoteConsole; std::optional m_debug; std::optional m_localConsole; - std::optional m_particleRegistry; + //std::optional m_particleRegistry; std::shared_ptr m_gamemode; std::shared_ptr m_scriptingContext; std::string m_gamemodeName; @@ -284,13 +286,11 @@ namespace bw std::vector m_predictedInputs; std::vector m_tickedPackets; std::vector m_tickPredictions; - Ndk::Canvas* m_canvas; - Ndk::EntityHandle m_currentLayer; - Ndk::World m_renderWorld; - Nz::ColorBackgroundRef m_colorBackground; + Nz::Canvas* m_canvas; + entt::handle m_currentLayer; EntityId m_freeClientId; - Nz::RenderTarget* m_renderTarget; - Nz::RenderWindow* m_window; + Nz::EnttWorld& m_renderWorld; + Nz::Window* m_window; Nz::UInt16 m_activeLayerIndex; tsl::hopscotch_map m_entitiesByUniqueId; tsl::hopscotch_map m_playerEntitiesByUniqueId; @@ -298,7 +298,7 @@ namespace bw AnimationManager m_animationManager; AverageValues m_averageTickError; Chatbox m_chatBox; - ClientEditorApp& m_application; + ClientEditorAppComponent& m_application; ClientSession& m_session; EscapeMenu m_escapeMenu; PropertyValueMap m_gamemodeProperties; diff --git a/include/ClientLib/ClientMatch.inl b/include/ClientLib/ClientMatch.inl index bac43cfc..6c856b3c 100644 --- a/include/ClientLib/ClientMatch.inl +++ b/include/ClientLib/ClientMatch.inl @@ -45,7 +45,7 @@ namespace bw return *m_assetStore; } - inline ClientEditorApp& ClientMatch::GetApplication() + inline ClientEditorAppComponent& ClientMatch::GetApplication() { return m_application; } @@ -91,7 +91,7 @@ namespace bw assert(localPlayerIndex < m_localPlayers.size()); return m_localPlayers[localPlayerIndex].lastInputData; } - + /* inline ParticleRegistry& ClientMatch::GetParticleRegistry() { assert(m_particleRegistry); @@ -103,7 +103,7 @@ namespace bw assert(m_particleRegistry); return *m_particleRegistry; } - + */ inline ClientPlayer* ClientMatch::GetPlayerByIndex(Nz::UInt16 playerIndex) { if (playerIndex >= m_matchPlayers.size() || !m_matchPlayers[playerIndex].has_value()) @@ -112,7 +112,7 @@ namespace bw return &m_matchPlayers[playerIndex].value(); } - inline Ndk::World& ClientMatch::GetRenderWorld() + inline Nz::EnttWorld& ClientMatch::GetRenderWorld() { return m_renderWorld; } diff --git a/include/ClientLib/ClientSession.hpp b/include/ClientLib/ClientSession.hpp index 058f8716..958332a9 100644 --- a/include/ClientLib/ClientSession.hpp +++ b/include/ClientLib/ClientSession.hpp @@ -11,21 +11,21 @@ #include #include #include -#include +#include #include #include #include namespace bw { - class BurgApp; + class BurgAppComponent; class BURGWAR_CLIENTLIB_API ClientSession { friend class ClientCommandStore; public: - inline ClientSession(BurgApp& app); + inline ClientSession(BurgAppComponent& app); ClientSession(const ClientSession&) = delete; ClientSession(ClientSession&&) = delete; virtual ~ClientSession(); @@ -33,13 +33,13 @@ namespace bw bool Connect(std::shared_ptr sessionBridge); void Disconnect(); - inline BurgApp& GetApp(); - inline const BurgApp& GetApp() const; + inline BurgAppComponent& GetApp(); + inline const BurgAppComponent& GetApp() const; inline const NetworkStringStore& GetNetworkStringStore() const; inline bool IsConnected() const; - void HandleIncomingPacket(Nz::NetPacket& packet); + void HandleIncomingPacket(Nz::ByteArray& packet); inline void QuerySessionInfo(std::function callback) const; @@ -95,7 +95,7 @@ namespace bw NazaraSlot(SessionBridge, OnIncomingPacket, m_onIncomingPacketSlot); std::shared_ptr m_bridge; - BurgApp& m_application; + BurgAppComponent& m_application; ClientCommandStore m_commandStore; NetworkStringStore m_stringStore; }; diff --git a/include/ClientLib/ClientSession.inl b/include/ClientLib/ClientSession.inl index d002edd3..2314ca4b 100644 --- a/include/ClientLib/ClientSession.inl +++ b/include/ClientLib/ClientSession.inl @@ -3,23 +3,22 @@ // For conditions of distribution and use, see copyright notice in LICENSE #include -#include -#include +#include namespace bw { - inline ClientSession::ClientSession(BurgApp& application) : + inline ClientSession::ClientSession(BurgAppComponent& application) : m_application(application), m_commandStore(m_application.GetLogger()) { } - inline BurgApp& ClientSession::GetApp() + inline BurgAppComponent& ClientSession::GetApp() { return m_application; } - inline const BurgApp& ClientSession::GetApp() const + inline const BurgAppComponent& ClientSession::GetApp() const { return m_application; } @@ -48,8 +47,9 @@ namespace bw if (!IsConnected()) return; - Nz::NetPacket data; - m_commandStore.SerializePacket(data, packet); + Nz::ByteArray data; + Nz::ByteStream byteStream(&data, Nz::OpenMode::Write); + m_commandStore.SerializePacket(byteStream, packet); const auto& command = m_commandStore.GetOutgoingCommand(); m_bridge->SendPacket(command.channelId, command.flags, std::move(data)); diff --git a/include/ClientLib/Components/ClientMatchComponent.hpp b/include/ClientLib/Components/ClientMatchComponent.hpp index cc367306..dcfcfb01 100644 --- a/include/ClientLib/Components/ClientMatchComponent.hpp +++ b/include/ClientLib/Components/ClientMatchComponent.hpp @@ -10,14 +10,14 @@ #include #include #include -#include +#include namespace bw { class ClientLayer; class ClientMatch; - class BURGWAR_CLIENTLIB_API ClientMatchComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API ClientMatchComponent { public: inline ClientMatchComponent(ClientMatch& clientMatch, LayerIndex layerIndex, EntityId uniqueId); @@ -29,11 +29,9 @@ namespace bw inline ClientMatch& GetClientMatch() const; inline EntityId GetUniqueId() const; - static Ndk::ComponentIndex componentIndex; - private: + Nz::MovablePtr m_clientMatch; EntityId m_uniqueId; - ClientMatch& m_clientMatch; LayerIndex m_layerIndex; }; } diff --git a/include/ClientLib/Components/ClientMatchComponent.inl b/include/ClientLib/Components/ClientMatchComponent.inl index 793ce369..5f6c8d37 100644 --- a/include/ClientLib/Components/ClientMatchComponent.inl +++ b/include/ClientLib/Components/ClientMatchComponent.inl @@ -7,8 +7,8 @@ namespace bw { inline ClientMatchComponent::ClientMatchComponent(ClientMatch& clientMatch, LayerIndex layerIndex, EntityId uniqueId) : + m_clientMatch(&clientMatch), m_uniqueId(uniqueId), - m_clientMatch(clientMatch), m_layerIndex(layerIndex) { } @@ -20,7 +20,7 @@ namespace bw inline ClientMatch& ClientMatchComponent::GetClientMatch() const { - return m_clientMatch; + return *m_clientMatch; } inline EntityId ClientMatchComponent::GetUniqueId() const diff --git a/include/ClientLib/Components/ClientOwnerComponent.hpp b/include/ClientLib/Components/ClientOwnerComponent.hpp index 5c9ea586..2ef229dd 100644 --- a/include/ClientLib/Components/ClientOwnerComponent.hpp +++ b/include/ClientLib/Components/ClientOwnerComponent.hpp @@ -9,12 +9,11 @@ #include #include -#include #include namespace bw { - class BURGWAR_CLIENTLIB_API ClientOwnerComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API ClientOwnerComponent { public: ClientOwnerComponent(ClientPlayerHandle owner); @@ -22,8 +21,6 @@ namespace bw inline ClientPlayer* GetOwner() const; - static Ndk::ComponentIndex componentIndex; - private: ClientPlayerHandle m_owner; }; diff --git a/include/ClientLib/Components/LocalPlayerControlledComponent.hpp b/include/ClientLib/Components/LocalPlayerControlledComponent.hpp index d2a80f8b..14a56b54 100644 --- a/include/ClientLib/Components/LocalPlayerControlledComponent.hpp +++ b/include/ClientLib/Components/LocalPlayerControlledComponent.hpp @@ -9,14 +9,13 @@ #include #include -#include #include namespace bw { class ClientMatch; - class BURGWAR_CLIENTLIB_API LocalPlayerControlledComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API LocalPlayerControlledComponent { public: inline LocalPlayerControlledComponent(ClientMatch& clientMatch, Nz::UInt8 localPlayerIndex); @@ -25,8 +24,6 @@ namespace bw inline ClientMatch& GetClientMatch() const; inline Nz::UInt8 GetLocalPlayerIndex() const; - static Ndk::ComponentIndex componentIndex; - private: ClientMatch& m_clientMatch; Nz::UInt8 m_localPlayerIndex; diff --git a/include/ClientLib/Components/SoundEmitterComponent.hpp b/include/ClientLib/Components/SoundEmitterComponent.hpp index 882161e6..4b003620 100644 --- a/include/ClientLib/Components/SoundEmitterComponent.hpp +++ b/include/ClientLib/Components/SoundEmitterComponent.hpp @@ -10,13 +10,12 @@ #include #include #include -#include #include #include namespace bw { - class BURGWAR_CLIENTLIB_API SoundEmitterComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API SoundEmitterComponent { friend class SoundSystem; @@ -26,11 +25,9 @@ namespace bw SoundEmitterComponent(SoundEmitterComponent&&) = default; ~SoundEmitterComponent() = default; - Nz::UInt32 PlaySound(const Nz::SoundBufferRef& soundBuffer, const Nz::Vector3f& soundPosition, bool attachedToEntity, bool isLooping, bool isSpatialized); + Nz::UInt32 PlaySound(const std::shared_ptr& soundBuffer, const Nz::Vector3f& soundPosition, bool attachedToEntity, bool isLooping, bool isSpatialized); void StopSound(Nz::UInt32 soundId); - static Ndk::ComponentIndex componentIndex; - SoundEmitterComponent& operator=(const SoundEmitterComponent&) = delete; SoundEmitterComponent& operator=(SoundEmitterComponent&&) = default; diff --git a/include/ClientLib/Components/VisibleLayerComponent.hpp b/include/ClientLib/Components/VisibleLayerComponent.hpp index edaf5c6c..17d80105 100644 --- a/include/ClientLib/Components/VisibleLayerComponent.hpp +++ b/include/ClientLib/Components/VisibleLayerComponent.hpp @@ -7,24 +7,30 @@ #ifndef BURGWAR_CLIENTLIB_COMPONENTS_VISIBLELAYERCOMPONENT_HPP #define BURGWAR_CLIENTLIB_COMPONENTS_VISIBLELAYERCOMPONENT_HPP +#include #include #include #include #include #include #include -#include -#include +#include #include +namespace Nz +{ + class EnttWorld; +} + namespace bw { class ClientLayerEntity; - class BURGWAR_CLIENTLIB_API VisibleLayerComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API VisibleLayerComponent : public BaseComponent { public: - inline VisibleLayerComponent(Ndk::World& renderWorld); + inline VisibleLayerComponent(Nz::EnttWorld& renderWorld, entt::handle entity); + VisibleLayerComponent(VisibleLayerComponent&&) noexcept = default; ~VisibleLayerComponent() = default; void Clear(); @@ -32,8 +38,6 @@ namespace bw void RegisterLocalLayer(ClientLayer& localLayer, int renderOrder, const Nz::Vector2f& scale, const Nz::Vector2f& parallaxFactor); void RegisterVisibleLayer(Camera& camera, VisualLayer& visualLayer, int renderOrder, const Nz::Vector2f& scale, const Nz::Vector2f& parallaxFactor); - static Ndk::ComponentIndex componentIndex; - private: struct VisibleLayer; @@ -68,7 +72,7 @@ namespace bw //FIXME (shared_ptr => unique_ptr) std::vector> m_visibleLayers; - Ndk::World& m_renderWorld; + Nz::EnttWorld& m_renderWorld; }; } diff --git a/include/ClientLib/Components/VisibleLayerComponent.inl b/include/ClientLib/Components/VisibleLayerComponent.inl index 7031c2c6..f3ff990e 100644 --- a/include/ClientLib/Components/VisibleLayerComponent.inl +++ b/include/ClientLib/Components/VisibleLayerComponent.inl @@ -6,7 +6,8 @@ namespace bw { - inline VisibleLayerComponent::VisibleLayerComponent(Ndk::World& renderWorld) : + inline VisibleLayerComponent::VisibleLayerComponent(Nz::EnttWorld& renderWorld, entt::handle entity) : + BaseComponent(entity), m_renderWorld(renderWorld) { } diff --git a/include/ClientLib/Components/VisualComponent.hpp b/include/ClientLib/Components/VisualComponent.hpp index f1e17aac..1a5008a7 100644 --- a/include/ClientLib/Components/VisualComponent.hpp +++ b/include/ClientLib/Components/VisualComponent.hpp @@ -9,11 +9,10 @@ #include #include -#include namespace bw { - class BURGWAR_CLIENTLIB_API VisualComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API VisualComponent { public: inline VisualComponent(LayerVisualEntityHandle visualEntity); @@ -21,8 +20,6 @@ namespace bw inline const LayerVisualEntityHandle& GetLayerVisual() const; - static Ndk::ComponentIndex componentIndex; - private: LayerVisualEntityHandle m_visualEntity; }; diff --git a/include/ClientLib/Components/VisualInterpolationComponent.hpp b/include/ClientLib/Components/VisualInterpolationComponent.hpp index bc2e261b..1dc66e5e 100644 --- a/include/ClientLib/Components/VisualInterpolationComponent.hpp +++ b/include/ClientLib/Components/VisualInterpolationComponent.hpp @@ -10,11 +10,10 @@ #include #include #include -#include namespace bw { - class BURGWAR_CLIENTLIB_API VisualInterpolationComponent : public Ndk::Component + class BURGWAR_CLIENTLIB_API VisualInterpolationComponent { friend class VisualInterpolationSystem; @@ -22,8 +21,6 @@ namespace bw inline VisualInterpolationComponent(); ~VisualInterpolationComponent() = default; - static Ndk::ComponentIndex componentIndex; - private: inline const Nz::Vector2f& GetLastPosition(); inline const Nz::RadianAnglef& GetLastRotation(); diff --git a/include/ClientLib/Console.hpp b/include/ClientLib/Console.hpp index e1e0e98f..cc4a9ab4 100644 --- a/include/ClientLib/Console.hpp +++ b/include/ClientLib/Console.hpp @@ -8,10 +8,9 @@ #define BURGWAR_CLIENTLIB_CONSOLE_HPP #include -#include -#include -#include -#include +#include +#include +#include #include #include @@ -22,7 +21,7 @@ namespace bw public: using ExecuteCallback = std::function; - Console(Nz::RenderTarget* window, Ndk::Canvas* canvas); + Console(const Nz::RenderTarget& window, Nz::Canvas* canvas); Console(const Console&) = delete; Console(Console&&) = delete; ~Console(); @@ -33,7 +32,7 @@ namespace bw inline bool IsVisible() const; - void Print(const std::string& str, Nz::Color color = Nz::Color::White); + void Print(const std::string& str, Nz::Color color = Nz::Color::White()); void SetExecuteCallback(ExecuteCallback callback); void Show(bool shouldShow); @@ -47,7 +46,7 @@ namespace bw NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_onTargetChangeSizeSlot); ExecuteCallback m_callback; - Ndk::Console* m_widget; + //Nz::Console* m_widget; }; } diff --git a/include/ClientLib/Console.inl b/include/ClientLib/Console.inl index 21c9cc3a..e3a4d288 100644 --- a/include/ClientLib/Console.inl +++ b/include/ClientLib/Console.inl @@ -13,6 +13,7 @@ namespace bw inline bool Console::IsVisible() const { - return m_widget->IsVisible(); + return false; + //return m_widget->IsVisible(); } } diff --git a/include/ClientLib/DownloadManager.hpp b/include/ClientLib/DownloadManager.hpp index a0f41373..bee71051 100644 --- a/include/ClientLib/DownloadManager.hpp +++ b/include/ClientLib/DownloadManager.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/ClientLib/EscapeMenu.hpp b/include/ClientLib/EscapeMenu.hpp index 4e18ff61..8ca71c1a 100644 --- a/include/ClientLib/EscapeMenu.hpp +++ b/include/ClientLib/EscapeMenu.hpp @@ -8,22 +8,20 @@ #define BURGWAR_CLIENTLIB_ESCAPEMENU_HPP #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include namespace bw { - class ClientEditorApp; + class ClientEditorAppComponent; class OptionWidget; class BURGWAR_CLIENTLIB_API EscapeMenu { public: - EscapeMenu(ClientEditorApp& clientEditorApp, Ndk::Canvas* canvas); + EscapeMenu(ClientEditorAppComponent& clientEditorApp, Nz::Canvas* canvas); EscapeMenu(const EscapeMenu&) = delete; EscapeMenu(EscapeMenu&&) = delete; ~EscapeMenu(); @@ -46,12 +44,12 @@ namespace bw void Layout(); - Ndk::ButtonWidget* m_closeMenuButton; - Ndk::ButtonWidget* m_leaveMatchButton; - Ndk::ButtonWidget* m_optionsButton; - Ndk::ButtonWidget* m_quitAppButton; - Ndk::BaseWidget* m_backgroundWidget; - ClientEditorApp& m_app; + Nz::ButtonWidget* m_closeMenuButton; + Nz::ButtonWidget* m_leaveMatchButton; + Nz::ButtonWidget* m_optionsButton; + Nz::ButtonWidget* m_quitAppButton; + Nz::BaseWidget* m_backgroundWidget; + ClientEditorAppComponent& m_app; OptionWidget* m_optionWidget; }; } diff --git a/include/ClientLib/Export.hpp b/include/ClientLib/Export.hpp index 68866af8..6015a13d 100644 --- a/include/ClientLib/Export.hpp +++ b/include/ClientLib/Export.hpp @@ -7,7 +7,7 @@ #ifndef BURGWAR_CLIENTLIB_EXPORT_HPP #define BURGWAR_CLIENTLIB_EXPORT_HPP -#include +#include #ifdef BURGWAR_CLIENTLIB_STATIC #define BURGWAR_CLIENTLIB_API diff --git a/include/ClientLib/HttpDownloadManager.hpp b/include/ClientLib/HttpDownloadManager.hpp index 2eceb1b3..6d771627 100644 --- a/include/ClientLib/HttpDownloadManager.hpp +++ b/include/ClientLib/HttpDownloadManager.hpp @@ -7,12 +7,12 @@ #ifndef BURGWAR_CLIENTLIB_HTTPDOWNLOADMANAGER_HPP #define BURGWAR_CLIENTLIB_HTTPDOWNLOADMANAGER_HPP -#include +#include #include #include #include #include -#include +#include #include #include @@ -23,7 +23,7 @@ namespace bw class BURGWAR_CLIENTLIB_API HttpDownloadManager : public DownloadManager { public: - HttpDownloadManager(const Logger& logger, std::vector baseDownloadUrls, std::size_t maxSimultanousDownload = 2); + HttpDownloadManager(Nz::WebService& webService, const Logger& logger, std::vector baseDownloadUrls, std::size_t maxSimultanousDownload = 2); HttpDownloadManager(const HttpDownloadManager&) = delete; HttpDownloadManager(HttpDownloadManager&&) = delete; ~HttpDownloadManager() = default; @@ -65,8 +65,8 @@ namespace bw std::vector m_downloadList; std::vector m_requests; Nz::ByteArray m_byteArray; + Nz::WebService& m_webService; const Logger& m_logger; - WebService m_webService; }; } diff --git a/include/ClientLib/InputPoller.hpp b/include/ClientLib/InputPoller.hpp index f98344e1..66091839 100644 --- a/include/ClientLib/InputPoller.hpp +++ b/include/ClientLib/InputPoller.hpp @@ -10,8 +10,7 @@ #include #include #include -#include -#include +#include namespace bw { diff --git a/include/ClientLib/KeyboardAndMousePoller.hpp b/include/ClientLib/KeyboardAndMousePoller.hpp index 814a45da..108c0ffa 100644 --- a/include/ClientLib/KeyboardAndMousePoller.hpp +++ b/include/ClientLib/KeyboardAndMousePoller.hpp @@ -22,8 +22,8 @@ namespace bw PlayerInputData Poll(ClientMatch& clientMatch, const ClientLayerEntityHandle& controlledEntity) override; private: - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_onKeyPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_onMouseWheelMovedSlot); + NazaraSlot(Nz::WindowEventHandler, OnKeyPressed, m_onKeyPressedSlot); + NazaraSlot(Nz::WindowEventHandler, OnMouseWheelMoved, m_onMouseWheelMovedSlot); Nz::Window& m_window; Nz::UInt8 m_localPlayerIndex; diff --git a/include/ClientLib/LayerVisualEntity.hpp b/include/ClientLib/LayerVisualEntity.hpp index b2ec575e..4c2d39a5 100644 --- a/include/ClientLib/LayerVisualEntity.hpp +++ b/include/ClientLib/LayerVisualEntity.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,22 +32,22 @@ namespace bw friend VisualEntity; public: - inline LayerVisualEntity(const Ndk::EntityHandle& entity, LayerIndex layerIndex, EntityId uniqueId); + inline LayerVisualEntity(entt::handle entity, LayerIndex layerIndex, EntityId uniqueId); LayerVisualEntity(const LayerVisualEntity&) = delete; LayerVisualEntity(LayerVisualEntity&& entity) noexcept; virtual ~LayerVisualEntity(); - void AttachHoveringRenderable(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& offsetMatrix, int renderOrder, float hoveringHeight); - void AttachRenderable(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& offsetMatrix, int renderOrder); - void DetachHoveringRenderable(const Nz::InstancedRenderableRef& renderable); - void DetachRenderable(const Nz::InstancedRenderableRef& renderable); + void AttachHoveringRenderable(std::shared_ptr renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation, float hoveringHeight); + void AttachRenderable(std::shared_ptr renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); + void DetachHoveringRenderable(const std::shared_ptr& renderable); + void DetachRenderable(const std::shared_ptr& renderable); inline void Disable(); void Enable(bool enable = true); template void ForEachRenderable(Func&& func) const; - inline const Ndk::EntityHandle& GetEntity() const; + inline entt::handle GetEntity() const; Nz::Boxf GetGlobalBounds() const; inline LayerIndex GetLayerIndex() const; Nz::Boxf GetLocalBounds() const; @@ -58,9 +58,9 @@ namespace bw void SyncVisuals(); - void UpdateHoveringRenderableHoveringHeight(const Nz::InstancedRenderableRef& renderable, float newHoveringHeight); - void UpdateHoveringRenderableMatrix(const Nz::InstancedRenderableRef& renderable, const Nz::Matrix4f& offsetMatrix); - void UpdateRenderableMatrix(const Nz::InstancedRenderableRef& renderable, const Nz::Matrix4f& offsetMatrix); + void UpdateHoveringRenderableHoveringHeight(const std::shared_ptr& renderable, float newHoveringHeight); + void UpdateHoveringRenderableTransform(const std::shared_ptr& renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); + void UpdateRenderableTransform(const std::shared_ptr& renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); void UpdateScale(float newScale); void UpdateState(const Nz::Vector2f& position, const Nz::RadianAnglef& rotation); void UpdateState(const Nz::Vector2f& position, const Nz::RadianAnglef& rotation, const Nz::Vector2f& linearVel, const Nz::RadianAnglef& angularVel); @@ -75,9 +75,9 @@ namespace bw struct RenderableData { - Nz::InstancedRenderableRef renderable; - Nz::Matrix4f offsetMatrix; - int renderOrder; + std::shared_ptr renderable; + Nz::Quaternionf rotation; + Nz::Vector3f offset; }; struct HoveringRenderableData @@ -89,7 +89,7 @@ namespace bw std::vector m_attachedHoveringRenderables; std::vector m_attachedRenderables; std::vector m_visualEntities; - Ndk::EntityOwner m_entity; + EntityOwner m_entity; EntityId m_uniqueId; LayerIndex m_layerIndex; }; diff --git a/include/ClientLib/LayerVisualEntity.inl b/include/ClientLib/LayerVisualEntity.inl index 10cdd79a..1759556e 100644 --- a/include/ClientLib/LayerVisualEntity.inl +++ b/include/ClientLib/LayerVisualEntity.inl @@ -8,12 +8,12 @@ namespace bw { - inline LayerVisualEntity::LayerVisualEntity(const Ndk::EntityHandle& entity, LayerIndex layerIndex, EntityId uniqueId) : + inline LayerVisualEntity::LayerVisualEntity(entt::handle entity, LayerIndex layerIndex, EntityId uniqueId) : m_entity(entity), m_uniqueId(uniqueId), m_layerIndex(layerIndex) { - assert(m_entity); + assert(m_entity.GetEntity()); } inline void LayerVisualEntity::Disable() @@ -25,12 +25,12 @@ namespace bw void LayerVisualEntity::ForEachRenderable(Func&& func) const { for (const auto& renderableData : m_attachedRenderables) - func(std::as_const(renderableData.renderable), std::as_const(renderableData.offsetMatrix), std::as_const(renderableData.renderOrder)); + func(std::as_const(renderableData.renderable), std::as_const(renderableData.offset), std::as_const(renderableData.rotation)); } - inline const Ndk::EntityHandle& LayerVisualEntity::GetEntity() const + inline entt::handle LayerVisualEntity::GetEntity() const { - return m_entity; + return m_entity.GetEntity(); } inline LayerIndex LayerVisualEntity::GetLayerIndex() const @@ -45,6 +45,8 @@ namespace bw inline bool LayerVisualEntity::IsEnabled() const { - return m_entity->IsEnabled(); + return true; + // TODO + //return m_entity->IsEnabled(); } } diff --git a/include/ClientLib/LocalPlayerInputController.hpp b/include/ClientLib/LocalPlayerInputController.hpp index ee5e2822..7259d491 100644 --- a/include/ClientLib/LocalPlayerInputController.hpp +++ b/include/ClientLib/LocalPlayerInputController.hpp @@ -18,7 +18,7 @@ namespace bw LocalPlayerInputController() = default; ~LocalPlayerInputController() = default; - std::optional GenerateInputs(const Ndk::EntityHandle& entity) const override; + std::optional GenerateInputs(entt::handle entity) const override; }; } diff --git a/include/ClientLib/LocalSessionBridge.hpp b/include/ClientLib/LocalSessionBridge.hpp index 13e77941..0042b14b 100644 --- a/include/ClientLib/LocalSessionBridge.hpp +++ b/include/ClientLib/LocalSessionBridge.hpp @@ -22,17 +22,17 @@ namespace bw void Disconnect() override; - void HandleIncomingPacket(Nz::NetPacket& packet) override; + void HandleIncomingPacket(Nz::ByteArray& packet) override; inline bool IsServer() const; bool IsLocal() const override; void QueryInfo(std::function callback) const override; - void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::NetPacket&& packet) override; + void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::ByteArray&& packet) override; private: std::size_t m_peerId; - Nz::UInt64 m_lastReceiveTime; + Nz::Time m_lastReceiveTime; mutable SessionInfo m_sessionInfo; LocalSessionManager& m_sessionManager; bool m_isServer; diff --git a/include/ClientLib/LocalSessionManager.hpp b/include/ClientLib/LocalSessionManager.hpp index af7fdaa2..52d67767 100644 --- a/include/ClientLib/LocalSessionManager.hpp +++ b/include/ClientLib/LocalSessionManager.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -38,14 +38,14 @@ namespace bw private: void DisconnectPeer(std::size_t peerId); - void SendPacket(std::size_t peerId, Nz::NetPacket&& packet, bool isServer); + void SendPacket(std::size_t peerId, Nz::ByteArray&& packet, bool isServer); struct Peer { std::shared_ptr clientBridge; std::shared_ptr serverBridge; - std::vector clientPackets; - std::vector serverPackets; + std::vector clientPackets; + std::vector serverPackets; MatchClientSession* session; bool disconnectionRequested = false; }; diff --git a/include/ClientLib/NetworkReactorManager.hpp b/include/ClientLib/NetworkReactorManager.hpp index ffed2483..82993cee 100644 --- a/include/ClientLib/NetworkReactorManager.hpp +++ b/include/ClientLib/NetworkReactorManager.hpp @@ -41,7 +41,7 @@ namespace bw private: void HandlePeerConnection(bool outgoing, std::size_t peerId, Nz::UInt32 data); void HandlePeerDisconnection(std::size_t peerId, Nz::UInt32 data); - void HandlePeerPacket(std::size_t peerId, Nz::NetPacket& packet); + void HandlePeerPacket(std::size_t peerId, Nz::ByteArray& packet); std::vector> m_reactors; std::vector> m_connections; diff --git a/include/ClientLib/OptionWidget.hpp b/include/ClientLib/OptionWidget.hpp index 65b25ab0..b4153782 100644 --- a/include/ClientLib/OptionWidget.hpp +++ b/include/ClientLib/OptionWidget.hpp @@ -8,22 +8,22 @@ #define BURGWAR_CLIENTLIB_OPTIONMENU_HPP #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include namespace bw { class ConfigFile; - class BURGWAR_CLIENTLIB_API OptionWidget : public Ndk::BaseWidget + class BURGWAR_CLIENTLIB_API OptionWidget : public Nz::BaseWidget { public: - OptionWidget(Ndk::BaseWidget* parent, ConfigFile& playerConfig); + OptionWidget(Nz::BaseWidget* parent, ConfigFile& playerConfig); OptionWidget(const OptionWidget&) = delete; OptionWidget(OptionWidget&&) = delete; ~OptionWidget() = default; @@ -61,35 +61,35 @@ namespace bw struct Option { std::string keyName; - Ndk::LabelWidget* label; + Nz::LabelWidget* label; }; struct BoolOption : Option { - Ndk::CheckboxWidget* optionWidget; + Nz::CheckboxWidget* optionWidget; - NazaraSlot(Ndk::CheckboxWidget, OnStateChanged, onStateChangeSlot); + NazaraSlot(Nz::CheckboxWidget, OnCheckboxStateUpdate, onStateChangeSlot); }; struct FloatOption : Option { - Ndk::TextAreaWidget* optionWidget; + Nz::TextAreaWidget* optionWidget; - NazaraSlot(Ndk::TextAreaWidget, OnTextChanged, onTextChangedSlot); + NazaraSlot(Nz::TextAreaWidget, OnTextChanged, onTextChangedSlot); }; struct IntegerOption : Option { - Ndk::TextAreaWidget* optionWidget; + Nz::TextAreaWidget* optionWidget; - NazaraSlot(Ndk::TextAreaWidget, OnTextChanged, onTextChangedSlot); + NazaraSlot(Nz::TextAreaWidget, OnTextChanged, onTextChangedSlot); }; struct StringOption : Option { - Ndk::TextAreaWidget* optionWidget; + Nz::TextAreaWidget* optionWidget; - NazaraSlot(Ndk::TextAreaWidget, OnTextChanged, onTextChangedSlot); + NazaraSlot(Nz::TextAreaWidget, OnTextChanged, onTextChangedSlot); }; using OptionType = std::variant; @@ -97,18 +97,18 @@ namespace bw struct Section { - Ndk::ButtonWidget* button; + Nz::ButtonWidget* button; std::vector options; - NazaraSlot(Ndk::ButtonWidget, OnButtonTrigger, onTriggerSlot); + NazaraSlot(Nz::ButtonWidget, OnButtonTrigger, onTriggerSlot); }; std::unordered_map m_sections; std::unordered_map m_updatedValues; Section* m_activeSection; - Ndk::ButtonWidget* m_applyButton; - Ndk::ButtonWidget* m_backButton; - Ndk::ButtonWidget* m_resetButton; + Nz::ButtonWidget* m_applyButton; + Nz::ButtonWidget* m_backButton; + Nz::ButtonWidget* m_resetButton; ConfigFile& m_playerConfig; bool m_ignoreWidgetUpdate; }; diff --git a/include/ClientLib/PacketDownloadManager.hpp b/include/ClientLib/PacketDownloadManager.hpp index 06b393cc..30f0dc2f 100644 --- a/include/ClientLib/PacketDownloadManager.hpp +++ b/include/ClientLib/PacketDownloadManager.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/ClientLib/PlayerConfig.hpp b/include/ClientLib/PlayerConfig.hpp index 94476ec7..6208e4ac 100644 --- a/include/ClientLib/PlayerConfig.hpp +++ b/include/ClientLib/PlayerConfig.hpp @@ -12,12 +12,12 @@ namespace bw { - class BurgApp; + class BurgAppComponent; class BURGWAR_CLIENTLIB_API PlayerConfig : public ConfigFile { public: - PlayerConfig(BurgApp& app); + PlayerConfig(BurgAppComponent& app); ~PlayerConfig() = default; }; } diff --git a/include/ClientLib/Scoreboard.hpp b/include/ClientLib/Scoreboard.hpp index 03cdf2a3..0698c0aa 100644 --- a/include/ClientLib/Scoreboard.hpp +++ b/include/ClientLib/Scoreboard.hpp @@ -9,9 +9,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include namespace bw @@ -21,10 +21,10 @@ namespace bw using ScoreboardHandle = Nz::ObjectHandle; - class BURGWAR_CLIENTLIB_API Scoreboard : public Ndk::BaseWidget, public Nz::HandledObject + class BURGWAR_CLIENTLIB_API Scoreboard : public Nz::BaseWidget, public Nz::HandledObject { public: - Scoreboard(Ndk::BaseWidget* parent, const Logger& logger); + Scoreboard(Nz::BaseWidget* parent, const Logger& logger); Scoreboard(const Scoreboard&) = delete; Scoreboard(Scoreboard&&) = delete; ~Scoreboard(); @@ -34,7 +34,7 @@ namespace bw void RegisterPlayer(std::size_t playerIndex, std::size_t teamId, std::vector values, std::optional color = {}, bool isLocalPlayer = false); - Nz::String ToString() const; + std::string ToString() const; void UnregisterPlayer(std::size_t playerIndex); @@ -54,10 +54,10 @@ namespace bw struct ColumnData { std::string value; - Ndk::LabelWidget* label; + Nz::LabelWidget* label; }; - Ndk::BaseWidget* background; + Nz::BaseWidget* background; std::optional color; std::size_t teamId; std::vector values; @@ -66,25 +66,25 @@ namespace bw struct ColumnData { std::string name; - Ndk::LabelWidget* widget; + Nz::LabelWidget* widget; }; struct TeamData { std::string name; Nz::Color color; - Ndk::BaseWidget* background; - Ndk::ImageWidget* line; - Ndk::LabelWidget* widget; + Nz::BaseWidget* background; + Nz::ImageWidget* line; + Nz::LabelWidget* widget; }; std::vector m_columns; std::vector> m_players; std::vector m_teams; - Ndk::BaseWidget* m_backgroundWidget; - Ndk::BaseWidget* m_columnBackgroundWidget; - Ndk::BaseWidget* m_contentWidget; - Ndk::ScrollAreaWidget* m_scrollArea; + Nz::BaseWidget* m_backgroundWidget; + Nz::BaseWidget* m_columnBackgroundWidget; + Nz::BaseWidget* m_contentWidget; + Nz::ScrollAreaWidget* m_scrollArea; const Logger& m_logger; }; } diff --git a/include/ClientLib/Scripting/ClientEditorEntityStore.hpp b/include/ClientLib/Scripting/ClientEditorEntityStore.hpp index c0144479..785840dc 100644 --- a/include/ClientLib/Scripting/ClientEditorEntityStore.hpp +++ b/include/ClientLib/Scripting/ClientEditorEntityStore.hpp @@ -12,7 +12,6 @@ #include #include #include -#include namespace bw { @@ -26,8 +25,8 @@ namespace bw ClientEditorEntityStore(ClientEditorEntityStore&&) = delete; ~ClientEditorEntityStore() = default; - bool InitializeEntity(const Ndk::EntityHandle& entity) const; - virtual const Ndk::EntityHandle& InstantiateEntity(Ndk::World& world, std::size_t entityIndex, const Nz::Vector2f& position, const Nz::DegreeAnglef& rotation, float scale, PropertyValueMap properties, const Ndk::EntityHandle& parentEntity = Ndk::EntityHandle::InvalidHandle) const; + bool InitializeEntity(entt::handle entity) const; + virtual entt::handle InstantiateEntity(entt::registry& registry, std::size_t entityIndex, const Nz::Vector2f& position, const Nz::DegreeAnglef& rotation, float scale, PropertyValueMap properties, entt::handle parentEntity = {}) const; protected: void InitializeElementTable(sol::main_table& elementTable) override; diff --git a/include/ClientLib/Scripting/ClientElementLibrary.hpp b/include/ClientLib/Scripting/ClientElementLibrary.hpp index f3db9960..3f6062c4 100644 --- a/include/ClientLib/Scripting/ClientElementLibrary.hpp +++ b/include/ClientLib/Scripting/ClientElementLibrary.hpp @@ -24,7 +24,7 @@ namespace bw protected: virtual void RegisterClientLibrary(sol::table& elementTable); - void SetScale(const Ndk::EntityHandle& entity, float newScale) override; + void SetScale(entt::handle entity, float newScale) override; private: ClientAssetStore& m_assetStore; diff --git a/include/ClientLib/Scripting/ClientEntityLibrary.hpp b/include/ClientLib/Scripting/ClientEntityLibrary.hpp index 3afa1fb9..63300314 100644 --- a/include/ClientLib/Scripting/ClientEntityLibrary.hpp +++ b/include/ClientLib/Scripting/ClientEntityLibrary.hpp @@ -24,7 +24,7 @@ namespace bw void RegisterLibrary(sol::table& elementMetatable) override; protected: - void InitRigidBody(lua_State* L, const Ndk::EntityHandle& entity, float mass) override; + void InitRigidBody(lua_State* L, entt::handle entity, float mass) override; private: void RegisterClientLibrary(sol::table& elementMetatable); diff --git a/include/ClientLib/Scripting/ClientEntityStore.hpp b/include/ClientLib/Scripting/ClientEntityStore.hpp index 3c2c3048..33448153 100644 --- a/include/ClientLib/Scripting/ClientEntityStore.hpp +++ b/include/ClientLib/Scripting/ClientEntityStore.hpp @@ -27,7 +27,7 @@ namespace bw ClientEntityStore(ClientEntityStore&&) = delete; ~ClientEntityStore() = default; - std::optional InstantiateEntity(ClientLayer& layer, std::size_t elementIndex, Nz::UInt32 serverId, EntityId uniqueId, const Nz::Vector2f& position, const Nz::DegreeAnglef& rotation, float scale, const PropertyValueMap& properties, const Ndk::EntityHandle& parentEntity = Ndk::EntityHandle::InvalidHandle) const; + std::optional InstantiateEntity(ClientLayer& layer, std::size_t elementIndex, Nz::UInt32 serverId, EntityId uniqueId, const Nz::Vector2f& position, const Nz::DegreeAnglef& rotation, float scale, const PropertyValueMap& properties, entt::handle parentEntity = entt::handle{}) const; }; } diff --git a/include/ClientLib/Scripting/ClientScriptingLibrary.hpp b/include/ClientLib/Scripting/ClientScriptingLibrary.hpp index dd277304..6ac85541 100644 --- a/include/ClientLib/Scripting/ClientScriptingLibrary.hpp +++ b/include/ClientLib/Scripting/ClientScriptingLibrary.hpp @@ -8,8 +8,8 @@ #define BURGWAR_CORELIB_CLIENTSCRIPTINGLIBRARY_HPP #include -#include #include +#include namespace bw { diff --git a/include/ClientLib/Scripting/ClientWeaponStore.hpp b/include/ClientLib/Scripting/ClientWeaponStore.hpp index f0d3b12c..6f790786 100644 --- a/include/ClientLib/Scripting/ClientWeaponStore.hpp +++ b/include/ClientLib/Scripting/ClientWeaponStore.hpp @@ -22,7 +22,7 @@ namespace bw inline ClientWeaponStore(ClientAssetStore& assetStore, const Logger& logger, std::shared_ptr context); ~ClientWeaponStore() = default; - std::optional InstantiateWeapon(ClientLayer& layer, std::size_t elementIndex, Nz::UInt32 serverId, EntityId uniqueId, const PropertyValueMap& properties, const Ndk::EntityHandle& parent); + std::optional InstantiateWeapon(ClientLayer& layer, std::size_t elementIndex, Nz::UInt32 serverId, EntityId uniqueId, const PropertyValueMap& properties, entt::handle parent); private: void InitializeElementTable(sol::main_table& elementTable) override; diff --git a/include/ClientLib/Scripting/Music.hpp b/include/ClientLib/Scripting/Music.hpp index 7c49da0f..f32ef35a 100644 --- a/include/ClientLib/Scripting/Music.hpp +++ b/include/ClientLib/Scripting/Music.hpp @@ -9,24 +9,24 @@ #include #include -#include +#include namespace bw { - class ClientEditorApp; + class ClientEditorAppComponent; class BURGWAR_CLIENTLIB_API Music { public: - Music(ClientEditorApp& app, Nz::Music music); + Music(ClientEditorAppComponent& app, std::unique_ptr music); Music(const Music&) = delete; - Music(Music&&) noexcept = default; + Music(Music&& music) noexcept; ~Music() = default; inline void EnableLooping(bool loop); - inline Nz::UInt32 GetDuration() const; - inline Nz::UInt32 GetPlayingOffset() const; + inline Nz::Time GetDuration() const; + inline Nz::Time GetPlayingOffset() const; inline Nz::UInt64 GetSampleCount() const; inline Nz::UInt32 GetSampleRate() const; @@ -36,17 +36,21 @@ namespace bw inline void Pause(); inline void Play(); - inline void SetPlayingOffset(Nz::UInt32 offset); + inline void SetPlayingOffset(Nz::Time offset); inline void Stop(); Music& operator=(const Music&) = delete; - Music& operator=(Music&&) noexcept = default; + Music& operator=(Music&& music) noexcept; private: + void ConnectSignals(); + void DisconnectSignals(); + typename Nz::Signal::ConnectionGuard m_musicVolumeUpdateSlot; - Nz::Music m_music; + std::unique_ptr m_music; + ClientEditorAppComponent& m_app; }; } diff --git a/include/ClientLib/Scripting/Music.inl b/include/ClientLib/Scripting/Music.inl index 47c66668..26dd5b91 100644 --- a/include/ClientLib/Scripting/Music.inl +++ b/include/ClientLib/Scripting/Music.inl @@ -8,56 +8,56 @@ namespace bw { inline void Music::EnableLooping(bool loop) { - m_music.EnableLooping(loop); + m_music->EnableLooping(loop); } - inline Nz::UInt32 Music::GetDuration() const + inline Nz::Time Music::GetDuration() const { - return m_music.GetDuration(); + return m_music->GetDuration(); } - inline Nz::UInt32 Music::GetPlayingOffset() const + inline Nz::Time Music::GetPlayingOffset() const { - return m_music.GetPlayingOffset(); + return m_music->GetPlayingOffset(); } inline Nz::UInt64 Music::GetSampleCount() const { - return m_music.GetSampleCount(); + return m_music->GetSampleCount(); } inline Nz::UInt32 Music::GetSampleRate() const { - return m_music.GetSampleRate(); + return m_music->GetSampleRate(); } inline bool Music::IsLooping() const { - return m_music.IsLooping(); + return m_music->IsLooping(); } inline bool Music::IsPlaying() const { - return m_music.GetStatus() == Nz::SoundStatus_Playing; + return m_music->GetStatus() == Nz::SoundStatus::Playing; } inline void Music::Pause() { - m_music.Pause(); + m_music->Pause(); } inline void Music::Play() { - m_music.Play(); + m_music->Play(); } - inline void Music::SetPlayingOffset(Nz::UInt32 offset) + inline void Music::SetPlayingOffset(Nz::Time offset) { - m_music.SetPlayingOffset(offset); + m_music->SeekToPlayingOffset(offset); } inline void Music::Stop() { - m_music.Stop(); + m_music->Stop(); } } diff --git a/include/ClientLib/Scripting/ParticleGroup.hpp b/include/ClientLib/Scripting/ParticleGroup.hpp index 576a1dd9..735dfb22 100644 --- a/include/ClientLib/Scripting/ParticleGroup.hpp +++ b/include/ClientLib/Scripting/ParticleGroup.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace bw { @@ -18,7 +18,7 @@ namespace bw class BURGWAR_CLIENTLIB_API ParticleGroup { public: - ParticleGroup(const ParticleRegistry& particleRegistry, const Ndk::EntityHandle& particleGroup); + ParticleGroup(const ParticleRegistry& particleRegistry, entt::handle particleGroup); ParticleGroup(const ParticleGroup&) = delete; ParticleGroup(ParticleGroup&&) noexcept = default; ~ParticleGroup() = default; @@ -38,7 +38,7 @@ namespace bw ParticleGroup& operator=(ParticleGroup&&) noexcept = default; private: - Ndk::EntityOwner m_entity; + EntityOwner m_entity; const ParticleRegistry& m_registry; }; } diff --git a/include/ClientLib/Scripting/ParticleRegistry.hpp b/include/ClientLib/Scripting/ParticleRegistry.hpp index b051e0b9..42c6f51b 100644 --- a/include/ClientLib/Scripting/ParticleRegistry.hpp +++ b/include/ClientLib/Scripting/ParticleRegistry.hpp @@ -7,11 +7,9 @@ #ifndef BURGWAR_CLIENTLIB_SCRIPTING_PARTICLEREGISTRY_HPP #define BURGWAR_CLIENTLIB_SCRIPTING_PARTICLEREGISTRY_HPP +#if 0 + #include -#include -#include -#include -#include #include #include #include @@ -56,3 +54,5 @@ namespace bw #include #endif + +#endif diff --git a/include/ClientLib/Scripting/Sound.hpp b/include/ClientLib/Scripting/Sound.hpp index be6df55b..34d4869f 100644 --- a/include/ClientLib/Scripting/Sound.hpp +++ b/include/ClientLib/Scripting/Sound.hpp @@ -20,7 +20,7 @@ namespace bw Sound(Sound&&) noexcept = default; ~Sound() = default; - float GetDuration() const; + Nz::Time GetDuration() const; void Stop(); diff --git a/include/ClientLib/Scripting/Sprite.hpp b/include/ClientLib/Scripting/Sprite.hpp index ac2aad75..f9dd6112 100644 --- a/include/ClientLib/Scripting/Sprite.hpp +++ b/include/ClientLib/Scripting/Sprite.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace bw @@ -20,7 +19,7 @@ namespace bw class BURGWAR_CLIENTLIB_API Sprite { public: - inline Sprite(LayerVisualEntityHandle visualEntity, Nz::SpriteRef sprite, const Nz::Matrix4f& transformMatrix, int renderOrder); + inline Sprite(LayerVisualEntityHandle visualEntity, std::shared_ptr sprite, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation); Sprite(const Sprite&) = delete; Sprite(Sprite&&) noexcept = default; ~Sprite() = default; @@ -33,8 +32,8 @@ namespace bw inline bool IsValid() const; inline bool IsVisible() const; - void SetColor(Nz::Color color); - void SetCornerColor(const std::string_view& corner, Nz::Color cornerColor); + void SetColor(const Nz::Color& color); + void SetCornerColor(const std::string_view& corner, const Nz::Color& cornerColor); void SetCornerColors(const sol::table& cornerTable); inline void SetOffset(const Nz::Vector2f& newOffset); inline void SetRotation(const Nz::DegreeAnglef& newRotation); @@ -45,12 +44,12 @@ namespace bw Sprite& operator=(Sprite&&) noexcept = default; private: - void UpdateTransformMatrix(); + void UpdateTransform(); LayerVisualEntityHandle m_visualEntity; - Nz::Matrix4f m_transformMatrix; - Nz::SpriteRef m_sprite; - int m_renderOrder; + Nz::DegreeAnglef m_rotation; + Nz::Vector2f m_offset; + std::shared_ptr m_sprite; bool m_isVisible; }; } diff --git a/include/ClientLib/Scripting/Sprite.inl b/include/ClientLib/Scripting/Sprite.inl index e12c8cc9..88bb666c 100644 --- a/include/ClientLib/Scripting/Sprite.inl +++ b/include/ClientLib/Scripting/Sprite.inl @@ -6,11 +6,11 @@ namespace bw { - inline Sprite::Sprite(LayerVisualEntityHandle visualEntity, Nz::SpriteRef sprite, const Nz::Matrix4f& transformMatrix, int renderOrder) : + inline Sprite::Sprite(LayerVisualEntityHandle visualEntity, std::shared_ptr sprite, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation) : m_visualEntity(std::move(visualEntity)), - m_transformMatrix(transformMatrix), + m_rotation(rotation), + m_offset(offset), m_sprite(std::move(sprite)), - m_renderOrder(renderOrder), m_isVisible(false) { } @@ -42,16 +42,16 @@ namespace bw inline void Sprite::SetOffset(const Nz::Vector2f& newOffset) { - m_transformMatrix.SetTranslation(newOffset); + m_offset = newOffset; - UpdateTransformMatrix(); + UpdateTransform(); } inline void Sprite::SetRotation(const Nz::DegreeAnglef& newRotation) { - m_transformMatrix.SetRotation(newRotation); + m_rotation = newRotation; - UpdateTransformMatrix(); + UpdateTransform(); } inline void Sprite::SetSize(const Nz::Vector2f& newSize) diff --git a/include/ClientLib/Scripting/Text.hpp b/include/ClientLib/Scripting/Text.hpp index 9bd034a4..4f0ba230 100644 --- a/include/ClientLib/Scripting/Text.hpp +++ b/include/ClientLib/Scripting/Text.hpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include namespace bw @@ -20,7 +20,7 @@ namespace bw class Text { public: - inline Text(LayerVisualEntityHandle visualEntity, Nz::SimpleTextDrawer drawer, Nz::TextSpriteRef textSprite, const Nz::Matrix4f& transformMatrix, int renderOrder, bool isHovering); + inline Text(LayerVisualEntityHandle visualEntity, Nz::SimpleTextDrawer drawer, std::shared_ptr textSprite, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation, bool isHovering); Text(const Text&) = delete; Text(Text&&) = default; ~Text() = default; @@ -45,16 +45,16 @@ namespace bw private: void UpdateTextSprite(); - void UpdateTransformMatrix(); + void UpdateTransform(); LayerVisualEntityHandle m_visualEntity; - Nz::Matrix4f m_transformMatrix; + Nz::DegreeAnglef m_rotation; + Nz::Vector2f m_offset; Nz::SimpleTextDrawer m_drawer; - Nz::TextSpriteRef m_textSprite; + std::shared_ptr m_textSprite; bool m_isHovering; bool m_isVisible; float m_hoveringHeight; - int m_renderOrder; }; } diff --git a/include/ClientLib/Scripting/Text.inl b/include/ClientLib/Scripting/Text.inl index b1e38114..9473989d 100644 --- a/include/ClientLib/Scripting/Text.inl +++ b/include/ClientLib/Scripting/Text.inl @@ -6,27 +6,27 @@ namespace bw { - inline Text::Text(LayerVisualEntityHandle visualEntity, Nz::SimpleTextDrawer drawer, Nz::TextSpriteRef textSprite, const Nz::Matrix4f& transformMatrix, int renderOrder, bool isHovering) : + inline Text::Text(LayerVisualEntityHandle visualEntity, Nz::SimpleTextDrawer drawer, std::shared_ptr textSprite, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation, bool isHovering) : m_visualEntity(std::move(visualEntity)), - m_transformMatrix(transformMatrix), + m_rotation(rotation), + m_offset(offset), m_drawer(std::move(drawer)), m_textSprite(std::move(textSprite)), m_isHovering(isHovering), m_isVisible(false), - m_hoveringHeight(0.f), - m_renderOrder(renderOrder) + m_hoveringHeight(0.f) { } inline Nz::Vector2f Text::GetSize() const { - Nz::Boxf box = m_textSprite->GetBoundingVolume().obb.localBox; + Nz::Boxf box = m_textSprite->GetAABB(); return { box.width, box.height }; } inline std::string Text::GetText() const { - return m_drawer.GetText().ToStdString(); + return m_drawer.GetText(); } inline void Text::Hide() @@ -46,16 +46,16 @@ namespace bw inline void Text::SetOffset(const Nz::Vector2f& newOffset) { - m_transformMatrix.SetTranslation(newOffset); + m_offset = newOffset; - UpdateTransformMatrix(); + UpdateTransform(); } inline void Text::SetRotation(const Nz::DegreeAnglef& newRotation) { - m_transformMatrix.SetRotation(newRotation); + m_rotation = newRotation; - UpdateTransformMatrix(); + UpdateTransform(); } inline void Text::SetText(const std::string& text) diff --git a/include/ClientLib/Scripting/Texture.hpp b/include/ClientLib/Scripting/Texture.hpp index 9696915b..fd639aab 100644 --- a/include/ClientLib/Scripting/Texture.hpp +++ b/include/ClientLib/Scripting/Texture.hpp @@ -8,14 +8,14 @@ #define BURGWAR_CLIENTLIB_SCRIPTING_TEXTURE_HPP #include -#include +#include namespace bw { class BURGWAR_CLIENTLIB_API Texture { public: - inline Texture(Nz::TextureRef texture); + inline Texture(std::shared_ptr texture); Texture(const Texture&) = default; Texture(Texture&&) = default; ~Texture() = default; @@ -26,7 +26,7 @@ namespace bw Texture& operator=(Texture&&) = default; private: - Nz::TextureRef m_texture; + std::shared_ptr m_texture; }; } diff --git a/include/ClientLib/Scripting/Texture.inl b/include/ClientLib/Scripting/Texture.inl index 82c7a763..bdc0717d 100644 --- a/include/ClientLib/Scripting/Texture.inl +++ b/include/ClientLib/Scripting/Texture.inl @@ -6,7 +6,7 @@ namespace bw { - inline Texture::Texture(Nz::TextureRef texture) : + inline Texture::Texture(std::shared_ptr texture) : m_texture(std::move(texture)) { } diff --git a/include/ClientLib/Scripting/Tilemap.hpp b/include/ClientLib/Scripting/Tilemap.hpp index 6023dfc1..b6178728 100644 --- a/include/ClientLib/Scripting/Tilemap.hpp +++ b/include/ClientLib/Scripting/Tilemap.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include namespace bw @@ -20,7 +20,7 @@ namespace bw class BURGWAR_CLIENTLIB_API Tilemap { public: - inline Tilemap(LayerVisualEntityHandle visualEntity, Nz::TileMapRef tilemap, const Nz::Matrix4f& transformMatrix, int renderOrder); + inline Tilemap(LayerVisualEntityHandle visualEntity, std::shared_ptr tilemap, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation); Tilemap(const Tilemap&) = delete; Tilemap(Tilemap&&) noexcept = default; ~Tilemap() = default; @@ -43,12 +43,12 @@ namespace bw Tilemap& operator=(Tilemap&&) noexcept = default; private: - void UpdateTransformMatrix(); + void UpdateTransform(); LayerVisualEntityHandle m_visualEntity; - Nz::Matrix4f m_transformMatrix; - Nz::TileMapRef m_tilemap; - int m_renderOrder; + Nz::DegreeAnglef m_rotation; + Nz::Vector2f m_offset; + std::shared_ptr m_tilemap; bool m_isVisible; }; } diff --git a/include/ClientLib/Scripting/Tilemap.inl b/include/ClientLib/Scripting/Tilemap.inl index fc3c829c..384ef144 100644 --- a/include/ClientLib/Scripting/Tilemap.inl +++ b/include/ClientLib/Scripting/Tilemap.inl @@ -6,11 +6,11 @@ namespace bw { - inline Tilemap::Tilemap(LayerVisualEntityHandle visualEntity, Nz::TileMapRef tilemap, const Nz::Matrix4f& transformMatrix, int renderOrder) : + inline Tilemap::Tilemap(LayerVisualEntityHandle visualEntity, std::shared_ptr tilemap, const Nz::Vector2f& offset, const Nz::DegreeAnglef& rotation) : m_visualEntity(std::move(visualEntity)), - m_transformMatrix(transformMatrix), + m_rotation(rotation), + m_offset(offset), m_tilemap(std::move(tilemap)), - m_renderOrder(renderOrder), m_isVisible(false) { } @@ -47,15 +47,15 @@ namespace bw inline void Tilemap::SetOffset(const Nz::Vector2f& newOffset) { - m_transformMatrix.SetTranslation(newOffset); + m_offset = newOffset; - UpdateTransformMatrix(); + UpdateTransform(); } inline void Tilemap::SetRotation(const Nz::DegreeAnglef& newRotation) { - m_transformMatrix.SetRotation(newRotation); + m_rotation = newRotation; - UpdateTransformMatrix(); + UpdateTransform(); } } diff --git a/include/ClientLib/SoundEntity.hpp b/include/ClientLib/SoundEntity.hpp index da8dcdf6..860971a3 100644 --- a/include/ClientLib/SoundEntity.hpp +++ b/include/ClientLib/SoundEntity.hpp @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include namespace bw { @@ -23,15 +23,15 @@ namespace bw friend ClientLayerSound; public: - SoundEntity(Ndk::World& renderWorld, ClientLayerSoundHandle layerEntityHandle, float depth = 0.f); - SoundEntity(Ndk::World& renderWorld, ClientLayerSoundHandle layerEntityHandle, const Nz::Node& parentNode, float depth = 0.f); + SoundEntity(entt::registry& renderWorld, ClientLayerSoundHandle layerEntityHandle, float depth = 0.f); + SoundEntity(entt::registry& renderWorld, ClientLayerSoundHandle layerEntityHandle, const Nz::Node& parentNode, float depth = 0.f); SoundEntity(const SoundEntity&) = delete; SoundEntity(SoundEntity&& entity) noexcept; ~SoundEntity(); - inline const Ndk::EntityHandle& GetEntity() const; + inline entt::handle GetEntity() const; - void PlaySound(std::size_t soundIndex, const Nz::SoundBufferRef& soundBuffer, bool isLooping, bool isSpatialized); + void PlaySound(std::size_t soundIndex, const std::shared_ptr& soundBuffer, bool isLooping, bool isSpatialized); void StopSound(std::size_t soundIndex); @@ -42,7 +42,7 @@ namespace bw private: std::vector m_soundIds; - Ndk::EntityOwner m_entity; + EntityOwner m_entity; ClientLayerSoundHandle m_layerSound; float m_depth; }; diff --git a/include/ClientLib/SoundEntity.inl b/include/ClientLib/SoundEntity.inl index d9a7feae..7305e197 100644 --- a/include/ClientLib/SoundEntity.inl +++ b/include/ClientLib/SoundEntity.inl @@ -6,7 +6,7 @@ namespace bw { - inline const Ndk::EntityHandle& SoundEntity::GetEntity() const + inline entt::handle SoundEntity::GetEntity() const { return m_entity; } diff --git a/include/ClientLib/Systems/FrameCallbackSystem.hpp b/include/ClientLib/Systems/FrameCallbackSystem.hpp index c002b78d..d5972ad8 100644 --- a/include/ClientLib/Systems/FrameCallbackSystem.hpp +++ b/include/ClientLib/Systems/FrameCallbackSystem.hpp @@ -8,28 +8,28 @@ #define BURGWAR_CLIENTLIB_SYSTEMS_FRAMECALLBACKSYSTEM_HPP #include -#include -#include +#include +#include #include namespace bw { - class ClientMatch; - - class BURGWAR_CLIENTLIB_API FrameCallbackSystem : public Ndk::System + class BURGWAR_CLIENTLIB_API FrameCallbackSystem { public: - FrameCallbackSystem(); + static constexpr Nz::Int64 ExecutionOrder = 100; + + FrameCallbackSystem(entt::registry& registry); ~FrameCallbackSystem() = default; - static Ndk::SystemIndex systemIndex; + void Update(Nz::Time elapsedTime); private: - void OnEntityRemoved(Ndk::Entity* entity) override; - void OnEntityValidation(Ndk::Entity* entity, bool justAdded) override; - void OnUpdate(float elapsedTime) override; + void OnScriptDestroy(entt::registry& registry, entt::entity entity); - Ndk::EntityList m_frameUpdateEntities; + std::unordered_set m_frameUpdateEntities; + entt::scoped_connection m_scriptDestroyConnection; + entt::registry& m_registry; }; } diff --git a/include/ClientLib/Systems/PostFrameCallbackSystem.hpp b/include/ClientLib/Systems/PostFrameCallbackSystem.hpp index 225fa8af..616a17a1 100644 --- a/include/ClientLib/Systems/PostFrameCallbackSystem.hpp +++ b/include/ClientLib/Systems/PostFrameCallbackSystem.hpp @@ -8,26 +8,28 @@ #define BURGWAR_CLIENTLIB_SYSTEMS_POSTFRAMECALLBACKSYSTEM_HPP #include -#include -#include +#include +#include #include namespace bw { - class BURGWAR_CLIENTLIB_API PostFrameCallbackSystem : public Ndk::System + class BURGWAR_CLIENTLIB_API PostFrameCallbackSystem { public: - PostFrameCallbackSystem(); + static constexpr Nz::Int64 ExecutionOrder = 150; + + PostFrameCallbackSystem(entt::registry& registry); ~PostFrameCallbackSystem() = default; - static Ndk::SystemIndex systemIndex; + void Update(Nz::Time elapsedTime); private: - void OnEntityRemoved(Ndk::Entity* entity) override; - void OnEntityValidation(Ndk::Entity* entity, bool justAdded) override; - void OnUpdate(float elapsedTime) override; + void OnScriptDestroy(entt::registry& registry, entt::entity entity); - Ndk::EntityList m_frameUpdateEntities; + std::unordered_set m_frameUpdateEntities; + entt::scoped_connection m_scriptDestroyConnection; + entt::registry& m_registry; }; } diff --git a/include/ClientLib/Systems/SoundSystem.hpp b/include/ClientLib/Systems/SoundSystem.hpp index 9a700892..9ed242e3 100644 --- a/include/ClientLib/Systems/SoundSystem.hpp +++ b/include/ClientLib/Systems/SoundSystem.hpp @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -18,27 +18,25 @@ namespace bw { class ConfigFile; - class BURGWAR_CLIENTLIB_API SoundSystem : public Ndk::System + class BURGWAR_CLIENTLIB_API SoundSystem { friend class SoundEmitterComponent; public: - SoundSystem(ConfigFile& playerSettings); + SoundSystem(entt::registry& registry, ConfigFile& playerSettings); ~SoundSystem() = default; - static Ndk::SystemIndex systemIndex; + void Update(Nz::Time elapsedTime); static constexpr Nz::UInt32 InvalidSoundId = 0; private: - Nz::UInt32 PlaySound(const Nz::SoundBufferRef& soundBuffer, const Nz::Vector3f& soundPosition, bool attachedToEntity, bool isLooping, bool isSpatialized); + void OnSoundDestroy(entt::registry& registry, entt::entity entity); + + Nz::UInt32 PlaySound(const std::shared_ptr& soundBuffer, const Nz::Vector3f& soundPosition, bool attachedToEntity, bool isLooping, bool isSpatialized); void StopSound(Nz::UInt32 soundId); void UpdateVolume(float newVolume); - void OnEntityRemoved(Ndk::Entity* entity) override; - void OnEntityValidation(Ndk::Entity* entity, bool justAdded) override; - void OnUpdate(float elapsedTime) override; - struct SoundData { Nz::Sound sound; @@ -47,12 +45,16 @@ namespace bw }; std::size_t m_maxSoundInPool; + std::unordered_set m_movableEntities; std::vector m_soundPool; tsl::hopscotch_map m_playingSounds; + entt::observer m_observer; + entt::scoped_connection m_nodeDestroyConnection; + entt::scoped_connection m_soundEmitterDestroyConnection; + entt::registry& m_registry; typename Nz::Signal::ConnectionGuard m_effectVolumeUpdateSlot; Nz::Vector3f m_soundOffset; Nz::UInt32 m_nextSoundId; - Ndk::EntityList m_movableEntities; float m_volume; }; } diff --git a/include/ClientLib/Systems/VisualInterpolationSystem.hpp b/include/ClientLib/Systems/VisualInterpolationSystem.hpp index fd35ab78..bfbe77f3 100644 --- a/include/ClientLib/Systems/VisualInterpolationSystem.hpp +++ b/include/ClientLib/Systems/VisualInterpolationSystem.hpp @@ -8,21 +8,22 @@ #define BURGWAR_CLIENTLIB_SYSTEMS_VISUALINTERPOLATIONSYSTEM_HPP #include -#include +#include +#include namespace bw { - class BURGWAR_CLIENTLIB_API VisualInterpolationSystem : public Ndk::System + class BURGWAR_CLIENTLIB_API VisualInterpolationSystem { public: - VisualInterpolationSystem(); + VisualInterpolationSystem(entt::registry& registry); ~VisualInterpolationSystem() = default; - static Ndk::SystemIndex systemIndex; + void Update(Nz::Time elapsedTime); private: - void OnEntityAdded(Ndk::Entity* entity) override; - void OnUpdate(float elapsedTime) override; + entt::observer m_observer; + entt::registry& m_registry; }; } diff --git a/include/ClientLib/VisualEntity.hpp b/include/ClientLib/VisualEntity.hpp index 1d5e7792..3fa9eca8 100644 --- a/include/ClientLib/VisualEntity.hpp +++ b/include/ClientLib/VisualEntity.hpp @@ -10,10 +10,15 @@ #include #include #include -#include -#include +#include +#include #include +namespace Nz +{ + class EnttWorld; +}; + namespace bw { class LayerVisualEntity; @@ -25,13 +30,13 @@ namespace bw friend LayerVisualEntity; public: - VisualEntity(Ndk::World& renderWorld, LayerVisualEntityHandle visualEntityHandle, int baseRenderOrder = 0); - VisualEntity(Ndk::World& renderWorld, LayerVisualEntityHandle visualEntityHandle, const Nz::Node& parentNode, int baseRenderOrder = 0); + VisualEntity(Nz::EnttWorld& renderWorld, LayerVisualEntityHandle visualEntityHandle, int baseRenderOrder = 0); + VisualEntity(Nz::EnttWorld& renderWorld, LayerVisualEntityHandle visualEntityHandle, const Nz::Node& parentNode, int baseRenderOrder = 0); VisualEntity(const VisualEntity&) = delete; VisualEntity(VisualEntity&& entity) noexcept; ~VisualEntity(); - inline const Ndk::EntityHandle& GetEntity() const; + inline entt::handle GetEntity() const; void Update(const Nz::Vector2f& position, const Nz::Quaternionf& rotation, const Nz::Vector2f& scale); @@ -39,29 +44,34 @@ namespace bw VisualEntity& operator=(VisualEntity&& entity) = delete; private: - void AttachHoveringRenderable(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& offsetMatrix, int renderOrder, float hoverOffset); - void AttachRenderable(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& offsetMatrix, int renderOrder); - void DetachHoveringRenderable(const Nz::InstancedRenderableRef& renderable); - void DetachRenderable(const Nz::InstancedRenderableRef& renderable); + void AttachHoveringRenderable(std::shared_ptr renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation, float hoverOffset); + void AttachRenderable(std::shared_ptr renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); + void DetachHoveringRenderable(const std::shared_ptr& renderable); + void DetachRenderable(const std::shared_ptr& renderable); inline void Enable(bool enable); - void UpdateHoveringRenderableHoveringHeight(const Nz::InstancedRenderableRef& renderable, float newHoveringHeight); - void UpdateHoveringRenderableMatrix(const Nz::InstancedRenderableRef& renderable, const Nz::Matrix4f& offsetMatrix); - void UpdateHoveringRenderableRenderOrder(const Nz::InstancedRenderableRef& renderable, int renderOrder); + void UpdateHoveringRenderableHoveringHeight(const std::shared_ptr& renderable, float newHoveringHeight); + void UpdateHoveringRenderableTransform(const std::shared_ptr& renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); - void UpdateRenderableMatrix(const Nz::InstancedRenderableRef& renderable, const Nz::Matrix4f& offsetMatrix); - void UpdateRenderableRenderOrder(const Nz::InstancedRenderableRef& renderable, int renderOrder); + void UpdateRenderableTransform(const std::shared_ptr& renderable, const Nz::Vector3f& offset, const Nz::Quaternionf& rotation); struct HoveringRenderable { float offset; - Ndk::EntityOwner entity; - Nz::InstancedRenderableRef renderable; + EntityOwner entity; + std::shared_ptr renderable; + }; + + struct Renderable + { + EntityOwner entity; + std::shared_ptr renderable; }; std::vector m_hoveringRenderables; - Ndk::EntityOwner m_entity; + std::vector m_renderables; + EntityOwner m_entity; LayerVisualEntityHandle m_visualEntity; int m_baseRenderOrder; }; diff --git a/include/ClientLib/VisualEntity.inl b/include/ClientLib/VisualEntity.inl index fe22ee13..27d603c1 100644 --- a/include/ClientLib/VisualEntity.inl +++ b/include/ClientLib/VisualEntity.inl @@ -3,18 +3,30 @@ // For conditions of distribution and use, see copyright notice in LICENSE #include +#include namespace bw { - inline const Ndk::EntityHandle& VisualEntity::GetEntity() const + inline entt::handle VisualEntity::GetEntity() const { return m_entity; } inline void VisualEntity::Enable(bool enable) { - m_entity->Enable(enable); + auto EnableEntity = [enable](const entt::handle& entity) + { + if (enable) + entity.remove(); + else + entity.emplace_or_replace(); + }; + + EnableEntity(m_entity); + for (auto& renderable : m_renderables) + EnableEntity(renderable.entity); + for (auto& hoveringRenderable : m_hoveringRenderables) - hoveringRenderable.entity->Enable(enable); + EnableEntity(hoveringRenderable.entity); } } diff --git a/include/ClientLib/VisualLayer.hpp b/include/ClientLib/VisualLayer.hpp index 6c5e0d18..06a7eb24 100644 --- a/include/ClientLib/VisualLayer.hpp +++ b/include/ClientLib/VisualLayer.hpp @@ -8,7 +8,7 @@ #define BURGWAR_CLIENTLIB_VISUALLAYER_HPP #include -#include +#include namespace bw { diff --git a/include/CoreLib/AnimationManager.hpp b/include/CoreLib/AnimationManager.hpp index 365afa3f..bc3a57d6 100644 --- a/include/CoreLib/AnimationManager.hpp +++ b/include/CoreLib/AnimationManager.hpp @@ -8,7 +8,8 @@ #define BURGWAR_CORELIB_ANIMATIONMANAGER_HPP #include -#include +#include +#include #include #include @@ -23,17 +24,17 @@ namespace bw AnimationManager() = default; ~AnimationManager() = default; - inline void PushAnimation(float duration, UpdateCallback update, FinishCallback finish); + inline void PushAnimation(Nz::Time duration, UpdateCallback update, FinishCallback finish); - inline void Update(float elapsedTime); + inline void Update(Nz::Time elapsedTime); private: struct Animation { std::function finishCallback; std::function updateCallback; - float duration; - float elapsedtime; + Nz::Time duration; + Nz::Time elapsedtime; }; std::vector m_newAnimations; diff --git a/include/CoreLib/AnimationManager.inl b/include/CoreLib/AnimationManager.inl index 121c0c01..a705feb5 100644 --- a/include/CoreLib/AnimationManager.inl +++ b/include/CoreLib/AnimationManager.inl @@ -8,19 +8,19 @@ namespace bw { - inline void AnimationManager::PushAnimation(float duration, UpdateCallback update, FinishCallback finish) + inline void AnimationManager::PushAnimation(Nz::Time duration, UpdateCallback update, FinishCallback finish) { if (!update(0.f)) return; Animation& anim = m_newAnimations.emplace_back(); anim.duration = duration; - anim.elapsedtime = 0.f; + anim.elapsedtime = Nz::Time::Zero(); anim.finishCallback = std::move(finish); anim.updateCallback = std::move(update); } - inline void AnimationManager::Update(float elapsedTime) + inline void AnimationManager::Update(Nz::Time elapsedTime) { std::move(m_newAnimations.begin(), m_newAnimations.end(), std::back_inserter(m_playingAnimations)); m_newAnimations.clear(); @@ -41,7 +41,7 @@ namespace bw isRunning = false; } else - isRunning = anim.updateCallback(anim.elapsedtime / anim.duration); + isRunning = anim.updateCallback((anim.elapsedtime / anim.duration).AsSeconds()); if (isRunning) ++i; diff --git a/include/CoreLib/AnimationStore.hpp b/include/CoreLib/AnimationStore.hpp index e744124f..18f060d3 100644 --- a/include/CoreLib/AnimationStore.hpp +++ b/include/CoreLib/AnimationStore.hpp @@ -8,8 +8,8 @@ #define BURGWAR_CORELIB_ANIMATIONSTORE_HPP #include +#include #include -#include #include #include @@ -31,7 +31,7 @@ namespace bw struct AnimationData { std::string animationName; - std::chrono::milliseconds duration; + Nz::Time duration; }; static constexpr std::size_t InvalidId = std::numeric_limits::max(); diff --git a/include/CoreLib/AssetStore.hpp b/include/CoreLib/AssetStore.hpp index 1772bb12..2c2d6680 100644 --- a/include/CoreLib/AssetStore.hpp +++ b/include/CoreLib/AssetStore.hpp @@ -8,9 +8,9 @@ #define BURGWAR_CORELIB_ASSETSTORE_HPP #include -#include +#include #include -#include +#include #include namespace bw @@ -20,24 +20,24 @@ namespace bw class BURGWAR_CORELIB_API AssetStore { public: - inline AssetStore(const Logger& logger, std::shared_ptr assetDirectory); + inline AssetStore(const Logger& logger, std::shared_ptr assetDirectory); virtual ~AssetStore(); virtual void Clear(); - inline const std::shared_ptr& GetAssetDirectory() const; - const Nz::ImageRef& GetImage(const std::string& imagePath) const; + inline const std::shared_ptr& GetAssetDirectory() const; + const std::shared_ptr& GetImage(const std::string& imagePath) const; - inline void UpdateAssetDirectory(std::shared_ptr assetDirectory); + inline void UpdateAssetDirectory(std::shared_ptr assetDirectory); protected: - template const Nz::ObjectRef& GetResource(const std::string& resourcePath, tsl::hopscotch_map>& cache, const ParameterType& params) const; + template const std::shared_ptr& GetResource(const std::string& resourcePath, tsl::hopscotch_map>& cache, const ParameterType& params) const; const Logger& m_logger; private: - mutable tsl::hopscotch_map m_images; - mutable std::shared_ptr m_assetDirectory; + mutable tsl::hopscotch_map> m_images; + mutable std::shared_ptr m_assetDirectory; }; } diff --git a/include/CoreLib/AssetStore.inl b/include/CoreLib/AssetStore.inl index dc915f98..42d1c478 100644 --- a/include/CoreLib/AssetStore.inl +++ b/include/CoreLib/AssetStore.inl @@ -9,55 +9,56 @@ namespace bw { - inline AssetStore::AssetStore(const Logger& logger, std::shared_ptr assetDirectory) : + inline AssetStore::AssetStore(const Logger& logger, std::shared_ptr assetDirectory) : m_logger(logger), m_assetDirectory(std::move(assetDirectory)) { } - inline const std::shared_ptr& bw::AssetStore::GetAssetDirectory() const + inline const std::shared_ptr& bw::AssetStore::GetAssetDirectory() const { return m_assetDirectory; } - inline void AssetStore::UpdateAssetDirectory(std::shared_ptr assetDirectory) + inline void AssetStore::UpdateAssetDirectory(std::shared_ptr assetDirectory) { m_assetDirectory = std::move(assetDirectory); } - template - const Nz::ObjectRef& AssetStore::GetResource(const std::string& resourcePath, tsl::hopscotch_map>& cache, const ParameterType& params) const + template + const std::shared_ptr& AssetStore::GetResource(const std::string& resourcePath, tsl::hopscotch_map>& cache, const ParameterType& params) const { - static Nz::ObjectRef InvalidResource; + static std::shared_ptr InvalidResource; if (auto it = cache.find(resourcePath); it != cache.end()) return it->second; - VirtualDirectory::Entry entry; - if (!m_assetDirectory->GetEntry(resourcePath, &entry)) - return InvalidResource; - - auto resource = std::visit([&](auto&& arg) -> Nz::ObjectRef + std::shared_ptr resource; + auto LoadResource = [&](const Nz::VirtualDirectory::Entry& entry) { - using T = std::decay_t; - if constexpr (std::is_same_v) - { - bwLog(m_logger, LogLevel::Info, "Loading asset from memory"); - return ResourceType::LoadFromMemory(arg.data(), arg.size(), params); - } - else if constexpr (std::is_same_v) + return std::visit([&](auto&& arg) { - bwLog(m_logger, LogLevel::Info, "Loading asset from {}", arg.generic_u8string()); - return ResourceType::LoadFromFile(arg.generic_u8string(), params); - } - else if constexpr (std::is_same_v) - { - return nullptr; - } - else - static_assert(AlwaysFalse::value, "non-exhaustive visitor"); - }, entry); + using T = std::decay_t; + + if constexpr (std::is_same_v) + { + bwLog(m_logger, LogLevel::Info, "Loading asset from {}", arg.stream->GetPath()); + if constexpr (Streaming) + resource = ResourceType::OpenFromStream(*arg.stream, params); + else + resource = ResourceType::LoadFromStream(*arg.stream, params); + + return resource != nullptr; + } + else if constexpr (std::is_base_of_v) + { + return false; + } + else + static_assert(AlwaysFalse(), "non-exhaustive visitor"); + }, entry); + }; - if (!resource) + if (!m_assetDirectory->GetEntry(resourcePath, LoadResource)) return InvalidResource; return cache.emplace(resourcePath, std::move(resource)).first->second; diff --git a/include/CoreLib/BasicPlayerMovementController.hpp b/include/CoreLib/BasicPlayerMovementController.hpp index 9088f861..42795a16 100644 --- a/include/CoreLib/BasicPlayerMovementController.hpp +++ b/include/CoreLib/BasicPlayerMovementController.hpp @@ -18,7 +18,7 @@ namespace bw BasicPlayerMovementController() = default; ~BasicPlayerMovementController() = default; - bool PreSolveCollision(PlayerMovementComponent& playerMovement, const Ndk::EntityHandle& collisionBody, Nz::Arbiter2D& arbiter) const override; + bool PreSolveCollision(PlayerMovementComponent& playerMovement, entt::entity collisionBody, Nz::PhysArbiter2D& arbiter) const override; void UpdateVelocity(const PlayerInputData& inputs, PlayerMovementComponent& playerMovement, Nz::RigidBody2D& rigidBody, const Nz::Vector2f& gravity, float damping, float dt) const override; }; diff --git a/include/CoreLib/BurgApp.inl b/include/CoreLib/BurgApp.inl deleted file mode 100644 index 311d292a..00000000 --- a/include/CoreLib/BurgApp.inl +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Burgwar" project -// For conditions of distribution and use, see copyright notice in LICENSE - -#include -#include -#include -#include -#include - -namespace bw -{ - inline Nz::UInt64 BurgApp::GetAppTime() const - { - return m_appTime; - } - - inline const ConfigFile& BurgApp::GetConfig() const - { - return m_config; - } - - inline auto BurgApp::GetLogger() -> Logger& - { - return m_logger; - } - - inline Nz::UInt64 BurgApp::GetLogTime() const - { - return Nz::GetElapsedMicroseconds() - m_startTime; - } - - inline const tsl::hopscotch_map>& BurgApp::GetMods() const - { - return m_mods; - } - - inline WebService& BurgApp::GetWebService() - { - assert(m_webService); - return *m_webService; - } -} diff --git a/include/CoreLib/BurgApp.hpp b/include/CoreLib/BurgAppComponent.hpp similarity index 54% rename from include/CoreLib/BurgApp.hpp rename to include/CoreLib/BurgAppComponent.hpp index 5f7be4c2..a1ae566d 100644 --- a/include/CoreLib/BurgApp.hpp +++ b/include/CoreLib/BurgAppComponent.hpp @@ -8,10 +8,11 @@ #define BURGWAR_CORELIB_BURGAPP_HPP #include -#include +#include #include #include -#include +#include +#include #include #include #include @@ -21,44 +22,39 @@ namespace bw class ConfigFile; class Mod; - class BURGWAR_CORELIB_API BurgApp + class BURGWAR_CORELIB_API BurgAppComponent : public Nz::ApplicationComponent { public: - BurgApp(LogSide side, const ConfigFile& config); - ~BurgApp(); + BurgAppComponent(Nz::ApplicationBase& app, LogSide side, const ConfigFile& config); + ~BurgAppComponent(); - inline Nz::UInt64 GetAppTime() const; + inline Nz::Time GetAppTime() const; inline const ConfigFile& GetConfig() const; inline Logger& GetLogger(); - inline Nz::UInt64 GetLogTime() const; + inline Nz::Time GetLogTime() const; inline const tsl::hopscotch_map>& GetMods() const; - inline WebService& GetWebService(); + inline Nz::WebService& GetWebService(); - void Update(); + inline bool HasWebService() const; - private: - static void HandleInterruptSignal(const char* signalName); - - void InstallInterruptHandlers(); + void Update(Nz::Time elapsedTime) override; + private: Logger m_logger; - static BurgApp* s_application; + static BurgAppComponent* s_application; protected: void LoadMods(); - virtual void Quit() = 0; - const ConfigFile& m_config; - std::optional m_webService; + std::unique_ptr m_webService; tsl::hopscotch_map> m_mods; - Nz::UInt64 m_appTime; - Nz::UInt64 m_lastTime; - Nz::UInt64 m_startTime; + Nz::Time m_appTime; + Nz::Time m_startTime; }; } -#include +#include #endif diff --git a/include/CoreLib/BurgAppComponent.inl b/include/CoreLib/BurgAppComponent.inl new file mode 100644 index 00000000..1d488499 --- /dev/null +++ b/include/CoreLib/BurgAppComponent.inl @@ -0,0 +1,47 @@ +// Copyright (C) 2020 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in LICENSE + +#include +#include +#include +#include + +namespace bw +{ + inline Nz::Time BurgAppComponent::GetAppTime() const + { + return m_appTime; + } + + inline const ConfigFile& BurgAppComponent::GetConfig() const + { + return m_config; + } + + inline auto BurgAppComponent::GetLogger() -> Logger& + { + return m_logger; + } + + inline Nz::Time BurgAppComponent::GetLogTime() const + { + return Nz::GetElapsedNanoseconds() - m_startTime; + } + + inline const tsl::hopscotch_map>& BurgAppComponent::GetMods() const + { + return m_mods; + } + + inline Nz::WebService& BurgAppComponent::GetWebService() + { + assert(m_webService); + return *m_webService; + } + + inline bool BurgAppComponent::HasWebService() const + { + return m_webService != nullptr; + } +} diff --git a/include/CoreLib/CommandStore.hpp b/include/CoreLib/CommandStore.hpp index 1903f736..7759e7ae 100644 --- a/include/CoreLib/CommandStore.hpp +++ b/include/CoreLib/CommandStore.hpp @@ -7,8 +7,8 @@ #ifndef BURGWAR_CORELIB_COMMANDSTORE_HPP #define BURGWAR_CORELIB_COMMANDSTORE_HPP +#include #include -#include #include #include #include @@ -33,16 +33,16 @@ namespace bw template const OutgoingCommand& GetOutgoingCommand() const; template - void SerializePacket(Nz::NetPacket& packet, const T& data) const; + void SerializePacket(Nz::ByteStream& packet, const T& data) const; - bool UnserializePacket(PeerRef peer, Nz::NetPacket& packet) const; + bool DeserializePacket(PeerRef peer, Nz::ByteStream& packet) const; - using UnserializeFunction = std::function; + using DeserializeFunction = std::function; struct IncomingCommand { bool enabled = false; - UnserializeFunction unserialize; + DeserializeFunction deserialize; const char* name; }; @@ -59,7 +59,7 @@ namespace bw template void RegisterOutgoingCommand(const char* name, Nz::ENetPacketFlags flags, Nz::UInt8 channelId); private: - using HandleFunction = std::function; + using HandleFunction = std::function; std::vector m_incomingCommands; std::vector m_outgoingCommands; diff --git a/include/CoreLib/CommandStore.inl b/include/CoreLib/CommandStore.inl index 78eff45f..e6c795c7 100644 --- a/include/CoreLib/CommandStore.inl +++ b/include/CoreLib/CommandStore.inl @@ -52,7 +52,7 @@ namespace bw IncomingCommand& newCommand = m_incomingCommands[packetId]; newCommand.enabled = true; - newCommand.unserialize = [this, cb = std::forward(callback)](PeerRef peer, Nz::NetPacket& packet) + newCommand.deserialize = [this, cb = std::forward(callback)](PeerRef peer, Nz::ByteStream& packet) { T data; try @@ -63,7 +63,7 @@ namespace bw } catch (const std::exception&) { - bwLog(m_logger, LogLevel::Error, "Failed to unserialize packet"); + bwLog(m_logger, LogLevel::Error, "Failed to deserialize packet"); return false; } @@ -91,7 +91,7 @@ namespace bw template template - void CommandStore::SerializePacket(Nz::NetPacket& packet, const T& data) const + void CommandStore::SerializePacket(Nz::ByteStream& packet, const T& data) const { packet << static_cast(T::Type); @@ -106,7 +106,7 @@ namespace bw } template - bool CommandStore::UnserializePacket(PeerRef peer, Nz::NetPacket& packet) const + bool CommandStore::DeserializePacket(PeerRef peer, Nz::ByteStream& packet) const { Nz::UInt8 opcode; try @@ -115,7 +115,7 @@ namespace bw } catch (const std::exception&) { - bwLog(m_logger, LogLevel::Error, "Failed to unserialize opcode"); + bwLog(m_logger, LogLevel::Error, "Failed to deserialize opcode"); return false; } @@ -125,7 +125,7 @@ namespace bw return false; } - m_incomingCommands[opcode].unserialize(peer, packet); + m_incomingCommands[opcode].deserialize(peer, packet); return true; } } diff --git a/include/CoreLib/Components/AnimationComponent.hpp b/include/CoreLib/Components/AnimationComponent.hpp index 52788247..eec8ca01 100644 --- a/include/CoreLib/Components/AnimationComponent.hpp +++ b/include/CoreLib/Components/AnimationComponent.hpp @@ -8,8 +8,9 @@ #define BURGWAR_CORELIB_COMPONENTS_ANIMATIONCOMPONENT_HPP #include -#include -#include +#include +#include +#include #include #include @@ -17,36 +18,34 @@ namespace bw { class AnimationStore; - class BURGWAR_CORELIB_API AnimationComponent : public Ndk::Component + class BURGWAR_CORELIB_API AnimationComponent : public BaseComponent { friend class AnimationSystem; public: - inline AnimationComponent(std::shared_ptr animStore); + inline AnimationComponent(entt::handle entity, std::shared_ptr animStore); inline AnimationComponent(const AnimationComponent& animation); ~AnimationComponent() = default; inline std::size_t GetAnimId() const; inline const std::shared_ptr& GetAnimationStore() const; - inline Nz::UInt64 GetEndTime() const; - inline Nz::UInt64 GetStartTime() const; + inline Nz::Time GetEndTime() const; + inline Nz::Time GetStartTime() const; inline bool IsPlaying() const; - void Play(std::size_t animId, Nz::UInt64 animStartTime); - - static Ndk::ComponentIndex componentIndex; + void Play(std::size_t animId, Nz::Time animStartTime); NazaraSignal(OnAnimationEnd, AnimationComponent* /*emitter*/); NazaraSignal(OnAnimationStart, AnimationComponent* /*emitter*/); private: - void Update(Nz::UInt64 now); + void Update(Nz::Time now); struct ActiveAnimation { std::size_t animId; - Nz::UInt64 endTime; - Nz::UInt64 startTime; + Nz::Time endTime; + Nz::Time startTime; }; std::optional m_playingAnimation; diff --git a/include/CoreLib/Components/AnimationComponent.inl b/include/CoreLib/Components/AnimationComponent.inl index 5551019d..42a4eef6 100644 --- a/include/CoreLib/Components/AnimationComponent.inl +++ b/include/CoreLib/Components/AnimationComponent.inl @@ -3,15 +3,18 @@ // For conditions of distribution and use, see copyright notice in LICENSE #include +#include namespace bw { - inline AnimationComponent::AnimationComponent(std::shared_ptr animStore) : + inline AnimationComponent::AnimationComponent(entt::handle entity, std::shared_ptr animStore) : + BaseComponent(entity), m_animationStore(std::move(animStore)) { } inline AnimationComponent::AnimationComponent(const AnimationComponent& animation) : + BaseComponent(animation), m_playingAnimation(animation.m_playingAnimation), m_animationStore(animation.m_animationStore) { @@ -28,13 +31,13 @@ namespace bw return m_animationStore; } - inline Nz::UInt64 AnimationComponent::GetEndTime() const + inline Nz::Time AnimationComponent::GetEndTime() const { assert(IsPlaying()); return m_playingAnimation->endTime; } - inline Nz::UInt64 AnimationComponent::GetStartTime() const + inline Nz::Time AnimationComponent::GetStartTime() const { assert(IsPlaying()); return m_playingAnimation->startTime; diff --git a/include/CoreLib/Components/BaseComponent.hpp b/include/CoreLib/Components/BaseComponent.hpp new file mode 100644 index 00000000..8f4aae5c --- /dev/null +++ b/include/CoreLib/Components/BaseComponent.hpp @@ -0,0 +1,41 @@ +// Copyright (C) 2020 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in LICENSE + +#pragma once + +#ifndef BURGWAR_CORELIB_COMPONENTS_BASECOMPONENT_HPP +#define BURGWAR_CORELIB_COMPONENTS_BASECOMPONENT_HPP + +#include +#include +#include + +namespace bw +{ + class BURGWAR_CORELIB_API BaseComponent + { + public: + inline BaseComponent(entt::handle handle); + BaseComponent(const BaseComponent&) = default; + BaseComponent(BaseComponent&&) noexcept = default; + ~BaseComponent() = default; + + inline entt::entity GetEntity() const; + inline entt::handle GetHandle() const; + inline entt::registry* GetRegistry(); + inline entt::registry* GetRegistry() const; + + void KillEntity(); + + BaseComponent& operator=(const BaseComponent&) = default; + BaseComponent& operator=(BaseComponent&&) = default; + + private: + entt::handle m_handle; + }; +} + +#include + +#endif diff --git a/include/CoreLib/Components/BaseComponent.inl b/include/CoreLib/Components/BaseComponent.inl new file mode 100644 index 00000000..8a56c85f --- /dev/null +++ b/include/CoreLib/Components/BaseComponent.inl @@ -0,0 +1,39 @@ +// Copyright (C) 2020 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in LICENSE + +#include +#include + +namespace bw +{ + inline BaseComponent::BaseComponent(entt::handle handle) : + m_handle(handle) + { + } + + inline entt::entity BaseComponent::GetEntity() const + { + return m_handle; + } + + inline entt::handle BaseComponent::GetHandle() const + { + return m_handle; + } + + inline entt::registry* BaseComponent::GetRegistry() + { + return m_handle.registry(); + } + + inline entt::registry* BaseComponent::GetRegistry() const + { + return m_handle.registry(); + } + + inline void BaseComponent::KillEntity() + { + m_handle.destroy(); + } +} diff --git a/include/CoreLib/Components/CollisionDataComponent.hpp b/include/CoreLib/Components/CollisionDataComponent.hpp index d245724a..4554cc96 100644 --- a/include/CoreLib/Components/CollisionDataComponent.hpp +++ b/include/CoreLib/Components/CollisionDataComponent.hpp @@ -10,29 +10,31 @@ #include #include #include -#include #include namespace bw { - class BURGWAR_CORELIB_API CollisionDataComponent : public Ndk::Component + class BURGWAR_CORELIB_API CollisionDataComponent { friend class ColliderSystem; public: CollisionDataComponent() = default; + CollisionDataComponent(const CollisionDataComponent&) = default; + CollisionDataComponent(CollisionDataComponent&&) = default; ~CollisionDataComponent() = default; inline void AddCollider(Collider collider); - Nz::Collider2DRef BuildCollider(float scale = 1.f) const; + std::shared_ptr BuildCollider(float scale = 1.f) const; inline const std::vector& GetColliders() const; - static Ndk::ComponentIndex componentIndex; + CollisionDataComponent& operator=(const CollisionDataComponent&) = default; + CollisionDataComponent& operator=(CollisionDataComponent&&) = default; private: - static Nz::Collider2DRef ToCollider(const Collider& collider, float scale); + static std::shared_ptr ToCollider(const Collider& collider, float scale); std::vector m_colliders; }; diff --git a/include/CoreLib/Components/ConstraintComponent2D.hpp b/include/CoreLib/Components/ConstraintComponent2D.hpp new file mode 100644 index 00000000..000d61a7 --- /dev/null +++ b/include/CoreLib/Components/ConstraintComponent2D.hpp @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequisites.hpp + +#pragma once + +#ifndef BURGWAR_CORELIB_CONSTRAINTCOMPONENT2D_HPP +#define BURGWAR_CORELIB_CONSTRAINTCOMPONENT2D_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace bw +{ + class BURGWAR_CORELIB_API ConstraintComponent2D + { + public: + ConstraintComponent2D() = default; + ConstraintComponent2D(const ConstraintComponent2D&) = delete; + ConstraintComponent2D(ConstraintComponent2D&& joint) noexcept = default; + + template T* CreateConstraint(entt::registry& registry, entt::entity first, entt::entity second, Args&&... args); + bool RemoveConstraint(Nz::PhysConstraint2D* constraint); + + ConstraintComponent2D& operator=(const ConstraintComponent2D& joint) = delete; + ConstraintComponent2D& operator=(ConstraintComponent2D&& joint) noexcept = default; + + + private: + struct ConstraintData + { + std::unique_ptr constraint; + + NazaraSlot(DestructionWatcherComponent, OnDestruction, onBodyADestruction); + NazaraSlot(DestructionWatcherComponent, OnDestruction, onBodyBDestruction); + }; + + std::vector m_constraints; + }; +} + +#include + +#endif // NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP diff --git a/include/CoreLib/Components/ConstraintComponent2D.inl b/include/CoreLib/Components/ConstraintComponent2D.inl new file mode 100644 index 00000000..6c5ad781 --- /dev/null +++ b/include/CoreLib/Components/ConstraintComponent2D.inl @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequisites.hpp + +#include +#include +#include + +namespace bw +{ + template + T* ConstraintComponent2D::CreateConstraint(entt::registry& registry, entt::entity first, entt::entity second, Args&& ...args) + { + auto FetchBody = [&](entt::entity entity) -> Nz::RigidBody2D* + { + if (Nz::RigidBody2DComponent* physBodyA = registry.try_get(entity)) + return physBodyA; + + return nullptr; + }; + + Nz::RigidBody2D* firstBody = FetchBody(first); + NazaraAssert(firstBody, "First entity has no CollisionComponent2D nor PhysicsComponent2D component"); + + Nz::RigidBody2D* secondBody = FetchBody(second); + NazaraAssert(secondBody, "Second entity has no CollisionComponent2D nor PhysicsComponent2D component"); + + auto& constraintData = m_constraints.emplace_back(); + constraintData.constraint = std::make_unique(*firstBody, *secondBody, std::forward(args)...); + + if (DestructionWatcherComponent* deathComponent = registry.try_get(first)) + { + constraintData.onBodyADestruction.Connect(deathComponent->OnDestruction, [this, constraint = constraintData.constraint.get()](DestructionWatcherComponent* /*emitter*/) + { + RemoveConstraint(constraint); + }); + } + + if (DestructionWatcherComponent* deathComponent = registry.try_get(second)) + { + constraintData.onBodyBDestruction.Connect(deathComponent->OnDestruction, [this, constraint = constraintData.constraint.get()](DestructionWatcherComponent* /*emitter*/) + { + RemoveConstraint(constraint); + }); + } + + return static_cast(constraintData.constraint.get()); + } + + inline bool ConstraintComponent2D::RemoveConstraint(Nz::PhysConstraint2D* constraintPtr) + { + auto it = std::find_if(m_constraints.begin(), m_constraints.end(), [constraintPtr](const ConstraintData& constraintData) { return constraintData.constraint.get() == constraintPtr; }); + if (it != m_constraints.end()) + m_constraints.erase(it); + + return !m_constraints.empty(); + } +} diff --git a/include/CoreLib/Components/CooldownComponent.hpp b/include/CoreLib/Components/CooldownComponent.hpp index 769885f7..80e88470 100644 --- a/include/CoreLib/Components/CooldownComponent.hpp +++ b/include/CoreLib/Components/CooldownComponent.hpp @@ -8,26 +8,24 @@ #define BURGWAR_CORELIB_COMPONENTS_COOLDOWNCOMPONENT_HPP #include -#include +#include namespace bw { - class BURGWAR_CORELIB_API CooldownComponent : public Ndk::Component + class BURGWAR_CORELIB_API CooldownComponent { public: - inline CooldownComponent(Nz::UInt32 cooldown); + inline CooldownComponent(Nz::Time cooldown); CooldownComponent(const CooldownComponent&) = default; ~CooldownComponent() = default; - inline void SetNextTriggerTime(Nz::UInt64 time); + inline void SetNextTriggerTime(Nz::Time time); - inline bool Trigger(Nz::UInt64 currentTime); - - static Ndk::ComponentIndex componentIndex; + inline bool Trigger(Nz::Time currentTime); private: - Nz::UInt32 m_cooldown; - Nz::UInt64 m_nextTriggerTime; + Nz::Time m_cooldown; + Nz::Time m_nextTriggerTime; }; } diff --git a/include/CoreLib/Components/CooldownComponent.inl b/include/CoreLib/Components/CooldownComponent.inl index 348fb0ad..e5e0c7ee 100644 --- a/include/CoreLib/Components/CooldownComponent.inl +++ b/include/CoreLib/Components/CooldownComponent.inl @@ -6,18 +6,18 @@ namespace bw { - inline CooldownComponent::CooldownComponent(Nz::UInt32 cooldown) : + inline CooldownComponent::CooldownComponent(Nz::Time cooldown) : m_cooldown(cooldown), - m_nextTriggerTime(0) + m_nextTriggerTime(Nz::Time::Zero()) { } - inline void CooldownComponent::SetNextTriggerTime(Nz::UInt64 time) + inline void CooldownComponent::SetNextTriggerTime(Nz::Time time) { m_nextTriggerTime = time; } - inline bool CooldownComponent::Trigger(Nz::UInt64 currentTime) + inline bool CooldownComponent::Trigger(Nz::Time currentTime) { if (currentTime < m_nextTriggerTime) return false; diff --git a/include/CoreLib/Components/DestructionWatcherComponent.hpp b/include/CoreLib/Components/DestructionWatcherComponent.hpp new file mode 100644 index 00000000..47df8b11 --- /dev/null +++ b/include/CoreLib/Components/DestructionWatcherComponent.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in LICENSE + +#pragma once + +#ifndef BURGWAR_CORELIB_COMPONENTS_DESTRUCTIONWATCHERCOMPONENT_HPP +#define BURGWAR_CORELIB_COMPONENTS_DESTRUCTIONWATCHERCOMPONENT_HPP + +#include +#include +#include +#include + +namespace bw +{ + class BURGWAR_CORELIB_API DestructionWatcherComponent : public BaseComponent + { + public: + using BaseComponent::BaseComponent; + DestructionWatcherComponent(const DestructionWatcherComponent&) = delete; + DestructionWatcherComponent(DestructionWatcherComponent&&) noexcept = default; + inline ~DestructionWatcherComponent(); + + DestructionWatcherComponent& operator=(const DestructionWatcherComponent&) = delete; + DestructionWatcherComponent& operator=(DestructionWatcherComponent&&) noexcept = default; + + NazaraSignal(OnDestruction, DestructionWatcherComponent* /*emitter*/); + }; +} + +#include + +#endif diff --git a/src/ClientLib/Components/LocalPlayerControlledComponent.cpp b/include/CoreLib/Components/DestructionWatcherComponent.inl similarity index 53% rename from src/ClientLib/Components/LocalPlayerControlledComponent.cpp rename to include/CoreLib/Components/DestructionWatcherComponent.inl index 73323f93..58ff9aa7 100644 --- a/src/ClientLib/Components/LocalPlayerControlledComponent.cpp +++ b/include/CoreLib/Components/DestructionWatcherComponent.inl @@ -2,9 +2,12 @@ // This file is part of the "Burgwar" project // For conditions of distribution and use, see copyright notice in LICENSE -#include +#include namespace bw { - Ndk::ComponentIndex LocalPlayerControlledComponent::componentIndex; + inline DestructionWatcherComponent::~DestructionWatcherComponent() + { + OnDestruction(this); + } } diff --git a/include/CoreLib/Components/EntityOwnerComponent.hpp b/include/CoreLib/Components/EntityOwnerComponent.hpp index c9a4ded1..6073808b 100644 --- a/include/CoreLib/Components/EntityOwnerComponent.hpp +++ b/include/CoreLib/Components/EntityOwnerComponent.hpp @@ -8,24 +8,26 @@ #define BURGWAR_CORELIB_COMPONENTS_ENTITYOWNERCOMPONENT_HPP #include -#include -#include +#include +#include namespace bw { - class BURGWAR_CORELIB_API EntityOwnerComponent : public Ndk::Component + class BURGWAR_CORELIB_API EntityOwnerComponent : public BaseComponent { public: - EntityOwnerComponent() = default; - inline EntityOwnerComponent(const EntityOwnerComponent&); + using BaseComponent::BaseComponent; + EntityOwnerComponent(const EntityOwnerComponent&) = delete; + EntityOwnerComponent(EntityOwnerComponent&&) noexcept = default; ~EntityOwnerComponent() = default; - inline void Register(const Ndk::EntityHandle& entity); + inline void Register(entt::handle entity); - static Ndk::ComponentIndex componentIndex; + EntityOwnerComponent& operator=(const EntityOwnerComponent&) = delete; + EntityOwnerComponent& operator=(EntityOwnerComponent&&) noexcept = default; private: - std::vector m_ownedEntities; + std::vector m_ownedEntities; }; } diff --git a/include/CoreLib/Components/EntityOwnerComponent.inl b/include/CoreLib/Components/EntityOwnerComponent.inl index ef94aad7..c1064df7 100644 --- a/include/CoreLib/Components/EntityOwnerComponent.inl +++ b/include/CoreLib/Components/EntityOwnerComponent.inl @@ -6,25 +6,9 @@ namespace bw { - inline EntityOwnerComponent::EntityOwnerComponent(const EntityOwnerComponent&) + inline void EntityOwnerComponent::Register(entt::handle entity) { - } - - inline void EntityOwnerComponent::Register(const Ndk::EntityHandle& entity) - { - if (entity) - { - // Try to reuse expired handles before adding an entry - for (auto& ownerHandle : m_ownedEntities) - { - if (!ownerHandle) - { - ownerHandle = entity; - return; - } - } - - m_ownedEntities.emplace_back(entity); - } + // Try to reuse expired handles before adding an entry + m_ownedEntities.emplace_back(entity); } } diff --git a/include/CoreLib/Components/HealthComponent.hpp b/include/CoreLib/Components/HealthComponent.hpp index d7c25286..e464d043 100644 --- a/include/CoreLib/Components/HealthComponent.hpp +++ b/include/CoreLib/Components/HealthComponent.hpp @@ -8,31 +8,29 @@ #define BURGWAR_CORELIB_COMPONENTS_HEALTHCOMPONENT_HPP #include -#include -#include +#include +#include namespace bw { - class BURGWAR_CORELIB_API HealthComponent : public Ndk::Component + class BURGWAR_CORELIB_API HealthComponent : public BaseComponent { public: - inline HealthComponent(Nz::UInt16 maxHealth); - inline HealthComponent(const HealthComponent&); + inline HealthComponent(entt::handle entity, Nz::UInt16 maxHealth); + inline HealthComponent(const HealthComponent& health); - inline void Damage(Nz::UInt16 damage, const Ndk::EntityHandle& attacker); + inline void Damage(Nz::UInt16 damage, entt::handle attacker); inline Nz::UInt16 GetHealth() const; inline float GetHealthPct() const; inline Nz::UInt16 GetMaxHealth() const; - inline void Heal(Nz::UInt16 heal, const Ndk::EntityHandle& healer); + inline void Heal(Nz::UInt16 heal, entt::handle healer); - static Ndk::ComponentIndex componentIndex; - - NazaraSignal(OnDamage, HealthComponent* /*emitter*/, Nz::UInt16& /*damage*/, const Ndk::EntityHandle& /*attacker*/); - NazaraSignal(OnDying, HealthComponent* /*emitter*/, const Ndk::EntityHandle& /*attacker*/); - NazaraSignal(OnDied, const HealthComponent* /*emitter*/, const Ndk::EntityHandle& /*attacker*/); - NazaraSignal(OnHealthChange, HealthComponent* /*emitter*/, Nz::UInt16 /*newHealth*/, const Ndk::EntityHandle& /*source*/); + NazaraSignal(OnDamage, HealthComponent* /*emitter*/, Nz::UInt16& /*damage*/, entt::handle /*attacker*/); + NazaraSignal(OnDying, HealthComponent* /*emitter*/, entt::handle /*attacker*/); + NazaraSignal(OnDie, const HealthComponent* /*emitter*/, entt::handle /*attacker*/); + NazaraSignal(OnHealthChange, HealthComponent* /*emitter*/, Nz::UInt16 /*newHealth*/, entt::handle /*source*/); private: Nz::UInt16 m_currentHealth; diff --git a/include/CoreLib/Components/HealthComponent.inl b/include/CoreLib/Components/HealthComponent.inl index 8908dbee..ace99f17 100644 --- a/include/CoreLib/Components/HealthComponent.inl +++ b/include/CoreLib/Components/HealthComponent.inl @@ -6,19 +6,21 @@ namespace bw { - inline HealthComponent::HealthComponent(Nz::UInt16 maxHealth) : + inline HealthComponent::HealthComponent(entt::handle entity, Nz::UInt16 maxHealth) : + BaseComponent(entity), m_currentHealth(maxHealth), m_maxHealth(maxHealth) { } inline HealthComponent::HealthComponent(const HealthComponent& health) : + BaseComponent(health), m_currentHealth(health.m_currentHealth), m_maxHealth(health.m_maxHealth) { } - inline void HealthComponent::Damage(Nz::UInt16 damage, const Ndk::EntityHandle& attacker) + inline void HealthComponent::Damage(Nz::UInt16 damage, entt::handle attacker) { OnDamage(this, damage, attacker); @@ -40,10 +42,7 @@ namespace bw // Recheck health in case a slot gave us health if (m_currentHealth == 0) - { - OnDied(this, attacker); - m_entity->Kill(); - } + OnDie(this, attacker); } } } @@ -63,7 +62,7 @@ namespace bw return m_maxHealth; } - inline void HealthComponent::Heal(Nz::UInt16 heal, const Ndk::EntityHandle& healer) + inline void HealthComponent::Heal(Nz::UInt16 heal, entt::handle healer) { Nz::UInt16 newHealth = m_currentHealth + heal; if (newHealth < m_currentHealth) diff --git a/include/CoreLib/Components/InputComponent.hpp b/include/CoreLib/Components/InputComponent.hpp index 592ce53e..7b413842 100644 --- a/include/CoreLib/Components/InputComponent.hpp +++ b/include/CoreLib/Components/InputComponent.hpp @@ -10,17 +10,17 @@ #include #include #include -#include -#include +#include +#include #include #include namespace bw { - class BURGWAR_CORELIB_API InputComponent : public Ndk::Component + class BURGWAR_CORELIB_API InputComponent : public BaseComponent { public: - inline InputComponent(std::shared_ptr inputController); + inline InputComponent(entt::handle handle, std::shared_ptr inputController); inline const std::shared_ptr& GetController() const; inline const PlayerInputData& GetInputs() const; @@ -30,8 +30,6 @@ namespace bw inline void UpdateInputs(const PlayerInputData& inputData); inline void UpdatePreviousInputs(const PlayerInputData& inputData); - static Ndk::ComponentIndex componentIndex; - NazaraSignal(OnInputUpdate, InputComponent* /*input*/); private: diff --git a/include/CoreLib/Components/InputComponent.inl b/include/CoreLib/Components/InputComponent.inl index d2853773..662bb057 100644 --- a/include/CoreLib/Components/InputComponent.inl +++ b/include/CoreLib/Components/InputComponent.inl @@ -6,7 +6,8 @@ namespace bw { - inline InputComponent::InputComponent(std::shared_ptr inputController) : + inline InputComponent::InputComponent(entt::handle handle, std::shared_ptr inputController) : + BaseComponent(handle), m_inputIndex(0), m_inputController(std::move(inputController)) { @@ -43,7 +44,7 @@ namespace bw if (++m_inputIndex >= m_inputData.size()) m_inputIndex = 0; - m_inputData[m_inputIndex] = std::move(inputData); + m_inputData[m_inputIndex] = inputData; OnInputUpdate(this); } diff --git a/include/CoreLib/Components/MatchComponent.hpp b/include/CoreLib/Components/MatchComponent.hpp index 622d78aa..a1718c36 100644 --- a/include/CoreLib/Components/MatchComponent.hpp +++ b/include/CoreLib/Components/MatchComponent.hpp @@ -10,27 +10,30 @@ #include #include #include -#include +#include namespace bw { class Match; - class BURGWAR_CORELIB_API MatchComponent : public Ndk::Component + class BURGWAR_CORELIB_API MatchComponent { public: inline MatchComponent(Match& match, LayerIndex layerIndex, EntityId uniqueId); + MatchComponent(const MatchComponent&) = delete; + MatchComponent(MatchComponent&&) noexcept = default; ~MatchComponent() = default; inline LayerIndex GetLayerIndex() const; inline Match& GetMatch() const; inline EntityId GetUniqueId() const; - static Ndk::ComponentIndex componentIndex; + MatchComponent& operator=(const MatchComponent&) = delete; + MatchComponent& operator=(MatchComponent&&) noexcept = default; private: + Nz::MovablePtr m_match; EntityId m_uniqueId; - Match& m_match; LayerIndex m_layerIndex; }; } diff --git a/include/CoreLib/Components/MatchComponent.inl b/include/CoreLib/Components/MatchComponent.inl index fc65f0c0..b950a22d 100644 --- a/include/CoreLib/Components/MatchComponent.inl +++ b/include/CoreLib/Components/MatchComponent.inl @@ -7,8 +7,8 @@ namespace bw { inline MatchComponent::MatchComponent(Match& match, LayerIndex layerIndex, EntityId uniqueId) : + m_match(&match), m_uniqueId(uniqueId), - m_match(match), m_layerIndex(layerIndex) { } @@ -20,7 +20,7 @@ namespace bw inline Match& MatchComponent::GetMatch() const { - return m_match; + return *m_match; } inline EntityId MatchComponent::GetUniqueId() const diff --git a/include/CoreLib/Components/NetworkSyncComponent.hpp b/include/CoreLib/Components/NetworkSyncComponent.hpp index 920878c5..3af31028 100644 --- a/include/CoreLib/Components/NetworkSyncComponent.hpp +++ b/include/CoreLib/Components/NetworkSyncComponent.hpp @@ -8,32 +8,43 @@ #define BURGWAR_CORELIB_COMPONENTS_NETWORKSYNCCOMPONENT_HPP #include -#include -#include +#include +#include +#include #include namespace bw { - class BURGWAR_CORELIB_API NetworkSyncComponent : public Ndk::Component + class NetworkSyncSystem; + + class BURGWAR_CORELIB_API NetworkSyncComponent { public: - inline NetworkSyncComponent(std::string entityClass, const Ndk::EntityHandle& parent = Ndk::EntityHandle::InvalidHandle); - ~NetworkSyncComponent() = default; + NetworkSyncComponent(NetworkSyncSystem& networkSync, std::string entityClass, entt::handle parent = {}); + NetworkSyncComponent(const NetworkSyncComponent&) = delete; + inline NetworkSyncComponent(NetworkSyncComponent&& networkComponent) noexcept; + ~NetworkSyncComponent(); inline const std::string& GetEntityClass() const; - inline const Ndk::EntityHandle& GetParent() const; + inline Nz::UInt32 GetNetworkId() const; + inline entt::handle GetParent() const; inline void Invalidate(); - inline void UpdateParent(const Ndk::EntityHandle& parent); + inline void UpdateParent(entt::handle parent); - static Ndk::ComponentIndex componentIndex; + NetworkSyncComponent& operator=(const NetworkSyncComponent&) = delete; + inline NetworkSyncComponent& operator=(NetworkSyncComponent&& networkComponent) noexcept; NazaraSignal(OnInvalidated, NetworkSyncComponent* /*emitter*/); private: - Ndk::EntityHandle m_parent; + static constexpr Nz::UInt32 InvalidNetworkId = 0xFFFFFFFF; + std::string m_entityClass; + entt::handle m_parent; + Nz::MovablePtr m_networkSystem; + Nz::UInt32 m_networkId; }; } diff --git a/include/CoreLib/Components/NetworkSyncComponent.inl b/include/CoreLib/Components/NetworkSyncComponent.inl index 5633b954..fa2ae4f3 100644 --- a/include/CoreLib/Components/NetworkSyncComponent.inl +++ b/include/CoreLib/Components/NetworkSyncComponent.inl @@ -3,12 +3,15 @@ // For conditions of distribution and use, see copyright notice in LICENSE #include +#include namespace bw { - inline NetworkSyncComponent::NetworkSyncComponent(std::string entityClass, const Ndk::EntityHandle& parent) : - m_parent(parent), - m_entityClass(entityClass) + inline NetworkSyncComponent::NetworkSyncComponent(NetworkSyncComponent&& networkComponent) noexcept : + m_entityClass(std::move(networkComponent.m_entityClass)), + m_parent(std::move(networkComponent.m_parent)), + m_networkId(std::exchange(networkComponent.m_networkId, InvalidNetworkId)), + m_networkSystem(std::move(networkComponent.m_networkSystem)) { } @@ -17,7 +20,12 @@ namespace bw return m_entityClass; } - inline const Ndk::EntityHandle& NetworkSyncComponent::GetParent() const + inline Nz::UInt32 NetworkSyncComponent::GetNetworkId() const + { + return m_networkId; + } + + inline entt::handle NetworkSyncComponent::GetParent() const { return m_parent; } @@ -27,9 +35,20 @@ namespace bw OnInvalidated(this); } - inline void NetworkSyncComponent::UpdateParent(const Ndk::EntityHandle& parent) + inline void NetworkSyncComponent::UpdateParent(entt::handle parent) { m_parent = parent; //TODO: network event } + + inline NetworkSyncComponent& NetworkSyncComponent::operator=(NetworkSyncComponent&& networkComponent) noexcept + { + m_entityClass = std::move(networkComponent.m_entityClass); + m_parent = std::move(networkComponent.m_parent); + m_networkSystem = std::move(networkComponent.m_networkSystem); + + std::swap(m_networkId, networkComponent.m_networkId); + + return *this; + } } diff --git a/include/CoreLib/Components/OwnerComponent.hpp b/include/CoreLib/Components/OwnerComponent.hpp index cebc5f27..113943ea 100644 --- a/include/CoreLib/Components/OwnerComponent.hpp +++ b/include/CoreLib/Components/OwnerComponent.hpp @@ -9,12 +9,11 @@ #include #include -#include #include namespace bw { - class BURGWAR_CORELIB_API OwnerComponent : public Ndk::Component + class BURGWAR_CORELIB_API OwnerComponent { public: OwnerComponent(PlayerHandle owner); @@ -22,8 +21,6 @@ namespace bw inline Player* GetOwner() const; - static Ndk::ComponentIndex componentIndex; - private: PlayerHandle m_owner; }; diff --git a/include/CoreLib/Components/PlayerControlledComponent.hpp b/include/CoreLib/Components/PlayerControlledComponent.hpp index f8117b5f..7ed27dc8 100644 --- a/include/CoreLib/Components/PlayerControlledComponent.hpp +++ b/include/CoreLib/Components/PlayerControlledComponent.hpp @@ -9,12 +9,11 @@ #include #include -#include #include namespace bw { - class BURGWAR_CORELIB_API PlayerControlledComponent : public Ndk::Component + class BURGWAR_CORELIB_API PlayerControlledComponent { public: PlayerControlledComponent(PlayerHandle owner); @@ -22,8 +21,6 @@ namespace bw inline Player* GetOwner() const; - static Ndk::ComponentIndex componentIndex; - private: PlayerHandle m_owner; }; diff --git a/include/CoreLib/Components/PlayerMovementComponent.hpp b/include/CoreLib/Components/PlayerMovementComponent.hpp index a5e03469..17b2e1fa 100644 --- a/include/CoreLib/Components/PlayerMovementComponent.hpp +++ b/include/CoreLib/Components/PlayerMovementComponent.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -17,7 +16,7 @@ namespace bw { class PlayerMovementController; - class BURGWAR_CORELIB_API PlayerMovementComponent : public Ndk::Component + class BURGWAR_CORELIB_API PlayerMovementComponent { public: PlayerMovementComponent(); @@ -47,8 +46,6 @@ namespace bw inline bool WasJumping() const; - static Ndk::ComponentIndex componentIndex; - private: std::shared_ptr m_controller; Nz::Vector2f m_targetVelocity; diff --git a/include/CoreLib/Components/ScriptComponent.hpp b/include/CoreLib/Components/ScriptComponent.hpp index d1ffced7..3953d925 100644 --- a/include/CoreLib/Components/ScriptComponent.hpp +++ b/include/CoreLib/Components/ScriptComponent.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,12 +22,14 @@ namespace bw { - class BURGWAR_CORELIB_API ScriptComponent : public Ndk::Component + class BURGWAR_CORELIB_API ScriptComponent { friend class TickCallbackSystem; public: ScriptComponent(const Logger& logger, std::shared_ptr element, std::shared_ptr context, sol::table entityTable, PropertyValueMap properties); + ScriptComponent(const ScriptComponent&) = delete; + ScriptComponent(ScriptComponent&&) noexcept = default; ~ScriptComponent(); template @@ -51,29 +53,31 @@ namespace bw inline std::size_t RegisterCallback(ElementEvent event, sol::main_protected_function callback, bool async); inline std::size_t RegisterCallbackCustom(std::size_t eventIndex, sol::main_protected_function callback, bool async); - inline void SetNextTick(float seconds); + inline void SetNextTick(Nz::Time seconds); inline bool UnregisterCallback(ElementEvent event, std::size_t callbackId); inline bool UnregisterCallbackCustom(std::size_t eventIndex, std::size_t callbackId); inline void UpdateElement(std::shared_ptr element); - void UpdateEntity(const Ndk::EntityHandle& entity); + void UpdateEntity(entt::entity entity); - static Ndk::ComponentIndex componentIndex; + ScriptComponent& operator=(const ScriptComponent&) = delete; + ScriptComponent& operator=(ScriptComponent&&) noexcept = default; + + static constexpr auto in_place_delete = true; private: - inline bool CanTriggerTick(float elapsedTime); - void OnAttached() override; + inline bool CanTriggerTick(Nz::Time elapsedTime); std::array, ElementEventCount> m_eventCallbacks; std::vector> m_customEventCallbacks; std::shared_ptr m_element; std::shared_ptr m_context; + std::unique_ptr m_logger; std::size_t m_nextCallbackId; sol::table m_entityTable; - EntityLogger m_logger; PropertyValueMap m_properties; - float m_timeBeforeTick; + Nz::Time m_timeBeforeTick; }; } diff --git a/include/CoreLib/Components/ScriptComponent.inl b/include/CoreLib/Components/ScriptComponent.inl index 0915244b..6cbedf58 100644 --- a/include/CoreLib/Components/ScriptComponent.inl +++ b/include/CoreLib/Components/ScriptComponent.inl @@ -32,7 +32,7 @@ namespace bw if (!callbackResult.valid()) { sol::error err = callbackResult; - bwLog(m_logger, LogLevel::Error, "{} callback failed: {}", ToString(Event), err.what()); + bwLog(*m_logger, LogLevel::Error, "{} callback failed: {}", ToString(Event), err.what()); if constexpr (!EventData::FatalError) continue; @@ -63,7 +63,7 @@ namespace bw if (!callbackResult.valid()) { sol::error err = callbackResult; - bwLog(m_logger, LogLevel::Error, "{} callback failed: {}", ToString(Event), err.what()); + bwLog(*m_logger, LogLevel::Error, "{} callback failed: {}", ToString(Event), err.what()); if constexpr (!EventData::FatalError) continue; @@ -110,7 +110,7 @@ namespace bw if (!callbackResult.valid()) { sol::error err = callbackResult; - bwLog(m_logger, LogLevel::Error, "{} callback failed: {}", eventData.name, err.what()); + bwLog(*m_logger, LogLevel::Error, "{} callback failed: {}", eventData.name, err.what()); continue; } @@ -135,7 +135,7 @@ namespace bw if (!callbackResult.valid()) { sol::error err = callbackResult; - bwLog(m_logger, LogLevel::Error, "{} callback failed: {}", eventData.name, err.what()); + bwLog(*m_logger, LogLevel::Error, "{} callback failed: {}", eventData.name, err.what()); continue; } @@ -146,7 +146,7 @@ namespace bw if (!callbackResult.valid()) { sol::error err = callbackResult; - bwLog(m_logger, LogLevel::Error, "{} combinator failed: {}", eventData.name, err.what()); + bwLog(*m_logger, LogLevel::Error, "{} combinator failed: {}", eventData.name, err.what()); continue; } @@ -173,7 +173,8 @@ namespace bw inline const EntityLogger& ScriptComponent::GetLogger() const { - return m_logger; + assert(m_logger); + return *m_logger; } inline std::optional> ScriptComponent::GetProperty(const std::string& keyName) const @@ -230,7 +231,7 @@ namespace bw return callbackData.callbackId; } - inline void ScriptComponent::SetNextTick(float seconds) + inline void ScriptComponent::SetNextTick(Nz::Time seconds) { m_timeBeforeTick = seconds; } @@ -275,9 +276,9 @@ namespace bw m_element = std::move(element); } - inline bool ScriptComponent::CanTriggerTick(float elapsedTime) + inline bool ScriptComponent::CanTriggerTick(Nz::Time elapsedTime) { m_timeBeforeTick -= elapsedTime; - return m_timeBeforeTick < 0.f; + return m_timeBeforeTick < Nz::Time::Zero(); } } diff --git a/include/CoreLib/Components/WeaponComponent.hpp b/include/CoreLib/Components/WeaponComponent.hpp index 0a652a6a..91140a7b 100644 --- a/include/CoreLib/Components/WeaponComponent.hpp +++ b/include/CoreLib/Components/WeaponComponent.hpp @@ -8,7 +8,7 @@ #define BURGWAR_CORELIB_COMPONENTS_WEAPONCOMPONENT_HPP #include -#include +#include namespace bw { @@ -20,14 +20,14 @@ namespace bw Max = SingleShotRepeat }; - class BURGWAR_CORELIB_API WeaponComponent : public Ndk::Component + class BURGWAR_CORELIB_API WeaponComponent { public: - inline WeaponComponent(Ndk::EntityHandle owner, WeaponAttackMode attackMode); + inline WeaponComponent(entt::handle owner, WeaponAttackMode attackMode); ~WeaponComponent() = default; inline WeaponAttackMode GetAttackMode() const; - inline const Ndk::EntityHandle& GetOwner() const; + inline entt::handle GetOwner() const; inline bool IsActive() const; inline bool IsAttacking() const; @@ -35,12 +35,10 @@ namespace bw inline void SetActive(bool isActive); inline void SetAttacking(bool isAttacking); - inline void UpdateOwner(Ndk::EntityHandle owner); - - static Ndk::ComponentIndex componentIndex; + inline void UpdateOwner(entt::handle owner); private: - Ndk::EntityHandle m_owner; + entt::handle m_owner; WeaponAttackMode m_attackMode; bool m_isActive; bool m_isAttacking; diff --git a/include/CoreLib/Components/WeaponComponent.inl b/include/CoreLib/Components/WeaponComponent.inl index 445f7cbb..e9d7fe5d 100644 --- a/include/CoreLib/Components/WeaponComponent.inl +++ b/include/CoreLib/Components/WeaponComponent.inl @@ -6,8 +6,8 @@ namespace bw { - inline WeaponComponent::WeaponComponent(Ndk::EntityHandle owner, WeaponAttackMode attackMode) : - m_owner(std::move(owner)), + inline WeaponComponent::WeaponComponent(entt::handle owner, WeaponAttackMode attackMode) : + m_owner(owner), m_attackMode(attackMode), m_isActive(false), m_isAttacking(false) @@ -19,7 +19,7 @@ namespace bw return m_attackMode; } - inline const Ndk::EntityHandle& WeaponComponent::GetOwner() const + inline entt::handle WeaponComponent::GetOwner() const { return m_owner; } @@ -46,8 +46,8 @@ namespace bw m_isAttacking = isAttacking; } - inline void WeaponComponent::UpdateOwner(Ndk::EntityHandle owner) + inline void WeaponComponent::UpdateOwner(entt::handle owner) { - m_owner = std::move(owner); + m_owner = owner; } } diff --git a/include/CoreLib/Components/WeaponWielderComponent.hpp b/include/CoreLib/Components/WeaponWielderComponent.hpp index 824dd20c..6ebb84ee 100644 --- a/include/CoreLib/Components/WeaponWielderComponent.hpp +++ b/include/CoreLib/Components/WeaponWielderComponent.hpp @@ -8,28 +8,32 @@ #define BURGWAR_CORELIB_COMPONENTS_WEAPONWIELDERCOMPONENT_HPP #include +#include +#include +#include +#include #include -#include -#include +#include #include #include #include - + namespace bw { - class BURGWAR_CORELIB_API WeaponWielderComponent : public Ndk::Component + class BURGWAR_CORELIB_API WeaponWielderComponent : public BaseComponent { public: - using WeaponInitCallback = std::function; + using WeaponInitCallback = Nz::FunctionRef; - inline WeaponWielderComponent(); + inline WeaponWielderComponent(entt::handle entity); inline WeaponWielderComponent(const WeaponWielderComponent& weaponWielder); + WeaponWielderComponent(WeaponWielderComponent&&) noexcept = default; ~WeaponWielderComponent() = default; - inline const Ndk::EntityHandle& GetActiveWeapon() const; + inline entt::handle GetActiveWeapon() const; inline std::size_t GetSelectedWeapon() const; - inline const Ndk::EntityHandle& GetWeapon(std::size_t weaponIndex) const; - inline const std::vector& GetWeapons() const; + inline entt::handle GetWeapon(std::size_t weaponIndex) const; + inline const std::vector& GetWeapons() const; inline std::size_t GetWeaponCount() const; inline const Nz::Vector2f& GetWeaponOffset() const; @@ -38,7 +42,7 @@ namespace bw inline bool HasActiveWeapon() const; inline bool HasWeapon(const std::string& weaponClass) const; - void OverrideEntities(const std::function& callback); + void OverrideEntities(const std::function& callback); void RemoveWeapon(const std::string& weaponClass); @@ -46,7 +50,8 @@ namespace bw inline bool SelectWeapon(const std::string& weaponClass); inline void SetWeaponOffset(const Nz::Vector2f& weaponOffset); - static Ndk::ComponentIndex componentIndex; + WeaponWielderComponent& operator=(const WeaponWielderComponent&) = delete; + WeaponWielderComponent& operator=(WeaponWielderComponent&&) noexcept = default; static constexpr std::size_t NoWeapon = std::numeric_limits::max(); @@ -55,10 +60,10 @@ namespace bw NazaraSignal(OnWeaponRemove, WeaponWielderComponent* /*wielder*/, const std::string& /*weaponClass*/, std::size_t /*weaponIndex*/); private: - Nz::Vector2f m_weaponOffset; std::size_t m_activeWeaponIndex; - std::vector m_weapons; + std::vector m_weapons; tsl::hopscotch_map m_weaponByName; + Nz::Vector2f m_weaponOffset; }; } diff --git a/include/CoreLib/Components/WeaponWielderComponent.inl b/include/CoreLib/Components/WeaponWielderComponent.inl index ac6aa142..1132691a 100644 --- a/include/CoreLib/Components/WeaponWielderComponent.inl +++ b/include/CoreLib/Components/WeaponWielderComponent.inl @@ -6,25 +6,27 @@ namespace bw { - inline WeaponWielderComponent::WeaponWielderComponent() : - m_weaponOffset(Nz::Vector2f::Zero()), - m_activeWeaponIndex(NoWeapon) + inline WeaponWielderComponent::WeaponWielderComponent(entt::handle entity) : + BaseComponent(entity), + m_activeWeaponIndex(NoWeapon), + m_weaponOffset(Nz::Vector2f::Zero()) { } inline WeaponWielderComponent::WeaponWielderComponent(const WeaponWielderComponent& weaponWielder) : - m_weaponOffset(weaponWielder.m_weaponOffset), + BaseComponent(weaponWielder), m_activeWeaponIndex(weaponWielder.m_activeWeaponIndex), - m_weaponByName(weaponWielder.m_weaponByName) + m_weaponByName(weaponWielder.m_weaponByName), + m_weaponOffset(weaponWielder.m_weaponOffset) { //FIXME: - for (const Ndk::EntityHandle& entity : weaponWielder.m_weapons) + for (entt::handle entity : weaponWielder.m_weapons) m_weapons.emplace_back(entity); } - inline const Ndk::EntityHandle& WeaponWielderComponent::GetActiveWeapon() const + inline entt::handle WeaponWielderComponent::GetActiveWeapon() const { - return (m_activeWeaponIndex != NoWeapon) ? m_weapons[m_activeWeaponIndex] : Ndk::EntityHandle::InvalidHandle; + return (m_activeWeaponIndex != NoWeapon) ? m_weapons[m_activeWeaponIndex].GetEntity() : entt::handle{}; } inline std::size_t WeaponWielderComponent::GetSelectedWeapon() const @@ -32,13 +34,13 @@ namespace bw return m_activeWeaponIndex; } - inline const Ndk::EntityHandle& WeaponWielderComponent::GetWeapon(std::size_t weaponIndex) const + inline entt::handle WeaponWielderComponent::GetWeapon(std::size_t weaponIndex) const { assert(weaponIndex < m_weapons.size()); return m_weapons[weaponIndex]; } - inline const std::vector& WeaponWielderComponent::GetWeapons() const + inline const std::vector& WeaponWielderComponent::GetWeapons() const { return m_weapons; } diff --git a/include/CoreLib/ConfigFile.hpp b/include/CoreLib/ConfigFile.hpp index b8977310..01132a24 100644 --- a/include/CoreLib/ConfigFile.hpp +++ b/include/CoreLib/ConfigFile.hpp @@ -8,10 +8,10 @@ #define BURGWAR_CORELIB_CONFIGFILE_HPP #include -#include -#include +#include +#include +#include #include -#include #include #include #include @@ -21,12 +21,12 @@ namespace bw { - class BurgApp; + class BurgAppComponent; class BURGWAR_CORELIB_API ConfigFile { public: - ConfigFile(BurgApp& app); + ConfigFile(BurgAppComponent& app); ConfigFile(const ConfigFile&) = delete; ConfigFile(ConfigFile&&) noexcept = default; ~ConfigFile() = default; @@ -54,9 +54,9 @@ namespace bw ConfigFile& operator=(ConfigFile&&) = delete; protected: - using FloatValidation = std::function(double value)>; - using IntegerValidation = std::function(long long value)>; - using StringValidation = std::function(std::string value)>; + using FloatValidation = std::function(double value)>; + using IntegerValidation = std::function(long long value)>; + using StringValidation = std::function(std::string value)>; inline void RegisterBoolOption(std::string optionName, std::optional defaultValue = std::nullopt); inline void RegisterFloatOption(std::string optionName, std::optional defaultValue = std::nullopt, FloatValidation validation = nullptr); @@ -130,7 +130,7 @@ namespace bw std::vector m_options; std::unordered_map m_optionByName; - BurgApp& m_app; + BurgAppComponent& m_app; ConfigSection m_globalSection; }; } diff --git a/include/CoreLib/ConfigFile.inl b/include/CoreLib/ConfigFile.inl index d7a29d2f..d7b1dbbe 100644 --- a/include/CoreLib/ConfigFile.inl +++ b/include/CoreLib/ConfigFile.inl @@ -9,7 +9,7 @@ namespace bw { - inline ConfigFile::ConfigFile(BurgApp& app) : + inline ConfigFile::ConfigFile(BurgAppComponent& app) : m_app(app) { } diff --git a/include/CoreLib/CustomInputController.hpp b/include/CoreLib/CustomInputController.hpp index 638373e1..06f94514 100644 --- a/include/CoreLib/CustomInputController.hpp +++ b/include/CoreLib/CustomInputController.hpp @@ -18,7 +18,7 @@ namespace bw inline CustomInputController(sol::main_protected_function callback); ~CustomInputController() = default; - std::optional GenerateInputs(const Ndk::EntityHandle& entity) const override; + std::optional GenerateInputs(entt::handle entity) const override; private: sol::main_protected_function m_callback; diff --git a/include/CoreLib/EntityId.hpp b/include/CoreLib/EntityId.hpp index d4147045..e9ceaba6 100644 --- a/include/CoreLib/EntityId.hpp +++ b/include/CoreLib/EntityId.hpp @@ -7,7 +7,7 @@ #ifndef BURGWAR_CORELIB_ENTITYID_HPP #define BURGWAR_CORELIB_ENTITYID_HPP -#include +#include namespace bw { diff --git a/include/CoreLib/EntityOwner.hpp b/include/CoreLib/EntityOwner.hpp new file mode 100644 index 00000000..1abb8715 --- /dev/null +++ b/include/CoreLib/EntityOwner.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2020 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in LICENSE + +#pragma once + +#ifndef BURGWAR_CORELIB_ENTITYOWNER_HPP +#define BURGWAR_CORELIB_ENTITYOWNER_HPP + +#include + +namespace bw +{ + class EntityOwner + { + public: + inline EntityOwner(entt::handle entity = entt::handle{}); + EntityOwner(const EntityOwner&) = delete; + inline EntityOwner(EntityOwner&& entityOwner) noexcept; + inline ~EntityOwner(); + + inline entt::handle GetEntity() const; + + inline explicit operator bool() const; + inline operator entt::handle() const; + inline entt::handle* operator->(); + inline const entt::handle* operator->() const; + + EntityOwner& operator=(const EntityOwner&) = delete; + inline EntityOwner& operator=(EntityOwner&& entityOwner) noexcept; + + private: + entt::handle m_entity; + }; +} + +#include + +#endif diff --git a/include/CoreLib/EntityOwner.inl b/include/CoreLib/EntityOwner.inl new file mode 100644 index 00000000..be9a1e2e --- /dev/null +++ b/include/CoreLib/EntityOwner.inl @@ -0,0 +1,56 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Burgwar" project +// For conditions of distribution and use, see copyright notice in Prerequisites.hpp + +#include + +namespace bw +{ + inline EntityOwner::EntityOwner(entt::handle entity) : + m_entity(entity) + { + } + + inline EntityOwner::EntityOwner(EntityOwner&& entityOwner) noexcept : + m_entity(entityOwner.m_entity) + { + entityOwner.m_entity = {}; + } + + inline EntityOwner::~EntityOwner() + { + if (m_entity) + m_entity.destroy(); + } + + inline entt::handle EntityOwner::GetEntity() const + { + return m_entity; + } + + inline EntityOwner::operator bool() const + { + return bool(m_entity); + } + + inline EntityOwner::operator entt::handle() const + { + return m_entity; + } + + inline entt::handle* EntityOwner::operator->() + { + return &m_entity; + } + + inline const entt::handle* EntityOwner::operator->() const + { + return &m_entity; + } + + inline EntityOwner& EntityOwner::operator=(EntityOwner&& entityOwner) noexcept + { + std::swap(m_entity, entityOwner.m_entity); + return *this; + } +} diff --git a/include/CoreLib/Export.hpp b/include/CoreLib/Export.hpp index 6eeab16c..cc843338 100644 --- a/include/CoreLib/Export.hpp +++ b/include/CoreLib/Export.hpp @@ -7,7 +7,7 @@ #ifndef BURGWAR_CORELIB_EXPORT_HPP #define BURGWAR_CORELIB_EXPORT_HPP -#include +#include #ifdef BURGWAR_CORELIB_STATIC #define BURGWAR_CORELIB_API diff --git a/include/CoreLib/InputController.hpp b/include/CoreLib/InputController.hpp index 99b9ad30..645cf26f 100644 --- a/include/CoreLib/InputController.hpp +++ b/include/CoreLib/InputController.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include namespace bw @@ -20,7 +20,7 @@ namespace bw InputController() = default; virtual ~InputController(); - virtual std::optional GenerateInputs(const Ndk::EntityHandle& entity) const = 0; + virtual std::optional GenerateInputs(entt::handle entity) const = 0; }; } diff --git a/include/CoreLib/LayerIndex.hpp b/include/CoreLib/LayerIndex.hpp index 88d81586..61245d14 100644 --- a/include/CoreLib/LayerIndex.hpp +++ b/include/CoreLib/LayerIndex.hpp @@ -7,7 +7,7 @@ #ifndef BURGWAR_CORELIB_LAYERINDEX_HPP #define BURGWAR_CORELIB_LAYERINDEX_HPP -#include +#include #include namespace bw diff --git a/include/CoreLib/LogSystem/EntityLogContext.hpp b/include/CoreLib/LogSystem/EntityLogContext.hpp index a77ec8a5..d11e5fb8 100644 --- a/include/CoreLib/LogSystem/EntityLogContext.hpp +++ b/include/CoreLib/LogSystem/EntityLogContext.hpp @@ -9,13 +9,13 @@ #include #include -#include +#include namespace bw { struct EntityLogContext : MatchLogContext { - Ndk::EntityHandle entity; + entt::entity entity; }; } diff --git a/include/CoreLib/LogSystem/EntityLogger.hpp b/include/CoreLib/LogSystem/EntityLogger.hpp index 78fc27a6..c6dd2f60 100644 --- a/include/CoreLib/LogSystem/EntityLogger.hpp +++ b/include/CoreLib/LogSystem/EntityLogger.hpp @@ -10,25 +10,26 @@ #include #include #include +#include namespace bw { class BURGWAR_CORELIB_API EntityLogger : public LoggerProxy { public: - inline EntityLogger(Ndk::EntityHandle entity, const Logger& logParent); + inline EntityLogger(entt::entity entity, const Logger& logParent); EntityLogger(const EntityLogger&) = default; EntityLogger(EntityLogger&&) = default; ~EntityLogger() = default; void InitializeContext(LogContext& context) const override; - inline void UpdateEntity(Ndk::EntityHandle newEntity); + inline void UpdateEntity(entt::entity newEntity); private: void OverrideContent(const LogContext& context, std::string& content) const override; - Ndk::EntityHandle m_entity; + entt::entity m_entity; }; } diff --git a/include/CoreLib/LogSystem/EntityLogger.inl b/include/CoreLib/LogSystem/EntityLogger.inl index f6631eb3..a7e8a4ad 100644 --- a/include/CoreLib/LogSystem/EntityLogger.inl +++ b/include/CoreLib/LogSystem/EntityLogger.inl @@ -6,13 +6,13 @@ namespace bw { - inline EntityLogger::EntityLogger(Ndk::EntityHandle entity, const Logger& logParent) : + inline EntityLogger::EntityLogger(entt::entity entity, const Logger& logParent) : LoggerProxy(logParent), m_entity(std::move(entity)) { } - inline void EntityLogger::UpdateEntity(Ndk::EntityHandle newEntity) + inline void EntityLogger::UpdateEntity(entt::entity newEntity) { m_entity = newEntity; } diff --git a/include/CoreLib/LogSystem/LogContextPtr.hpp b/include/CoreLib/LogSystem/LogContextPtr.hpp index 48066d4f..b0d9213f 100644 --- a/include/CoreLib/LogSystem/LogContextPtr.hpp +++ b/include/CoreLib/LogSystem/LogContextPtr.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace bw { diff --git a/include/CoreLib/LogSystem/Logger.hpp b/include/CoreLib/LogSystem/Logger.hpp index 4dc4389c..5ceb78d5 100644 --- a/include/CoreLib/LogSystem/Logger.hpp +++ b/include/CoreLib/LogSystem/Logger.hpp @@ -12,9 +12,10 @@ #include #include #include -#include -#include +#include +#include #include +#include #include #include @@ -29,7 +30,7 @@ while (false) namespace bw { - class BurgApp; + class BurgAppComponent; class LogSink; class BURGWAR_CORELIB_API Logger : public AbstractLogger @@ -38,13 +39,13 @@ namespace bw friend class LoggerProxy; public: - inline Logger(BurgApp& app, LogSide logSide, std::size_t contextSize = sizeof(bw::LogContext)); - inline Logger(BurgApp& app, LogSide logSide, const AbstractLogger& logParent, std::size_t contextSize = sizeof(bw::LogContext)); + inline Logger(BurgAppComponent& app, LogSide logSide); + inline Logger(BurgAppComponent& app, LogSide logSide, const AbstractLogger& logParent); Logger(const Logger&) = delete; Logger(Logger&&) noexcept = default; ~Logger() = default; - template void LogFormat(const LogContext& context, Args&& ... args) const; + template void LogFormat(const LogContext& context, fmt::format_string fmt, Args&& ... args) const; void Log(const LogContext& context, std::string content) const override; void LogRaw(const LogContext& context, std::string_view content) const override; @@ -61,18 +62,17 @@ namespace bw Logger& operator=(Logger&&) = delete; protected: - template T* AllocateContext(Nz::MemoryPool& pool) const; + template T* AllocateContext() const; template LogContextPtr PushCustomContext() const; virtual void InitializeContext(LogContext& context) const; - virtual LogContext* NewContext(Nz::MemoryPool& pool) const; + virtual LogContext* NewContext() const; virtual void OverrideContent(const LogContext& context, std::string& content) const; private: void FreeContext(LogContext* context) const; - mutable Nz::MemoryPool m_contextPool; - BurgApp& m_app; + BurgAppComponent& m_app; LogLevel m_minimumLogLevel; Nz::MovablePtr m_logParent; std::vector> m_sinks; diff --git a/include/CoreLib/LogSystem/Logger.inl b/include/CoreLib/LogSystem/Logger.inl index 8b3947f8..c7f7020d 100644 --- a/include/CoreLib/LogSystem/Logger.inl +++ b/include/CoreLib/LogSystem/Logger.inl @@ -7,33 +7,32 @@ namespace bw { - inline Logger::Logger(BurgApp& app, LogSide logSide, std::size_t contextSize) : + inline Logger::Logger(BurgAppComponent& app, LogSide logSide) : AbstractLogger(logSide), - m_contextPool(static_cast(contextSize), 4), m_app(app), m_minimumLogLevel(LogLevel::Debug), m_logParent(nullptr) { } - inline Logger::Logger(BurgApp& app, LogSide logSide, const AbstractLogger& logParent, std::size_t contextSize) : - Logger(app, logSide, contextSize) + inline Logger::Logger(BurgAppComponent& app, LogSide logSide, const AbstractLogger& logParent) : + Logger(app, logSide) { m_logParent = &logParent; } template - void Logger::LogFormat(const LogContext& context, Args&&... args) const + void Logger::LogFormat(const LogContext& context, fmt::format_string fmt, Args&& ... args) const { - Log(context, fmt::format(std::forward(args)...)); + Log(context, fmt::format(fmt, std::forward(args)...)); } template - T* Logger::AllocateContext(Nz::MemoryPool& pool) const + T* Logger::AllocateContext() const { static_assert(std::is_base_of_v); - T* logContext = pool.New(); + T* logContext = new T; InitializeContext(*logContext); return logContext; @@ -42,12 +41,12 @@ namespace bw template LogContextPtr Logger::PushCustomContext() const { - return LogContextPtr(this, AllocateContext(m_contextPool)); + return LogContextPtr(this, AllocateContext()); } inline LogContextPtr Logger::PushContext() const { - return LogContextPtr(this, NewContext(m_contextPool)); + return LogContextPtr(this, NewContext()); } inline void Logger::RegisterSink(std::shared_ptr sinkPtr) diff --git a/include/CoreLib/LogSystem/LoggerProxy.hpp b/include/CoreLib/LogSystem/LoggerProxy.hpp index 1c5e4268..2e882e0a 100644 --- a/include/CoreLib/LogSystem/LoggerProxy.hpp +++ b/include/CoreLib/LogSystem/LoggerProxy.hpp @@ -22,7 +22,7 @@ namespace bw LoggerProxy(LoggerProxy&&) noexcept = default; ~LoggerProxy() = default; - template void LogFormat(const LogContext& context, Args&& ... args) const; + template void LogFormat(const LogContext& context, fmt::format_string fmt, Args&& ... args) const; void Log(const LogContext& context, std::string content) const override; void LogRaw(const LogContext& context, std::string_view content) const override; diff --git a/include/CoreLib/LogSystem/LoggerProxy.inl b/include/CoreLib/LogSystem/LoggerProxy.inl index 53a907ed..8fa645a2 100644 --- a/include/CoreLib/LogSystem/LoggerProxy.inl +++ b/include/CoreLib/LogSystem/LoggerProxy.inl @@ -14,9 +14,9 @@ namespace bw } template - void LoggerProxy::LogFormat(const LogContext& context, Args&&... args) const + void LoggerProxy::LogFormat(const LogContext& context, fmt::format_string fmt, Args&&... args) const { - Log(context, fmt::format(std::forward(args)...)); + Log(context, fmt::format(fmt, std::forward(args)...)); } inline LogContextPtr LoggerProxy::PushContext() const diff --git a/include/CoreLib/LogSystem/MatchLogger.hpp b/include/CoreLib/LogSystem/MatchLogger.hpp index 0e28e4a7..00116765 100644 --- a/include/CoreLib/LogSystem/MatchLogger.hpp +++ b/include/CoreLib/LogSystem/MatchLogger.hpp @@ -16,8 +16,8 @@ namespace bw class BURGWAR_CORELIB_API MatchLogger : public Logger { public: - inline MatchLogger(BurgApp& app, SharedMatch& sharedMatch, LogSide logSide, std::size_t contextSize = sizeof(bw::MatchLogContext)); - inline MatchLogger(BurgApp& app, SharedMatch& sharedMatch, LogSide logSide, const AbstractLogger& logParent, std::size_t contextSize = sizeof(bw::MatchLogContext)); + inline MatchLogger(BurgAppComponent& app, SharedMatch& sharedMatch, LogSide logSide); + inline MatchLogger(BurgAppComponent& app, SharedMatch& sharedMatch, LogSide logSide, const AbstractLogger& logParent); MatchLogger(const MatchLogger&) = delete; MatchLogger(MatchLogger&&) noexcept = default; ~MatchLogger() = default; @@ -26,7 +26,7 @@ namespace bw private: void InitializeContext(LogContext& context) const override; - LogContext* NewContext(Nz::MemoryPool& pool) const override; + LogContext* NewContext() const override; void OverrideContent(const LogContext& context, std::string& content) const override; SharedMatch& m_sharedMatch; diff --git a/include/CoreLib/LogSystem/MatchLogger.inl b/include/CoreLib/LogSystem/MatchLogger.inl index 242a1a6f..6e612eff 100644 --- a/include/CoreLib/LogSystem/MatchLogger.inl +++ b/include/CoreLib/LogSystem/MatchLogger.inl @@ -6,14 +6,14 @@ namespace bw { - inline MatchLogger::MatchLogger(BurgApp& app, SharedMatch& sharedMatch, LogSide logSide, std::size_t contextSize) : - Logger(app, logSide, contextSize), + inline MatchLogger::MatchLogger(BurgAppComponent& app, SharedMatch& sharedMatch, LogSide logSide) : + Logger(app, logSide), m_sharedMatch(sharedMatch) { } - inline MatchLogger::MatchLogger(BurgApp& app, SharedMatch& sharedMatch, LogSide logSide, const AbstractLogger& logParent, std::size_t contextSize) : - Logger(app, logSide, logParent, contextSize), + inline MatchLogger::MatchLogger(BurgAppComponent& app, SharedMatch& sharedMatch, LogSide logSide, const AbstractLogger& logParent) : + Logger(app, logSide, logParent), m_sharedMatch(sharedMatch) { } diff --git a/include/CoreLib/Map.hpp b/include/CoreLib/Map.hpp index 1e65ec1a..c1359dd9 100644 --- a/include/CoreLib/Map.hpp +++ b/include/CoreLib/Map.hpp @@ -123,7 +123,7 @@ namespace bw struct Layer { - Nz::Color backgroundColor = Nz::Color::Black; + Nz::Color backgroundColor = Nz::Color::Black(); Nz::Vector2f positionAlignment = Nz::Vector2f::Unit(); std::string name = "unnamed layer"; std::vector entities; @@ -140,17 +140,23 @@ namespace bw static nlohmann::json Serialize(const Map& map); static nlohmann::json SerializeEntity(const Entity& entity); - static Map Unserialize(const nlohmann::json& mapInfo); - static Entity UnserializeEntity(const nlohmann::json& entityInfo); + static Map Deserialize(const nlohmann::json& mapInfo); + static Entity DeserializeEntity(const nlohmann::json& entityInfo, Nz::UInt16 fileVersion); private: bool CheckEntityIndices() const; void LoadFromBinaryInternal(const std::filesystem::path& mapFile); void LoadFromDirectoryInternal(const std::filesystem::path& mapFolder); + void HandleVersionUpdate(Nz::UInt16 fileVersion); + void HandleVersionUpdate(Asset& asset, Nz::UInt16 fileVersion); + void HandleVersionUpdate(Entity& entity, Nz::UInt16 fileVersion); + void HandleVersionUpdate(Layer& layer, Nz::UInt16 fileVersion); + void HandleVersionUpdate(Script& script, Nz::UInt16 fileVersion); inline void RegisterEntity(EntityId uniqueId, LayerIndex layerIndex, std::size_t entityIndex); void Sanitize(); inline void UnregisterEntity(EntityId uniqueId); + std::vector m_assets; std::vector m_layers; std::vector