Retro Game Engine

A small game engine which I named 'Sparc-16', focused on providing a platform for developing very authentic retro pixel-art games.
The first part of the name is short for "Super Arcade", with the "16" suffix being a reference to the 16-bit era of game consoles it draws inspiration from.

Sparc is built on C++ and SDL. At the core, it is designed to provide a graphics API and feature set which is on par with consoles such as the SNES and Mega Drive.
Graphically, it supports four tile layers and four sprite layers. There can be up to 256 sprites on the screen at a time. Each tile layer and sprite references one of 16 palettes, which each contain 15 color entries plus one transparency entry. Sprites can also define a blend mode, inspired by some of the blend modes of the SNES (although less limiting). Sprites can be set to additive, multiply, subtract, or average (which is equivalent to 50% transparency). I also integrated Blargg's SNES NTSC filter, which faithfully recreates the color palette and artifacts of NTSC televisions, to complete the authentic look of Sparc.

While originally I had wanted to go with a custom audio system which supported a mix of FM synthesis and PCM playback, the tracker interface for composing music proved to be a much larger time investment than I had anticipated. So I scrapped the custom audio core and instead opted for pure PCM playback in the form of a MOD player library plus custom sound mixing code. I used the Micromod library, with a few custom bugfixes, to provide up to 16-channel MOD playback. On top of that, I wrote custom sound mixing code which could playback sounds through up to 8 channels at a user-defined rate. On top of those, Sparc supports a simple echo filter with a hard-coded feedback amount and user-defined delay time between 0 and 200 milliseconds (a setting of 0 disables the echo filter), which was inspired by the echo filter of the SPC chip on the SNES.

Additionally, inspired by fantasy console projects such as PixelVision 8 and PICO-8, I wanted to be able to develop games on Sparc entirely with a scripting language. To that end I integrated Duktape, a project which aims to provide an implementation of Javascript which is as easy to integrate with C++ as Lua. For the most part the scripting interface is complete, but a few pain points still exist. For example, image loading is implemented entirely within Javascript using PNG.js (from Browserify) and Pako (a Javascript port of ZLIB), and is unfortunately quite slow. I believe a better approach might be to implement some sort of persistent caching mechanism, saving images to a more efficient and compact intermediate format which requires a minimum of parsing into a separate cache directory. This, as well as an asset bundling system, are features I'd like to investigate in the future.

Having used Tiled in the past, it was an obvious first choice to investigate as a level editor. Tiled natively supports JSON export, so this was relatively easy to implement with a few assumed limitations (for example, tile layers can't reference multiple tilesets).
In the video below, I show off a tilemap which was created in Tiled and loaded into Sparc.

Additionally, one of the things I definitely wanted to accomplish in Sparc was the ability to change graphics state per-scanline. This enabled some pretty cool and well-known effects in titles of the 16-bit era, such as the water effects in the Sonic The Hedgehog series, or the fire effect in the Final Fantasy 3 title logo.
Inspired by the latter, I wanted to create a cool-looking flame and spark effect which might serve as a main menu background. Three layers are employed here - the background layer, for the flame image, and two scrolling overlay layers for the sparks (I decided it would be simpler to make a single image for sparks rather than use a sprite per spark). The horizontal positions of each layer are offset on a per-scanline basis using sine and cosine functions.