浏览代码

fix lights for Windows

David Rose 24 年之前
父节点
当前提交
9d5a0a521e

+ 75 - 18
panda/src/graph/multiTransition.T

@@ -22,6 +22,20 @@
 template<class Property, class NameClass>
 TypeHandle MultiTransition<Property, NameClass>::_type_handle;
 
+////////////////////////////////////////////////////////////////////
+//     Function: MultiTransition::SortByFirstOfPair function operator
+//       Access: Public
+//  Description: Implements the STL function object that sorts
+//               elements in the vector according to the first
+//               component of each element.
+////////////////////////////////////////////////////////////////////
+template<class Property, class NameClass>
+INLINE_GRAPH bool MultiTransition<Property, NameClass>::SortByFirstOfPair::
+operator ()(const MultiTransition<Property, NameClass>::Element &a, 
+            const MultiTransition<Property, NameClass>::Element &b) const {
+  return a.first < b.first;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MultiTransition::Constructor
 //       Access: Public
@@ -139,7 +153,20 @@ get_default_dir() const {
 template<class Property, class NameClass>
 void MultiTransition<Property, NameClass>::
 set_identity(const Property &property) {
-  _properties[property] = TD_identity;
+  Properties::iterator pi;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      (*pi).second = TD_identity;
+      state_changed();
+      return;
+    }
+  }
+
+  // It wasn't already on the list; append it.
+  _properties.push_back(Element(property, TD_identity));
+
+  // And now we need to re-sort the list.
+  sort(_properties.begin(), _properties.end(), SortByFirstOfPair());
   state_changed();
 }
 
@@ -153,7 +180,20 @@ set_identity(const Property &property) {
 template<class Property, class NameClass>
 void MultiTransition<Property, NameClass>::
 set_on(const Property &property) {
-  _properties[property] = TD_on;
+  Properties::iterator pi;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      (*pi).second = TD_on;
+      state_changed();
+      return;
+    }
+  }
+
+  // It wasn't already on the list; append it.
+  _properties.push_back(Element(property, TD_on));
+
+  // And now we need to re-sort the list.
+  sort(_properties.begin(), _properties.end(), SortByFirstOfPair());
   state_changed();
 }
 
@@ -167,7 +207,20 @@ set_on(const Property &property) {
 template<class Property, class NameClass>
 void MultiTransition<Property, NameClass>::
 set_off(const Property &property) {
-  _properties[property] = TD_off;
+  Properties::iterator pi;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      (*pi).second = TD_off;
+      state_changed();
+      return;
+    }
+  }
+
+  // It wasn't already on the list; append it.
+  _properties.push_back(Element(property, TD_off));
+
+  // And now we need to re-sort the list.
+  sort(_properties.begin(), _properties.end(), SortByFirstOfPair());
   state_changed();
 }
 
@@ -181,9 +234,10 @@ template<class Property, class NameClass>
 bool MultiTransition<Property, NameClass>::
 is_identity(const Property &property) const {
   Properties::const_iterator pi;
-  pi = _properties.find(property);
-  if (pi != _properties.end()) {
-    return (*pi).second == TD_identity;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      return (*pi).second == TD_identity;
+    }
   }
 
   // The property is not mentioned.  It's implicitly identity only if
@@ -201,13 +255,14 @@ template<class Property, class NameClass>
 bool MultiTransition<Property, NameClass>::
 is_on(const Property &property) const {
   Properties::const_iterator pi;
-  pi = _properties.find(property);
-  if (pi != _properties.end()) {
-    return (*pi).second == TD_on;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      return (*pi).second == TD_on;
+    }
   }
 
-  // The property is not mentioned.  It's implicitly 'on' only if the
-  // default_dir flag is TD_on.
+  // The property is not mentioned.  It's implicitly on only if
+  // the default_dir flag is on.
   return (_default_dir == TD_on);
 }
 
@@ -221,13 +276,14 @@ template<class Property, class NameClass>
 bool MultiTransition<Property, NameClass>::
 is_off(const Property &property) const {
   Properties::const_iterator pi;
-  pi = _properties.find(property);
-  if (pi != _properties.end()) {
-    return (*pi).second == TD_off;
+  for (pi = _properties.begin(); pi != _properties.end(); ++pi) {
+    if ((*pi).first == property) {
+      return (*pi).second == TD_off;
+    }
   }
 
-  // The property is not mentioned.  It's implicitly 'off' only if the
-  // default_dir flag is TD_off.
+  // The property is not mentioned.  It's implicitly off only if
+  // the default_dir flag is off.
   return (_default_dir == TD_off);
 }
 
@@ -291,7 +347,7 @@ compose(const NodeTransition *other) const {
 
     dmap_compose(_properties.begin(), _properties.end(),
                  ot->_properties.begin(), ot->_properties.end(),
-                 inserter(result->_properties, result->_properties.begin()));
+                 back_inserter(result->_properties));
 
     return result;
   }
@@ -315,7 +371,8 @@ invert() const {
   result->_default_dir = TD_identity;
 
   dmap_invert(_properties.begin(), _properties.end(),
-              inserter(result->_properties, result->_properties.begin()));
+              back_inserter(result->_properties),
+              (Element *)NULL);
 
   return result;
 }

+ 17 - 5
panda/src/graph/multiTransition.h

@@ -19,13 +19,15 @@
 #ifndef MULTITRANSITION_H
 #define MULTITRANSITION_H
 
-#include <pandabase.h>
+#include "pandabase.h"
 
 #include "nodeTransition.h"
 #include "transitionDirection.h"
 #include "multiTransitionHelpers.h"
 
-#include <indent.h>
+#include "indent.h"
+
+#include <algorithm>
 
 ////////////////////////////////////////////////////////////////////
 //       Class : MultiTransition
@@ -52,7 +54,18 @@
 template<class Property, class NameClass>
 class MultiTransition : public NodeTransition {
 private:
-  typedef pmap<Property, TransitionDirection> Properties;
+  typedef pair<Property, TransitionDirection> Element;
+
+  // This has to be a vector and not a map, so we can safely access
+  // the iterators outside of PANDA.DLL.
+  typedef pvector<Element> Properties;
+
+  // We use this as an STL function object for sorting the vector in
+  // order by its property.
+  class SortByFirstOfPair {
+  public:
+    INLINE_GRAPH bool operator ()(const Element &a, const Element &b) const;
+  };
 
 protected:
   MultiTransition();
@@ -106,8 +119,7 @@ protected:
 
 public:
   // These functions and typedefs allow one to peruse all of the
-  // Properties in the transition.  Beware!  It is not safe to use
-  // this interface outside of PANDA.DLL.
+  // Properties in the transition.
   typedef Properties::const_iterator iterator;
   typedef Properties::const_iterator const_iterator;
   typedef Properties::value_type value_type;

+ 5 - 7
panda/src/graph/multiTransitionHelpers.I

@@ -131,26 +131,24 @@ dmap_invert_compose(InputIterator1 first1, InputIterator1 last1,
 //               input.  Guarantees that the new list will have
 //               exactly the same length as the input list.
 ////////////////////////////////////////////////////////////////////
-template<class InputIterator, class OutputIterator>
+template<class InputIterator, class OutputIterator, class ValueType>
 OutputIterator
 dmap_invert(InputIterator first, InputIterator last,
-            OutputIterator result) {
-  typedef TYPENAME InputIterator::value_type OutputType;
-
+            OutputIterator result, ValueType *) {
   while (first != last) {
     switch ((*first).second) {
     case TD_identity:
-      (*result) = OutputType((*first).first, TD_identity);
+      (*result) = ValueType((*first).first, TD_identity);
       ++result;
       break;
 
     case TD_on:
-      (*result) = OutputType((*first).first, TD_off);
+      (*result) = ValueType((*first).first, TD_off);
       ++result;
       break;
 
     case TD_off:
-      (*result) = OutputType((*first).first, TD_on);
+      (*result) = ValueType((*first).first, TD_on);
       ++result;
       break;
     }

+ 2 - 2
panda/src/graph/multiTransitionHelpers.h

@@ -56,10 +56,10 @@ dmap_invert_compose(InputIterator1 first1, InputIterator1 last1,
 //               input.  Guarantees that the new list will have
 //               exactly the same length as the input list.
 ////////////////////////////////////////////////////////////////////
-template<class InputIterator, class OutputIterator>
+template<class InputIterator, class OutputIterator, class ValueType>
 OutputIterator
 dmap_invert(InputIterator first, InputIterator last,
-            OutputIterator result);
+            OutputIterator result, ValueType *);
 
 
 ////////////////////////////////////////////////////////////////////

+ 9 - 0
panda/src/light/lightTransition.h

@@ -55,6 +55,15 @@ public:
   virtual NodeTransition *make_identity() const;
   virtual NodeTransition *make_initial() const;
 
+#ifdef CPPPARSER
+  // Interrogate seems to have difficulty figuring out that we do
+  // implement this pure virtual function properly in MultiTransition.
+  // For now, we'll pretend for interrogate's sake that it's also
+  // implemented here, just so interrogate doesn't believe the class
+  // is abstract.
+  virtual NodeAttribute *apply(const NodeAttribute *attrib) const;
+#endif
+
   virtual void issue(GraphicsStateGuardianBase *gsgbase);
 
 protected: