]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/persparam.hxx
Provide something more sensible for the properties root
[simgear.git] / simgear / scene / model / persparam.hxx
index 4ee014b6465c85c1080d27a717b22764a7b2c637..e8b571fcf133f02b9c6c695a7a2e615552f16d23 100755 (executable)
@@ -5,17 +5,20 @@
 #ifndef _SG_PERSPARAM_HXX
 #define _SG_PERSPARAM_HXX 1
 
+#include <simgear/math/sg_random.h>
+
+
 template <class T>
 class SGPersonalityParameter {
 public:
-  SGPersonalityParameter( SGPropertyNode *props, const char *name, T defval )
+  SGPersonalityParameter(const SGPropertyNode *props, const char *name, T defval )
     : _var( defval ), _min( defval ), _max( defval ) {
-    SGPropertyNode_ptr node = props->getNode( name );
+    const SGPropertyNode* node = props->getNode( name );
     if ( node != 0 ) {
-      SGPropertyNode_ptr rand_n = node->getNode( "random" );
+      const SGPropertyNode* rand_n = node->getNode( "random" );
       if ( rand_n != 0 ) {
-        _min = rand_n->getDoubleValue( "min", 0.0 );
-        _max = rand_n->getDoubleValue( "max", 1.0 );
+        _min = getNodeValue( rand_n, "min", (T)0 );
+        _max = getNodeValue( rand_n, "max", (T)1 );
         shuffle();
       } else {
         _var = _min = _max = getNodeValue( props, name, defval );
@@ -27,7 +30,7 @@ public:
   SGPersonalityParameter<T> &operator-=( T v ) { _var -= v; return *this; }
   T shuffle() { return ( _var = _min + sg_random() * ( _max - _min ) ); }
   T value() const { return _var; }
-  T getNodeValue( SGPropertyNode *props, const char *name, T defval ) const;
+  T getNodeValue(const SGPropertyNode *props, const char *name, T defval ) const;
   operator T() const { return _var; }
 
 private:
@@ -36,4 +39,10 @@ private:
   T _max;
 };
 
+template <> double
+SGPersonalityParameter<double>::getNodeValue( const SGPropertyNode *props,
+                                              const char *name,
+                                              double defval ) const;
+
 #endif // _SG_PERSPARAM_HXX
+