void Replay::CarState::RecordFrame(const std::vector <float> & inputs, CarDynamics & car) { assert(inputbuffer.size() == CarInput::INVALID); // record inputs, delta encoding InputFrame newinputframe(frame); for (unsigned i = 0; i < CarInput::INVALID; i++) { if (inputs[i] != inputbuffer[i]) { inputbuffer[i] = inputs[i]; newinputframe.AddInput(i, inputs[i]); } } if (newinputframe.GetNumInputs() > 0) inputframes.push_back(newinputframe); // record every 30th state, input frame if (frame % 30 == 0) { std::ostringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); car.Serialize(serialize_output); stateframes.push_back(StateFrame(frame)); stateframes.back().SetBinaryStateData(statestream.str()); stateframes.back().SetInputSnapshot(inputs); } frame++; }
void PerformanceTesting::Test( const std::string & cardir, const std::string & carname, ContentManager & content, std::ostream & info_output, std::ostream & error_output) { info_output << "Beginning car performance test on " << carname << std::endl; // init track assert(!track); assert(!plane); btVector3 planeNormal(0, 0, 1); btScalar planeConstant = 0; plane = new btStaticPlaneShape(planeNormal, planeConstant); plane->setUserPointer(static_cast<void*>(&surface)); track = new btCollisionObject(); track->setCollisionShape(plane); track->setActivationState(DISABLE_SIMULATION); track->setUserPointer(static_cast<void*>(&surface)); world.addCollisionObject(track); //load the car dynamics std::tr1::shared_ptr<PTree> cfg; content.load(cfg, cardir, carname + ".car"); if (!cfg->size()) { return; } // position is the center of a 2 x 4 x 1 meter box on track surface btVector3 pos(0.0, -2.0, 0.5); btQuaternion rot = btQuaternion::getIdentity(); const std::string tire = ""; const bool damage = false; if (!car.Load(*cfg, cardir, tire, pos, rot, damage, world, content, error_output)) { return; } info_output << "Car dynamics loaded" << std::endl; info_output << carname << " Summary:\n" << "Mass (kg) including driver and fuel: " << 1 / car.GetInvMass() << "\n" << "Center of mass (m): " << car.GetCenterOfMass() << std::endl; std::ostringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); if (!car.Serialize(serialize_output)) { error_output << "Serialization error" << std::endl; } //else info_output << "Car state: " << statestream.str(); carstate = statestream.str(); TestMaxSpeed(info_output, error_output); TestStoppingDistance(false, info_output, error_output); TestStoppingDistance(true, info_output, error_output); info_output << "Car performance test complete." << std::endl; }
void REPLAY::CARSTATE::RecordFrame(const std::vector <float> & inputs, CAR & car) { assert(inputbuffer.size() == CARINPUT::GAME_ONLY_INPUTS_START_HERE); // record inputs, delta encoding INPUTFRAME newinputframe(frame); for (unsigned i = 0; i < CARINPUT::GAME_ONLY_INPUTS_START_HERE; i++) { if (inputs[i] != inputbuffer[i]) { inputbuffer[i] = inputs[i]; newinputframe.AddInput(i, inputs[i]); } } if (newinputframe.GetNumInputs() > 0) inputframes.push_back(newinputframe); // record every 30th state, input frame if (frame % 30 == 0) { std::stringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); car.Serialize(serialize_output); stateframes.push_back(STATEFRAME(frame)); stateframes.back().SetBinaryStateData(statestream.str()); stateframes.back().SetInputSnapshot(inputs); } frame++; }
void REPLAY::SaveHeader(std::ostream & outstream) { //write the file format version data manually. if the serialization functions were used, a variable length string would be written instead, which isn't exactly what we want version_info.Save(outstream); joeserialize::BinaryOutputSerializer serialize_output(outstream); Serialize(serialize_output); }
void REPLAY::VERSION::Save(std::ostream & outstream) { //write the file format version data manually. if the serialization functions were used, a variable length string would be written instead, which isn't exactly what we want outstream.write(format_version.data(), format_version.length()); //write the rest of the versioning info joeserialize::BinaryOutputSerializer serialize_output(outstream); Serialize(serialize_output); }
void REPLAY::Save(std::ostream & outstream) { joeserialize::BinaryOutputSerializer serialize_output(outstream); //the convention is that input frames come first, then state frames. joeserialize::Serializer & s = serialize_output; s.Serialize("inputframes", inputframes); s.Serialize("stateframes", stateframes); inputframes.clear(); stateframes.clear(); }
void PERFORMANCE_TESTING::Test( const std::string & carpath, const std::string & carname, const std::string & partspath, std::ostream & info_output, std::ostream & error_output) { info_output << "Beginning car performance test on " << carname << std::endl; const std::string carfile = carpath+"/"+carname+".car"; //load the car dynamics PTree cfg; file_open_basic fopen(carpath, partspath); if (!read_ini(carname+".car", fopen, cfg)) { error_output << "Error loading car configuration file: " << carfile << std::endl; return; } btVector3 size(0, 0, 0), center(0, 0, 0), pos(0, 0, 0); // collision shape from wheel data btQuaternion rot = btQuaternion::getIdentity(); bool damage = false; if (!car.dynamics.Load(cfg, size, center, pos, rot, damage, world, error_output)) { error_output << "Error during car dynamics load: " << carfile << std::endl; return; } info_output << "Car dynamics loaded" << std::endl; info_output << carname << " Summary:\n" << "Mass (kg) including driver and fuel: " << 1/car.GetInvMass() << "\n" << "Center of mass (m): " << car.GetCenterOfMassPosition() << std::endl; std::stringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); if (!car.Serialize(serialize_output)) { error_output << "Serialization error" << std::endl; } //else info_output << "Car state: " << statestream.str(); carstate = statestream.str(); // fixme info_output << "Car performance test broken - exiting." << std::endl; return; TestMaxSpeed(info_output, error_output); TestStoppingDistance(false, info_output, error_output); TestStoppingDistance(true, info_output, error_output); info_output << "Car performance test complete." << std::endl; }
void PERFORMANCE_TESTING::Test( const std::string & cardir, const std::string & carname, ContentManager & content, std::ostream & info_output, std::ostream & error_output) { info_output << "Beginning car performance test on " << carname << std::endl; //load the car dynamics std::tr1::shared_ptr<PTree> cfg; content.load(cfg, cardir, carname + ".car"); if (!cfg->size()) { return; } btVector3 size(0, 0, 0), center(0, 0, 0), pos(0, 0, 0); // collision shape from wheel data btQuaternion rot = btQuaternion::getIdentity(); bool damage = false; if (!car.Load(*cfg, size, center, pos, rot, damage, world, error_output)) { return; } info_output << "Car dynamics loaded" << std::endl; info_output << carname << " Summary:\n" << "Mass (kg) including driver and fuel: " << 1 / car.GetInvMass() << "\n" << "Center of mass (m): " << car.GetCenterOfMass() << std::endl; std::stringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); if (!car.Serialize(serialize_output)) { error_output << "Serialization error" << std::endl; } //else info_output << "Car state: " << statestream.str(); carstate = statestream.str(); // fixme info_output << "Car performance test broken - exiting." << std::endl; return; TestMaxSpeed(info_output, error_output); TestStoppingDistance(false, info_output, error_output); TestStoppingDistance(true, info_output, error_output); info_output << "Car performance test complete." << std::endl; }
void REPLAY::RecordFrame(const std::vector <float> & inputs, CAR & car) { if (!GetRecording()) return; if (frame > 2000000000) //enforce a maximum recording time of about 92 days { StopRecording(""); } assert(inputbuffer.size() == CARINPUT::GAME_ONLY_INPUTS_START_HERE); assert((unsigned int) version_info.inputs_supported == CARINPUT::GAME_ONLY_INPUTS_START_HERE); //record inputs INPUTFRAME newinputframe(frame); for (unsigned i = 0; i < CARINPUT::GAME_ONLY_INPUTS_START_HERE; i++) { if (inputs[i] != inputbuffer[i]) { inputbuffer[i] = inputs[i]; newinputframe.AddInput(i, inputs[i]); } } if (newinputframe.GetNumInputs() > 0) inputframes.push_back(newinputframe); //record state int framespersecond = 1.0/version_info.framerate; if (frame % framespersecond == 0) //once per second { std::stringstream statestream; joeserialize::BinaryOutputSerializer serialize_output(statestream); car.Serialize(serialize_output); stateframes.push_back(STATEFRAME(frame)); //stateframes.push_back(STATEFRAME(11189196)); //for debugging; in hex, 11189196 is AABBCC //cout << "Recording state size: " << statestream.str().length() << endl; //should be ~984 stateframes.back().SetBinaryStateData(statestream.str()); stateframes.back().SetInputSnapshot(inputs); } frame++; }