simPath.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. class BaseMatInstance;
  37. namespace SimPath
  38. {
  39. //--------------------------------------------------------------------------
  40. /// A path!
  41. class Path : public SimGroup
  42. {
  43. typedef SimGroup Parent;
  44. public:
  45. enum : U32
  46. {
  47. NoPathIndex = 0xFFFFFFFF
  48. };
  49. private:
  50. U32 mPathIndex;
  51. bool mIsLooping;
  52. protected:
  53. bool onAdd();
  54. void onRemove();
  55. public:
  56. Path();
  57. ~Path();
  58. void addObject(SimObject*);
  59. void removeObject(SimObject*);
  60. void sortMarkers();
  61. void updatePath();
  62. bool isLooping() { return mIsLooping; }
  63. U32 getPathIndex() const;
  64. DECLARE_CONOBJECT(Path);
  65. static void initPersistFields();
  66. };
  67. //--------------------------------------------------------------------------
  68. //--------------------------------------------------------------------------
  69. inline U32 Path::getPathIndex() const
  70. {
  71. return mPathIndex;
  72. }
  73. } // Namespace
  74. //--------------------------------------------------------------------------
  75. class Marker : public SceneObject
  76. {
  77. typedef SceneObject Parent;
  78. friend class Path;
  79. public:
  80. enum SmoothingType
  81. {
  82. SmoothingTypeLinear,
  83. SmoothingTypeSpline,
  84. SmoothingTypeAccelerate,
  85. };
  86. enum KnotType
  87. {
  88. KnotTypeNormal,
  89. KnotTypePositionOnly,
  90. KnotTypeKink,
  91. };
  92. U32 mSeqNum;
  93. U32 mSmoothingType;
  94. U32 mKnotType;
  95. U32 mMSToNext;
  96. // Rendering
  97. protected:
  98. void prepRenderImage(SceneRenderState *state);
  99. void renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance* overrideMat);
  100. protected:
  101. bool onAdd();
  102. void onRemove();
  103. void onGroupAdd();
  104. void onEditorEnable();
  105. void onEditorDisable();
  106. static void initGFXResources();
  107. static GFXStateBlockRef smStateBlock;
  108. static GFXVertexBufferHandle<GFXVertexPCT> smVertexBuffer;
  109. static GFXPrimitiveBufferHandle smPrimitiveBuffer;
  110. public:
  111. Marker();
  112. ~Marker();
  113. DECLARE_CONOBJECT(Marker);
  114. static void initPersistFields();
  115. void inspectPostApply();
  116. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
  117. void unpackUpdate(NetConnection *conn, BitStream *stream);
  118. };
  119. typedef Marker::SmoothingType MarkerSmoothingType;
  120. typedef Marker::KnotType MarkerKnotType;
  121. DefineEnumType( MarkerSmoothingType );
  122. DefineEnumType( MarkerKnotType );
  123. #endif // _H_PATH