Restore palette (due to ColorCycling) when game ends.
This commit is contained in:
parent
c6a2fc0a3f
commit
2fcae8f279
3 changed files with 44 additions and 2 deletions
|
@ -951,6 +951,7 @@ void CleanGame()
|
|||
Map.Clean();
|
||||
CleanReplayLog();
|
||||
FreePathfinder();
|
||||
RestoreColorCyclingSurface();
|
||||
CursorBuilding = NULL;
|
||||
UnitUnderCursor = NULL;
|
||||
}
|
||||
|
|
|
@ -486,6 +486,7 @@ extern void VideoPaletteListRemove(SDL_Surface *surface);
|
|||
extern void ClearAllColorCyclingRange();
|
||||
extern void AddColorCyclingRange(unsigned int begin, unsigned int end);
|
||||
extern void SetColorCycleAll(bool value);
|
||||
extern void RestoreColorCyclingSurface();
|
||||
|
||||
/// Does ColorCycling..
|
||||
extern void ColorCycle();
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
class CColorCycling
|
||||
{
|
||||
private:
|
||||
CColorCycling() : ColorCycleAll(false)
|
||||
CColorCycling() : ColorCycleAll(false), cycleCount(0)
|
||||
{}
|
||||
|
||||
static void CreateInstanceIfNeeded() {
|
||||
|
@ -141,7 +141,7 @@ public:
|
|||
std::vector<SDL_Surface *> PaletteList; /// List of all used palettes.
|
||||
std::vector<ColorIndexRange> ColorIndexRanges; /// List of range of color index for cycling.
|
||||
bool ColorCycleAll; /// Flag Color Cycle with all palettes
|
||||
|
||||
unsigned int cycleCount;
|
||||
private:
|
||||
static CColorCycling *s_instance;
|
||||
};
|
||||
|
@ -405,6 +405,28 @@ static void ColorCycleSurface(SDL_Surface &surface)
|
|||
SDL_SetPalette(&surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
}
|
||||
|
||||
/**
|
||||
** Undo Color Cycle for particular surface
|
||||
** @note function may be optimized.
|
||||
*/
|
||||
static void ColorCycleSurface_Reverse(SDL_Surface &surface, unsigned int count)
|
||||
{
|
||||
for (unsigned int i = 0; i != count; ++i) {
|
||||
SDL_Color *palcolors = surface.format->palette->colors;
|
||||
SDL_Color colors[256];
|
||||
CColorCycling &colorCycling = CColorCycling::GetInstance();
|
||||
|
||||
memcpy(colors, palcolors, sizeof(colors));
|
||||
for (std::vector<ColorIndexRange>::const_iterator it = colorCycling.ColorIndexRanges.begin(); it != colorCycling.ColorIndexRanges.end(); ++it) {
|
||||
const ColorIndexRange &range = *it;
|
||||
|
||||
memcpy(colors + range.begin + 1, palcolors + range.begin, (range.end - range.begin) * sizeof(SDL_Color));
|
||||
colors[range.begin] = palcolors[range.end];
|
||||
}
|
||||
SDL_SetPalette(&surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Color cycle.
|
||||
*/
|
||||
|
@ -418,16 +440,34 @@ void ColorCycle()
|
|||
}
|
||||
CColorCycling &colorCycling = CColorCycling::GetInstance();
|
||||
if (colorCycling.ColorCycleAll) {
|
||||
++colorCycling.cycleCount;
|
||||
for (std::vector<SDL_Surface *>::iterator it = colorCycling.PaletteList.begin(); it != colorCycling.PaletteList.end(); ++it) {
|
||||
SDL_Surface *surface = (*it);
|
||||
|
||||
ColorCycleSurface(*surface);
|
||||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
++colorCycling.cycleCount;
|
||||
ColorCycleSurface(*Map.TileGraphic->Surface);
|
||||
}
|
||||
}
|
||||
|
||||
void RestoreColorCyclingSurface()
|
||||
{
|
||||
CColorCycling &colorCycling = CColorCycling::GetInstance();
|
||||
if (colorCycling.ColorCycleAll) {
|
||||
for (std::vector<SDL_Surface *>::iterator it = colorCycling.PaletteList.begin(); it != colorCycling.PaletteList.end(); ++it) {
|
||||
SDL_Surface *surface = (*it);
|
||||
|
||||
ColorCycleSurface_Reverse(*surface, colorCycling.cycleCount);
|
||||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
ColorCycleSurface_Reverse(*Map.TileGraphic->Surface, colorCycling.cycleCount);
|
||||
}
|
||||
colorCycling.cycleCount = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//@}
|
||||
|
|
Loading…
Reference in a new issue