From 2ed3320b841aeb95ac0ed141f631a167a5615e2c Mon Sep 17 00:00:00 2001 From: Jordan Cristiano Date: Wed, 27 May 2015 22:58:19 -0400 Subject: [PATCH] Partial implementation of demo file writer --- demboyz/demowriter.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/demboyz/demowriter.cpp b/demboyz/demowriter.cpp index d4f00dd..3084ea1 100644 --- a/demboyz/demowriter.cpp +++ b/demboyz/demowriter.cpp @@ -1,6 +1,12 @@ #include "idemowriter.h" +#include "demotypes.h" +#include "demofile.h" +#include "netmessages/nethandlers.h" +#include "netmessages/netcontants.h" +#include "bitbuf.h" #include +#include class DemoWriter: public IDemoWriter { @@ -14,6 +20,11 @@ public: virtual void EndCommandPacket() override final; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) override final; + +private: + DemoFileWriter m_writer; + bf_write m_cmdPacketBuf; + std::unique_ptr m_packetBuffer; }; IDemoWriter* IDemoWriter::CreateDemoWriter(void* outputFp) @@ -21,12 +32,16 @@ IDemoWriter* IDemoWriter::CreateDemoWriter(void* outputFp) return new DemoWriter(reinterpret_cast(outputFp)); } -DemoWriter::DemoWriter(FILE* outputFp) +DemoWriter::DemoWriter(FILE* outputFp): + m_writer(outputFp), + m_packetBuffer(new uint8_t[NET_MAX_PAYLOAD]) { + m_cmdPacketBuf.StartWriting(m_packetBuffer.get(), NET_MAX_PAYLOAD); } void DemoWriter::StartWriting(demoheader_t& header) { + m_writer.WriteDemoHeader(header); } void DemoWriter::EndWriting() @@ -35,12 +50,21 @@ void DemoWriter::EndWriting() void DemoWriter::StartCommandPacket(CommandPacket& packet) { + m_writer.WriteCmdHeader(packet.cmd, packet.tick); + if (packet.cmd == dem_packet || packet.cmd == dem_signon) + { + m_writer.WriteCmdInfo(*packet.cmdInfo); + m_writer.WriteSequenceInfo(packet.sequenceInfo1, packet.sequenceInfo2); + } + m_cmdPacketBuf.Reset(); } void DemoWriter::EndCommandPacket() { + m_writer.WriteRawData(m_cmdPacketBuf.GetBasePointer(), m_cmdPacketBuf.GetNumBytesWritten()); } void DemoWriter::WriteNetPacket(NetPacket& packet, SourceGameContext& context) { + NetHandlers::NetMsg_BitWrite(packet.type, m_cmdPacketBuf, context, packet.data); }