Legacy fog gtraphic moved from CMap to CFogOfWar

This commit is contained in:
alyokhin 2021-10-02 19:21:18 +03:00
parent 9ad4af9dc8
commit e5095c1509
5 changed files with 29 additions and 25 deletions

View file

@ -56,7 +56,9 @@ public:
enum VisionType { cUnseen = 0, cExplored = 0b001, cVisible = 0b010 }; enum VisionType { cUnseen = 0, cExplored = 0b001, cVisible = 0b010 };
enum States { cFirstEntry = 0, cGenerateFog, cGenerateTexture, cBlurTexture, cReady }; enum States { cFirstEntry = 0, cGenerateFog, cGenerateTexture, cBlurTexture, cReady };
enum UpscaleTypes { cSimple = 0, cBilinear }; enum UpscaleTypes { cSimple = 0, cBilinear };
static void SetLegacyFogGraphic(const std::string &fogGraphicFile);
void Init(); void Init();
void Clean(const bool isHardClean = false); void Clean(const bool isHardClean = false);
bool SetType(const FogOfWarTypes fowType); bool SetType(const FogOfWarTypes fowType);
@ -140,6 +142,7 @@ private:
/// ThisPlayer and his allies in normal games /// ThisPlayer and his allies in normal games
/// Any set of players for observers and in the replays /// Any set of players for observers and in the replays
static CGraphic *LegacyFogGraphic; /// graphic for legacy fog of war
SDL_Surface *LegacyFogFullShroud {nullptr}; SDL_Surface *LegacyFogFullShroud {nullptr};
/** /**

View file

@ -270,7 +270,6 @@ public:
CTileset *Tileset; /// tileset data CTileset *Tileset; /// tileset data
std::string TileModelsFileName; /// lua filename that loads all tilemodels std::string TileModelsFileName; /// lua filename that loads all tilemodels
CGraphic *TileGraphic; /// graphic for all the tiles CGraphic *TileGraphic; /// graphic for all the tiles
static CGraphic *LegacyFogGraphic; /// graphic for legacy fog of war
bool isMapInitialized { false }; bool isMapInitialized { false };
CMapInfo Info; /// descriptive information CMapInfo Info; /// descriptive information

View file

@ -57,10 +57,19 @@
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
/// FIXME: Maybe move it into CMap /// FIXME: Maybe move it into CMap
CFogOfWar FogOfWar; /// Fog of war itself CFogOfWar FogOfWar; /// Fog of war itself
CGraphic *CFogOfWar::LegacyFogGraphic {nullptr}; // Graphic tiles set for legacy fog
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
-- Functions -- 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 /// Calculate values of upscale table for explored/unexplored tiles
void CFogOfWar::GenerateUpscaleTables(uint32_t (*table)[4], const uint8_t alphaFrom, const uint8_t alphaTo) 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)); SDL_FillRect(LegacyFogFullShroud, NULL, Settings.FogColorSDL | (uint32_t(0xFF) << ASHIFT));
VideoPaletteListAdd(LegacyFogFullShroud); 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_MasksToPixelFormatEnum(32, RMASK, GMASK, BMASK, AMASK), 0);
SDL_FreeSurface(Map.LegacyFogGraphic->Surface); SDL_FreeSurface(CFogOfWar::LegacyFogGraphic->Surface);
Map.LegacyFogGraphic->Surface = newFogSurface; 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 (IsMapFieldVisible(visIndex) || ReplayRevealMap) {
if (fogTile && fogTile != blackFogTile) { if (fogTile && fogTile != blackFogTile) {
Map.LegacyFogGraphic->DrawFrameClipCustomMod(fogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, CFogOfWar::LegacyFogGraphic->DrawFrameClipCustomMod(fogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey,
FogOfWar.GetExploredOpacity(), FogOfWar.GetExploredOpacity(),
vpFogSurface); vpFogSurface);
} }
} else { } else {
DrawFullShroudOfFog(dx, dy, FogOfWar.GetExploredOpacity(), vpFogSurface); DrawFullShroudOfFog(dx, dy, FogOfWar.GetExploredOpacity(), vpFogSurface);
} }
if (blackFogTile) { if (blackFogTile) {
Map.LegacyFogGraphic->DrawFrameClipCustomMod(blackFogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey, CFogOfWar::LegacyFogGraphic->DrawFrameClipCustomMod(blackFogTile, dx, dy, PixelModifier::CopyWithSrcAlphaKey,
GameSettings.RevealMap ? FogOfWar.GetRevealedOpacity() GameSettings.RevealMap ? FogOfWar.GetRevealedOpacity()
: FogOfWar.GetUnseenOpacity(), : FogOfWar.GetUnseenOpacity(),
vpFogSurface); vpFogSurface);
} }
} }
/** /**
@ -850,9 +859,9 @@ void CFogOfWar::DrawLegacy(CViewport &viewport)
void CFogOfWar::CleanLegacyFogOfWar(const bool isHardClean /*= false*/) void CFogOfWar::CleanLegacyFogOfWar(const bool isHardClean /*= false*/)
{ {
if (isHardClean && Map.LegacyFogGraphic) { if (isHardClean && CFogOfWar::LegacyFogGraphic) {
CGraphic::Free(Map.LegacyFogGraphic); CGraphic::Free(CFogOfWar::LegacyFogGraphic);
Map.LegacyFogGraphic = nullptr; CFogOfWar::LegacyFogGraphic = nullptr;
} }
if (LegacyFogFullShroud) { if (LegacyFogFullShroud) {

View file

@ -57,10 +57,6 @@
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
CFieldOfView FieldOfView; CFieldOfView FieldOfView;
/// FIXME: Maybe move it into CFogOfWar
CGraphic *CMap::LegacyFogGraphic { nullptr };
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
-- Functions -- Functions
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/

View file

@ -662,10 +662,7 @@ static int CclSetFogOfWarGraphics(lua_State *l)
LuaCheckArgs(l, 1); LuaCheckArgs(l, 1);
FogGraphicFile = LuaToString(l, 1); FogGraphicFile = LuaToString(l, 1);
if (CMap::LegacyFogGraphic) { CFogOfWar::SetLegacyFogGraphic(FogGraphicFile);
CGraphic::Free(CMap::LegacyFogGraphic);
}
CMap::LegacyFogGraphic = CGraphic::New(FogGraphicFile, PixelTileSize.x, PixelTileSize.y);
return 0; return 0;
} }