Plasma Engine  2.0
Loading...
Searching...
No Matches
ScriptWorldModule.h
1#pragma once
2
3#include <Core/ResourceManager/ResourceHandle.h>
4#include <Core/Scripting/ScriptCoroutine.h>
5#include <Core/Utils/IntervalScheduler.h>
6#include <Core/World/World.h>
7#include <Foundation/CodeUtils/Expression/ExpressionVM.h>
8
11
12class PL_CORE_DLL plScriptWorldModule : public plWorldModule
13{
14 PL_DECLARE_WORLD_MODULE();
15 PL_ADD_DYNAMIC_REFLECTION(plScriptWorldModule, plWorldModule);
16 PL_DISALLOW_COPY_AND_ASSIGN(plScriptWorldModule);
17
18public:
21
22 virtual void Initialize() override;
23 virtual void WorldClear() override;
24
25 void AddUpdateFunctionToSchedule(const plAbstractFunctionProperty* pFunction, void* pInstance, plTime updateInterval, bool bOnlyWhenSimulating);
26 void RemoveUpdateFunctionToSchedule(const plAbstractFunctionProperty* pFunction, void* pInstance);
27
30
34 plScriptCoroutineHandle CreateCoroutine(const plRTTI* pCoroutineType, plStringView sName, plScriptInstance& inout_instance, plScriptCoroutineCreationMode::Enum creationMode, plScriptCoroutine*& out_pCoroutine);
35
37 void StartCoroutine(plScriptCoroutineHandle hCoroutine, plArrayPtr<plVariant> arguments);
38
40 void StopAndDeleteCoroutine(plScriptCoroutineHandle hCoroutine);
41
43 void StopAndDeleteCoroutine(plStringView sName, plScriptInstance* pInstance);
44
46 void StopAndDeleteAllCoroutines(plScriptInstance* pInstance);
47
49 bool IsCoroutineFinished(plScriptCoroutineHandle hCoroutine) const;
50
52
55 plExpressionVM& GetSharedExpressionVM() { return m_SharedExpressionVM; }
56
58 {
59 enum Flags : plUInt8
60 {
61 None,
62 OnlyWhenSimulating
63 };
64
66 void* m_pInstance = nullptr;
67
68 bool operator==(const FunctionContext& other) const
69 {
70 return m_pFunctionAndFlags == other.m_pFunctionAndFlags && m_pInstance == other.m_pInstance;
71 }
72 };
73
74private:
75 void CallUpdateFunctions(const plWorldModule::UpdateContext& context);
76
78
82
83 plExpressionVM m_SharedExpressionVM;
84};
85
87
88template <>
89struct plHashHelper<plScriptWorldModule::FunctionContext>
90{
91 PL_ALWAYS_INLINE static plUInt32 Hash(const plScriptWorldModule::FunctionContext& value)
92 {
93 plUInt32 hash = plHashHelper<const void*>::Hash(value.m_pFunctionAndFlags);
95 return hash;
96 }
97
98 PL_ALWAYS_INLINE static bool Equal(const plScriptWorldModule::FunctionContext& a, const plScriptWorldModule::FunctionContext& b) { return a == b; }
99};
The base class for a property that represents a function.
Definition AbstractProperty.h:535
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
Definition ExpressionVM.h:7
Definition HashTable.h:333
static constexpr plUInt32 CombineHashValues32(plUInt32 ui0, plUInt32 ui1)
Combines two 32 bit hash values into one.
Definition HashingUtils_inl.h:144
Definition IdTable.h:171
Definition IntervalScheduler.h:65
A wrapper around a raw pointer that allows to use the lower N bits for flags.
Definition PointerWithFlags.h:12
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Base class of script coroutines.
Definition ScriptCoroutine.h:35
Definition ScriptRTTI.h:66
Definition ScriptWorldModule.h:13
plExpressionVM & GetSharedExpressionVM()
Returns a expression vm that can be used in custom script implementations. Make sure to only execute ...
Definition ScriptWorldModule.h:55
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition WorldModule.h:10
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
virtual void WorldClear()
Called by plWorld::Clear(). Can be used to clear cached data when a world is completely cleared of ob...
Definition WorldModule.h:108
Helper struct to calculate the Hash of different types.
Definition HashingUtils.h:75
Enum
Definition ScriptCoroutine.h:122
A handle to a script coroutine which can be used to determine whether a coroutine is still running ev...
Definition ScriptCoroutine.h:16
Definition ScriptWorldModule.h:58
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
Definition WorldModule.h:33