2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
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.
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.
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
24 Grid is a logical segment of the game world represented inside MaNGOS.
25 Grid is bind at compile time to a particular type of object which
26 we call it the object of interested. There are many types of loader,
27 specially, dynamic loader, static loader, or on-demand loader. There's
28 a subtle difference between dynamic loader and on-demand loader but
29 this is implementation specific to the loader class. From the
30 Grid's perspective, the loader meets its API requirement is suffice.
33 #include "Platform/Define.h"
34 #include "Policies/ThreadingModel.h"
35 #include "TypeContainer.h"
36 #include "TypeContainerVisitor.h"
38 // forward declaration
39 template<class A
, class T
, class O
> class GridLoader
;
44 class WORLD_OBJECT_TYPES
,
45 class GRID_OBJECT_TYPES
47 class MANGOS_DLL_DECL Grid
49 // allows the GridLoader to access its internals
50 template<class A
, class T
, class O
> friend class GridLoader
;
54 /** destructor to clean up its resources. This includes unloading the
55 grid if it has not been unload.
59 /** an object of interested enters the grid
61 template<class SPECIFIC_OBJECT
>
62 bool AddWorldObject(SPECIFIC_OBJECT
* obj
)
64 return i_objects
.template insert
<SPECIFIC_OBJECT
>(obj
);
67 /** an object of interested exits the grid
69 template<class SPECIFIC_OBJECT
>
70 bool RemoveWorldObject(SPECIFIC_OBJECT
* obj
)
72 return i_objects
.template remove
<SPECIFIC_OBJECT
>(obj
);
75 /** Grid visitor for grid objects
78 void Visit(TypeContainerVisitor
<T
, TypeMapContainer
<GRID_OBJECT_TYPES
> >& visitor
)
80 visitor
.Visit(i_container
);
83 /** Grid visitor for world objects
86 void Visit(TypeContainerVisitor
<T
, TypeMapContainer
<WORLD_OBJECT_TYPES
> >& visitor
)
88 visitor
.Visit(i_objects
);
91 /** Returns the number of object within the grid.
93 uint32
ActiveObjectsInGrid() const
95 return m_activeGridObjects
.size() + i_objects
.template Count
<ACTIVE_OBJECT
>();
98 /** Inserts a container type object into the grid.
100 template<class SPECIFIC_OBJECT
>
101 bool AddGridObject(SPECIFIC_OBJECT
* obj
)
103 if (obj
->isActiveObject())
104 m_activeGridObjects
.insert(obj
);
106 return i_container
.template insert
<SPECIFIC_OBJECT
>(obj
);
109 /** Removes a containter type object from the grid
111 template<class SPECIFIC_OBJECT
>
112 bool RemoveGridObject(SPECIFIC_OBJECT
* obj
)
114 if (obj
->isActiveObject())
115 m_activeGridObjects
.erase(obj
);
117 return i_container
.template remove
<SPECIFIC_OBJECT
>(obj
);
122 TypeMapContainer
<GRID_OBJECT_TYPES
> i_container
;
123 TypeMapContainer
<WORLD_OBJECT_TYPES
> i_objects
;
124 typedef std::set
<void*> ActiveGridObjects
;
125 ActiveGridObjects m_activeGridObjects
;