Compare commits
2 Commits
fa663d0481
...
51dc910359
| Author | SHA1 | Date | |
|---|---|---|---|
|
51dc910359
|
|||
|
ced20ca991
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ using TileFactory = sp::MessageFactory<Tile, AllTiles>;
|
||||
|
||||
class TileHandler : public sp::GenericHandler<AllTiles> {};
|
||||
|
||||
using TilePtr = std::shared_ptr<sp::SerializableMessage<TileFactory>>;
|
||||
using TilePtr = sp::SerializableMessage<TileFactory>;
|
||||
|
||||
// typedef std::shared_ptr<Tile> TilePtr;
|
||||
typedef std::vector<std::uint16_t> ChunkPalette;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include <sp/common/GenericHandler.h>
|
||||
#include <sp/io/SerializableMessage.h>
|
||||
#include <sp/protocol/ConcreteMessage.h>
|
||||
#include <sp/protocol/MessageDispatcher.h>
|
||||
#include <sp/protocol/MessageFactory.h>
|
||||
@@ -15,6 +14,8 @@
|
||||
#include <td/common/NonCopyable.h>
|
||||
#include <td/protocol/command/CommandData.h>
|
||||
|
||||
#include <sp/io/SerializableMessage.h>
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
|
||||
@@ -58,9 +59,9 @@ using CommandDispatcher = sp::MessageDispatcher<CommandBase>;
|
||||
|
||||
using CommandFactory = sp::MessageFactory<CommandBase, AllCommands>;
|
||||
|
||||
using LockStep = std::vector<std::shared_ptr<CommandBase>>;
|
||||
using CommandPtr = sp::SerializableMessage<CommandFactory>;
|
||||
|
||||
using CommandPtr = std::unique_ptr<sp::SerializableMessage<CommandFactory>>;
|
||||
using LockStep = std::vector<CommandPtr>;
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace td
|
||||
|
||||
@@ -74,7 +74,7 @@ struct BeginGame {
|
||||
|
||||
struct LockSteps {
|
||||
std::uint16_t m_FirstFrameNumber;
|
||||
Array<LockStep, LOCKSTEP_BUFFER_SIZE> m_LockSteps;
|
||||
std::array<LockStep, LOCKSTEP_BUFFER_SIZE> m_LockSteps;
|
||||
};
|
||||
|
||||
struct WorldHeader {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
20
src/main.cpp
20
src/main.cpp
@@ -82,10 +82,12 @@ td::sim::GameHistory GetCustomHistory() {
|
||||
|
||||
td::sim::GameHistory gh(MAX_COUNT);
|
||||
|
||||
auto spawn = std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0);
|
||||
auto spawn = td::protocol::CommandPtr(
|
||||
std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0));
|
||||
gh[0].push_back(spawn);
|
||||
|
||||
auto tower = std::make_shared<td::protocol::commands::PlaceTowerCommand>(td::TowerType::Archer, 0, td::TowerCoords{77, 13});
|
||||
auto tower = td::protocol::CommandPtr(
|
||||
std::make_shared<td::protocol::commands::PlaceTowerCommand>(td::TowerType::Archer, 0, td::TowerCoords{77, 13}));
|
||||
gh[0].push_back(tower);
|
||||
|
||||
return gh;
|
||||
@@ -109,19 +111,21 @@ int main(int argc, char** argv) {
|
||||
renderer.AddRenderer<td::render::EntityRenderer>(cam, w);
|
||||
renderer.AddRenderer<td::render::TowerRenderer>(cam, w);
|
||||
|
||||
cam.SetCamPos({77, 5, 13});
|
||||
cam.SetCamPos({77, 10, 13});
|
||||
cam.UpdatePerspective(display.GetAspectRatio());
|
||||
|
||||
td::sim::RealTimeSimulation simulation(w, 500);
|
||||
td::sim::RealTimeSimulation simulation(w, 50);
|
||||
|
||||
display.OnKeyDown.Connect([&simulation](SDL_Keycode key) {
|
||||
static int counter = 0;
|
||||
if (key == SDLK_A) {
|
||||
auto spawn =
|
||||
std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0);
|
||||
td::Array<td::protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps{};
|
||||
auto spawn = td::protocol::CommandPtr(
|
||||
std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0));
|
||||
std::array<td::protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps{};
|
||||
steps[0].push_back(spawn);
|
||||
td::protocol::packets::LockStepsPacket packet{0, steps};
|
||||
td::protocol::packets::LockStepsPacket packet{counter * LOCKSTEP_BUFFER_SIZE * 3, steps};
|
||||
simulation.HandlePacket(packet);
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <sp/common/DataBuffer.h>
|
||||
#include <sp/common/ByteSwapping.h>
|
||||
#include <sp/common/DataBufferOperators.h>
|
||||
|
||||
namespace td {
|
||||
|
||||
|
||||
@@ -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<td::game::Chunk>();
|
||||
a_Buffer >> a_Chunk->m_Palette;
|
||||
return a_Buffer >> a_Chunk->m_Data;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <td/protocol/packet/PacketData.h>
|
||||
#include <td/protocol/packet/PacketSerialize.h>
|
||||
|
||||
#include <sp/common/DataBufferOperators.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -33,7 +33,7 @@ void GameHistory::FromPacket(protocol::pdata::LockSteps&& a_Steps) {
|
||||
}
|
||||
|
||||
protocol::packets::LockStepsPacket GameHistory::ToPacket(HistorySizeType a_StartIndex) {
|
||||
Array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps;
|
||||
std::array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> steps;
|
||||
for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) {
|
||||
steps[i] = GetLockStep(a_StartIndex + i);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ std::uint64_t GetTime() {
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(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<WorldSnapshot>()),
|
||||
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();
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user