summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-19 21:51:21 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-11-19 21:51:21 -0800
commit6d77e0f78aa203c44661d8b88e489a65bbc4b56c (patch)
treeace6571e18733bf19d3731cea58d0f790dca02f2 /src
parent995d440e28204f354f8103cdeb28d585f85b212a (diff)
downloadohsp-6d77e0f78aa203c44661d8b88e489a65bbc4b56c.zip
ohsp-6d77e0f78aa203c44661d8b88e489a65bbc4b56c.tar.gz
Playback recorded input on initial state snapshot
Diffstat (limited to 'src')
-rw-r--r--src/platform_sdl.c19
-rw-r--r--src/platform_sdl.h4
2 files changed, 22 insertions, 1 deletions
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index 500ca6d..8682b4a 100644
--- 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
index 471324b..c7b7745 100644
--- 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