63 void Clean(
const bool isHardClean =
false);
65 void SetOpacityLevels(
const uint8_t explored,
const uint8_t revealed,
const uint8_t unseen);
78 void SetFogColor(
const uint8_t r,
const uint8_t g,
const uint8_t b);
83 void InitBlurer(
const float radius1,
const float radius2,
const uint16_t numOfIterations);
85 void Update(
bool doAtOnce =
false);
94 void GenerateUpscaleTables(uint32_t (*table)[4],
const uint8_t alphaFrom,
const uint8_t alphaTo);
99 uint8_t DeterminePattern(
const size_t index,
const uint8_t visFlag)
const;
100 void FillUpscaledRec(uint32_t *texture,
const uint16_t textureWidth,
size_t index,
101 const uint8_t patternVisible,
const uint8_t patternExplored)
const;
103 void UpscaleBilinear(
const uint8_t *
const src,
const SDL_Rect &srcRect,
const int16_t srcWidth,
104 SDL_Surface *
const trgSurface,
const SDL_Rect &trgRect)
const;
106 void UpscaleSimple(
const uint8_t *src,
const SDL_Rect &srcRect,
const int16_t srcWidth,
107 SDL_Surface *
const trgSurface,
const SDL_Rect &trgRect)
const;
110 void CleanTiled(
const bool isHardClean =
false);
112 void DrawFullShroudOfFog(
const int16_t x,
const int16_t y,
const uint8_t alpha,
113 SDL_Surface *
const vpFogSurface);
114 void GetFogTile(
const size_t visIndex,
const size_t mapIndex,
const size_t mapIndexBase,
115 int *fogTile,
int *blackFogTile)
const;
116 bool IsMapFieldExplored(
const size_t index)
const {
return (VisTable[index] != 0); }
117 bool IsMapFieldVisible(
const size_t index)
const {
return (VisTable[index] > 1); }
118 void DrawFogTile(
const size_t visIndex,
const size_t mapIndex,
const size_t mapIndexBase,
119 const int16_t dx,
const int16_t dy, SDL_Surface *
const vpFogSurface);
121 void DrawTiledLegacy(
CViewport &viewport);
126 struct FogOfWarSettings
129 uint8_t NumOfEasingSteps {8};
130 float BlurRadius[2] {2.0, 1.5};
131 uint8_t BlurIterations {3};
132 uint8_t UpscaleType {UpscaleTypes::cSimple};
133 CColor FogColor {0, 0, 0, 0};
134 uint32_t FogColorSDL {0};
135 uint8_t ExploredOpacity {0x7F};
136 uint8_t RevealedOpacity {0xBE};
137 uint8_t UnseenOpacity {0xFE};
140 uint8_t State { States::cFirstEntry };
142 std::set<uint8_t> VisionFor;
148 SDL_Surface *TileOfFogOnly {
nullptr};
153 const int TiledFogTable[16] = {0, 11, 10, 2, 13, 6, 14, 3, 12, 15, 4, 1, 8, 9, 7, 0};
155 std::vector<uint8_t> VisTable;
156 size_t VisTable_Index0 {0};
157 size_t VisTableWidth {0};
159 std::vector<uint8_t> RenderedFog;
164 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
165 const uint32_t UpscaleTable_4x4[16][4] { {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
166 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x007FFFFF},
167 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF7F, 0xFFFF7F00},
168 {0xFFFFFFFF, 0xFFFFFFFF, 0x7F7F7F7F, 0x00000000},
169 {0x007FFFFF, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
170 {0x007FFFFF, 0x007FFFFF, 0x007FFFFF, 0x007FFFFF},
171 {0x007FFFFF, 0x7FFFFFFF, 0xFFFFFF7F, 0xFFFF7F00},
172 {0x00007FFF, 0x0000007F, 0x00000000, 0x00000000},
173 {0xFFFF7F00, 0xFFFFFF7F, 0xFFFFFFFF, 0xFFFFFFFF},
174 {0xFFFF7F00, 0xFFFFFF7F, 0x7FFFFFFF, 0x007FFFFF},
175 {0xFFFF7F00, 0xFFFF7F00, 0xFFFF7F00, 0xFFFF7F00},
176 {0xFF7F0000, 0x7F000000, 0x00000000, 0x00000000},
177 {0x00000000, 0x7F7F7F7F, 0xFFFFFFFF, 0xFFFFFFFF},
178 {0x00000000, 0x00000000, 0x0000007F, 0x00007FFF},
179 {0x00000000, 0x00000000, 0x7F000000, 0xFF7F0000},
180 {0x00000000, 0x00000000, 0x00000000, 0x00000000} };
183 const uint32_t UpscaleTable_4x4[16][4] { {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
184 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFF7F, 0xFFFF7F00},
185 {0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF, 0x007FFFFF},
186 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},
187 {0xFFFF7F00, 0xFFFFFF7F, 0xFFFFFFFF, 0xFFFFFFFF},
188 {0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000},
189 {0xFFFF7F00, 0xFFFFFF7F, 0x7FFFFFFF, 0x007FFFFF},
190 {0xFF7F0000, 0x7F000000, 0x00000000, 0x00000000},
191 {0x007FFFFF, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
192 {0x007FFFFF, 0x7FFFFFFF, 0xFFFFFF7F, 0xFFFF7F00},
193 {0x0000FFFF, 0x0000FFFF, 0x0000FFFF, 0x0000FFFF},
194 {0x00007FFF, 0x0000007F, 0x00000000, 0x00000000},
195 {0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF},
196 {0x00000000, 0x00000000, 0x7F000000, 0xFF7F0000},
197 {0x00000000, 0x00000000, 0x0000007F, 0x00007FFF},
198 {0x00000000, 0x00000000, 0x00000000, 0x00000000} };
201 uint32_t UpscaleTableVisible[16][4] = {};
202 uint32_t UpscaleTableExplored[16][4] = {};
203 uint32_t UpscaleTableRevealed[16][4] = {};
204 const uint32_t (*CurrUpscaleTableExplored)[4] = UpscaleTableVisible;
217 inline uint8_t CFogOfWar::DeterminePattern(
const size_t index,
const uint8_t visFlag)
const
221 uint8_t n1, n2, n3, n4;
222 size_t offset = index;
224 n1 = (visFlag & VisTable[offset]);
225 n2 = (visFlag & VisTable[offset + 1]);
226 offset += VisTableWidth;
227 n3 = (visFlag & VisTable[offset]);
228 n4 = (visFlag & VisTable[offset + 1]);
235 return ( (n1 << 3) | (n2 << 2) | (n3 << 1) | n4 );
248 inline void CFogOfWar::FillUpscaledRec(uint32_t *texture,
const uint16_t textureWidth,
size_t index,
249 const uint8_t patternVisible,
const uint8_t patternExplored)
const
251 for (uint8_t scan_line = 0; scan_line < 4; scan_line++) {
252 texture[index] = UpscaleTableVisible[patternVisible][scan_line] + CurrUpscaleTableExplored[patternExplored][scan_line];
253 index += textureWidth;
259 return VisTable[VisTable_Index0 + tilePos.
x + VisTableWidth * tilePos.
y];