fli_pal_dirty_from(3alleg4)

πŸ’… fli_pal_dirty_from β€” bestie edition

okay so this is from the Allegro manual (yes, the Allegro game programming library, we love her) and the page is called fli_pal_dirty_from(3alleg4). Two lil global ints, one big job: telling you which slice of your palette just changed. let's get into it πŸŽ€


✨ NAME ✨

fli_pal_dirty_from, fli_pal_dirty_to β€” indicate which parts of the palette have changed. Allegro game programming library. periodt.


🌸 SYNOPSIS 🌸

#include <allegro.h>

extern int fli_pal_dirty_from;

extern int fli_pal_dirty_to;

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: these two variables get set by next_fli_frame(), and what they're telling you is which part of the fli_palette has changed since the last time somebody called reset_fli_variables(). it's giving receipts πŸ“‹

here's the tea tho, the logic is lowkey backwards-cute:

  • if fli_pal_dirty_from is greater than fli_pal_dirty_to, that means the palette has not changed at all. nothing happened. go home. πŸ’€
  • otherwise, colors fli_pal_dirty_from to fli_pal_dirty_to (inclusive, bestie, don't forget the endpoints) have altered. πŸ‘‘

and the whole point of knowing this?? it's so you can use it while you're updating the hardware palette and avoid unnecessary calls to set_palette(). no cap, stop wasting cycles on palette ranges that didn't even move. she's efficient. she's iconic. 🫢

example, fresh from the source:

if (fli_pal_dirty_from <= fli_pal_dirty_to)
   set_palette_range(fli_palette, fli_pal_dirty_from,
                     fli_pal_dirty_to, 1);

see how she checks the condition first? main character energy fr fr πŸ”₯


πŸ’– SEE ALSO πŸ’–

go read those next, iykyk πŸ“š


ngl this is the kind of tiny optimization that makes you feel like a genius. use it. πŸ’…

and that's the whole page babes ✨ this was Allegro, version 4.4.3 β€” fli_pal_dirty_from(3alleg4), brought to you with love, extern int energy, and exactly zero unnecessary set_palette() calls. mwah πŸ’–πŸŒˆ