simPath.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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();
  63. void onRemove();
  64. public:
  65. Path();
  66. ~Path();
  67. void addObject(SimObject*);
  68. void removeObject(SimObject*);
  69. void sortMarkers();
  70. void updatePath();
  71. bool isLooping() { return mIsLooping; }
  72. U32 getPathIndex() const;
  73. DECLARE_CONOBJECT(Path);
  74. static void initPersistFields();
  75. DECLARE_CALLBACK(void, onAdd, (SimObjectId ID));
  76. };
  77. //--------------------------------------------------------------------------
  78. //--------------------------------------------------------------------------
  79. inline U32 Path::getPathIndex() const
  80. {
  81. return mPathIndex;
  82. }
  83. } // Namespace
  84. //--------------------------------------------------------------------------
  85. class Marker : public SceneObject
  86. {
  87. typedef SceneObject Parent;
  88. friend class Path;
  89. public:
  90. enum SmoothingType
  91. {
  92. SmoothingTypeLinear,
  93. SmoothingTypeSpline,
  94. SmoothingTypeAccelerate,
  95. };
  96. enum KnotType
  97. {
  98. KnotTypeNormal,
  99. KnotTypePositionOnly,
  100. KnotTypeKink,
  101. };
  102. U32 mSeqNum;
  103. String mHitCommand;
  104. U32 mSmoothingType;
  105. U32 mKnotType;
  106. U32 mMSToNext;
  107. // Rendering
  108. protected:
  109. void prepRenderImage(SceneRenderState *state);
  110. void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* overrideMat);
  111. protected:
  112. bool onAdd();
  113. void onRemove();
  114. void onGroupAdd();
  115. void onEditorEnable();
  116. void onEditorDisable();
  117. static void initGFXResources();
  118. static GFXStateBlockRef smStateBlock;
  119. static GFXVertexBufferHandle<GFXVertexPCT> smVertexBuffer;
  120. static GFXPrimitiveBufferHandle smPrimitiveBuffer;
  121. public:
  122. Marker();
  123. ~Marker();
  124. DECLARE_CONOBJECT(Marker);
  125. static void initPersistFields();
  126. void inspectPostApply();
  127. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  128. void unpackUpdate(NetConnection *conn, BitStream *stream);
  129. };
  130. typedef Marker::SmoothingType MarkerSmoothingType;
  131. typedef Marker::KnotType MarkerKnotType;
  132. DefineEnumType( MarkerSmoothingType );
  133. DefineEnumType( MarkerKnotType );
  134. #endif // _H_PATH