begin serversimulation

This commit is contained in:
2025-08-03 18:20:21 +02:00
parent c0a560a16e
commit 731c742346
6 changed files with 58 additions and 25 deletions

View File

@@ -1,14 +1,14 @@
#include <iostream>
#include <td/protocol/packet/PacketSerialize.h>
#include <fstream>
#include <td/game/World.h>
#include <td/input/Display.h>
#include <td/protocol/packet/PacketSerialize.h>
#include <td/protocol/packet/Packets.h>
#include <td/render/renderer/EntityRenderer.h>
#include <td/render/renderer/TowerRenderer.h>
#include <td/render/renderer/WorldRenderer.h>
#include <td/simulation/RealTimeSimulation.h>
#include <td/simulation/ClientSimulation.h>
#include <sp/common/DataBuffer.h>
#include <sp/extensions/Compress.h>
@@ -59,8 +59,8 @@ td::game::World GetWorld() {
WorldApply wa(w);
td::protocol::PacketDispatcher d;
d.RegisterHandler(td::protocol::PacketID::WorldData, &wa);
d.RegisterHandler(td::protocol::PacketID::WorldHeader, &wa);
d.RegisterHandler(td::protocol::PacketID::WorldData, &wa);
d.Dispatch(*header);
d.Dispatch(*data);
@@ -83,7 +83,7 @@ td::sim::GameHistory GetCustomHistory() {
td::sim::GameHistory gh(MAX_COUNT);
auto spawn = td::protocol::CommandPtr(
std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0));
std::make_shared<td::protocol::commands::SpawnTroopCommand>(td::EntityType::Zombie, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0));
gh[0].push_back(spawn);
auto tower = td::protocol::CommandPtr(
@@ -114,17 +114,17 @@ int main(int argc, char** argv) {
cam.SetCamPos({77, 7, 13});
cam.UpdatePerspective(display.GetAspectRatio());
td::sim::RealTimeSimulation simulation(w, 50);
td::sim::ClientSimulation simulation(w, 50);
display.OnKeyDown.Connect([&simulation](SDL_Keycode key) {
static int counter = 0;
if (key == SDLK_A) {
auto spawn = td::protocol::CommandPtr(
std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0));
std::make_shared<td::protocol::commands::SpawnTroopCommand>(td::EntityType::Zombie, 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{counter * LOCKSTEP_BUFFER_SIZE * 3, steps};
simulation.HandlePacket(packet);
simulation.Handle(packet);
counter++;
}
});