2012-07-14 16:37:52 +02:00
/*
* 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/>
*/
2012-07-14 19:46:03 +02:00
# ifndef REPLAY_H
# define REPLAY_H
# include "stage.h"
# include "player.h"
2017-02-09 01:13:06 +01:00
# define REPLAY_ALLOC_INITIAL 256
2017-02-05 02:25:17 +01:00
# define REPLAY_EXTENSION "tsr"
2017-02-09 01:13:06 +01:00
# 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
2017-02-09 01:13:06 +01:00
# define REPLAY_LOAD_GARBAGE_TEST
2017-02-05 03:58:27 +01:00
# endif
2012-07-14 19:46:03 +02:00
typedef struct ReplayEvent {
2017-02-05 02:25:17 +01:00
uint32_t frame ;
uint8_t type ;
2017-02-05 03:04:31 +01:00
uint16_t value ;
2012-07-14 19:46:03 +02:00
} ReplayEvent ;
2012-08-07 05:28:41 +02:00
typedef struct ReplayStage {
2012-07-14 19:46:03 +02:00
// initial game settings
2017-02-09 01:13:06 +01:00
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 ;
2012-07-14 19:46:03 +02:00
// initial player settings
2017-02-05 02:25:17 +01:00
uint8_t plr_char ;
uint8_t plr_shot ;
2017-02-08 20:59:43 +01:00
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 ;
2017-02-08 20:59:43 +01:00
uint16_t plr_power ;
2017-02-05 02:25:17 +01:00
uint8_t plr_lifes ;
uint8_t plr_bombs ;
uint8_t plr_moveflags ;
2012-07-14 19:46:03 +02:00
2012-07-29 22:39:52 +02:00
// events
2012-07-14 19:46:03 +02:00
ReplayEvent * events ;
2017-02-09 01:13:06 +01:00
uint16_t ecount ;
2012-07-14 19:46:03 +02:00
// 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 ;
2017-02-09 01:13:06 +01:00
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 ;
2012-07-14 19:46:03 +02:00
} 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 ) ;
2012-07-14 19:46:03 +02:00
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 ) ;
2017-02-05 03:04:31 +01:00
void replay_event ( Replay * rpy , uint8_t type , int16_t value ) ;
2012-07-14 19:46:03 +02:00
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
2012-07-29 22:39:52 +02:00
char * replay_getpath ( char * name , int ext ) ; // must be freed
2012-07-16 17:47:06 +02:00
int replay_save ( Replay * rpy , char * name ) ;
int replay_load ( Replay * rpy , char * name ) ;
2012-07-29 22:39:52 +02:00
void replay_copy ( Replay * dst , Replay * src ) ;
2012-07-16 17:47:06 +02:00
2012-07-14 19:46:03 +02:00
# endif
2017-02-05 03:58:27 +01:00
void replay_check_desync ( Replay * rpy , int time , uint16_t check ) ;
2017-02-09 01:13:06 +01:00
int replay_test ( void ) ;