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 (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * 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 |
7 | * 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 |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
145 | { |
145 | { |
146 | }; |
146 | }; |
147 | |
147 | |
148 | ///////////////////////////////////////////////////////////////////////////// |
148 | ///////////////////////////////////////////////////////////////////////////// |
149 | |
149 | |
150 | template<int N, typename T = uint8_t> |
150 | template< int N, typename T> |
151 | struct permutation |
151 | struct permutation |
152 | { |
152 | { |
153 | T pmap[N]; |
153 | T pmap[N]; |
154 | |
154 | |
155 | void seed (seedable_rand_gen &rng); |
155 | void seed (seedable_rand_gen &rng); |
156 | |
156 | |
157 | T operator ()(T v) func_pure |
157 | T operator ()(T v) func_pure |
158 | { |
158 | { |
159 | return pmap[v & (N - 1)]; |
159 | return pmap[v & T(N - 1)]; |
160 | } |
160 | } |
161 | }; |
161 | }; |
162 | |
162 | |
163 | ///////////////////////////////////////////////////////////////////////////// |
163 | ///////////////////////////////////////////////////////////////////////////// |
164 | |
164 | |
165 | template<class vec_t> |
165 | template<class vec_t> |
166 | struct noise_gen_base |
166 | struct noise_gen_base |
167 | { |
167 | { |
168 | permutation<256, uint8_t> rvmap[vec_t::numElements]; |
168 | permutation<256, uint8_t> rvmap[vec_t::numElements + 1]; |
169 | |
169 | |
170 | typedef typename vec_t::T_numtype value_t; |
170 | typedef typename vec_t::T_numtype value_t; |
171 | |
171 | |
172 | void seed (seedable_rand_gen &rng); |
172 | void seed (seedable_rand_gen &rng); |
173 | void seed (seed_t seed); |
173 | void seed (seed_t seed); |
… | |
… | |
235 | }; |
235 | }; |
236 | |
236 | |
237 | typedef frac_gen<vec2d> frac2d; |
237 | typedef frac_gen<vec2d> frac2d; |
238 | typedef frac_gen<vec3d> frac3d; |
238 | typedef frac_gen<vec3d> frac3d; |
239 | |
239 | |
|
|
240 | ///////////////////////////////////////////////////////////////////////////// |
|
|
241 | |
|
|
242 | template<typename T, typename U> |
|
|
243 | inline T |
|
|
244 | border_blend (T a, T b, vec2d P, U N, U W) |
|
|
245 | { |
|
|
246 | U border = W; // within n places of the border |
|
|
247 | |
|
|
248 | min_it (border, P [0]); |
|
|
249 | min_it (border, N - P [0]); |
|
|
250 | min_it (border, P [1]); |
|
|
251 | min_it (border, N - P [1]); |
|
|
252 | |
|
|
253 | return blend (a, b, border, U(0), W); |
|
|
254 | } |
|
|
255 | |
240 | #endif |
256 | #endif |
241 | |
257 | |