From e5095c1509c5c465056f4806760a7e9d8cc734fc Mon Sep 17 00:00:00 2001 From: alyokhin Date: Sat, 2 Oct 2021 19:21:18 +0300 Subject: [PATCH] Legacy fog gtraphic moved from CMap to CFogOfWar --- src/include/fow.h | 5 ++++- src/include/map.h | 1 - src/map/fow.cpp | 39 ++++++++++++++++++++++++--------------- src/map/map_fog.cpp | 4 ---- src/map/script_map.cpp | 5 +---- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/include/fow.h b/src/include/fow.h index 2cd4ab2e6..ea250c4af 100644 --- a/src/include/fow.h +++ b/src/include/fow.h @@ -56,7 +56,9 @@ public: enum VisionType { cUnseen = 0, cExplored = 0b001, cVisible = 0b010 }; enum States { cFirstEntry = 0, cGenerateFog, cGenerateTexture, cBlurTexture, cReady }; enum UpscaleTypes { cSimple = 0, cBilinear }; - + + static void SetLegacyFogGraphic(const std::string &fogGraphicFile); + void Init(); void Clean(const bool isHardClean = false); bool SetType(const FogOfWarTypes fowType); @@ -140,6 +142,7 @@ private: /// ThisPlayer and his allies in normal games /// Any set of players for observers and in the replays + static CGraphic *LegacyFogGraphic; /// graphic for legacy fog of war SDL_Surface *LegacyFogFullShroud {nullptr}; /** diff --git a/src/include/map.h b/src/include/map.h index b4cbcb12b..a8507a0d8 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -270,7 +270,6 @@ public: CTileset *Tileset; /// tileset data std::string TileModelsFileName; /// lua filename that loads all tilemodels CGraphic *TileGraphic; /// graphic for all the tiles - static CGraphic *LegacyFogGraphic; /// graphic for legacy fog of war bool isMapInitialized { false }; CMapInfo Info; /// descriptive information diff --git a/src/map/fow.cpp b/src/map/fow.cpp index 2e4b76e1c..c389f049f 100644 --- a/src/map/fow.cpp +++ b/src/map/fow.cpp @@ -57,10 +57,19 @@ ----------------------------------------------------------------------------*/ /// FIXME: Maybe move it into CMap CFogOfWar FogOfWar; /// Fog of war itself +CGraphic *CFogOfWar::LegacyFogGraphic {nullptr}; // Graphic tiles set for legacy fog /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ +void CFogOfWar::SetLegacyFogGraphic(const std::string &fogGraphicFile) +{ + if (CFogOfWar::LegacyFogGraphic) { + CGraphic::Free(CFogOfWar::LegacyFogGraphic); + } + CFogOfWar::LegacyFogGraphic = CGraphic::New(fogGraphicFile, PixelTileSize.x, PixelTileSize.y); +} + /// Calculate values of upscale table for explored/unexplored tiles void CFogOfWar::GenerateUpscaleTables(uint32_t (*table)[4], const uint8_t alphaFrom, const uint8_t alphaTo) { @@ -130,14 +139,14 @@ void CFogOfWar::InitLegacyFogOfWar() SDL_FillRect(LegacyFogFullShroud, NULL, Settings.FogColorSDL | (uint32_t(0xFF) << ASHIFT)); VideoPaletteListAdd(LegacyFogFullShroud); - Map.LegacyFogGraphic->Load(); + CFogOfWar::LegacyFogGraphic->Load(); - SDL_Surface * const newFogSurface = SDL_ConvertSurfaceFormat(Map.LegacyFogGraphic->Surface, + SDL_Surface * const newFogSurface = SDL_ConvertSurfaceFormat(CFogOfWar::LegacyFogGraphic->Surface, SDL_MasksToPixelFormatEnum(32, RMASK, GMASK, BMASK, AMASK), 0); - SDL_FreeSurface(Map.LegacyFogGraphic->Surface); - Map.LegacyFogGraphic->Surface = newFogSurface; + SDL_FreeSurface(CFogOfWar::LegacyFogGraphic->Surface); + CFogOfWar::LegacyFogGraphic->Surface = newFogSurface; - SDL_SetSurfaceBlendMode(Map.LegacyFogGraphic->Surface, SDL_BLENDMODE_BLEND); + SDL_SetSurfaceBlendMode(CFogOfWar::LegacyFogGraphic->Surface, SDL_BLENDMODE_BLEND); } /** @@ -772,18 +781,18 @@ void CFogOfWar::DrawFogOfWarTile(const size_t visIndex, const size_t mapIndex, c if (IsMapFieldVisible(visIndex) || ReplayRevealMap) { if (fogTile && fogTile != blackFogTile) { - Map.LegacyFogGraphic->DrawFrameClipCustomMod(fogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, - FogOfWar.GetExploredOpacity(), - vpFogSurface); + CFogOfWar::LegacyFogGraphic->DrawFrameClipCustomMod(fogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, + FogOfWar.GetExploredOpacity(), + vpFogSurface); } } else { DrawFullShroudOfFog(dx, dy, FogOfWar.GetExploredOpacity(), vpFogSurface); } if (blackFogTile) { - Map.LegacyFogGraphic->DrawFrameClipCustomMod(blackFogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, - GameSettings.RevealMap ? FogOfWar.GetRevealedOpacity() - : FogOfWar.GetUnseenOpacity(), - vpFogSurface); + CFogOfWar::LegacyFogGraphic->DrawFrameClipCustomMod(blackFogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, + GameSettings.RevealMap ? FogOfWar.GetRevealedOpacity() + : FogOfWar.GetUnseenOpacity(), + vpFogSurface); } } /** @@ -850,9 +859,9 @@ void CFogOfWar::DrawLegacy(CViewport &viewport) void CFogOfWar::CleanLegacyFogOfWar(const bool isHardClean /*= false*/) { - if (isHardClean && Map.LegacyFogGraphic) { - CGraphic::Free(Map.LegacyFogGraphic); - Map.LegacyFogGraphic = nullptr; + if (isHardClean && CFogOfWar::LegacyFogGraphic) { + CGraphic::Free(CFogOfWar::LegacyFogGraphic); + CFogOfWar::LegacyFogGraphic = nullptr; } if (LegacyFogFullShroud) { diff --git a/src/map/map_fog.cpp b/src/map/map_fog.cpp index 4df400a67..817e54612 100644 --- a/src/map/map_fog.cpp +++ b/src/map/map_fog.cpp @@ -57,10 +57,6 @@ ----------------------------------------------------------------------------*/ CFieldOfView FieldOfView; -/// FIXME: Maybe move it into CFogOfWar -CGraphic *CMap::LegacyFogGraphic { nullptr }; - - /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ diff --git a/src/map/script_map.cpp b/src/map/script_map.cpp index 984639a3a..f58413f54 100644 --- a/src/map/script_map.cpp +++ b/src/map/script_map.cpp @@ -662,10 +662,7 @@ static int CclSetFogOfWarGraphics(lua_State *l) LuaCheckArgs(l, 1); FogGraphicFile = LuaToString(l, 1); - if (CMap::LegacyFogGraphic) { - CGraphic::Free(CMap::LegacyFogGraphic); - } - CMap::LegacyFogGraphic = CGraphic::New(FogGraphicFile, PixelTileSize.x, PixelTileSize.y); + CFogOfWar::SetLegacyFogGraphic(FogGraphicFile); return 0; }