#2 Devlog : Architecture refactor

That moment always comes. You have an idea, you start a project, maybe you whipped up a quick prototype and saw that it could work. Your head is buzzing with ideas, imagining how that video game could be, how it would look, what mechanics it would have.

It’s a unique feeling of excitement and motivation that’s hard to explain, something only those passionate about a subject understand. It’s pure creative fire; you have to at least try or let out that creativity that’s burning inside you.

You create the project and get down to work, adding content—maybe a menu, a character, an interaction system. The project is going great, progressing quickly, and on top of that, you’re taking care to follow good programming practices to a certain extent.

And then that other moment always arrives. The game grows, there’s that bug you don’t know where it comes from, that feature you don’t know in which context it should be, whether it should be in the player, the camera, a singleton… and especially that new bug that appears when you try to include something new, that bug you fix and there’s another one behind it leading you to yet another bug that was waiting.

You lose perspective, that creative fire turns into frustration, and those initial thoughts of abandoning the project run through your head. You were doing a damn good job, but overall, it’s a mess.
In my case, I’ve been there many times, but this time, quitting is not an option at all. Even though I took into account many good practices, trying to decouple everything as much as I could, there was always some hard reference pulling me from one place to another in a plate of “Dependency Spaghetti.” All this probably due to rushing or simply spending too many hours programming, not thinking clearly, and still pushing forward.

It was time to rethink the project’s structure, to think globally, since it’s practically impossible to create an adequate architecture on the first try, considering that “the perfect architecture” is, in fact, non-existent. I have to confess that all this seems by far the most complicated aspect when developing a project like this.

It was time to delve deeper into programming patterns, and even though I read the classic Game Programming Patterns a few years ago, the truth is I don’t usually follow any guide or strictly adhere to any pattern; you end up applying those patterns automatically without thinking too much, according to your needs.

I’ve noticed there’s a new trend these days of not using patterns or good practices, of getting straight to the point, writing dirty code that just works. It’s an idea I come across in many places, even with mockery towards developers who implement correct practices and ‘clean’ code.

“HAHAHA look at those show-offs, check out that sucker doing good practices”

Well, neither extreme is good; you have to find a balance and move forward, or it’s short-term gain for long-term pain. That chaotic code will come back to bite you at some point, guaranteed.

At that precise moment, I had the pleasure of having a top-notch developer (https://www.nosolopau.com/) at my place. He’s not into gamedev, but believe me, he knows about these things. After showing him the project, I shared the dilemma I had: continue development much further, wrestling with bugs, or start an important refactor now.

The truth is he gave me advice where he was absolutely right: focus on the most essential and basic stuff, deal with what I had, and face new things that I might need to refactor later.

And that’s how it went. I advanced through a swamp of bugs and inconsistencies until I reached the basic turn loop—kill, die, resurrect, etc. Once I hit that wall, I could finally start rethinking the project’s structure and the execution order of things, more firmly implementing an EventBus, an asyncronous scene loader, a generation system (Factory Pattern), and a command system (Command Pattern), which undoubtedly keeps different areas of the project separated.

It’s taken me quite a bit of time, but now everything makes more sense, and development is going much more smoothly.
It has been an exercise in patience halfway through development, but it was worth it.

Onward!

Similar Posts