Browse Source

mine-detected bugfixes

David Rose 24 years ago
parent
commit
8089e93eb4

+ 4 - 1
panda/src/device/buttonNode.cxx

@@ -119,7 +119,10 @@ transmit_data(AllTransitionsWrapper &data) {
   if (is_valid()) {
   if (is_valid()) {
     _button->poll();
     _button->poll();
     _button->lock();
     _button->lock();
-    (*_button_events) = (*_button->get_button_events());
+
+    // We can no longer copy these in the old scene graph.
+    //    (*_button_events) = (*_button->get_button_events());
+
     _button->get_button_events()->clear();
     _button->get_button_events()->clear();
     _button->unlock();
     _button->unlock();
 
 

+ 1 - 0
panda/src/device/buttonNode.h

@@ -26,6 +26,7 @@
 
 
 #include <dataNode.h>
 #include <dataNode.h>
 #include <allTransitionsWrapper.h>
 #include <allTransitionsWrapper.h>
+#include <buttonEventDataTransition.h>
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
panda/src/device/clientButtonDevice.I

@@ -122,7 +122,7 @@ is_button_known(int index) const {
 //               This must be periodically cleared, or the buttons
 //               This must be periodically cleared, or the buttons
 //               will accumulate.
 //               will accumulate.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE ButtonEventDataTransition *ClientButtonDevice::
+INLINE ButtonEventList *ClientButtonDevice::
 get_button_events() const {
 get_button_events() const {
   return _button_events;
   return _button_events;
 }
 }

+ 3 - 3
panda/src/device/clientButtonDevice.cxx

@@ -19,7 +19,7 @@
 
 
 #include "clientButtonDevice.h"
 #include "clientButtonDevice.h"
 
 
-#include <indent.h>
+#include "indent.h"
 
 
 TypeHandle ClientButtonDevice::_type_handle;
 TypeHandle ClientButtonDevice::_type_handle;
 
 
@@ -32,7 +32,7 @@ ClientButtonDevice::
 ClientButtonDevice(ClientBase *client, const string &device_name):
 ClientButtonDevice(ClientBase *client, const string &device_name):
   ClientDevice(client, get_class_type(), device_name)
   ClientDevice(client, get_class_type(), device_name)
 {
 {
-  _button_events = new ButtonEventDataTransition();
+  _button_events = new ButtonEventList();
 }
 }
 
 
 
 
@@ -53,7 +53,7 @@ set_button_state(int index, bool down) {
 
 
   ButtonHandle handle = _buttons[index]._handle;
   ButtonHandle handle = _buttons[index]._handle;
   if (handle != ButtonHandle::none()) {
   if (handle != ButtonHandle::none()) {
-    _button_events->push_back(ButtonEvent(handle, down ? ButtonEvent::T_down : ButtonEvent::T_up));
+    _button_events->add_event(ButtonEvent(handle, down ? ButtonEvent::T_down : ButtonEvent::T_up));
   }
   }
 }
 }
 
 

+ 7 - 7
panda/src/device/clientButtonDevice.h

@@ -19,14 +19,14 @@
 #ifndef CLIENTBUTTONDEVICE_H
 #ifndef CLIENTBUTTONDEVICE_H
 #define CLIENTBUTTONDEVICE_H
 #define CLIENTBUTTONDEVICE_H
 
 
-#include <pandabase.h>
+#include "pandabase.h"
 
 
 #include "clientDevice.h"
 #include "clientDevice.h"
 
 
-#include <buttonHandle.h>
-#include <buttonEvent.h>
-#include <buttonEventDataTransition.h>
-#include <pointerTo.h>
+#include "buttonHandle.h"
+#include "buttonEvent.h"
+#include "buttonEventList.h"
+#include "pointerTo.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : ClientButtonDevice
 //       Class : ClientButtonDevice
@@ -52,7 +52,7 @@ public:
   INLINE bool get_button_state(int index) const;
   INLINE bool get_button_state(int index) const;
   INLINE bool is_button_known(int index) const;
   INLINE bool is_button_known(int index) const;
 
 
-  INLINE ButtonEventDataTransition *get_button_events() const;
+  INLINE ButtonEventList *get_button_events() const;
 
 
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, int indent_level = 0) const;
   virtual void write(ostream &out, int indent_level = 0) const;
@@ -81,7 +81,7 @@ protected:
   typedef pvector<ButtonState> Buttons;
   typedef pvector<ButtonState> Buttons;
   Buttons _buttons;
   Buttons _buttons;
 
 
-  PT(ButtonEventDataTransition) _button_events;
+  PT(ButtonEventList) _button_events;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {

+ 1 - 2
panda/src/device/qpbuttonNode.cxx

@@ -120,8 +120,7 @@ do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
     _button->poll();
     _button->poll();
     _button->lock();
     _button->lock();
 
 
-    // *** here we should copy the button events from the ClientButtonDevice.
-    //    (*_button_events) = (*_button->get_button_events());
+    (*_button_events) = (*_button->get_button_events());
 
 
     _button->get_button_events()->clear();
     _button->get_button_events()->clear();
     _button->unlock();
     _button->unlock();

+ 2 - 2
panda/src/pgraph/qpnodePath.I

@@ -376,7 +376,7 @@ ls(ostream &out, int indent_level) const {
 //       Access: Published
 //       Access: Published
 //  Description: Returns the complete state object set on this node.
 //  Description: Returns the complete state object set on this node.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE CPT(RenderState) qpNodePath::
+INLINE const RenderState *qpNodePath::
 get_state() const {
 get_state() const {
   nassertr_always(!is_empty(), RenderState::make_empty());
   nassertr_always(!is_empty(), RenderState::make_empty());
   return node()->get_state();
   return node()->get_state();
@@ -409,7 +409,7 @@ get_net_state() const {
 //       Access: Published
 //       Access: Published
 //  Description: Returns the complete transform object set on this node.
 //  Description: Returns the complete transform object set on this node.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE CPT(TransformState) qpNodePath::
+INLINE const TransformState *qpNodePath::
 get_transform() const {
 get_transform() const {
   nassertr_always(!is_empty(), TransformState::make_identity());
   nassertr_always(!is_empty(), TransformState::make_identity());
   return node()->get_transform();
   return node()->get_transform();

+ 131 - 37
panda/src/pgraph/qpnodePath.cxx

@@ -141,7 +141,7 @@ get_children() const {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: qoNodePath::find
+//     Function: qpNodePath::find
 //       Access: Published
 //       Access: Published
 //  Description: Searches for a node below the referenced node that
 //  Description: Searches for a node below the referenced node that
 //               matches the indicated string.  Returns the shortest
 //               matches the indicated string.  Returns the shortest
@@ -162,6 +162,30 @@ find(const string &path) const {
   return col.get_path(0);
   return col.get_path(0);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpNodePath::find_path_to
+//       Access: Published
+//  Description: Searches for the indicated node below this node and
+//               returns the shortest NodePath that connects them.
+////////////////////////////////////////////////////////////////////
+qpNodePath qpNodePath::
+find_path_to(PandaNode *node) const {
+  nassertr_always(!is_empty(), fail());
+  nassertr(node != (PandaNode *)NULL, fail());
+
+  qpNodePathCollection col;
+  qpFindApproxPath approx_path;
+  approx_path.add_match_many(0);
+  approx_path.add_match_pointer(node, 0);
+  find_matches(col, approx_path, 1);
+
+  if (col.is_empty()) {
+    return qpNodePath::not_found();
+  }
+
+  return col.get_path(0);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: qpNodePath::find_all_matches
 //     Function: qpNodePath::find_all_matches
 //       Access: Published
 //       Access: Published
@@ -863,7 +887,25 @@ heads_up(const LPoint3f &point, const LVector3f &up) {
 void qpNodePath::
 void qpNodePath::
 set_pos(const qpNodePath &other, const LVecBase3f &pos) {
 set_pos(const qpNodePath &other, const LVecBase3f &pos) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  set_transform(other, get_transform(other)->set_pos(pos));
+  CPT(TransformState) rel_transform = get_transform(other);
+
+  CPT(TransformState) orig_transform = get_transform();
+  if (orig_transform->has_components()) {
+    // If we had a componentwise transform before we started, we
+    // should be careful to preserve the other two components.  We
+    // wouldn't need to do this, except for the possibility of
+    // numerical error or decompose ambiguity.
+    const LVecBase3f &orig_hpr = orig_transform->get_hpr();
+    const LVecBase3f &orig_scale = orig_transform->get_scale();
+
+    set_transform(other, rel_transform->set_pos(pos));
+    set_pos_hpr_scale(get_transform()->get_pos(), orig_hpr, orig_scale);
+
+  } else {
+    // If we didn't have a componentwise transform already, never
+    // mind.
+    set_transform(other, rel_transform->set_pos(pos));
+  }
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
@@ -911,39 +953,53 @@ get_pos(const qpNodePath &other) const {
 void qpNodePath::
 void qpNodePath::
 set_hpr(const qpNodePath &other, const LVecBase3f &hpr) {
 set_hpr(const qpNodePath &other, const LVecBase3f &hpr) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  set_transform(other, transform->set_hpr(hpr));
+  CPT(TransformState) rel_transform = get_transform(other);
+  nassertv(rel_transform->has_components());
+
+  CPT(TransformState) orig_transform = get_transform();
+  if (orig_transform->has_components()) {
+    // If we had a componentwise transform before we started, we
+    // should be careful to preserve the other two components.  We
+    // wouldn't need to do this, except for the possibility of
+    // numerical error or decompose ambiguity.
+    const LVecBase3f &orig_pos = orig_transform->get_pos();
+    const LVecBase3f &orig_scale = orig_transform->get_scale();
+
+    set_transform(other, rel_transform->set_hpr(hpr));
+    const TransformState *new_transform = get_transform();
+    if (new_transform->has_components()) {
+      set_pos_hpr_scale(orig_pos, new_transform->get_hpr(), orig_scale);
+    }
+
+  } else {
+    // If we didn't have a componentwise transform already, never
+    // mind.
+    set_transform(other, rel_transform->set_hpr(hpr));
+  }
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_h(const qpNodePath &other, float h) {
 set_h(const qpNodePath &other, float h) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f hpr = transform->get_hpr();
+  LVecBase3f hpr = get_hpr(other);
   hpr[0] = h;
   hpr[0] = h;
-  set_transform(other, transform->set_hpr(hpr));
+  set_hpr(other, hpr);
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_p(const qpNodePath &other, float p) {
 set_p(const qpNodePath &other, float p) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f hpr = transform->get_hpr();
+  LVecBase3f hpr = get_hpr(other);
   hpr[1] = p;
   hpr[1] = p;
-  set_transform(other, transform->set_hpr(hpr));
+  set_hpr(other, hpr);
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_r(const qpNodePath &other, float r) {
 set_r(const qpNodePath &other, float r) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f hpr = transform->get_hpr();
+  LVecBase3f hpr = get_hpr(other);
   hpr[2] = r;
   hpr[2] = r;
-  set_transform(other, transform->set_hpr(hpr));
+  set_hpr(other, hpr);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -985,39 +1041,53 @@ get_hpr(const qpNodePath &other, float roll) const {
 void qpNodePath::
 void qpNodePath::
 set_scale(const qpNodePath &other, const LVecBase3f &scale) {
 set_scale(const qpNodePath &other, const LVecBase3f &scale) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  set_transform(other, transform->set_scale(scale));
+  CPT(TransformState) rel_transform = get_transform(other);
+  nassertv(rel_transform->has_components());
+
+  CPT(TransformState) orig_transform = get_transform();
+  if (orig_transform->has_components()) {
+    // If we had a componentwise transform before we started, we
+    // should be careful to preserve the other two components.  We
+    // wouldn't need to do this, except for the possibility of
+    // numerical error or decompose ambiguity.
+    const LVecBase3f &orig_pos = orig_transform->get_pos();
+    const LVecBase3f &orig_hpr = orig_transform->get_hpr();
+
+    set_transform(other, rel_transform->set_scale(scale));
+    const TransformState *new_transform = get_transform();
+    if (new_transform->has_components()) {
+      set_pos_hpr_scale(orig_pos, orig_hpr, new_transform->get_scale());
+    }
+
+  } else {
+    // If we didn't have a componentwise transform already, never
+    // mind.
+    set_transform(other, rel_transform->set_scale(scale));
+  }
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_sx(const qpNodePath &other, float sx) {
 set_sx(const qpNodePath &other, float sx) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f scale = transform->get_scale();
+  LVecBase3f scale = get_scale(other);
   scale[0] = sx;
   scale[0] = sx;
-  set_transform(other, transform->set_scale(scale));
+  set_scale(other, scale);
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_sy(const qpNodePath &other, float sy) {
 set_sy(const qpNodePath &other, float sy) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f scale = transform->get_scale();
+  LVecBase3f scale = get_scale(other);
   scale[1] = sy;
   scale[1] = sy;
-  set_transform(other, transform->set_scale(scale));
+  set_scale(other, scale);
 }
 }
 
 
 void qpNodePath::
 void qpNodePath::
 set_sz(const qpNodePath &other, float sz) {
 set_sz(const qpNodePath &other, float sz) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  LVecBase3f scale = transform->get_scale();
+  LVecBase3f scale = get_scale(other);
   scale[2] = sz;
   scale[2] = sz;
-  set_transform(other, transform->set_scale(scale));
+  set_scale(other, scale);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1044,11 +1114,31 @@ void qpNodePath::
 set_pos_hpr(const qpNodePath &other, const LVecBase3f &pos,
 set_pos_hpr(const qpNodePath &other, const LVecBase3f &pos,
             const LVecBase3f &hpr) {
             const LVecBase3f &hpr) {
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
-  CPT(TransformState) transform = get_transform(other);
-  nassertv(transform->has_components());
-  transform = TransformState::make_pos_hpr_scale
-    (pos, hpr, transform->get_scale());
-  set_transform(other, transform);
+  CPT(TransformState) rel_transform = get_transform(other);
+  nassertv(rel_transform->has_components());
+
+  CPT(TransformState) orig_transform = get_transform();
+  if (orig_transform->has_components()) {
+    // If we had a componentwise transform before we started, we
+    // should be careful to preserve the other two components.  We
+    // wouldn't need to do this, except for the possibility of
+    // numerical error or decompose ambiguity.
+    const LVecBase3f &orig_scale = orig_transform->get_scale();
+
+    set_transform(other, TransformState::make_pos_hpr_scale
+                  (pos, hpr, rel_transform->get_scale()));
+    const TransformState *new_transform = get_transform();
+    if (new_transform->has_components()) {
+      set_pos_hpr_scale(new_transform->get_pos(), new_transform->get_hpr(),
+                        orig_scale);
+    }
+
+  } else {
+    // If we didn't have a componentwise transform already, never
+    // mind.
+    set_transform(other, TransformState::make_pos_hpr_scale
+                  (pos, hpr, rel_transform->get_scale()));
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1061,6 +1151,10 @@ set_pos_hpr(const qpNodePath &other, const LVecBase3f &pos,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void qpNodePath::
 void qpNodePath::
 set_hpr_scale(const qpNodePath &other, const LVecBase3f &hpr, const LVecBase3f &scale) {
 set_hpr_scale(const qpNodePath &other, const LVecBase3f &hpr, const LVecBase3f &scale) {
+  // We don't bother trying very hard to preserve pos across this
+  // operation, unlike the work we do above to preserve hpr or scale,
+  // since it generally doesn't matter that much if pos is off by a
+  // few thousandths.
   nassertv_always(!is_empty());
   nassertv_always(!is_empty());
   CPT(TransformState) transform = get_transform(other);
   CPT(TransformState) transform = get_transform(other);
   transform = TransformState::make_pos_hpr_scale
   transform = TransformState::make_pos_hpr_scale

+ 3 - 2
panda/src/pgraph/qpnodePath.h

@@ -187,6 +187,7 @@ PUBLISHED:
   INLINE qpNodePath get_parent() const;
   INLINE qpNodePath get_parent() const;
 
 
   qpNodePath find(const string &path) const;
   qpNodePath find(const string &path) const;
+  qpNodePath find_path_to(PandaNode *node) const;
   qpNodePathCollection find_all_matches(const string &path) const;
   qpNodePathCollection find_all_matches(const string &path) const;
   qpNodePathCollection find_all_paths_to(PandaNode *node) const;
   qpNodePathCollection find_all_paths_to(PandaNode *node) const;
 
 
@@ -216,13 +217,13 @@ PUBLISHED:
 
 
 
 
   // Aggregate transform and state information.
   // Aggregate transform and state information.
-  INLINE CPT(RenderState) get_state() const;
+  INLINE const RenderState *get_state() const;
   INLINE void set_state(const RenderState *state) const;
   INLINE void set_state(const RenderState *state) const;
   CPT(RenderState) get_state(const qpNodePath &other) const;
   CPT(RenderState) get_state(const qpNodePath &other) const;
   void set_state(const qpNodePath &other, const RenderState *state) const;
   void set_state(const qpNodePath &other, const RenderState *state) const;
   INLINE CPT(RenderState) get_net_state() const;
   INLINE CPT(RenderState) get_net_state() const;
 
 
-  INLINE CPT(TransformState) get_transform() const;
+  INLINE const TransformState *get_transform() const;
   INLINE void set_transform(const TransformState *transform) const;
   INLINE void set_transform(const TransformState *transform) const;
   CPT(TransformState) get_transform(const qpNodePath &other) const;
   CPT(TransformState) get_transform(const qpNodePath &other) const;
   void set_transform(const qpNodePath &other, const TransformState *transform) const;
   void set_transform(const qpNodePath &other, const TransformState *transform) const;