Codechange: Use std::endian instead of TTD_ENDIAN where trivial. (#12778)

This commit is contained in:
Peter Nelson 2024-06-15 10:24:17 +01:00 committed by GitHub
parent f9f07e9001
commit b68172c225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 25 deletions

View File

@ -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
if constexpr (std::endian::native == std::endian::little) {
png_set_bgr(png_ptr);
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
#else
} else {
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
}
}
/* use by default 64k temp memory */

View File

@ -137,15 +137,15 @@ static bool SetBankSource(MixerChannel *mc, const SoundEntry *sound)
}
}
#if TTD_ENDIAN == TTD_BIG_ENDIAN
if constexpr (std::endian::native == std::endian::big) {
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++) {
size_t num_samples = sound->file_size / 2;
int16_t *samples = reinterpret_cast<int16_t *>(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);

View File

@ -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<std::string_view> SoundDriver_Cocoa::Start(const StringList &parm)
requestedDesc.mBitsPerChannel = 16;
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
#if TTD_ENDIAN == TTD_BIG_ENDIAN
if constexpr (std::endian::native == std::endian::big) {
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
}
requestedDesc.mFramesPerPacket = 1;
requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;

View File

@ -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"