getting closer

This commit is contained in:
Cary Sandvig 2000-12-01 19:55:38 +00:00
parent 41dd451133
commit 3a37cdb358
2 changed files with 39 additions and 5 deletions

View File

@ -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;

View File

@ -12,6 +12,7 @@
#include <guiFrame.h>
#include <guiButton.h>
#include <guiSign.h>
#include <clockObject.h>
#include <dconfig.h>
@ -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) {