Monthly Archive for April, 2009

Working on OpenGTA2 fonts – part one

I worked on OpenGTA2 fonts today. As the result of my work everything is working now – it means that graphics subsystem (responsible for loading sprites and sprite data + caching), converter tools (which convert GTA2 graphics stuff into OpenGTA2 shared format), and font rendering work entirely now.

I split this post in two due to amount of work done (and it’s clearly divided into two steps).

I had few troubles on my way – the very first one I encountered looked like this:

This was a simple one, I just messed up VBO output (I wrote 4 vertexes, instead of 6 vertexes, aka two triangles), and also there was a problem with texture atlas – there was a read in the loop, something along the lines of fread((char*)entry->TextureAtlas->textureData,1,min(2048,chunkSize),TEX);, and it was reading only into first 2048 bytes of texture atlas graphics data.

So I fixed that, and this was what I saw on screen:

Okay. That is sort of font, but not quite. In fact what the hell is that thing…

I decided to perform a simple test – I made font renderer just output sprites named GTA2_0, GTA2_1 and so on. It’s known that those sprites define car graphics, and ONLY car graphics. What did I see on screen?

Oh wow, those aren’t cars at all – instead those are largest sprites in texture atlas, which means they were wrongfully exported with names GTA2_0, …. while they should have been exported with proper names.

OpenGTA2 progress

I’m feeling better today, so I worked a bit on OpenGTA2. The most major change is graphics manager – it now actually works, and is remotely useful :)

The new design of graphics manager gives it following purpose (NOTE: by “texture atlas” I mean a giant 2048×2048 texture, and by “texture” I mean a subtexture in it):

  • Graphics manager gives out texture ID by name (name can be something like GTA2_SPR325 for GTA2 sprites (but not for long, there will be replacement), STE_303 (for GTA2 map tiles), MY_OBJECT_D for custom objects)
  • Graphics manager builds texture tables on load. All found textures are loaded th
  • Graphics manager preloads all texture atlases if requested, or loads them when they are referenced
  • Graphics manager gives out OpenGL texture ID’s, or any other sort of reference
  • Graphics manager loads TEX file format – including font data (which will be passed to font manager)

I planned to add font manager, but didn’t quite get to it. Font manager uses GTA2 fonts (currently named GTA2_FONT3 etc).

I changed the actual TEX format, so it can store several sets of graphics (sprites or tiles). Difference between sprites and tiles is that tiles are always fixed size, and store no extra placement information like sprites).

There are few chunks in TEX file, like these:

ZTEX Texture file header
SPR0 GTA2-exported sprites (2048x2048 atlas)
SPR1 GTA2-exported sprites (1024x1024 atlas)
SPR2 GTA2-exported sprites (256x256 atlas)
SPR3 OpenGTA2 sprites (variable atlas size)
TILE GTA2-exported tiles (2048x2048 atlas by 64x64 tiles)
TIL1 GTA2-exported tiles (1024x1024 atlas)
TIL2 GTA2-exported tiles (256x256 atlas)
TIL3 OpenGTA2 tiles (variable tile size, variable atlas size)
FNT0 GTA2-exported fonts
FNT1 OpenGTA2 fonts (sprite based)
FNT2 OpenGTA2 fonts (with font graphics)

PACK Packed information (unpacked into different chunk)

The RMP map format didn’t change much, except maps now specify tileset names (and tile names are assumed to be TILESETNAME_123, like STE_349). Also you can pack several maps in single file now (cell coordinates are part of geometry data, not map header!).

Fizyks OS scheduling

Sorry, I got sick with something, and I’m not feeling well, so I didn’t work on any project today. Although you might be interested in something else I’m (slightly) working on for Fizyks Acylone Wiremod OS: a very simple and efficient multitasking.

It’s not usual fair multitasking, but instead it’s a very unfair and biased one. One of threads is declared foreground thread (there is API call to set foreground thread), and other ones are assumed to be background.

The task switching works as follows:

  • Even cycle: switch to foreground thread
  • Odd cycle: pick a random thread from entire thread list, and switch to it

Switches occur at same interval of 5 or 10 times per second. As you can see, foreground thread will get most of CPU time, and sometimes it even will be picked for two cycles.

This is an odd way, but reason for that is limited capability of ZCPU – task switching is relatively heavy task, and using this way I managed to decrease this time to less than 5-10% of total CPU time. Besides, it’s almost exclusively single-tasking OS, and it’s kind of similar to old Windows version (think 3.1) – it gives most of time to window in foreground, while background stuff still runs.

This should work great for when you have under 10 active threads – in about 1-2 seconds it should (in theory) cycle through all them, executing at least once.

There might be additional checks in case thread is waiting for IO response (HDDC controller from few posts ago, for example, will take about 3-10 seconds to complete IO request…).

OpenGTA2

I decided to work again on OpenGTA2.

I fixed matrices and projection stuff (the problem was in using row-major matrices instead of column-major), and also found some flaws in graphics manager.

I changed graphics manager so it indexes/links tiles/sprites by name rather than index, and stuff like that. There’s nothing much to describe right now, but there will be more tomorrow.

HDDC

Today I worked with Fizyk from wiremod.com – he is the guy working on a major BIOS & OS projects for garrysmod. They are called AlcorBIOS and Acylone (if I’m correct).

It’s a first OS to have complete FAT filesystem (he showed it to me yesterday, it works really good), and today we were testing his HDD interface – so I made a harddrive which uses CD system for storage. It has two (could be four) rays, and has 222KB or 444KB of storage.

It’s driven by two controllers – CDDC controller which runs the actual disk reading, writing, head positioning, spinning, etc, and HDDC controller which acts as interface for Fizyks computer.

This is the current HDD interface for his computer:

[0]     Execute command (write 32 to execute command)
[1]     Device on/off
[2]     Command number
[3]     Device ready/command completed successfuly
[4..17] Command parameters
[18...] Data buffer

Commands:
  0 - Return device type in [2]
  1 - Return device capacity in [2]
  2 - Read from device ([3] - start address, [4] - byte count)
  3 - Write to device ([3] - start address, [4] - byte count)

By the way, I slightly updated CDDC interface, now it looks like this:
Continue reading ‘HDDC’

WSM multiplayer

It’s an old screenshot, but recently I also fixed multiplayer game. It works correctly now, you need network adapter plug between two consoles and it’s gonna work.

Movement is synced, but powerups aren’t at the moment, and I don’t think I’m gonna change that. It just shares X-Y coordinates between two consoles, simple stuff. One of games will be played as Mario, and other one will automatically switch to Luigi.

Wired Super Mario

I decided to work a little bit on WSM. So I did the following:

  • Fixed pallete bugs (all world palletes are now proper)
  • Fixed world 4 being corrupted
  • Fixed wrong game code for some levels
  • Fixed some misc bugs

The game shouldn’t crash anywhere now, and right now all first 12 levels are fully done, including design and game code. Even the bonus levels.

The game follows a day of life of our hero – from morning to night. The time of day actually changes as he passess the levels – it’s morning on 1-1 and it’s dark night on 4-2.

Each of levels has some unique gameplay element – secret warp, moving floor, lasers, scrolling level, or a lot of neat coins. Some coins give you extra bonus but they are very tricky to get. Oh, there’s very unstable floor at some levels, it falls under you. And a bonus underwater level

The game does not have any enemies – because it’s very hard already, and limited power of ZCPU does not allow for more stuff happening on screen. You can have several lasers and elevators though.

Here are some graphics features (they are part of level design). I still have to finish functionality for POW and SHADOW blocks.

Fake shadows/ambient lighting:

(That’s a SHADOW block down there, it’s supposed to be S, not O)

Red killer plant thingy from mars:

(it kills you on touch)

Dawn, neat backgrounds:

Wire GPU new vertex buffer

I recoded vertex buffer in Wire GPU. Now it has full support of 3D graphics. Anything, any shape, everything works:

  • Z-Sorting – very fast
  • Face culling – always proper (it culls by already projected data, so it always faces camera)
  • Lighting – fully colored diffuse lighting, up to 8 lights
  • Efficient – right now the official polygon maximum is considered to be 256 polygons. That’s as much as lua can process before getting REALLY laggy

You can see three light sources shading cube here (lights are really close, so cause it lights every triangle separately, they have different shade):

I also added raster quality register, which looks like the old NES pixelization effect. I’ll try to fetch video/screenshot tomorrow (it makes everything very pixelated).