diff --git a/src/airport.cpp b/src/airport.cpp --- a/src/airport.cpp +++ b/src/airport.cpp @@ -7,11 +7,10 @@ #include "debug.h" #include "map.h" #include "airport.h" -#include "macros.h" #include "variables.h" #include "airport_movement.h" #include "date.h" -#include "helpers.hpp" +#include "core/bitmath_func.hpp" /* Uncomment this to print out a full report of the airport-structure * You should either use diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -6,6 +6,7 @@ #define BLITTER_32BPP_BASE_HPP #include "base.hpp" +#include "../core/bitmath_func.hpp" class Blitter_32bppBase : public Blitter { public: diff --git a/src/bmp.cpp b/src/bmp.cpp --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -6,8 +6,7 @@ #include "openttd.h" #include "gfx.h" #include "bmp.h" -#include "macros.h" -#include "helpers.hpp" +#include "core/bitmath_func.hpp" void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file) { diff --git a/src/bridge_map.h b/src/bridge_map.h --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -6,7 +6,6 @@ #define BRIDGE_MAP_H #include "direction_func.h" -#include "macros.h" #include "map.h" #include "rail_type.h" #include "road_map.h" diff --git a/src/cargotype.cpp b/src/cargotype.cpp --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -4,11 +4,11 @@ #include "stdafx.h" #include "openttd.h" -#include "macros.h" #include "table/sprites.h" #include "table/strings.h" #include "newgrf_cargo.h" #include "cargotype.h" +#include "core/bitmath_func.hpp" #include "table/cargo_const.h" diff --git a/src/clear_map.h b/src/clear_map.h --- a/src/clear_map.h +++ b/src/clear_map.h @@ -5,7 +5,6 @@ #ifndef CLEAR_MAP_H #define CLEAR_MAP_H -#include "macros.h" #include "bridge_map.h" /** diff --git a/src/cmd_helper.h b/src/cmd_helper.h --- a/src/cmd_helper.h +++ b/src/cmd_helper.h @@ -4,7 +4,6 @@ #define CMD_HELPER_H #include "direction_type.h" -#include "macros.h" #include "road_type.h" diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -276,4 +276,19 @@ template static inline T ROR return (T)(x >> n | x << (sizeof(x) * 8 - n)); } +/** + * Do an operation for each set set bit in a value. + * + * This macros is used to do an operation for each set + * bit in a variable. The first variable can be reused + * in the operation due to it's the bit position counter. + * The second variable will be cleared during the usage + * + * @param i The position counter + * @param b The value which we check for set bits + */ +#define FOR_EACH_SET_BIT(i, b) \ + for (i = 0; b != 0; i++, b >>= 1) \ + if (b & 1) + #endif /* BITMATH_FUNC_HPP */ diff --git a/src/core/endian_func.hpp b/src/core/endian_func.hpp new file mode 100644 --- /dev/null +++ b/src/core/endian_func.hpp @@ -0,0 +1,22 @@ +/* $Id$ */ + +/** @file endian_func.hpp */ + +#ifndef ENDIAN_FUNC_H +#define ENDIAN_FUNC_H + +static inline uint16 ReadLE16Aligned(const void *x) +{ + return FROM_LE16(*(const uint16*)x); +} + +static inline uint16 ReadLE16Unaligned(const void *x) +{ +#ifdef OTTD_ALIGNMENT + return ((const byte*)x)[0] | ((const byte*)x)[1] << 8; +#else + return FROM_LE16(*(const uint16*)x); +#endif +} + +#endif /* ENDIAN_FUNC_H */ diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -18,6 +18,12 @@ #endif /** + * The largest value that can be entered in a variable + * @param type the type of the variable + */ +#define MAX_UVALUE(type) ((type)~(type)0) + +/** * Returns the maximum of two values. * * This function returns the greater value of two given values. diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -5,6 +5,8 @@ #ifndef OVERFLOWSAFE_TYPE_HPP #define OVERFLOWSAFE_TYPE_HPP +#include "math_func.hpp" + /** * Overflow safe template for integers, i.e. integers that will never overflow * you multiply the maximum value with 2, or add 2, or substract somethng from diff --git a/src/core/random_func.cpp b/src/core/random_func.cpp --- a/src/core/random_func.cpp +++ b/src/core/random_func.cpp @@ -3,9 +3,9 @@ /** @file random_func.cpp */ #include "../stdafx.h" -#include "../macros.h" #include "../variables.h" #include "random_func.hpp" +#include "bitmath_func.hpp" uint32 InteractiveRandom() { diff --git a/src/date.cpp b/src/date.cpp --- a/src/date.cpp +++ b/src/date.cpp @@ -6,7 +6,6 @@ #include "openttd.h" #include "date.h" #include "variables.h" -#include "macros.h" #include "vehicle.h" #include "network/network.h" #include "network/network_data.h" diff --git a/src/fileio.cpp b/src/fileio.cpp --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -7,7 +7,6 @@ #include "fileio.h" #include "functions.h" #include "string.h" -#include "macros.h" #include "variables.h" #include "debug.h" #include "fios.h" diff --git a/src/fontcache.cpp b/src/fontcache.cpp --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" -#include "macros.h" #include "debug.h" #include "table/sprites.h" #include "table/control_codes.h" diff --git a/src/gfx.cpp b/src/gfx.cpp --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" -#include "macros.h" #include "spritecache.h" #include "strings.h" #include "string.h" diff --git a/src/gfx.h b/src/gfx.h --- a/src/gfx.h +++ b/src/gfx.h @@ -36,6 +36,7 @@ #define GFX_H #include "openttd.h" +#include "core/math_func.hpp" #include "zoom.hpp" enum WindowKeyCodes { diff --git a/src/industry_map.h b/src/industry_map.h --- a/src/industry_map.h +++ b/src/industry_map.h @@ -6,7 +6,6 @@ #define INDUSTRY_MAP_H #include "industry.h" -#include "macros.h" #include "tile_map.h" diff --git a/src/macros.h b/src/macros.h deleted file mode 100644 --- a/src/macros.h +++ /dev/null @@ -1,58 +0,0 @@ -/* $Id$ */ - -/** @file macros.h */ - -#ifndef MACROS_H -#define MACROS_H - -#include "core/bitmath_func.hpp" -#include "core/math_func.hpp" - -#define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START) -#define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner])) - -/** - * Whether a sprite comes from the original graphics files or a new grf file - * (either supplied by OpenTTD or supplied by the user). - * - * @param sprite The sprite to check - * @return True if it is a new sprite, or false if it is original. - */ -#define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE) - -/** - * Do an operation for each set set bit in a value. - * - * This macros is used to do an operation for each set - * bit in a variable. The first variable can be reused - * in the operation due to it's the bit position counter. - * The second variable will be cleared during the usage - * - * @param i The position counter - * @param b The value which we check for set bits - */ -#define FOR_EACH_SET_BIT(i, b) \ - for (i = 0; b != 0; i++, b >>= 1) \ - if (b & 1) - - -static inline uint16 ReadLE16Aligned(const void* x) -{ - return FROM_LE16(*(const uint16*)x); -} - -static inline uint16 ReadLE16Unaligned(const void* x) -{ -#ifdef OTTD_ALIGNMENT - return ((const byte*)x)[0] | ((const byte*)x)[1] << 8; -#else - return FROM_LE16(*(const uint16*)x); -#endif -} - - -/** return the largest value that can be entered in a variable. - */ -#define MAX_UVALUE(type) ((type)~(type)0) - -#endif /* MACROS_H */ diff --git a/src/map.cpp b/src/map.cpp --- a/src/map.cpp +++ b/src/map.cpp @@ -6,10 +6,10 @@ #include "openttd.h" #include "debug.h" #include "functions.h" -#include "macros.h" #include "map.h" +#include "helpers.hpp" #include "direction_func.h" -#include "helpers.hpp" +#include "core/bitmath_func.hpp" #if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */ /* Why the hell is that not in all MSVC headers?? */ diff --git a/src/music_gui.cpp b/src/music_gui.cpp --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -11,7 +11,6 @@ #include "fileio.h" #include "gfx.h" #include "sound.h" -#include "macros.h" #include "variables.h" #include "music.h" #include "music/music_driver.hpp" diff --git a/src/namegen.cpp b/src/namegen.cpp --- a/src/namegen.cpp +++ b/src/namegen.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "debug.h" -#include "macros.h" #include "namegen.h" #include "table/namegen.h" #include "string.h" diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -7,7 +7,6 @@ #ifdef ENABLE_NETWORK #include "../../stdafx.h" -#include "../../macros.h" #include "../../string.h" #include "../../helpers.hpp" diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -8,8 +8,8 @@ #include "../../stdafx.h" #include "../../debug.h" -#include "../../macros.h" -#include "../../helpers.hpp" +#include "../../core/bitmath_func.hpp" +#include "../../core/math_func.hpp" #include "packet.h" #include "udp.h" diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" -#include "macros.h" #include "debug.h" #include "variables.h" #include "string.h" diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -6,7 +6,6 @@ #include "openttd.h" #include "debug.h" #include "functions.h" -#include "macros.h" #include "variables.h" #include "landscape.h" #include "table/strings.h" diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "variables.h" -#include "macros.h" #include "landscape.h" #include "oldpool.h" #include "newgrf_callbacks.h" diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -15,7 +15,6 @@ #include "string.h" #include "strings.h" #include "variables.h" -#include "macros.h" #include "table/strings.h" #include "newgrf.h" #include "newgrf_text.h" diff --git a/src/npf.cpp b/src/npf.cpp --- a/src/npf.cpp +++ b/src/npf.cpp @@ -10,7 +10,6 @@ #include "landscape.h" #include "npf.h" #include "aystar.h" -#include "macros.h" #include "pathfind.h" #include "station.h" #include "station_map.h" diff --git a/src/oldpool.h b/src/oldpool.h --- a/src/oldpool.h +++ b/src/oldpool.h @@ -5,6 +5,8 @@ #ifndef OLDPOOL_H #define OLDPOOL_H +#include "core/math_func.hpp" + /* The function that is called after a new block is added start_item is the first item of the new made block */ typedef void OldMemoryPoolNewBlock(uint start_item); diff --git a/src/openttd.h b/src/openttd.h --- a/src/openttd.h +++ b/src/openttd.h @@ -8,7 +8,6 @@ #define VARDEF extern #endif -#include "macros.h" #include "helpers.hpp" struct Oblong { diff --git a/src/order.h b/src/order.h --- a/src/order.h +++ b/src/order.h @@ -5,8 +5,8 @@ #ifndef ORDER_H #define ORDER_H -#include "macros.h" #include "oldpool.h" +#include "core/bitmath_func.hpp" enum { INVALID_VEH_ORDER_ID = 0xFF, diff --git a/src/rail.h b/src/rail.h --- a/src/rail.h +++ b/src/rail.h @@ -8,6 +8,7 @@ #include "gfx.h" #include "rail_type.h" #include "track_type.h" +#include "core/bitmath_func.hpp" #include "variables.h" /** This struct contains all the info that is needed to draw and construct tracks. diff --git a/src/road.cpp b/src/road.cpp --- a/src/road.cpp +++ b/src/road.cpp @@ -7,7 +7,6 @@ #include "road_map.h" #include "road_internal.h" #include "water_map.h" -#include "macros.h" bool IsPossibleCrossing(const TileIndex tile, Axis ax) { diff --git a/src/road_func.h b/src/road_func.h --- a/src/road_func.h +++ b/src/road_func.h @@ -5,6 +5,7 @@ #ifndef ROAD_FUNC_H #define ROAD_FUNC_H +#include "core/bitmath_func.hpp" #include "road_type.h" /** diff --git a/src/road_map.h b/src/road_map.h --- a/src/road_map.h +++ b/src/road_map.h @@ -5,7 +5,6 @@ #ifndef ROAD_MAP_H #define ROAD_MAP_H -#include "macros.h" #include "track_func.h" #include "rail_type.h" #include "road_func.h" diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -23,7 +23,6 @@ #include "openttd.h" #include "currency.h" #include "functions.h" -#include "macros.h" #include "screenshot.h" #include "sound.h" #include "string.h" diff --git a/src/slope_func.h b/src/slope_func.h --- a/src/slope_func.h +++ b/src/slope_func.h @@ -5,6 +5,7 @@ #ifndef SLOPE_FUNC_H #define SLOPE_FUNC_H +#include "core/math_func.hpp" #include "slope_type.h" #include "direction_type.h" diff --git a/src/sprite.h b/src/sprite.h --- a/src/sprite.h +++ b/src/sprite.h @@ -5,6 +5,17 @@ #ifndef SPRITE_H #define SPRITE_H +#define GENERAL_SPRITE_COLOR(color) ((color) + PALETTE_RECOLOR_START) +#define PLAYER_SPRITE_COLOR(owner) (GENERAL_SPRITE_COLOR(_player_colors[owner])) + +/** + * Whether a sprite comes from the original graphics files or a new grf file + * (either supplied by OpenTTD or supplied by the user). + * + * @param sprite The sprite to check + * @return True if it is a new sprite, or false if it is original. + */ +#define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE) /* The following describes bunch of sprites to be drawn together in a single 3D * bounding box. Used especially for various multi-sprite buildings (like diff --git a/src/spritecache.cpp b/src/spritecache.cpp --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -8,7 +8,6 @@ #include "string.h" #include "debug.h" #include "functions.h" -#include "macros.h" #include "spritecache.h" #include "table/sprites.h" #include "fileio.h" diff --git a/src/string.cpp b/src/string.cpp --- a/src/string.cpp +++ b/src/string.cpp @@ -6,7 +6,6 @@ #include "openttd.h" #include "functions.h" #include "string.h" -#include "macros.h" #include "table/control_codes.h" #include "helpers.hpp" #include "debug.h" diff --git a/src/string.h b/src/string.h --- a/src/string.h +++ b/src/string.h @@ -5,7 +5,7 @@ #ifndef STRING_H #define STRING_H -#include "macros.h" +#include "core/bitmath_func.hpp" /** * usage ttd_strlcpy(dst, src, lengthof(dst)); diff --git a/src/texteff.cpp b/src/texteff.cpp --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" -#include "macros.h" #include "strings.h" #include "gfx.h" #include "landscape.h" diff --git a/src/tile_map.cpp b/src/tile_map.cpp --- a/src/tile_map.cpp +++ b/src/tile_map.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "tile_map.h" +#include "core/math_func.hpp" Slope GetTileSlope(TileIndex tile, uint *h) { diff --git a/src/tile_map.h b/src/tile_map.h --- a/src/tile_map.h +++ b/src/tile_map.h @@ -8,6 +8,7 @@ #include "tile_type.h" #include "slope_type.h" #include "map.h" +#include "core/bitmath_func.hpp" /** * Returns the height of a tile diff --git a/src/track_func.h b/src/track_func.h --- a/src/track_func.h +++ b/src/track_func.h @@ -5,6 +5,7 @@ #ifndef TRACK_FUNC_H #define TRACK_FUNC_H +#include "core/bitmath_func.hpp" #include "track_type.h" #include "direction_type.h" #include "slope_func.h" diff --git a/src/tree_map.h b/src/tree_map.h --- a/src/tree_map.h +++ b/src/tree_map.h @@ -5,8 +5,6 @@ #ifndef TREE_MAP_H #define TREE_MAP_H -#include "macros.h" - /** * List of tree types along all landscape types. * diff --git a/src/tunnel_map.h b/src/tunnel_map.h --- a/src/tunnel_map.h +++ b/src/tunnel_map.h @@ -6,7 +6,6 @@ #define TUNNEL_MAP_H #include "direction_func.h" -#include "macros.h" #include "map.h" #include "rail_type.h" #include "road_type.h" diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -8,7 +8,6 @@ #include "../debug.h" #include "../functions.h" #include "../gfx.h" -#include "../macros.h" #include "../sdl.h" #include "../variables.h" #include "../blitter/factory.hpp" diff --git a/src/window_gui.h b/src/window_gui.h --- a/src/window_gui.h +++ b/src/window_gui.h @@ -5,7 +5,6 @@ #ifndef WINDOW_GUI_H #define WINDOW_GUI_H -#include "macros.h" #include "string.h" #include "order.h" #include "rail_type.h"