[7272] Trailing whitespace cleaning
[getmangos.git] / src / shared / vmap / VMapManager.h
blob3d9057f914d6aa793543411e1f95cfe656677ad4
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _VMAPMANAGER_H
20 #define _VMAPMANAGER_H
22 // load our modified version first !!
23 #include "AABSPTree.h"
24 #include "ManagedModelContainer.h"
25 #include "IVMapManager.h"
26 #ifdef _VMAP_LOG_DEBUG
27 #include "DebugCmdLogger.h"
28 #endif
29 #include <G3D/Table.h>
31 //===========================================================
33 #define DIR_FILENAME_EXTENSION ".vmdir"
35 #define FILENAMEBUFFER_SIZE 500
37 /**
38 This is the main Class to manage loading and unloading of maps, line of sight, height calculation and so on.
39 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.
40 Each global map or instance has its own dynamic BSP-Tree.
41 The loaded ModelContainers are included in one of these BSP-Trees.
42 Additionally a table to match map ids and map names is used.
45 // Create a value describing the map tile
46 #define MAP_TILE_IDENT(x,y) ((x<<8) + y)
47 //===========================================================
49 namespace VMAP
51 //===========================================================
53 class FilesInDir
55 private:
56 int iRefCount;
57 G3D::Array<std::string> iFiles;
58 public:
60 FilesInDir() { iRefCount = 0; }
61 void append(const std::string& pName) { iFiles.append(pName); }
62 void incRefCount() { ++iRefCount; }
63 void decRefCount() { if(iRefCount > 0) --iRefCount; }
64 int getRefCount() { return iRefCount; }
65 const G3D::Array<std::string>& getFiles() const { return iFiles; }
68 //===========================================================
69 //===========================================================
70 //===========================================================
71 //===========================================================
73 class MapTree
75 private:
76 G3D::AABSPTree<ModelContainer *> *iTree;
78 // Key: filename, value ModelContainer
79 G3D::Table<std::string, ManagedModelContainer *> iLoadedModelContainer;
81 // Key: dir file name, value FilesInDir
82 G3D::Table<std::string, FilesInDir> iLoadedDirFiles;
84 // Store all the map tile idents that are loaded for that map
85 // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
86 G3D::Table<unsigned int, bool> iLoadedMapTiles;
87 std::string iBasePath;
89 private:
90 float getIntersectionTime(const G3D::Ray& pRay, float pMaxDist, bool pStopAtFirstHit);
91 bool isAlreadyLoaded(const std::string& pName) const { return(iLoadedModelContainer.containsKey(pName)); }
92 void setLoadedMapTile(unsigned int pTileIdent) { iLoadedMapTiles.set(pTileIdent, true); }
93 void removeLoadedMapTile(unsigned int pTileIdent) { iLoadedMapTiles.remove(pTileIdent); }
94 bool hasLoadedMapTiles() const { return iLoadedMapTiles.size() > 0; }
95 bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
96 public:
97 ManagedModelContainer *getModelContainer(const std::string& pName) { return(iLoadedModelContainer.get(pName)); }
98 bool hasDirFile(const std::string& pDirName) const { return(iLoadedDirFiles.containsKey(pDirName)); }
99 FilesInDir& getDirFiles(const std::string& pDirName) const { return(iLoadedDirFiles.get(pDirName)); }
100 public:
101 MapTree(const char *pBasePath);
102 ~MapTree();
104 bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2);
105 bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist);
106 float getHeight(const G3D::Vector3& pPos);
108 bool PrepareTree();
109 bool loadMap(const std::string& pDirFileName, unsigned int pMapTileIdent);
110 void addModelContainer(const std::string& pName, ManagedModelContainer *pMc);
111 void unloadMap(const std::string& dirFileName, unsigned int pMapTileIdent, bool pForce=false);
113 void getModelContainer(G3D::Array<ModelContainer *>& pArray ) { iTree->getMembers(pArray); }
114 void addDirFile(const std::string& pDirName, const FilesInDir& pFilesInDir) { iLoadedDirFiles.set(pDirName, pFilesInDir); }
115 size_t size() { return(iTree->size()); }
118 //===========================================================
119 class MapIdNames
121 public:
122 std::string iDirName;
123 std::string iMapGroupName;
126 //===========================================================
127 class VMapManager : public IVMapManager
129 private:
130 // Tree to check collision
131 G3D::Table<unsigned int , MapTree *> iInstanceMapTrees;
132 G3D::Table<unsigned int , bool> iMapsSplitIntoTiles;
133 G3D::Table<unsigned int , bool> iIgnoreMapIds;
135 #ifdef _VMAP_LOG_DEBUG
136 CommandFileRW iCommandLogger;
137 #endif
138 private:
139 bool _loadMap(const char* pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad=false);
140 void _unloadMap(unsigned int pMapId, int x, int y);
141 bool _existsMap(const std::string& pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad);
143 public:
144 // public for debug
145 G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const;
146 G3D::Vector3 convertPositionToMangosRep(float x, float y, float z) const;
147 std::string getDirFileName(unsigned int pMapId) const;
148 std::string getDirFileName(unsigned int pMapId, int x, int y) const;
149 MapTree* getInstanceMapTree(int pMapId) { return(iInstanceMapTrees.get(pMapId)); }
150 public:
151 VMapManager();
152 ~VMapManager(void);
154 int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y);
156 bool existsMap(const char* pBasePath, unsigned int pMapId, int x, int y);
158 void unloadMap(unsigned int pMapId, int x, int y);
159 void unloadMap(unsigned int pMapId);
161 bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2) ;
163 fill the hit pos and return true, if an object was hit
165 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);
166 float getHeight(unsigned int pMapId, float x, float y, float z);
168 bool processCommand(char *pCommand); // for debug and extensions
170 void preventMapsFromBeingUsed(const char* pMapIdString);
173 #endif