Horizon Official Technical Documentation
GridHolder.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_GAME_GRIDHOLDER_HPP
31#define HORIZON_ZONE_GAME_GRIDHOLDER_HPP
32
33#include "GridDefinitions.hpp"
37
42template<class ZONE_OBJECT_TYPES>
44{
45public:
47
50 {
51 }
52
54 {
55 }
56
57 GridType &get_grid(int x, int y)
58 {
59 assert(x <= _width);
60 assert(y <= _height);
61 assert(x >= 0 && y >= 0);
62
63 return _grids[x][y];
64 }
65
66 uint16_t height() { return _height; }
67 uint16_t width() { return _width; }
68
69 template<class VISITOR, class CONTAINER_TYPE>
71 {
72 for (uint16_t x = 0; x < _width; ++x) {
73 for (uint16_t y = 0; y < _height; ++y) {
74 get_grid(x, y).visit(visitor);
75 }
76 }
77 }
78
79 template<class VISITOR, class CONTAINER_TYPE>
81 {
82 get_grid(x, y).Visit(visitor);
83 }
84
85private:
86 int _width{ 0 }, _height{ 0 };
88};
89
90#endif /* HORIZON_ZONE_GAME_GRIDHOLDER_HPP */
#define MAX_GRIDS_PER_MAP
Definition: GridDefinitions.hpp:66
GridHolder is a container for Grids, handles the visiting of grids.
Definition: GridHolder.hpp:44
int _height
Definition: GridHolder.hpp:86
int _width
Definition: GridHolder.hpp:86
void visit(int x, int y, GridReferenceContainerVisitor< VISITOR, GridReferenceContainer< CONTAINER_TYPE > > &visitor)
Definition: GridHolder.hpp:80
GridType _grids[MAX_GRIDS_PER_MAP][MAX_GRIDS_PER_MAP]
Definition: GridHolder.hpp:87
~GridHolder()
Definition: GridHolder.hpp:53
uint16_t width()
Definition: GridHolder.hpp:67
Grid< ZONE_OBJECT_TYPES > GridType
Definition: GridHolder.hpp:46
void visit_all(GridReferenceContainerVisitor< VISITOR, GridReferenceContainer< CONTAINER_TYPE > > &visitor)
Definition: GridHolder.hpp:70
uint16_t height()
Definition: GridHolder.hpp:66
GridHolder(int width, int height)
Definition: GridHolder.hpp:48
GridType & get_grid(int x, int y)
Definition: GridHolder.hpp:57
Definition: GridReferenceContainerVisitor.hpp:70
Definition: GridReferenceContainer.hpp:149
void visit(GridReferenceContainerVisitor< VISITOR, GridReferenceContainer< GRID_OBJECT_TYPES > > &visitor)
Definition: Grid.hpp:61