Saturday, November 6, 2021

Hands-on Rust by Herbert Wolverson Part 1

 

I've been chasing the Rust programming language for well over 4 years now. The language, to me, feels complex but in a fun and rewarding way. Previous languages that I've worked with have done their jobs respectfully but have never felt they are special. The easiest way I can equate it is:

I have a hammer and I use it for hammering nails. I use that hammer and I put it away, done. Most languages I've used have felt like a hammer.

Rust feels like using I'm using my workbench and all the tools on it. I'm not just mundanely pounding with a hammer or drilling with a drill. I am giving thought to what I'm creating, using different tools in their proper manner, and finally have created something that works as intended.

Less about my general rust adventures though and more about "Hands-on Rust, Effective Learning through 2D Game Development and Play" by Herbert Wolverson. I had worked on Wovlerson's previous RLTK tutorial way back in my earlier stages of playing with Rust and trying game development. Games have always been a passion of mine, but I never realized how hard it actually was to build a game. I've written dozens of enterprise applications for business class services but have yet to create a single game...I've come close!

Hands-On Rust takes similar concepts from the RLTK tutorials but cleans it up and polishes it in book form. Additionally, the RLTK tutorials focus on his libraries and roguelike game development, where as Hands-On Rust instead tries to bring you along with general Rust language concepts as well. This is both rewarding and mildly taxing depending on your skill level. A few times I've had to force myself to go back and focus on what he was explaining because I chose to skim and transcribe the tutorial pieces. I did this because I had the Rust knowledge that was being explained, however I was losing out on the game concept knowledge he was also conveying.

The chapters are very well organized and work you through many concepts of programming. A few times he has you do mild refactoring which is good. This is a concept that is always necessary in development but not necessarily developed.

ECS (Entity Component System)

The biggest reason I bought this book was because of two main concepts he conveys to you through the chapters. ECS and minimalist game development. ECS is a new(er) style of game engine development meant for decoupling Entities (things that have components), Components (the attributes that entities posses) and the Systems that dictate what Entities and resources do. The ECS engine that Wolverson uses in this book is Legion ECS, which is part of the Amethyst project. There are various comparisons out on the web of different ECS's. The reason I lean towards Legion is its ease of use. I played with Legion prior to learning about this book and was able to do some really cool things incorrectly. After reading through about half of the book I have a much more solid foundation to use to go back and rework my little simulator I was creating.

The joy of ECS is that you can expand your game without major refactoring efforts. Object oriented game engines require frameworks for inheritance which can potentially translate to unintended consequences if you add new features. ECS assumes that all things are considered individually and that you act upon only the things you care about. This means that if I add features to a player Entity, say I care about their height and weight now, the Systems act on the player character will not care about the height and weight until I specifically tell the Systems about it. Adding height and weight in object oriented approaches means that these values could unintentionally be accessed because they are now made available to all things that inherit the "Player" object.

Minimalist Development

Another joy of this book is that Wolverson introduces how to use his libraries to build out games in a way that modeling and testing ideas is not a major endeavor. Prototyping ideas and expanding on them are easy when you have the basic building blocks to model with. Wolverson's Bracket-lib Rust library leverages all sorts of different ASCII, 2D, 3D toolings, however you're not required to dig deep into the graphics and design requirements to get started. To me this is very important. I have notebooks full of game ideas but I struggle with the larger engines and the need to be a "completionist" with my ideas. This happened with Godot, which is an engine I also enjoy thoroughly. I struggled with Godot though because of the indirect ability to use Rust which seemed more complicated than jumping to Godot's native language or C#. Not that I couldn't use those languages, I just don't want to.

Bracket-lib fills a perfect niche where an idea can be born and developed, shared, tested, and eventually grown into something larger. Using ECS and Bracket-lib, along with the guidance from Wolverson's book, enables basic and advanced developers to create as individuals without the need for a larger production effort.

Final Thoughts

The one thing I would wish more from Wolverson is more accessibility to a side-by-side of the book and online code. This may be a timing or work/effort issue. An example is that the RLTK code and examples are extensive and very thorough, in a sense I don't even need a book there. This does not necessarily translate financially for Wolverson and we all need to be rewarded for our labors, especially labors of love. Wolverson's RLTK/Specs documentation is especially complete. His documentation for Bracket-lib and Legion is somewhat sparse. I am taking for granted that I am not the one that has to maintain either of these efforts and he is only one man. Maybe my take away from this should be expanding his Bracket-lib/legion examples with what I've learned from his book and pushing that to him to review.

Thank you Herbert Wolverson!

Edit:

This will be a multipart post as I want to revisit the topic when I finish the book. I'm about half way through it now.