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

Revision 44, 5.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

Line 
1/*
2 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
3 *
4 * Thanks to the original authors: MaNGOS <http://www.mangosproject.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_GRID_H
22#define TRINITY_GRID_H
23
24/*
25  @class Grid
26  Grid is a logical segment of the game world represented inside TrinIty.
27  Grid is bind at compile time to a particular type of object which
28  we call it the object of interested.  There are many types of loader,
29  specially, dynamic loader, static loader, or on-demand loader.  There's
30  a subtle difference between dynamic loader and on-demand loader but
31  this is implementation specific to the loader class.  From the
32  Grid's perspective, the loader meets its API requirement is suffice.
33*/
34
35#include "Platform/Define.h"
36#include "Policies/ThreadingModel.h"
37#include "TypeContainer.h"
38#include "TypeContainerVisitor.h"
39
40// forward declaration
41template<class A, class T, class O> class GridLoader;
42
43template
44<
45class ACTIVE_OBJECT,
46class WORLD_OBJECT_TYPES,
47class GRID_OBJECT_TYPES,
48class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT>
49>
50class TRINITY_DLL_DECL Grid
51{
52    // allows the GridLoader to access its internals
53    template<class A, class T, class O> friend class GridLoader;
54    public:
55
56        /** destructor to clean up its resources. This includes unloading the
57        grid if it has not been unload.
58        */
59        ~Grid() {}
60
61        /** an object of interested enters the grid
62         */
63        template<class SPECIFIC_OBJECT> bool AddWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
64        {
65            return i_objects.template insert<SPECIFIC_OBJECT>(hdl, obj);
66        }
67
68        /** an object of interested exits the grid
69         */
70        template<class SPECIFIC_OBJECT> bool RemoveWorldObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl)
71        {
72            return i_objects.template remove<SPECIFIC_OBJECT>(obj, hdl);
73        }
74
75        /** Accessors: Returns a specific type of object in the WORDL_OBJECT_TYPES
76         */
77        template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT* fake) const { return i_objects.template find<SPECIFIC_OBJECT>(hdl); }
78        template<class SPECIFIC_OBJECT>       SPECIFIC_OBJECT* GetWorldObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake)       { return i_objects.template find<SPECIFIC_OBJECT>(hdl, fake); }
79
80        /** Refreshes/update the grid. This required for remote grids.
81         */
82        void RefreshGrid(void) { /* TBI */}
83
84        /** Locks a grid.  Any object enters must wait until the grid is unlock.
85         */
86        void LockGrid(void) { /* TBI */ }
87
88        /** Unlocks the grid.
89         */
90        void UnlockGrid(void) { /* TBI */ }
91
92        /** Grid visitor for grid objects
93         */
94        template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
95        {
96            visitor.Visit(i_container);
97        }
98
99        /** Grid visitor for world objects
100         */
101        template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
102        {
103            visitor.Visit(i_objects);
104        }
105
106        /** Returns the number of object within the grid.
107         */
108        unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); }
109
110        /** Accessors: Returns a specific type of object in the GRID_OBJECT_TYPES
111         */
112        template<class SPECIFIC_OBJECT> const SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake) const { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
113        template<class SPECIFIC_OBJECT>       SPECIFIC_OBJECT* GetGridObject(OBJECT_HANDLE hdl, SPECIFIC_OBJECT *fake)       { return i_container.template find<SPECIFIC_OBJECT>(hdl, fake); }
114
115        /** Inserts a container type object into the grid.
116         */
117        template<class SPECIFIC_OBJECT> bool AddGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template insert<SPECIFIC_OBJECT>(hdl, obj); }
118
119        /** Removes a containter type object from the grid
120         */
121        template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl); }
122
123    private:
124
125        typedef typename ThreadModel::Lock Guard;
126        typedef typename ThreadModel::VolatileType VolatileType;
127
128        TypeMapContainer<GRID_OBJECT_TYPES> i_container;
129        TypeMapContainer<WORLD_OBJECT_TYPES> i_objects;
130};
131#endif
Note: See TracBrowser for help on using the browser.