Graphics Conversion / Data Generation

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

The very next step is to write a tool - I'll do it in Python - to convert the mockup graphics I've just drawn into C data structures for the game. In particular, I'll be converting to characters in a character set. The characters in the engine are simply a bunch of bytes, in the "ChronoColour" format. This is essentially triplets of bytes representing "red", "green", and "blue" for each scanline of the character.  Given the mockup graphics are indicating 5 trixels width and 11 trixels depth is pretty nice, that's going to be the size of our characters.  I'll write the tool to grab a full character set from an arbitrary "image set" such as shown in the image. The "drawing" of shapes in the set will then be simply putting the appropriate character # (mostly 2 bytes per car) into the "board".

Here's a sample character from Sokoban - which uses 5-wide and 10-trixel-deep characters.

static const unsigned char char_box_deadlocked[CHAR_HEIGHT] = {

    0b00011111,     /*0*/
    0b00011111,
    0b00011111,
    0b00010100,     /*1*/
    0b00000100,
    0b00011111,
    0b00011111,     /*1*/
    0b00001110,
    0b00011111,
    0b00011010,     /*2*/
    0b00001010, \
    0b00011111, \
    0b00010011,     /*3*/
    0b00000010,
    0b00011111,
    0b00010110,     /*4*/
    0b00000110,
    0b00011111,
    0b00010101,     /*5*/
    0b00000100,
    0b00011111,
    0b00010000,     /*6*/
    0b00000000,
    0b00011111,
    0b00010101,     /*7*/
    0b00000100,
    0b00011111,
    0b00011111,     /*8*/
    0b00000000,
    0b00011111
};

The comments such as /*5*/ indicate that this is the start of a trixel (5), which consists of 3 bytes (RGB). Incidentally, ChronoColour just places those bytes on successive scan lines when drawing the character. iCC "rolls" through the bytes, changing the order of those 3 every frame.  So on frame 1 it's ABC, frame 2 it's BCA and frame 3 it's CAB ... and then back to frame 1 for the next. That's pretty much the only difference between ChronoColour and iCC; the rolling of the colours *for each trixel line* from the character set definition.

In this case, the 3 upper bits of each byte are unused. The draw system self-adjusts for the character set width. This game will use 5 trixels, but the systems handle up to 8.  I have a "large" character shape, and a "medium and small" character shape for each actual character. The medium is 3-wide by 9-deep trixels and can be merged with the large character if we have enough bit free; a shape definition can go in any of the bits.  Here we're using the low 5 bits, but using the high 5 bits is fine; the draw system does the appropriate bit shifting at runtime.

For now, it's time to write the tool. I'll share the source code as it's going to be reasonably small iI hope.

Specs:
- accept any image filename (including wildcards) on the command line
- accept character size (x,y) on the command line
- load all images and process
- processing means to step through each character position in the grid of (x,y) size shapes
- the pixels in each position form a "character" - add to the "character set" we're building
- put the character number in our output grid
- once we've done all positions in the source image, output the character set and usage to source code



Andrew Davie

#1
OK, tool written and confirmed working!  Source code and output attached, for the curious.
Essentially it takes any source image (8-colour palettised) and produces correct character set data for the iCC engine. The screenshot shows the very first working version; in fact it worked first time. Though it doesn't look like much, what we're seeing here is correctly formed characters being drawn, and if you look carefully you can identify those characters in the source image (also attached) as parts of cars towards the top left.  The output c-file also includes the mapping from screen/grid position to actual character number to use - so you can figure out which characters to draw for which car.
I expect nobody but me cares.



Andrew Davie

#2
A quick update/test. I used the character number usage grid from test.c to put characters on the board, and lo and behold the cars are all drawn correctly as per the original image. I'm tempted to retro-fit this tool into Sokoban and earlier games, because it makes modifying character data visual rather than typing 0's and 1's which was always super-confusing.

Andrew Davie

Had a bit of fun drawing "cars" - and playing with colours. I think it's going to look OK, one just has to think of these as vehicles of some sort. Anyway, time to move on to the next step, which will be separating out each vehicle into its own little structure, so that I can simply draw a vehicle by indexing the type, and the draw will look up the vehicle character matrix shape, and plonk that on the screen. After that, I can start thinking about moving vehicles around the screen. That will be reasonably straightforward; I'll copy the ROM vehicle graphics into a ram buffer containing up to 3 characters; and then I'll shift the data inside that RAM copy, for drawing. It will look pretty good.


Andrew Davie

I refined the random colour selections. Mainly because I'm too lazy to do anything meaningful.
Next thing, I think I should start work on the "fine" movement of cars; that is, allowing them to move a trixel at a time, rather than blocky character-based movement.