Introducing Stagemaster
In order to take a small break from thinking about economics, while still doing something useful for it, I decided to work on engine code for creating user interfaces.
Although the prototypes thus far already contained a pretty flexible and nice system for complicated mouse interactions with objects in the 3D game world (creating, selecting, modifiying roads and lanes with drag and drop), keyboard interaction was pretty rough and 2D user interfaces (buttons, texts, info windows, menus, ...) were pretty much nonexistent.
Both Herbstein and kingoflolz, two of my most avid contributors, already went great lengths towards better keyboard interaction (such as rebindable key bindings) and their ideas were a direct inspiration to what I ended up implementing.
Regarding the 2D user interface part, I originally planned to write a UI library from the ground up, just like I did for interaction with the 3D world. But then, in the spirit of keeping things simple, I decided that I don't really need to revolutionize good ol' button-clicking and text-showing and instead opted to use an existing 2D user interface library.
I decided to use "dear imgui", a library that's really popular with game developers and already contains a huge catalogue of useful controls like sliders, scrollable windows, ... pretty much whatever you will ever need. People create all kinds of simple and complex UIs with it.
Even though using "dear imgui" would save me a lot of work, integrating it still brought some challenges:
- marriage to the actor system (a difficult marriage, since "dear imgui" is the oldschool "everything is global & single threaded", and the actor system is the new and wild "everything is happening at once")
- deciding when to give mouse & keyboard events to "dear imgui" and when to the 3D user interface (basically: "when are you clicking on a button and when are you clicking into the world?")
- Making "dear imgur" use the Citybound text font and make that look nice on glorious retina displays
- Choosing some nice colors for the UI
But the biggest challenge was probably:
- All the existing code for 3D world interaction, handling keyboard events and displaying debug messages and telling the renderer what to draw was all over the place.
- It became clear that this old responsibilities plus the new 2D user interface code really all belonged in one place.
So I unified all of that and called it Stagemaster, which is now the one and only part of the engine to:
- handle mouse and keyboard input
- convert that into 3D world or 2D interface interaction
- draw the 2D UI
- handle camera control
- offer loading and saving of user preferences
- offer rebindable key bindings for all different parts of the game and a quick way to create a settings UI
Here is the first screenshot of Stagemaster in action:
As you can see, it shows the debug info we all know and love, as well as a fully-functional control settings menu for camera control and plan editing!
The best thing is that with this set up, it is now really easy for me to add all kinds of UI.
This will not only mean that I will finally put a stronger focus on that in the upcoming prototypes, but also that I will be able to write some really nice inspection and debug UI to look at individual households and companies while developing the economy simulation.
What else I did in the past couple days:
- Working on a unificaiton/redesign of the homepage & blog using Webflow, which will make it much more pleasant for me to write blog posts, update the homepage and make everything look much nicer in general
- Already started a little bit with implementing the new economy simulation model - stay tuned for more
As always, let me know what you think!