Plasma Engine  2.0
Loading...
Searching...
No Matches
SpawnComponent.h
1#pragma once
2
3#include <GameEngine/GameEngineDLL.h>
4
5#include <Core/Prefabs/PrefabResource.h>
6#include <Core/World/World.h>
7#include <Foundation/Types/RangeView.h>
8
10
12{
13 using StorageType = plUInt16;
14
15 enum Enum
16 {
17 None = 0,
18 SpawnAtStart = PL_BIT(0),
19 SpawnContinuously = PL_BIT(1),
20 AttachAsChild = PL_BIT(2),
21 SpawnInFlight = PL_BIT(3),
22
23 Default = None
24 };
25
26 struct Bits
27 {
28 StorageType SpawnAtStart : 1;
29 StorageType SpawnContinuously : 1;
30 StorageType AttachAsChild : 1;
31 StorageType SpawnInFlight : 1;
32 };
33};
34
35PL_DECLARE_FLAGS_OPERATORS(plSpawnComponentFlags);
36
38
46class PL_GAMEENGINE_DLL plSpawnComponent : public plComponent
47{
48 PL_DECLARE_COMPONENT_TYPE(plSpawnComponent, plComponent, plSpawnComponentManager);
49
51 // plComponent
52
53public:
54 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
55 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
56
57protected:
58 virtual void OnSimulationStarted() override;
59 virtual void OnDeactivated() override;
60
61
63 // plSpawnComponent
64
65public:
68
70 bool CanTriggerManualSpawn() const; // [ scriptable ]
71
77 bool TriggerManualSpawn(bool bIgnoreSpawnDelay = false, const plVec3& vLocalOffset = plVec3::MakeZero()); // [ scriptable ]
78
83 void ScheduleSpawn(); // [ scriptable ]
84
86 void SetPrefabFile(const char* szFile); // [ property ]
87 const char* GetPrefabFile() const; // [ property ]
88
90 void SetSpawnAtStart(bool b); // [ property ]
91 bool GetSpawnAtStart() const; // [ property ]
92
94 void SetSpawnContinuously(bool b); // [ property ]
95 bool GetSpawnContinuously() const; // [ property ]
96
98 void SetAttachAsChild(bool b); // [ property ]
99 bool GetAttachAsChild() const; // [ property ]
100
102 void SetPrefab(const plPrefabResourceHandle& hPrefab);
103 PL_ALWAYS_INLINE const plPrefabResourceHandle& GetPrefab() const { return m_hPrefab; }
104
106 plTime m_MinDelay; // [ property ]
107
109 plTime m_DelayRange; // [ property ]
110
112 plAngle m_MaxDeviation; // [ property ]
113
114 const plRangeView<const char*, plUInt32> GetParameters() const; // [ property ] (exposed parameter)
115 void SetParameter(const char* szKey, const plVariant& value); // [ property ] (exposed parameter)
116 void RemoveParameter(const char* szKey); // [ property ] (exposed parameter)
117 bool GetParameter(const char* szKey, plVariant& out_value) const; // [ property ] (exposed parameter)
118
121
122protected:
124
125 virtual void DoSpawn(const plTransform& tLocalSpawn);
126 bool SpawnOnce(const plVec3& vLocalOffset);
127 void OnTriggered(plMsgComponentInternalTrigger& msg);
128
129 plTime m_LastManualSpawn;
130 plPrefabResourceHandle m_hPrefab;
131};
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
See plArrayMapBase for details.
Definition ArrayMap.h:149
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 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 DeserializeComponent(plWorldReader &inout_stream)
Override this to load the current state of the component from the given stream.
Definition Component.cpp:58
Definition ComponentManager.h:88
This class uses delegates to define a range of values that can be enumerated using a forward iterator...
Definition RangeView.h:24
Spawns instances of prefabs dynamically at runtime.
Definition SpawnComponent.h:47
plArrayMap< plHashedString, plVariant > m_Parameters
Key/value pairs of parameters to pass to the prefab instantiation.
Definition SpawnComponent.h:120
plTime m_DelayRange
For scheduled spawns (continuous / at start) this is an additional random range on top of the minimum...
Definition SpawnComponent.h:109
plAngle m_MaxDeviation
The spawned object's orientation may deviate by this amount around the X axis. 180° is completely ran...
Definition SpawnComponent.h:112
plTime m_MinDelay
The minimum delay between spawning objects. This is also enforced for manually spawning things.
Definition SpawnComponent.h:106
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
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 plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
For internal use by components to trigger some known behavior. Usually components will post this mess...
Definition TriggerMessage.h:26
Definition SpawnComponent.h:27
Definition SpawnComponent.h:12
Enum
Definition SpawnComponent.h:16
@ AttachAsChild
All objects spawned will be attached as children to this node.
Definition SpawnComponent.h:20
@ SpawnInFlight
[internal] A spawn trigger message has been posted.
Definition SpawnComponent.h:21
@ SpawnContinuously
Every time a scheduled spawn was done, a new one is scheduled.
Definition SpawnComponent.h:19
@ SpawnAtStart
The component will schedule a spawn once at creation time.
Definition SpawnComponent.h:18
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12