nanard wrote: ↑Sun Dec 27, 2020 8:13 pm
Eero Tamminen wrote: ↑Sun Dec 27, 2020 11:52 am
I would have thought that palette doesn't need changing during normal game play, but GFX_SetPalette() + Video_SetPalette() take together >6.5% of the cycles!
There are color cycling that happens during the game in Dune II :
Code: Select all
color 223 = Windtrap cycling color
color 239 : highlighted text in structure menu : PLACE IT / REPAIR etc.
is alterning white / red
color 255 = unit/structure selection (palette cycling) on the map
and also in factories/construction yard menu
6.5% seems a bit excessive considering that Windtrap isn't there from beginning of the campaign, and for large part of the game, it's not even visible on screen.
Looking at the callgraph screenshot in my previous post, you can see that during my first campaign play, main() calls GUI_PaletteAnimate() 19510 times, and GUI_DisplayFactoryWin() additional 9124 times, for total of 29470 calls. Of those calls, GFX_SetPalette() is called 10871 i.e. approximately every 3rd animation call, or every 2nd game frame (I assume main() calls animate every frame).
In my campaign profile, most time in GFX_SetPalette() is consumed by the loop at the beginning:
Code: Select all
_GFX_SetPalette:
$00021be2 : movem.l d2-d7/a2-a6,-(sp) 0.00% (11106, 1067260, 0, 0)
$00021be6 : movea.l $30(sp),a1 0.00% (11106, 177808, 0, 0)
$00021bea : move.l #$9c3de,d7 0.00% (11106, 133328, 0, 0)
$00021bf0 : movea.l d7,a0 0.00% (11106, 44536, 0, 0)
$00021bf2 : movea.l a1,a2 0.00% (11106, 44424, 0, 0)
$00021bf4 : moveq #0,d1 0.00% (11106, 44480, 0, 0)
$00021bf6 : movea.l a2,a5 0.09% (2560608, 10256712, 0, 0)
$00021bf8 : suba.l a1,a5 0.09% (2560608, 20504844, 0, 0)
$00021bfa : move.b (a2),d0 0.09% (2560608, 20506608, 0, 0)
$00021bfc : cmp.b (a0),d0 0.09% (2560608, 20508780, 0, 0)
$00021bfe : bne.s $21c34 0.09% (2560608, 20529556, 0, 0)
$00021c00 : move.b 1(a2),d4 0.09% (2555583, 30696188, 0, 0)
$00021c04 : cmp.b 1(a0),d4 0.09% (2555583, 30700132, 0, 0)
$00021c08 : bne.s $21c34 0.09% (2555583, 20471476, 0, 0)
$00021c0a : move.b 2(a2),d0 0.09% (2555583, 30700844, 0, 0)
$00021c0e : cmp.b 2(a0),d0 0.09% (2555583, 30698960, 0, 0)
$00021c12 : bne.s $21c34 0.09% (2555583, 20493816, 0, 0)
$00021c14 : addq.l #1,d1 0.09% (2549511, 20419856, 0, 0)
$00021c16 : addq.l #3,a2 0.09% (2549511, 20417552, 0, 0)
$00021c18 : addq.l #3,a0 0.09% (2549511, 20420184, 0, 0)
$00021c1a : cmpi.l #$100,d1 0.09% (2549511, 35729526, 0, 0)
$00021c20 : bne.s $21bf6 0.09% (2549511, 25524510, 0, 0)
$00021c22 : move.l #$21bc2,$30(sp) 0.00% (9, 216, 0, 0)
...
I.e. this code:
https://github.com/OpenDUNE/OpenDUNE/bl ... gfx.c#L467
I think using just memcmp() would be more effective.
Most time consuming part in Video_SetPalette() is obviously the ST/STE palette color handling:
https://github.com/OpenDUNE/OpenDUNE/bl ... ari.c#L534
If those palette changes are only needed for a very small set of fixed palettes, you could consider adding specific shortcuts for them. These specific palettes could be recognized either with memcmp(), or by annotating the palette calls (with extra arg) so that the resulting ST/STE palette can be directly taken from some pre-defined array, instead of each color needing to be separately calculated / searched for.
As to the rest of that function, you could split it into Atari machine specific functions, and in Video_Init() just assign Video_SetPalette() pointer to the correct one for given machine.