Lambda_Connector.cpp
Go to the documentation of this file.
1 #include "Lambda_Connector.hpp"
2 #include "../../Defs.hpp"
3 
4 namespace iv
5 {
6 
8  AnimConnector( inst ),
9  cm( inst, this, "Lambda_Connector" ),
10  _retarget( true )
11 {
12  this->cm.inherits( this->AnimConnector::cm );
13 }
14 
16 {
17  for( AnimNodeI * node : this->_parents )
18  node->anim_removeChild( this );
19 
20  for( AnimNodeI * node : this->_children )
21  node->anim_unsetParent( this );
22 }
23 
24 void Lambda_Connector::anim_eachChild( std::function< void( AnimNodeI * ) > const & f )
25 {
26  for( AnimNodeI * node : this->_children )
27  f( node );
28 }
29 
31 {
32  this->_children.erase( node );
33  node->anim_unsetParent( this );
34  this->Activate();
35  this->_retarget = true;
36 }
37 
38 void Lambda_Connector::anim_eachParent( std::function< void( AnimNodeI * ) > const & f )
39 {
40  for( AnimNodeI * node : this->_parents )
41  f( node );
42 }
43 
45 {
46  this->_parents.erase( node );
47  node->anim_removeChild( this );
48  this->Activate();
49  this->_retarget = true;
50 }
51 
53 {
54  this->_parents.insert( node );
55  node->anim_addChild( this );
56  this->Activate();
57  this->_retarget = true;
58  return this;
59 }
60 
62 {
63  this->_children.insert( node );
64  node->anim_setParent( this );
65  this->Activate();
66  this->_retarget = true;
67  return this;
68 }
69 
70 void Lambda_Connector::Retargeting( std::function< void( bool warping ) > const & val )
71 {
72  this->_retargeting = val;
73  this->Activate();
74  this->_retarget = true;
75 }
76 
78 {
79  // decide if we need to retarget
80  bool retarget = this->_retarget || this->parentChanged_Get();
81  this->_retarget = false;
82  this->parentChanged_Clear();
83 
84  // compute update distances
85  Anim_float distance = 0.0f;
86  for( AnimNodeI * parent : this->_parents )
87  distance = std::max( distance, parent->Step() );
88 
89  //
90  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Down | Retarget=", retarget, ", step=", distance, "." );
91 
92  // retarget
93  if( retarget )
94  this->Retarget( distance == std::numeric_limits< Anim_float >::infinity() );
95 
96  // request updates on children
97  for( AnimNodeI * child : this->_children )
98  child->Connector_RequestStep( distance );
99 }
100 
102 {
103  // compute distance from children
104  if( this->childArrived_Get() )
105  {
106  this->childArrived_Clear();
107  this->_retarget = true;
108  }
109 
110  // aggregate distance
111  Anim_float distance = 0.0f;
112  for( AnimNodeI * child : this->_children )
113  distance = std::max( distance, child->Distance() );
114 
115  if( this->_retarget )
116  distance = std::max( distance, std::numeric_limits< Anim_float >::epsilon() );
117 
118  //
119  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Up | distance=", distance, "." );
120 
121  // set distance to parents
122  for( AnimNodeI * parent : this->_parents )
123  parent->Connector_UpdateDistance( distance );
124 }
125 
126 void Lambda_Connector::Retarget( bool warping )
127 {
128  if( warping )
129  this->cm.log( SRC_INFO, iv::Defs::Log::Animation_Events, "Retarget (warping)." );
130  else
131  this->cm.log( SRC_INFO, iv::Defs::Log::Animation_Events, "Retarget." );
132 
133  this->Activate();
134  this->_retargeting( warping );
135 
137  for( AnimNodeI * child : this->_children )
138  this->cm.log( SRC_INFO, iv::Defs::Log::Animation_Events, " Child ", child->cm, " (", child->label(), ") -> ", child->StringIO_GetTarget( &this->cm ), " (speed=",child->Speed(),")." );
139 }
140 
141 }