Cary Sandvig 25 лет назад
Родитель
Сommit
57fda682f4

+ 2 - 2
panda/src/lerp/lerp.cxx

@@ -85,7 +85,7 @@ LerpFunctor* Lerp::get_functor(void) const {
   return _func;
 }
 
-void Lerp::set_end_event(std::string& event) {
+void Lerp::set_end_event(const std::string& event) {
   _event = event;
 }
 
@@ -156,7 +156,7 @@ float AutonomousLerp::get_t(void) const {
   return _t;
 }
 
-void AutonomousLerp::set_end_event(std::string& event) {
+void AutonomousLerp::set_end_event(const std::string& event) {
   _event = event;
 }
 

+ 2 - 2
panda/src/lerp/lerp.h

@@ -37,7 +37,7 @@ PUBLISHED:
   float get_t(void) const;
   bool is_done(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;
 
 public:
@@ -88,7 +88,7 @@ PUBLISHED:
   LerpFunctor* get_functor(void) const;
   void set_t(float);
   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;
 
 public:

+ 62 - 5
panda/src/testbed/deadrec_rec.cxx

@@ -9,6 +9,7 @@
 #include <queuedConnectionListener.h>
 #include <modelPool.h>
 #include <ipc_thread.h>
+#include <transformTransition.h>
 
 #include <dconfig.h>
 
@@ -24,6 +25,7 @@ typedef set<PT(Connection)> Clients;
 
 static PT_Node smiley;
 static RenderRelation* my_arc;
+static LPoint3f my_pos;
 static int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead);
 static thread* monitor;
 static bool stop_monitoring;
@@ -32,6 +34,29 @@ QueuedConnectionManager cm;
 Clients clients;
 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*) {
   if (deadrec_cat->is_debug())
     deadrec_cat->debug() << "internal monitoring thread started" << endl;
@@ -63,11 +88,32 @@ static void* internal_monitor(void*) {
     while (reader->data_available()) {
       NetDatagram datagram;
       if (reader->get_data(datagram)) {
-	if (deadrec_cat->is_debug()) {
-	  deadrec_cat->debug() << "Got datagram ";
-	  datagram.dump_hex(deadrec_cat->debug(false));
-	  deadrec_cat->debug(false) << " from " << datagram.get_address()
-				    << endl;
+	unsigned char* buff = (unsigned char*)(datagram.get_data());
+	unsigned char byte;
+	TelemetryToken t;
+	buff = get_uint8(buff, byte);
+	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
 	// DO THIS
@@ -107,8 +153,19 @@ static void deadrec_setup(void) {
 			   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) {
   deadrec_setup();
+
+  eh.add_hook("NewFrame", event_frame);
 }
 
 int main(int argc, char* argv[]) {

+ 43 - 36
panda/src/testbed/deadrec_send.cxx

@@ -7,6 +7,8 @@
 #include <renderRelation.h>
 #include <queuedConnectionManager.h>
 #include <modelPool.h>
+#include <transformTransition.h>
+#include <lerp.h>
 
 #include <dconfig.h>
 
@@ -29,7 +31,7 @@ static QueuedConnectionManager cm;
 PT(Connection) conn;
 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) {
   d.add_uint8(T_Pos);
@@ -95,36 +97,37 @@ enum MotionType { M_None, M_Line, M_Box, M_Circle, M_Random };
 PT(AutonomousLerp) curr_lerp;
 MotionType curr_type;
 
+class MyPosFunctor : public LPoint3fLerpFunctor {
+public:
+  MyPosFunctor(LPoint3f start, LPoint3f end) : LPoint3fLerpFunctor(start,
+								   end) {}
+  MyPosFunctor(const MyPosFunctor& p) : LPoint3fLerpFunctor(p) {}
+  virtual ~MyPosFunctor(void) {}
+  virtual void operator()(float t) {
+    LPoint3f p = interpolate(t);
+    my_vel = p - my_pos;
+    my_pos = p;
+    update_smiley();
+  }
+public:
+  // type stuff
+  static TypeHandle get_class_type(void) { return _type_handle; }
+  static void init_type(void) {
+    LPoint3fLerpFunctor::init_type();
+    register_type(_type_handle, "MyPosFunctor",
+		  LPoint3fLerpFunctor::get_class_type());
+  }
+  virtual TypeHandle get_type(void) const { return get_class_type(); }
+  virtual TypeHandle force_init_type(void) {
+    init_type();
+    return get_class_type();
+  }
+private:
+  static TypeHandle _type_handle;
+};
+TypeHandle MyPosFunctor::_type_handle;
+
 static void run_line(void) {
-  class MyPosFunctor : public LPoint3fLerpFunctor {
-  public:
-    MyPosFunctor(LPoint3f start, LPoint3f end) : LPoint3fLerpFunctor(start,
-								     end) {}
-    MyPosFunctor(const MyPosFunctor& p) : LPoint3fLerpFunctor(p) {}
-    virtual ~MyPosFunctor(void) {}
-    virtual void operator()(float t) {
-      LPoint3f p = interpolate(t);
-      my_vel = p - my_pos;
-      my_pos = p;
-      update_smiley();
-    }
-  public:
-    // type stuff
-    static TypeHandle get_class_type(void) { return _type_handle; }
-    static void init_type(void) {
-      LPoint3fLerpFunctor::init_type();
-      register_type(_type_handle, "MyPosFunctor",
-		    LPoint3fLerpFunctor::get_class_type());
-    }
-    virtual TypeHandle get_type(void) const { return get_class_type(); }
-    virtual TypeHandle force_init_type(void) {
-      init_type();
-      return get_class_type();
-    }
-  private:
-    static TypeHandle _type_handle;
-  };
-  static TypeHandle MyPosFunctor::_type_handle;
   static bool inited = false;
   static bool where = false;
 
@@ -133,13 +136,15 @@ static void run_line(void) {
     inited = true;
   }
   if (where) {
-    MyPosFunctor func(my_pos, LPoint3f:rfu(10., 0., 0.));
-    curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
+    curr_lerp =
+      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->start();
   } else {
-    MyPosFunctor func(my_pos, LPoint3f:rfu(-10., 0., 0.));
-    curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
+    curr_lerp =
+      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->start();
   }
@@ -147,6 +152,8 @@ static void run_line(void) {
 }
 
 static void handle_lerp(void) {
+  if (curr_lerp != (AutonomousLerp*)0L)
+    curr_lerp->stop();
   curr_lerp = (AutonomousLerp*)0L;
   switch (curr_type) {
   case M_None:
@@ -161,7 +168,7 @@ static void handle_lerp(void) {
   case M_Random:
     break;
   default:
-    deadrec_cat->error() << "unknown motion type (" << curr_type << ")"
+    deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")"
 			 << endl;
   }
 }
@@ -171,7 +178,7 @@ static void event_lerp(CPT_Event) {
 }
 
 static void event_1(CPT_Event) {
-  curr_lerp = M_Line;
+  curr_type = M_Line;
   handle_lerp();
 }