bool Replay::Load(std::istream & instream, std::ostream & error_output) { Version stream_version; stream_version.Load(instream); if (!(stream_version == version_info)) { error_output << "Stream version " << stream_version.format_version << "/" << stream_version.inputs_supported << "/" << stream_version.framerate << " does not match expected version " << version_info.format_version << "/" << version_info.inputs_supported << "/" << version_info.framerate << std::endl; return false; } joeserialize::BinaryInputSerializer serialize_input(instream); if (!Serialize(serialize_input)) { error_output << "Error loading replay." << std::endl; return false; } return true; }
void PERFORMANCE_TESTING::ResetCar() { std::stringstream statestream(carstate); joeserialize::BinaryInputSerializer serialize_input(statestream); car.Serialize(serialize_input); car.dynamics.SetPosition(btVector3(0, 0, 0)); car.dynamics.SetTCS(true); car.dynamics.SetABS(true); car.SetAutoShift(true); car.SetAutoClutch(true); }
void PERFORMANCE_TESTING::ResetCar() { std::stringstream statestream(carstate); joeserialize::BinaryInputSerializer serialize_input(statestream); car.Serialize(serialize_input); car.SetTCS(true); car.SetABS(true); car.SetAutoShift(true); car.SetAutoClutch(true); car.ShiftGear(1); car.SetBrake(1); }
void Replay::CarState::ProcessPlayStateFrame(const StateFrame & frame, CarDynamics & car) { // process input snapshot for (unsigned i = 0; i < inputbuffer.size() && i < frame.GetInputSnapshot().size(); i++) { inputbuffer[i] = frame.GetInputSnapshot()[i]; } // process binary car state std::istringstream statestream(frame.GetBinaryStateData()); joeserialize::BinaryInputSerializer serialize_input(statestream); car.Serialize(serialize_input); }
void REPLAY::CARSTATE::ProcessPlayStateFrame(const STATEFRAME & frame, CAR & car) { // process input snapshot for (unsigned i = 0; i < inputbuffer.size() && i < frame.GetInputSnapshot().size(); i++) { inputbuffer[i] = frame.GetInputSnapshot()[i]; } // process binary car state std::stringstream statestream(frame.GetBinaryStateData()); joeserialize::BinaryInputSerializer serialize_input(statestream); car.Serialize(serialize_input); }
void Replay::Version::Load(std::istream & instream) { // read the file format version data manually const unsigned bufsize = format_version.length(); char * version_buf = new char[bufsize+1]; instream.read(version_buf, bufsize); version_buf[bufsize] = '\0'; format_version = version_buf; delete [] version_buf; // read the rest of the versioning info joeserialize::BinaryInputSerializer serialize_input(instream); Serialize(serialize_input); }
void PerformanceTesting::ResetCar() { std::istringstream statestream(carstate); joeserialize::BinaryInputSerializer serialize_input(statestream); car.Serialize(serialize_input); car.SetAutoShift(true); car.SetAutoClutch(true); car.SetTCS(true); car.SetABS(true); carinput.clear(); carinput.resize(CarInput::INVALID, 0.0f); carinput[CarInput::THROTTLE] = 1.0f; carinput[CarInput::BRAKE] = 1.0f; }
bool REPLAY::Load(std::istream & instream) { //peek to ensure we're not at the EOF instream.peek(); if (instream.eof()) return false; std::vector <INPUTFRAME> newinputframes; std::vector <STATEFRAME> newstateframes; joeserialize::BinaryInputSerializer serialize_input(instream); //the convention is that input frames come first, then state frames. joeserialize::Serializer & s = serialize_input; s.Serialize("inputframes", newinputframes); s.Serialize("stateframes", newstateframes); //append the frames to the list inputframes.insert(inputframes.end(), newinputframes.begin(), newinputframes.end()); stateframes.insert(stateframes.end(), newstateframes.begin(), newstateframes.end()); return true; }
int main( int argc, char *argv[] ) { /** Retrieve the program's name */ name = condor_basename ( argv[0] ); if ( !name ) { name = argv[0]; } /** Parse the command line and populate the global state */ parse_command_line ( argc, argv ); /** Grab the user's input */ serialize_input (); if ( ad ) { wake_machine (); } return 0; }
int main (int argc, char *argv[]) { char buffer[10000]; token tokens[500]; int t; //total number of tokens int i; //general use counter int res; FILE *fp; if (argc < 2) { //check if the number of arguments is correct printf("Usage: %s <input_file> -o <output_file>\n", argv[0]); return 1; } else if ((fp = fopen(argv[1], "r")) == NULL) { //try to open the input file printf("%s\n", strerror(errno)); return 2; } else { /*Phase 0: Put instuctions from the input file to the buffer serialized*/ res = serialize_input(buffer, fp); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { printf("Phase 0: Put instuctions from the input file to the buffer serialized:\n%s\n\n", buffer); } close(fp); if (res == 0) { puts("Empty input file."); return 3; } } /*Phase 1: Parse the code*/ validate_tokens(buffer); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { printf("Phase 1: Remove lines with invalid tokens:\n%s\n\n", buffer); } /*Phase 2: Extract the tokens*/ t = extract_tokens(buffer, tokens); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { puts("Phase 2: Extract the tokens:"); print_tokens(tokens, t); putchar('\n'); } /*Phase 3: Do syntax analysis on the tokens*/ t = analize_tokens(tokens, t); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { puts("Phase 3: Do syntax analysis on the tokens:"); print_tokens(tokens, t); putchar('\n'); } /*Phase 4: Do optimization on the tokens*/ t = optimize_tokens(tokens, t); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { puts("Phase 4: Do optimization on the tokens:"); print_tokens(tokens, t); putchar('\n'); } /*Phase 5: Do code generation based on the tokens*/ generate_code(buffer, tokens, t); /*If is on DEBUG_MODE print debuggin info*/ if (DEBUG_MODE) { printf("Phase 5: Do code generation based on the tokens:\n%s\n\n", buffer); } /*Print errors buffer*/ if (error_cnt != 0) { puts(error_buffer); } else { puts("No Errors"); } /*Final Phase: Save the code in a file*/ if (argc == 4 && strcmp(argv[2], "-o") == 0) { //check if user provided output file name save_code(buffer, argv[3]); } else { save_code(buffer, "out.c"); } return 0; }