[7017] Updated copyright notice for new year
[getmangos.git] / src / framework / GameSystem / Grid.h
blobf1c826da0b03dead14b0a3dadc547cea4440f9f5
1 /*
2 * Copyright (C) 2005-2009 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
19 #ifndef MANGOS_GRID_H
20 #define MANGOS_GRID_H
23 @class Grid
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;
41 template
43 class ACTIVE_OBJECT,
44 class WORLD_OBJECT_TYPES,
45 class GRID_OBJECT_TYPES,
46 class ThreadModel = MaNGOS::SingleThreaded<ACTIVE_OBJECT>
48 class MANGOS_DLL_DECL Grid
50 // allows the GridLoader to access its internals
51 template<class A, class T, class O> friend class GridLoader;
52 public:
54 /** destructor to clean up its resources. This includes unloading the
55 grid if it has not been unload.
57 ~Grid() {}
59 /** an object of interested enters the grid
61 template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
63 return i_objects.template insert<SPECIFIC_OBJECT>(hdl, obj);
66 /** an object of interested exits the grid
68 template<class SPECIFIC_OBJECT> bool RemoveWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
70 return i_objects.template remove<SPECIFIC_OBJECT>(obj, hdl);
73 /** Accessors: Returns a specific type of object in the WORDL_OBJECT_TYPES
75 template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT* fake) const { return i_objects.template find<SPECIFIC_OBJECT>(hdl); }
76 template<class SPECIFIC_OBJECT> SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) { return i_objects.template find<SPECIFIC_OBJECT>(hdl, fake); }
78 /** Refreshes/update the grid. This required for remote grids.
80 void RefreshGrid(void) { /* TBI */}
82 /** Locks a grid. Any object enters must wait until the grid is unlock.
84 void LockGrid(void) { /* TBI */ }
86 /** Unlocks the grid.
88 void UnlockGrid(void) { /* TBI */ }
90 /** Grid visitor for grid objects
92 template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
94 visitor.Visit(i_container);
97 /** Grid visitor for world objects
99 template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
101 visitor.Visit(i_objects);
104 /** Returns the number of object within the grid.
106 unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); }
108 /** Accessors: Returns a specific type of object in the GRID_OBJECT_TYPES
110 template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) const { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
111 template<class SPECIFIC_OBJECT> SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
113 /** Inserts a container type object into the grid.
115 template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template insert<SPECIFIC_OBJECT>(hdl, obj); }
117 /** Removes a containter type object from the grid
119 template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl); }
121 private:
123 typedef typename ThreadModel::Lock Guard;
124 typedef typename ThreadModel::VolatileType VolatileType;
126 TypeMapContainer<GRID_OBJECT_TYPES> i_container;
127 TypeMapContainer<WORLD_OBJECT_TYPES> i_objects;
129 #endif