Programming rambles

Since I don't have a "blog", this page will have some programming problems I've encountered and thought were interesting.

Isometric Z layering with rising ground height

One of the interesting challenges when working on RR was making the terrain rendering work correctly. At first glance it seems like a normal problem that everyone has already solved, but because the floor in this game can be raised and be in front of things, units move smoothly from one tile to another (as opposed to changing position instantly), and units/buildings can be very tall and placed anywhere, it becomes a lot more complicated than typical isometric games.

In this example, the tiles 1 and 2 are both on the same horizontal position, but one of them needs to be drawn in front of the tower, and another needs to be drawn behind it. Both of them including the tower needs to be drawn behind the tank.

You cannot solve it by increasing the render order of raised up tiles, because otherwise the raised tile will be drawn on top of the tank. There's some very wide buildings and units in this game so you would have to raise the render order a lot. For similar reasons, you cannot solve it by drawing "cubes" on top of each other and increasing the rendering order of the cubes that are on top. The radio tower is quite tall and would be rendered under some tall cubes behind it.

Here's a more complex situation. The big pad needs to be in front of all the tiles under and behind it, but behind all the tiles in front and to the sides. But on top of that, the large red tank unit is going on top of the pad, so it needs to be drawn in front of the pad, but also behind one of the side tiles.

Because units can move, you cannot split them into multiple parts to solve this problem. Even if it was possible, it would be a lot of work both artistically and in terms of programming to split all the sprites and their animation frames into many parts.

The solution I came up with was this:

The sprites are split vertically in real-time. For each entity, you find the bottom-most tile that it's on top of (including all tiles it's moving between), and then draw new vertical slices at the sides for each tile, each slice having the z layer of the next adjacent tile.

Additionally (this isn't visible in the screenshots), the render order of the slices will inherit the render order of entities under it. For example the red tank above is on top of the pad, so the left-most tank slice would be drawn in front of the middle slice of the healing pad. The right corner of the red tank isn't on top of the pad so it would be drawn normally on top of tile B. The "back" corner of the tank is ignored, it's drawn in the same slices along with the front corner.

There may be unforeseen consequences to this that I haven't realized yet, but I think it should work fine.

You cannot make horizontal holes into the terrain with this system, but that won't be necessary anyway.