ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

commit e2aefe68f080c390b8cfd870ae068f9eef6be646
parent 84f5223a8955eeb16ad3cdefd78119b352e367b4
Author: amin <dev@aminmesbah.com>
Date:   Mon, 20 Nov 2017 05:51:20 +0000

Playback recorded input on initial state snapshot

FossilOrigin-Name: 360f6b9787f8e1ed5eea72fb96a7cb4e89be3d2c1e68d40a14ed653fade8bf03
Diffstat:
Msrc/platform_sdl.c | 19+++++++++++++++++++
Msrc/platform_sdl.h | 4+++-
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/platform_sdl.c b/src/platform_sdl.c @@ -122,6 +122,7 @@ bool sdl_handle_event(SDL_Event *event, struct GameControllerInput *controller_i if (input_record.state == INACTIVE) { printf("input_record: RECORDING\n"); + input_record.initial_state_recorded = false; input_record.record_head = 0; input_record.state = RECORDING; } @@ -130,6 +131,10 @@ bool sdl_handle_event(SDL_Event *event, struct GameControllerInput *controller_i printf("input_record: INACTIVE\n"); input_record.state = INACTIVE; } + else if (input_record.state == PLAYING_BACK) + { + printf("Can't record while playing back\n"); + } else { printf("ERROR: input_record invalid state\n"); @@ -148,6 +153,10 @@ bool sdl_handle_event(SDL_Event *event, struct GameControllerInput *controller_i printf("input_record: INACTIVE\n"); input_record.state = INACTIVE; } + else if (input_record.state == RECORDING) + { + printf("Can't play back while recording\n"); + } else { printf("ERROR: input_record invalid state\n"); @@ -321,6 +330,11 @@ int main(int argc, char *argv[]) // TODO: sdl_input_record(&controller_input); if (input_record.record_head < INPUT_RECORD_SIZE) { + if (input_record.record_head == 0) + { + input_record.initial_state = game_state; + input_record.initial_state_recorded = true; + } input_record.input_buffer[input_record.record_head] = controller_input; ++input_record.record_head; } @@ -335,6 +349,11 @@ int main(int argc, char *argv[]) { if (input_record.playback_head < input_record.record_head) { + if (input_record.playback_head == 0 && input_record.initial_state_recorded) + { + game_state = input_record.initial_state; + } + // TODO: sdl_input_playback(&controller_input); controller_input = input_record.input_buffer[input_record.playback_head]; ++input_record.playback_head; diff --git a/src/platform_sdl.h b/src/platform_sdl.h @@ -45,9 +45,11 @@ enum SDLInputRecordState struct SDLInputRecord { struct GameControllerInput input_buffer[INPUT_RECORD_SIZE]; - enum SDLInputRecordState state; + struct GameState initial_state; uint64_t record_head; uint64_t playback_head; + enum SDLInputRecordState state; + bool initial_state_recorded; }; #define PLATFORM_SDL_H