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

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

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef _VMAPMANAGER_H
20#define _VMAPMANAGER_H
21
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>
30
31//===========================================================
32
33#define DIR_FILENAME_EXTENSION ".vmdir"
34
35#define FILENAMEBUFFER_SIZE 500
36
37/**
38This is the main Class to manage loading and unloading of maps, line of sight, height calculation and so on.
39For each map or map tile to load it reads a directory file that contains the ModelContainer files used by this map or map tile.
40Each global map or instance has its own dynamic BSP-Tree.
41The loaded ModelContainers are included in one of these BSP-Trees.
42Additionally a table to match map ids and map names is used.
43*/
44
45// Create a value describing the map tile
46#define MAP_TILE_IDENT(x,y) ((x<<8) + y)
47//===========================================================
48
49namespace VMAP
50{
51    //===========================================================
52
53    class FilesInDir
54    {
55        private:
56            int iRefCount;
57            G3D::Array<std::string> iFiles;
58        public:
59
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; }
66    };
67
68    //===========================================================
69    //===========================================================
70    //===========================================================
71    //===========================================================
72
73    class MapTree
74    {
75        private:
76            G3D::AABSPTree<ModelContainer *> *iTree;
77
78            // Key: filename, value ModelContainer
79            G3D::Table<std::string, ManagedModelContainer *> iLoadedModelContainer;
80
81            // Key: dir file name, value FilesInDir
82            G3D::Table<std::string, FilesInDir> iLoadedDirFiles;
83
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;
88
89        private:
90            float getIntersectionTime(const G3D::Ray& pRay, float pMaxDist, bool pStopAtFirstHit);
91            bool isAlreadyLoaded(const std::string& pName) { 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() { return(iLoadedMapTiles.size() > 0); }
95            bool containsLoadedMapTile(unsigned int pTileIdent) { return(iLoadedMapTiles.containsKey(pTileIdent)); }
96        public:
97            ManagedModelContainer *getModelContainer(const std::string& pName) { return(iLoadedModelContainer.get(pName)); }
98            const 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();
103
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);
107
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);
112
113            void getModelContainer(G3D::Array<ModelContainer *>& pArray ) { iTree->getMembers(pArray); }
114            const void addDirFile(const std::string& pDirName, const FilesInDir& pFilesInDir) { iLoadedDirFiles.set(pDirName, pFilesInDir); }
115            size_t size() { return(iTree->size()); }
116    };
117
118    //===========================================================
119    class MapIdNames
120    {
121        public:
122            std::string iDirName;
123            std::string iMapGroupName;
124    };
125
126    //===========================================================
127    class VMapManager : public IVMapManager
128    {
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;
134
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);
142
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);
153
154            int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y);
155
156            bool existsMap(const char* pBasePath, unsigned int pMapId, int x, int y);
157
158            void unloadMap(unsigned int pMapId, int x, int y);
159            void unloadMap(unsigned int pMapId);
160
161            bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2) ;
162            /**
163            fill the hit pos and return true, if an object was hit
164            */
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);
167
168            bool processCommand(char *pCommand);            // for debug and extensions
169
170            void preventMapsFromBeingUsed(const char* pMapIdString);
171    };
172}
173#endif
Note: See TracBrowser for help on using the browser.