CARLA
Loading...
Searching...
No Matches
CarlaRecorderAnimVehicle.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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
8#include "CarlaRecorder.h"
10
11#include <algorithm>
12#include <limits>
13
14void CarlaRecorderAnimVehicle::Write(std::ostream &OutFile)
15{
16 // database id
17 WriteValue<uint32_t>(OutFile, this->DatabaseId);
18 WriteValue<float>(OutFile, this->Steering);
19 WriteValue<float>(OutFile, this->Throttle);
20 WriteValue<float>(OutFile, this->Brake);
21 WriteValue<bool>(OutFile, this->bHandbrake);
22 WriteValue<int32_t>(OutFile, this->Gear);
23}
24void CarlaRecorderAnimVehicle::Read(std::istream &InFile)
25{
26 // database id
27 ReadValue<uint32_t>(InFile, this->DatabaseId);
28 ReadValue<float>(InFile, this->Steering);
29 ReadValue<float>(InFile, this->Throttle);
30 ReadValue<float>(InFile, this->Brake);
31 ReadValue<bool>(InFile, this->bHandbrake);
32 ReadValue<int32_t>(InFile, this->Gear);
33}
34
35// ---------------------------------------------
36
38{
39 Vehicles.clear();
40}
41
46
47void CarlaRecorderAnimVehicles::Write(std::ostream &OutFile)
48{
49 // write the packet id
50 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimVehicle));
51
52 std::streampos PosStart = OutFile.tellp();
53
54 // write a dummy packet size
55 uint32_t Total = 0;
56 WriteValue<uint32_t>(OutFile, Total);
57
58 // write total records
59 Total = std::min<size_t>(Vehicles.size(), std::numeric_limits<uint16_t>::max());
60 WriteValue<uint16_t>(OutFile, Total);
61
62 for (uint16_t i=0; i<Total; ++i)
63 Vehicles[i].Write(OutFile);
64
65 // write the real packet size
66 std::streampos PosEnd = OutFile.tellp();
67 Total = PosEnd - PosStart - sizeof(uint32_t);
68 OutFile.seekp(PosStart, std::ios::beg);
69 WriteValue<uint32_t>(OutFile, Total);
70 OutFile.seekp(PosEnd, std::ios::beg);
71}
72
73void CarlaRecorderAnimVehicles::Read(std::istream &InFile)
74{
75 uint16_t i, Total = 0;
77
78 // read Total Vehicles
79 ReadValue<uint16_t>(InFile, Total);
80 for (i = 0; (i < Total) && InFile; ++i)
81 {
82 Vehicle.Read(InFile);
83 Add(Vehicle);
84 }
85}
86
87const std::vector<CarlaRecorderAnimVehicle>& CarlaRecorderAnimVehicles::GetVehicles()
88{
89 return Vehicles;
90}
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)