From 7c4e5613d4974e440afa9cc47e06972f255a506f Mon Sep 17 00:00:00 2001 From: dooglus Date: Fri, 21 Dec 2007 16:40:31 +0000 Subject: [PATCH] When cloning a 'random' valuenode with a constant, non-exported seed, use a new random seed. git-svn-id: http://svn.voria.com/code@1224 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../src/modules/mod_noise/valuenode_random.cpp | 22 ++++++++++++++++++++++ .../trunk/src/modules/mod_noise/valuenode_random.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp index 3bf6ab4..24bfe23 100644 --- a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp @@ -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)); + } +} diff --git a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h index 98a167e..d1818d1 100644 --- a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h +++ b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h @@ -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); -- 2.7.4