root/trunk/src/game/MapManager.h @ 22

Revision 2, 4.8 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 MANGOS_MAPMANAGER_H
20#define MANGOS_MAPMANAGER_H
21
22#include "Platform/Define.h"
23#include "Policies/Singleton.h"
24#include "zthread/Mutex.h"
25#include "Common.h"
26#include "Map.h"
27#include "GridStates.h"
28class Transport;
29
30class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex> >
31{
32
33    friend class MaNGOS::OperatorNew<MapManager>;
34    typedef HM_NAMESPACE::hash_map<uint32, Map*> MapMapType;
35    typedef std::pair<HM_NAMESPACE::hash_map<uint32, Map*>::iterator, bool>  MapMapPair;
36
37    public:
38
39        Map* GetMap(uint32, const WorldObject* obj);
40        Map* FindMap(uint32 mapid) { return _findMap(mapid); }
41        Map* FindMap(uint32 mapid, uint32 instanceId);
42
43        // only const version for outer users
44        Map const* GetBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_GetBaseMap(id); }
45        void DeleteInstance(uint32 mapid, uint32 instanceId, uint8 mode);
46
47        inline uint16 GetAreaFlag(uint32 mapid, float x, float y) const
48        {
49            Map const* m = GetBaseMap(mapid);
50            return m->GetAreaFlag(x, y);
51        }
52        inline uint32 GetAreaId(uint32 mapid, float x, float y) { return Map::GetAreaId(GetAreaFlag(mapid, x, y),mapid); }
53        inline uint32 GetZoneId(uint32 mapid, float x, float y) { return Map::GetZoneId(GetAreaFlag(mapid, x, y),mapid); }
54
55        void Initialize(void);
56        void Update(time_t);
57
58        inline void SetGridCleanUpDelay(uint32 t)
59        {
60            if( t < MIN_GRID_DELAY )
61                i_gridCleanUpDelay = MIN_GRID_DELAY;
62            else
63                i_gridCleanUpDelay = t;
64        }
65
66        inline void SetMapUpdateInterval(uint32 t)
67        {
68            if( t > MIN_MAP_UPDATE_DELAY )
69                t = MIN_MAP_UPDATE_DELAY;
70
71            i_timer.SetInterval(t);
72            i_timer.Reset();
73        }
74
75        void LoadGrid(int mapid, float x, float y, const WorldObject* obj, bool no_unload = false);
76        void UnloadAll();
77
78        static bool ExistMapAndVMap(uint32 mapid, float x, float y);
79        static bool IsValidMAP(uint32 mapid);
80
81        static bool IsValidMapCoord(uint32 mapid, float x,float y)
82        {
83            return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y);
84        }
85
86        static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
87        {
88            return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z);
89        }
90
91        static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
92        {
93            return IsValidMAP(mapid) && MaNGOS::IsValidMapCoord(x,y,z,o);
94        }
95
96        void DoDelayedMovesAndRemoves();
97
98        void LoadTransports();
99
100        typedef std::set<Transport *> TransportSet;
101        TransportSet m_Transports;
102
103        typedef std::map<uint32, TransportSet> TransportMap;
104        TransportMap m_TransportsByMap;
105
106        bool CanPlayerEnter(uint32 mapid, Player* player);
107        void RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y);
108        inline uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
109        void InitMaxInstanceId();
110
111        /* statistics */
112        uint32 GetNumInstances();
113        uint32 GetNumPlayersInInstances();
114
115    private:
116        // debugging code, should be deleted some day
117        void checkAndCorrectGridStatesArray();              // just for debugging to find some memory overwrites
118        GridState* i_GridStates[MAX_GRID_STATE];            // shadow entries to the global array in Map.cpp
119        int i_GridStateErrorCount;
120    private:
121        MapManager();
122        ~MapManager();
123
124        MapManager(const MapManager &);
125        MapManager& operator=(const MapManager &);
126
127        Map* _GetBaseMap(uint32 id);
128        Map* _findMap(uint32 id) const
129        {
130            MapMapType::const_iterator iter = i_maps.find(id);
131            return (iter == i_maps.end() ? NULL : iter->second);
132        }
133
134        typedef MaNGOS::ClassLevelLockable<MapManager, ZThread::Mutex>::Lock Guard;
135        uint32 i_gridCleanUpDelay;
136        MapMapType i_maps;
137        IntervalTimer i_timer;
138
139        uint32 i_MaxInstanceId;
140};
141#endif
Note: See TracBrowser for help on using the browser.