My Project
WeatherParticleSpawner.h
1 #pragma once
2 #include "TextureEntity.h"
3 #include "util/FastRandom.h"
4 #include "BaseObject.h"
5 
6 #include <vector>
7 #include "WeatherParticle.h"
8 
9 namespace ParaEngine
10 {
11  struct SceneState;
12  class WeatherParticleSpawner;
13  class CCameraFrustum;
14  class CWeatherEffect;
15 
17  {
18  public:
19  WeatherParticleSpawner(WeatherType nType);
20  virtual ~WeatherParticleSpawner();
21 
22  ATTRIBUTE_DEFINE_CLASS(WeatherParticleSpawner);
24  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
25 
26  ATTRIBUTE_METHOD1(WeatherParticleSpawner, SetEnable_s, bool) { cls->SetEnabled(p1); return S_OK; }
27  ATTRIBUTE_METHOD1(WeatherParticleSpawner, IsEnabled_s, bool*) { *p1 = cls->IsEnabled(); return S_OK; }
28 
29  ATTRIBUTE_METHOD1(WeatherParticleSpawner, SetStrength_s, float) { cls->SetStrength(p1); return S_OK; }
30  ATTRIBUTE_METHOD1(WeatherParticleSpawner, GetStrength_s, float*) { *p1 = cls->GetStrength(); return S_OK; }
31 
32  ATTRIBUTE_METHOD1(WeatherParticleSpawner, SetSpawnRadius_s, float) { cls->SetSpawnRadius(p1); return S_OK; }
33  ATTRIBUTE_METHOD1(WeatherParticleSpawner, GetSpawnRadius_s, float*) { *p1 = cls->GetSpawnRadius(); return S_OK; }
34 
35  ATTRIBUTE_METHOD1(WeatherParticleSpawner, SetTexture_s, const char*) { cls->SetTextureFilename(p1); return S_OK; }
36 
37  ATTRIBUTE_METHOD1(WeatherParticleSpawner, SetTextureRowsCols_s, Vector2) { cls->SetTextureRowsCols((int)p1.x, (int)p1.y); return S_OK; }
38  ATTRIBUTE_METHOD1(WeatherParticleSpawner, GetTextureRowsCols_s, Vector2*) { *p1 = cls->GetTextureRowsCols(); return S_OK; }
39 
40  public:
41 
42  bool IsEnabled() const;
43  void SetEnabled(bool val);
44 
45  float GetStrength() const { return m_fStrength; }
46  void SetStrength(float val) { m_fStrength = val; }
47 
48  float GetSpawnRadius() const { return m_fSpawnRadius; }
49  void SetSpawnRadius(float val) { m_fSpawnRadius = val; }
50 
51  TextureEntity* GetTexture() const { return m_pTexture.get(); }
52  void SetTexture(TextureEntity* val) { m_pTexture = val; }
53 
54  ParaEngine::WeatherType GetWeatherType() const { return m_type; }
55  FastRandom& GetSpeedRand() { return m_randomSpeed; }
56 
57  CWeatherEffect* GetWeatherEffect() { return m_pWeatherEffect; }
58  void SetWeatherEffect(CWeatherEffect* val) { m_pWeatherEffect = val; }
63  void SetTextureRowsCols(int nRows, int nCols, int nFromIndex = 0, int nToIndex = -1);
64  Vector2 GetTextureRowsCols();
65  void SetTextureFilename(const std::string& sFilename);
66 
67  void Cleanup();
68 
70  bool IsSpawnPoolFull();
71  public:
72  WeatherType m_type;
73  bool m_isEnabled;
74  float m_fStrength;
75  float m_fSpawnRadius;
76  FastRandom m_randomSpeed;
77  public:
81 
83  bool RecollectEntity(WeatherParticle* entity);
84 
85  int GetReusableCount();
86 
87  int GetTotalCount();
88 
89  void Clear();
90 
91  ParticleRectUV& GetTileUV(int nTileIndex);
92  int GetRandomTileIndex();
93  protected:
94 
95  // total number of pooled object created.
96  int m_totalCount;
97  int m_maxPoolSize;
98  // Next index to use when adding a Pool Entry.
99  int m_nextPoolIndex;
100  // Largest index reached by this Pool since last CleanPool operation.
101  int m_maxPoolIndex;
102  // List of entity stored in this Pool
103  std::vector <WeatherParticle*> m_unusedEntities;
104  asset_ptr<TextureEntity> m_pTexture;
110  int m_texRows;
111 
112  int m_nFromTileIndex;
113  int m_nToTileIndex;
114  // this is automatically generated from rows, cols
115  std::vector<ParticleRectUV> m_tiles;
116  CWeatherEffect* m_pWeatherEffect;
117  };
118 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
int m_texCols
a new particle will use a random image at one of the rows*cols regions in the texture accociated with...
Definition: WeatherParticleSpawner.h:109
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
different physics engine has different winding order.
Definition: EventBinding.h:32
base class for weather particle
Definition: WeatherParticle.h:21
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
void SetTextureRowsCols(int nRows, int nCols, int nFromIndex=0, int nToIndex=-1)
set how many rows and cols that the texture associated with this particle system is evenly divided in...
Definition: WeatherParticleSpawner.cpp:107
either rain or snow.
Definition: WeatherEffect.h:14
Definition: FastRandom.h:3
void Cleanup()
clean up the object.
Definition: WeatherParticleSpawner.cpp:27
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: WeatherParticleSpawner.cpp:183
Definition: WeatherParticleSpawner.h:16
bool RecollectEntity(WeatherParticle *entity)
this function should and can only be called after the entity is detached or destroyed.
Definition: WeatherParticleSpawner.cpp:66
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
WeatherParticle * CreateEntity()
Creates a new entity, or reuses one that&#39;s no longer in use.
Definition: WeatherParticleSpawner.cpp:32
bool IsSpawnPoolFull()
return true if we have reached the max number of particles allowed at a time.
Definition: WeatherParticleSpawner.cpp:178
for pre-calculated UV
Definition: ParticleElement.h:12