mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
get it working more
This commit is contained in:
parent
f97a47558b
commit
57fda682f4
@ -85,7 +85,7 @@ LerpFunctor* Lerp::get_functor(void) const {
|
|||||||
return _func;
|
return _func;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lerp::set_end_event(std::string& event) {
|
void Lerp::set_end_event(const std::string& event) {
|
||||||
_event = event;
|
_event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ float AutonomousLerp::get_t(void) const {
|
|||||||
return _t;
|
return _t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutonomousLerp::set_end_event(std::string& event) {
|
void AutonomousLerp::set_end_event(const std::string& event) {
|
||||||
_event = event;
|
_event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ PUBLISHED:
|
|||||||
float get_t(void) const;
|
float get_t(void) const;
|
||||||
bool is_done(void) const;
|
bool is_done(void) const;
|
||||||
LerpFunctor* get_functor(void) const;
|
LerpFunctor* get_functor(void) const;
|
||||||
void set_end_event(std::string&);
|
void set_end_event(const std::string&);
|
||||||
std::string get_end_event(void) const;
|
std::string get_end_event(void) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -88,7 +88,7 @@ PUBLISHED:
|
|||||||
LerpFunctor* get_functor(void) const;
|
LerpFunctor* get_functor(void) const;
|
||||||
void set_t(float);
|
void set_t(float);
|
||||||
float get_t(void) const;
|
float get_t(void) const;
|
||||||
void set_end_event(std::string&);
|
void set_end_event(const std::string&);
|
||||||
std::string get_end_event(void) const;
|
std::string get_end_event(void) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <queuedConnectionListener.h>
|
#include <queuedConnectionListener.h>
|
||||||
#include <modelPool.h>
|
#include <modelPool.h>
|
||||||
#include <ipc_thread.h>
|
#include <ipc_thread.h>
|
||||||
|
#include <transformTransition.h>
|
||||||
|
|
||||||
#include <dconfig.h>
|
#include <dconfig.h>
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ typedef set<PT(Connection)> Clients;
|
|||||||
|
|
||||||
static PT_Node smiley;
|
static PT_Node smiley;
|
||||||
static RenderRelation* my_arc;
|
static RenderRelation* my_arc;
|
||||||
|
static LPoint3f my_pos;
|
||||||
static int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead);
|
static int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead);
|
||||||
static thread* monitor;
|
static thread* monitor;
|
||||||
static bool stop_monitoring;
|
static bool stop_monitoring;
|
||||||
@ -32,6 +34,29 @@ QueuedConnectionManager cm;
|
|||||||
Clients clients;
|
Clients clients;
|
||||||
QueuedConnectionReader* reader;
|
QueuedConnectionReader* reader;
|
||||||
|
|
||||||
|
enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num };
|
||||||
|
|
||||||
|
static inline unsigned char* get_uint8(unsigned char* b, unsigned char& v) {
|
||||||
|
v = b[0];
|
||||||
|
return ++b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline unsigned char* get_float64(unsigned char* b, float& f) {
|
||||||
|
unsigned char t[8]; // 64-bits
|
||||||
|
memcpy(t, b, 8);
|
||||||
|
if (sizeof(float)==8) {
|
||||||
|
memcpy(&f, t, 8);
|
||||||
|
} else if (sizeof(double)==8) {
|
||||||
|
double d;
|
||||||
|
memcpy(&d, t, 8);
|
||||||
|
f = d;
|
||||||
|
} else {
|
||||||
|
deadrec_cat->error() << "neither float or double are 64-bit" << endl;
|
||||||
|
f = 0.;
|
||||||
|
}
|
||||||
|
return b+8;
|
||||||
|
}
|
||||||
|
|
||||||
static void* internal_monitor(void*) {
|
static void* internal_monitor(void*) {
|
||||||
if (deadrec_cat->is_debug())
|
if (deadrec_cat->is_debug())
|
||||||
deadrec_cat->debug() << "internal monitoring thread started" << endl;
|
deadrec_cat->debug() << "internal monitoring thread started" << endl;
|
||||||
@ -63,11 +88,32 @@ static void* internal_monitor(void*) {
|
|||||||
while (reader->data_available()) {
|
while (reader->data_available()) {
|
||||||
NetDatagram datagram;
|
NetDatagram datagram;
|
||||||
if (reader->get_data(datagram)) {
|
if (reader->get_data(datagram)) {
|
||||||
if (deadrec_cat->is_debug()) {
|
unsigned char* buff = (unsigned char*)(datagram.get_data());
|
||||||
deadrec_cat->debug() << "Got datagram ";
|
unsigned char byte;
|
||||||
datagram.dump_hex(deadrec_cat->debug(false));
|
TelemetryToken t;
|
||||||
deadrec_cat->debug(false) << " from " << datagram.get_address()
|
buff = get_uint8(buff, byte);
|
||||||
<< endl;
|
t = (TelemetryToken)byte;
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
case T_Vel:
|
||||||
|
if (deadrec_cat->is_debug())
|
||||||
|
deadrec_cat->debug() << "got T_Num" << endl;
|
||||||
|
break;
|
||||||
|
case T_Num:
|
||||||
|
if (deadrec_cat->is_debug())
|
||||||
|
deadrec_cat->debug() << "got T_Num" << endl;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
deadrec_cat->warning() << "got bad token in datagram (" << (int)t
|
||||||
|
<< ")" << endl;
|
||||||
|
}
|
||||||
|
buff = get_uint8(buff, byte);
|
||||||
|
t = (TelemetryToken)byte;
|
||||||
}
|
}
|
||||||
// unpack and deal with the datagram now
|
// unpack and deal with the datagram now
|
||||||
// DO THIS
|
// DO THIS
|
||||||
@ -107,8 +153,19 @@ static void deadrec_setup(void) {
|
|||||||
thread::PRIORITY_NORMAL);
|
thread::PRIORITY_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_smiley(void) {
|
||||||
|
LMatrix4f mat = LMatrix4f::translate_mat(my_pos);
|
||||||
|
my_arc->set_transition(new TransformTransition(mat));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void event_frame(CPT_Event) {
|
||||||
|
update_smiley();
|
||||||
|
}
|
||||||
|
|
||||||
static void deadrec_keys(EventHandler& eh) {
|
static void deadrec_keys(EventHandler& eh) {
|
||||||
deadrec_setup();
|
deadrec_setup();
|
||||||
|
|
||||||
|
eh.add_hook("NewFrame", event_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <renderRelation.h>
|
#include <renderRelation.h>
|
||||||
#include <queuedConnectionManager.h>
|
#include <queuedConnectionManager.h>
|
||||||
#include <modelPool.h>
|
#include <modelPool.h>
|
||||||
|
#include <transformTransition.h>
|
||||||
|
#include <lerp.h>
|
||||||
|
|
||||||
#include <dconfig.h>
|
#include <dconfig.h>
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ static QueuedConnectionManager cm;
|
|||||||
PT(Connection) conn;
|
PT(Connection) conn;
|
||||||
ConnectionWriter* writer;
|
ConnectionWriter* writer;
|
||||||
|
|
||||||
enum TelemetryToken { T_End, T_Pos, T_Vel, T_Num };
|
enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num };
|
||||||
|
|
||||||
static inline NetDatagram& add_pos(NetDatagram& d) {
|
static inline NetDatagram& add_pos(NetDatagram& d) {
|
||||||
d.add_uint8(T_Pos);
|
d.add_uint8(T_Pos);
|
||||||
@ -95,9 +97,8 @@ enum MotionType { M_None, M_Line, M_Box, M_Circle, M_Random };
|
|||||||
PT(AutonomousLerp) curr_lerp;
|
PT(AutonomousLerp) curr_lerp;
|
||||||
MotionType curr_type;
|
MotionType curr_type;
|
||||||
|
|
||||||
static void run_line(void) {
|
class MyPosFunctor : public LPoint3fLerpFunctor {
|
||||||
class MyPosFunctor : public LPoint3fLerpFunctor {
|
public:
|
||||||
public:
|
|
||||||
MyPosFunctor(LPoint3f start, LPoint3f end) : LPoint3fLerpFunctor(start,
|
MyPosFunctor(LPoint3f start, LPoint3f end) : LPoint3fLerpFunctor(start,
|
||||||
end) {}
|
end) {}
|
||||||
MyPosFunctor(const MyPosFunctor& p) : LPoint3fLerpFunctor(p) {}
|
MyPosFunctor(const MyPosFunctor& p) : LPoint3fLerpFunctor(p) {}
|
||||||
@ -108,7 +109,7 @@ static void run_line(void) {
|
|||||||
my_pos = p;
|
my_pos = p;
|
||||||
update_smiley();
|
update_smiley();
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
// type stuff
|
// type stuff
|
||||||
static TypeHandle get_class_type(void) { return _type_handle; }
|
static TypeHandle get_class_type(void) { return _type_handle; }
|
||||||
static void init_type(void) {
|
static void init_type(void) {
|
||||||
@ -121,10 +122,12 @@ static void run_line(void) {
|
|||||||
init_type();
|
init_type();
|
||||||
return get_class_type();
|
return get_class_type();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
static TypeHandle _type_handle;
|
static TypeHandle _type_handle;
|
||||||
};
|
};
|
||||||
static TypeHandle MyPosFunctor::_type_handle;
|
TypeHandle MyPosFunctor::_type_handle;
|
||||||
|
|
||||||
|
static void run_line(void) {
|
||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
static bool where = false;
|
static bool where = false;
|
||||||
|
|
||||||
@ -133,13 +136,15 @@ static void run_line(void) {
|
|||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
if (where) {
|
if (where) {
|
||||||
MyPosFunctor func(my_pos, LPoint3f:rfu(10., 0., 0.));
|
curr_lerp =
|
||||||
curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
|
new AutonomousLerp(new MyPosFunctor(my_pos, LPoint3f::rfu(10., 0., 0.)),
|
||||||
|
5., new NoBlendType(), &event_handler);
|
||||||
curr_lerp->set_end_event("lerp_done");
|
curr_lerp->set_end_event("lerp_done");
|
||||||
curr_lerp->start();
|
curr_lerp->start();
|
||||||
} else {
|
} else {
|
||||||
MyPosFunctor func(my_pos, LPoint3f:rfu(-10., 0., 0.));
|
curr_lerp =
|
||||||
curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
|
new AutonomousLerp(new MyPosFunctor(my_pos, LPoint3f::rfu(-10., 0., 0.)),
|
||||||
|
5., new NoBlendType(), &event_handler);
|
||||||
curr_lerp->set_end_event("lerp_done");
|
curr_lerp->set_end_event("lerp_done");
|
||||||
curr_lerp->start();
|
curr_lerp->start();
|
||||||
}
|
}
|
||||||
@ -147,6 +152,8 @@ static void run_line(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void handle_lerp(void) {
|
static void handle_lerp(void) {
|
||||||
|
if (curr_lerp != (AutonomousLerp*)0L)
|
||||||
|
curr_lerp->stop();
|
||||||
curr_lerp = (AutonomousLerp*)0L;
|
curr_lerp = (AutonomousLerp*)0L;
|
||||||
switch (curr_type) {
|
switch (curr_type) {
|
||||||
case M_None:
|
case M_None:
|
||||||
@ -161,7 +168,7 @@ static void handle_lerp(void) {
|
|||||||
case M_Random:
|
case M_Random:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
deadrec_cat->error() << "unknown motion type (" << curr_type << ")"
|
deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")"
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +178,7 @@ static void event_lerp(CPT_Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void event_1(CPT_Event) {
|
static void event_1(CPT_Event) {
|
||||||
curr_lerp = M_Line;
|
curr_type = M_Line;
|
||||||
handle_lerp();
|
handle_lerp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user