Is the source available somewhere? As Jonne said, using a sin/cos LUT instead of a formula should help, if you aren’t doing so already.
So are you using drawColumn()
? Just to check.
Will try the LUT.
No, the column is rendered by the library pixel by pixel in a Pokitto-independent way. The drawing on the actual display is done via drawPixel(). Is that slow?
I think what I need is profiling – see where the bottleneck is first, then try to optimize that.
EDIT:
For info, current FPS is about 20 - 25.
It might be. Which mode are you using?
Using mode 2, I’d like to switch to mode 13 but somehow can’t get it to work
Also does anyone have an idea why the leftmost column (x == 0) on my Pokitto display overflows to the right side of the display? E.g. doing drawpixel(0,5)
draws it on the right side of the display, drawpixel(1,5)
draws it on the left (first column). In simulator it works normally (indexed from 0).
EDIT: Is it this?
This might help a bit (mode 13 only):
inline void pixelFunc(PixelInfo pixel)
{
uint8_t color = pixel.isWall ? pixel.hit.direction + 4 : 3;
uint8_t *buf = p.display.screenbuffer;
buf += pixel.position.x*2;
buf += pixel.position.y*p.display.width;
*buf++ = color;
*buf = color;
}
Packing all the data into a struct instead of simply using multiple arguments is not very good for performance. In ARM the first 4 arguments are passed as registers. The struct forces it to put everything in memory.
You will also get a little boost if you don’t use a function pointer in this instance. Calling function pointers on ARM is cheap, but it might prevent optimizations in some cases. Simply use a forward declaration in the header, unless you plan on changing the pixelFunction in run-time.
Instead of a pixelFunction
, consider having a floorFunction
that draws an entire column of floor and a wallFunction
for walls.
Edit: Hang on… mode 2? The code I got from gitlab uses mode 13.
How do you know? I don’t have the settings file there yet.
Heh, I don’t. I pulled it, guessed mode 13 and it worked so I just assumed that was correct.
That’s mode 1. What did you do to see this?
I set it to draw half the screen (for (uint16_t i = 0; i < cam.resolution.x/2; ++i)
) and didn’t see a line on the right in either mode 2 or 13.
Well it just happens every time I run my program, that’s how I noticed it:
I also tried drawing a vertical line on the 0th column only and it bricked my Pokitto completely Something’s probably terribly wrong somewhere in my settings, my setup isn’t exactly standard.
bin:
raycast.LPC11U68.bin (32.0 KB)
Are you sure the PokittoLib you’re using is up to date with the one on GitHub?
Also, you can improve performance (getting about 40fps with this and the pixelFunc above) by enabling persistence and drawing the roof/floors with this, instead of using raycasting, before you call render:
// mode 13 only, needs adjustments for mode 2
void clear(){
uint8_t *buf = p.display.screenbuffer;
int32_t c = p.display.width*p.display.height/2;
while( c-->0 ) *buf++ = 0; // roof
c = p.display.width*p.display.height/2;
while( c-->0 ) *buf++ = 3; // floor
}
I need this.
I’ll check.
EDIT: I’m using the mbed online IDE, imported the latest PokittoLib (from the search/import tab), still the issue is there. Mbed repo.
I just checked it, it’s not up to date:
SET and CLR are swapped, compared to the github version on the right.
This was fixed a while ago, you might be missing out on other fixes/improvements. IIRC, mbed doesn’t use the hand-optimized assembly version of the code.
mbed online ide does not allow inline assembler. It is an unfortunate limitation.
@drummyfish, in order to get to the more powerful code, you need to user EmBitz or Platformio or Code::Blocks for the hardware.
@drummyfish : this is what I mean that the optimization begins when all the self-evident stuff has been used up.
Just ran the demo on my pokitto. Very, very cool. This may turn into a low-rez doom. Looking good.
Edit: but I would do the fog with a color ramp instead.
Yes, or TES Arena. I’d hope it to become an engine for multiple games rather than only one Once I add texturing and ceilings, it should start to look like Doom.
Definitely, once I get mode 13 to work Somehow it still doesn’t work for me in the simulator now.
Thanks @FManga @jonne @Pharap for the advices! I’ll have to set up an offline compiler now.
If you want to have something with a lot of contents, keep in mind it’d be best to load it from SD card too. I didn’t saw too much games here relying on external files yet?