Homunculus Devlog 2018-05-05

Tags:
By Max Woerner Chase

In this post:


Okay, here's the deal. It's 9:30 PM right now, and I haven't had a chance to touch the code, let alone write anything up. I'm going to put this up, poke at the code a little, and publish by midnight GMT. I just do not want to force my way through this right now.

One thing to keep in mind for later is effect. It looks like someone did a lot of the hard work in making something like what I envisioned for replacing all the plumbed-in TDL calls.

Okay, so here's where things stand after a good night's sleep. I realized that the way I was trying to convert the main loop to an object wasn't working, so I deleted that attempt. Instead, I started modifying the function directly. First, I consolidated all of its non-rendering-related arguments into a "Game" object. Then, I moved it to the beginning and renamed it "self", and brought it into the "Game" class. I divided the new method into a top-level loop that takes the rendering variables, and goes into an infinite loop of rendering, and stepping. The step function does not take the rendering arguments, so that's a really good sign.

Split out some functions, then realized that I'd like to try moving the message log up a level, turn the step function into a generator. The hurdle here is that the step function currently has some return values that the program uses. I turned the return value into another instance variable, simplified control flow a bit, and converted more of the code to using generators.

Of course, I do all that and find I've managed to introduce a bug from all the rewrites. I managed to miss one change from local variable to instance variable. Looks like everything else is okay, though.

I've now divided up a monolithic function into many smaller components that don't mingle scope so much. I think I need to take some time to evaluate the code, see what looks scary now.


Next week, I should probably rank the remainder of the code by how big the functions are. Big functions are suspect because they almost certainly mingle concerns that are possible to separate.