NXEngine v1.0.0.6
[NXEngine.git] / replay.h
blob9ac44080bbec9c7467f0ef0b69f7bd83bb5dbe68
2 #ifndef _REPLAY_H
3 #define _REPLAY_H
5 #include "common/FileBuffer.h"
6 #define MAX_REPLAYS 8 // how many automatic replays to save
8 #define REC_OK 0
9 #define REC_ERR 1
10 #define REC_END 2
11 struct ReplayHeader
13 uint16_t magick;
14 uint32_t randseed;
15 bool locked;
16 int total_frames;
17 int stageno;
18 uint64_t createstamp;
19 Settings settings;
22 struct ReplayRecording
24 ReplayHeader hdr;
25 FileBuffer fb;
27 uint32_t lastkeys;
28 uint32_t runlength;
29 FILE *fp;
32 struct ReplayPlaying
34 ReplayHeader hdr;
36 uint32_t keys;
37 uint32_t runlength;
38 int elapsed_frames;
39 int elapsed_records;
40 FILE *fp;
42 int ffwdto, ffwd_accel;
43 int stopat;
45 int termtimer; // blinks "TERMINATED" after replay ends
48 enum RS_Status
50 RS_UNUSED, // there is no file in this slot
51 RS_UNLOCKED, // there is an unlocked file in this slot
52 RS_LOCKED // there is a locked file in this slot
55 struct ReplaySlotInfo
57 char filename[MAXPATHLEN]; // filename of the replay for this slot, if there is one
58 int status; // status of this slot
59 ReplayHeader hdr; // header from slot
63 namespace Replay
65 bool begin_record(const char *fname);
66 bool end_record();
68 bool begin_playback(const char *fname);
69 bool end_playback();
71 void run();
72 void close();
74 void OnGameStarting();
75 bool begin_record_next();
77 bool IsRecording();
78 bool IsPlaying();
79 void DrawStatus();
81 void set_ffwd(int frame, bool accel=true);
82 void set_stopat(int frame);
85 bool LoadHeader(const char *fname, ReplayHeader *hdr);
86 bool SaveHeader(const char *fname, ReplayHeader *hdr);
88 void GetSlotInfo(int slotno, ReplaySlotInfo *slot);
89 void FramesToTime(int framecount, char *buffer);
90 int GetPlaybackPosition(int max);
92 static uint32_t EncodeBits(bool *values, int nvalues);
93 static void DecodeBits(uint32_t value, bool *array, int len);
95 static void run_record();
96 static void run_playback();
98 static int GetAvailableSlot(void);
102 const char *GetReplayName(int slotno, char *buffer = NULL);
104 #endif