diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 0f54a89cae..90d5c82154 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -71,7 +71,7 @@ struct ScreenshotFormat { ScreenshotHandlerProc *proc; ///< Function for writing the screenshot. }; -#define MKCOLOUR(x) TO_LE32X(x) +#define MKCOLOUR(x) TO_LE32(x) /************************************************* **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) @@ -360,12 +360,12 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user sig_bit.gray = 8; png_set_sBIT(png_ptr, info_ptr, &sig_bit); -#if TTD_ENDIAN == TTD_LITTLE_ENDIAN - png_set_bgr(png_ptr); - png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); -#else - png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); -#endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */ + if constexpr (std::endian::native == std::endian::little) { + png_set_bgr(png_ptr); + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); + } else { + png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); + } } /* use by default 64k temp memory */ diff --git a/src/sound.cpp b/src/sound.cpp index c4ab75df6c..2e51d31b26 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -137,15 +137,15 @@ static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound) } } -#if TTD_ENDIAN == TTD_BIG_ENDIAN - if (sound->bits_per_sample == 16) { - uint num_samples = sound->file_size / 2; - int16_t *samples = (int16_t *)mem; - for (uint i = 0; i < num_samples; i++) { - samples[i] = BSWAP16(samples[i]); + if constexpr (std::endian::native == std::endian::big) { + if (sound->bits_per_sample == 16) { + size_t num_samples = sound->file_size / 2; + int16_t *samples = reinterpret_cast(mem); + for (size_t i = 0; i < num_samples; i++) { + samples[i] = BSWAP16(samples[i]); + } } } -#endif assert(sound->bits_per_sample == 8 || sound->bits_per_sample == 16); assert(sound->channels == 1); diff --git a/src/sound/cocoa_s.cpp b/src/sound/cocoa_s.cpp index 6c4348acdb..54198b0b5e 100644 --- a/src/sound/cocoa_s.cpp +++ b/src/sound/cocoa_s.cpp @@ -20,7 +20,6 @@ #include "../debug.h" #include "../driver.h" #include "../mixer.h" -#include "../core/endian_type.hpp" #include "cocoa_s.h" #define Rect OTTDRect @@ -58,9 +57,9 @@ std::optional SoundDriver_Cocoa::Start(const StringList &parm) requestedDesc.mBitsPerChannel = 16; requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; -#if TTD_ENDIAN == TTD_BIG_ENDIAN - requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; -#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */ + if constexpr (std::endian::native == std::endian::big) { + requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; + } requestedDesc.mFramesPerPacket = 1; requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8; diff --git a/src/survey.cpp b/src/survey.cpp index 0b1d62affa..123c82563e 100644 --- a/src/survey.cpp +++ b/src/survey.cpp @@ -219,13 +219,8 @@ void SurveyOpenTTD(nlohmann::json &survey) 32 #endif ; - survey["endian"] = -#if (TTD_ENDIAN == TTD_LITTLE_ENDIAN) - "little" -#else - "big" -#endif - ; + if constexpr (std::endian::native == std::endian::little) survey["endian"] = "little"; + if constexpr (std::endian::native == std::endian::big) survey["endian"] = "big"; survey["dedicated_build"] = #ifdef DEDICATED "yes"