lorez | github.com/Bartvds/lorez |
demo | bartvds.github.io/lorez |
This was originally a module I found on reddit and I forked it to have some fun because I hadn't done much display-code for a while.
It was a simple pixel renderer for low-res-style games (big-pixels), it was made for a 32x32 pixel game-jam.
Many revisions later I migrated it to TypeScript and it is now becoming quite a complete render engine with many helpers.
The original was terribly inefficient, using canvas fillRect()
and a ugly triple-nested array model for the pixels.
So I re-gutted the whole thing to use a single continuous ArrayBuffer (with Uint8Array/Uint8ClampedArray views). Then recoded the drawing loop for a nice speed boost on smaller sizes.
Note I didn't touch the loops in the code (yet), as I intended to get this merged I'd left that for the owner.
Because it was still slow at full-screen on my big 1920x1200 monitor I did a crash course WebGL and added a simple 2D crispy-upscaling renderer. The GL code and shader are probably the simplest ever, but GL is so alien I'm proud I hacked it together on tutorials.
As the pixel buffer is tiny Uint8Array we can easily pump it to the GPU every frame, an use it as a texture with nearest-neighbour sampling to fill fullscreen with big sharp pixels. It caps at the 60hz of requestAnimationFrame
with plenty of CPU headroom.
Sadly the owner got intimidated when I pushed a browserified version and so he didn't merge all of it.
A few weeks later and now everything is different, I cut the fork and moved the project ahead. It is now written in TypeScript and has a ton of optimisations and additional features. It has become heavy in code but it is screen-blistering fast in rendering.
WebGL is now active by default, there is some alpha channel support, sprite-sheets, perlin-noise (imported via stackoverflow of course), PNG/JPG loaders and the demo player is improved with history API. Also the font is expanded with numerals and special-character and the demos auto-deploy from Travis. I've flipped the loops for cache-coherency (y as outer loop), pulled many conditionals out the loops and did some other magic to make the profilers happy.
It's never enough, there is always a slow method and the whole thing should have alpha support and maybe some blendmodes.
Im working to get it ready for npm and bower and relaunch it on /r/gamedev.