mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
getting closer
This commit is contained in:
parent
41dd451133
commit
3a37cdb358
@ -33,8 +33,11 @@ QueuedConnectionListener* listener;
|
|||||||
QueuedConnectionManager cm;
|
QueuedConnectionManager cm;
|
||||||
Clients clients;
|
Clients clients;
|
||||||
QueuedConnectionReader* reader;
|
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) {
|
static inline unsigned char* get_uint8(unsigned char* b, unsigned char& v) {
|
||||||
v = b[0];
|
v = b[0];
|
||||||
@ -96,9 +99,11 @@ static void* internal_monitor(void*) {
|
|||||||
while (t != T_End) {
|
while (t != T_End) {
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case T_Pos:
|
case T_Pos:
|
||||||
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
buff = get_float64(get_float64(get_float64(buff, x), y), z);
|
buff = get_float64(get_float64(get_float64(buff, x), y), z);
|
||||||
my_pos = LPoint3f(x, y, z);
|
my_pos = LPoint3f(x, y, z);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case T_Vel:
|
case T_Vel:
|
||||||
if (deadrec_cat->is_debug())
|
if (deadrec_cat->is_debug())
|
||||||
@ -108,6 +113,19 @@ static void* internal_monitor(void*) {
|
|||||||
if (deadrec_cat->is_debug())
|
if (deadrec_cat->is_debug())
|
||||||
deadrec_cat->debug() << "got T_Num" << endl;
|
deadrec_cat->debug() << "got T_Num" << endl;
|
||||||
break;
|
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:
|
default:
|
||||||
deadrec_cat->warning() << "got bad token in datagram (" << (int)t
|
deadrec_cat->warning() << "got bad token in datagram (" << (int)t
|
||||||
<< ")" << endl;
|
<< ")" << endl;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <guiFrame.h>
|
#include <guiFrame.h>
|
||||||
#include <guiButton.h>
|
#include <guiButton.h>
|
||||||
#include <guiSign.h>
|
#include <guiSign.h>
|
||||||
|
#include <clockObject.h>
|
||||||
|
|
||||||
#include <dconfig.h>
|
#include <dconfig.h>
|
||||||
|
|
||||||
@ -34,7 +35,13 @@ static QueuedConnectionManager cm;
|
|||||||
PT(Connection) conn;
|
PT(Connection) conn;
|
||||||
ConnectionWriter* writer;
|
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) {
|
static inline NetDatagram& add_pos(NetDatagram& d) {
|
||||||
d.add_uint8(T_Pos);
|
d.add_uint8(T_Pos);
|
||||||
@ -63,6 +70,12 @@ static void event_frame(CPT_Event) {
|
|||||||
send(add_pos(d));
|
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,
|
enum MotionType { M_None, M_Line, M_SLine, M_Box, M_SBox, M_Circle, M_SCircle,
|
||||||
M_Random, M_SRandom };
|
M_Random, M_SRandom };
|
||||||
PT(AutonomousLerp) curr_lerp;
|
PT(AutonomousLerp) curr_lerp;
|
||||||
@ -529,6 +542,9 @@ static void deadrec_setup(EventHandler& eh) {
|
|||||||
f1->align_to_top(0.05);
|
f1->align_to_top(0.05);
|
||||||
f1->recompute();
|
f1->recompute();
|
||||||
f1->manage(mgr, eh);
|
f1->manage(mgr, eh);
|
||||||
|
|
||||||
|
// sync clock
|
||||||
|
sync_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_lerp(CPT_Event) {
|
static void event_lerp(CPT_Event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user