Emergency 20 Dokumentation  4.2.0
ComplexFireComponent.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 "em5/fire/component/FireReceiverComponent.h" // As parent class
15 
16 
17 //[-------------------------------------------------------]
18 //[ Forward declarations ]
19 //[-------------------------------------------------------]
20 namespace em5
21 {
22  class DamageComponent;
23 }
24 
25 
26 //[-------------------------------------------------------]
27 //[ Namespace ]
28 //[-------------------------------------------------------]
29 namespace em5
30 {
31 
32 
33  //[-------------------------------------------------------]
34  //[ Classes ]
35  //[-------------------------------------------------------]
51  {
52 
53 
54  //[-------------------------------------------------------]
55  //[ Friends ]
56  //[-------------------------------------------------------]
57  friend class FireComponent;
58 
59 
60  //[-------------------------------------------------------]
61  //[ Public definitions ]
62  //[-------------------------------------------------------]
63  public:
64  static const uint32 COMPONENT_ID;
65  static const uint32 FIREENTITIES_ARRAY;
66 
67  static const float MAXIMUM_BALANCING_PERCENT;
68 
69 
70  //[-------------------------------------------------------]
71  //[ Public methods ]
72  //[-------------------------------------------------------]
73  public:
81  inline explicit ComplexFireComponent(qsf::Prototype* prototype);
82 
87  inline virtual ~ComplexFireComponent();
88 
93  void balancingFireEnergy();
94 
99  void startFire(FreeplayEvent* freeplayEvent = nullptr);
100 
105  void startFireOnAllFireComponents(FreeplayEvent* freeplayEvent);
106 
111  void stopFire();
112 
117  void destroyByFire();
118 
123  bool isReadyForCleanup() const;
124 
129  void cleanup();
130 
131  float getRelativeCombustionEnergy() const;
132 
133  void setEnergyPercent(float fraction);
134 
139  float getEnergyPercent() const;
140 
141  float getTotalDamagePercentage() const;
142 
147  void updateHitPointBar();
148 
153  FireComponent* getBurningFireComponent() const;
154 
159  void getAllFireComponents(std::vector<FireComponent*>& fireComponents) const;
160 
165  const std::vector<uint64>& getAllFireParticleIds() const;
166 
171  bool isBurnable() const;
172 
173  void updateParticlesVisibility();
174 
175 
176  //[-------------------------------------------------------]
177  //[ Public virtual em5::FireReceiver methods ]
178  //[-------------------------------------------------------]
179  public:
180  virtual bool canCountedForExtinguishAchievement() const override;
181  virtual void setCountedForExtinguishAchievement(bool canCounted) override;
182 
183 
184  //[-------------------------------------------------------]
185  //[ Public virtual qsf::FireReceiver methods ]
186  //[-------------------------------------------------------]
187  public:
192  inline virtual bool isBurned() const override;
193 
198  inline virtual bool isBurning() const override;
199 
216  virtual void addCoolingEnergySource(uint64 entityId, float extinguishEnergy, float coolingEnergy) override;
217 
228  virtual void removeCoolingEnergySource(uint64 entityId) override;
229 
230 
231  //[-------------------------------------------------------]
232  //[ Protected virtual em5::FireReceiver methods ]
233  //[-------------------------------------------------------]
234  protected:
235  virtual bool checkFireReceiver(qsf::Component* senderComponent) override;
236  virtual void receiveFireEnergy(float fireEnergy, const qsf::Time& timePassed, qsf::Component* senderComponent) override;
237  virtual void updateSimulation(const qsf::Time& timePassed) override;
238 
239 
240  //[-------------------------------------------------------]
241  //[ Protected virtual qsf::Component methods ]
242  //[-------------------------------------------------------]
243  protected:
244  virtual void onSetActive(bool active) override;
245  virtual void onSetSimulating(bool simulating) override;
246 
247 
248  //[-------------------------------------------------------]
249  //[ Protected virtual qsf::MovableObjectRenderingListener methods ]
250  //[-------------------------------------------------------]
251  protected:
252  virtual qsf::Component* getMovableObjectRenderingListenerComponent() override;
253  virtual void onObjectRenderingStartup() override;
254 
255 
256  //[-------------------------------------------------------]
257  //[ Protected virtual qsf::JobProxyMovableObjectRenderingListener methods ]
258  //[-------------------------------------------------------]
259  protected:
260  virtual void onUpdateMovableObjectRenderingJob(const qsf::JobArguments& jobArguments) override;
261 
262 
263  //[-------------------------------------------------------]
264  //[ Private methods ]
265  //[-------------------------------------------------------]
266  private:
267  // Job updates
268  void updateDamageComponent();
269 
279  bool checkForBalancingEnergy(float& totalEnergy, const std::vector<FireComponent*>& fireComponents) const;
280 
281  void rebuildFireComponentArray();
282 
283  // This method must be called after the fire component array is build/updated
284  void assignFireParticlesToFireComponents();
285  void updateComplexFireVisualization(); // TODO(co) Complex fire visualization test so I'm able to test the visual aspect
286 
287  // State change
288  void recheckFireState();
289  void onStartedBurning();
290  void onStoppedBurning();
291 
292  // Called by em5::FireComponent
293  void onFireComponentStartedBurning(FireComponent& fireComponent);
294  void onFireComponentStoppedBurning(FireComponent& fireComponent);
295 
296  // Gets called when a fire/fireparticle entity slot changes
297  void onFireAndFireParticleEntitiesSlotChanged();
298 
299 
300  //[-------------------------------------------------------]
301  //[ Private definitions ]
302  //[-------------------------------------------------------]
303  private:
304  typedef std::vector<uint64> EntityIdArray;
305  typedef std::vector<FireComponent*> FireComponentArray;
306 
307 
308  //[-------------------------------------------------------]
309  //[ Private data ]
310  //[-------------------------------------------------------]
311  private:
312  qsf::JobProxy mSimulationJobProxy;
313  EntityIdArray mEntityIds;
314  EntityIdArray mFireParticleEntityIds;
315  FireComponent::FireState mFireState;
316  FireComponentArray mFireComponents;
317  qsf::WeakPtr<DamageComponent> mDamageComponent;
318  size_t mNumFireObjects;
319 
320  // Fire bar
321  qsf::DebugDrawProxy mHitpointbarProxy;
322  uint32 mLastShownHitpointValue;
323  float mTotalDamage;
324 
325  // Helper member
326  bool mPrintedNoFireComponentsWarning;
327  qsf::JobProxy mOneShotUpdateParticleAssignmentJobProxy;
328 
329 
330  //[-------------------------------------------------------]
331  //[ CAMP reflection system ]
332  //[-------------------------------------------------------]
333  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
334 
335  public:
336  QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(EntityIdArrayInterface, ComplexFireComponent, std::vector<uint64>, uint64);
337  EntityIdArrayInterface FireEntityIdArray;
338  EntityIdArrayInterface FireParticleIdArray;
339 
340 
341  };
342 
343 
344 //[-------------------------------------------------------]
345 //[ Namespace ]
346 //[-------------------------------------------------------]
347 } // em5
348 
349 
350 //[-------------------------------------------------------]
351 //[ Implementation ]
352 //[-------------------------------------------------------]
353 #include "em5/fire/component/ComplexFireComponent-inl.h"
354 
355 
356 //[-------------------------------------------------------]
357 //[ CAMP reflection system ]
358 //[-------------------------------------------------------]
360 QSF_CAMP_ARRAY_MAPPER_DEFINITION(em5::ComplexFireComponent::EntityIdArrayInterface)
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
Abstract component class.
Definition: Component.h:105
Job proxy based OGRE movable object rendering listener.
Definition: JobProxyMovableObjectRenderingListener.h:31
unsigned int uint32
Definition: PlatformTypes.h:181
EMERGENCY 5 fire receiver component class.
Definition: FireReceiverComponent.h:69
FireState
Definition: FireComponent.h:88
#define EM5_API_EXPORT
Definition: Export.h:28
Definition: AreaConfiguration.h:58
EMERGENCY 5 complex fire component class.
Definition: ComplexFireComponent.h:50
#define QSF_CAMP_ARRAY_INTERFACE_CLASS_WITH_VARIABLE(interfaceClassName, ownerType, variableType, elementType)
Definition: CampClass.h:241
EMERGENCY 5 fire component class.
Definition: FireComponent.h:64
static const float MAXIMUM_BALANCING_PERCENT
Definition: ComplexFireComponent.h:67
uint64_t uint64
Definition: PlatformTypes.h:184
Lightweight weak pointer implementation.
Definition: WeakPtr.h:133
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
static const uint32 FIREENTITIES_ARRAY
Property id for the fire entities array.
Definition: ComplexFireComponent.h:65
QSF_CAMP_ARRAY_MAPPER_DEFINITION(qsf::ai::TrafficLightTimerComponent::ManagedTrafficLightList)
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Prototype class.
Definition: Prototype.h:100
static const uint32 COMPONENT_ID
"em5::ComplexFireComponent" unique component ID
Definition: ComplexFireComponent.h:64
Abstract EMERGENCY 5 freeplay event base class.
Definition: FreeplayEvent.h:66
Data type for encapsulating time information. It might represents points in time and time spans...
Definition: Time.h:32