“Pete Shinners” wrote
i believe the flaw comes from the painful method of searching
through all the rectangles comparing to all the other rectangles.
this gives me exponential slowdown for each rectangle in the list.
well, it turns out the flaw was some sloppy loop handling on my
part. i’ve fixed the code and am amazed at the results.
all these tests are done with the aliens demo with the
SDL_Delay call taken out so the code runs as fast as possible.
(i also made the seed a constant so each run would be the same)
Lets just start by saying the code with my ‘new’ updaterects
function runs anywhere between 130% to 180% the speed of the
original updaterects. in the most complex scene the framerate
went from 57fps to 102fps. here’s my numbers…
aliens with SDL_UpdateRects runs at 296fps with one alien and
57fps with MAX_ALIENS. SDL_UpdateRects is about 73% of the total
runtime.
aliens with my UpdateRectsOpto runs at 384fps with one alien
and 102fps with MAX_ALIENS. UpdateRectsOpto is about 60% of the
total runtime.
i attained these results with the DirectX driver. initial dabbling
with the GDI driver seems to show similar results.
i’m releasing the code here so people can try it out, report
the results, maybe even tune it further? if all goes well i’d
like to see if this could get some form of this merged with SDL.
basically the code rearranges all the rects so that no pixel is
updated twice. it also prunes and carefully places new rectangles
so that the minimum number of rectangles is used.
to try it out, include the source file with your project and
add the declaration for the new function in your file.
extern void UpdateRectsOpto(SDL_Surface* screen, int rectcount, SDL_Rect* rectlist);
then, just replace
SDL_UpdateRects(screen, numrects, rectlist);
with
UpdateRectsOpto(screen, numrects, rectlist);
i’d like to hear what happens :]
begin 666 rectsopto.zip
M4$L#!!0(`&BS(2E,P*W2^00``+@:```+
<F5C=’-O<‘1O+F/M66UO
MVS80_NP^0^W#BADQW&2#=B7V,'0=2L&!$N1ET]#42 at 2;5&124&BH[A#_OON MJ!=3$BT[BY/TPU#4M8YW#^^Y-\KLT0#^%%QQ-P+%4L7%#*8R
1=BJ9@@>;2$
MN4P8R.F4>B\OP<#6,2^JUC"/)6""EP%GEQ$/MPRX,+%C[S(>,J@*N/YR,R
MT$:?F6)P%7 A6)(".#$^_YH6SR.9S/I:[8K%"DY2-82?CH^/272TOT=_?BRP
M89PJ/^*WH^"L(>2R(5-\SK3($+Y#I[[><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