New mechanism for source update with callbacks

Similarly to Node update callbacks, sources now have SourceCallbacks called at the start of each update. Several SourceCallback are implemented to ensure thread safe update of more complex properties (mixing alpha, depth, etc.).
This commit is contained in:
Bruno Herbelin
2021-12-20 00:25:42 +01:00
parent 8deb364025
commit f921e7610c
9 changed files with 464 additions and 169 deletions

88
SourceCallback.h Normal file
View File

@@ -0,0 +1,88 @@
#ifndef SOURCECALLBACK_H
#define SOURCECALLBACK_H
#include <glm/glm.hpp>
class Source;
class SourceCallback
{
public:
typedef enum {
CALLBACK_GENERIC = 0,
CALLBACK_ALPHA,
CALLBACK_DEPTH,
CALLBACK_PLAY,
CALLBACK_TRANSLATION
} CallbackType;
SourceCallback();
virtual ~SourceCallback() {}
virtual void update(Source *, float) = 0;
virtual CallbackType type () { return CALLBACK_GENERIC; }
inline bool finished() const { return finished_; }
inline bool active() const { return active_; }
inline void reset() { initialized_ = false; }
protected:
bool active_;
bool finished_;
bool initialized_;
};
class SetAlpha : public SourceCallback
{
float alpha_;
glm::vec2 pos_;
glm::vec2 step_;
public:
SetAlpha(float alpha);
void update(Source *s, float) override;
CallbackType type () override { return CALLBACK_ALPHA; }
};
class SetDepth : public SourceCallback
{
float duration_;
float progress_;
float start_;
float target_;
public:
SetDepth(float depth, float duration = 0.f);
void update(Source *s, float dt) override;
CallbackType type () override { return CALLBACK_DEPTH; }
};
class SetPlay : public SourceCallback
{
bool play_;
float delay_;
float progress_;
public:
SetPlay(bool on, float delay = 0.f);
void update(Source *s, float) override;
CallbackType type () override { return CALLBACK_PLAY; }
};
class Translation : public SourceCallback
{
glm::vec2 speed_;
glm::vec2 start_;
glm::vec2 target_;
float duration_;
float progress_;
public:
Translation(float dx, float dy, float duration = 0.f);
void update(Source *s, float) override;
CallbackType type () override { return CALLBACK_TRANSLATION; }
};
#endif // SOURCECALLBACK_H