Plasma Engine  2.0
Loading...
Searching...
No Matches
PropertyAnimComponent.h
1#pragma once
2
3#include <Core/Messages/CommonMessages.h>
4#include <Core/Messages/EventMessage.h>
5#include <Core/World/Component.h>
6#include <Core/World/World.h>
7#include <Foundation/Types/SharedPtr.h>
8#include <GameEngine/Animation/PropertyAnimResource.h>
9#include <GameEngine/GameEngineDLL.h>
10struct plMsgSetPlaying;
11
13
18class PL_GAMEENGINE_DLL plPropertyAnimComponent : public plComponent
19{
21
23 // plComponent
24
25public:
26 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
27 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
28
29protected:
30 virtual void OnSimulationStarted() override;
31
33 // plPropertyAnimComponent
34
35public:
38
39 void SetPropertyAnimFile(const char* szFile); // [ property ]
40 const char* GetPropertyAnimFile() const; // [ property ]
41
42 void SetPropertyAnim(const plPropertyAnimResourceHandle& hResource); // [ property ]
43 PL_ALWAYS_INLINE const plPropertyAnimResourceHandle& GetPropertyAnim() const { return m_hPropertyAnim; } // [ property ]
44
46 void PlayAnimationRange(plTime rangeLow, plTime rangeHigh); // [ scriptable ]
47
49 void OnMsgSetPlaying(plMsgSetPlaying& ref_msg); // [ msg handler ]
50
51 plEnum<plPropertyAnimMode> m_AnimationMode; // [ property ]
52 plTime m_RandomOffset; // [ property ]
53 float m_fSpeed = 1.0f; // [ property ]
54 plTime m_AnimationRangeLow; // [ property ]
55 plTime m_AnimationRangeHigh; // [ property ]
56 bool m_bPlaying = true; // [ property ]
57
58protected:
59 plEventMessageSender<plMsgAnimationReachedEnd> m_ReachedEndMsgSender; // [ event ]
60 plEventMessageSender<plMsgGenericEvent> m_EventTrackMsgSender; // [ event ]
61
62 struct Binding
63 {
64 const plAbstractMemberProperty* m_pMemberProperty = nullptr;
65 mutable void* m_pObject = nullptr; // needs to be updated in case components / objects get relocated in memory
66 };
67
68 struct FloatBinding : public Binding
69 {
70 const plFloatPropertyAnimEntry* m_pAnimation[4] = {nullptr, nullptr, nullptr, nullptr};
71 };
72
74 {
75 plComponentHandle m_hComponent;
76 };
77
79 {
80 plGameObjectHandle m_hObject;
81 };
82
83 struct ColorBinding : public Binding
84 {
85 plComponentHandle m_hComponent;
86 const plColorPropertyAnimEntry* m_pAnimation = nullptr;
87 };
88
89 void Update();
90 void CreatePropertyBindings();
91 void CreateGameObjectBinding(const plFloatPropertyAnimEntry* pAnim, const plRTTI* pRtti, void* pObject, const plGameObjectHandle& hGameObject);
92 void CreateFloatPropertyBinding(const plFloatPropertyAnimEntry* pAnim, const plRTTI* pRtti, void* pObject, const plComponentHandle& hComponent);
93 void CreateColorPropertyBinding(const plColorPropertyAnimEntry* pAnim, const plRTTI* pRtti, void* pObject, const plComponentHandle& hComponent);
94 void ApplyAnimations(const plTime& tDiff);
95 void ApplyFloatAnimation(const FloatBinding& binding, plTime lookupTime);
96 void ApplySingleFloatAnimation(const FloatBinding& binding, plTime lookupTime);
97 void ApplyColorAnimation(const ColorBinding& binding, plTime lookupTime);
98 plTime ComputeAnimationLookup(plTime tDiff);
99 void EvaluateEventTrack(plTime startTime, plTime endTime);
100 void StartPlayback();
101
102 bool m_bReverse = false;
103
104 plTime m_AnimationTime;
105 plHybridArray<GameObjectBinding, 4> m_GoFloatBindings;
106 plHybridArray<ComponentFloatBinding, 4> m_ComponentFloatBindings;
107 plHybridArray<ColorBinding, 4> m_ColorBindings;
108 plPropertyAnimResourceHandle m_hPropertyAnim;
109
110 // we do not want to recreate the binding when the resource changes at runtime
111 // therefore we use a sharedptr to keep the data around as long as necessary
112 // otherwise that would lead to weird state, because the animation would be interrupted at some point
113 // and then the new animation would start from there
114 // e.g. when the position is animated, objects could jump around the level
115 // when the animation resource is reloaded
116 // instead we go with one animation state until this component is reset entirely
117 // that means you need to restart a level to see the updated animation
119};
This is the base class for all properties that are members of a class. It provides more information a...
Definition AbstractProperty.h:237
Base class of all component types.
Definition Component.h:25
virtual void SerializeComponent(plWorldWriter &inout_stream) const
Override this to save the current state of the component to the given stream.
Definition Component.cpp:54
virtual void OnSimulationStarted()
This method is called once for active components, at the start of the next world update,...
Definition Component.cpp:144
virtual void DeserializeComponent(plWorldReader &inout_stream)
Override this to load the current state of the component from the given stream.
Definition Component.cpp:58
Simple component manager implementation that calls an update method on all components every frame.
Definition ComponentManager.h:142
A message sender that sends all messages to the next component derived from plEventMessageHandlerComp...
Definition EventMessage.h:39
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Animates properties on other objects and components according to the property animation resource.
Definition PropertyAnimComponent.h:19
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
Definition PropertyAnimResource.h:69
A handle to a component.
Definition Declarations.h:138
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition PropertyAnimResource.h:64
A handle to a game object.
Definition Declarations.h:76
Common message for components that can be toggled between playing and paused states.
Definition CommonMessages.h:9
Definition PropertyAnimComponent.h:63
Definition PropertyAnimComponent.h:84
Definition PropertyAnimComponent.h:74
Definition PropertyAnimComponent.h:69
Definition PropertyAnimComponent.h:79
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12