TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Grid.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_GRID_H
20 #define TRINITY_GRID_H
21 
22 /*
23  @class Grid
24  Grid is a logical segment of the game world represented inside TrinIty.
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 "Define.h"
34 #include "TypeContainer.h"
35 #include "TypeContainerVisitor.h"
36 
37 // forward declaration
38 template<class A, class T, class O> class GridLoader;
39 
40 template
41 <
42 class ACTIVE_OBJECT,
43 class WORLD_OBJECT_TYPES,
44 class GRID_OBJECT_TYPES
45 >
46 class Grid
47 {
48  // allows the GridLoader to access its internals
49  template<class A, class T, class O> friend class GridLoader;
50  public:
51 
55  ~Grid() { }
56 
59  template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj)
60  {
61  i_objects.template insert<SPECIFIC_OBJECT>(obj);
62  ASSERT(obj->IsInGrid());
63  }
64 
67  //Actually an unlink is enough, no need to go through the container
68  //template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj)
69  //{
70  // ASSERT(obj->GetGridRef().isValid());
71  // i_objects.template remove<SPECIFIC_OBJECT>(obj);
72  // ASSERT(!obj->GetGridRef().isValid());
73  //}
74 
77  //void RefreshGrid(void) { /* TBI */}
78 
81  //void LockGrid(void) { /* TBI */ }
82 
85  //void UnlockGrid(void) { /* TBI */ }
86 
87  // Visit grid objects
88  template<class T>
90  {
91  visitor.Visit(i_container);
92  }
93 
94  // Visit world objects
95  template<class T>
97  {
98  visitor.Visit(i_objects);
99  }
100 
103  //unsigned int ActiveObjectsInGrid(void) const { return i_objects.template Count<ACTIVE_OBJECT>(); }
104  template<class T>
106  {
107  return uint32(i_objects.template Count<T>());
108  }
109 
112  template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj)
113  {
114  i_container.template insert<SPECIFIC_OBJECT>(obj);
115  ASSERT(obj->IsInGrid());
116  }
117 
120  //template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj)
121  //{
122  // ASSERT(obj->GetGridRef().isValid());
123  // i_container.template remove<SPECIFIC_OBJECT>(obj);
124  // ASSERT(!obj->GetGridRef().isValid());
125  //}
126 
127  /*bool NoWorldObjectInGrid() const
128  {
129  return i_objects.GetElements().isEmpty();
130  }
131 
132  bool NoGridObjectInGrid() const
133  {
134  return i_container.GetElements().isEmpty();
135  }*/
136  private:
137 
140  //typedef std::set<void*> ActiveGridObjects;
141  //ActiveGridObjects m_activeGridObjects;
142 };
143 #endif
Definition: TypeContainerVisitor.h:32
void Visit(TypeContainerVisitor< T, TypeMapContainer< WORLD_OBJECT_TYPES > > &visitor)
Definition: Grid.h:96
Definition: Grid.h:46
uint32 GetWorldObjectCountInGrid() const
Definition: Grid.h:105
TypeMapContainer< WORLD_OBJECT_TYPES > i_objects
Definition: Grid.h:139
~Grid()
Definition: Grid.h:55
void AddGridObject(SPECIFIC_OBJECT *obj)
Definition: Grid.h:112
uint32_t uint32
Definition: Define.h:150
Definition: Grid.h:38
void Visit(TypeContainerVisitor< T, TypeMapContainer< GRID_OBJECT_TYPES > > &visitor)
Definition: Grid.h:89
#define ASSERT
Definition: Errors.h:55
TypeMapContainer< GRID_OBJECT_TYPES > i_container
Definition: Grid.h:138
uint32_t uint32
Definition: g3dmath.h:168
void AddWorldObject(SPECIFIC_OBJECT *obj)
Definition: Grid.h:59