mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::endian instead of TTD_ENDIAN defines.
parent
b70438b76a
commit
fb6781015a
|
@ -5,7 +5,6 @@ add_files(
|
||||||
backup_type.hpp
|
backup_type.hpp
|
||||||
bitmath_func.hpp
|
bitmath_func.hpp
|
||||||
endian_func.hpp
|
endian_func.hpp
|
||||||
endian_type.hpp
|
|
||||||
enum_type.hpp
|
enum_type.hpp
|
||||||
format.hpp
|
format.hpp
|
||||||
geometry_func.cpp
|
geometry_func.cpp
|
||||||
|
|
|
@ -10,32 +10,54 @@
|
||||||
#ifndef ENDIAN_FUNC_HPP
|
#ifndef ENDIAN_FUNC_HPP
|
||||||
#define ENDIAN_FUNC_HPP
|
#define ENDIAN_FUNC_HPP
|
||||||
|
|
||||||
#include "endian_type.hpp"
|
|
||||||
#include "bitmath_func.hpp"
|
#include "bitmath_func.hpp"
|
||||||
|
|
||||||
/* Setup alignment and conversion macros */
|
static constexpr uint16_t FROM_BE16(uint16_t x)
|
||||||
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
{
|
||||||
# define FROM_BE16(x) (x)
|
if constexpr (std::endian::native == std::endian::big) return x;
|
||||||
# define FROM_BE32(x) (x)
|
return std::byteswap(x);
|
||||||
# define TO_BE16(x) (x)
|
}
|
||||||
# define TO_BE32(x) (x)
|
|
||||||
# define TO_BE32X(x) (x)
|
static constexpr uint32_t FROM_BE32(uint32_t x)
|
||||||
# define FROM_LE16(x) std::byteswap(x)
|
{
|
||||||
# define FROM_LE32(x) std::byteswap(x)
|
if constexpr (std::endian::native == std::endian::big) return x;
|
||||||
# define TO_LE16(x) std::byteswap(x)
|
return std::byteswap(x);
|
||||||
# define TO_LE32(x) std::byteswap(x)
|
}
|
||||||
# define TO_LE32X(x) std::byteswap(x)
|
|
||||||
#else
|
static constexpr uint16_t TO_BE16(uint16_t x)
|
||||||
# define FROM_BE16(x) std::byteswap(x)
|
{
|
||||||
# define FROM_BE32(x) std::byteswap(x)
|
if constexpr (std::endian::native == std::endian::big) return x;
|
||||||
# define TO_BE16(x) std::byteswap(x)
|
return std::byteswap(x);
|
||||||
# define TO_BE32(x) std::byteswap(x)
|
}
|
||||||
# define TO_BE32X(x) std::byteswap(x)
|
|
||||||
# define FROM_LE16(x) (x)
|
static constexpr uint32_t TO_BE32(uint32_t x)
|
||||||
# define FROM_LE32(x) (x)
|
{
|
||||||
# define TO_LE16(x) (x)
|
if constexpr (std::endian::native == std::endian::big) return x;
|
||||||
# define TO_LE32(x) (x)
|
return std::byteswap(x);
|
||||||
# define TO_LE32X(x) (x)
|
}
|
||||||
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
|
||||||
|
static constexpr uint16_t FROM_LE16(uint16_t x)
|
||||||
|
{
|
||||||
|
if constexpr (std::endian::native == std::endian::little) return x;
|
||||||
|
return std::byteswap(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr uint32_t FROM_LE32(uint32_t x)
|
||||||
|
{
|
||||||
|
if constexpr (std::endian::native == std::endian::little) return x;
|
||||||
|
return std::byteswap(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr uint16_t TO_LE16(uint16_t x)
|
||||||
|
{
|
||||||
|
if constexpr (std::endian::native == std::endian::little) return x;
|
||||||
|
return std::byteswap(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr uint32_t TO_LE32(uint32_t x)
|
||||||
|
{
|
||||||
|
if constexpr (std::endian::native == std::endian::little) return x;
|
||||||
|
return std::byteswap(x);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ENDIAN_FUNC_HPP */
|
#endif /* ENDIAN_FUNC_HPP */
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of OpenTTD.
|
|
||||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
||||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @file endian_type.hpp Definition of various endian-dependant macros. */
|
|
||||||
|
|
||||||
#ifndef ENDIAN_TYPE_HPP
|
|
||||||
#define ENDIAN_TYPE_HPP
|
|
||||||
|
|
||||||
/** Little endian builds use this for TTD_ENDIAN. */
|
|
||||||
#define TTD_LITTLE_ENDIAN 0
|
|
||||||
/** Big endian builds use this for TTD_ENDIAN. */
|
|
||||||
#define TTD_BIG_ENDIAN 1
|
|
||||||
|
|
||||||
#if !defined(TTD_ENDIAN)
|
|
||||||
# error "TTD_ENDIAN is not defined; please set it to either TTD_LITTLE_ENDIAN or TTD_BIG_ENDIAN"
|
|
||||||
#endif /* !TTD_ENDIAN */
|
|
||||||
|
|
||||||
#endif /* ENDIAN_TYPE_HPP */
|
|
|
@ -2697,10 +2697,10 @@ struct SaveLoadFormat {
|
||||||
uint8_t max_compression; ///< the maximum compression level of this format
|
uint8_t max_compression; ///< the maximum compression level of this format
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t SAVEGAME_TAG_LZO = TO_BE32X('OTTD');
|
static const uint32_t SAVEGAME_TAG_LZO = TO_BE32('OTTD');
|
||||||
static const uint32_t SAVEGAME_TAG_NONE = TO_BE32X('OTTN');
|
static const uint32_t SAVEGAME_TAG_NONE = TO_BE32('OTTN');
|
||||||
static const uint32_t SAVEGAME_TAG_ZLIB = TO_BE32X('OTTZ');
|
static const uint32_t SAVEGAME_TAG_ZLIB = TO_BE32('OTTZ');
|
||||||
static const uint32_t SAVEGAME_TAG_LZMA = TO_BE32X('OTTX');
|
static const uint32_t SAVEGAME_TAG_LZMA = TO_BE32('OTTX');
|
||||||
|
|
||||||
/** The different saveload formats known/understood by OpenTTD. */
|
/** The different saveload formats known/understood by OpenTTD. */
|
||||||
static const SaveLoadFormat _saveload_formats[] = {
|
static const SaveLoadFormat _saveload_formats[] = {
|
||||||
|
|
|
@ -256,7 +256,7 @@ static const LegendAndColour * const _legend_table[] = {
|
||||||
_legend_land_owners,
|
_legend_land_owners,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MKCOLOUR(x) TO_LE32X(x)
|
#define MKCOLOUR(x) TO_LE32(x)
|
||||||
|
|
||||||
#define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
|
#define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
|
||||||
#define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
|
#define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
/** @file palettes.h The colour translation of the GRF palettes. */
|
/** @file palettes.h The colour translation of the GRF palettes. */
|
||||||
|
|
||||||
#include "../core/endian_type.hpp"
|
|
||||||
|
|
||||||
#define M(r, g, b) Colour(r, g, b)
|
#define M(r, g, b) Colour(r, g, b)
|
||||||
|
|
||||||
/** Colour palette (DOS) */
|
/** Colour palette (DOS) */
|
||||||
|
|
Loading…
Reference in New Issue