MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DoPaletteAnimations

Function DoPaletteAnimations

src/palette.cpp:245–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243#define EXTR2(p, q) (((uint16_t)(~palette_animation_counter * (p)) * (q)) >> 16)
244
245void DoPaletteAnimations()
246{
247 std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
248
249 /* Animation counter for the palette animation. */
250 static int palette_animation_counter = 0;
251 palette_animation_counter += 8;
252
253 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
254 const Colour *s;
255 const ExtraPaletteValues *ev = &_extra_palette_values;
256 const uint old_tc = palette_animation_counter;
257 uint j;
258
259 if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PaletteAnimation::None) {
260 palette_animation_counter = 0;
261 }
262
263 std::span<Colour> current_palette{&_cur_palette.palette[PALETTE_ANIM_START], PALETTE_ANIM_SIZE};
264 /* Makes a copy of the current animation palette in old_val,
265 * so the work on the current palette could be compared, see if there has been any changes */
266 std::array<Colour, PALETTE_ANIM_SIZE> original_palette;
267 std::ranges::copy(current_palette, original_palette.begin());
268 auto palette_pos = current_palette.begin(); // Points to where animations are taking place on the palette
269
270 /* Fizzy Drink bubbles animation */
271 s = ev->fizzy_drink;
272 j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK);
273 for (uint i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) {
274 *palette_pos++ = s[j];
275 j++;
276 if (j == EPV_CYCLES_FIZZY_DRINK) j = 0;
277 }
278
279 /* Oil refinery fire animation */
280 s = ev->oil_refinery;
281 j = EXTR2(512, EPV_CYCLES_OIL_REFINERY);
282 for (uint i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) {
283 *palette_pos++ = s[j];
284 j++;
285 if (j == EPV_CYCLES_OIL_REFINERY) j = 0;
286 }
287
288 /* Radio tower blinking */
289 {
290 uint8_t i = (palette_animation_counter >> 1) & 0x7F;
291 uint8_t v;
292
293 if (i < 0x3f) {
294 v = 255;
295 } else if (i < 0x4A || i >= 0x75) {
296 v = 128;
297 } else {
298 v = 20;
299 }
300 palette_pos->r = v;
301 palette_pos->g = 0;
302 palette_pos->b = 0;

Callers 2

GameLoopFunction · 0.85
GfxInitPalettesFunction · 0.85

Calls 3

copyFunction · 0.85
UsePaletteAnimationMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected