1 /* $Id$ */ |
|
2 |
|
3 /** @file macros.h */ |
|
4 |
|
5 #ifndef MACROS_H |
|
6 #define MACROS_H |
|
7 |
|
8 #include "core/bitmath_func.hpp" |
|
9 #include "core/math_func.hpp" |
|
10 |
|
11 #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START) |
|
12 #define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner])) |
|
13 |
|
14 /** |
|
15 * Whether a sprite comes from the original graphics files or a new grf file |
|
16 * (either supplied by OpenTTD or supplied by the user). |
|
17 * |
|
18 * @param sprite The sprite to check |
|
19 * @return True if it is a new sprite, or false if it is original. |
|
20 */ |
|
21 #define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE) |
|
22 |
|
23 /** |
|
24 * Do an operation for each set set bit in a value. |
|
25 * |
|
26 * This macros is used to do an operation for each set |
|
27 * bit in a variable. The first variable can be reused |
|
28 * in the operation due to it's the bit position counter. |
|
29 * The second variable will be cleared during the usage |
|
30 * |
|
31 * @param i The position counter |
|
32 * @param b The value which we check for set bits |
|
33 */ |
|
34 #define FOR_EACH_SET_BIT(i, b) \ |
|
35 for (i = 0; b != 0; i++, b >>= 1) \ |
|
36 if (b & 1) |
|
37 |
|
38 |
|
39 static inline uint16 ReadLE16Aligned(const void* x) |
|
40 { |
|
41 return FROM_LE16(*(const uint16*)x); |
|
42 } |
|
43 |
|
44 static inline uint16 ReadLE16Unaligned(const void* x) |
|
45 { |
|
46 #ifdef OTTD_ALIGNMENT |
|
47 return ((const byte*)x)[0] | ((const byte*)x)[1] << 8; |
|
48 #else |
|
49 return FROM_LE16(*(const uint16*)x); |
|
50 #endif |
|
51 } |
|
52 |
|
53 |
|
54 /** return the largest value that can be entered in a variable. |
|
55 */ |
|
56 #define MAX_UVALUE(type) ((type)~(type)0) |
|
57 |
|
58 #endif /* MACROS_H */ |
|