On Linear Code and Functional Programming WRT Games

A friend sent me this old email from John Carmack talking about how his habits had changed over time to be less modular and less reusable to combat a primary source of bugs: invalid input state.

http://number-none.com/blow/blog/programming/2014/09/26/carmack-on-inlined-code.html


This has honestly connected a lot of dots for me and makes a ton of sense. Something that has been holding me back with my engine implementation for Chronicles had been attempting to modularize and snapshot and delegate everything to keep it clean.

Part of my combat actions system requires some extremely complex operations involving simulating entire game states from potential decisions and part of what was making that really hard was not just treating game state as a pure functional input every frame.

Hard to get detailed on this without just doing a code review. I'm just kind of excited to do some fairly straightforward refactor to get my board state into the sort of place where I can start using it as a trivially copyable object.

This whole thing gives me some much needed guidance on just where to put everything and what the general rules are for how data is supposed to be stored and when it's allowed to be modified. It makes me a lot less anxious about scaling upward!

Maybe next week I can show some of this working with some really complex combat simulations,

Wouldn't that be cool considering I first started working on combat actions in mid-September.

Edit: Follow-up

Happy to say that this refactor is going very well. Turning my game state into a trivially copyable object with limited rules for modification opens up a ton of possibilities for existing systems, future systems, and debug tools.

One neat thing is I can pause the game live, and step it forward one frame at a time. And as a debug utility I can just store every frame and have a slider that just let's me roll back to a previous state. Wild! You see this in emulators and such but never imagined having it for a personal game project. I'll have to show this working with cool gifs soon.

#gamedev #chron4

| 🌐 | 🙋‍ | @britown@blog.brianna.town