Michael Pidde => { Programmer(); }

Development Console

I took a slight detour lately in my game and built in a REPL style development console. As you can imagine if you've ever played a modern PC game and poked around under the hood a bit, I can use this to enhance my debugging and play testing capabilities by allowing quick ability to modify game state. I can load different maps, change sound settings, toggle collision - the possibilities are as broad as my desire to build them.

The way I'm storing valid commands is in an unordered_map which uses the command as the key and a struct of metadata as the value. An entry looks like this:

{"collision", {validation_types::BIT, [](Types::state_t &state, std::string v) {
        bool value = (bool)std::stoi(v);
        Trigger::collision(state, value);
    }
}},

The metadata struct takes an enum value for the validation type and a lambda callback which gets called if command validation passes. The lambda does nothing more than cast the command argument(s) accordingly (the casting has already been validated which is why I'm not doing redundant error checking there), and then kicks them out to a Trigger function. The Trigger namespace houses a bunch of disparate event functions as an undignified messenger between subsystems. I plan on reworking this code over time into a more graceful design, but for right now it's working. One of the goals of this project, programmatically speaking, is to only architect what is necessary. I will take the time to go back and rearchitect pain points since I have the luxury of time and hindsight; I've already done this time and again.

Here's a gameplay video showing the console in action.

(https://www.bitchute.com/video/ywJi0ZnF8LnP/)

Code Stats

-------------------------------------------------------------------------------
C++                             18            232             87           1910
C/C++ Header                    31            128             18           1148
JavaScript                       2             80             35            559
PHP                              3             15             16             88
JSON                             4              0              0             82
DOS Batch                        3              5              0             30
Bourne Shell                     1              0              0              5
-------------------------------------------------------------------------------
SUM:                            62            460            156           3822
-------------------------------------------------------------------------------