diff --git a/panda/src/testbed/deadrec_rec.cxx b/panda/src/testbed/deadrec_rec.cxx index e42d41ef36..34af29083e 100644 --- a/panda/src/testbed/deadrec_rec.cxx +++ b/panda/src/testbed/deadrec_rec.cxx @@ -33,8 +33,11 @@ QueuedConnectionListener* listener; QueuedConnectionManager cm; Clients clients; QueuedConnectionReader* reader; +static float clock_skew = 0.; +static bool doing_sync = false; +static float my_time; -enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num }; +enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num, T_Time, T_Sync }; static inline unsigned char* get_uint8(unsigned char* b, unsigned char& v) { v = b[0]; @@ -96,9 +99,11 @@ static void* internal_monitor(void*) { while (t != T_End) { switch (t) { case T_Pos: - float x, y, z; - buff = get_float64(get_float64(get_float64(buff, x), y), z); - my_pos = LPoint3f(x, y, z); + { + float x, y, z; + buff = get_float64(get_float64(get_float64(buff, x), y), z); + my_pos = LPoint3f(x, y, z); + } break; case T_Vel: if (deadrec_cat->is_debug()) @@ -108,6 +113,19 @@ static void* internal_monitor(void*) { if (deadrec_cat->is_debug()) deadrec_cat->debug() << "got T_Num" << endl; break; + case T_Time: + { + float x; + buff = get_float64(buff, x); + if (doing_sync) + clock_skew = ClockObject::get_global_clock()->get_time() - x; + else + my_time = x + clock_skew; + } + break; + case T_Sync: + doing_sync = true; + break; default: deadrec_cat->warning() << "got bad token in datagram (" << (int)t << ")" << endl; diff --git a/panda/src/testbed/deadrec_send.cxx b/panda/src/testbed/deadrec_send.cxx index c46cc3963d..42aaf9c2a0 100644 --- a/panda/src/testbed/deadrec_send.cxx +++ b/panda/src/testbed/deadrec_send.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -34,7 +35,13 @@ static QueuedConnectionManager cm; PT(Connection) conn; ConnectionWriter* writer; -enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num }; +enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num, T_Time, T_Sync }; + +static inline NetDatagram& add_time(NetDatagram& d) { + d.add_uint8(T_Time); + d.add_float64(ClockObject::get_global_clock()->get_time()); + return d; +} static inline NetDatagram& add_pos(NetDatagram& d) { d.add_uint8(T_Pos); @@ -63,6 +70,12 @@ static void event_frame(CPT_Event) { send(add_pos(d)); } +static void sync_clock(void) { + NetDatagram d; + d.add_uint8(T_Sync); + send(add_time(d)); +} + enum MotionType { M_None, M_Line, M_SLine, M_Box, M_SBox, M_Circle, M_SCircle, M_Random, M_SRandom }; PT(AutonomousLerp) curr_lerp; @@ -529,6 +542,9 @@ static void deadrec_setup(EventHandler& eh) { f1->align_to_top(0.05); f1->recompute(); f1->manage(mgr, eh); + + // sync clock + sync_clock(); } static void event_lerp(CPT_Event) {