ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/noise.h
(Generate patch)

Comparing deliantra/server/include/noise.h (file contents):
Revision 1.5 by root, Sat Apr 23 04:46:26 2011 UTC vs.
Revision 1.7 by root, Sat Apr 23 05:42:11 2011 UTC

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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2010,2011 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.
36template<int N, typename T = uint8_t> 36template<int N, typename T = uint8_t>
37struct permutation 37struct permutation
38{ 38{
39 T pmap[N]; 39 T pmap[N];
40 40
41 template<class generator> 41 template<class random_generator>
42 void seed (generator &rng) 42 void seed (random_generator &rng);
43 {
44 for (int i = 0; i < N; ++i)
45 pmap[i] = i;
46
47 // fisher-yates to randomly perturb
48 for (int i = N; --i; )
49 ::swap (pmap[i], pmap[rng (i + 1)]);
50 }
51 43
52 T operator ()(T v) 44 T operator ()(T v)
53 { 45 {
54 return pmap[v & (N - 1)]; 46 return pmap[v & (N - 1)];
55 } 47 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines