diff options
50 files changed, 76 insertions, 98 deletions
diff --git a/src/airport.cpp b/src/airport.cpp index 5654d4efc..2fd5c09a1 100644 --- 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 index 51afea336..828136201 100644 --- 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 index fa78b55a8..59d559877 100644 --- 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 index 870512d1e..ac6826fb1 100644 --- 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 index 7c8cb40de..6a880b93b 100644 --- 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 index d616fb4d4..c4cb6df96 100644 --- 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 index bbab273f5..c18721430 100644 --- 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 index 357a52212..6f9c35806 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -276,4 +276,19 @@ template<typename T> static inline T ROR(const T x, const uint8 n) 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 index 000000000..545e6b986 --- /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 index c05e7ffeb..242b17b95 100644 --- 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 index 632e261a6..8f1f404a7 100644 --- 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 index 7e2f7fbf9..803250040 100644 --- 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 index 23354cde1..7f33fb744 100644 --- 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 index 54a7ef932..b7a679e1f 100644 --- 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 index 03977c402..e11ae7a40 100644 --- 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 index 6a7cb51e3..f81b5e504 100644 --- 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" @@ -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 index f4047f4bc..e7e53e6a5 100644 --- 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 index 5ec7b96e0..000000000 --- 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 index 60cad92b0..33e255e7b 100644 --- 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 "direction_func.h" #include "helpers.hpp" +#include "direction_func.h" +#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 index 0b383d5e6..2f8dbda90 100644 --- 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 index cefd0be25..64b37a0a9 100644 --- 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 index 0da9b1a07..21c6b5ba6 100644 --- 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 index 8da8ba6a6..58c586813 100644 --- 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 index 8a26ad40f..326719a61 100644 --- 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 index 921544661..986ad5ead 100644 --- 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 index 3c557f673..c75565f6d 100644 --- 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 index 052c84f56..205ccee35 100644 --- 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 index 653aff2a2..3c7a0da05 100644 --- 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 index cc8bc2370..1bcd41f8c 100644 --- 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 index 11db9139e..a128cbb61 100644 --- 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 index 2887972ec..17370db5e 100644 --- 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 index fe5664152..8cf2fdeec 100644 --- 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 index 5ecb2d75c..0f5412f4c 100644 --- 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 index 4081796e4..0a730c31f 100644 --- 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 index 5854f0dc8..2cf57ea68 100644 --- 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 index bc813af85..b393f6d41 100644 --- 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 index 4a68f6713..507650552 100644 --- 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 index e2654c2af..00ceed3ee 100644 --- 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 index fef1d536d..ad22fff89 100644 --- 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 index fbbf5ea9f..0a5343df5 100644 --- 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 index b3beacb23..bdbe9b46a 100644 --- 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 index c0a136c26..ca1902b1f 100644 --- 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 index a4d106ebe..945cbfab3 100644 --- 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 index 4f13d1bd2..1e7ad67ed 100644 --- 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 index 030872385..47364b8c0 100644 --- 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 index d1749fb57..22fbcd1d2 100644 --- 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 index 2902fa7cb..1ddac5751 100644 --- 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 index e1130c3ae..8b3c4adbb 100644 --- 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 index ef2b8a77c..1b36117ea 100644 --- 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" |