pathManager.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 _PATHMANAGER_H_
  23. #define _PATHMANAGER_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. #ifndef _MPOINT3_H_
  31. #include "math/mPoint3.h"
  32. #endif
  33. #ifndef _MQUAT_H_
  34. #include "math/mQuat.h"
  35. #endif
  36. #ifndef _SCENEOBJECT_H_
  37. #include "scene/sceneObject.h"
  38. #endif
  39. class NetConnection;
  40. class BitStream;
  41. class PathManager
  42. {
  43. friend class PathManagerEvent;
  44. private:
  45. struct PathEntry {
  46. U32 totalTime;
  47. bool looping;
  48. Vector<Point3F> positions;
  49. Vector<QuatF> rotations;
  50. Vector<U32> smoothingType;
  51. Vector<U32> msToNext;
  52. PathEntry() {
  53. totalTime = 0;
  54. VECTOR_SET_ASSOCIATION(positions);
  55. VECTOR_SET_ASSOCIATION(rotations);
  56. VECTOR_SET_ASSOCIATION(smoothingType);
  57. VECTOR_SET_ASSOCIATION(msToNext);
  58. }
  59. };
  60. Vector<PathEntry*> mPaths;
  61. public:
  62. enum PathType {
  63. BackAndForth,
  64. Looping
  65. };
  66. public:
  67. PathManager(const bool isServer);
  68. ~PathManager();
  69. void clearPaths();
  70. //-------------------------------------- Path querying
  71. public:
  72. bool isValidPath(const U32 id) const;
  73. void getPathPosition(const U32 id, const F64 msPosition, Point3F& rPosition, QuatF &rotation);
  74. U32 getPathTotalTime(const U32 id) const;
  75. U32 getPathNumWaypoints(const U32 id) const;
  76. U32 getWaypointTime(const U32 id, const U32 wayPoint) const;
  77. F64 getClosestTimeToPoint(const U32 id, const Point3F p);
  78. F64 getClosestTimeToPoint(const U32 id, const Point3F p, const F64 tMin, const F64 tMax);
  79. U32 getPathTimeBits(const U32 id);
  80. U32 getPathWaypointBits(const U32 id);
  81. //-------------------------------------- Path Registration/Transmission/Management
  82. public:
  83. // Called after mission load to clear out the paths on the client, and to transmit
  84. // the information for the current mission's paths.
  85. void transmitPaths(NetConnection*);
  86. void transmitPath(U32);
  87. U32 allocatePathId();
  88. void updatePath(const U32 id, const Vector<Point3F>&, const Vector<QuatF>&, const Vector<U32>&, const Vector<U32>&, const bool looping);
  89. //-------------------------------------- State dumping/reading
  90. public:
  91. bool dumpState(BitStream*) const;
  92. bool readState(BitStream*);
  93. private:
  94. bool mIsServer;
  95. };
  96. struct PathNode {
  97. Point3F position;
  98. QuatF rotation;
  99. U32 smoothingType;
  100. U32 msToNext;
  101. };
  102. extern PathManager* gClientPathManager;
  103. extern PathManager* gServerPathManager;
  104. //--------------------------------------------------------------------------
  105. inline bool PathManager::isValidPath(const U32 id) const
  106. {
  107. return (id < U32(mPaths.size())) && mPaths[id]->positions.size() > 0;
  108. }
  109. #endif // _H_PATHMANAGER