An experiment to see if I could get a raytracer running in PICO-8. It's not very speedy, but it's as optimised as I could be bothered to do. If you find further optimisations I'd love to hear about them!
optimization hints in no order:
- try shl() to replace any power of 2 multiply
- inline functions as much as possible
- favor k,v in pairs(array) instead of for i=1,#array when ordering is not important
- switch to 64x64 resolution (see pokes from wiki) and use pset instead of rectfill(x/x+1)
over and out :)
I was just thinking of earlier QBasic code doing this. One thing that made it run fast was that SIN and COS calculations were copied to an array and then the raytracer used that.
There is no need to calculate every SIN and COS each machine cycle for a rotating image, right ?
Yeah, but that’s not the slow part :-). The ray tracing isn’t using any sin/cos stuff. I tried the suggestions from Freds and they didn’t make a significant difference. The best speed up I’ve found so far is to switch both uses of sqrt to x^0.5 but even that didn’t make a huge difference. Thanks for the suggestions so far folks!
Then again we COULD just have ZEP release all the stops in PICO-8 and actually use up the computer's CPU, I would definitely not be against that - and all programs would still run smoothly with _DRAW(), FLIP(), and YIELD().
Running this I see this Firefox tab uses 3% of my CPU. Heaven knows how fast it could be bumped up to and to run even faster in immediate mode or compiled.
[Please log in to post a comment]