-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition_animate.cpp
75 lines (61 loc) · 2.27 KB
/
transition_animate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <utility>
#include "connection.hpp"
#include "event.hpp"
#include "core/manager.hpp"
#include "transition_animate.hpp"
#include "scoped.hpp"
#include "types.hpp"
#include "utility_colorwheel.hpp"
using namespace std;
namespace sc {
/**
* class AnimateTransitionBase
*/
struct AnimateTransitionState
{
bool polling {};
double elapsed {};
ChannelBuffer output;
EventScope pollEventScope;
std::shared_ptr< void > data;
};
AnimateTransitionBase::AnimateTransitionBase( string&& id, Manager& manager )
: Transition( move( id ) )
, manager_( manager )
{
}
unique_ptr< TransitionInstance > AnimateTransitionBase::instantiate() const
{
return unique_ptr< TransitionInstance >( new TransitionInstanceImpl< AnimateTransitionBase, AnimateTransitionState >( *this ) );
}
void AnimateTransitionBase::transform( AnimateTransitionState& state, Connection& connection, ChannelBuffer& values ) const
{
if ( state.data == nullptr ) {
state.data = instantiateData();
}
if ( state.output.empty() ) {
state.output = ChannelBuffer( values.size() );
}
Scoped scoped( [&state, &values] { values = state.output; state.polling = false; } );
if ( find_if( values.cbegin(), values.cend(), []( auto const& value ) { return value.on(); } ) == values.cend() ) {
state.output.fill();
state.pollEventScope = nullptr;
return;
}
animate( state.output, state.data.get(), state.elapsed );
if ( !state.polling ) {
Connection* safeConnection = &connection;
AnimateTransitionState* safeState = &state;
state.pollEventScope = manager_.pollEvent().subscribe(
[this, safeConnection, safeState]( chrono::nanoseconds elapsed ) {
poll( *safeState, *safeConnection, elapsed );
} );
}
}
void AnimateTransitionBase::poll( AnimateTransitionState& state, Connection& connection, chrono::nanoseconds elapsed ) const
{
state.polling = true;
state.elapsed = chrono::duration< double >( elapsed ).count();
connection.transfer();
}
} // namespace sc