1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
6 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
10 | * option) any later version. |
… | |
… | |
21 | */ |
22 | */ |
22 | |
23 | |
23 | #ifndef NOISE_H_ |
24 | #ifndef NOISE_H_ |
24 | #define NOISE_H_ |
25 | #define NOISE_H_ |
25 | |
26 | |
|
|
27 | #if 0 // blitz++0.09 |
26 | #include <string.h> // workaround for tinyvec using memcpy without including string.h |
28 | #include <string.h> // workaround for tinyvec using memcpy without including string.h |
|
|
29 | #include <cstdlib> // workaround for tinyvec using labs without including cstdlib |
27 | #include <blitz/tinyvec.h> |
30 | #include <blitz/tinyvec.h> |
28 | #include <blitz/tinyvec-et.h> |
31 | #include <blitz/tinyvec-et.h> |
29 | |
|
|
30 | #include "global.h" |
|
|
31 | |
|
|
32 | typedef blitz::TinyVector<float,2> vec2d; |
32 | typedef blitz::TinyVector<float,2> vec2d; |
33 | typedef blitz::TinyVector<float,3> vec3d; |
33 | typedef blitz::TinyVector<float,3> vec3d; |
|
|
34 | #else |
|
|
35 | |
|
|
36 | // blitz++ 0.10 - not working |
|
|
37 | #include <blitz/array.h> |
|
|
38 | #include <blitz/tinyvec2.h> |
|
|
39 | #include <blitz/tinyvec2.cc> |
|
|
40 | |
|
|
41 | template<typename T, int length> |
|
|
42 | struct vecnd |
|
|
43 | : blitz::TinyVector<T, length> |
|
|
44 | { |
|
|
45 | static const int numElements = length; |
|
|
46 | using blitz::TinyVector<T, length>::TinyVector; |
|
|
47 | }; |
|
|
48 | |
|
|
49 | typedef vecnd<float,2> vec2d; |
|
|
50 | typedef vecnd<float,3> vec3d; |
|
|
51 | |
|
|
52 | #endif |
|
|
53 | |
|
|
54 | #include "global.h" |
34 | |
55 | |
35 | vec2d |
56 | vec2d |
36 | inline floor (vec2d v) |
57 | inline floor (vec2d v) |
37 | { |
58 | { |
38 | return vec2d (fastfloor (v[0]), fastfloor (v[1])); |
59 | return vec2d (fastfloor (v[0]), fastfloor (v[1])); |
… | |
… | |
153 | { |
174 | { |
154 | T pmap[N]; |
175 | T pmap[N]; |
155 | |
176 | |
156 | void seed (seedable_rand_gen &rng); |
177 | void seed (seedable_rand_gen &rng); |
157 | |
178 | |
158 | T operator ()(T v) func_pure |
179 | ecb_pure T operator ()(T v) |
159 | { |
180 | { |
160 | return pmap[v & T(N - 1)]; |
181 | return pmap[v & T(N - 1)]; |
161 | } |
182 | } |
162 | }; |
183 | }; |
163 | |
184 | |
… | |
… | |
171 | typedef typename vec_t::T_numtype value_t; |
192 | typedef typename vec_t::T_numtype value_t; |
172 | |
193 | |
173 | void seed (seedable_rand_gen &rng); |
194 | void seed (seedable_rand_gen &rng); |
174 | void seed (seed_t seed); |
195 | void seed (seed_t seed); |
175 | |
196 | |
176 | value_t operator ()(vec_t P, uint32_t seed = 0) func_pure; |
197 | ecb_pure value_t operator ()(vec_t P, uint32_t seed = 0); |
177 | }; |
198 | }; |
178 | |
199 | |
179 | template<class vec_t> |
200 | template<class vec_t> |
180 | struct noise_gen; |
201 | struct noise_gen; |
181 | |
202 | |
… | |
… | |
194 | static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise)) |
215 | static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise)) |
195 | |
216 | |
196 | using noise_gen_base<vec3d>::operator (); |
217 | using noise_gen_base<vec3d>::operator (); |
197 | |
218 | |
198 | // noise projected on a surface with normal n |
219 | // noise projected on a surface with normal n |
199 | vec2d::T_numtype operator() (vec3d P, vec3d N, uint32_t seed = 0) func_pure; |
220 | ecb_pure vec2d::T_numtype operator() (vec3d P, vec3d N, uint32_t seed = 0); |
200 | }; |
221 | }; |
201 | |
222 | |
202 | typedef noise_gen<vec2d> noise2d; |
223 | typedef noise_gen<vec2d> noise2d; |
203 | typedef noise_gen<vec3d> noise3d; |
224 | typedef noise_gen<vec3d> noise3d; |
204 | |
225 | |
… | |
… | |
217 | value_t fbm_mul[MAX_OCTAVES]; |
238 | value_t fbm_mul[MAX_OCTAVES]; |
218 | rotate_xy<vec_t> rot[MAX_OCTAVES]; |
239 | rotate_xy<vec_t> rot[MAX_OCTAVES]; |
219 | |
240 | |
220 | frac_gen (int octaves = 3, value_t lacunarity = 2, value_t hurst_expo = .5, uint32_t seed = 0); |
241 | frac_gen (int octaves = 3, value_t lacunarity = 2, value_t hurst_expo = .5, uint32_t seed = 0); |
221 | |
242 | |
222 | value_t noise (vec_t P, uint32_t seed = 0) func_pure |
243 | ecb_pure value_t noise (vec_t P, uint32_t seed = 0) |
223 | { |
244 | { |
224 | return this->operator() (P, seed); |
245 | return this->operator() (P, seed); |
225 | } |
246 | } |
226 | |
247 | |
227 | value_t fBm (vec_t P) func_pure; |
248 | ecb_pure value_t fBm (vec_t P); |
228 | value_t turbulence (vec_t P) func_pure; |
249 | ecb_pure value_t turbulence (vec_t P); |
229 | value_t multifractal (vec_t P, value_t offset = 1) func_pure; |
250 | ecb_pure value_t multifractal (vec_t P, value_t offset = 1); |
230 | value_t heterofractal (vec_t P, value_t offset = 1) func_pure; |
251 | ecb_pure value_t heterofractal (vec_t P, value_t offset = 1); |
231 | value_t hybridfractal (vec_t P, value_t offset = 1, value_t gain = 1) func_pure; |
252 | ecb_pure value_t hybridfractal (vec_t P, value_t offset = 1, value_t gain = 1); |
232 | value_t ridgedmultifractal (vec_t P, value_t offset = 1, value_t gain = 8) func_pure; |
253 | ecb_pure value_t ridgedmultifractal (vec_t P, value_t offset = 1, value_t gain = 8); |
233 | value_t billowfractal (vec_t P, value_t offset = 1, value_t gain = 2) func_pure; |
254 | ecb_pure value_t billowfractal (vec_t P, value_t offset = 1, value_t gain = 2); |
234 | value_t terrain (vec_t P) func_pure; |
255 | ecb_pure value_t terrain (vec_t P); |
235 | value_t terrain2 (vec_t P) func_pure; |
256 | ecb_pure value_t terrain2 (vec_t P); |
236 | }; |
257 | }; |
237 | |
258 | |
238 | typedef frac_gen<vec2d> frac2d; |
259 | typedef frac_gen<vec2d> frac2d; |
239 | typedef frac_gen<vec3d> frac3d; |
260 | typedef frac_gen<vec3d> frac3d; |
240 | |
261 | |