diff options
Diffstat (limited to 'src/shared/vmap/VMapManager.h')
-rw-r--r-- | src/shared/vmap/VMapManager.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/vmap/VMapManager.h b/src/shared/vmap/VMapManager.h index 4e0e6bdfb18..bfeba3cfe67 100644 --- a/src/shared/vmap/VMapManager.h +++ b/src/shared/vmap/VMapManager.h @@ -17,8 +17,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #ifndef _VMAPMANAGER_H #define _VMAPMANAGER_H + // load our modified version first !! #include "AABSPTree.h" #include "ManagedModelContainer.h" @@ -27,9 +29,13 @@ #include "DebugCmdLogger.h" #endif #include <G3D/Table.h> + //=========================================================== + #define DIR_FILENAME_EXTENSION ".vmdir" + #define FILENAMEBUFFER_SIZE 500 + /** This is the main Class to manage loading and unloading of maps, line of sight, height calculation and so on. For each map or map tile to load it reads a directory file that contains the ModelContainer files used by this map or map tile. @@ -37,18 +43,22 @@ Each global map or instance has its own dynamic BSP-Tree. The loaded ModelContainers are included in one of these BSP-Trees. Additionally a table to match map ids and map names is used. */ + // Create a value describing the map tile #define MAP_TILE_IDENT(x,y) ((x<<8) + y) //=========================================================== + namespace VMAP { //=========================================================== + class FilesInDir { private: int iRefCount; G3D::Array<std::string> iFiles; public: + FilesInDir() { iRefCount = 0; } void append(const std::string& pName) { iFiles.append(pName); } void incRefCount() { ++iRefCount; } @@ -56,22 +66,28 @@ namespace VMAP int getRefCount() { return iRefCount; } const G3D::Array<std::string>& getFiles() const { return iFiles; } }; + //=========================================================== //=========================================================== //=========================================================== //=========================================================== + class MapTree { private: G3D::AABSPTree<ModelContainer *> *iTree; + // Key: filename, value ModelContainer G3D::Table<std::string, ManagedModelContainer *> iLoadedModelContainer; + // Key: dir file name, value FilesInDir G3D::Table<std::string, FilesInDir> iLoadedDirFiles; + // Store all the map tile idents that are loaded for that map // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed G3D::Table<unsigned int, bool> iLoadedMapTiles; std::string iBasePath; + private: float getIntersectionTime(const G3D::Ray& pRay, float pMaxDist, bool pStopAtFirstHit); bool isAlreadyLoaded(const std::string& pName) { return(iLoadedModelContainer.containsKey(pName)); } @@ -86,17 +102,21 @@ namespace VMAP public: MapTree(const char *pBasePath); ~MapTree(); + bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2); bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist); float getHeight(const G3D::Vector3& pPos); + bool PrepareTree(); bool loadMap(const std::string& pDirFileName, unsigned int pMapTileIdent); void addModelContainer(const std::string& pName, ManagedModelContainer *pMc); void unloadMap(const std::string& dirFileName, unsigned int pMapTileIdent, bool pForce=false); + void getModelContainer(G3D::Array<ModelContainer *>& pArray ) { iTree->getMembers(pArray); } const void addDirFile(const std::string& pDirName, const FilesInDir& pFilesInDir) { iLoadedDirFiles.set(pDirName, pFilesInDir); } size_t size() { return(iTree->size()); } }; + //=========================================================== class MapIdNames { @@ -104,6 +124,7 @@ namespace VMAP std::string iDirName; std::string iMapGroupName; }; + //=========================================================== class VMapManager : public IVMapManager { @@ -112,6 +133,7 @@ namespace VMAP G3D::Table<unsigned int , MapTree *> iInstanceMapTrees; G3D::Table<unsigned int , bool> iMapsSplitIntoTiles; G3D::Table<unsigned int , bool> iIgnoreMapIds; + #ifdef _VMAP_LOG_DEBUG CommandFileRW iCommandLogger; #endif @@ -119,6 +141,7 @@ namespace VMAP bool _loadMap(const char* pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad=false); void _unloadMap(unsigned int pMapId, int x, int y); bool _existsMap(const std::string& pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad); + public: // public for debug G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const; @@ -129,17 +152,23 @@ namespace VMAP public: VMapManager(); ~VMapManager(void); + int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y); + bool existsMap(const char* pBasePath, unsigned int pMapId, int x, int y); + void unloadMap(unsigned int pMapId, int x, int y); void unloadMap(unsigned int pMapId); + bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2) ; /** fill the hit pos and return true, if an object was hit */ bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist); float getHeight(unsigned int pMapId, float x, float y, float z); + bool processCommand(char *pCommand); // for debug and extensions + void preventMapsFromBeingUsed(const char* pMapIdString); }; } |