Posted January 12, 2020 by freds72
Disclaimer: updated version will all tracks is not yet published - should be published later in Jan.
The next step for Virtua Racing is to have other competitors to play against (or zoom past them as in the arcade).
Some performance boost is necessary (and beside Zedwolf showed me that 300+ tri/frame was possible on pico!)
gif are not aligned thanks to a slightly different screen center (63.5 vs. 64)
Most notable performance elements listed below (with estimate on total pico-8 cpu in brackets)
Full minute code diff (Github)
Virtual Racing track and 3d models are mainly convex quads, well suited for an optimized edge renderer.
That shaved between 2-8% cpu per frame.
Side by side. trifill vs. edge renderer (max. cpu over 2s)
Note: right gif taken before full optimization pass
camera(-64,-64) was used to remove centering from all vertex coords calculations. Pays at scale.
Before:
local x,y=64+flr(64*px/pz),64-flr(64*py/pz)
After:
local x,y=flr(64*px/pz),-flr(64*py/pz)
Many "little" performance improvements are just "better" code, loops unrolling...
One aspect I took care of was to avoid closure access cost:
function make_track() local i=0 return function() local li=i for j=1,100 do -- i: closure variable, accessed by 'unboxing' the data if(i==j) print(i) -- li: "local"ized version, fast if(li==j) print(li) end end end
Was not expecting this one, but a major gain was achieved by trimming down the number of tiles on the background map!
Full background image is now rendered with 2 rectfills on top of each other + map.