Skip to content

Commit

Permalink
[Clean up] Use Meyers's singleton for CColorCycling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed May 13, 2024
1 parent fa19408 commit 66f1a50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,6 @@ extern void DeInitImageLoaders();
/// initialize the video part
extern void InitVideo();

/// deinitliaize the video part
void DeInitVideo();

/// Initializes video synchronization.
extern void SetVideoSync();

Expand Down
2 changes: 1 addition & 1 deletion src/stratagus/stratagus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void Exit(int err)
(SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1));
lua_settop(Lua, 0);
lua_close(Lua);
DeInitVideo();

DeInitImageLoaders();

delete UnitManager;
Expand Down
30 changes: 7 additions & 23 deletions src/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,22 @@ struct Clip {
class CColorCycling
{
private:
CColorCycling() : ColorCycleAll(false), cycleCount(0)
{}
CColorCycling() {}

static void CreateInstanceIfNeeded()
public:
static CColorCycling &GetInstance()
{
if (s_instance == nullptr) {
s_instance = new CColorCycling;
}
static CColorCycling s_instance;
return s_instance;
}

public:
static CColorCycling &GetInstance() { CreateInstanceIfNeeded(); return *s_instance; }

static void ReleaseInstance() { delete s_instance; s_instance = nullptr; }
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;
bool ColorCycleAll = false; /// Flag Color Cycle with all palettes
unsigned int cycleCount = 0;
};




/*----------------------------------------------------------------------------
-- Externals
----------------------------------------------------------------------------*/
Expand All @@ -157,7 +147,6 @@ extern void SdlUnlockScreen(); /// Do SDL hardware unlock
----------------------------------------------------------------------------*/

CVideo Video;
/*static*/ CColorCycling *CColorCycling::s_instance = nullptr;

char VideoForceFullScreen; /// fullscreen set from commandline

Expand Down Expand Up @@ -348,11 +337,6 @@ void InitVideo()
InitLineDraw();
}

void DeInitVideo()
{
CColorCycling::ReleaseInstance();
}

/**
** Set the video sync speed
**
Expand Down

0 comments on commit 66f1a50

Please sign in to comment.