libtcod
Loading...
Searching...
No Matches
noise.h
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#pragma once
35#ifndef TCOD_PERLIN_H_
36#define TCOD_PERLIN_H_
37
38#include "config.h"
39#include "mersenne_types.h"
40#include "noise_defaults.h"
41
42typedef enum {
43 TCOD_NOISE_PERLIN = 1,
44 TCOD_NOISE_SIMPLEX = 2,
45 TCOD_NOISE_WAVELET = 4,
46 TCOD_NOISE_DEFAULT = 0
47} TCOD_noise_type_t;
48
49typedef struct TCOD_Noise {
50 int ndim;
52 unsigned char map[256];
54 float buffer[256][TCOD_NOISE_MAX_DIMENSIONS];
55 /* fractal stuff */
56 float H;
57 float lacunarity;
58 float exponent[TCOD_NOISE_MAX_OCTAVES];
59 float* __restrict waveletTileData;
60 TCOD_Random* rand;
61 /* noise type */
62 TCOD_noise_type_t noise_type;
64typedef TCOD_Noise* TCOD_noise_t;
65#ifdef __cplusplus
66extern "C" {
67#endif
68/* create a new noise object */
69TCOD_NODISCARD
70TCOD_PUBLIC TCOD_Noise* TCOD_noise_new(int dimensions, float hurst, float lacunarity, TCOD_Random* random);
71
72/* simplified API */
73TCOD_PUBLIC void TCOD_noise_set_type(TCOD_Noise* __restrict noise, TCOD_noise_type_t type);
74TCOD_NODISCARD
75TCOD_PUBLIC float TCOD_noise_get_ex(TCOD_Noise* __restrict noise, const float* __restrict f, TCOD_noise_type_t type);
76TCOD_NODISCARD
77TCOD_PUBLIC float TCOD_noise_get_fbm_ex(
78 TCOD_Noise* __restrict noise, const float* __restrict f, float octaves, TCOD_noise_type_t type);
79TCOD_NODISCARD
80TCOD_PUBLIC float TCOD_noise_get_turbulence_ex(
81 TCOD_Noise* __restrict noise, const float* __restrict f, float octaves, TCOD_noise_type_t type);
82TCOD_NODISCARD
83TCOD_PUBLIC float TCOD_noise_get(TCOD_Noise* __restrict noise, const float* __restrict f);
84TCOD_NODISCARD
85TCOD_PUBLIC float TCOD_noise_get_fbm(TCOD_Noise* __restrict noise, const float* __restrict f, float octaves);
86TCOD_NODISCARD
87TCOD_PUBLIC float TCOD_noise_get_turbulence(TCOD_Noise* __restrict noise, const float* __restrict f, float octaves);
88/* delete the noise object */
89TCOD_PUBLIC void TCOD_noise_delete(TCOD_Noise* __restrict noise);
90
112 TCOD_Noise* __restrict noise,
113 TCOD_noise_type_t type,
114 int n,
115 float* __restrict x,
116 float* __restrict y,
117 float* __restrict z,
118 float* __restrict w,
119 float* __restrict out);
120
132 TCOD_Noise* __restrict noise,
133 TCOD_noise_type_t type,
134 float octaves,
135 int n,
136 float* __restrict x,
137 float* __restrict y,
138 float* __restrict z,
139 float* __restrict w,
140 float* __restrict out);
141
153 TCOD_Noise* __restrict noise,
154 TCOD_noise_type_t type,
155 float octaves,
156 int n,
157 float* __restrict x,
158 float* __restrict y,
159 float* __restrict z,
160 float* __restrict w,
161 float* __restrict out);
162#ifdef __cplusplus
163}
164#endif
165#endif // TCOD_PERLIN_H_
Libtcod config header.
Random number generator types.
void TCOD_noise_get_fbm_vectorized(TCOD_Noise *noise, TCOD_noise_type_t type, float octaves, int n, float *x, float *y, float *z, float *w, float *out)
Generate noise as a vectorized operation with fractional Brownian motion.
void TCOD_noise_get_vectorized(TCOD_Noise *noise, TCOD_noise_type_t type, int n, float *x, float *y, float *z, float *w, float *out)
Generate noise as a vectorized operation.
void TCOD_noise_get_turbulence_vectorized(TCOD_Noise *noise, TCOD_noise_type_t type, float octaves, int n, float *x, float *y, float *z, float *w, float *out)
Generate noise as a vectorized operation with turbulence.
Noise default parameters.
Definition noise.h:49
float buffer[256][TCOD_NOISE_MAX_DIMENSIONS]
Random 256 x ndim buffer.
Definition noise.h:54
unsigned char map[256]
Randomized map of indexes into buffer.
Definition noise.h:52
Pseudorandom number generator toolkit, all attributes are private.
Definition mersenne_types.h:87