navPath.h
Engine/source/navigation/navPath.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2014 Daniel Buckmaster 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _NAVPATH_H_ 25#define _NAVPATH_H_ 26 27#include "scene/sceneObject.h" 28#include "scene/simPath.h" 29#include "navMesh.h" 30#include <DetourNavMeshQuery.h> 31 32class NavPath: public SceneObject { 33 typedef SceneObject Parent; 34 static const U32 MaxPathLen = 2048; 35public: 36 /// @name NavPath 37 /// Functions for planning and accessing the path. 38 /// @{ 39 40 String mMeshName; 41 NavMesh *mMesh; 42 SimPath::Path *mWaypoints; 43 44 Point3F mFrom; 45 bool mFromSet; 46 Point3F mTo; 47 bool mToSet; 48 49 bool mIsLooping; 50 bool mAutoUpdate; 51 bool mIsSliced; 52 53 S32 mMaxIterations; 54 55 bool mAlwaysRender; 56 bool mXray; 57 bool mRenderSearch; 58 59 /// What sort of link types are we allowed to move on? 60 LinkData mLinkTypes; 61 62 /// Plan the path. 63 bool plan(); 64 65 /// Updated a sliced plan. 66 /// @return True if we need to keep updating, false if we can stop. 67 bool update(); 68 69 /// Finalise a sliced plan. 70 /// @return True if the plan was successful overall. 71 bool finalise(); 72 73 /// Did the path plan successfully? 74 bool success() const { return dtStatusSucceed(mStatus); } 75 76 /// @} 77 78 /// @name Path interface 79 /// These functions are provided to make NavPath behave 80 /// similarly to the existing Path class, despite NavPath 81 /// not being a SimSet. 82 /// @{ 83 84 /// Return the length of this path. 85 F32 getLength() const { return mLength; }; 86 87 /// Get the number of nodes in a path. 88 S32 size() const; 89 90 /// Return world-space position of a path node. 91 Point3F getNode(S32 idx) const; 92 93 /// Get the flags for a given path node. 94 U16 getFlags(S32 idx) const; 95 96 /// @} 97 98 /// @name SceneObject 99 /// @{ 100 101 static void initPersistFields(); 102 103 bool onAdd(); 104 void onRemove(); 105 106 void onEditorEnable(); 107 void onEditorDisable(); 108 void inspectPostApply(); 109 110 void onDeleteNotify(SimObject *object); 111 112 U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream); 113 void unpackUpdate(NetConnection *conn, BitStream *stream); 114 115 void prepRenderImage(SceneRenderState *state); 116 void renderSimple(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat); 117 118 DECLARE_CONOBJECT(NavPath); 119 120 /// @} 121 122 /// @name ProcessObject 123 /// @{ 124 void processTick(const Move *move); 125 /// @} 126 127 NavPath(); 128 ~NavPath(); 129 130protected: 131 enum masks { 132 PathMask = Parent::NextFreeMask << 0, 133 NextFreeMask = Parent::NextFreeMask << 1 134 }; 135 136private: 137 /// Create appropriate data structures and stuff. 138 bool init(); 139 140 /// Plan the path. 141 bool planInstant(); 142 143 /// Start a sliced plan. 144 /// @return True if the plan initialised successfully. 145 bool planSliced(); 146 147 /// Add points of the path between the two specified points. 148 //bool addPoints(Point3F from, Point3F to, Vector<Point3F> *points); 149 150 /// 'Visit' the last two points on our visit list. 151 bool visitNext(); 152 153 dtNavMeshQuery *mQuery; 154 dtStatus mStatus; 155 dtQueryFilter mFilter; 156 S32 mCurIndex; 157 Vector<Point3F> mPoints; 158 Vector<U16> mFlags; 159 Vector<Point3F> mVisitPoints; 160 F32 mLength; 161 162 /// Resets our world transform and bounds to fit our point list. 163 void resize(); 164 165 /// Function used to set mMesh object from console. 166 static bool setProtectedMesh(void *obj, const char *index, const char *data); 167 168 /// Function used to set mWaypoints from console. 169 static bool setProtectedWaypoints(void *obj, const char *index, const char *data); 170 171 void checkAutoUpdate(); 172 /// Function used to protect auto-update flag. 173 static bool setProtectedAutoUpdate(void *obj, const char *index, const char *data); 174 175 /// @name Protected from and to vectors 176 /// @{ 177 static bool setProtectedFrom(void *obj, const char *index, const char *data); 178 static bool setProtectedTo(void *obj, const char *index, const char *data); 179 static const char *getProtectedFrom(void *obj, const char *data); 180 static const char *getProtectedTo(void *obj, const char *data); 181 /// @} 182}; 183 184#endif 185