TrinityCore
Grid.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_GRID_H
19#define TRINITY_GRID_H
20
21/*
22 @class Grid
23 Grid is a logical segment of the game world represented inside TrinIty.
24 Grid is bind at compile time to a particular type of object which
25 we call it the object of interested. There are many types of loader,
26 specially, dynamic loader, static loader, or on-demand loader. There's
27 a subtle difference between dynamic loader and on-demand loader but
28 this is implementation specific to the loader class. From the
29 Grid's perspective, the loader meets its API requirement is suffice.
30*/
31
32#include "Define.h"
33#include "TypeContainer.h"
35
36// forward declaration
37template<class A, class T, class O> class GridLoader;
38
39template
40<
41class ACTIVE_OBJECT,
42class WORLD_OBJECT_TYPES,
43class GRID_OBJECT_TYPES
44>
45class Grid
46{
47 // allows the GridLoader to access its internals
48 template<class A, class T, class O> friend class GridLoader;
49 public:
50
54 ~Grid() { }
55
58 template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj)
59 {
60 i_objects.template insert<SPECIFIC_OBJECT>(obj);
61 ASSERT(obj->IsInGrid());
62 }
63
66 //Actually an unlink is enough, no need to go through the container
67 //template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj)
68 //{
69 // ASSERT(obj->GetGridRef().isValid());
70 // i_objects.template remove<SPECIFIC_OBJECT>(obj);
71 // ASSERT(!obj->GetGridRef().isValid());
72 //}
73
76 //void RefreshGrid(void) { /* TBI */}
77
80 //void LockGrid(void) { /* TBI */ }
81
84 //void UnlockGrid(void) { /* TBI */ }
85
86 // Visit grid objects
87 template<class T>
89 {
90 visitor.Visit(i_container);
91 }
92
93 // Visit world objects
94 template<class T>
96 {
97 visitor.Visit(i_objects);
98 }
99
102 //unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); }
103 template<class T>
105 {
106 return uint32(i_objects.template Count<T>());
107 }
108
111 template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj)
112 {
113 i_container.template insert<SPECIFIC_OBJECT>(obj);
114 ASSERT(obj->IsInGrid());
115 }
116
119 //template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj)
120 //{
121 // ASSERT(obj->GetGridRef().isValid());
122 // i_container.template remove<SPECIFIC_OBJECT>(obj);
123 // ASSERT(!obj->GetGridRef().isValid());
124 //}
125
126 /*bool NoWorldObjectInGrid() const
127 {
128 return i_objects.GetElements().isEmpty();
129 }
130
131 bool NoGridObjectInGrid() const
132 {
133 return i_container.GetElements().isEmpty();
134 }*/
135 private:
136
139 //typedef std::set<void*> ActiveGridObjects;
140 //ActiveGridObjects m_activeGridObjects;
141};
142#endif
uint32_t uint32
Definition: Define.h:142
#define ASSERT
Definition: Errors.h:68
Definition: Grid.h:46
TypeMapContainer< WORLD_OBJECT_TYPES > i_objects
Definition: Grid.h:138
TypeMapContainer< GRID_OBJECT_TYPES > i_container
Definition: Grid.h:137
uint32 GetWorldObjectCountInGrid() const
Definition: Grid.h:104
void Visit(TypeContainerVisitor< T, TypeMapContainer< GRID_OBJECT_TYPES > > &visitor)
Definition: Grid.h:88
void AddWorldObject(SPECIFIC_OBJECT *obj)
Definition: Grid.h:58
void AddGridObject(SPECIFIC_OBJECT *obj)
Definition: Grid.h:111
~Grid()
Definition: Grid.h:54
void Visit(TypeContainerVisitor< T, TypeMapContainer< WORLD_OBJECT_TYPES > > &visitor)
Definition: Grid.h:95