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

Comparing deliantra/server/include/util.h (file contents):
Revision 1.27 by root, Mon Jan 15 00:40:49 2007 UTC vs.
Revision 1.28 by root, Mon Jan 15 01:25:41 2007 UTC

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
40inline int
41isqrt (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
52inline int
53idistance (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
38struct zero_initialised 69struct zero_initialised
39{ 70{
40 void *operator new (size_t s, void *p) 71 void *operator new (size_t s, void *p)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines