pathedInterior.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 _H_PATHEDINTERIOR
  23. #define _H_PATHEDINTERIOR
  24. #ifndef _INTERIOR_H_
  25. #include "interior/interior.h"
  26. #endif
  27. #ifndef _GAMEBASE_H_
  28. #include "T3D/gameBase/gameBase.h"
  29. #endif
  30. #ifndef _INTERIORRES_H_
  31. #include "interior/interiorRes.h"
  32. #endif
  33. #ifndef __RESOURCE_H__
  34. #include "core/resource.h"
  35. #endif
  36. class InteriorInstance;
  37. class EditGeometry;
  38. class EditInteriorResource;
  39. class SFXProfile;
  40. class SFXSource;
  41. struct PathedInteriorData : public GameBaseData {
  42. typedef GameBaseData Parent;
  43. public:
  44. enum Sounds {
  45. StartSound,
  46. SustainSound,
  47. StopSound,
  48. MaxSounds
  49. };
  50. SFXProfile *sound[MaxSounds];
  51. static void initPersistFields();
  52. virtual void packData(BitStream* stream);
  53. virtual void unpackData(BitStream* stream);
  54. bool preload(bool server, String &errorStr);
  55. PathedInteriorData();
  56. DECLARE_CONOBJECT(PathedInteriorData);
  57. };
  58. class PathedInterior : public GameBase
  59. {
  60. typedef GameBase Parent;
  61. friend class InteriorInstance;
  62. friend class EditGeometry;
  63. friend class EditInteriorResource;
  64. PathedInteriorData *mDataBlock;
  65. public:
  66. enum UpdateMasks {
  67. NewTargetMask = Parent::NextFreeMask,
  68. NewPositionMask = Parent::NextFreeMask << 1,
  69. NextFreeMask = Parent::NextFreeMask << 2,
  70. };
  71. private:
  72. U32 getPathKey(); // only used on the server
  73. // Persist fields
  74. protected:
  75. StringTableEntry mName;
  76. S32 mPathIndex;
  77. Vector<StringTableEntry> mTriggers;
  78. Point3F mOffset;
  79. Box3F mExtrudedBox;
  80. bool mStopped;
  81. // Loaded resources and fields
  82. protected:
  83. static PathedInterior *mClientPathedInteriors;
  84. SFXSource* mSustainSound;
  85. StringTableEntry mInteriorResName;
  86. S32 mInteriorResIndex;
  87. Resource<InteriorResource> mInteriorRes;
  88. Interior* mInterior;
  89. Vector<ColorI> mVertexColorsNormal;
  90. Vector<ColorI> mVertexColorsAlarm;
  91. MatrixF mBaseTransform;
  92. Point3F mBaseScale;
  93. U32 mPathKey; // only used on the client
  94. F64 mCurrentPosition;
  95. S32 mTargetPosition;
  96. Point3F mCurrentVelocity;
  97. PathedInterior *mNextClientPI;
  98. // Rendering
  99. protected:
  100. void prepRenderImage( SceneRenderState *state );
  101. void renderObject( SceneRenderState *state );
  102. void renderShadowVolumes( SceneRenderState *state );
  103. protected:
  104. bool onAdd();
  105. void onRemove();
  106. public:
  107. PathedInterior();
  108. ~PathedInterior();
  109. PathedInterior *getNext() { return mNextClientPI; }
  110. static PathedInterior *getClientPathedInteriors() { return mClientPathedInteriors; }
  111. void processTick(const Move* move);
  112. void setStopped() { mStopped = true; }
  113. void resolvePathKey();
  114. bool onNewDataBlock( GameBaseData *dptr, bool reload );
  115. bool buildPolyList(AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere);
  116. bool readPI(Stream&);
  117. bool writePI(Stream&) const;
  118. PathedInterior* clone() const;
  119. DECLARE_CONOBJECT(PathedInterior);
  120. static void initPersistFields();
  121. void setPathPosition(S32 newPosition);
  122. void setTargetPosition(S32 targetPosition);
  123. void computeNextPathStep(U32 timeDelta);
  124. Box3F getExtrudedBox() { return mExtrudedBox; }
  125. Point3F getVelocity();
  126. void advance(F64 timeDelta);
  127. U32 packUpdate(NetConnection *conn, U32 mask, BitStream* stream);
  128. void unpackUpdate(NetConnection *conn, BitStream* stream);
  129. };
  130. #endif // _H_PATHEDINTERIOR