Day 1.
The first second task to overcome was how to handle lightmapping. (The real first task was to figure out how to draw directly to the hardware overlay, but that's covered on the wiki.)
Because the game is 'only' 2D, but I want it to 'feel' very immersive and and emotionally compelling, having dramatic lighting is going to play a big part. Since I'm working in Allegro, I settled on the following:
- When loading a new map, the engine will also load an image that controls how tiles should be lit.
- The engine makes a copy of this image.
- Dynamic lights, like lanterns, fire, spell effects and the like get painted into the image from step 1.
- The image from step 1 is used as inputs to draw_gouraud_sprite().
- At the end of every frame, the lightmap image from step 1 is restored from the copy in step 2.
The restoring part sounds expensive, but it really isn't - because the world is split into rooms, a bit like Maze Of Galious, the lightmap and the copy I'm restoring from only need to be 50x30, since a 400x240 display will hold about half those dimensions worth of 16x16 tiles, and I want each room to be at most two screens across. Most of the drawing time will be taken up by the gouraud-shaded tiles, and even though all of the shading and blending is happening on the CPU, it seems like a Pandora's up to the task, even at the stock 500 MHz, even with a MOD player running.
I wrote a quick proglet to raycast from light positions to walls that should block light and save the output to a file. It's admittedly quite stupid, slow and performs a lot of ray-following it doesn't need to, but because lightmaps get made out of band on the content-authoring side, I don't care
.
With that sorted out, along with deciding to use Mappy as a tilemap editor, I tried to draw my first map to the screen, only to discover that -
surprise! -
draw_gouraud_sprite() doesn't fully take into account RGB when setting up the gradients between the corners of the sprite, and instead, just blindly interpolates between c1, c2, c3 and c4 (whoops). I guess, when it was originally written, no one ever expected handhelds to be fast enough to do colour lighting in software.
I'll probably just rewrite it somewhere inside the game engine. I think, since all tiles are going to be 16 by 16 pixels anyway, I can probably replace some of the divisions with shifts.
More later after work and hockey practice.