resonance 1.0.1
Loading...
Searching...
No Matches
animatable.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5#include "rnd/object.h"
6
7class MetRenderer;
8namespace Rnd {
9class Dbg;
10class Stream;
11} // namespace Rnd
12
13namespace Rnd {
14
43class Animatable : public virtual Object {
44 // CollectChildren() in rnd/collectchildren.h walks mAnims directly, and the image has no
45 // accessor for it.
46 friend void CollectChildren(std::list<Object *> &objects, Animatable *pAnimatable);
47 // MetRenderer::AddScreenView() and AddBackgroundView() search mAnims directly before
48 // AddAnim(), and the image has no accessor for it.
49 friend class ::MetRenderer;
50
51public:
66
84 class Filter {
85 public:
94 virtual float Apply(float flValue) = 0;
95
109 virtual float Unapply(float flValue);
110
119 virtual void Print(Dbg &sink) const = 0;
120
128 virtual void Save(Stream &stream) = 0;
129
137 virtual void Load(Stream &stream) = 0;
138
146 virtual int Type() = 0;
147
157 virtual void Copy(const Filter *pSource) = 0;
158 };
159
166 class ScaleOffset : public Filter {
167 public:
175 }
176
183 ScaleOffset(float flScale, float flOffset) : mScale(flScale), mOffset(flOffset) {
184 }
185
194 virtual float Apply(float flValue);
195
206 virtual float Unapply(float flValue);
207
215 virtual void Print(Dbg &sink) const;
216
224 virtual void Save(Stream &stream);
225
233 virtual void Load(Stream &stream);
234
242 virtual int Type();
243
251 virtual void Copy(const Filter *pSource);
252
253 // Public because Animatable::SetRate() and Animatable::SetOffset() write both parameters
254 // directly, and the image has no accessor to route those writes through.
255
256 float mScale;
257 float mOffset;
258 };
259
266 class MinMaxLoop : public Filter {
267 public:
275 }
276
286 MinMaxLoop(float flMin, float flMax, int nLoop) : mMin(flMin), mMax(flMax), mLoop(nLoop) {
287 }
288
300 virtual float Apply(float flValue);
301
309 virtual void Print(Dbg &sink) const;
310
318 virtual void Save(Stream &stream);
319
327 virtual void Load(Stream &stream);
328
336 virtual int Type();
337
345 virtual void Copy(const Filter *pSource);
346
347 // Public because Animatable::SetLoopRange() writes both ends directly, and the image has
348 // no accessor to route those writes through.
349
350 float mMin;
351 float mMax;
352
353 private:
354 int mLoop; // +0x0c
355 };
356
366 class ZeroOrder : public Filter {
367 public:
370 }
371
378 ZeroOrder(float flLevel, float flMaxDelta) : mLevel(flLevel), mMaxDelta(flMaxDelta) {
379 }
380
389 virtual float Apply(float flValue);
390
402 virtual float Unapply(float flValue);
403
411 virtual void Print(Dbg &sink) const;
412
420 virtual void Save(Stream &stream);
421
429 virtual void Load(Stream &stream);
430
438 virtual int Type();
439
447 virtual void Copy(const Filter *pSource);
448
449 private:
450 float mLevel; // +0x04
451 float mMaxDelta; // +0x08
452 };
453
462 class FirstOrder : public Filter {
463 public:
466 }
467
474 FirstOrder(float flLevel, float flRatio) : mLevel(flLevel), mRatio(flRatio) {
475 }
476
485 virtual float Apply(float flValue);
486
497 virtual float Unapply(float flValue);
498
506 virtual void Print(Dbg &sink) const;
507
515 virtual void Save(Stream &stream);
516
524 virtual void Load(Stream &stream);
525
533 virtual int Type();
534
542 virtual void Copy(const Filter *pSource);
543
544 private:
545 float mLevel; // +0x04
546 float mRatio; // +0x08
547 };
548
559 class SecondOrder : public Filter {
560 public:
566 SecondOrder() : mVel(0.0f) {
567 }
568
576 SecondOrder(float flLevel, float flSpring, float flDamper)
577 : mLevel(flLevel), mSpring(flSpring), mDamper(flDamper), mVel(0.0f) {
578 }
579
588 virtual float Apply(float flValue);
589
600 virtual float Unapply(float flValue);
601
613 virtual void Print(Dbg &sink) const;
614
622 virtual void Save(Stream &stream);
623
634 virtual void Load(Stream &stream);
635
643 virtual int Type();
644
652 virtual void Copy(const Filter *pSource);
653
654 private:
655 float mLevel; // +0x04
656 float mSpring; // +0x08
657 float mDamper; // +0x0c
658 float mVel; // +0x10
659 };
660
668
675 virtual ~Animatable();
676
689
700 void AddAnim(Animatable *pAnim);
701
711 void RemoveAnim(Animatable *pAnim);
712
725 void SetFrame(float flFrame);
726
739 float UnfilterFrame(float flValue);
740
750 void AddFilter(Filter *pFilter);
751
760 void AddScaleOffset(float flScale, float flOffset);
761
771 void AddMinMaxLoop(float flMin, float flMax, int nLoop);
772
781 void AddZeroOrder(float flLevel, float flMaxDelta);
782
791 void AddFirstOrder(float flLevel, float flRatio);
792
802 void AddSecondOrder(float flLevel, float flSpring, float flDamper);
803
813 void RemoveFilter(int nIndex);
814
826 Filter *FilterAt(int nIndex);
827
840 void SetRate(float flRate);
841
853 void SetOffset(float flOffset);
854
867 void SetLoopRange(float flMin, float flMax);
868
880 static Filter *NewFilter(int nType);
881
894 virtual float FilteredFrameEnd();
895
907 virtual void StartAnim();
908
920 virtual void DumpText(Dbg &sink);
921
929 virtual void Save(Stream &stream);
930
939 virtual void Replace(Object *pFrom, Object *pTo);
940
949 virtual void Copy(const Object *pSource, unsigned nFlags);
950
961 virtual void Load(Stream &stream);
962
979
980protected:
992 virtual void SetFrameSelf(float flFrame);
993
994private:
1005 void ReleaseObjects();
1012 float FilterFrame(float flValue);
1019 void AcquireAnimsRefs();
1020
1021 // Declared in recovered offset order. The animatables this one drives, each of which
1022 // registers this object as a referrer.
1023 std::list<Animatable *> mAnims; // +0x04
1024 // The filter chain, owned outright and deleted by the destructor.
1025 std::list<Filter *> mFilters; // +0x08
1026 // The frame SetFrame() last received, before the filter chain.
1027 float mFrame; // +0x0c
1028
1029public:
1038};
1039
1040} // namespace Rnd
Front-end renderer that owns the screen stack and drives every MetScreen.
Definition metrenderer.h:68
One stage of the frame-number filter chain.
Definition animatable.h:84
virtual float Unapply(float flValue)
Map a value back through this stage.
virtual void Copy(const Filter *pSource)=0
Replace this stage's parameters with those of pSource.
virtual void Print(Dbg &sink) const =0
Write this stage's parameters to sink.
virtual void Load(Stream &stream)=0
Read this stage's parameters from stream.
virtual float Apply(float flValue)=0
Map a value forward through this stage.
virtual void Save(Stream &stream)=0
Write this stage's parameters to stream.
virtual int Type()=0
Report the type tag of this stage.
virtual void Copy(const Filter *pSource)
Copy both parameters from pSource.
virtual void Load(Stream &stream)
Read both parameters from stream.
virtual void Save(Stream &stream)
Write both parameters to stream.
virtual int Type()
Report kFilterFirstOrder.
FirstOrder(float flLevel, float flRatio)
Construct a stage with both parameters set.
Definition animatable.h:474
FirstOrder()
Construct a stage with indeterminate parameters.
Definition animatable.h:465
virtual float Apply(float flValue)
Move mLevel a fraction mRatio of the way towards the value.
virtual float Unapply(float flValue)
Report the mLevel that preceded an Apply() of the value.
virtual void Print(Dbg &sink) const
Write "(level:%.2f ratio:%.2f)" to sink.
virtual void Copy(const Filter *pSource)
Copy all three parameters from pSource.
virtual void Print(Dbg &sink) const
Write "(min:%.2f max:%.2f loop:true)" to sink, with mLoop as a word rather than a number.
virtual void Load(Stream &stream)
Read the two ends as floats and mLoop as a single byte.
virtual float Apply(float flValue)
Bring the value into the range.
MinMaxLoop()
Construct a stage with indeterminate parameters.
Definition animatable.h:274
MinMaxLoop(float flMin, float flMax, int nLoop)
Construct a stage with all three parameters set.
Definition animatable.h:286
virtual void Save(Stream &stream)
Write the two ends as floats and mLoop as a single byte.
float mMax
Definition animatable.h:351
virtual int Type()
Report kFilterMinMaxLoop.
float mMin
Definition animatable.h:350
virtual float Apply(float flValue)
Scale and then offset the value.
virtual int Type()
Report kFilterScaleOffset.
virtual void Load(Stream &stream)
Read both parameters from stream.
virtual void Copy(const Filter *pSource)
Copy both parameters from pSource.
float mOffset
Definition animatable.h:257
virtual void Save(Stream &stream)
Write both parameters to stream.
float mScale
Definition animatable.h:256
virtual void Print(Dbg &sink) const
Write "(scale:%.2f offset:%.2f)" to sink.
ScaleOffset(float flScale, float flOffset)
Construct a stage with both parameters set.
Definition animatable.h:183
ScaleOffset()
Construct a stage with indeterminate parameters.
Definition animatable.h:174
virtual float Unapply(float flValue)
Undo the affine map.
SecondOrder()
Construct a stage at rest with indeterminate spring parameters.
Definition animatable.h:566
virtual void Save(Stream &stream)
Write the three spring parameters to stream, the velocity excluded.
virtual void Copy(const Filter *pSource)
Copy all four members from pSource.
virtual int Type()
Report kFilterSecondOrder.
virtual float Unapply(float flValue)
Report the mLevel that preceded the last Apply().
SecondOrder(float flLevel, float flSpring, float flDamper)
Construct a stage at rest with all three parameters set.
Definition animatable.h:576
virtual void Load(Stream &stream)
Read the three spring parameters from stream, the velocity excluded.
virtual void Print(Dbg &sink) const
Write "(level:%.2f spring:%.2f damper:)%.2f vel%.2f" to sink.
virtual float Apply(float flValue)
Integrate the spring and the damper by one step.
ZeroOrder(float flLevel, float flMaxDelta)
Construct a stage with both parameters set.
Definition animatable.h:378
virtual void Load(Stream &stream)
Read both parameters from stream.
virtual void Print(Dbg &sink) const
Write "(level:%.2f maxDelta:%.2f)" to sink.
virtual float Unapply(float flValue)
Report the mLevel that preceded an Apply() of the value.
virtual void Save(Stream &stream)
Write both parameters to stream.
virtual float Apply(float flValue)
Advance mLevel towards the value by at most mMaxDelta.
virtual void Copy(const Filter *pSource)
Copy both parameters from pSource.
ZeroOrder()
Construct a stage with indeterminate parameters.
Definition animatable.h:369
virtual int Type()
Report kFilterZeroOrder.
virtual float FilteredFrameEnd()
Report the last frame this object's subtree animates to.
Animatable * Parent()
Report the animatable that animates this one.
void SetFrame(float flFrame)
Drive this object and its whole subtree to a frame.
float UnfilterFrame(float flValue)
Map a value back through mFilters.
void AddSecondOrder(float flLevel, float flSpring, float flDamper)
Append a new SecondOrder stage to mFilters.
friend void CollectChildren(std::list< Object * > &objects, Animatable *pAnimatable)
Append every animation descendant of an animatable.
Definition collectchildren.h:27
void RemoveAnim(Animatable *pAnim)
Erase pAnim from mAnims.
virtual void Load(Stream &stream)
Replace the filter chain and the child list from stream.
virtual void Replace(Object *pFrom, Object *pTo)
Retarget every mAnims entry equal to pFrom at pTo.
float mFilteredFrame
The frame SetFrame() last received, after the filter chain.
Definition animatable.h:1037
void AddMinMaxLoop(float flMin, float flMax, int nLoop)
Append a new MinMaxLoop stage to mFilters.
void AddScaleOffset(float flScale, float flOffset)
Append a new ScaleOffset stage to mFilters.
virtual void DumpText(Dbg &sink)
Write a description of this object to sink.
void AddZeroOrder(float flLevel, float flMaxDelta)
Append a new ZeroOrder stage to mFilters.
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
FilterType
Value a filter reports from Filter::Type() and a .rnd file stores in front of its payload.
Definition animatable.h:59
@ kFilterScaleOffset
Definition animatable.h:60
@ kFilterFirstOrder
Definition animatable.h:63
@ kFilterSecondOrder
Definition animatable.h:64
@ kFilterZeroOrder
Definition animatable.h:62
@ kFilterMinMaxLoop
Definition animatable.h:61
void AddAnim(Animatable *pAnim)
Append pAnim to mAnims.
void SetRate(float flRate)
Change the multiplier of the ScaleOffset stage at the front of mFilters.
void RemoveFilter(int nIndex)
Delete and erase the filter at one position in mFilters.
void AddFirstOrder(float flLevel, float flRatio)
Append a new FirstOrder stage to mFilters.
virtual void Copy(const Object *pSource, unsigned nFlags)
Clone the filter chain of pSource, and its child list when nFlags requests it.
void SetOffset(float flOffset)
Change the addend of the ScaleOffset stage at the front of mFilters.
virtual ~Animatable()
Drop this object's references on its children and delete its filters.
static Filter * NewFilter(int nType)
Build one default-constructed filter for a type tag.
virtual void SetFrameSelf(float flFrame)
Animate this object alone to a frame.
void SetLoopRange(float flMin, float flMax)
Change both ends of the MinMaxLoop stage at the back of mFilters.
void AddFilter(Filter *pFilter)
Append an already-built filter to mFilters.
void RemoveAllAnims()
Drop this object's reference on every mAnims entry and then empty mAnims.
Filter * FilterAt(int nIndex)
Return the filter at one position in mFilters.
virtual void StartAnim()
Restart the animation of this object and its whole subtree.
virtual void Save(Stream &stream)
Write the revision, mFilters, and mAnims to stream.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Object()
Construct an unnamed object.
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
The rendering engine.
Definition animhelper.h:3