OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Record.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // scenario record functionality
17 
18 #ifndef INC_C4Record
19 #define INC_C4Record
20 
21 class C4Record;
22 
23 #include "c4group/C4Group.h"
24 #include "control/C4Control.h"
25 
26 extern int DoNoDebugRec; // debugrec disable counter in C4Record.cpp
27 
28 #define DEBUGREC_OFF ++DoNoDebugRec;
29 #define DEBUGREC_ON --DoNoDebugRec;
30 
31 // turn off debugrecs in current block
33 {
34  bool fDoOff;
35 
36 public:
37  C4DebugRecOff();
38  C4DebugRecOff(bool fDoOff);
40 
41  void Clear();
42 };
43 
44 enum C4RecordChunkType // record file chunk type
45 {
46  RCT_Ctrl = 0x00, // control
47  RCT_CtrlPkt= 0x01, // control packet
48  RCT_Frame = 0x02, // beginning frame
49  RCT_End = 0x10, // --- the end ---
50  RCT_Log = 0x20, // log message
51  // Streaming
52  RCT_File = 0x30, // file data
53  // DEBUGREC
54  RCT_DbgFrame= 0x81, // frame start in Game::Execute
55  RCT_Block = 0x82, // point in Game::Execute
56  RCT_SetPix = 0x83, // set landscape pixel
57  RCT_ExecObj = 0x84, // exec object
58  RCT_Random = 0x85, // Random()-call
59  RCT_Rn3 = 0x86, // Rn3()-call
60  RCT_MMC = 0x87, // create MassMover
61  RCT_MMD = 0x88, // destroy MassMover
62  RCT_CrObj = 0x89, // create object
63  RCT_DsObj = 0x8A, // remove object
64  RCT_GetPix = 0x8B, // get landscape pixel; let the Gigas flow!
65  RCT_RotVtx1 = 0x8C, // before shape is rotated
66  RCT_RotVtx2 = 0x8D, // after shape is rotated
67  RCT_ExecPXS = 0x8E, // execute pxs system
68  RCT_Sin = 0x8F, // sin by Shape-Rotation
69  RCT_Cos = 0x90, // cos by Shape-Rotation
70  RCT_Map = 0x91, // map dump
71  RCT_Ls = 0x92, // complete landscape dump!
72  RCT_MCT1 = 0x93, // MapCreatorS2: before transformation
73  RCT_MCT2 = 0x94, // MapCreatorS2: after transformation
74  RCT_AulFunc = 0x9A, // script function call
75  RCT_ObjCom = 0x9B, // object com
76  RCT_PlrCom = 0x9C, // player com
77  RCT_PlrInCom= 0x9D, // player InCom
78  RCT_MatScan = 0x9E, // landscape scan execute
79  RCT_MatScanDo= 0x9F, // landscape scan mat change
80  RCT_Area = 0xA0, // object area change
81  RCT_MenuAdd = 0xA1, // add menu item
82  RCT_MenuAddC = 0xA2, // add menu item: Following commands
83  RCT_OCF = 0xA3, // OCF setting of updating
84  RCT_DirectExec = 0xA4, // a DirectExec-script
85  RCT_Definition = 0xA5, // Definition callback
86  RCT_SetProperty= 0xA6, // set a property in a proplist
87 
88  RCT_Custom = 0xc0, // varies
89 
91 };
92 
93 void AddDbgRec(C4RecordChunkType eType, const void *pData=nullptr, int iSize=0); // record debug stuff
94 
95 #pragma pack(1)
96 
97 struct C4RecordChunkHead // record file chunk head
98 {
99  uint8_t iFrm; // frame
100  uint8_t Type; // chunk type
101 };
102 
104 {
105  int32_t Frame;
106  uint8_t Type;
107  union
108  {
109  C4Control *pCtrl;
110  C4IDPacket *pPkt;
111  class C4PktDebugRec *pDbg;
112  StdBuf *pFileData;
113  };
114  StdCopyStrBuf Filename; // RCT_File only
115 public:
116  C4RecordChunk();
117  void Delete();
118  virtual void CompileFunc(StdCompiler *pComp);
119  virtual ~C4RecordChunk() {}
120 };
121 
123 {
124  int x,y; // pos
125  BYTE clr; // new fg color
126  BYTE bgClr; // new bg color
127 };
128 
130 {
131  int Number; // object number
133 };
134 
136 {
137  int x,y; // pos
138 };
139 
141 {
142  int Cnt; // index in seed
143  uint32_t Range; // random range query
144  uint32_t Val; // random value
145 };
146 
148 {
149  int oei;
150  char id[32+1];
151  int x,y,ownr;
152 };
153 
154 struct C4RCSin
155 {
156  // value+return value
157  double v,r;
158 };
159 
161 {
162  // shape size
163  int x,y,wdt,hgt,r;
164  // vertices
165  int VtxX[4], VtxY[4];
166 };
167 
169 {
170  // pos
172  // mat
173  int32_t iMat;
174  // execution pos
175  int32_t pos;
176 };
177 
178 struct C4RCTrf
179 {
181 };
182 
183 struct C4RCPos
184 {
185  int x,y;
186 };
187 
189 {
191  int32_t data;
192  int32_t o;
193 };
194 
196 {
197  int32_t cx, cy, mat, conv_to, dir, mconvs;
198 };
199 
200 struct C4RCArea
201 {
202  char op;
203  int32_t obj;
204  int32_t x1,y1, xL, yL, dpitch;
205  bool out;
206 };
207 
209 {
210  int32_t iObjNum;
211  int32_t iCount;
213  bool fOwnValue;
214  int32_t iValue;
216 };
217 
218 struct C4RCOCF
219 {
220  uint32_t dwOCFOld;
221  uint32_t dwOCFNew;
222  bool fUpdate;
223 };
224 
225 #pragma pack()
226 
227 // debug record packet
228 class C4PktDebugRec : public C4PktBuf
229 {
230 protected:
232 public:
234  C4PktDebugRec(const C4PktDebugRec &rCopy) : C4PktBuf(rCopy), eType(rCopy.eType) {}
235  C4PktDebugRec(C4RecordChunkType eType, const StdBuf &rCpyData)
236  : C4PktBuf(rCpyData), eType(eType) {}
237 
238  C4RecordChunkType getType() const { return eType; }
239 
240  virtual void CompileFunc(StdCompiler *pComp);
241 };
242 
243 class C4Record // demo recording
244 {
245 private:
246  CStdFile CtrlRec; // control file handle
247  CStdFile LogRec; // handle for additional log file in record
248  StdStrBuf sFilename; // recorded scenario file name
249  C4Group RecordGrp; // record scenario group
250  bool fRecording; // set if recording is active
251  uint32_t iLastFrame; // frame of last chunk written
252  bool fStreaming; // perdiodically sent new control to server
253  unsigned int iStreamingPos; // Position of current buffer in stream
254  StdBuf StreamingData; // accumulated control data since last stream sync
255 public:
256  C4Record(); // constructor; creates control file etc
257  C4Record(const char *szPlaybackFile, const char *szRecordFile, const char *szTempRecFile); // start recording from replay into record
258  ~C4Record(); // destructor; close file; create demo scen
259  int Index;
260 
261  bool IsRecording() const { return fRecording; } // return whether Start() has been called
262  unsigned int GetStreamingPos() const { return iStreamingPos; }
263  const StdBuf &GetStreamingBuf() const { return StreamingData; }
264 
265  bool Start(bool fInitial);
266  bool Stop(StdStrBuf *pRecordName = nullptr, BYTE *pRecordSHA1 = nullptr);
267 
268  bool Rec(const C4Control &Ctrl, int iFrame); // record control
269  bool Rec(C4PacketType eCtrlType, C4ControlPacket *pCtrl, int iFrame); // record control packet
270  bool Rec(int iFrame, const StdBuf &sBuf, C4RecordChunkType eType);
271 
272  bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete = false);
273 
274  bool StartStreaming(bool fInitial);
275  void ClearStreamingBuf(unsigned int iAmount);
276  void StopStreaming();
277 
278  CStdFile * GetLogFile() { return &LogRec; }
279 
280 private:
281  void Stream(const C4RecordChunkHead &Head, const StdBuf &sBuf);
282  bool StreamFile(const char *szFilename, const char *szAddAs);
283 };
284 
285 class C4Playback // demo playback
286 {
287 private:
288  typedef std::list<C4RecordChunk> chunks_t;
289  chunks_t chunks;
290  chunks_t::iterator currChunk;
291  bool Finished; // if set, free playback in next frame
292  CStdFile playbackFile; // if open, try reading additional chunks from this file
293  bool fLoadSequential; // used for debugrecs: Sequential reading of files
294  StdBuf sequentialBuffer; // buffer to manage sequential reads
295  uint32_t iLastSequentialFrame; // frame number of last chunk read
296  void Finish(); // end playback
297  C4PacketList DebugRec;
298 public:
299  C4Playback(); // constructor; init playback
300  ~C4Playback(); // destructor; deinit playback
301 
302  bool Open(C4Group &rGrp);
303  bool ReadBinary(const StdBuf &Buf);
304  bool ReadText(const StdStrBuf &Buf);
305  void NextChunk(); // point to next prepared chunk in mem or read it
306  bool NextSequentialChunk(); // read from seq file until a new chunk has been filled
309  void Strip();
310  bool ExecuteControl(C4Control *pCtrl, int iFrame); // assign control
311  bool IsFinished() { return Finished; }
312  void Clear();
313  void Check(C4RecordChunkType eType, const uint8_t *pData, int iSize); // compare with debugrec
314  void DebugRecError(const char *szError);
315  static bool StreamToRecord(const char *szStream, StdStrBuf *pRecord);
316 };
317 
318 #endif
int32_t mconvs
Definition: C4Record.h:197
C4RecordChunkType getType() const
Definition: C4Record.h:238
C4PktDebugRec(const C4PktDebugRec &rCopy)
Definition: C4Record.h:234
int32_t o
Definition: C4Record.h:192
int VtxX[4]
Definition: C4Record.h:165
int32_t dir
Definition: C4Record.h:197
C4Real y
Definition: C4Record.h:171
C4Real fy
Definition: C4Record.h:132
int32_t iMat
Definition: C4Record.h:173
int x
Definition: C4Record.h:180
Definition: StdBuf.h:37
virtual void CompileFunc(StdCompiler *pComp)
Definition: C4Record.cpp:62
C4Real fr
Definition: C4Record.h:132
CStdFile * GetLogFile()
Definition: C4Record.h:278
int32_t xL
Definition: C4Record.h:204
bool Rec(const C4Control &Ctrl, int iFrame)
Definition: C4Record.cpp:220
int32_t y1
Definition: C4Record.h:204
const StdBuf & GetStreamingBuf() const
Definition: C4Record.h:263
int DoNoDebugRec
Definition: C4Record.cpp:34
uint32_t Range
Definition: C4Record.h:143
bool IsFinished()
Definition: C4Record.h:311
virtual void CompileFunc(StdCompiler *pComp)
Definition: C4Record.cpp:89
bool fIsSelectable
Definition: C4Record.h:215
C4PacketType
Definition: C4PacketBase.h:76
StdBuf ReWriteBinary()
Definition: C4Record.cpp:669
void Delete()
Definition: C4Record.cpp:76
void Clear()
Definition: C4Record.cpp:56
double r
Definition: C4Record.h:157
uint8_t BYTE
uint8_t Type
Definition: C4Record.h:106
int y
Definition: C4Record.h:180
C4PktDebugRec(C4RecordChunkType eType, const StdBuf &rCpyData)
Definition: C4Record.h:235
void StopStreaming()
Definition: C4Record.cpp:360
bool out
Definition: C4Record.h:205
int32_t data
Definition: C4Record.h:191
void NextChunk()
Definition: C4Record.cpp:620
Definition: C4Real.h:58
int Rotate
Definition: C4Record.h:180
C4RecordChunkType
Definition: C4Record.h:44
double v
Definition: C4Record.h:157
int32_t conv_to
Definition: C4Record.h:197
bool ReadText(const StdStrBuf &Buf)
Definition: C4Record.cpp:615
bool fOwnValue
Definition: C4Record.h:213
bool Stop(StdStrBuf *pRecordName=nullptr, BYTE *pRecordSHA1=nullptr)
Definition: C4Record.cpp:178
int Turbulence
Definition: C4Record.h:180
C4Real x
Definition: C4Record.h:171
uint32_t Val
Definition: C4Record.h:144
StdStrBuf ReWriteText()
Definition: C4Record.cpp:656
int y
Definition: C4Record.h:185
int32_t cx
Definition: C4Record.h:197
int32_t iValue
Definition: C4Record.h:214
int32_t cy
Definition: C4Record.h:197
bool Open(C4Group &rGrp)
Definition: C4Record.cpp:393
char op
Definition: C4Record.h:202
void Check(C4RecordChunkType eType, const uint8_t *pData, int iSize)
Definition: C4Record.cpp:1003
void Clear()
Definition: C4Record.cpp:920
int32_t Frame
Definition: C4Record.h:105
StdCopyStrBuf Filename
Definition: C4Record.h:114
Definition: C4Id.h:28
int32_t yL
Definition: C4Record.h:204
C4RecordChunkType eType
Definition: C4Record.h:231
bool Start(bool fInitial)
Definition: C4Record.cpp:113
void Strip()
Definition: C4Record.cpp:724
int Number
Definition: C4Record.h:131
C4ID idID
Definition: C4Record.h:212
void AddDbgRec(C4RecordChunkType eType, const void *pData=nullptr, int iSize=0)
Definition: C4Record.cpp:36
bool ExecuteControl(C4Control *pCtrl, int iFrame)
Definition: C4Record.cpp:851
int32_t dpitch
Definition: C4Record.h:204
int32_t pos
Definition: C4Record.h:175
bool IsRecording() const
Definition: C4Record.h:261
C4Real fx
Definition: C4Record.h:132
uint32_t dwOCFOld
Definition: C4Record.h:220
BYTE bgClr
Definition: C4Record.h:126
int Index
Definition: C4Record.h:259
int32_t mat
Definition: C4Record.h:197
bool fUpdate
Definition: C4Record.h:222
void ClearStreamingBuf(unsigned int iAmount)
Definition: C4Record.cpp:348
virtual ~C4RecordChunk()
Definition: C4Record.h:119
bool NextSequentialChunk()
Definition: C4Record.cpp:633
int32_t iCount
Definition: C4Record.h:211
uint32_t dwOCFNew
Definition: C4Record.h:221
bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete=false)
Definition: C4Record.cpp:275
bool ReadBinary(const StdBuf &Buf)
Definition: C4Record.cpp:515
int x
Definition: C4Record.h:185
int32_t obj
Definition: C4Record.h:203
bool StartStreaming(bool fInitial)
Definition: C4Record.cpp:320
BYTE clr
Definition: C4Record.h:125
int32_t iObjNum
Definition: C4Record.h:210
void DebugRecError(const char *szError)
Definition: C4Record.cpp:1112
uint8_t iFrm
Definition: C4Record.h:99
int iSize
Definition: TstC4NetIO.cpp:35
unsigned int GetStreamingPos() const
Definition: C4Record.h:262
int32_t x1
Definition: C4Record.h:204
int VtxY[4]
Definition: C4Record.h:165
static bool StreamToRecord(const char *szStream, StdStrBuf *pRecord)
Definition: C4Record.cpp:1118