At some point of engine lifetime full debug builds become unplayable. This leads to solutions like fast debug builds and such, but they limit your ability to hunt down bugs. In some situations full debug builds is the must to do the job.
Fortunately, there is a
simple solution.
Dividing your engine into modules allows you to run separate modules in different modes. So you can run everything in release mode and one single module in full debug mode. With 10-12 modules slowdown from single module (except may be renderer) will be unnoticed. Bingo!
Some details
Divide your engine into modules, like
Rendering,
Physics,
Animation,
Sound,
Scripts,
UI,
Networking,
Resources,
Scene Management and one central module I'm calling
Main. You can add more modules freely, but don't divide it too much. Like your brand new flash player can be added to
UI instead of creating new module.
Compile them all as DLLs that have different names for different levels of debugging. I have four basic configurations:
- Full Debug (let's call is Debug);
- Release with profiling code and turned off Omit Frame Pointers (let's call it Profile);
- Full Speed release build (let's call it Release);
- Full Speed release compiled as static library for DRM protected final builds;
Ignore configuration number 4 at this point as it has limited use. So UI module will compile into 3 versions:
UI_Debug.dll,
UI_Profile.dll and
UI_Release.dll.
The trick here is to add into
Main module the ability to load different versions of the same module by user request. In case of GEM I just show the following window when Shift is pressed on start of the
Main module:
This dialog is shown only in debug version of
Main module. Simple as that.
For games and demos that use GEM I'm creating two additional projects.
Launcher (exe) links with appropriate version of
Main module.
Game module contains all game logic and implements specific game interface. In this way
Game module can be loaded by GEM and we are getting
very nice bonus: ability to play the game inside the editor without any additional code (more on this later).
This approach has 3 major drawbacks:
- You need to define a lot of pure interface files as modules will interconnect only through them. But if you ask me, I think that this organization leads to much cleaner engine structure from external point of view. And you can get DX9/DX11/OpenGL/NULL renderers without much effort (yikes!). It can be frustrating to press "Go to definition" and get into interface file instead of implementation, though;
- As modules can be run in different modes you can't pass between them classes that behave differently in debug and release builds (like STL). For example std::string in release mode module can try to reallocate memory allocated in debug mode module. This will lead to crash. In practice this is not a big deal, if interfaces are defined only by limited set of people;
- If user changes something in say renderer module, that is used in release configuration, but current configuration in VS is set to debug - renderer module will be updated only for debug configuration and this can lead to undefined behavior. It's rare issue on practice, though.
Good point for large scale engines from this organization is the ability of the tech team to publish engine in SDK mode. It means you compile everything into DLLs and LIBs, add interface files and publish this to game production teams. In most cases they just don't have anything to mess with inside engine code.