taisei/src/replay.h

100 lines
2.3 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
*/
#ifndef REPLAY_H
#define REPLAY_H
#include "stage.h"
#include "player.h"
#define REPLAY_ALLOC_INITIAL 256
2017-02-05 02:25:17 +01:00
#define REPLAY_EXTENSION "tsr"
#define REPLAY_STRUCT_VERSION 2
#define REPLAY_USELESS_BYTE 0x69
2017-02-05 02:25:17 +01:00
2017-02-05 03:58:27 +01:00
#ifdef DEBUG
#define REPLAY_WRITE_DESYNC_CHECKS
#define REPLAY_LOAD_GARBAGE_TEST
2017-02-05 03:58:27 +01:00
#endif
typedef struct ReplayEvent {
2017-02-05 02:25:17 +01:00
uint32_t frame;
uint8_t type;
uint16_t value;
} ReplayEvent;
2012-08-07 05:28:41 +02:00
typedef struct ReplayStage {
// initial game settings
uint16_t stage;
2017-02-05 02:25:17 +01:00
uint32_t seed; // this also happens to be the game initiation time - and we use this property, don't break it please
uint8_t diff;
uint32_t points;
// initial player settings
2017-02-05 02:25:17 +01:00
uint8_t plr_char;
uint8_t plr_shot;
uint16_t plr_pos_x;
uint16_t plr_pos_y;
2017-02-05 02:25:17 +01:00
uint8_t plr_focus;
uint8_t plr_fire;
uint16_t plr_power;
2017-02-05 02:25:17 +01:00
uint8_t plr_lifes;
uint8_t plr_bombs;
uint8_t plr_moveflags;
// events
ReplayEvent *events;
uint16_t ecount;
// The fields below should not be stored
2012-07-15 12:16:27 +02:00
int capacity;
2012-07-29 15:54:49 +02:00
int playpos;
2012-08-07 05:28:41 +02:00
} ReplayStage;
typedef struct Replay {
// metadata
2017-02-05 02:25:17 +01:00
// uint16_t version;
2012-08-07 05:28:41 +02:00
char *playername;
// stages (NOTE FOR FUTURE: stages do not represent stage runs in particular, they can and should be used to store stuff like spell practice runs, too)
ReplayStage *stages;
uint16_t stgcount;
2012-08-07 05:28:41 +02:00
// The fields below should not be stored
int active;
ReplayStage *current;
int currentidx;
2017-02-05 03:58:27 +01:00
uint16_t desync_check;
} Replay;
enum {
REPLAY_RECORD,
REPLAY_PLAY
};
2012-08-07 05:28:41 +02:00
void replay_init(Replay *rpy);
2017-02-05 02:25:17 +01:00
ReplayStage* replay_init_stage(Replay *rpy, StageInfo *stage, uint64_t seed, Player *plr);
void replay_destroy(Replay *rpy);
2012-08-07 05:28:41 +02:00
void replay_destroy_stage(ReplayStage *stage);
ReplayStage* replay_select(Replay *rpy, int stage);
void replay_event(Replay *rpy, uint8_t type, int16_t value);
2017-02-05 02:25:17 +01:00
int replay_write(Replay *rpy, SDL_RWops *file);
int replay_read(Replay *rpy, SDL_RWops *file);
2012-07-15 12:16:27 +02:00
char* replay_getpath(char *name, int ext); // must be freed
int replay_save(Replay *rpy, char *name);
int replay_load(Replay *rpy, char *name);
void replay_copy(Replay *dst, Replay *src);
#endif
2017-02-05 03:58:27 +01:00
void replay_check_desync(Replay *rpy, int time, uint16_t check);
int replay_test(void);