Skip to content

Integrating to your own codebase

Doug Binks edited this page Feb 2, 2020 · 10 revisions

The Runtime Compiled C++ Dear ImGui and DirectX11 Tutorial showcases how to convert a Windows Dear ImGui example to using RCC++. Most of the code changes, with the exception of Visual Studio project setup, are applicable to cross platform / non windows projects.

Short teaser of Runtime Compiled C++ Dear ImGui and DirectX11 Example

Project Setup

To integrate to your own codebase, you will need to include the following projects:

  • RuntimeCompiler
  • RuntimeObjectSystem

To add support for new compilers or operating systems you'll need to alter or add a compiler based on the Compiler.h header, and for new operating systems add a file monitor based on the IFileMonitor.h header.

The RuntimeObjectsystem could optionally be replaced with your own system should you desire a different methodology, for example function based.

We have found that on gcc under Linux the path embedded in code is relative to the compile dir, in this case set the define COMPILE_PATH="$(PWD)/";

With Visual Studio compiler make sure to compile with "/FC" option in order to get full filenames.

Basic code infrastructure

For a basic integration which doesn't include passing interfaces to your engine through a systems table, and also lacks support for error handling via runtime exceptions, see the ConsoleExample. The SimpleTest shows a more complete integration to a simple game engine.

The main steps in your code required are:

  • Create a instance of class RuntimeObjectSystem.
  • Initialise the RuntimeObjectSystem. The compiler log and system table parameters can be NULL.
  • Regularly call RuntimeObjectSystem::GetFileChangeNotifier()->Update(dt), where dt is the time difference since it was last called.
  • Regularly check if a compile has been completed via RuntimeObjectSystem::GetIsCompiledComplete() and load the module if desired through RuntimeObjectSystem::LoadCompiledModule()

Interfacing to other code

Three basic methods exist to interface to other code (other than using headers).

  1. For C++ code which can be sensibly used through a virtual interface (or for structures of C function pointers) we recommend Using the SystemTable to pass interfaces to Runtime Compiled Code.
  2. For large C or C++ libraries we recommend linking Using libraries from Runtime Modifiable Classes.
  3. For smaller pieces of code, you can use Runtime Source Dependencies.