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:
- Skipping what the camera can't see takes only the planes of its view, read straight out of the same matrix that draws the picture, so what's skipped can never disagree with what's shown.
- The threads that build land in the background stay safe by touching only copies they were handed, never the game itself.
- The world's noise is a pure function of position and seed, so the same land comes out whichever order the threads happen to build it in.
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.
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.
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.
Back to building next time.
Thoughts or feedback? I'd love to hear them at thewonjdev@gmail.com.