wip event parsing

This commit is contained in:
Jordan Cristiano 2015-04-30 16:03:22 -04:00
parent 9bb4aa46e8
commit 5fc4c59245

View File

@ -1,17 +1,61 @@
#include "demofile.h"
#include "demofilebitbuf.h"
#include <assert.h>
#include <memory>
#include <vector>
#include <fstream>
std::vector<std::string> eventNames;
void ParseGameEvent(const std::string& eventBuf)
{
CBitRead bitBuf(eventBuf.data(), eventBuf.size());
uint32 eventId = bitBuf.ReadUBitLong(9);
printf("%s\n", eventNames[eventId-1].c_str());
}
void ParsePacket(const std::string& packetBuf)
{
auto data = packetBuf.data();
CBitRead bitBuf(packetBuf.data(), packetBuf.size());
uint32 typeId = bitBuf.ReadUBitLong(5);
printf("%i\n", typeId);
if (typeId != 25)
{
return;
}
uint32 length = bitBuf.ReadUBitLong(11);
int numBytes = (length / 8) + (length % 8 > 0);
std::string subpacket;
subpacket.resize(numBytes);
bitBuf.ReadBits(&subpacket[0], length);
ParseGameEvent(subpacket);
}
void ParseEventNames(const char* eventfile, std::vector<std::string>& eventNames)
{
using namespace std;
ifstream eventStream(eventfile);
if (eventStream)
{
move(istream_iterator<string>(eventStream), istream_iterator<string>(), back_inserter(eventNames));
}
}
int main(const int argc, const char* argv[])
{
if (argc < 2)
if (argc < 3)
{
return -1;
}
ParseEventNames(argv[1], eventNames);
CDemoFile demoFile;
if (!demoFile.Open(argv[1]))
if (!demoFile.Open(argv[2]))
{
return -1;
}
@ -33,13 +77,15 @@ int main(const int argc, const char* argv[])
for (int i = 0; i <= numFrames; ++i)
{
demoFile.ReadCmdHeader(cmd, tick);
printf("tick: %i\n", tick);
//printf("tick: %i\n", tick);
switch (cmd)
{
case dem_packet:
demoFile.ReadCmdInfo(cmdInfo);
demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2);
assert(sequenceInfo1 == sequenceInfo2);
demoFile.ReadRawData(packetBuf);
ParsePacket(packetBuf);
break;
case dem_stop:
assert(i == numFrames && tick == numTicks);