The Wonj

Devlog 7: a day of cleaning house

No new features today. After a week of building fast, the RPG got a day of cleaning house: code nothing used is gone, the longest functions read as a list of named steps, and the two creators share one set of buttons. Nothing about the game looks or plays any differently, and that was the point.

Why stop

The Wonj read through the engine's code, file by file, and a few ideas in it clicked on the way:

Each of those deserves a write-up of its own, and may get one. Reading it all also showed where the code had grown untidy, which is what the rest of the day went on.

Sakura trees in blossom on green terraced hills above sandy ground, with oaks and snowy pine slopes behind, seen from the air.

What went

A whole way of drawing that nothing used any more is gone: its own mesh type, its own list of things to draw, a cube and a square that never appeared, and the shaders that went with them. So is a header file nothing included. Comments that pointed at code which had since moved now point at where it lives, and a few that described how things used to work now say how they work.

Long functions, as named steps

The function that builds a town had grown into one long block, nested so deep that the code for placing a building sat far to the right of the screen. It now reads top to bottom in the order a town is built: choose its kinds of building, place the square, lay out the roads out of town, fill the rim of the square, line the roads, grow the roads, add a fountain, level the ground, and stamp the buildings in. Each step is a function of its own with a name that says what it does.

The same went for the Object Creator's input handling, the drawing of each frame, the game's main loop and the way a body moves: each now reads as its steps, with every drawing call still in the same order as before.

Proof nothing changed

Tidying code is only safe if nothing changes, so the town builder was checked the hard way: every town in several whole worlds was built with the old code and the new, and they came out byte for byte identical.

Shaders that share

The sky and the lit world both need to know the sky's colours, and each shader kept its own copy, with a note to change both together. GLSL, the language shaders are written in, has no way to include one file in another, so the engine now adds its own: the sky's code lives in one file, and the engine pastes it in where a shader asks for it. When a shader has an error, the message still points at the right file and line.

Sunrise over snowy pines and green hills, the sun low and white on the horizon. Midday under a bright blue sky, the sun high and haloed above the player on a chimney top among pines. Dusk over the same hills: a deep blue sky with the first stars and a pink glow along the horizon. Night: a full moon and stars over dark trees and snow lit a pale blue.

The creators share their buttons

The Object Creator and the Sound Maker each drew their own buttons, text fields, name rules and "are you sure?" cards, and the copies had already started to disagree: one took an underscore in a name and the other didn't. They now share one set. A name takes letters, digits and hyphens in both, with the same longest length, and holding Backspace repeats in both.

The player gliding high under the glider beside a bright sun, over green hills and a pale cliff, with pines and snow in the haze below.

Back to building next time.