simPath.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 _SIMPATH_H_
  23. #define _SIMPATH_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _GFXSTATEBLOCK_H_
  28. #include "gfx/gfxStateBlock.h"
  29. #endif
  30. #ifndef _GFXVERTEXBUFFER_H_
  31. #include "gfx/gfxVertexBuffer.h"
  32. #endif
  33. #ifndef _GFXPRIMITIVEBUFFER_H_
  34. #include "gfx/gfxPrimitiveBuffer.h"
  35. #endif
  36. #ifndef _STATICSHAPE_H_
  37. #include "T3D/staticShape.h"
  38. #endif
  39. class BaseMatInstance;
  40. struct PathShapeData;
  41. namespace SimPath
  42. {
  43. //--------------------------------------------------------------------------
  44. /// A path!
  45. class Path : public GameBase
  46. {
  47. typedef GameBase Parent;
  48. public:
  49. enum : U32
  50. {
  51. NoPathIndex = 0xFFFFFFFF
  52. };
  53. private:
  54. U32 mPathIndex;
  55. F32 mPathSpeed;
  56. bool mIsLooping;
  57. PathShapeData* mDataBlock;
  58. S32 mSpawnCount;
  59. S32 mMinDelay;
  60. S32 mMaxDelay;
  61. protected:
  62. bool onAdd() override;
  63. void onRemove() override;
  64. public:
  65. Path();
  66. ~Path();
  67. void addObject(SimObject*) override;
  68. void onPostAdd() override;
  69. void removeObject(SimObject*) override;
  70. void sortMarkers();
  71. void updatePath();
  72. bool isLooping() { return mIsLooping; }
  73. U32 getPathIndex() const;
  74. void setTransform(const MatrixF& mat) override;
  75. DECLARE_CONOBJECT(Path);
  76. DECLARE_CATEGORY("Cinematic");
  77. static void initPersistFields();
  78. DECLARE_CALLBACK(void, onAdd, (SimObjectId ID));
  79. };
  80. //--------------------------------------------------------------------------
  81. //--------------------------------------------------------------------------
  82. inline U32 Path::getPathIndex() const
  83. {
  84. return mPathIndex;
  85. }
  86. } // Namespace
  87. //--------------------------------------------------------------------------
  88. class Marker : public SceneObject
  89. {
  90. typedef SceneObject Parent;
  91. friend class Path;
  92. public:
  93. enum SmoothingType
  94. {
  95. SmoothingTypeLinear,
  96. SmoothingTypeSpline,
  97. SmoothingTypeAccelerate,
  98. };
  99. enum KnotType
  100. {
  101. KnotTypeNormal,
  102. KnotTypePositionOnly,
  103. KnotTypeKink,
  104. };
  105. U32 mSeqNum;
  106. String mHitCommand;
  107. U32 mSmoothingType;
  108. U32 mKnotType;
  109. U32 mMSToNext;
  110. // Rendering
  111. protected:
  112. void prepRenderImage(SceneRenderState *state) override;
  113. void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* overrideMat);
  114. protected:
  115. bool onAdd() override;
  116. void onRemove() override;
  117. void onGroupAdd() override;
  118. void onEditorEnable() override;
  119. void onEditorDisable() override;
  120. static void initGFXResources();
  121. static GFXStateBlockRef smStateBlock;
  122. static GFXVertexBufferHandle<GFXVertexPCT> smVertexBuffer;
  123. static GFXPrimitiveBufferHandle smPrimitiveBuffer;
  124. public:
  125. Marker();
  126. ~Marker();
  127. DECLARE_CONOBJECT(Marker);
  128. DECLARE_CATEGORY("Cinematic");
  129. static void initPersistFields();
  130. void inspectPostApply() override;
  131. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream) override;
  132. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  133. };
  134. typedef Marker::SmoothingType MarkerSmoothingType;
  135. typedef Marker::KnotType MarkerKnotType;
  136. DefineEnumType( MarkerSmoothingType );
  137. DefineEnumType( MarkerKnotType );
  138. #endif // _H_PATH