I became distracted by a question on the PALib forum this evening, so haven’t fixed any of the Woopsi bugs I’d intended to. Interesting problem - is it possible to draw a 100x100 rectangle rotating through 360 degrees, using nothing but PALib’s line routines and a floodfill algorithm, at 60fps?
Short answer: No. Long answer: Well, I couldn’t get it working fast enough.
This was an interesting query for a few reasons. I’m thinking of writing a vector-based game in a Woopsi window when that’s finished. Also, Woopsi may (or may not) get a floodfill routine at some point, so it was good to see how that should work.
I tried two floodfill algorithms, both from this page:
The first one I tried was the 4-way recursive routine which, as the site suggests, is a bit useless - it overflowed the stack. The second one I tried was the scanline-with-stack routine, which did the job. I optimised it by replacing its single pixel plotting method with a DMA accelerated line routine (which meant switching it from scanning through columns of pixels to rows) and switching to bitshifts where possible. There’s a “QuickFill” method on the internets somewhere that would probably do it a bit faster.
The (bog-standard C) code below includes useful functions such as stack management routines, polygon rotation and drawing routines, and the accelerated line drawing routine. This might turn out to be useful for Woopsi - I’ve been meaning to write this for ages, and it does produce a speed increase over the current routine. Instead of plotting each pixel in the line one by one, it plots the first 8th of the pixels required, then copies those to the location of the next 8th. It then copies all of the pixels drawn so far to the location of the next quarter, and so on (you can see the pattern emerging - each copy is double the size of the last). A 16-pixel wide line will thus take 5 draw operations (2 plots and 3 copies) instead of 16. Any pixels left to be drawn after the copies have completed are plotted using the standard method.