Cary Sandvig hace 25 años
padre
commit
28eb9f3092
Se han modificado 2 ficheros con 103 adiciones y 3 borrados
  1. 102 2
      panda/src/testbed/deadrec_rec.cxx
  2. 1 1
      panda/src/testbed/deadrec_send.cxx

+ 102 - 2
panda/src/testbed/deadrec_rec.cxx

@@ -10,6 +10,11 @@
 #include <modelPool.h>
 #include <ipc_thread.h>
 #include <transformTransition.h>
+#include <lerp.h>
+#include <guiFrame.h>
+#include <guiButton.h>
+#include <guiSign.h>
+#include <clockObject.h>
 
 #include <dconfig.h>
 
@@ -38,6 +43,17 @@ static bool doing_sync = false;
 static float my_time;
 
 enum TelemetryToken { T_End = 1, T_Pos, T_Vel, T_Num, T_Time, T_Sync };
+enum PredictToken { P_Null, P_Linear };
+enum CorrectToken { C_Pop, C_Lerp, C_Spline };
+
+PT(AutonomousLerp) curr_lerp;
+PredictToken curr_pred, pred_switch;
+CorrectToken curr_corr, corr_switch;
+PT(GuiButton) pnullButton;
+PT(GuiButton) plinearButton;
+PT(GuiButton) cpopButton;
+PT(GuiButton) clerpButton;
+PT(GuiButton) csplineButton;
 
 static inline unsigned char* get_uint8(unsigned char* b, unsigned char& v) {
   v = b[0];
@@ -119,6 +135,7 @@ static void* internal_monitor(void*) {
 	      buff = get_float64(buff, x);
 	      if (doing_sync) {
 		clock_skew = ClockObject::get_global_clock()->get_time() - x;
+		doing_sync = false;
 		cerr << "setting clock skew to: " << clock_skew << endl;
 	      } else
 		my_time = x + clock_skew;
@@ -147,7 +164,42 @@ static void* internal_monitor(void*) {
   return (void*)0L;
 }
 
-static void deadrec_setup(void) {
+static void predict_event(CPT_Event e) {
+  string s = e->get_name();
+  s = s.substr(0, s.find("-down"));
+}
+
+static void correct_event(CPT_Event e) {
+  string s = e->get_name();
+  s = s.substr(0, s.find("-down"));
+}
+
+typedef void event_func(CPT_Event);
+
+static inline GuiButton* make_button(const string& name, Node* font,
+				     EventHandler& eh, event_func func) {
+  GuiLabel* l1 = GuiLabel::make_simple_text_label(name, font);
+  GuiLabel* l2 = GuiLabel::make_simple_text_label(name, font);
+  GuiLabel* l3 = GuiLabel::make_simple_text_label(name, font);
+  GuiLabel* l4 = GuiLabel::make_simple_text_label(name, font);
+  GuiLabel* l5 = GuiLabel::make_simple_text_label(name, font);
+  // up
+  l1->set_background_color(1., 1., 1., 0.);
+  // up-rollover
+  l2->set_background_color(1., 1., 1., 0.5);
+  // down
+  l3->set_background_color(1., 1., 1., 0.);
+  // down-rollover
+  l4->set_background_color(1., 1., 1., 0.5);
+  // 'inactive'
+  l5->set_background_color(1., 0., 0., 0.7);
+  GuiButton* b1 = new GuiButton(name, l1, l2, l3, l4, l5);
+  eh.add_hook(name + "-down", func);
+  eh.add_hook(name + "-down-rollover", func);
+  return b1;
+}
+
+static void deadrec_setup(EventHandler& eh) {
   static bool done = false;
   if (done)
     return;
@@ -170,6 +222,54 @@ static void deadrec_setup(void) {
   stop_monitoring = false;
   monitor = thread::create(internal_monitor, (void*)0L,
 			   thread::PRIORITY_NORMAL);
+  // create an interface
+  GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
+  PT_Node font = ModelPool::load_model("ttf-comic");
+  GuiFrame* f1 = new GuiFrame("predicters");
+  GuiLabel* l1 = GuiLabel::make_simple_text_label("predicter:", font);
+  l1->set_background_color(1., 1., 1., 0.);
+  GuiSign* s1 = new GuiSign("predicter", l1);
+  s1->set_scale(0.08);
+  f1->add_item(s1);
+  pnullButton = make_button("null", font, eh, predict_event);
+  pnullButton->set_scale(0.08);
+  f1->add_item(pnullButton);
+  plinearButton = make_button("linear", font, eh, predict_event);
+  plinearButton->set_scale(0.08);
+  f1->add_item(plinearButton);
+  f1->pack_item(pnullButton, GuiFrame::UNDER, s1);
+  f1->pack_item(pnullButton, GuiFrame::ALIGN_LEFT, s1);
+  f1->pack_item(plinearButton, GuiFrame::UNDER, s1);
+  f1->pack_item(plinearButton, GuiFrame::RIGHT, pnullButton, 0.02);
+  f1->align_to_left(0.05);
+  f1->align_to_top(0.05);
+  f1->recompute();
+  f1->manage(mgr, eh);
+  GuiFrame* f2 = new GuiFrame("correctors");
+  GuiLabel* l2 = GuiLabel::make_simple_text_label("corrector:", font);
+  l2->set_background_color(1., 1., 1., 0.);
+  GuiSign* s2 = new GuiSign("corrector", l2);
+  s2->set_scale(0.08);
+  f2->add_item(s2);
+  cpopButton = make_button("pop", font, eh, correct_event);
+  cpopButton->set_scale(0.08);
+  f2->add_item(cpopButton);
+  clerpButton = make_button("lerp", font, eh, correct_event);
+  clerpButton->set_scale(0.08);
+  f2->add_item(clerpButton);
+  csplineButton = make_button("lerp", font, eh, correct_event);
+  csplineButton->set_scale(0.08);
+  f2->add_item(csplineButton);
+  f2->pack_item(cpopButton, GuiFrame::UNDER, s2);
+  f2->pack_item(cpopButton, GuiFrame::ALIGN_LEFT, s2);
+  f2->pack_item(clerpButton, GuiFrame::UNDER, s2);
+  f2->pack_item(clerpButton, GuiFrame::RIGHT, cpopButton, 0.02);
+  f2->pack_item(csplineButton, GuiFrame::UNDER, s2);
+  f2->pack_item(csplineButton, GuiFrame::RIGHT, clerpButton, 0.02);
+  f2->align_to_left(0.05);
+  f2->align_to_bottom(0.05);
+  f2->recompute();
+  f2->manage(mgr, eh);
 }
 
 static void update_smiley(void) {
@@ -182,7 +282,7 @@ static void event_frame(CPT_Event) {
 }
 
 static void deadrec_keys(EventHandler& eh) {
-  deadrec_setup();
+  deadrec_setup(eh);
 
   eh.add_hook("NewFrame", event_frame);
 }

+ 1 - 1
panda/src/testbed/deadrec_send.cxx

@@ -67,7 +67,7 @@ static inline void send(NetDatagram& d) {
 static void event_frame(CPT_Event) {
   // send deadrec data
   NetDatagram d;
-  send(add_pos(d));
+  send(add_time(add_pos(d)));
 }
 
 static void sync_clock(void) {