src/macros.h
branchcpp_gui
changeset 6308 646711c5feaa
parent 6285 187e3ef04cc9
equal deleted inserted replaced
6307:f40e88cff863 6308:646711c5feaa
    80 	return x ^= (T)1 << y;
    80 	return x ^= (T)1 << y;
    81 }
    81 }
    82 
    82 
    83 
    83 
    84 /* checking more bits. Maybe unneccessary, but easy to use */
    84 /* checking more bits. Maybe unneccessary, but easy to use */
    85 #define HASBITS(x,y) ((x) & (y))
    85 #define HASBITS(x, y) ((x) & (y))
    86 #define SETBITS(x,y) ((x) |= (y))
    86 #define SETBITS(x, y) ((x) |= (y))
    87 #define CLRBITS(x,y) ((x) &= ~(y))
    87 #define CLRBITS(x, y) ((x) &= ~(y))
    88 
    88 
    89 #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)
    89 #define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START)
    90 #define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner]))
    90 #define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner]))
    91 
    91 
    92 extern const byte _ffb_64[128];
    92 extern const byte _ffb_64[128];
    96  */
    96  */
    97 #define FIND_FIRST_BIT(x) _ffb_64[(x)]
    97 #define FIND_FIRST_BIT(x) _ffb_64[(x)]
    98 /* Returns x with the first bit that is not zero, counted from the left, set
    98 /* Returns x with the first bit that is not zero, counted from the left, set
    99  * to zero. So, 10110100 returns 10110000, 00000001 returns 00000000, etc.
    99  * to zero. So, 10110100 returns 10110000, 00000001 returns 00000000, etc.
   100  */
   100  */
   101 #define KILL_FIRST_BIT(x) _ffb_64[(x)+64]
   101 #define KILL_FIRST_BIT(x) _ffb_64[(x) + 64]
   102 
   102 
   103 static inline int FindFirstBit2x64(int value)
   103 static inline int FindFirstBit2x64(int value)
   104 {
   104 {
   105 /*
   105 /*
   106 	int i = 0;
   106 	int i = 0;
   131 
   131 
   132 /** returns true if value a has only one bit set to 1 */
   132 /** returns true if value a has only one bit set to 1 */
   133 #define HAS_SINGLE_BIT(a) ( ((a) & ((a) - 1)) == 0)
   133 #define HAS_SINGLE_BIT(a) ( ((a) & ((a) - 1)) == 0)
   134 
   134 
   135 /* [min,max), strictly less than */
   135 /* [min,max), strictly less than */
   136 #define IS_BYTE_INSIDE(a,min,max) ((byte)((a)-(min)) < (byte)((max)-(min)))
   136 #define IS_BYTE_INSIDE(a, min, max) ((byte)((a) - (min)) < (byte)((max) - (min)))
   137 #define IS_INT_INSIDE(a,min,max) ((uint)((a)-(min)) < (uint)((max)-(min)))
   137 #define IS_INT_INSIDE(a, min, max) ((uint)((a) - (min)) < (uint)((max) - (min)))
   138 
   138 
   139 
   139 
   140 #define CHANCE16(a,b) ((uint16)Random() <= (uint16)((65536 * (a)) / (b)))
   140 #define CHANCE16(a, b) ((uint16)Random() <= (uint16)((65536 * (a)) / (b)))
   141 #define CHANCE16R(a,b,r) ((uint16)(r=Random()) <= (uint16)((65536 * (a)) / (b)))
   141 #define CHANCE16R(a, b, r) ((uint16)(r = Random()) <= (uint16)((65536 * (a)) / (b)))
   142 #define CHANCE16I(a,b,v) ((uint16)(v) <= (uint16)((65536 * (a)) / (b)))
   142 #define CHANCE16I(a, b, v) ((uint16)(v) <= (uint16)((65536 * (a)) / (b)))
   143 
   143 
   144 
   144 
   145 #define for_each_bit(_i, _b)            \
   145 #define for_each_bit(_i, _b)            \
   146 	for (_i = 0; _b != 0; _i++, _b >>= 1) \
   146 	for (_i = 0; _b != 0; _i++, _b >>= 1) \
   147 		if (_b & 1)
   147 		if (_b & 1)