fork/slippc
git clone https://git.julia.blue/fork/slippc
81596bb
0.4.0
1#ifndef PARSER_H_ 2#define PARSER_H_ 3 4#include <iostream> 5#include <fstream> 6#include <sstream> 7#include <regex> 8 9#include "util.h" 10#include "replay.h" 11#include "analyzer.h" 12 13// Replay File (.slp) Spec: https://github.com/project-slippi/project-slippi/wiki/Replay-File-Spec 14 15const std ::string PARSER_VERSION = "0.4.0" ; 16 17namespace slip { 18 19class Parser { 20private : 21int _debug ;//Current debug level 22SlippiReplay _replay ;//Internal struct for replay being parsed 23uint16_t _payload_sizes [256 ]= {0 };//Size of payload for each event 24std ::string _slippi_version ;//String representation of the Slippi version of the replay 25uint8_t _slippi_maj = 0 ;//Major version number of replay being parsed 26uint8_t _slippi_min = 0 ;//Minor version number of replay being parsed 27uint8_t _slippi_rev = 0 ;//Revision number of replay being parsed 28int32_t _max_frames = 0 ;//Maximum number of frames that there will be in the replay file 29 30char * _rb = nullptr ;//Read buffer 31unsigned _bp ;//Current position in buffer 32uint32_t _length_raw ;//Remaining length of raw payload 33uint32_t _length_raw_start ;//Total length of raw payload 34uint32_t _file_size ;//Total size of the replay file on disk 35bool _parse ();//Internal main parsing funnction 36bool _parseHeader (); 37bool _parseEventDescriptions (); 38bool _parseEvents (); 39bool _parseGameStart (); 40bool _parsePreFrame (); 41bool _parsePostFrame (); 42bool _parseGameEnd (); 43bool _parseMetadata (); 44void _cleanup ();//Cleanup replay data 45public : 46Parser (int debug_level ); //Instantiate the parser (possibly in debug mode) 47~ Parser (); //Destroy the parser 48bool load ( const char * replayfilename); //Load a replay file 49Analysis * analyze (); //Analyze the loaded replay file 50std :: string asJson ( bool delta); //Convert the parsed replay structure to a JSON 51void save ( const char * outfilename, bool delta); //Save a replay file 52 53//Estimate the maximum number of frames stored in the file 54// -> Assumes only two people are alive for the whole match / one ice climber 55inline int32_t getMaxNumFrames () { 56//Get the base size for the file 57unsigned base_size = 0 ; 58base_size += 1 + _payload_sizes[Event:: EV_PAYLOADS ]; //One meta event 59base_size += 1 + _payload_sizes[Event:: GAME_START ]; //One start event 60base_size += 1 + _payload_sizes[Event:: GAME_END ]; //One end event 61 62unsigned num_players = 2 ; 63 64unsigned frame_size = num_players * ( 65_payload_sizes[Event:: PRE_FRAME ] + 661 + 67_payload_sizes[Event:: POST_FRAME ] + 681 69); 70 71if (_length_raw_start < base_size) { 72return 0 ; //There's a problem 73} 74 75// std::cerr << "((" << _length_raw_start << "-" << base_size << ")/" << frame_size << ")-123" << std::endl; 76int32_t maxframes = ((_length_raw_start - base_size)/frame_size) + LOAD_FRAME ; 77return maxframes + 1 ; //TODO: the above doesn't compute an exact number sometimes and we need the +1; figure out why 78} 79}; 80 81} 82 83#endif /* PARSER_H_ */