ohsp

Prototype for a game with dual thruster controls.
Log | Files | Refs | LICENSE

commit 6d77e0f78aa203c44661d8b88e489a65bbc4b56c
parent 995d440e28204f354f8103cdeb28d585f85b212a
Author: Amin Mesbah <mesbahamin@gmail.com>
Date:   Sun, 19 Nov 2017 21:51:21 -0800

Playback recorded input on initial state snapshot

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