2 ms·
I did something like this back in 2010 with javascript when browsers were much slower at executing code. I was experimenting with manual image scaling and rotat
by furgooswft13 8y ago
I did something like this back in 2010 with javascript when browsers were much slower at executing code. I was experimenting with manual image scaling and rotation without use of built in canvas functions, mostly to get perfect nearest-neighbour rendering and do extra tricks like perspective transforms which were not really available at the time (just affine transformations were built into the canvas API).
I was struggling to hit 60fps so I devised this hacky system where I'd leave various markers in a "template" function, then parse that using Function.toString() and replace certain areas with unrolled loops, removed if conditions etc. Put the generated function code in a new Function() and used that for the remainder of the animation loop until settings changed.
Actually worked pretty well, along with some other optimizations, was able to hit 60fps in chrome and almost that in FF, depending on the scaling mode of course. At the time my manual implementation of bilinear filtering destroyed the frame rate no matter what, but these days browsers can run it without breaking a sweat. They've come a long way performance wise.
I still have it stashed away on my webserver, so here if anyone is curious. Code is a mess though: http://bigmooworld.com/pwings/pilotwings/pilotwings.html http://bigmooworld.com/pwings/pilotwings/pilotwings.html
You might recognize it..