Codechange: use _cur_palette the same in all the drivers

It was a bit of a mixed bag. With this change, gfx.cpp is in
control who accesses _cur_palette from the video-drivers.
This commit is contained in:
Patric Stout
2021-06-17 10:34:43 +02:00
committed by Patric Stout
parent 1ed7afc0a8
commit 74186998a2
11 changed files with 98 additions and 95 deletions

View File

@@ -1201,6 +1201,30 @@ void GfxInitPalettes()
DoPaletteAnimations();
}
/**
* Copy the current palette if the palette was updated.
* Used by video-driver to get a current up-to-date version of the palette,
* to avoid two threads accessing the same piece of memory (with a good chance
* one is already updating the palette while the other is drawing based on it).
* @param local_palette The location to copy the palette to.
* @param force_copy Whether to ignore if there is an update for the palette.
* @return True iff a copy was done.
*/
bool CopyPalette(Palette &local_palette, bool force_copy)
{
if (!force_copy && _cur_palette.count_dirty == 0) return false;
local_palette = _cur_palette;
_cur_palette.count_dirty = 0;
if (force_copy) {
local_palette.first_dirty = 0;
local_palette.count_dirty = 256;
}
return true;
}
#define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
#define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)