Emergency 20 Dokumentation  4.2.0
FireSpreadCalculation.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include <qsf/math/Color4.h>
14 #include <qsf/time/Time.h>
15 
16 #include <thread>
17 #include <atomic>
18 #include <vector>
19 #include <condition_variable>
20 
21 
22 //[-------------------------------------------------------]
23 //[ Forward declarations ]
24 //[-------------------------------------------------------]
25 namespace em5
26 {
27  class FireReceiverComponent;
28 }
29 
30 
31 //[-------------------------------------------------------]
32 //[ Namespace ]
33 //[-------------------------------------------------------]
34 namespace em5
35 {
36 
37 
38  //[-------------------------------------------------------]
39  //[ Structs ]
40  //[-------------------------------------------------------]
41  namespace firesimulation
42  {
43  // This struct holds all data needed inside the multi-threaded fire simulation
45  {
48  bool mIsBurning;
50  float mHardRadius;
51  float mSoftRadius;
52  float mFireEnergy;
53  glm::vec3 mPosition;
54  bool mHasPosition;
56  bool mIsExploded;
60  };
61  }
62 
63 
64  //[-------------------------------------------------------]
65  //[ Classes ]
66  //[-------------------------------------------------------]
75  {
76 
77 
78  //[-------------------------------------------------------]
79  //[ Public definitions ]
80  //[-------------------------------------------------------]
81  public:
83 
84  // Holds the data for the fire spread lines
86  {
87  glm::vec3 mStartPosition;
88  glm::vec3 mEndPosition;
90  float mFireEnergy;
93  float mFactor;
94 
95  // Need a default constructor otherwise vector::emplace_back(<val>, <val2>) doesn't work...
96  inline DebugRequestData() :
97  mFireEnergy(0.0f),
98  mTargetEntityId(qsf::getUninitialized<uint64>()),
99  mSourceEntityId(qsf::getUninitialized<uint64>()),
100  mFactor(0.0f)
101  {}
102 
103  // Need a constructor otherwise vector::emplace_back(<val>, <val2>) doesn't work...
104  // Note: the mPosition element in the given ComponentDatas must be valid
105  DebugRequestData(const ComponentData& sourceComponent, const ComponentData& targetComponent, const qsf::Color4& lineColor, const float& fireEnergy);
106  };
107 
108 
109  //[-------------------------------------------------------]
110  //[ Public methods ]
111  //[-------------------------------------------------------]
112  public:
118 
126  // We don't return a const reference to the container because the caller swaps out the content of the container
127  std::vector<ComponentData>& getCalculationResult();
128 
134 
139  void startNextCalculationRun(float secondsPassed);
140 
145  ComponentData& addNewComponentData();
146 
151  void stopCalculation();
152 
158 
163  inline const std::vector<DebugRequestData>& getDebugDrawRequests() const;
164 
169  inline void setDebugActive(bool isActive);
170 
175  inline int64 getCalculationTime() const;
176 
181  inline const qsf::Time getTimePassed() const;
182 
183 
184  //[-------------------------------------------------------]
185  //[ Private methods ]
186  //[-------------------------------------------------------]
187  private:
192  void doFireSpreadCalculation();
193 
194  void getItemsInCircle(const glm::vec3& center, float radius, std::vector<ComponentData*>& result);
195 
196  void applyCoolingEnergy(ComponentData& componentData);
197 
198  void updateSpreadFire(const ComponentData& componentData);
199 
200  // Note: the mPosition member of the components data parameters must be valid
201  bool calcSpreadingEnergy(const ComponentData& sourceComponent, ComponentData& targetComponent, float& amountSpreadEnergy);
202 
203  void calculateDebugInformation();
204 
205 
206  //[-------------------------------------------------------]
207  //[ Private data ]
208  //[-------------------------------------------------------]
209  private:
210  std::atomic<bool> mRunning;
211  bool mShowDebug;
212  int64 mCalculationTime;
213  float mSecondsPassed;
214  float mFireEnergyMultiplier;
215  std::unique_ptr<std::thread> mCalculationThread;
216  std::vector<ComponentData> mComponentList;
217  std::condition_variable mConditionalVariable;
218  std::mutex mMutex;
219  std::vector<DebugRequestData> mDebugDrawRequestsCache;
220 
221 
222  };
223 
224 
225 //[-------------------------------------------------------]
226 //[ Namespace ]
227 //[-------------------------------------------------------]
228 } // em5
229 
230 
231 //[-------------------------------------------------------]
232 //[ Implementation ]
233 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
ComponentData & addNewComponentData()
Add a new uninitialized component data element, and return a reference to it.
float mFireResistance
The resistance to fire energy.
Definition: FireSpreadCalculation.h:59
uint64 mSourceEntityId
The entity ID of the source fire component (This entity is selectable)
Definition: FireSpreadCalculation.h:92
int64 getCalculationTime() const
Returns the time (in microseconds) how much time the thread spent to do the calculation.
Definition: FireSpreadCalculation-inl.h:24
float mCalculatedSpreadEnergy
Calculated amount of fire energy a fire receiver gets from other entities.
Definition: FireSpreadCalculation.h:55
void startNextCalculationRun(float secondsPassed)
Start the next calculation run.
float mFireEnergy
How much fire energy gets transferred via this "line".
Definition: FireSpreadCalculation.h:90
Color class with red, green, blue and alpha component.
Definition: Color4.h:39
bool mIsDestroyed
Definition: FireSpreadCalculation.h:49
EMERGENCY 5 fire receiver component class.
Definition: FireReceiverComponent.h:69
void setDebugActive(bool isActive)
Setter for setting the information of debug request data should be generated for fire receiver lines...
Definition: FireSpreadCalculation-inl.h:19
glm::vec3 mPosition
Position of the component, needed for getting the neighbours of a fire component, is optional (e...
Definition: FireSpreadCalculation.h:53
bool mHasPosition
"true" if position of the component is set at all
Definition: FireSpreadCalculation.h:54
float mSoftRadius
The soft radius of the fire component (is zero for fire receiver)
Definition: FireSpreadCalculation.h:51
float mFireEnergy
The amount of fire energy which the component has.
Definition: FireSpreadCalculation.h:52
uint64 mTargetEntityId
The entity ID of the target fire receiver (This entity is selectable)
Definition: FireSpreadCalculation.h:91
FireReceiverComponent * mComponent
Fire receiver component (or fire component) to which this data block belongs; note that this will be ...
Definition: FireSpreadCalculation.h:46
std::vector< ComponentData > & getCalculationResult()
Returns the result of the last calculation.
glm::vec3 mEndPosition
End position of the line.
Definition: FireSpreadCalculation.h:88
Definition: FireSpreadCalculation.h:44
uint64_t uint64
Definition: PlatformTypes.h:184
bool mIsBurning
Indicates of the entity is already burning.
Definition: FireSpreadCalculation.h:48
Definition: PickupPersonByParamedicAction.h:21
firesimulation::ComponentData ComponentData
Definition: FireSpreadCalculation.h:82
void invalidateComponent(FireReceiverComponent &component)
Invalidate a component for fire spread calculation.
bool mIsFireSender
Indicates if the entity is emitting heat energy (it is burning)
Definition: FireSpreadCalculation.h:47
float mHardRadius
The hard radius of the fire component (is zero for fire receiver)
Definition: FireSpreadCalculation.h:50
void prepareNextCalculationRun()
Prepare for the next calculation run, remove old component data.
T getUninitialized()
Definition: GetUninitialized.h:38
float mCoolingEnergy
The amount of cooling energy which the component has currently applied.
Definition: FireSpreadCalculation.h:57
FireSpreadCalculation()
Default constructor.
glm::vec3 mStartPosition
Start position of the line.
Definition: FireSpreadCalculation.h:87
float mFactor
Percent value how much the transferred energy contributes to the whole transferred energy to the targ...
Definition: FireSpreadCalculation.h:93
int64_t int64
Definition: PlatformTypes.h:183
const qsf::Time getTimePassed() const
Returns the time passed value which was used for the calculation (for time based interpolation) ...
Definition: FireSpreadCalculation-inl.h:29
const std::vector< DebugRequestData > & getDebugDrawRequests() const
Returns a list of DebugRequestData items for displaying fire receiver debug draw info.
Definition: FireSpreadCalculation-inl.h:14
DebugRequestData()
Definition: FireSpreadCalculation.h:96
void stopCalculation()
Stops the calculation thread (the thread has ended after this call)
qsf::Color4 mLineColor
Line color.
Definition: FireSpreadCalculation.h:89
bool mIsExploded
Indicates if the entity exploded.
Definition: FireSpreadCalculation.h:56
ComponentData const * mSource
Component data instance of the fire receiver component which caused the first fire energy delivery (m...
Definition: FireSpreadCalculation.h:58
Definition: FireSpreadCalculation.h:85
Fire spread calculation helper.
Definition: FireSpreadCalculation.h:74
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32