1
0
Fork 0

Codechange: use std::ranges::equal over memcmp

pull/14224/head
Rubidium 2025-05-06 19:44:42 +02:00 committed by rubidium42
parent 89deb3876f
commit 0ffdc86a2c
3 changed files with 12 additions and 5 deletions

View File

@ -183,6 +183,8 @@ union ColourRGBA {
* @param data The colour in the correct packed format.
*/
constexpr ColourRGBA(uint data = 0) : data(data) { }
bool operator==(const ColourRGBA &other) const { return this->data == other.data; };
};
/** Packed colour union to access the alpha, red, green, and blue channels from a 32 bit number for big-endian systems. */
@ -206,6 +208,8 @@ union ColourARGB {
* @param data The colour in the correct packed format.
*/
constexpr ColourARGB(uint data = 0) : data(data) { }
bool operator==(const ColourARGB &other) const { return this->data == other.data; };
};
/** Packed colour union to access the alpha, red, green, and blue channels from a 32 bit number for little-endian systems. */
@ -229,6 +233,8 @@ union ColourBGRA {
* @param data The colour in the correct packed format.
*/
constexpr ColourBGRA(uint data = 0) : data(data) { }
bool operator==(const ColourBGRA &other) const { return this->data == other.data; };
};
#if defined(__EMSCRIPTEN__)

View File

@ -198,7 +198,7 @@ static bool ReadTrackChunk(FileHandle &file, MidiFile &target)
if (fread(buf, sizeof(magic), 1, file) != 1) {
return false;
}
if (memcmp(magic, buf, sizeof(magic)) != 0) {
if (!std::ranges::equal(magic, buf)) {
return false;
}

View File

@ -253,7 +253,6 @@ void DoPaletteAnimations()
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const Colour *s;
const ExtraPaletteValues *ev = &_extra_palette_values;
Colour old_val[PALETTE_ANIM_SIZE];
const uint old_tc = palette_animation_counter;
uint j;
@ -261,10 +260,12 @@ void DoPaletteAnimations()
palette_animation_counter = 0;
}
Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette
std::span<Colour> current_palette{&_cur_palette.palette[PALETTE_ANIM_START], PALETTE_ANIM_SIZE};
/* Makes a copy of the current animation palette in old_val,
* so the work on the current palette could be compared, see if there has been any changes */
memcpy(old_val, palette_pos, sizeof(old_val));
std::array<Colour, PALETTE_ANIM_SIZE> original_palette;
std::ranges::copy(current_palette, original_palette.begin());
auto palette_pos = current_palette.begin(); // Points to where animations are taking place on the palette
/* Fizzy Drink bubbles animation */
s = ev->fizzy_drink;
@ -344,7 +345,7 @@ void DoPaletteAnimations()
if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PaletteAnimation::None) {
palette_animation_counter = old_tc;
} else if (_cur_palette.count_dirty == 0 && memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0) {
} else if (_cur_palette.count_dirty == 0 && !std::ranges::equal(current_palette, original_palette)) {
/* Did we changed anything on the palette? Seems so. Mark it as dirty */
_cur_palette.first_dirty = PALETTE_ANIM_START;
_cur_palette.count_dirty = PALETTE_ANIM_SIZE;