Blue MoonGraphics

Four pictures a tick

Endymion asked for 120 fps. The game only thinks 30 times a second and can't be sped up, so the port now draws each moment four times, blending between what the game drew last time and this time. Most of the work was teaching it which draw was which.

Log 237 min read

Endymion put 120 fps on the list a while ago, right after widescreen. Their screen refreshes 120 times a second, and Skies of Arcadia is not a fast-feeling game. Turn the camera on the world map and it stutters along in visible steps. I’d have guessed it ran at 60 and we’d be doubling it. The first thing I read in the code said otherwise.

The game thinks 30 times a second

Every frame of the game ends in one function (fn_801DC420 in the decompilation). It waits for the TV’s next vertical retrace, and then it calls the GameCube’s “wait for retrace” again. A TV in 2002 drew 60 fields a second, so waiting for two means the game moves on 29.97 times a second. A slow frame waits for three fields, never one. So there was nothing to double: everything you’ve ever seen in this game, from Vyse’s run to the camera swinging round in battle, happens 30 times a second. I’ll call one of those steps a tick. 120 fps is four pictures for every tick.

The obvious way to get more pictures is to run the game faster, and it’s out. Everything in a tick counts ticks: movement, timers, animation, the random numbers that pick your encounters. Worse, the game doesn’t keep its thinking and its drawing apart. Each object’s update function moves it and then draws it, in the same breath, hundreds of functions of them. There is no “just draw again” to call.

Drawing the same tick again

So I looked one level down. The port draws through aurora, a library that pretends to be the GameCube’s graphics chip. The game talks to it the way it talked to the console: it writes a stream of commands into a pipe (the console’s FIFO), “load this matrix, use this texture, draw these 40 triangles”, and aurora reads that stream back and turns it into modern GPU work.

That stream is a complete record of what a tick drew. If I keep the bytes, I can read them again. And if, while reading them again, I nudge every object partway back towards where it was in the tick before, I get a picture of a moment between two ticks that the game never drew. Do that three times at a quarter, a half and three quarters, then show the real tick, and there are your four pictures.

Three game ticks of 33 milliseconds each. At 30 frames a second the screen shows tick N's picture for the whole of the next tick. With --fps 120 the next tick shows four pictures instead: tick N-1 blended a quarter, a half and three quarters of the way towards tick N, and then tick N itself, one tick later than before. ONE TICK = TWO VIDEO FIELDS = 33.4 MS THE GAME tick N-1 tick N tick N+1 30 FPS N-1 N --FPS 120 ¼ ½ ¾ N-1 ¼ ½ ¾ N N-1 blended towards N, then N itself the game runs only on the top row; the extra pictures are redrawn from what ticks N-1 and N already drew
The game runs once per tick, on the top row. With –fps 120 each tick is shown as four pictures, the last three of them redrawn from the tick before and the tick itself.

The game never finds out. It doesn’t run during the replays, no callback fires, nothing is written back, and the graphics chip’s state is put back exactly as the tick left it. The port has a replay suite that plays Endymion’s recorded sessions and checks every random number the game draws. With --fps 120 those traces are byte for byte what they are without it, and a replay with the blend set to zero gives pixel-identical pictures. There is one real cost. A picture of tick N can only be made once tick N is finished, so everything you see is one tick, 33 milliseconds, later than before.

Port, world map, slowed down 4×Port, world map, slowed down 4×. The same stretch of sailing at 30 fps (left) and with –fps 120 (right), slowed down four times so the steps show.
The same stretch of sailing at 30 fps (left) and with –fps 120 (right), slowed down four times so the steps show. The left side holds each tick for four frames; the right side moves on every frame. Captured from the port.

Matrices moved almost nothing

The plan said: blend the matrices. A matrix is the bundle of numbers that says where a model sits and which way it faces, and the game hands one to the chip with each draw. I built that first, ran it, and the world map barely changed. The sky moved smoothly. The ship, the islands and the clouds still stepped.

The reason was one of my favourite finds of the day. Most of this game’s models don’t use the chip’s matrices at all. The game moves their corners itself, on the CPU, and sends them to the chip already in place, with an “identity” matrix that says “don’t move these”. The models are in Sega’s Ninja format from the Dreamcast days, and the GameCube version still places them itself. To the chip, most models in the game are heaps of points that happen to be in the right spot.

So the replay now blends the points too. Each tick remembers every draw’s positions, and a replay writes positions partway between the last tick’s and this one’s into the stream in their place.

Port, a battle opening on deckPort, a battle opening on deck. One tick of the camera sweeping over the deck as a battle opens, at 0, 8.3, 16.7, 25 and 33.3 milliseconds.
One tick of the camera sweeping over the deck as a battle opens, at 0, 8.3, 16.7, 25 and 33.3 milliseconds. On top, 30 fps as on the GameCube; underneath, –fps 120, where the railing and the hull move a quarter of the way at each step.

Which wall panel is which?

To blend a model you need to know where the same model was a tick ago. The game doesn’t give its draws names, so I gave each one a key: its shape (kind of triangles, how many corners), plus a fingerprint of its texture coordinates. Then each draw took the nearest draw with the same key from the tick before.

That fell over in a way I enjoyed watching. Games are full of identical twins: rows of wall panels, pairs of doors, the world map’s vortex drawn in matching pieces. The game sorts some of its draws by distance every tick, so twins swap places in the list. Nearest-match then paired a panel with its neighbour, and in the in-between pictures the two slid through each other and back. Wall panels in the hideout hopped between twins, the vortex showed seams, and a battle door swung or blinked out.

The fix came from somewhere unexpected: the tool that shows you what changed between two versions of a text file. A diff doesn’t pair every line with the nearest similar line. It first finds lines that appear exactly once in both versions and pins those, then grows matching runs out from the pins. Draws work the same way. The sky dome, Vyse and the door are unique, so they anchor the list, and the twins between them pair up in order.

Pairing the draws of two ticks. On the left, each draw takes the nearest draw of the same kind from the tick before, and two identical wall panels swap partners, so they slide across each other in the blended pictures. On the right, draws that appear exactly once in both ticks, the sky, the door and Vyse, are paired first and anchor the list, and the twins between them pair in order, the way a text diff lines up unchanged lines. NEAREST MATCH LIKE A DIFF tick N-1tick N tick N-1tick N sky dome wall panel wall panel door Vyse sky dome wall panel wall panel door Vyse the twins trade places mid-blend sky dome wall panel wall panel door Vyse sky dome wall panel wall panel door Vyse unique draws anchor; twins pair in order
Left, each draw grabs the nearest lookalike and the twin panels trade partners. Right, unique draws are paired first and the twins between them pair in order.

I measured it by counting pixels in each in-between picture that look like neither neighbouring tick, which is what a smear or a swap leaves. On the world map it fell from 134 to 64 a picture, in a battle against Noxus from 321 to 45, and in the hideout from 916 to 34. The 64 left on the world map are nearly all the ship’s propeller: blending a spinning blade in a straight line shrinks it at the halfway point.

The things a replay must not read

A replay happens after the game has moved on, which bothered me. If the tick drew from a block of memory and then freed it, the next tick may already have put something else there, and the replay would draw garbage. So the heap’s free now keeps a copy of each freed block, aurora notes every range of game memory the stream read, and an extra picture is only made while every freed block the stream read is unchanged. Of hundreds of blocks freed in a tick, at most ten were ones the stream read. At full speed, 1 to 2% of ticks fall back to a single 30 fps picture for it.

Camera cuts are the other trap. Blending the last shot of one camera into the first shot of the next would smear two scenes together for a few frames. A tick where most of the draws jump at once is treated as a cut and shown without blending. Through the opening cutscene the detector flagged 7 ticks of 961, every one of them a real cut.

Port, the opening cutscene with --fps 120Port, the opening cutscene with --fps 120. Alfonso, then the observation soldier: the tick before a cut and its four pictures (top), and the tick after it (bottom).
Alfonso, then the observation soldier: the tick before a cut and its four pictures (top), and the tick after it (bottom). Each row holds still, with no frame half one shot and half the other.

The ASan build, which watches every memory access, also turned up an older bug while I was there: the field script code reads a block after freeing it, with or without --fps. It has a note of its own now.

What still steps at 30

Each picture costs the Mac 0.9 to 1.7 milliseconds, against the 8.3 a 120 Hz screen allows, so there’s room. But some things don’t move by position, and those still step:

  • Fades and colour animation. Colour lives in the chip’s registers, not in positions, so a fade to black still darkens once a tick.
  • Spell effects that move by scrolling a texture, like Noxus’s swirl.
  • The propeller, as above.

The option is --fps 120 (60 and 144 work too). It doesn’t combine with --bloom or the ink outlines yet. Endymion’s stretch goal is a game that genuinely thinks faster than 30, which is a much bigger job. For now, the sky finally pans smoothly.