diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-23 21:28:29 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-23 21:28:29 -0400 |
| commit | f545cf0276e95c9dca33d36d1a0cfe3b4995473a (patch) | |
| tree | 7ff4023bd6c9e22f82a230a358eb70521f4c2306 /vendor/fov.h | |
| download | ether-f545cf0276e95c9dca33d36d1a0cfe3b4995473a.tar.gz ether-f545cf0276e95c9dca33d36d1a0cfe3b4995473a.tar.bz2 ether-f545cf0276e95c9dca33d36d1a0cfe3b4995473a.zip | |
somethign
Diffstat (limited to 'vendor/fov.h')
| -rw-r--r-- | vendor/fov.h | 245 |
1 files changed, 245 insertions, 0 deletions
| diff --git a/vendor/fov.h b/vendor/fov.h new file mode 100644 index 0000000..b27f59c --- /dev/null +++ b/vendor/fov.h | |||
| @@ -0,0 +1,245 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2006-2007, Greg McIntyre. All rights reserved. See the file | ||
| 3 | * named COPYING in the distribution for more details. | ||
| 4 | */ | ||
| 5 | |||
| 6 | /** | ||
| 7 | * \mainpage Field of View Library | ||
| 8 | * | ||
| 9 | * \section about About | ||
| 10 | * | ||
| 11 | * This is a C library which implements a course-grained lighting | ||
| 12 | * algorithm suitable for tile-based games such as roguelikes. | ||
| 13 | * | ||
| 14 | * \section copyright Copyright | ||
| 15 | * | ||
| 16 | * \verbinclude COPYING | ||
| 17 | * | ||
| 18 | * \section thanks Thanks | ||
| 19 | * | ||
| 20 | * Thanks to Björn Bergström | ||
| 21 | * <bjorn.bergstrom@hyperisland.se> for the algorithm. | ||
| 22 | * | ||
| 23 | */ | ||
| 24 | |||
| 25 | /** | ||
| 26 | * \file fov.h | ||
| 27 | * Field-of-view algorithm for dynamically casting light/shadow on a | ||
| 28 | * low resolution 2D raster. | ||
| 29 | */ | ||
| 30 | #ifndef LIBFOV_HEADER | ||
| 31 | #define LIBFOV_HEADER | ||
| 32 | |||
| 33 | #include <stdbool.h> | ||
| 34 | #include <stddef.h> | ||
| 35 | |||
| 36 | #ifdef __cplusplus | ||
| 37 | extern "C" { | ||
| 38 | #endif | ||
| 39 | |||
| 40 | /** Eight-way directions. */ | ||
| 41 | typedef enum { | ||
| 42 | FOV_EAST = 0, | ||
| 43 | FOV_NORTHEAST, | ||
| 44 | FOV_NORTH, | ||
| 45 | FOV_NORTHWEST, | ||
| 46 | FOV_WEST, | ||
| 47 | FOV_SOUTHWEST, | ||
| 48 | FOV_SOUTH, | ||
| 49 | FOV_SOUTHEAST | ||
| 50 | } fov_direction_type; | ||
| 51 | |||
| 52 | /** Values for the shape setting. */ | ||
| 53 | typedef enum { | ||
| 54 | FOV_SHAPE_CIRCLE_PRECALCULATE, | ||
| 55 | FOV_SHAPE_SQUARE, | ||
| 56 | FOV_SHAPE_CIRCLE, | ||
| 57 | FOV_SHAPE_OCTAGON | ||
| 58 | } fov_shape_type; | ||
| 59 | |||
| 60 | /** Values for the corner peek setting. */ | ||
| 61 | typedef enum { | ||
| 62 | FOV_CORNER_NOPEEK, | ||
| 63 | FOV_CORNER_PEEK | ||
| 64 | } fov_corner_peek_type; | ||
| 65 | |||
| 66 | /** Values for the opaque apply setting. */ | ||
| 67 | typedef enum { | ||
| 68 | FOV_OPAQUE_APPLY, | ||
| 69 | FOV_OPAQUE_NOAPPLY | ||
| 70 | } fov_opaque_apply_type; | ||
| 71 | |||
| 72 | /** @cond INTERNAL */ | ||
| 73 | typedef /*@null@*/ unsigned *height_array_t; | ||
| 74 | /** @endcond */ | ||
| 75 | |||
| 76 | typedef struct { | ||
| 77 | /** Opacity test callback. */ | ||
| 78 | /*@null@*/ bool (*opaque)(void *map, int x, int y); | ||
| 79 | |||
| 80 | /** Lighting callback to set lighting on a map tile. */ | ||
| 81 | /*@null@*/ void (*apply)(void *map, int x, int y, int dx, int dy, void *src); | ||
| 82 | |||
| 83 | /** Shape setting. */ | ||
| 84 | fov_shape_type shape; | ||
| 85 | |||
| 86 | /** Whether to peek around corners. */ | ||
| 87 | fov_corner_peek_type corner_peek; | ||
| 88 | |||
| 89 | /** Whether to call apply on opaque tiles. */ | ||
| 90 | fov_opaque_apply_type opaque_apply; | ||
| 91 | |||
| 92 | /** \cond INTERNAL */ | ||
| 93 | |||
| 94 | /** Pre-calculated data. \internal */ | ||
| 95 | /*@null@*/ height_array_t *heights; | ||
| 96 | |||
| 97 | /** Size of pre-calculated data. \internal */ | ||
| 98 | unsigned numheights; | ||
| 99 | |||
| 100 | /** \endcond */ | ||
| 101 | } fov_settings_type; | ||
| 102 | |||
| 103 | /** The opposite direction to that given. */ | ||
| 104 | #define fov_direction_opposite(direction) ((fov_direction_type)(((direction)+4)&0x7)) | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Set all the default options. You must call this option when you | ||
| 108 | * create a new settings data structure. | ||
| 109 | * | ||
| 110 | * These settings are the defaults used: | ||
| 111 | * | ||
| 112 | * - shape: FOV_SHAPE_CIRCLE_PRECALCULATE | ||
| 113 | * - corner_peek: FOV_CORNER_NOPEEK | ||
| 114 | * - opaque_apply: FOV_OPAQUE_APPLY | ||
| 115 | * | ||
| 116 | * Callbacks still need to be set up after calling this function. | ||
| 117 | * | ||
| 118 | * \param settings Pointer to data structure containing settings. | ||
| 119 | */ | ||
| 120 | void fov_settings_init(fov_settings_type *settings); | ||
| 121 | |||
| 122 | /** | ||
| 123 | * Set the shape of the field of view. | ||
| 124 | * | ||
| 125 | * \param settings Pointer to data structure containing settings. | ||
| 126 | * \param value One of the following values, where R is the radius: | ||
| 127 | * | ||
| 128 | * - FOV_SHAPE_CIRCLE_PRECALCULATE \b (default): Limit the FOV to a | ||
| 129 | * circle with radius R by precalculating, which consumes more memory | ||
| 130 | * at the rate of 4*(R+2) bytes per R used in calls to fov_circle. | ||
| 131 | * Each radius is only calculated once so that it can be used again. | ||
| 132 | * Use fov_free() to free this precalculated data's memory. | ||
| 133 | * | ||
| 134 | * - FOV_SHAPE_CIRCLE: Limit the FOV to a circle with radius R by | ||
| 135 | * calculating on-the-fly. | ||
| 136 | * | ||
| 137 | * - FOV_SHAPE_OCTOGON: Limit the FOV to an octogon with maximum radius R. | ||
| 138 | * | ||
| 139 | * - FOV_SHAPE_SQUARE: Limit the FOV to an R*R square. | ||
| 140 | */ | ||
| 141 | void fov_settings_set_shape(fov_settings_type *settings, fov_shape_type value); | ||
| 142 | |||
| 143 | /** | ||
| 144 | * <em>NOT YET IMPLEMENTED</em>. | ||
| 145 | * | ||
| 146 | * Set whether sources will peek around corners. | ||
| 147 | * | ||
| 148 | * \param settings Pointer to data structure containing settings. | ||
| 149 | * \param value One of the following values: | ||
| 150 | * | ||
| 151 | * - FOV_CORNER_PEEK \b (default): Renders: | ||
| 152 | \verbatim | ||
| 153 | ........ | ||
| 154 | ........ | ||
| 155 | ........ | ||
| 156 | ..@# | ||
| 157 | ...# | ||
| 158 | \endverbatim | ||
| 159 | * - FOV_CORNER_NOPEEK: Renders: | ||
| 160 | \verbatim | ||
| 161 | ...... | ||
| 162 | ..... | ||
| 163 | .... | ||
| 164 | ..@# | ||
| 165 | ...# | ||
| 166 | \endverbatim | ||
| 167 | */ | ||
| 168 | void fov_settings_set_corner_peek(fov_settings_type *settings, fov_corner_peek_type value); | ||
| 169 | |||
| 170 | /** | ||
| 171 | * Whether to call the apply callback on opaque tiles. | ||
| 172 | * | ||
| 173 | * \param settings Pointer to data structure containing settings. | ||
| 174 | * \param value One of the following values: | ||
| 175 | * | ||
| 176 | * - FOV_OPAQUE_APPLY \b (default): Call apply callback on opaque tiles. | ||
| 177 | * - FOV_OPAQUE_NOAPPLY: Do not call the apply callback on opaque tiles. | ||
| 178 | */ | ||
| 179 | void fov_settings_set_opaque_apply(fov_settings_type *settings, fov_opaque_apply_type value); | ||
| 180 | |||
| 181 | /** | ||
| 182 | * Set the function used to test whether a map tile is opaque. | ||
| 183 | * | ||
| 184 | * \param settings Pointer to data structure containing settings. | ||
| 185 | * \param f The function called to test whether a map tile is opaque. | ||
| 186 | */ | ||
| 187 | void fov_settings_set_opacity_test_function(fov_settings_type *settings, bool (*f)(void *map, int x, int y)); | ||
| 188 | |||
| 189 | /** | ||
| 190 | * Set the function used to apply lighting to a map tile. | ||
| 191 | * | ||
| 192 | * \param settings Pointer to data structure containing settings. | ||
| 193 | * \param f The function called to apply lighting to a map tile. | ||
| 194 | */ | ||
| 195 | 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)); | ||
| 196 | |||
| 197 | /** | ||
| 198 | * Free any memory that may have been cached in the settings | ||
| 199 | * structure. | ||
| 200 | * | ||
| 201 | * \param settings Pointer to data structure containing settings. | ||
| 202 | */ | ||
| 203 | void fov_settings_free(fov_settings_type *settings); | ||
| 204 | |||
| 205 | /** | ||
| 206 | * Calculate a full circle field of view from a source at (x,y). | ||
| 207 | * | ||
| 208 | * \param settings Pointer to data structure containing settings. | ||
| 209 | * \param map Pointer to map data structure to be passed to callbacks. | ||
| 210 | * \param source Pointer to data structure holding source of light. | ||
| 211 | * \param source_x x-axis coordinate from which to start. | ||
| 212 | * \param source_y y-axis coordinate from which to start. | ||
| 213 | * \param radius Euclidean distance from (x,y) after which to stop. | ||
| 214 | */ | ||
| 215 | void fov_circle(fov_settings_type *settings, void *map, void *source, | ||
| 216 | int source_x, int source_y, unsigned radius | ||
| 217 | ); | ||
| 218 | |||
| 219 | /** | ||
| 220 | * Calculate a field of view from source at (x,y), pointing | ||
| 221 | * in the given direction and with the given angle. The larger | ||
| 222 | * the angle, the wider, "less focused" the beam. Each side of the | ||
| 223 | * line pointing in the direction from the source will be half the | ||
| 224 | * angle given such that the angle specified will be represented on | ||
| 225 | * the raster. | ||
| 226 | * | ||
| 227 | * \param settings Pointer to data structure containing settings. | ||
| 228 | * \param map Pointer to map data structure to be passed to callbacks. | ||
| 229 | * \param source Pointer to data structure holding source of light. | ||
| 230 | * \param source_x x-axis coordinate from which to start. | ||
| 231 | * \param source_y y-axis coordinate from which to start. | ||
| 232 | * \param radius Euclidean distance from (x,y) after which to stop. | ||
| 233 | * \param direction One of eight directions the beam of light can point. | ||
| 234 | * \param angle The angle at the base of the beam of light, in degrees. | ||
| 235 | */ | ||
| 236 | void fov_beam(fov_settings_type *settings, void *map, void *source, | ||
| 237 | int source_x, int source_y, unsigned radius, | ||
| 238 | fov_direction_type direction, float angle | ||
| 239 | ); | ||
| 240 | |||
| 241 | #ifdef __cplusplus | ||
| 242 | } /* extern "C" */ | ||
| 243 | #endif | ||
| 244 | |||
| 245 | #endif | ||
