diff --git a/include/td/game/World.h b/include/td/game/World.h index 93ee19f..82edaf9 100644 --- a/include/td/game/World.h +++ b/include/td/game/World.h @@ -61,7 +61,7 @@ class World { TilePtr GetTilePtr(TileIndex index) const { if (index == 0) - return nullptr; + return TilePtr(nullptr); return m_TilePalette.at(index - 1); } diff --git a/include/td/game/WorldTypes.h b/include/td/game/WorldTypes.h index 4177225..60023a6 100644 --- a/include/td/game/WorldTypes.h +++ b/include/td/game/WorldTypes.h @@ -67,7 +67,7 @@ using TileFactory = sp::MessageFactory; class TileHandler : public sp::GenericHandler {}; -using TilePtr = std::shared_ptr>; +using TilePtr = sp::SerializableMessage; // typedef std::shared_ptr TilePtr; typedef std::vector ChunkPalette; diff --git a/include/td/protocol/command/Commands.h b/include/td/protocol/command/Commands.h index 77c9f1a..b9fae92 100644 --- a/include/td/protocol/command/Commands.h +++ b/include/td/protocol/command/Commands.h @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -15,6 +14,8 @@ #include #include +#include + namespace td { namespace protocol { @@ -58,9 +59,9 @@ using CommandDispatcher = sp::MessageDispatcher; using CommandFactory = sp::MessageFactory; -using LockStep = std::vector>; +using CommandPtr = sp::SerializableMessage; -using CommandPtr = std::unique_ptr>; +using LockStep = std::vector; } // namespace protocol } // namespace td diff --git a/include/td/protocol/packet/PacketData.h b/include/td/protocol/packet/PacketData.h index da5648d..656bb8d 100644 --- a/include/td/protocol/packet/PacketData.h +++ b/include/td/protocol/packet/PacketData.h @@ -74,7 +74,7 @@ struct BeginGame { struct LockSteps { std::uint16_t m_FirstFrameNumber; - Array m_LockSteps; + std::array m_LockSteps; }; struct WorldHeader { diff --git a/include/td/protocol/packet/PacketSerialize.h b/include/td/protocol/packet/PacketSerialize.h index 0f0b127..29c2331 100644 --- a/include/td/protocol/packet/PacketSerialize.h +++ b/include/td/protocol/packet/PacketSerialize.h @@ -40,8 +40,8 @@ namespace game { sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const TeamCastle& a_Castle); sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, TeamCastle& a_Castle); -sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const ChunkPtr& a_Chunk); -sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, ChunkPtr& a_Chunk); +sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Spawn& a_Spawn); +sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Spawn& a_Spawn); } // namespace game } // namespace td diff --git a/include/td/simulation/RealTimeSimulation.h b/include/td/simulation/RealTimeSimulation.h index 2fe4db2..e77f42b 100644 --- a/include/td/simulation/RealTimeSimulation.h +++ b/include/td/simulation/RealTimeSimulation.h @@ -28,7 +28,7 @@ class RealTimeSimulation { * \brief Replay constructor * \param a_StepTime in ms */ - RealTimeSimulation(game::World& a_World, const GameHistory& a_History, std::uint64_t a_StepTime); + RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime); /** * \brief Live update constructor (continuous game updates) diff --git a/src/main.cpp b/src/main.cpp index ab13d0d..2466406 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,10 +82,12 @@ td::sim::GameHistory GetCustomHistory() { td::sim::GameHistory gh(MAX_COUNT); - auto spawn = std::make_shared(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0); + auto spawn = td::protocol::CommandPtr( + std::make_shared(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0)); gh[0].push_back(spawn); - auto tower = std::make_shared(td::TowerType::Archer, 0, td::TowerCoords{77, 13}); + auto tower = td::protocol::CommandPtr( + std::make_shared(td::TowerType::Archer, 0, td::TowerCoords{77, 13})); gh[0].push_back(tower); return gh; @@ -116,9 +118,9 @@ int main(int argc, char** argv) { display.OnKeyDown.Connect([&simulation](SDL_Keycode key) { if (key == SDLK_A) { - auto spawn = - std::make_shared(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0); - td::Array steps{}; + auto spawn = td::protocol::CommandPtr( + std::make_shared(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0)); + std::array steps{}; steps[0].push_back(spawn); td::protocol::packets::LockStepsPacket packet{0, steps}; simulation.HandlePacket(packet); diff --git a/src/td/Types.cpp b/src/td/Types.cpp index d4c2fdf..25ce84f 100644 --- a/src/td/Types.cpp +++ b/src/td/Types.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace td { diff --git a/src/td/protocol/packet/ChunkSerialize.cpp b/src/td/protocol/packet/ChunkSerialize.cpp index b666424..28d20d7 100644 --- a/src/td/protocol/packet/ChunkSerialize.cpp +++ b/src/td/protocol/packet/ChunkSerialize.cpp @@ -3,17 +3,7 @@ namespace td { namespace game { -sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const ChunkPtr& a_Chunk) { - a_Buffer << a_Chunk->m_Palette; - a_Buffer << a_Chunk->m_Data; - return a_Buffer; -} -sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, ChunkPtr& a_Chunk) { - a_Chunk = std::make_shared(); - a_Buffer >> a_Chunk->m_Palette; - return a_Buffer >> a_Chunk->m_Data; -} } // namespace game } // namespace td \ No newline at end of file diff --git a/src/td/protocol/packet/PacketSerialize.cpp b/src/td/protocol/packet/PacketSerialize.cpp index 2ba507e..b119ca6 100644 --- a/src/td/protocol/packet/PacketSerialize.cpp +++ b/src/td/protocol/packet/PacketSerialize.cpp @@ -1,6 +1,8 @@ #include #include +#include + namespace td { namespace game { @@ -15,5 +17,17 @@ sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, TeamCastle& a_Castle) { return a_Buffer; } +sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Spawn& a_Spawn) { + return a_Buffer << a_Spawn.GetCenterX() << a_Spawn.GetCenterY(); +} + +sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Spawn& a_Spawn) { + float x, y; + a_Buffer >> x >> y; + a_Spawn.SetCenter({x, y}); + return a_Buffer; +} + + } // namespace game } // namespace td diff --git a/src/td/render/loader/WorldLoader.cpp b/src/td/render/loader/WorldLoader.cpp index fe1a7a5..fa478ce 100644 --- a/src/td/render/loader/WorldLoader.cpp +++ b/src/td/render/loader/WorldLoader.cpp @@ -27,7 +27,7 @@ GL::VertexArray LoadWorldModel(const td::game::World* world) { td::game::TileIndex tileIndex = chunk->GetTileIndex(tileNumber); td::game::TilePtr tile = world->GetTilePtr(tileIndex); - if (tile == nullptr) + if (!tile) continue; positions.insert( diff --git a/src/td/simulation/GameHistory.cpp b/src/td/simulation/GameHistory.cpp index ef8cce1..14ada01 100644 --- a/src/td/simulation/GameHistory.cpp +++ b/src/td/simulation/GameHistory.cpp @@ -33,7 +33,7 @@ void GameHistory::FromPacket(protocol::pdata::LockSteps&& a_Steps) { } protocol::packets::LockStepsPacket GameHistory::ToPacket(HistorySizeType a_StartIndex) { - Array steps; + std::array steps; for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) { steps[i] = GetLockStep(a_StartIndex + i); } diff --git a/src/td/simulation/RealTimeSimulation.cpp b/src/td/simulation/RealTimeSimulation.cpp index 26ec283..8696e38 100644 --- a/src/td/simulation/RealTimeSimulation.cpp +++ b/src/td/simulation/RealTimeSimulation.cpp @@ -12,7 +12,7 @@ std::uint64_t GetTime() { std::chrono::duration_cast(std::chrono::system_clock().now().time_since_epoch()).count()); } -RealTimeSimulation::RealTimeSimulation(game::World& a_World, const GameHistory& a_History, std::uint64_t a_StepTime) : +RealTimeSimulation::RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime) : m_StepTime(a_StepTime), m_World(a_World), m_CurrentTime(0), @@ -21,8 +21,8 @@ RealTimeSimulation::RealTimeSimulation(game::World& a_World, const GameHistory& m_LastSnapshot(std::make_shared()), m_LastValidStep(0) { m_History.reserve(a_History.size()); - for (const auto& lockstep : a_History) { - m_History.emplace_back(lockstep); + for (auto&& lockstep : a_History) { + m_History.emplace_back(std::move(lockstep)); } Step(); } diff --git a/test/tdmap.tdmap2 b/test/tdmap.tdmap2 index df65e86..5df803c 100644 Binary files a/test/tdmap.tdmap2 and b/test/tdmap.tdmap2 differ diff --git a/xmake.lua b/xmake.lua index 959efb7..de05652 100644 --- a/xmake.lua +++ b/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git") add_requires("imgui 1.92.0", {configs = {sdl3 = true, opengl3 = true}}) -add_requires("splib 2.1.0", "zlib") +add_requires("splib 2.2.0", "zlib") add_requires("libsdl3 3.2.16", "glew", "fpm", "enet6") set_languages("c++17")