I'm starting work on an editor for my game engine. I've found countless articles on game architecture, but I've searched everywhere and can't find anything on game EDITOR architecture. I'm using Qt to build it with, and I want to make sure it's extensible and well-written so that I don't have to come back and rewrite it later. Does anyone know of good resources with information on writing good editors?
Game editor architecture
Members - Reputation: 1166
Posted 31 August 2014 - 06:49 PM
Members - Reputation: 1942
Posted 01 September 2014 - 07:38 AM
In terms of the user interface and application structuring, I'd imagine much of the same applies as in the design or implementation of any GUI application. However what's specific to a game editor is the interaction between the game data & the editor. There are multiple possible approaches, but one that should lead to the least duplicate effort would be:
- The editor runs an instance of the game engine runtime, typically showing a viewport widget produced by the runtime, which is surrounded by the editing tools, scene structure tree widget etc.
- The editor uses the API of the game engine to manipulate the scene, just like the actual game program would (create / delete / modify / reparent objects). The runtime will also help in things like object selection with mouse (raycast)
- The engine runtime provides an introspection / reflection mechanism for the scene objects, typically in the form of attributes or properties. For example 3D scene nodes would have at least a Position (vector3), Rotation (Euler vector3 or quaternion) and Scale (vector3) attributes. The editor can use these for generic editing of any object. Scene save / load would also use the same mechanism, by just looping through all attributes of all scene objects.
If your engine runtime already uses Qt too you could use its metaobject capabilities for the introspection / reflection. Otherwise you can search for more lightweight third party alternatives, or roll your own. One result that popped up is https://github.com/jwatte/C---Introspection-and-Properties
Apologies if your engine already has a solid introspection layer, in that case most of this reply would be just restating the obvious!
Some other features or patterns that will pop up are undo / redo, and monitoring changes to the scene, in case you want to implement a play mode such as in Unity - you can see in real time as the scene tree changes.
- For undo / redo, one working approach is to abstract all modifications (create object, delete object, edit value...) as "edit actions" which have undo and redo capability. In terms of C++ these could be implemented as subclasses of an EditAction interface class.
- For monitoring scene changes and updating the GUI (scene tree etc.) correspondingly, you can use some sort of event or signal mechanism, for example have ObjectCreated, ObjectDeleted, ObjectReparented etc. events sent as they happen. In fact it may be worth it to implement these even if you don't have a live play mode, because that means you don't have to keep the editor GUI manually in sync whenever you perform some edit, but rather listening to these events keeps the GUI in sync automatically, no matter if the change comes from user input, or from the game running inside the editor.
Edit: at least one book which touches this subject to some depth, and also discusses alternate approaches such as not sharing code between the engine runtime and the editor, is the Game Engine Architecture
Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...