瀏覽代碼

support output of event parameter, spam in data graph

David Rose 23 年之前
父節點
當前提交
bddbd6788b

+ 42 - 0
panda/src/dgraph/dataNode.cxx

@@ -58,7 +58,49 @@ transmit_data(const DataNodeTransmit inputs[],
     new_input.set_data(connect._input_index, data);
   }
 
+#ifndef NDEBUG
+  if (dgraph_cat.is_spam()) {
+    bool any_data = false;
+    Wires::const_iterator wi;
+    for (wi = _input_wires.begin(); wi != _input_wires.end(); ++wi) {
+      const string &name = (*wi).first;
+      const WireDef &def = (*wi).second;
+      if (new_input.has_data(def._index)) {
+        if (!any_data) {
+          dgraph_cat.spam()
+            << *this << " receives:\n";
+          any_data = true;
+        }
+        dgraph_cat.spam(false) 
+          << "  " << name << " = " << new_input.get_data(def._index)
+          << "\n";
+      }
+    }
+  }
+#endif  // NDEBUG
+
   do_transmit_data(new_input, output);
+
+#ifndef NDEBUG
+  if (dgraph_cat.is_spam()) {
+    bool any_data = false;
+    Wires::const_iterator wi;
+    for (wi = _output_wires.begin(); wi != _output_wires.end(); ++wi) {
+      const string &name = (*wi).first;
+      const WireDef &def = (*wi).second;
+      if (output.has_data(def._index)) {
+        if (!any_data) {
+          dgraph_cat.spam()
+            << *this << " transmits:\n";
+          any_data = true;
+        }
+        dgraph_cat.spam(false) 
+          << "  " << name << " = " << output.get_data(def._index)
+          << "\n";
+      }
+    }
+  }
+#endif  // NDEBUG
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
panda/src/event/config_event.cxx

@@ -29,6 +29,7 @@ NotifyCategoryDef(event, "");
 ConfigureFn(config_event) {
   Event::init_type();
   EventHandler::init_type();
+  EventStoreValueBase::init_type();
   EventStoreInt::init_type("EventStoreInt");
   EventStoreDouble::init_type("EventStoreDouble");
   EventStoreString::init_type("EventStoreString");

+ 17 - 0
panda/src/event/eventParameter.I

@@ -200,6 +200,12 @@ get_ptr() const {
   return _ptr;
 }
 
+INLINE ostream &
+operator << (ostream &out, const EventParameter &param) {
+  param.output(out);
+  return out;
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: EventStoreValue::set_value
@@ -225,3 +231,14 @@ INLINE const Type &EventStoreValue<Type>::
 get_value() const {
   return _value;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventStoreValue::output
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+template<class Type>
+void EventStoreValue<Type>::
+output(ostream &out) const {
+  out << _value;
+}

+ 23 - 0
panda/src/event/eventParameter.cxx

@@ -17,8 +17,31 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "eventParameter.h"
+#include "dcast.h"
 
 // Tell GCC that we'll take care of the instantiation explicitly here.
 #ifdef __GNUC__
 #pragma implementation
 #endif
+
+TypeHandle EventStoreValueBase::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventParameter::output
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void EventParameter::
+output(ostream &out) const {
+  if (_ptr == (TypedReferenceCount *)NULL) {
+    out << "(empty)";
+
+  } else if (_ptr->is_of_type(EventStoreValueBase::get_class_type())) {
+    const EventStoreValueBase *sv_ptr;
+    DCAST_INTO_V(sv_ptr, _ptr);
+    sv_ptr->output(out);
+
+  } else {
+    out << _ptr->get_type();
+  }
+}

+ 36 - 3
panda/src/event/eventParameter.h

@@ -62,10 +62,41 @@ PUBLISHED:
 
   INLINE const TypedReferenceCount *get_ptr() const;
 
+  void output(ostream &out) const;
+
 private:
   CPT(TypedReferenceCount) _ptr;
 };
 
+INLINE ostream &operator << (ostream &out, const EventParameter &param);
+
+////////////////////////////////////////////////////////////////////
+//       Class : EventStoreValueBase
+// Description : A non-template base class of EventStoreValue (below),
+//               which serves mainly to define the placeholder for the
+//               virtual output function.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAEXPRESS EventStoreValueBase : public TypedReferenceCount {
+public:
+  virtual void output(ostream &out) const=0;
+
+public:
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedReferenceCount::init_type();
+    register_type(_type_handle, "EventStoreValueBase",
+                  TypedReferenceCount::get_class_type());
+  }
+
+private:
+  static TypeHandle _type_handle;
+};
 
 ////////////////////////////////////////////////////////////////////
 //       Class : EventStoreValue
@@ -77,13 +108,15 @@ private:
 //               EventParameter.
 ////////////////////////////////////////////////////////////////////
 template<class Type>
-class EventStoreValue : public TypedReferenceCount {
+class EventStoreValue : public EventStoreValueBase {
 public:
   EventStoreValue(const Type &value) : _value(value) { }
 
   INLINE void set_value(const Type &value);
   INLINE const Type &get_value() const;
 
+  virtual void output(ostream &out) const;
+
   Type _value;
 
 public:
@@ -91,9 +124,9 @@ public:
     return _type_handle;
   }
   static void init_type(const string &type_name = "UndefinedEventStoreValue") {
-    TypedReferenceCount::init_type();
+    EventStoreValueBase::init_type();
     _type_handle = register_dynamic_type
-      (type_name, TypedReferenceCount::get_class_type());
+      (type_name, EventStoreValueBase::get_class_type());
   }
   virtual TypeHandle get_type() const {
     return get_class_type();

+ 1 - 2
panda/src/pgraph/config_pgraph.cxx

@@ -226,8 +226,7 @@ init_libpgraph() {
   PosHprScaleLerpFunctor::init_type();
   ColorLerpFunctor::init_type();
   ColorScaleLerpFunctor::init_type();
-
-  EventStoreTransform::init_type("EventStoreTransform");
+  EventStoreTransform::init_type();
 
   AlphaTestAttrib::register_with_read_factory();
   AmbientLight::register_with_read_factory();

+ 31 - 0
panda/src/pgraph/transformState.I

@@ -498,3 +498,34 @@ is_destructing() const {
   return false;
 #endif
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventStoreTransform::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE EventStoreTransform::
+EventStoreTransform(const TransformState *value) :
+  _value(value)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventStoreTransform::set_value
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE void EventStoreTransform::
+set_value(const TransformState *value) {
+  _value = value;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventStoreTransform::get_value
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE const TransformState *EventStoreTransform::
+get_value() const {
+  return _value;
+}

+ 11 - 0
panda/src/pgraph/transformState.cxx

@@ -27,6 +27,7 @@
 TransformState::States *TransformState::_states = NULL;
 CPT(TransformState) TransformState::_identity_state;
 TypeHandle TransformState::_type_handle;
+TypeHandle EventStoreTransform::_type_handle;
 
 ////////////////////////////////////////////////////////////////////
 //     Function: TransformState::Constructor
@@ -1291,3 +1292,13 @@ fillin(DatagramIterator &scan, BamReader *manager) {
     }
   }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: EventStoreTransform::output
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void EventStoreTransform::
+output(ostream &out) const {
+  out << *_value;
+}

+ 32 - 4
panda/src/pgraph/transformState.h

@@ -230,11 +230,39 @@ INLINE ostream &operator << (ostream &out, const TransformState &state) {
   return out;
 }
 
-// This class is used to pass TransformState pointers as parameters to
-// events, or as elements on a data graph.
-EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, EventStoreValue< CPT(TransformState) >);
 
-typedef EventStoreValue<CPT(TransformState)> EventStoreTransform;
+////////////////////////////////////////////////////////////////////
+//       Class : EventStoreTransform
+// Description : This class is used to pass TransformState pointers as
+//               parameters to events, or as elements on a data graph.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA EventStoreTransform : public EventStoreValueBase {
+public:
+  INLINE EventStoreTransform(const TransformState *value);
+  INLINE void set_value(const TransformState *value);
+  INLINE const TransformState *get_value() const;
+
+  virtual void output(ostream &out) const;
+
+  CPT(TransformState) _value;
+
+public:
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    EventStoreValueBase::init_type();
+    register_type(_type_handle, "EventStoreTransform",
+                  EventStoreValueBase::get_class_type());
+  }
+
+private:
+  static TypeHandle _type_handle;
+};
 
 #include "transformState.I"
 

+ 1 - 1
panda/src/putil/Sources.pp

@@ -1,6 +1,6 @@
 #define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
                   dtoolutil:c dtoolbase:c dtool:m
-#define LOCAL_LIBS express pandabase
+#define LOCAL_LIBS express event pandabase
 
 #begin lib_target
   #define TARGET putil

+ 15 - 3
panda/src/putil/buttonEventList.cxx

@@ -39,12 +39,24 @@ update_mods(ModifierButtons &mods) const {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: ButtonEventList::output
-//       Access: Public
+//       Access: Public, Virtual
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 void ButtonEventList::
 output(ostream &out) const {
-  out << get_type() << " (" << get_num_events() << " events)";
+  if (_events.empty()) {
+    out << "(no buttons)";
+  } else {
+    Events::const_iterator ei;
+    ei = _events.begin();
+    out << "(" << (*ei);
+    ++ei;
+    while (ei != _events.end()) {
+      out << " " << (*ei);
+      ++ei;
+    }
+    out << ")";
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -54,7 +66,7 @@ output(ostream &out) const {
 ////////////////////////////////////////////////////////////////////
 void ButtonEventList::
 write(ostream &out, int indent_level) const {
-  indent(out, indent_level) << *this << ":\n";
+  indent(out, indent_level) << _events.size() << " events:\n";
   Events::const_iterator ei;
   for (ei = _events.begin(); ei != _events.end(); ++ei) {
     indent(out, indent_level + 2) << (*ei) << "\n";

+ 5 - 4
panda/src/putil/buttonEventList.h

@@ -23,6 +23,7 @@
 
 #include "buttonEvent.h"
 #include "typedReferenceCount.h"
+#include "eventParameter.h"
 #include "pvector.h"
 
 class ModifierButtons;
@@ -35,7 +36,7 @@ class ModifierButtons;
 //               but it may be used anywhere a list of ButtonEvents
 //               is desired.
 ////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA ButtonEventList : public TypedReferenceCount {
+class EXPCL_PANDA ButtonEventList : public EventStoreValueBase {
 public:
   INLINE ButtonEventList();
 
@@ -46,7 +47,7 @@ public:
 
   void update_mods(ModifierButtons &mods) const;
 
-  void output(ostream &out) const;
+  virtual void output(ostream &out) const;
   void write(ostream &out, int indent_level = 0) const;
 
 private:
@@ -58,9 +59,9 @@ public:
     return _type_handle;
   }
   static void init_type() {
-    TypedReferenceCount::init_type();
+    EventStoreValueBase::init_type();
     register_type(_type_handle, "ButtonEventList",
-                  TypedReferenceCount::get_class_type());
+                  EventStoreValueBase::get_class_type());
   }
   virtual TypeHandle get_type() const {
     return get_class_type();