add untested playback api implementation
This commit is contained in:
parent
0b01cfc53b
commit
9a2111f196
73
rt_replay.h
73
rt_replay.h
|
@ -156,6 +156,7 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
rtr_record_frame* frame;
|
||||
double timestamp;
|
||||
int is_finished;
|
||||
} rtr_playback_cursor;
|
||||
|
||||
|
@ -177,17 +178,18 @@ int rtr_add_analog_event(rtr_recording* recording, rtr_uint32 axis, double value
|
|||
* Playback api
|
||||
*/
|
||||
|
||||
int rtr_open_recording(void* buffer, rtr_uint64 buffer_size, void* user_ctx, rtr_recording* recording);
|
||||
int rtr_open_recording(void* buffer, rtr_uint64 buffer_size, void* user_ctx, rtr_recording* recording, rtr_playback_cursor* cursor);
|
||||
|
||||
void rtr_close_recording(rtr_recording* recording);
|
||||
|
||||
void rtr_playback_frame(rtr_recording* recording, double delta);
|
||||
rtr_playback_cursor rtr_create_cursor(rtr_recording* recording);
|
||||
|
||||
int rtr_get_events(rtr_recording* recording, unsigned int* num_events, rtr_event** events);
|
||||
void rtr_advance_playback(rtr_playback_cursor* cursor, double delta);
|
||||
|
||||
int rtr_get_events(rtr_playback_cursor* cursor, unsigned int* num_events, rtr_event* events);
|
||||
|
||||
#endif
|
||||
|
||||
#define RT_REPLAY_IMPLEMENTATION
|
||||
#ifdef RT_REPLAY_IMPLEMENTATION
|
||||
#undef RT_REPLAY_IMPLEMENTATION
|
||||
|
||||
|
@ -344,7 +346,7 @@ int rtr_add_analog_event(rtr_recording* recording, rtr_uint32 axis, double value
|
|||
return rtr_add_event(recording, event);
|
||||
}
|
||||
|
||||
int rtr_open_recording(void* buffer, rtr_uint64 buffer_size, void* user_ctx, rtr_recording* recording)
|
||||
int rtr_open_recording(void* buffer, rtr_uint64 buffer_size, void* user_ctx, rtr_recording* recording, rtr_playback_cursor* cursor)
|
||||
{
|
||||
rtr_buffer_header* hdr = (rtr_buffer_header*)buffer;
|
||||
if (hdr->version != RTR_VERSION) {
|
||||
|
@ -376,6 +378,12 @@ int rtr_open_recording(void* buffer, rtr_uint64 buffer_size, void* user_ctx, rtr
|
|||
recording->timestamp = 0.0;
|
||||
recording->ctx = user_ctx;
|
||||
|
||||
if (cursor) {
|
||||
cursor->frame = recording->frames;
|
||||
cursor->is_finished = 0;
|
||||
cursor->timestamp = 0.0;
|
||||
}
|
||||
|
||||
return RTR_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -387,11 +395,60 @@ void rtr_close_recording(rtr_recording* recording)
|
|||
RTR_MEMSET(recording, 0, sizeof(recording));
|
||||
}
|
||||
|
||||
void rtr_playback_frame(rtr_recording* recording, double delta)
|
||||
rtr_playback_cursor rtr_create_cursor(rtr_recording* recording)
|
||||
{
|
||||
|
||||
rtr_playback_cursor cursor = {NULL, 0.0, 0};
|
||||
if (recording->mode != RTR_RECORDING_MODE_PLAYBACK)
|
||||
return cursor;
|
||||
cursor.frame = recording->frames;
|
||||
cursor.is_finished = 0;
|
||||
cursor.timestamp = 0.0;
|
||||
return cursor;
|
||||
}
|
||||
|
||||
int rtr_get_events(rtr_recording* recording, unsigned int* num_events, rtr_event** events);
|
||||
void rtr_advance_playback(rtr_playback_cursor* cursor, double delta)
|
||||
{
|
||||
rtr_record_frame* next_frame = cursor->frame->next;
|
||||
/* skip extended frames */
|
||||
while (next_frame && next_frame->timestamp == cursor->frame->timestamp)
|
||||
next_frame = next_frame->next;
|
||||
|
||||
if (next_frame) {
|
||||
cursor->timestamp += delta;
|
||||
if (cursor->timestamp >= next_frame->timestamp)
|
||||
cursor->frame = next_frame;
|
||||
}
|
||||
else {
|
||||
cursor->is_finished = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int rtr_get_events(rtr_playback_cursor* cursor, unsigned int* num_events, rtr_event* events)
|
||||
{
|
||||
/* its possible that multiple frames are concatenated together */
|
||||
unsigned int n = (unsigned int)cursor->frame->num_events;
|
||||
|
||||
double ts = cursor->frame->timestamp;
|
||||
|
||||
rtr_record_frame* ext_frame = cursor->frame->next;
|
||||
while (ext_frame->timestamp == ts) {
|
||||
n += ext_frame->num_events;
|
||||
ext_frame = ext_frame->next;
|
||||
}
|
||||
|
||||
if (num_events)
|
||||
*num_events = n;
|
||||
if (events) {
|
||||
RTR_MEMCPY(events, cursor->frame->events, cursor->frame->num_events * sizeof(rtr_event));
|
||||
rtr_uint32 i = cursor->frame->num_events;
|
||||
rtr_record_frame* ext_frame = cursor->frame->next;
|
||||
while (ext_frame->timestamp == ts) {
|
||||
RTR_MEMCPY(&events[i], ext_frame->events, ext_frame->num_events * sizeof(rtr_event));
|
||||
i += ext_frame->num_events;
|
||||
ext_frame = ext_frame->next;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user