Plasma Engine  2.0
Loading...
Searching...
No Matches
ScriptComponent.h
1#pragma once
2
3#include <Core/Scripting/ScriptClassResource.h>
4#include <Core/World/EventMessageHandlerComponent.h>
5#include <Foundation/Types/RangeView.h>
6
8
10{
12
14 // plComponent
15
16protected:
17 virtual void SerializeComponent(plWorldWriter& stream) const override;
18 virtual void DeserializeComponent(plWorldReader& stream) override;
19 virtual void Initialize() override;
20 virtual void Deinitialize() override;
21 virtual void OnActivated() override;
22 virtual void OnDeactivated() override;
23 virtual void OnSimulationStarted() override;
24
26 // plScriptComponent
27public:
30
31 void SetScriptVariable(const plHashedString& sName, const plVariant& value); // [ scriptable ]
32 plVariant GetScriptVariable(const plHashedString& sName) const; // [ scriptable ]
33
34 void SetScriptClass(const plScriptClassResourceHandle& hScript);
35 const plScriptClassResourceHandle& GetScriptClass() const { return m_hScriptClass; }
36
37 void SetScriptClassFile(const char* szFile); // [ property ]
38 const char* GetScriptClassFile() const; // [ property ]
39
40 void SetUpdateInterval(plTime interval); // [ property ]
41 plTime GetUpdateInterval() const; // [ property ]
42
44 // Exposed Parameters
45 const plRangeView<const char*, plUInt32> GetParameters() const;
46 void SetParameter(const char* szKey, const plVariant& value);
47 void RemoveParameter(const char* szKey);
48 bool GetParameter(const char* szKey, plVariant& out_value) const;
49
50 PL_ALWAYS_INLINE plScriptInstance* GetScriptInstance() { return m_pInstance.Borrow(); }
51
52private:
53 void InstantiateScript(bool bActivate);
54 void ClearInstance(bool bDeactivate);
55 void AddUpdateFunctionToSchedule();
56 void RemoveUpdateFunctionToSchedule();
57
58 const plAbstractFunctionProperty* GetScriptFunction(plUInt32 uiFunctionIndex);
59 void CallScriptFunction(plUInt32 uiFunctionIndex);
60
61 void ReloadScript();
62
64
65 plScriptClassResourceHandle m_hScriptClass;
66 plTime m_UpdateInterval = plTime::MakeZero();
67
68 plSharedPtr<plScriptRTTI> m_pScriptType;
70};
The base class for a property that represents a function.
Definition AbstractProperty.h:535
See plArrayMapBase for details.
Definition ArrayMap.h:149
virtual void OnDeactivated()
This method is called when the component gets deactivated.
Definition Component.cpp:142
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 Initialize()
Can be overridden for basic initialization that depends on a valid hierarchy and position.
Definition Component.cpp:131
virtual void OnActivated()
This method is called when the component gets activated.
Definition Component.cpp:140
Definition ComponentManager.h:88
Base class for components that want to handle 'event messages'.
Definition EventMessageHandlerComponent.h:14
virtual void SerializeComponent(plWorldWriter &inout_stream) const override
Override this to save the current state of the component to the given stream.
Definition EventMessageHandlerComponent.cpp:56
virtual void DeserializeComponent(plWorldReader &inout_stream) override
Override this to load the current state of the component from the given stream.
Definition EventMessageHandlerComponent.cpp:68
virtual void Deinitialize() override
This method is called before the component is destroyed. A derived type can override this method to d...
Definition EventMessageHandlerComponent.cpp:88
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
This class uses delegates to define a range of values that can be enumerated using a forward iterator...
Definition RangeView.h:24
Definition ScriptComponent.h:10
Definition ScriptRTTI.h:66
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
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
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeZero()
Creates an instance of plTime that was initialized with zero.
Definition Time.h:42