TimeTransform_Connector.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class T >
6  Transform_ConnectorI< T, T >( inst ),
7  cm( inst, this, "TimeTransform_Connector", ClientMarker::Status() ),
8  current_source_time( 0.0 ),
9  current_total_time( 0.0 ),
10  current_distance( 0.0 ),
11  reset_remainder_distance( std::nullopt )
12 {
14 }
15 
16 template< class T >
18 {
19  auto row = view->Table( TimeTransform_Connector_DebugTable ).Row( this );
20  row.Column( "current_source_time", this->current_source_time );
21  row.Column( "current_total_time", this->current_total_time );
22  row.Column( "current_distance", this->current_distance );
23  row.Column( "reset_remainder_distance", this->reset_remainder_distance );
24 }
25 
26 template< class T >
28 {
29  this->_transform = transform;
30 }
31 
32 template< class T >
34 {
35  if( !this->parent || !this->child )
36  return;
37 
38  bool dirty = this->treeChanged_Get() || this->parentChanged_Get();
39  this->treeChanged_Clear();
40  this->parentChanged_Clear();
41 
42  Anim_float distance = this->parent->Step();
43  if( distance == std::numeric_limits< Anim_float >::infinity() )
44  {
45  if( dirty )
46  {
47  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_Events, "Reset target - target changed to ",this->parent->Target(),", warping." );
48  this->child->Target( this->parent->Target() );
49  }
50 
51  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Down | Warping." );
52 
53  this->child->Connector_RequestStep( distance );
54 
55  this->current_total_time = 0.0;
56  this->current_source_time = 0.0;
57  this->current_distance = 0.0;
58  }
59  else
60  {
61  if( dirty )
62  {
63  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_Events, "Reset target - target changed to ", this->parent->Target(), "." );
64  this->child->Target( this->parent->Target() );
65  this->current_total_time = 0.0;
66  this->current_source_time = 0.0;
67  this->reset_remainder_distance = distance;
68  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Down | Changing target." );
69  return;
70  }
71 
72  if( !this->reset_remainder_distance.has_value() ) // Only consider retargeting due to critical distance deviation when the current_total_time was fetched and has an actual value.
73  {
74  auto expected_target_time = this->_transform.Transform( this->current_source_time, this->current_total_time );
75  auto expected_target_distance = std::max( Anim_float( 0.0 ), this->current_total_time - expected_target_time );
76  auto current_target_distance = this->child->Distance();
77  auto difference = iv::abs( expected_target_distance - current_target_distance );
78 
79  if( ( this->current_total_time == 0 && current_target_distance != 0 )|| difference / this->current_total_time > DistanceChangeRatioThatCausesReset )
80  {
81  this->cm.log( SRC_INFO, iv::Defs::Log::Animation_Events, "Reset target - critical deviation of ", difference, " (", ( difference / this->current_total_time * 100 ) ,"%)." );
82  this->reset_remainder_distance = 0.0f;
83  this->current_source_time = 0.0;
84  }
85  }
86 
87  //
88  if( this->reset_remainder_distance.has_value() )
89  {
90  this->current_total_time = this->child->Distance();
91  distance += this->reset_remainder_distance.value();
92  this->reset_remainder_distance = std::nullopt;
93  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_Events, "New current_total_time is ", this->current_total_time, "." );
94  }
95 
96  // current time
97  auto current_target_time = this->_transform.Transform( this->current_source_time, this->current_total_time );
98 
99  // next time
100  auto next_source_time = this->current_source_time + distance;
101  auto next_target_time = this->_transform.Transform( next_source_time, this->current_total_time );
102 
103  // distance
104  auto target_distance = next_target_time - current_target_time;
105 
106  //
107  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Down | Step ",distance,", child_step ",target_distance,"." );
108 
109  // advance
110  this->current_source_time = next_source_time;
111  this->child->Connector_RequestStep( target_distance );
112 
113  // return new distance
114  this->current_distance = std::max( Anim_float( 0.0 ), this->current_total_time - this->current_source_time );
115  }
116 }
117 
118 template< class T >
120 {
121  auto distance = this->current_distance;
122  if( this->child->Distance() > 0.0f )
123  distance = std::max( Anim_float( 0.001f ), distance );
124 
125  this->cm.log( SRC_INFO, ::iv::Defs::Log::Animation_ConnectorUpdate, "UpdatePass_Up | Distance ",distance,"." );
126 
127  this->parent->Connector_UpdateDistance( distance );
128 }
129 
130 }