]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.cxx
Fixed a crash: the singleton needs to be instantiated the first time SGCommandMgr...
[simgear.git] / simgear / props / props.cxx
index c01650feb2d9952c24f6665b4ff130b1dba2acb4..5b778a7a97627969385f1f95f974400307ab8f91 100644 (file)
@@ -11,6 +11,7 @@
 #endif
 
 #include "props.hxx"
+#include "PropertyInterpolationMgr.hxx"
 #include "vectorPropTemplates.hxx"
 
 #include <algorithm>
@@ -158,7 +159,7 @@ inline bool validateName(const string& name)
 static char *
 copy_string (const char * s)
 {
-  unsigned long int slen = strlen(s);
+  size_t slen = strlen(s);
   char * copy = new char[slen + 1];
 
   // the source string length is known so no need to check for '\0'
@@ -181,15 +182,15 @@ template<typename Itr>
 static int
 find_child (Itr begin, Itr end, int index, const PropertyList& nodes)
 {
-  int nNodes = nodes.size();
+  size_t nNodes = nodes.size();
   boost::iterator_range<Itr> name(begin, end);
-  for (int i = 0; i < nNodes; i++) {
+  for (size_t i = 0; i < nNodes; i++) {
     SGPropertyNode * node = nodes[i];
 
-    // searching for a mathing index is a lot less time consuming than
+    // searching for a matching index is a lot less time consuming than
     // comparing two strings so do that first.
     if (node->getIndex() == index && boost::equals(node->getName(), name))
-      return i;
+      return static_cast<int>(i);
   }
   return -1;
 }
@@ -200,10 +201,10 @@ find_child (Itr begin, Itr end, int index, const PropertyList& nodes)
 static int
 find_last_child (const char * name, const PropertyList& nodes)
 {
-  int nNodes = nodes.size();
-  int index = 0;
+  size_t nNodes = nodes.size();
+  int index = -1;
 
-  for (int i = 0; i < nNodes; i++) {
+  for (size_t i = 0; i < nNodes; i++) {
     SGPropertyNode * node = nodes[i];
     if (compare_strings(node->getName(), name))
     {
@@ -230,7 +231,7 @@ first_unused_index( const char * name,
       return index;
   }
 
-  SG_LOG(SG_GENERAL, SG_ALERT, "Too much nodes: " << name);
+  SG_LOG(SG_GENERAL, SG_ALERT, "Too many nodes: " << name);
   return -1;
 }
 
@@ -1008,9 +1009,9 @@ PropertyList
 SGPropertyNode::getChildren (const char * name) const
 {
   PropertyList children;
-  int max = _children.size();
+  size_t max = _children.size();
 
-  for (int i = 0; i < max; i++)
+  for (size_t i = 0; i < max; i++)
     if (compare_strings(_children[i]->getName(), name))
       children.push_back(_children[i]);
 
@@ -1066,7 +1067,7 @@ SGPropertyNode::removeChildren (const char * name, bool keep)
 {
   PropertyList children;
 
-  for (int pos = _children.size() - 1; pos >= 0; pos--)
+  for (int pos = static_cast<int>(_children.size() - 1); pos >= 0; pos--)
     if (compare_strings(_children[pos]->getName(), name))
       children.push_back(removeChild(pos, keep));
 
@@ -1654,6 +1655,52 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
   return result;
 }
 
+//------------------------------------------------------------------------------
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const SGPropertyNode& target,
+                                  double duration,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to target immediately
+    setUnspecifiedValue( target.getStringValue() );
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, target, duration, easing);
+}
+
+//------------------------------------------------------------------------------
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const PropertyList& values,
+                                  const double_list& deltas,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to last value immediately
+    if( !values.empty() )
+      setUnspecifiedValue(values.back()->getStringValue());
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, values, deltas, easing);
+}
+
+//------------------------------------------------------------------------------
+void SGPropertyNode::setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr)
+{
+  _interpolation_mgr = mgr;
+}
+
+simgear::PropertyInterpolationMgr* SGPropertyNode::_interpolation_mgr = 0;
+
+//------------------------------------------------------------------------------
 std::ostream& SGPropertyNode::printOn(std::ostream& stream) const
 {
     if (!getAttribute(READ))
@@ -2139,15 +2186,18 @@ SGPropertyNode::fireChildAdded (SGPropertyNode * child)
 }
 
 void
-SGPropertyNode::fireCreatedRecursive()
+SGPropertyNode::fireCreatedRecursive(bool fire_self)
 {
-  _parent->fireChildAdded(this);
+  if( fire_self )
+  {
+    _parent->fireChildAdded(this);
 
-  if( _children.empty() && getType() != simgear::props::NONE )
-    return fireValueChanged();
+    if( _children.empty() && getType() != simgear::props::NONE )
+      return fireValueChanged();
+  }
 
   for(size_t i = 0; i < _children.size(); ++i)
-    _children[i]->fireCreatedRecursive();
+    _children[i]->fireCreatedRecursive(true);
 }
 
 void
@@ -2211,7 +2261,7 @@ SGPropertyNode::fireChildRemoved (SGPropertyNode * parent,
 
 SGPropertyChangeListener::~SGPropertyChangeListener ()
 {
-  for (int i = _properties.size() - 1; i >= 0; i--)
+  for (int i = static_cast<int>(_properties.size() - 1); i >= 0; i--)
     _properties[i]->removeChangeListener(this);
 }