Plasma Engine  2.0
Loading...
Searching...
No Matches
SpawnBoxComponent.h
1#pragma once
2
3#include <Core/Prefabs/PrefabResource.h>
4#include <Core/World/Component.h>
5#include <Core/World/ComponentManager.h>
6
8
10{
11 using StorageType = plUInt16;
12
13 enum Enum
14 {
15 None = 0,
16 SpawnAtStart = PL_BIT(0),
17 SpawnContinuously = PL_BIT(1),
18
19 Default = None
20 };
21
22 struct Bits
23 {
24 StorageType SpawnAtStart : 1;
25 };
26};
27
28PL_DECLARE_FLAGS_OPERATORS(plSpawnBoxComponentFlags);
29
31
41{
43
45 // plComponent
46
47public:
48 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
49 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
50
51protected:
52 virtual void OnSimulationStarted() override;
53
55 // plSpawnBoxComponent
56
57public:
61 void StartSpawning(); // [ scriptable ]
62
63 void SetHalfExtents(const plVec3& value); // [ property ]
64 const plVec3& GetHalfExtents() const { return m_vHalfExtents; } // [ property ]
65
66 void SetPrefabFile(const char* szFile); // [ property ]
67 const char* GetPrefabFile() const; // [ property ]
68
69 bool GetSpawnAtStart() const; // [ property ]
70 void SetSpawnAtStart(bool b); // [ property ]
71
72 bool GetSpawnContinuously() const; // [ property ]
73 void SetSpawnContinuously(bool b); // [ property ]
74
75 plTime m_SpawnDuration; // [ property ]
76 plUInt16 m_uiMinSpawnCount = 5; // [ property ]
77 plUInt16 m_uiSpawnCountRange = 5; // [ property ]
78 plPrefabResourceHandle m_hPrefab; // [ property ]
79
81 plAngle m_MaxRotationZ; // [ property ]
82
84 plAngle m_MaxTiltZ; // [ property ]
85
86
87private:
88 void OnTriggered(plMsgComponentInternalTrigger& msg);
89 void Spawn(plUInt32 uiCount);
90 void InternalStartSpawning(bool bFirstTime);
91
92 plUInt16 m_uiSpawned = 0;
93 plUInt16 m_uiTotalToSpawn = 0;
94 plTime m_StartTime;
96 plVec3 m_vHalfExtents = plVec3(0.5f);
97};
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
This component spawns prefabs inside a box.
Definition SpawnBoxComponent.h:41
virtual void OnSimulationStarted() override
This method is called once for active components, at the start of the next world update,...
Definition SpawnBoxComponent.cpp:127
plAngle m_MaxRotationZ
The spawned object's forward direction may deviate this amount from the spawn box's forward rotation....
Definition SpawnBoxComponent.h:81
plAngle m_MaxTiltZ
The spawned object's Z (up) axis may deviate by this amount from the spawn box's Z axis.
Definition SpawnBoxComponent.h:84
virtual void DeserializeComponent(plWorldReader &inout_stream) override
Override this to load the current state of the component from the given stream.
Definition SpawnBoxComponent.cpp:112
void StartSpawning()
When called, the component starts spawning the chosen number of prefabs over the set duration.
Definition SpawnBoxComponent.cpp:137
virtual void SerializeComponent(plWorldWriter &inout_stream) const override
Override this to save the current state of the component to the given stream.
Definition SpawnBoxComponent.cpp:97
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 SpawnBoxComponent.h:23
Definition SpawnBoxComponent.h:10
Enum
Definition SpawnBoxComponent.h:14
@ SpawnContinuously
Every time a spawn duration has finished, a new one is started.
Definition SpawnBoxComponent.h:17
@ SpawnAtStart
The component will schedule a spawn once at creation time.
Definition SpawnBoxComponent.h:16
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12