… | |
… | |
6 | #else |
6 | #else |
7 | # define is_constant(c) 0 |
7 | # define is_constant(c) 0 |
8 | #endif |
8 | #endif |
9 | |
9 | |
10 | #include <cstddef> |
10 | #include <cstddef> |
|
|
11 | #include <cmath> |
11 | #include <new> |
12 | #include <new> |
12 | #include <vector> |
13 | #include <vector> |
13 | |
14 | |
14 | #include <glib.h> |
15 | #include <glib.h> |
15 | |
16 | |
… | |
… | |
31 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
32 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
32 | |
33 | |
33 | // in range excluding end |
34 | // in range excluding end |
34 | #define IN_RANGE_EXC(val,beg,end) \ |
35 | #define IN_RANGE_EXC(val,beg,end) \ |
35 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
36 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
|
|
37 | |
|
|
38 | // this is much faster than crossfires original algorithm |
|
|
39 | // on modern cpus |
|
|
40 | inline int |
|
|
41 | isqrt (int n) |
|
|
42 | { |
|
|
43 | return (int)sqrtf ((float)n); |
|
|
44 | } |
|
|
45 | |
|
|
46 | // this is only twice as fast as naive sqrtf (dx*dy+dy*dy) |
|
|
47 | #if 0 |
|
|
48 | // and has a max. error of 6 in the range -100..+100. |
|
|
49 | #else |
|
|
50 | // and has a max. error of 9 in the range -100..+100. |
|
|
51 | #endif |
|
|
52 | inline int |
|
|
53 | idistance (int dx, int dy) |
|
|
54 | { |
|
|
55 | unsigned int dx_ = abs (dx); |
|
|
56 | unsigned int dy_ = abs (dy); |
|
|
57 | |
|
|
58 | #if 0 |
|
|
59 | return dx_ > dy_ |
|
|
60 | ? (dx_ * 61685 + dy_ * 26870) >> 16 |
|
|
61 | : (dy_ * 61685 + dx_ * 26870) >> 16; |
|
|
62 | #else |
|
|
63 | return dx + dy - min (dx, dy) * 5 / 8; |
|
|
64 | #endif |
|
|
65 | } |
|
|
66 | |
36 | |
67 | |
37 | // makes dynamically allocated objects zero-initialised |
68 | // makes dynamically allocated objects zero-initialised |
38 | struct zero_initialised |
69 | struct zero_initialised |
39 | { |
70 | { |
40 | void *operator new (size_t s, void *p) |
71 | void *operator new (size_t s, void *p) |