author | tron |
Wed, 08 Mar 2006 06:55:33 +0000 | |
changeset 3157 | 3f35e2d9c8e3 |
parent 3154 | 6ab0cb6b7ab3 |
child 3158 | 696a6ca0bfa9 |
permissions | -rw-r--r-- |
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
1 |
/* $Id$ */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
2 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
3 |
#ifndef DIRECTION_H |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
4 |
#define DIRECTION_H |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
5 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
6 |
/* Direction as commonly used in v->direction, 8 way. */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
7 |
typedef enum Direction { |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
8 |
DIR_N = 0, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
9 |
DIR_NE = 1, /* Northeast, upper right on your monitor */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
10 |
DIR_E = 2, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
11 |
DIR_SE = 3, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
12 |
DIR_S = 4, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
13 |
DIR_SW = 5, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
14 |
DIR_W = 6, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
15 |
DIR_NW = 7, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
16 |
DIR_END, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
17 |
INVALID_DIR = 0xFF, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
18 |
} Direction; |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
19 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
20 |
static inline Direction ReverseDir(Direction d) |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
21 |
{ |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
22 |
return (Direction)(4 ^ d); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
23 |
} |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
24 |
|
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
25 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
26 |
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
27 |
typedef enum DiagDirection { |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
28 |
DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
29 |
DIAGDIR_SE = 1, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
30 |
DIAGDIR_SW = 2, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
31 |
DIAGDIR_NW = 3, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
32 |
DIAGDIR_END, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
33 |
INVALID_DIAGDIR = 0xFF, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
34 |
} DiagDirection; |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
35 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
36 |
static inline DiagDirection ReverseDiagDir(DiagDirection d) |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
37 |
{ |
3148
96d6a2fa97df
(svn r3769) Add a cast to make KUDr's C++ compiler happy
tron
parents:
3147
diff
changeset
|
38 |
return (DiagDirection)(2 ^ d); |
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
39 |
} |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
40 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
41 |
|
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
42 |
static inline DiagDirection DirToDiagDir(Direction dir) |
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
43 |
{ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
44 |
return (DiagDirection)(dir >> 1); |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
45 |
} |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
46 |
|
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
47 |
|
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
48 |
static inline Direction DiagDirToDir(DiagDirection dir) |
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
49 |
{ |
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
50 |
return (Direction)(dir * 2 + 1); |
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
51 |
} |
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
52 |
|
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
53 |
|
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
54 |
/* the 2 axis */ |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
55 |
typedef enum Axis { |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
56 |
AXIS_X = 0, |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
57 |
AXIS_Y = 1 |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
58 |
} Axis; |
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
59 |
|
3154 | 60 |
|
61 |
static inline Axis DiagDirToAxis(DiagDirection d) |
|
62 |
{ |
|
63 |
return (Axis)(d & 1); |
|
64 |
} |
|
65 |
||
3147
fc76d566a68e
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
66 |
#endif |