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 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); }