When cloning a 'random' valuenode with a constant, non-exported seed, use a new rando...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 21 Dec 2007 16:40:31 +0000 (16:40 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 21 Dec 2007 16:40:31 +0000 (16:40 +0000)
git-svn-id: http://svn.voria.com/code@1224 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp
synfig-core/trunk/src/modules/mod_noise/valuenode_random.h

index 3bf6ab4..24bfe23 100644 (file)
@@ -275,3 +275,25 @@ ValueNode_Random::check_type(ValueBase::Type type)
                type==ValueBase::TYPE_TIME              ||
                type==ValueBase::TYPE_VECTOR    ;
 }
+
+ValueNode*
+ValueNode_Random::clone(const GUID& deriv_guid)const
+{
+       ValueNode_Random* ret = (ValueNode_Random*)LinkableValueNode::clone(deriv_guid);
+       ret->randomize_seed();
+       return ret;
+}
+
+void
+ValueNode_Random::randomize_seed()
+{
+       int i = get_link_index_from_name("seed");
+       ValueNode::Handle link = get_link_vfunc(i);
+       if(!link->is_exported() && link->get_name() == "constant")
+       {
+               int seed = time(NULL) + rand();
+               if (seed < 0) seed = -seed;
+               random.set_seed(seed);
+               set_link(i, ValueNode_Const::create(seed));
+       }
+}
index 98a167e..d1818d1 100644 (file)
@@ -68,6 +68,10 @@ public:
        virtual String link_local_name(int i)const;
        virtual int get_link_index_from_name(const String &name)const;
 
+       virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
+
+       void randomize_seed();
+
 protected:
        LinkableValueNode* create_new()const;
        virtual bool set_link_vfunc(int i,ValueNode::Handle x);