root/trunk/src/framework/GameSystem/Grid.h @ 8

Revision 2, 5.1 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_GRID_H
20#define MANGOS_GRID_H
21
22/*
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.
31*/
32
33#include "Platform/Define.h"
34#include "Policies/ThreadingModel.h"
35#include "TypeContainer.h"
36#include "TypeContainerVisitor.h"
37
38// forward declaration
39template<class A, class T, class O> class GridLoader;
40
41template
42<
43class ACTIVE_OBJECT,
44class WORLD_OBJECT_TYPES,
45class GRID_OBJECT_TYPES,
46class ThreadModel = MaNGOS::SingleThreaded<ACTIVE_OBJECT>
47>
48class MANGOS_DLL_DECL Grid
49{
50    // allows the GridLoader to access its internals
51    template<class A, class T, class O> friend class GridLoader;
52    public:
53
54        /** destructor to clean up its resources. This includes unloading the
55        grid if it has not been unload.
56        */
57        ~Grid() {}
58
59        /** an object of interested enters the grid
60         */
61        template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
62        {
63            return i_objects.template insert<SPECIFIC_OBJECT>(hdl, obj);
64        }
65
66        /** an object of interested exits the grid
67         */
68        template<class SPECIFIC_OBJECT> bool RemoveWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
69        {
70            return i_objects.template remove<SPECIFIC_OBJECT>(obj, hdl);
71        }
72
73        /** Accessors: Returns a specific type of object in the WORDL_OBJECT_TYPES
74         */
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); }
77
78        /** Refreshes/update the grid. This required for remote grids.
79         */
80        void RefreshGrid(void) { /* TBI */}
81
82        /** Locks a grid.  Any object enters must wait until the grid is unlock.
83         */
84        void LockGrid(void) { /* TBI */ }
85
86        /** Unlocks the grid.
87         */
88        void UnlockGrid(void) { /* TBI */ }
89
90        /** Grid visitor for grid objects
91         */
92        template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
93        {
94            visitor.Visit(i_container);
95        }
96
97        /** Grid visitor for world objects
98         */
99        template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
100        {
101            visitor.Visit(i_objects);
102        }
103
104        /** Returns the number of object within the grid.
105         */
106        unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); }
107
108        /** Accessors: Returns a specific type of object in the GRID_OBJECT_TYPES
109         */
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); }
112
113        /** Inserts a container type object into the grid.
114         */
115        template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template insert<SPECIFIC_OBJECT>(hdl, obj); }
116
117        /** Removes a containter type object from the grid
118         */
119        template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl); }
120
121    private:
122
123        typedef typename ThreadModel::Lock Guard;
124        typedef typename ThreadModel::VolatileType VolatileType;
125
126        TypeMapContainer<GRID_OBJECT_TYPES> i_container;
127        TypeMapContainer<WORLD_OBJECT_TYPES> i_objects;
128};
129#endif
Note: See TracBrowser for help on using the browser.