libtcod
Loading...
Searching...
No Matches
fov.hpp
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34// clang-format off
35#pragma once
36#ifndef TCOD_FOV_HPP_
37#define TCOD_FOV_HPP_
38
39#include <utility>
40
41#include "fov.h"
42
43class TCODPath;
44
48
55
56class TCODLIB_API TCODMap {
57 public :
70 TCODMap(int width, int height);
71
72 TCODMap(const TCODMap&) = delete;
73 TCODMap& operator=(const TCODMap&) = delete;
74 TCODMap(TCODMap&& rhs) noexcept { std::swap(data, rhs.data); };
75 TCODMap& operator=(TCODMap&& rhs) noexcept {
76 std::swap(data, rhs.data);
77 return *this;
78 };
79
94 void setProperties(int x,int y, bool isTransparent, bool isWalkable);
95
112 void clear(bool transparent=false, bool walkable=false);
113
141 void copy (const TCODMap *source);
142
190 void computeFov(int playerX,int playerY, int maxRadius = 0,bool light_walls = true, TCOD_fov_algorithm_t algo = FOV_BASIC);
191
222 bool isInFov(int x,int y) const;
244 bool isTransparent(int x, int y) const;
245 bool isWalkable(int x, int y) const;
246
265 int getWidth() const;
266 int getHeight() const;
267
268 virtual ~TCODMap();
269 void setInFov(int x,int y, bool fov);
270 int getNbCells() const;
271 friend class TCODLIB_API TCODPath;
272 friend class TCODLIB_API TCODDijkstra;
273// protected :
274 TCOD_map_t data{};
275};
276
277// clang-format on
278namespace tcod {
279struct MapDeleter_ {
280 void operator()(TCOD_Map* map) const { TCOD_map_delete(map); }
281};
282typedef std::unique_ptr<struct TCOD_Map, MapDeleter_> MapPtr_;
283} // namespace tcod
284#endif // TCOD_FOV_HPP_
Definition fov.hpp:56
int getWidth() const
You can retrieve the map size with :int TCODMap::getWidth() const int TCODMap::getHeight() constint T...
bool isInFov(int x, int y) const
Once your computed the field of view, you can know if a cell is visible with :
void copy(const TCODMap *source)
You can copy an existing map into another.
void setProperties(int x, int y, bool isTransparent, bool isWalkable)
Then, build your dungeon by defining which cells let the light pass (by default, all cells block the ...
TCODMap(int width, int height)
First, you have to allocate a map of the same size as your dungeon.
bool isTransparent(int x, int y) const
You can also retrieve transparent/walkable information with :bool TCODMap::isTransparent(int x,...
void computeFov(int playerX, int playerY, int maxRadius=0, bool light_walls=true, TCOD_fov_algorithm_t algo=FOV_BASIC)
Once your map is allocated and empty cells have been defined, you can calculate the field of view wit...
void clear(bool transparent=false, bool walkable=false)
You can clear an existing map (setting all cells to the chosen walkable/transparent values) with:void...
Definition path.hpp:72
Field-of-view module.
struct TCOD_Map TCOD_Map
Private map struct.
TCOD_fov_algorithm_t
Definition fov_types.h:63
void TCOD_map_delete(TCOD_Map *map)
Free a TCOD_Map object.
@ FOV_BASIC
Trace multiple Bresenham lines along the perimeter.
Definition fov_types.h:69
The libtcod namespace.
Definition bresenham.hpp:157