mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
restartable connections and stuff
This commit is contained in:
parent
1d78fb1608
commit
3e8caf8e17
@ -399,9 +399,22 @@ inline static void predict_null(void) {
|
||||
}
|
||||
|
||||
inline static void predict_linear(void) {
|
||||
static bool have_vel = false;
|
||||
|
||||
// DO THIS
|
||||
if (reinit_prediction) {
|
||||
have_vel = false;
|
||||
target_vel = LVector3f(0., 0., 0.);
|
||||
reinit_prediction = false;
|
||||
}
|
||||
if (have_vel) {
|
||||
if (new_telemetry)
|
||||
target_vel = target_pos - telemetry_pos;
|
||||
} else {
|
||||
if (new_telemetry)
|
||||
have_vel = true;
|
||||
}
|
||||
target_pos = telemetry_pos;
|
||||
reinit_prediction = false;
|
||||
}
|
||||
|
||||
inline static void run_predict(void) {
|
||||
|
@ -64,18 +64,64 @@ static inline void send(NetDatagram& d) {
|
||||
writer->send(d, conn);
|
||||
}
|
||||
|
||||
static void event_frame(CPT_Event) {
|
||||
// send deadrec data
|
||||
NetDatagram d;
|
||||
send(add_time(add_pos(d)));
|
||||
}
|
||||
|
||||
static void sync_clock(void) {
|
||||
NetDatagram d;
|
||||
d.add_uint8(T_Sync);
|
||||
send(add_time(d));
|
||||
}
|
||||
|
||||
static bool verify_connection(void) {
|
||||
static float time = 0.;
|
||||
|
||||
if (conn.is_null()) {
|
||||
if (time <= 0.) {
|
||||
NetAddress host;
|
||||
if (!host.set_host(hostname, hostport)) {
|
||||
deadrec_cat->warning() << "unknown host: " << hostname << endl;
|
||||
time = 100.;
|
||||
return false;
|
||||
}
|
||||
PT(Connection) local_conn = cm.open_TCP_client_connection(host, 5000);
|
||||
if (local_conn.is_null()) {
|
||||
deadrec_cat->warning() << "no connection" << endl;
|
||||
time = 5.;
|
||||
return false;
|
||||
}
|
||||
conn = local_conn;
|
||||
// sync clock
|
||||
sync_clock();
|
||||
return true;
|
||||
}
|
||||
time -= ClockObject::get_global_clock()->get_dt();
|
||||
return false;
|
||||
}
|
||||
if (cm.reset_connection_available()) {
|
||||
PT(Connection) local_conn;
|
||||
if (cm.get_reset_connection(local_conn)) {
|
||||
if (local_conn == conn) {
|
||||
cm.close_connection(conn);
|
||||
conn = (Connection*)0L;
|
||||
time = 5.;
|
||||
return false;
|
||||
} else
|
||||
deadrec_cat->error()
|
||||
<< "got a report of a closed connection that I've never heard of"
|
||||
<< endl;
|
||||
} else
|
||||
deadrec_cat->error()
|
||||
<< "a closed connection was reported, but none was listed" << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void event_frame(CPT_Event) {
|
||||
// send deadrec data
|
||||
if (verify_connection()) {
|
||||
NetDatagram d;
|
||||
send(add_time(add_pos(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;
|
||||
@ -472,6 +518,9 @@ static void deadrec_setup(EventHandler& eh) {
|
||||
smiley = ModelPool::load_model("smiley");
|
||||
nassertv(smiley != (Node*)0L);
|
||||
my_arc = new RenderRelation(render, smiley);
|
||||
|
||||
writer = new ConnectionWriter(&cm, 0);
|
||||
/*
|
||||
// open a connection to the receiver
|
||||
NetAddress host;
|
||||
if (!host.set_host(hostname, hostport)) {
|
||||
@ -488,6 +537,7 @@ static void deadrec_setup(EventHandler& eh) {
|
||||
<< " on port " << conn->get_address().get_port()
|
||||
<< " and IP " << conn->get_address() << endl;
|
||||
writer = new ConnectionWriter(&cm, 0);
|
||||
*/
|
||||
|
||||
// create an interface
|
||||
GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
|
||||
@ -542,9 +592,6 @@ 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user