Log In  

Cart #tayohuzabe-0 | 2020-07-24 | Code ▽ | Embed ▽ | No License

I'm considering making an adventure game with fullscreen backgrounds stored as sets of instructions for drawing, so I tried making a flood fill algorithm in the scanline variety, but found it to be rather slow. Even after fiddling with methods, such as wasting memory to avoid management and making the algorithm twice as long to avoid ever checking a pixel twice, I could only get it down to %128 cpu usage for the test case. Most optimizations I tried saved less than %1 cpu. If told to fill the entire screen, it goes even further up to %267 cpu.

It's definitely fast enough for drawing images that don't need redrawing every frame, but it'd be nice if it were fast enough for real time usage. Anyone know a way to make it faster?

P#79841 2020-07-24 10:44

Here's a version of your drawing using a little tool I've been working on that draws shapes from encoded strings. It uses under 6% cpu.


function trifill(x1,y1,x2,y2,c)
 local inc=sgn(y2-y1)
 local fy=y2-y1+inc/2
 for i=inc/2,fy,inc do
  local nx=x1+(x2-x1)*i/fy

 --string decoder
 for i=0,#s-1 do v=ord(s,i+1)-96
  if(i%5==4) ft[v\16](unpack(t1))
flip()goto _

I'm collaborating with TheRoboZ on a comprehensive shape-drawing tool he's making for Pico-8, so consider this kind of a preview. =)

You can find more information in this thread:

P#79860 2020-07-24 15:53 ( Edited 2020-07-24 16:00)

Hmm...I guess for real-time drawing it would make more sense generally to use known shapes. However, I think if I do decide to make my idea for an adventure game, I'll likely still use some form of floodfill for efficiency in storage. If nothing else, small areas with weird shapes are probably still a good target for flooding.

That said, I also was considering generalizing my scanfill function to allow applying it to memory other than the screen pixels, so I may be able to implement my own version of that trifill (just to suit my own tastes) and then concoct a way to automate its use on the spots that the scanfill finds.

P#79871 2020-07-24 19:51

Okay, sounds like you're going for something a little different, that's fine. If you're planning to use my triangle function, though, here's the new version of it I just made. It fixes some little anomalies in the line pattern at some angles, it takes less cpu power, and it's down from 76 tokens to just 63.

function trifill(x1,y1,x2,y2,c)
 local inc=sgn(y2-y1)
 local fy=y2-y1+inc/2
 for i=inc\2,fy,inc do
P#79938 2020-07-26 04:56 ( Edited 2020-07-26 04:57)

Oh, right. I was thinking of that. I found out if I just use the fill for unpacking the images, I could hide loading times as usual and store the images as just a series of parameters for pixel setting and line drawing (in a more literal scanline rasterization setup). The result is 9% cpu for drawing the whole screen. It's not as efficient as your method, but close enough to satisfy me. I'll post it here if I can find a nice way to generalize it and a decent way to enter the data in. I've already made a game recently that involved manually entering in image data in byte by byte, but I'm guessing most users wouldn't want to do that.

P#79939 2020-07-26 05:09

No, I'm guessing they wouldn't. That's how I made the picture I uploaded since I haven't made an editor yet, and it's not real fun.

P#79943 2020-07-26 08:48

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-01-19 20:44 | 0.021s | 4194k | Q:41