Tuesday, 18 October 2016

My CPC Wolfenstein engine (map editing tool)

It's time to continue by revealing the little map editing tool I started creating, just for the purpose of testing textures and designing the first map. Of course it's a crude tool I made just for the occasion, I once made to give to the artist so that he can try a texture loaded as a PNG (designed with CPC palette in mind), size 32*32 or less. It was never planned to be the level editor then, just a testing tool, but it can be expanded in the future in a way so that I can add monsters/items near blocks and additional metadata per block for scripting events.



Right now, you can draw/erase with left/right button on the down left side on the map, while seeing the blocks appearing in realtime on the upper window where you move with arrows (it's a simulation of what you expect to see and play on the real CPC, but on an SDL window in Windows). On the down right side there is the texture, the mouse scroll wheel will go through four textures atm. These are stored in a folder named texture1/2/3/4.PNG. It's just not complete atm, no menu to edit the mirroring of the door (which is hard coded for one of the textures), but there is also a rule. If you upload a texture that is something like 16*16, it will tile normally over 32*32. If you upload something bigger, it will just use the upper left 32*32 block of the graphics. Also,. there is a simple search through colors for palettes closest to the CPC palette. If your PNG uses colors very similar to the CPC palette, it will use those. But throw an arbitrary texture inside the folder (like some 32*32 Minecraft textures I tried) and it will automatically try to do it's best to match CPC colors, although usually it will look like crap.

Btw,. in the screenshot you see the unused two frame bat enemy sprite plastered on the wall. I might try to use this one (but maybe with dark blue instead of black) for my sprite enemies. Some other good news is that I am finally investigating some code for zooming sprites so that we can finally have some meaningful items/enemies in the game (a lot of work has to be done for that, not just zooming sprites, but clipping and calculation of position and zoom factor based on the camera visibility). I was trying some bruteforce slow C code and while you will get 2-3fps when sprite is filling fullscreen (something that will not happen with most sprites, I had to zoom by 8 to get this) this is very slow C code and I am already thinking of a nifty assembly solution, with very small unroll codes, that by calculating cycles doesn't eat more than 1VBL for 3-4 partially zoomed entities. And usually there will be less on screen and smaller items that I will not allow very close zoom in an RPG style game (you will be blocked by such so you won't get too near). And I am already thinking of transparent texture walls (like iron bars and doors) in a way that they can be drawn correctly with sprites and rest of the walls. I have some good ways to solve these problems, I just need to finish coding them first and test.

There are more stuff I want to do writeups for:

  • Texture repeat/packing/column offset engine and the cool things you can do with that.
  • Raycasting math, optimizations and interpolation tricks.
  • Wall rendering unroll codes explained.
  • My ideas for zooming sprite and transparent walls.
The thing is, most of these stuff need more intricate shapes to be prepared and careful write up. So, I am not sure when the next one will be (but I want to cover some of these bigger cool stuff). Meanwhile I might write smaller stuff or little news of progress. And even if I don't for few weeks, this means I might have focused more time on working on the engine rather than writing about it. So, don't expect anything, maybe it will take one or two weeks for the next update. But things are going good and I am motivating myself and planning things ahead.

Thursday, 6 October 2016

My CPC wolfenstein engine (history and progress)

I look back in my old emails and backup folders and repos, one of my biggest projects, beyond regular demos, to build a 3d maze wolfenstein engine for CPC. I was aware it's possible since coders in C64 and Spectrum have done this before and it doesn't involve anything other than fast software rendering and hard math (and a lot of sweat and tears).

Till this day I don't think it's complete, it's far ahead from the goal of perfect optimizing, part of it is still in C instead of assembly and there are few left muls and divs here and there to avoid. Meanwhile new ideas of cool things to do with this engine are coming through, only thing needed is the grand motivation to focus and work on it and hopefully a game.

Yesterday I released the first official playable preview of the engine, in four (six) flavours, you can find a download link here. You will need of course a real CPC or the Winape32 emulator and there are all the versions inside to try (64k, 128k, wolf/rpg, gx4000 cart).




So, some series of blogposts could be a good opportunity to remember the past and write my thoughts about the future, possibly motivating me to experiment more, improve things and occasionally post some progress here in the future.


  • 15th December 2010
    • It seems from my backup files, during that day I started working on some new projects and it's not just the first iteration of the wolfenstein engine (which was just the fast wall rendering algorithm without the raycasting yet) but also an unfinished 3d engine project (just rotating and projecting few 3d dots and later on rendering as points or lines). Fun fact, these were started in the old PhrozenC compiler (much much slower and more bulky in code size than the great SDCC I am currently using).
  • 29th December 2010
    • I release the first youtube preview of the engine. This is running at 25fps but that's because the math (distance of columns from camera) are precalculated data in memory for few frames. It's really the raycasting that it's costly and that's the only video where the engine looks pretty smooth but it's just wall rendering and zero math calculations. It looks nice as a teaser but the reality is a lie.
  • 10th January 2011
    • port to SDCC
  • 23th February 2011
    • First backup called Wolfenstration, so this could mean the start of my demo Wolfenstrad using the engine (Wolfenstration was ment too big for the logo designed by Voxfreax, so my brother much later said "Hey, why don't you just call it Wolfenstrad?")
  • 5th April 2011
    • Just as a parallel history (of the 3d engine I was designing for the purpose of doing flat 3d polygons, still pending) that's the day I started trying to write a triangle/polygon rasterizer. It's really a n-gon rasterizer, more suitable for flat color polygons (gouraud or texture won't interpolate evenly for each scanline unless you go triangles) of any number of edges. Used in 2d on my part in 30 years megademo. Still need to work in a future project to finally produce juicy flat and even gouraud cubes (my dream!).
  • 27th October 2011
    • It seems that during this day I started working on the RPG version of the engine, just moving one block per time and 90 degree rotations. The engine was much much slower and buggy even for that then (less than 5fps and would reset to AMSDOS at certain angles).
  • 18th March 2012
    • Wolfenstrad is released at Forever 2012 party. Finally a good use of the engine in a demo. There are many funny and interesting things about this. The real engine is still not playable (very very slow and crashing). In most of the scenes you are in a center rotating around but not moving. It's using a clever precalculating for this where 360 degrees of rays are calculating the distances before each part and you just scroll through these (but they have to be projected or fishbowl corrected to not look static). The walk through part is just precalced distance data I managed to fit. You can still realtime rotate through these scenes, so an adventure game where you fade in/out in new rooms and observe but not move would still be possible with this version. Interesting are also the effects on wall, most of them are pretty fast, based on column offset mapping tricks, an element of the engine which will be really really useful even on the game I prepare, both for fast special effects where you just change offsets of column lookup instead of changing the textures. Also suitable for fitting more textures ready for display in the limited memory and a special way to express them, so that you can have a pure wall and then a wall with a torch and then a wall with a lock without storing three times the texture. I really want to explain this feature in a future blogpost and what you can do with it, it's pretty cool!
  • 23th October 2015
    • Some weeks before this date there was a CPC gamedev competition and I thought I could maybe take part or just boost my motivation to work on this engine. I never finished the game I was planning (which I concluded it will be the rpg version now, it's an easier mode to avoid some tech problems in this engine and more interesting as a game than a pure FPS). But this compo forced me to relocate memory pages so that I have a port of the engine running on 64k CPCs. I even made a GX4000 cart version and released the first playable preview on youtube. That was the time that I used some optimization techniques to make this from unplayable to playable and fixed the problems creating crashes and some of the visual bugs but not all.
  • 9th October 2016
    • The decision was taken to upload the first playable preview so that CPCists can finally feel how the engine plays, walk near the walls (find the ugly glitches :), discover that the dream can be real (and there are still a lot to optimize and fix, this could be more smooth and nice). Such a preview was actually already shown privately at Reset demoparty although not the new RPG versions with knife weapon and ugly fading walls (the last experiments before I abandoned the project again). This is a decision I am fine with and it might release me a bit from the feeling of having worked with this sporadically for five -six years now and not having people see it in the real CPCs with their eyes. Meanwhile while doing so, looking the code again, trying to recompile, I started being inspired, thinking of some ways to fix some more bugs, how to experiment easily and fix the fade colors, try some new rendering stuff and gameplay elements I haven't thought before. I hope I will truly be motivated to work frequently with it (I have made a Trello account to organized plans and ideas for this and other projects to keep the ball rolling now) and post some blogpost or screenshot here and there.

So, truly a lot of things have happened in my life, mostly getting my master's degree, finding a new job and relocating to UK. The first version and demo was coded in Greece while I was unemployed and now remembered after I settled down here in UK. It's a long time, nice to remember how long it takes (although I wasn't working every day regularly on this, there were long pauses and comebacks).