particle.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PARTICLE_H_
  23. #define _PARTICLE_H_
  24. #ifndef _GAMEBASE_H_
  25. #include "T3D/gameBase/gameBase.h"
  26. #endif
  27. #ifndef _GFXTEXTUREHANDLE_H_
  28. #include "gfx/gfxTextureHandle.h"
  29. #endif
  30. #define MaxParticleSize 50.0
  31. struct Particle;
  32. //*****************************************************************************
  33. // Particle Data
  34. //*****************************************************************************
  35. class ParticleData : public SimDataBlock
  36. {
  37. typedef SimDataBlock Parent;
  38. public:
  39. enum PDConst
  40. {
  41. PDC_NUM_KEYS = 4,
  42. };
  43. F32 dragCoefficient;
  44. F32 windCoefficient;
  45. F32 gravityCoefficient;
  46. F32 inheritedVelFactor;
  47. F32 constantAcceleration;
  48. S32 lifetimeMS;
  49. S32 lifetimeVarianceMS;
  50. F32 spinSpeed; // degrees per second
  51. F32 spinRandomMin;
  52. F32 spinRandomMax;
  53. bool useInvAlpha;
  54. bool animateTexture;
  55. U32 numFrames;
  56. U32 framesPerSec;
  57. ColorF colors[ PDC_NUM_KEYS ];
  58. F32 sizes[ PDC_NUM_KEYS ];
  59. F32 times[ PDC_NUM_KEYS ];
  60. Point2F* animTexUVs;
  61. Point2F texCoords[4]; // default: {{0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0}}
  62. Point2I animTexTiling;
  63. StringTableEntry animTexFramesString;
  64. Vector<U8> animTexFrames;
  65. StringTableEntry textureName;
  66. GFXTexHandle textureHandle;
  67. static bool protectedSetSizes( void *object, const char *index, const char *data );
  68. static bool protectedSetTimes( void *object, const char *index, const char *data );
  69. public:
  70. ParticleData();
  71. ~ParticleData();
  72. // move this procedure to Particle
  73. void initializeParticle(Particle*, const Point3F&);
  74. void packData(BitStream* stream);
  75. void unpackData(BitStream* stream);
  76. bool onAdd();
  77. bool preload(bool server, String &errorStr);
  78. DECLARE_CONOBJECT(ParticleData);
  79. static void initPersistFields();
  80. bool reload(char errorBuffer[256]);
  81. };
  82. //*****************************************************************************
  83. // Particle
  84. //
  85. // This structure should be as small as possible.
  86. //*****************************************************************************
  87. struct Particle
  88. {
  89. Point3F pos; // current instantaneous position
  90. Point3F vel; // " " velocity
  91. Point3F acc; // Constant acceleration
  92. Point3F orientDir; // direction particle should go if using oriented particles
  93. U32 totalLifetime; // Total ms that this instance should be "live"
  94. ParticleData* dataBlock; // datablock that contains global parameters for
  95. // this instance
  96. U32 currentAge;
  97. // are these necessary to store here? - they are interpolated in real time
  98. ColorF color;
  99. F32 size;
  100. F32 spinSpeed;
  101. Particle * next;
  102. };
  103. #endif // _PARTICLE_H_