TrinityCore
Loading...
Searching...
No Matches
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 "Errors.h"
35
36template
37<
38class WORLD_OBJECT_CONTAINER,
39class GRID_OBJECT_CONTAINER
40>
41class Grid
42{
43 public:
44
48 ~Grid() { }
49
52 template<class SPECIFIC_OBJECT>
53 void AddWorldObject(SPECIFIC_OBJECT *obj)
54 {
55 i_objects.template Insert<SPECIFIC_OBJECT>(obj);
56 ASSERT(obj->IsInGrid());
57 }
58
61 //Actually an unlink is enough, no need to go through the container
62 //template<class SPECIFIC_OBJECT>
63 //void RemoveWorldObject(SPECIFIC_OBJECT *obj)
64 //{
65 // ASSERT(obj->GetGridRef().isValid());
66 // i_objects.template Remove<SPECIFIC_OBJECT>(obj);
67 // ASSERT(!obj->GetGridRef().isValid());
68 //}
69
70 // Visit grid objects
71 template<class T>
76
77 // Visit world objects
78 template<class T>
83
86 template<class T>
87 std::size_t GetWorldObjectCountInGrid() const
88 {
89 return i_objects.template Size<T>();
90 }
91
94 template<class SPECIFIC_OBJECT>
95 void AddGridObject(SPECIFIC_OBJECT *obj)
96 {
97 i_container.template Insert<SPECIFIC_OBJECT>(obj);
98 ASSERT(obj->IsInGrid());
99 }
100
103 //template<class SPECIFIC_OBJECT>
104 //void RemoveGridObject(SPECIFIC_OBJECT *obj)
105 //{
106 // ASSERT(obj->GetGridRef().isValid());
107 // i_container.template Remove<SPECIFIC_OBJECT>(obj);
108 // ASSERT(!obj->GetGridRef().isValid());
109 //}
110
113 template<class T>
114 std::size_t GetGridObjectCountInGrid() const
115 {
116 return i_container.template Size<T>();
117 }
118
119 private:
120 GRID_OBJECT_CONTAINER i_container;
121 WORLD_OBJECT_CONTAINER i_objects;
122};
123
124#endif
#define ASSERT
Definition Errors.h:80
Definition Grid.h:42
void AddWorldObject(SPECIFIC_OBJECT *obj)
Definition Grid.h:53
WORLD_OBJECT_CONTAINER i_objects
Definition Grid.h:121
std::size_t GetGridObjectCountInGrid() const
Definition Grid.h:114
void AddGridObject(SPECIFIC_OBJECT *obj)
Definition Grid.h:95
~Grid()
Definition Grid.h:48
void Visit(TypeContainerVisitor< T, GRID_OBJECT_CONTAINER > &visitor)
Definition Grid.h:72
std::size_t GetWorldObjectCountInGrid() const
Definition Grid.h:87
GRID_OBJECT_CONTAINER i_container
Definition Grid.h:120
void Visit(TypeContainerVisitor< T, WORLD_OBJECT_CONTAINER > &visitor)
Definition Grid.h:79
void Visit(TypeContainer &c)