… | |
… | |
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 | void fork_abort (const char *msg); |
|
|
39 | |
|
|
40 | // this is much faster than crossfires original algorithm |
|
|
41 | // on modern cpus |
|
|
42 | inline int |
|
|
43 | isqrt (int n) |
|
|
44 | { |
|
|
45 | return (int)sqrtf ((float)n); |
|
|
46 | } |
|
|
47 | |
|
|
48 | // this is only twice as fast as naive sqrtf (dx*dy+dy*dy) |
|
|
49 | #if 0 |
|
|
50 | // and has a max. error of 6 in the range -100..+100. |
|
|
51 | #else |
|
|
52 | // and has a max. error of 9 in the range -100..+100. |
|
|
53 | #endif |
|
|
54 | inline int |
|
|
55 | idistance (int dx, int dy) |
|
|
56 | { |
|
|
57 | unsigned int dx_ = abs (dx); |
|
|
58 | unsigned int dy_ = abs (dy); |
|
|
59 | |
|
|
60 | #if 0 |
|
|
61 | return dx_ > dy_ |
|
|
62 | ? (dx_ * 61685 + dy_ * 26870) >> 16 |
|
|
63 | : (dy_ * 61685 + dx_ * 26870) >> 16; |
|
|
64 | #else |
|
|
65 | return dx_ + dy_ - min (dx_, dy_) * 5 / 8; |
|
|
66 | #endif |
|
|
67 | } |
|
|
68 | |
|
|
69 | /* |
|
|
70 | * absdir(int): Returns a number between 1 and 8, which represent |
|
|
71 | * the "absolute" direction of a number (it actually takes care of |
|
|
72 | * "overflow" in previous calculations of a direction). |
|
|
73 | */ |
|
|
74 | inline int |
|
|
75 | absdir (int d) |
|
|
76 | { |
|
|
77 | return ((d - 1) & 7) + 1; |
|
|
78 | } |
36 | |
79 | |
37 | // makes dynamically allocated objects zero-initialised |
80 | // makes dynamically allocated objects zero-initialised |
38 | struct zero_initialised |
81 | struct zero_initialised |
39 | { |
82 | { |
40 | void *operator new (size_t s, void *p) |
83 | void *operator new (size_t s, void *p) |