migrating save files

This commit is contained in:
2025-07-31 13:48:26 +02:00
parent 2b8447766a
commit 02d872c49b
14 changed files with 249 additions and 176 deletions

View File

@@ -9,11 +9,15 @@
#include <td/protocol/packet/Packets.h>
#include <td/render/renderer/EntityRenderer.h>
#include <td/render/renderer/WorldRenderer.h>
#include <td/render/renderer/TowerRenderer.h>
#include <td/render/renderer/WorldRenderer.h>
#include <td/simulation/RealTimeSimulation.h>
#include <sp/io/MessageStream.h>
#include <sp/io/StdIo.h>
#include <fstream>
class WorldApply : public td::protocol::PacketHandler {
private:
td::game::World& m_World;
@@ -32,18 +36,15 @@ class WorldApply : public td::protocol::PacketHandler {
};
td::game::World GetWorld() {
sp::DataBuffer buffer;
buffer.ReadFile("test/tdmap.tdmap2");
auto comp = std::make_shared<sp::ZlibCompress>();
sp::DataBuffer buffer1 = sp::zlib::Decompress(buffer, 84);
buffer.SetReadOffset(buffer.GetReadOffset() + 83);
sp::DataBuffer buffer2 = sp::zlib::Decompress(buffer, 511);
std::ifstream fStream("test/tdmap.tdmap2");
auto out = std::make_shared<sp::StdInput>(fStream);
td::protocol::packets::WorldHeaderPacket header;
header.Read(buffer1);
sp::MessageStream<td::protocol::PacketFactory> stream(std::move(out), std::move(comp));
td::protocol::packets::WorldDataPacket data;
data.Read(buffer2);
auto header = stream.ReadMessage();
auto data = stream.ReadMessage();
td::game::World w;
WorldApply wa(w);
@@ -52,12 +53,24 @@ td::game::World GetWorld() {
d.RegisterHandler(td::protocol::PacketID::WorldData, &wa);
d.RegisterHandler(td::protocol::PacketID::WorldHeader, &wa);
d.Dispatch(header);
d.Dispatch(data);
d.Dispatch(*header);
d.Dispatch(*data);
return w;
}
void Save(td::protocol::packets::WorldHeaderPacket header, td::protocol::packets::WorldDataPacket data) {
auto comp = std::make_shared<sp::ZlibCompress>();
std::ofstream fStream("test/tdmap.tdmap2");
auto out = std::make_shared<sp::StdOuput>(fStream);
sp::MessageStream<td::protocol::PacketFactory> stream(std::move(out), std::move(comp));
stream.WriteMessage(header);
stream.WriteMessage(data);
}
void FastForward(td::game::World& a_World, const td::sim::GameHistory& a_LockSteps) {
@@ -81,6 +94,7 @@ td::sim::GameHistory GetCustomHistory() {
return gh;
}
int main(int argc, char** argv) {
td::game::World w = GetWorld();
@@ -89,9 +103,7 @@ int main(int argc, char** argv) {
td::render::Camera cam;
display.OnAspectRatioChange.Connect([&cam](float a_AspectRatio){
cam.UpdatePerspective(a_AspectRatio);
});
display.OnAspectRatioChange.Connect([&cam](float a_AspectRatio) { cam.UpdatePerspective(a_AspectRatio); });
td::sim::GameHistory gh = GetCustomHistory();
@@ -105,9 +117,10 @@ int main(int argc, char** argv) {
td::sim::RealTimeSimulation simulation(w, 500);
display.OnKeyDown.Connect([&simulation](SDL_Keycode key){
display.OnKeyDown.Connect([&simulation](SDL_Keycode key) {
if (key == SDLK_A) {
auto spawn = std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0);
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{};
steps[0].push_back(spawn);
td::protocol::packets::LockStepsPacket packet{0, steps};