From: Mikko Rasa Date: Tue, 30 Apr 2019 09:49:48 +0000 (+0300) Subject: Move the Action class out of Sequencer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8ffa42fba0e6a13286b465473fd399cac7c77dcf;p=libs%2Fdemoscene.git Move the Action class out of Sequencer --- diff --git a/source/action.cpp b/source/action.cpp new file mode 100644 index 0000000..b7cf082 --- /dev/null +++ b/source/action.cpp @@ -0,0 +1,37 @@ +#include "action.h" + +InterpolationAction::InterpolationAction(bool h): + hermite(h), + start_beat(0), + duration(0) +{ } + +void InterpolationAction::start(float b, float d) +{ + start_beat = b; + duration = d; + interpolate(0.0f, 0.0f); +} + +void InterpolationAction::tick(float b, float d) +{ + if(duration) + { + float t = (b-start_beat)/duration; + float dt = d/duration; + if(hermite) + { + dt = t-dt; + t = (3-2*t)*t*t; + dt = t-(3-2*dt)*dt*dt; + } + interpolate(t, dt); + } + else + interpolate(1.0f, 1.0f); +} + +void InterpolationAction::end(float) +{ + interpolate(1.0f, 0.0f); +} diff --git a/source/action.h b/source/action.h new file mode 100644 index 0000000..9988854 --- /dev/null +++ b/source/action.h @@ -0,0 +1,33 @@ +#ifndef MSP_DEMOSCENE_ACTION_H_ +#define MSP_DEMOSCENE_ACTION_H_ + +class Action +{ +protected: + Action() { } +public: + virtual ~Action() { } + + virtual void start(float, float) { } + virtual void beat(int) { } + virtual void tick(float, float) { } + virtual void end(float) { } +}; + +class InterpolationAction: public Action +{ +protected: + bool hermite; + float start_beat; + float duration; + + InterpolationAction(bool = false); + +public: + virtual void start(float, float); + virtual void tick(float, float); + virtual void end(float); + virtual void interpolate(float, float) { } +}; + +#endif diff --git a/source/beatcounter.h b/source/beatcounter.h index 856c8d7..952ed6b 100644 --- a/source/beatcounter.h +++ b/source/beatcounter.h @@ -5,9 +5,9 @@ #include #include #include -#include "sequencer.h" +#include "action.h" -class BeatCounter: public Msp::GL::Renderable, public Sequencer::Action +class BeatCounter: public Msp::GL::Renderable, public Action { private: Msp::GL::Text text; diff --git a/source/cameracontrol.h b/source/cameracontrol.h index 455bad6..a822144 100644 --- a/source/cameracontrol.h +++ b/source/cameracontrol.h @@ -3,12 +3,12 @@ #include #include -#include "sequencer.h" +#include "action.h" -class CameraControl: public Sequencer::Action +class CameraControl: public Action { public: - class SetCamera: public Sequencer::Action + class SetCamera: public Action { private: CameraControl &control; @@ -20,7 +20,7 @@ public: virtual void start(float, float); }; - class AnimateCamera: public Sequencer::Action + class AnimateCamera: public Action { private: CameraControl &control; diff --git a/source/colorfade.cpp b/source/colorfade.cpp index dfe7472..30d9658 100644 --- a/source/colorfade.cpp +++ b/source/colorfade.cpp @@ -3,7 +3,7 @@ using namespace Msp; ColorFadeAction::ColorFadeAction(const GL::Color &c): - Sequencer::InterpolationAction(true), + InterpolationAction(true), end_color(c) { } diff --git a/source/colorfade.h b/source/colorfade.h index ce2e0a6..3b87513 100644 --- a/source/colorfade.h +++ b/source/colorfade.h @@ -2,9 +2,9 @@ #define MSP_DEMOSCENE_COLORFADE_H_ #include -#include "sequencer.h" +#include "action.h" -class ColorFadeAction: public Sequencer::InterpolationAction +class ColorFadeAction: public InterpolationAction { protected: Msp::GL::Color start_color; diff --git a/source/sequencer.cpp b/source/sequencer.cpp index 4acad43..d9d3561 100644 --- a/source/sequencer.cpp +++ b/source/sequencer.cpp @@ -1,5 +1,6 @@ #include #include +#include "action.h" #include "sequencer.h" using namespace std; @@ -125,40 +126,3 @@ void Sequencer::update_next_event() if(i->end_beat>beat) next_event = min(next_event, i->end_beat); } - - -Sequencer::InterpolationAction::InterpolationAction(bool h): - hermite(h), - start_beat(0), - duration(0) -{ } - -void Sequencer::InterpolationAction::start(float b, float d) -{ - start_beat = b; - duration = d; - interpolate(0.0f, 0.0f); -} - -void Sequencer::InterpolationAction::tick(float b, float d) -{ - if(duration) - { - float t = (b-start_beat)/duration; - float dt = d/duration; - if(hermite) - { - dt = t-dt; - t = (3-2*t)*t*t; - dt = t-(3-2*dt)*dt*dt; - } - interpolate(t, dt); - } - else - interpolate(1.0f, 1.0f); -} - -void Sequencer::InterpolationAction::end(float) -{ - interpolate(1.0f, 0.0f); -} diff --git a/source/sequencer.h b/source/sequencer.h index 028c5d5..e6eb2b7 100644 --- a/source/sequencer.h +++ b/source/sequencer.h @@ -6,38 +6,10 @@ #include #include +class Action; + class Sequencer { -public: - class Action - { - protected: - Action() { } - public: - virtual ~Action() { } - - virtual void start(float, float) { } - virtual void beat(int) { } - virtual void tick(float, float) { } - virtual void end(float) { } - }; - - class InterpolationAction: public Action - { - protected: - bool hermite; - float start_beat; - float duration; - - InterpolationAction(bool = false); - - public: - virtual void start(float, float); - virtual void tick(float, float); - virtual void end(float); - virtual void interpolate(float, float) { } - }; - private: struct Segment { diff --git a/source/stage.h b/source/stage.h index f34e6ae..2933856 100644 --- a/source/stage.h +++ b/source/stage.h @@ -3,11 +3,11 @@ #include #include "cameracontrol.h" -#include "sequencer.h" +#include "action.h" struct Stage { - class UseInView: public Sequencer::Action + class UseInView: public Action { private: Msp::GL::View &view;