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

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