src/macros.h
changeset 7833 ba402b153b79
parent 7832 60035eb28f08
child 7837 99e21b117ae2
equal deleted inserted replaced
7832:60035eb28f08 7833:ba402b153b79
   352  * @param sprite The sprite to check
   352  * @param sprite The sprite to check
   353  * @return True if it is a new sprite, or false if it is original.
   353  * @return True if it is a new sprite, or false if it is original.
   354  */
   354  */
   355 #define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE)
   355 #define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE)
   356 
   356 
   357 extern const byte _ffb_64[128];
   357 extern const byte _ffb_64[64];
   358 
   358 
   359 /**
   359 /**
   360  * Returns the first occure of a bit in a 6-bit value (from right).
   360  * Returns the first occure of a bit in a 6-bit value (from right).
   361  *
   361  *
   362  * Returns the position of the first bit that is not zero, counted from the
   362  * Returns the position of the first bit that is not zero, counted from the
   365  *
   365  *
   366  * @param x The 6-bit value to check the first zero-bit
   366  * @param x The 6-bit value to check the first zero-bit
   367  * @return The first position of a bit started from the LSB or 0 if x is 0.
   367  * @return The first position of a bit started from the LSB or 0 if x is 0.
   368  */
   368  */
   369 #define FIND_FIRST_BIT(x) _ffb_64[(x)]
   369 #define FIND_FIRST_BIT(x) _ffb_64[(x)]
   370 
       
   371 /**
       
   372  * Returns a value with the first occured of a bit set to zero.
       
   373  *
       
   374  * Returns x with the first bit from LSB that is not zero set
       
   375  * to zero. So, 110100 returns 110000, 000001 returns 000000, etc.
       
   376  *
       
   377  * @param x The value to returned a new value
       
   378  * @return The value which the first bit is set to zero
       
   379  */
       
   380 #define KILL_FIRST_BIT(x) _ffb_64[(x) + 64]
       
   381 
   370 
   382 /**
   371 /**
   383  * Finds the position of the first bit in an integer.
   372  * Finds the position of the first bit in an integer.
   384  *
   373  *
   385  * This function returns the position of the first bit set in the
   374  * This function returns the position of the first bit set in the
   414 
   403 
   415 /**
   404 /**
   416  * Clear the first bit in an integer.
   405  * Clear the first bit in an integer.
   417  *
   406  *
   418  * This function returns a value where the first bit (from LSB)
   407  * This function returns a value where the first bit (from LSB)
   419  * is cleared. This function checks only the bits of 0x3F3F!
   408  * is cleared.
       
   409  * So, 110100 returns 110000, 000001 returns 000000, etc.
   420  *
   410  *
   421  * @param value The value to clear the first bit
   411  * @param value The value to clear the first bit
   422  * @return The new value with the first bit cleared
   412  * @return The new value with the first bit cleared
   423  */
   413  */
   424 static inline uint KillFirstBit2x64(uint value)
   414 template<typename T> static inline T KillFirstBit(T value)
   425 {
   415 {
   426 	return value &= (uint)(value - 1) | 0x3FFFC0C0;
   416 	return value &= (T)(value - 1);
   427 }
   417 }
   428 
   418 
   429 /**
   419 /**
   430  * Counts the number of set bits in a variable.
   420  * Counts the number of set bits in a variable.
   431  *
   421  *