fxShapeReplicator.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 _SHAPEREPLICATOR_H_
  23. #define _SHAPEREPLICATOR_H_
  24. #ifndef _TSSTATIC_H_
  25. #include "T3D/tsStatic.h"
  26. #endif
  27. #ifndef _TSSHAPEINSTANCE_H_
  28. #include "ts/tsShapeInstance.h"
  29. #endif
  30. #ifndef _RENDERPASSMANAGER_H_
  31. #include "renderInstance/renderPassManager.h"
  32. #endif
  33. #define AREA_ANIMATION_ARC (1.0f / 360.0f)
  34. #define FXREPLICATOR_COLLISION_MASK ( TerrainObjectType | \
  35. StaticShapeObjectType | \
  36. WaterObjectType )
  37. #define FXREPLICATOR_NOWATER_COLLISION_MASK ( TerrainObjectType | \
  38. StaticShapeObjectType )
  39. //------------------------------------------------------------------------------
  40. // Class: fxShapeReplicatedStatic
  41. //------------------------------------------------------------------------------
  42. class fxShapeReplicatedStatic : public TSStatic
  43. {
  44. private:
  45. typedef SceneObject Parent;
  46. public:
  47. fxShapeReplicatedStatic() {};
  48. ~fxShapeReplicatedStatic() {};
  49. void touchNetFlags(const U32 m, bool setflag = true) { if (setflag) mNetFlags.set(m); else mNetFlags.clear(m); };
  50. TSShape* getShape(void) { return mShapeInstance->getShape(); };
  51. void setTransform(const MatrixF & mat) override { Parent::setTransform(mat); setRenderTransform(mat); };
  52. DECLARE_CONOBJECT(fxShapeReplicatedStatic);
  53. DECLARE_CATEGORY("UNLISTED");
  54. };
  55. //------------------------------------------------------------------------------
  56. // Class: fxShapeReplicator
  57. //------------------------------------------------------------------------------
  58. class fxShapeReplicator : public SceneObject
  59. {
  60. private:
  61. typedef SceneObject Parent;
  62. protected:
  63. void CreateShapes(void);
  64. void DestroyShapes(void);
  65. void RenewShapes(void);
  66. enum { ReplicationMask = (1 << 0) };
  67. U32 mCreationAreaAngle;
  68. U32 mCurrentShapeCount;
  69. Vector<fxShapeReplicatedStatic*> mReplicatedShapes;
  70. MRandomLCG RandomGen;
  71. S32 mLastRenderTime;
  72. public:
  73. fxShapeReplicator();
  74. ~fxShapeReplicator();
  75. void StartUp(void);
  76. void ShowReplication(void);
  77. void HideReplication(void);
  78. GFXStateBlockRef mPlacementSB;
  79. void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance*);
  80. void renderArc(const F32 fRadiusX, const F32 fRadiusY);
  81. void renderPlacementArea(const F32 ElapsedTime);
  82. // SceneObject
  83. void prepRenderImage( SceneRenderState *state ) override;
  84. // SimObject
  85. bool onAdd() override;
  86. void onRemove() override;
  87. void inspectPostApply() override;
  88. // NetObject
  89. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream) override;
  90. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  91. // Editor
  92. void onGhostAlwaysDone();
  93. // ConObject.
  94. static void initPersistFields();
  95. // Field Data.
  96. class tagFieldData
  97. {
  98. public:
  99. U32 mSeed;
  100. StringTableEntry mShapeFile;
  101. U32 mShapeCount;
  102. U32 mShapeRetries;
  103. Point3F mShapeScaleMin;
  104. Point3F mShapeScaleMax;
  105. Point3F mShapeRotateMin;
  106. Point3F mShapeRotateMax;
  107. U32 mInnerRadiusX;
  108. U32 mInnerRadiusY;
  109. U32 mOuterRadiusX;
  110. U32 mOuterRadiusY;
  111. S32 mOffsetZ;
  112. bool mAllowOnTerrain;
  113. bool mAllowStatics;
  114. bool mAllowOnWater;
  115. S32 mAllowedTerrainSlope;
  116. bool mAlignToTerrain;
  117. bool mAllowWaterSurface;
  118. Point3F mTerrainAlignment;
  119. bool mInteractions;
  120. bool mHideReplications;
  121. bool mShowPlacementArea;
  122. U32 mPlacementBandHeight;
  123. LinearColorF mPlaceAreaColour;
  124. tagFieldData()
  125. {
  126. // Set Defaults.
  127. mSeed = 1376312589;
  128. mShapeFile = StringTable->EmptyString();
  129. mShapeCount = 10;
  130. mShapeRetries = 100;
  131. mInnerRadiusX = 0;
  132. mInnerRadiusY = 0;
  133. mOuterRadiusX = 100;
  134. mOuterRadiusY = 100;
  135. mOffsetZ = 0;
  136. mAllowOnTerrain = true;
  137. mAllowStatics = true;
  138. mAllowOnWater = false;
  139. mAllowWaterSurface = false;
  140. mAllowedTerrainSlope= 90;
  141. mAlignToTerrain = false;
  142. mInteractions = true;
  143. mHideReplications = false;
  144. mShowPlacementArea = true;
  145. mPlacementBandHeight = 25;
  146. mPlaceAreaColour .set(0.4f, 0, 0.8f);
  147. mShapeScaleMin .set(1, 1, 1);
  148. mShapeScaleMax .set(1, 1, 1);
  149. mShapeRotateMin .set(0, 0, 0);
  150. mShapeRotateMax .set(0, 0, 0);
  151. mTerrainAlignment .set(1, 1, 1);
  152. }
  153. } mFieldData;
  154. // Declare Console Object.
  155. DECLARE_CONOBJECT(fxShapeReplicator);
  156. DECLARE_CATEGORY("UNLISTED");
  157. };
  158. #endif // _SHAPEREPLICATOR_H_