From 72eb435729dc1c159880d4e7203e8825bdffe65a Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Mon, 27 Nov 2000 22:47:25 +0000 Subject: [PATCH] more updates --- panda/src/testbed/Sources.pp | 4 +- panda/src/testbed/deadrec_send.cxx | 285 ++++++++++++++++++++++++----- 2 files changed, 245 insertions(+), 44 deletions(-) diff --git a/panda/src/testbed/Sources.pp b/panda/src/testbed/Sources.pp index fc0d0e88ce..8b6d24e6f4 100644 --- a/panda/src/testbed/Sources.pp +++ b/panda/src/testbed/Sources.pp @@ -147,7 +147,7 @@ #define SOURCES \ deadrec_rec.cxx - #define LOCAL_LIBS $[LOCAL_LIBS] net + #define LOCAL_LIBS $[LOCAL_LIBS] net gui #end test_bin_target #begin test_bin_target @@ -156,5 +156,5 @@ #define SOURCES \ deadrec_send.cxx - #define LOCAL_LIBS $[LOCAL_LIBS] net lerp + #define LOCAL_LIBS $[LOCAL_LIBS] net lerp gui #end test_bin_target diff --git a/panda/src/testbed/deadrec_send.cxx b/panda/src/testbed/deadrec_send.cxx index fa5919aeb0..e5d3b6b3db 100644 --- a/panda/src/testbed/deadrec_send.cxx +++ b/panda/src/testbed/deadrec_send.cxx @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #include @@ -60,31 +63,14 @@ static void event_frame(CPT_Event) { send(add_pos(d)); } -static void deadrec_setup(void) { - static bool done = false; - if (done) - return; - // load smiley and put it in the scenegraph - smiley = ModelPool::load_model("smiley"); - nassertv(smiley != (Node*)0L); - my_arc = new RenderRelation(render, smiley); - // open a connection to the receiver - NetAddress host; - if (!host.set_host(hostname, hostport)) { - deadrec_cat->fatal() << "Unknown host: " << hostname << endl; - exit(0); - } - conn = cm.open_TCP_client_connection(host, 5000); - if (conn.is_null()) { - deadrec_cat->fatal() << "no connection." << endl; - exit(0); - } - if (deadrec_cat->is_debug()) - deadrec_cat->debug() << "opened TCP connection to " << hostname - << " on port " << conn->get_address().get_port() - << " and IP " << conn->get_address() << endl; - writer = new ConnectionWriter(&cm, 0); -} +enum MotionType { M_None, M_Line, M_SLine, M_Box, M_Circle, M_Random }; +PT(AutonomousLerp) curr_lerp; +MotionType curr_type; +PT(GuiButton) lineButton; +PT(GuiButton) slineButton; +PT(GuiButton) boxButton; +PT(GuiButton) circleButton; +PT(GuiButton) randomButton; // the various motion generators @@ -93,10 +79,6 @@ void update_smiley(void) { my_arc->set_transition(new TransformTransition(mat)); } -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, @@ -127,30 +109,94 @@ private: }; TypeHandle MyPosFunctor::_type_handle; -static void run_line(void) { +static void init_funcs(void) { static bool inited = false; - static bool where = false; - if (!inited) { MyPosFunctor::init_type(); inited = true; } +} + +static void run_line(bool smooth) { + static bool where = false; + LerpBlendType* blend; + + init_funcs(); + if (smooth) + blend = new EaseInOutBlendType(); + else + blend = new NoBlendType(); if (where) { curr_lerp = new AutonomousLerp(new MyPosFunctor(my_pos, LPoint3f::rfu(10., 0., 0.)), - 5., new NoBlendType(), &event_handler); + 5., blend, &event_handler); curr_lerp->set_end_event("lerp_done"); curr_lerp->start(); } else { curr_lerp = new AutonomousLerp(new MyPosFunctor(my_pos, LPoint3f::rfu(-10., 0., 0.)), - 5., new NoBlendType(), &event_handler); + 5., blend, &event_handler); curr_lerp->set_end_event("lerp_done"); curr_lerp->start(); } where = !where; } +static void run_box(bool smooth) { + static int where = 0; + LerpBlendType* blend; + + init_funcs(); + if (smooth) + blend = new EaseInOutBlendType(); + else + blend = new NoBlendType(); + switch (where) { + case 0: + curr_lerp = + new AutonomousLerp(new MyPosFunctor(my_pos, + LPoint3f::rfu(-10., 0., 10.)), + 5., blend, &event_handler); + where = 1; + break; + case 1: + curr_lerp = + new AutonomousLerp(new MyPosFunctor(my_pos, LPoint3f::rfu(10., 0., 10.)), + 5., blend, &event_handler); + where = 2; + break; + case 2: + curr_lerp = + new AutonomousLerp(new MyPosFunctor(my_pos, + LPoint3f::rfu(10., 0., -10.)), + 5., blend, &event_handler); + where = 3; + break; + case 3: + curr_lerp = + new AutonomousLerp(new MyPosFunctor(my_pos, + LPoint3f::rfu(-10., 0., -10.)), + 5., blend, &event_handler); + where = 0; + break; + default: + deadrec_cat->error() << "I'm a tard and box::where got out of range (" + << where << ")" << endl; + where = 0; + run_box(smooth); + } + curr_lerp->set_end_event("lerp_done"); + curr_lerp->start(); +} + +static void run_circle(bool smooth) { + init_funcs(); +} + +static void run_random(bool smooth) { + init_funcs(); +} + static void handle_lerp(void) { if (curr_lerp != (AutonomousLerp*)0L) curr_lerp->stop(); @@ -159,13 +205,19 @@ static void handle_lerp(void) { case M_None: break; case M_Line: - run_line(); + run_line(false); + break; + case M_SLine: + run_line(true); break; case M_Box: + run_box(false); break; case M_Circle: + run_circle(false); break; case M_Random: + run_random(false); break; default: deadrec_cat->error() << "unknown motion type (" << (int)curr_type << ")" @@ -173,20 +225,169 @@ static void handle_lerp(void) { } } +static void make_active(void) { + switch (curr_type) { + case M_None: + break; + case M_Line: + lineButton->up(); + break; + case M_SLine: + slineButton->up(); + break; + case M_Box: + boxButton->up(); + break; + case M_Circle: + circleButton->up(); + break; + case M_Random: + randomButton->up(); + break; + default: + deadrec_cat->error() <<" unknown motion type (" << (int)curr_type << ")" + << endl; + } +} + +static void event_button_down(CPT_Event e) { + string s = e->get_name(); + s = s.substr(0, s.find("-down")); + if (s == "line") { + if (curr_type != M_Line) { + make_active(); + curr_type = M_Line; + handle_lerp(); + lineButton->inactive(); + } + } else if (s == "s-line") { + if (curr_type != M_SLine) { + make_active(); + curr_type = M_SLine; + handle_lerp(); + slineButton->inactive(); + } + } else if (s == "box") { + if (curr_type != M_Box) { + make_active(); + curr_type = M_Box; + handle_lerp(); + boxButton->inactive(); + } + } else if (s == "circle") { + if (curr_type != M_Circle) { + make_active(); + curr_type = M_Circle; + handle_lerp(); + circleButton->inactive(); + } + } else if (s == "random") { + if (curr_type != M_Random) { + make_active(); + curr_type = M_Random; + handle_lerp(); + randomButton->inactive(); + } + } else { + deadrec_cat->error() << "got invalid button event '" << s << "'" << endl; + } +} + +static inline GuiButton* make_button(const string& name, Node* font, + EventHandler& eh) { + 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", event_button_down); + eh.add_hook(name + "-down-rollover", event_button_down); + return b1; +} + +static void deadrec_setup(EventHandler& eh) { + static bool done = false; + if (done) + return; + // load smiley and put it in the scenegraph + smiley = ModelPool::load_model("smiley"); + nassertv(smiley != (Node*)0L); + my_arc = new RenderRelation(render, smiley); + // open a connection to the receiver + NetAddress host; + if (!host.set_host(hostname, hostport)) { + deadrec_cat->fatal() << "Unknown host: " << hostname << endl; + exit(0); + } + conn = cm.open_TCP_client_connection(host, 5000); + if (conn.is_null()) { + deadrec_cat->fatal() << "no connection." << endl; + exit(0); + } + if (deadrec_cat->is_debug()) + deadrec_cat->debug() << "opened TCP connection to " << hostname + << " 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); + PT_Node font = ModelPool::load_model("ttf-comic"); + GuiFrame* f1 = new GuiFrame("motions"); + GuiLabel* l1 = GuiLabel::make_simple_text_label("motion:", font); + l1->set_background_color(1., 1., 1., 0.); + GuiSign* s1 = new GuiSign("motion", l1); + s1->set_scale(0.08); + f1->add_item(s1); + lineButton = make_button("line", font, eh); + lineButton->set_scale(0.08); + f1->add_item(lineButton); + slineButton = make_button("s-line", font, eh); + slineButton->set_scale(0.08); + f1->add_item(slineButton); + boxButton = make_button("box", font, eh); + boxButton->set_scale(0.08); + f1->add_item(boxButton); + circleButton = make_button("circle", font, eh); + circleButton->set_scale(0.08); + f1->add_item(circleButton); + randomButton = make_button("random", font, eh); + randomButton->set_scale(0.08); + f1->add_item(randomButton); + f1->pack_item(lineButton, GuiFrame::UNDER, s1); + f1->pack_item(lineButton, GuiFrame::ALIGN_LEFT, s1); + f1->pack_item(slineButton, GuiFrame::UNDER, s1); + f1->pack_item(slineButton, GuiFrame::RIGHT, lineButton, 0.02); + f1->pack_item(boxButton, GuiFrame::UNDER, s1); + f1->pack_item(boxButton, GuiFrame::RIGHT, slineButton, 0.02); + f1->pack_item(circleButton, GuiFrame::UNDER, s1); + f1->pack_item(circleButton, GuiFrame::RIGHT, boxButton, 0.02); + f1->pack_item(randomButton, GuiFrame::UNDER, s1); + f1->pack_item(randomButton, GuiFrame::RIGHT, circleButton, 0.02); + f1->set_pos(LVector3f::rfu(-0.1, 0., 0.9)); + f1->recompute(); + f1->manage(mgr, eh); +} + static void event_lerp(CPT_Event) { handle_lerp(); } -static void event_1(CPT_Event) { - curr_type = M_Line; - handle_lerp(); -} - static void deadrec_keys(EventHandler& eh) { - deadrec_setup(); + deadrec_setup(eh); eh.add_hook("NewFrame", event_frame); - eh.add_hook("1", event_1); eh.add_hook("lerp_done", event_lerp); }