Many game engines include a command console that allows a user to issue text commands to adjust settings, get debugging information, change the state of the world and so on. The feature opens up a great deal of potential for rapid development.
However, the implementation will usually be based on a scripting language of some kind: either giving access to one already integrated or using simple custom syntax. Both of these represent significant barriers and maintenance costs. To allow you to access all the features of your engine a scripting language must be pervasively integrated, which is a lot of work - and if you've been reading this blog, you know we see a lot of disadvantages in this approach. A simple custom scripting language will also take work and will always be much less powerful.
RCC++ offers a new option: allow the user to give commands directly in C++.
We can do this by taking the text the user has entered and dropping it into a simple .cpp file, forming the content of a standard
execute() method. We can then compile this file at runtime and immediately execute it, just once, as a "snippet" of disposable code. By passing in virtual interfaces to our major subsystems we can have access to our existing functionality with very little work. In essence, anything you could do in the C++ code, you can now do on the command console.
The same crash protection discussed before allows us to catch basic crash errors, so we can use it with confidence. We can also go further: if we restrict the symbols and methods we expose, we can make it safer to use; if we write some nicer wrapper methods we can make it easier to use. This opens the way for a console friendly enough for non-programmers.
We've got some other ideas for applications of code "snippets" and making them easier for designers to use - you can expect this topic to return in future posts.