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