CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderFrames.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 CarlaRecorderFrame::Read(std::istream &InFile)
12{
13 ReadValue<CarlaRecorderFrame>(InFile, *this);
14}
15
16void CarlaRecorderFrame::Write(std::ostream &OutFile)
17{
18 WriteValue<CarlaRecorderFrame>(OutFile, *this);
19}
20
21// ---------------------------------------------
22
27
29{
30 Frame.Id = 0;
31 Frame.DurationThis = 0.0f;
32 Frame.Elapsed = 0.0f;
34}
35
36void CarlaRecorderFrames::SetFrame(double DeltaSeconds)
37{
38 if (Frame.Id == 0)
39 {
40 Frame.Elapsed = 0.0f;
41 Frame.DurationThis = 0.0f;
42 }
43 else
44 {
45 Frame.DurationThis = DeltaSeconds;
46 Frame.Elapsed += DeltaSeconds;
47 }
48
49 ++Frame.Id;
50}
51
52void CarlaRecorderFrames::WriteStart(std::ostream &OutFile)
53{
54 std::streampos Pos, Offset;
55 double Dummy = -1.0f;
56
57 // write the packet id
58 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::FrameStart));
59
60 // write the packet size
61 uint32_t Total = sizeof(CarlaRecorderFrame);
62 WriteValue<uint32_t>(OutFile, Total);
63
64 // write frame record
65 WriteValue<uint64_t>(OutFile, Frame.Id);
66 Offset = OutFile.tellp();
67 WriteValue<double>(OutFile, Dummy);
68 WriteValue<double>(OutFile, Frame.Elapsed);
69
70 // we need to write this duration to previous frame
71 if (OffsetPreviousFrame > 0)
72 {
73 Pos = OutFile.tellp();
74 OutFile.seekp(OffsetPreviousFrame, std::ios::beg);
75 WriteValue<double>(OutFile, Frame.DurationThis);
76 OutFile.seekp(Pos, std::ios::beg);
77 }
78
79 // save position for next actualization
80 OffsetPreviousFrame = Offset;
81}
82
83void CarlaRecorderFrames::WriteEnd(std::ostream &OutFile)
84{
85 // write the packet id
86 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::FrameEnd));
87
88 // write the packet size (0)
89 uint32_t Total = 0;
90 WriteValue<uint32_t>(OutFile, Total);
91}
void SetFrame(double DeltaSeconds)
void WriteEnd(std::ostream &OutFile)
void WriteStart(std::ostream &OutFile)
std::streampos OffsetPreviousFrame
CarlaRecorderFrame Frame
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)