CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderAnimVehicle.cpp
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "CarlaRecorder.h"
10
11void CarlaRecorderAnimVehicle::Write(std::ostream &OutFile)
12{
13 // database id
14 WriteValue<uint32_t>(OutFile, this->DatabaseId);
15 WriteValue<float>(OutFile, this->Steering);
16 WriteValue<float>(OutFile, this->Throttle);
17 WriteValue<float>(OutFile, this->Brake);
18 WriteValue<bool>(OutFile, this->bHandbrake);
19 WriteValue<int32_t>(OutFile, this->Gear);
20}
21void CarlaRecorderAnimVehicle::Read(std::istream &InFile)
22{
23 // database id
24 ReadValue<uint32_t>(InFile, this->DatabaseId);
25 ReadValue<float>(InFile, this->Steering);
26 ReadValue<float>(InFile, this->Throttle);
27 ReadValue<float>(InFile, this->Brake);
28 ReadValue<bool>(InFile, this->bHandbrake);
29 ReadValue<int32_t>(InFile, this->Gear);
30}
31
32// ---------------------------------------------
33
35{
36 Vehicles.clear();
37}
38
43
44void CarlaRecorderAnimVehicles::Write(std::ostream &OutFile)
45{
46 // write the packet id
47 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicle));
48
49 std::streampos PosStart = OutFile.tellp();
50
51 // write a dummy packet size
52 uint32_t Total = 0;
53 WriteValue<uint32_t>(OutFile, Total);
54
55 // write total records
56 Total = Vehicles.size();
57 WriteValue<uint16_t>(OutFile, Total);
58
59 for (uint16_t i=0; i<Total; ++i)
60 Vehicles[i].Write(OutFile);
61
62 // write the real packet size
63 std::streampos PosEnd = OutFile.tellp();
64 Total = PosEnd - PosStart - sizeof(uint32_t);
65 OutFile.seekp(PosStart, std::ios::beg);
66 WriteValue<uint32_t>(OutFile, Total);
67 OutFile.seekp(PosEnd, std::ios::beg);
68}
69
70void CarlaRecorderAnimVehicles::Read(std::istream &InFile)
71{
72 uint16_t i, Total;
74
75 // read Total Vehicles
76 ReadValue<uint16_t>(InFile, Total);
77 for (i = 0; i < Total; ++i)
78 {
79 Vehicle.Read(InFile);
80 Add(Vehicle);
81 }
82}
83
84const std::vector<CarlaRecorderAnimVehicle>& CarlaRecorderAnimVehicles::GetVehicles()
85{
86 return Vehicles;
87}
const std::vector< CarlaRecorderAnimVehicle > & GetVehicles()
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Add(const CarlaRecorderAnimVehicle &InObj)
std::vector< CarlaRecorderAnimVehicle > Vehicles
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)