OregonCore  revision fb2a440-git
Your Favourite TBC server
VMapManager2.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _VMAPMANAGER2_H
19 #define _VMAPMANAGER2_H
20 
21 #include "IVMapManager.h"
22 #include "Utilities/UnorderedMap.h"
23 #include "Platform/Define.h"
24 #include <ace/Thread_Mutex.h>
25 #include <vector>
26 
27 //===========================================================
28 
29 #define MAP_FILENAME_EXTENSION2 ".vmtree"
30 
31 #define FILENAMEBUFFER_SIZE 500
32 
41 //===========================================================
42 
43 namespace G3D
44 {
45  class Vector3;
46 }
47 
48 namespace VMAP
49 {
50 class StaticMapTree;
51 class WorldModel;
52 
54 {
55  public:
56  ManagedModel(): iModel(0), iRefCount(0) {}
57  void setModel(WorldModel* model) { iModel = model; }
58  WorldModel* getModel() { return iModel; }
59  void incRefCount() { ++iRefCount; }
60  int decRefCount() { return --iRefCount; }
61  protected:
63  int iRefCount;
64 };
65 
66 typedef UNORDERED_MAP<uint32 , StaticMapTree*> InstanceTreeMap;
67 typedef UNORDERED_MAP<std::string, ManagedModel> ModelFileMap;
68 
69 class VMapManager2 : public IVMapManager
70 {
71  protected:
72  // Tree to check collision
73  ModelFileMap iLoadedModelFiles;
74  InstanceTreeMap iInstanceMapTrees;
76  // Mutex for iLoadedModelFiles
77  ACE_Thread_Mutex LoadedModelFilesLock;
78 
79  bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
80  /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
81 
82  InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
83 
84  public:
85  // public for debug
86  G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const;
87  static std::string getMapFileName(unsigned int mapId);
88 
89  VMapManager2();
90  ~VMapManager2(void);
91 
92  VMAPLoadResult loadMap(const char* pBasePath, unsigned int mapId, int x, int y);
93 
94  void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
95  void unloadMap(unsigned int mapId, int x, int y);
96  void unloadMap(unsigned int mapId);
97 
98  bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2) ;
102  bool getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist);
103  float getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist);
104 
105  bool processCommand(char* /*command*/) { return false; } // for debug and extensions
106 
107  bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
108  bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const;
109 
110  WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename);
111  void releaseModelInstance(const std::string& filename);
112 
113  virtual std::string getDirFileName(unsigned int mapId, int /*x*/, int /*y*/) const
114  {
115  return getMapFileName(mapId);
116  }
117 
118  virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y);
119 
120  uint32(*GetLiquidFlagsPtr)(uint32 liquidType);
121 
122  #ifdef MMAP_GENERATOR
123  public:
124  void getInstanceMapTree(InstanceTreeMap& instanceMapTree);
125  #endif
126 };
127 }
128 
129 #endif
ACE_INT32 int32
Definition: Define.h:67
virtual std::string getDirFileName(unsigned int mapId, int, int) const
Definition: VMapManager2.h:113
WorldModel * iModel
Definition: VMapManager2.h:62
bool thread_safe_environment
Definition: VMapManager2.h:75
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:73
ACE_UINT8 uint8
Definition: Define.h:73
VMAPLoadResult
Definition: IVMapManager.h:33
UNORDERED_MAP< uint32, StaticMapTree * > InstanceTreeMap
Definition: VMapManager2.h:66
bool processCommand(char *)
Definition: VMapManager2.h:105
ACE_Thread_Mutex LoadedModelFilesLock
Definition: VMapManager2.h:77
UNORDERED_MAP< std::string, ManagedModel > ModelFileMap
Definition: VMapManager2.h:67
WorldModel * getModel()
Definition: VMapManager2.h:58
void setModel(WorldModel *model)
Definition: VMapManager2.h:57
ACE_UINT32 uint32
Definition: Define.h:71
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74