Added packet parsing logic and assertions for frame and tick count
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
|  | ||||
| #include "demofile.h" | ||||
| #include <assert.h> | ||||
| #include <memory> | ||||
|  | ||||
| int main(const int argc, const char* argv[]) | ||||
| { | ||||
| @@ -19,9 +20,38 @@ int main(const int argc, const char* argv[]) | ||||
|  | ||||
|     unsigned char cmd; | ||||
|     int32 tick; | ||||
|     int32 sequenceInfo1; | ||||
|     int32 sequenceInfo2; | ||||
|     democmdinfo_t cmdInfo; | ||||
|     std::string packetBuf; | ||||
|     demoFile.ReadCmdHeader(cmd, tick); | ||||
|  | ||||
|     assert(cmd == dem_synctick && tick == 0); | ||||
|      | ||||
|     const int numFrames = demoHeader->playback_frames; | ||||
|     const int numTicks = demoHeader->playback_ticks; | ||||
|     for (int i = 0; i <= numFrames; ++i) | ||||
|     { | ||||
|         demoFile.ReadCmdHeader(cmd, tick); | ||||
|         printf("tick: %i\n", tick); | ||||
|         switch (cmd) | ||||
|         { | ||||
|             case dem_packet: | ||||
|                 demoFile.ReadCmdInfo(cmdInfo); | ||||
|                 demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2); | ||||
|                 demoFile.ReadRawData(packetBuf); | ||||
|                 break; | ||||
|             case dem_stop: | ||||
|                 assert(i == numFrames && tick == numTicks); | ||||
|                 break; | ||||
|             case dem_synctick: | ||||
|             case dem_consolecmd: | ||||
|             case dem_usercmd: | ||||
|             case dem_datatables: | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     demoFile.Close(); | ||||
|  | ||||
|   | ||||
| @@ -124,6 +124,32 @@ int32 CDemoFile::ReadRawData( char *buffer, int32 length ) | ||||
|     return size; | ||||
| } | ||||
|  | ||||
| bool CDemoFile::ReadRawData(std::string& buf) | ||||
| { | ||||
|     if (!m_fileBuffer.size()) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     // read length of data block | ||||
|     int32 size = *(int32 *)(&m_fileBuffer[m_fileBufferPos]); | ||||
|     m_fileBufferPos += sizeof(int32); | ||||
|  | ||||
|     if (size < 0) | ||||
|     { | ||||
|         fprintf(stderr, "CDemoFile::ReadRawData: invalid size (%i).\n", size); | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     buf.resize(size); | ||||
|  | ||||
|     // read data into buffer | ||||
|     memcpy(&buf[0], &m_fileBuffer[m_fileBufferPos], size); | ||||
|     m_fileBufferPos += size; | ||||
|  | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool CDemoFile::Open( const char *name ) | ||||
| { | ||||
|     Close(); | ||||
|   | ||||
| @@ -229,6 +229,8 @@ public: | ||||
|  | ||||
|     int32   ReadRawData( char *buffer, int32 length ); | ||||
|  | ||||
|     bool    ReadRawData(std::string& buf); | ||||
|  | ||||
|     void    ReadSequenceInfo( int32 &nSeqNrIn, int32 &nSeqNrOutAck ); | ||||
|  | ||||
|     void    ReadCmdInfo( democmdinfo_t& info ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user