pathManager.h

Engine/source/scene/pathManager.h

More...

Classes:

Detailed Description

Public Variables

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