| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <memory> |
| 4 |
#include "imodule.h" |
| 5 |
#include <list> |
| 6 |
|
| 7 |
#include "math/Plane3.h" |
| 8 |
#include "math/Vector3.h" |
| 9 |
#include "math/AABB.h" |
| 10 |
|
| 11 |
namespace map |
| 12 |
{ |
| 13 |
|
| 14 |
// An AAS type is defined by an entityDef block |
| 15 |
// Each AAS type has its own file extension |
| 16 |
struct AasType |
| 17 |
{ |
| 18 |
std::string entityDefName; |
| 19 |
std::string fileExtension; |
| 20 |
}; |
| 21 |
typedef std::list<AasType> AasTypeList; |
| 22 |
|
| 23 |
/** |
| 24 |
* Representation of a Area Awareness System file. |
| 25 |
* Provides read-only access to Area and Portal information. |
| 26 |
* Use the GlobalAasFileManager() to acquire an instance of |
| 27 |
* this class. |
| 28 |
*/ |
| 29 |
class IAasFile |
| 30 |
{ |
| 31 |
public: |
| 32 |
virtual std::size_t getNumPlanes() const = 0; |
| 33 |
virtual const Plane3& getPlane(std::size_t planeNum) const = 0; |
| 34 |
|
| 35 |
virtual std::size_t getNumVertices() const = 0; |
| 36 |
virtual const Vector3& getVertex(std::size_t vertexNum) const = 0; |
| 37 |
|
| 38 |
// An edge references two vertices by index |
| 39 |
struct Edge |
| 40 |
{ |
| 41 |
int vertexNumber[2]; |
| 42 |
}; |
| 43 |
|
| 44 |
virtual std::size_t getNumEdges() const = 0; |
| 45 |
virtual const Edge& getEdge(std::size_t index) const = 0; |
| 46 |
|
| 47 |
virtual std::size_t getNumEdgeIndexes() const = 0; |
| 48 |
virtual int getEdgeByIndex(int edgeIdx) const = 0; |
| 49 |
|
| 50 |
struct Face |
| 51 |
{ |
| 52 |
int planeNum; // number of the plane this face is on |
| 53 |
unsigned short flags; // face flags |
| 54 |
int numEdges; // number of edges in the boundary of the face |
| 55 |
int firstEdge; // first edge in the edge index |
| 56 |
short areas[2]; // area at the front and back of this face |
| 57 |
}; |
| 58 |
|
| 59 |
virtual std::size_t getNumFaces() const = 0; |
| 60 |
virtual const Face& getFace(int faceIndex) const = 0; |
| 61 |
virtual std::size_t getNumFaceIndexes() const = 0; |
| 62 |
virtual int getFaceByIndex(int faceIdx) const = 0; |
| 63 |
|
| 64 |
struct Area |
| 65 |
{ |
| 66 |
int numFaces; // number of faces used for the boundary of the area |
| 67 |
int firstFace; // first face in the face index used for the boundary of the area |
| 68 |
AABB bounds; // bounds of the area |
| 69 |
Vector3 center; // center of the area an AI can move towards |
| 70 |
unsigned short flags; // several area flags |
| 71 |
unsigned short contents; // contents of the area |
| 72 |
short cluster; // cluster the area belongs to, if negative it's a portal |
| 73 |
short clusterAreaNum; // number of the area in the cluster |
| 74 |
int travelFlags; // travel flags for traveling through this area |
| 75 |
}; |
| 76 |
|
| 77 |
virtual std::size_t getNumAreas() const = 0; |
| 78 |
virtual const Area& getArea(int areaNum) const = 0; |
| 79 |
}; |
| 80 |
typedef std::shared_ptr<IAasFile> IAasFilePtr; |
| 81 |
|
| 82 |
/** |
| 83 |
* A loader class capable of constructing an IAasFile instance from a token stream. |
| 84 |
*/ |
| 85 |
class IAasFileLoader : |
| 86 |
public RegisterableModule |
| 87 |
{ |
| 88 |
public: |
| 89 |
/** |
| 90 |
* Get the display name of this AAS file loader, e.g. "Doom 3", "Quake 4", etc. |
| 91 |
*/ |
| 92 |
virtual const std::string& getAasFormatName() const = 0; |
| 93 |
|
| 94 |
/** |
| 95 |
* Each MapFormat can have a certain game type it is designed for, |
| 96 |
* a value which conincides with the type attribute in the game tag |
| 97 |
* found in the .game file, e.g. "doom3" or "quake4". |
| 98 |
*/ |
| 99 |
virtual const std::string& getGameType() const = 0; |
| 100 |
|
| 101 |
/** |
| 102 |
* greebo: Returns true if this loader is able to parse |
| 103 |
* the contents of this file. Usually this includes a version |
| 104 |
* check of the file header. |
| 105 |
*/ |
| 106 |
virtual bool canLoad(std::istream& stream) const = 0; |
| 107 |
|
| 108 |
/** |
| 109 |
* Load the AAS file contents from the given stream. |
| 110 |
*/ |
| 111 |
virtual IAasFilePtr loadFromStream(std::istream& stream) = 0; |
| 112 |
}; |
| 113 |
typedef std::shared_ptr<IAasFileLoader> IAasFileLoaderPtr; |
| 114 |
|
| 115 |
// Info structure representing a single AAS file on disk |
| 116 |
struct AasFileInfo |
| 117 |
{ |
| 118 |
std::string absolutePath; |
| 119 |
|
| 120 |
AasType type; |
| 121 |
}; |
| 122 |
|
| 123 |
class IAasFileManager : |
| 124 |
public RegisterableModule |
| 125 |
{ |
| 126 |
public: |
| 127 |
virtual ~IAasFileManager() {} |
| 128 |
|
| 129 |
// Register a loader which is considered by all future AAS file load attempts |
| 130 |
virtual void registerLoader(const IAasFileLoaderPtr& loader) = 0; |
| 131 |
|
| 132 |
// Unregister a previously registered loader instance |
| 133 |
virtual void unregisterLoader(const IAasFileLoaderPtr& loader) = 0; |
| 134 |
|
| 135 |
// Get a loader capable of loading the given stream |
| 136 |
virtual IAasFileLoaderPtr getLoaderForStream(std::istream& stream) = 0; |
| 137 |
|
| 138 |
// Get the list of valid AAS types |
| 139 |
virtual AasTypeList getAasTypes() = 0; |
| 140 |
|
| 141 |
// Returns a specific AAS type. Will throw a std::runtime_error if the |
| 142 |
// type is not valid. |
| 143 |
virtual AasType getAasTypeByName(const std::string& typeName) = 0; |
| 144 |
|
| 145 |
// Returns a list of AAS files for the given map (absolute) map path |
| 146 |
virtual std::list<AasFileInfo> getAasFilesForMap(const std::string& mapPath) = 0; |
| 147 |
}; |
| 148 |
|
| 149 |
} // namespace |
| 150 |
|
| 151 |
const char* const MODULE_AASFILEMANAGER("ZAasFileManager"); |
| 152 |
|
| 153 |
// Application-wide Accessor to the global AAS file manager |
| 154 |
inline map::IAasFileManager& GlobalAasFileManager() |
| 155 |
{ |
| 156 |
static module::InstanceReference<map::IAasFileManager> _reference(MODULE_AASFILEMANAGER); |
| 157 |
return _reference; |
| 158 |
} |