root/trunk/src/shared/vmap/VMapManager.h

Revision 102, 7.5 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

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