/[anoncvs]/projects/roguelike/fov.h


UCC Code Repository

Contents of /projects/roguelike/fov.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Thu Apr 13 12:42:56 2006 UTC (15 years ago) by banana
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
File MIME type: text/plain
libfov cast fixes for C++

1 /*
2 Copyright (c) 2006, Greg McIntyre
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 - Neither the name of the nor the names of its contributors may be
17 used to endorse or promote products derived from this software
18 without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * fov.h
35 * Field-of-view algorithm for dynamically casting light/shadow on a low resolution 2D raster.
36 */
37 #pragma once
38
39 #include <stddef.h>
40
41 /** Eight-way directions. */
42 typedef enum {
43 FOV_EAST = 0,
44 FOV_NORTHEAST,
45 FOV_NORTH,
46 FOV_NORTHWEST,
47 FOV_WEST,
48 FOV_SOUTHWEST,
49 FOV_SOUTH,
50 FOV_SOUTHEAST
51 } fov_direction_type;
52
53 /** Values for the shape setting. */
54 typedef enum {
55 FOV_SHAPE_CIRCLE_PRECALCULATE,
56 FOV_SHAPE_SQUARE,
57 FOV_SHAPE_CIRCLE,
58 FOV_SHAPE_OCTAGON
59 } fov_shape_type;
60
61 /** Values for the corner peek setting. */
62 typedef enum {
63 FOV_CORNER_NOPEEK,
64 FOV_CORNER_PEEK
65 } fov_corner_peek_type;
66
67 /** Values for the opaque apply setting. */
68 typedef enum {
69 FOV_OPAQUE_APPLY,
70 FOV_OPAQUE_NOAPPLY
71 } fov_opaque_apply_type;
72
73 typedef struct {
74 /** Opacity test callback. */
75 bool (*opaque)(void *map, int x, int y);
76
77 /** Lighting callback to set lighting on a map tile. */
78 void (*apply)(void *map, int x, int y, int dx, int dy, void *src);
79
80 /** Shape setting. */
81 fov_shape_type shape;
82 fov_corner_peek_type corner_peek;
83 fov_opaque_apply_type opaque_apply;
84
85 /* Pre-calculated data. */
86 unsigned **heights;
87
88 /* Size of pre-calculated data. */
89 size_t numheights;
90 } fov_settings_type;
91
92 /** The opposite direction to that given. */
93 #define fov_direction_opposite(direction) ((fov_direction_type)(((direction)+4)&0x7))
94
95 /**
96 * Set all the default options. You must call this option when you
97 * create a new settings data structure.
98 *
99 * These settings are the defaults used:
100 *
101 * - shape: FOV_SHAPE_CIRCLE_PRECALCULATE
102 * - corner_peek: FOV_CORNER_NOPEEK
103 * - opaque_apply: FOV_OPAQUE_APPLY
104 *
105 * Callbacks still need to be set up after calling this function.
106 *
107 * \param settings Pointer to data structure containing settings.
108 */
109 void fov_settings_init(fov_settings_type *settings);
110
111 /**
112 * Set the shape of the field of view.
113 *
114 * \param settings Pointer to data structure containing settings.
115 * \param value One of the following values, where R is the radius:
116 *
117 * - FOV_SHAPE_CIRCLE_PRECALCULATE \b (default): Limit the FOV to a
118 * circle with radius R by precalculating, which consumes more memory
119 * at the rate of 4*(R+2) bytes per R used in calls to fov_circle.
120 * Each radius is only calculated once so that it can be used again.
121 * Use fov_free() to free this precalculated data's memory.
122 *
123 * - FOV_SHAPE_CIRCLE: Limit the FOV to a circle with radius R by
124 * calculating on-the-fly.
125 *
126 * - FOV_SHAPE_OCTOGON: Limit the FOV to an octogon with maximum radius R.
127 *
128 * - FOV_SHAPE_SQUARE: Limit the FOV to an R*R square.
129 */
130 void fov_settings_set_shape(fov_settings_type *settings, fov_shape_type value);
131
132 /**
133 * <em>NOT YET IMPLEMENTED</em>.
134 *
135 * Set whether sources will peek around corners.
136 *
137 * \param settings Pointer to data structure containing settings.
138 * \param value One of the following values:
139 *
140 * - FOV_CORNER_PEEK \b (default): Renders:
141 \verbatim
142 ........
143 ........
144 ........
145 [email protected]#
146 ...#
147 \endverbatim
148 * - FOV_CORNER_NOPEEK: Renders:
149 \verbatim
150 ......
151 .....
152 ....
153 [email protected]#
154 ...#
155 \endverbatim
156 */
157 void fov_settings_set_corner_peek(fov_settings_type *settings, fov_corner_peek_type value);
158
159 /**
160 * Whether to call the apply callback on opaque tiles.
161 *
162 * \param settings Pointer to data structure containing settings.
163 * \param value One of the following values:
164 *
165 * - FOV_OPAQUE_APPLY \b (default): Call apply callback on opaque tiles.
166 * - FOV_OPAQUE_NOAPPLY: Do not call the apply callback on opaque tiles.
167 */
168 void fov_settings_set_opaque_apply(fov_settings_type *settings, fov_opaque_apply_type value);
169
170 /**
171 * Set the function used to test whether a map tile is opaque.
172 *
173 * \param settings Pointer to data structure containing settings.
174 * \param f The function called to test whether a map tile is opaque.
175 */
176 void fov_settings_set_opacity_test_function(fov_settings_type *settings, bool (*f)(void *map, int x, int y));
177
178 /**
179 * Set the function used to apply lighting to a map tile.
180 *
181 * \param settings Pointer to data structure containing settings.
182 * \param f The function called to apply lighting to a map tile.
183 */
184 void fov_settings_set_apply_lighting_function(fov_settings_type *settings, void (*f)(void *map, int x, int y, int dx, int dy, void *src));
185
186 /**
187 * Free any memory that may have been cached in the settings
188 * structure.
189 *
190 * \param settings Pointer to data structure containing settings.
191 */
192 void fov_settings_free(fov_settings_type *settings);
193
194 /**
195 * Calculate a full circle field of view from a source at (x,y).
196 *
197 * \param settings Pointer to data structure containing settings.
198 * \param map Pointer to map data structure to be passed to callbacks.
199 * \param source Pointer to data structure holding source of light.
200 * \param source_x x-axis coordinate from which to start.
201 * \param source_y y-axis coordinate from which to start.
202 * \param radius Euclidean distance from (x,y) after which to stop.
203 */
204 void fov_circle(fov_settings_type *settings, void *map, void *source,
205 int source_x, int source_y, unsigned radius
206 );
207
208 /**
209 * Calculate a field of view from source at (x,y), pointing
210 * in the given direction and with the given angle. The larger
211 * the angle, the wider, "less focused" the beam. Each side of the
212 * line pointing in the direction from the source will be half the
213 * angle given such that the angle specified will be represented on
214 * the raster.
215 *
216 * \param settings Pointer to data structure containing settings.
217 * \param map Pointer to map data structure to be passed to callbacks.
218 * \param source Pointer to data structure holding source of light.
219 * \param source_x x-axis coordinate from which to start.
220 * \param source_y y-axis coordinate from which to start.
221 * \param radius Euclidean distance from (x,y) after which to stop.
222 * \param direction One of eight directions the beam of light can point.
223 * \param angle The angle at the base of the beam of light, in degrees.
224 */
225 void fov_beam(fov_settings_type *settings, void *map, void *source,
226 int source_x, int source_y, unsigned radius,
227 fov_direction_type direction, float angle
228 );

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26