My game has in-game level editor and I've been noticing that sometimes it hurts code readability.
Here's an example: in the level editor class I have
bool drawObjects which indicates whether objects are drawn or not. If it's changed I call code like this:
renderingSystem->setDrawObjects(drawObjects)
and in rendering system I have a code like this:
void RenderingSystem::render() {
...
if(drawObjects) {
... // draw objects
}
}
Or suppose that I don't want to draw effects and shadows while in Level editor, I'll have to do this:
void RenderingSystem::render() {
...
if(!isEditingLevel) {
... // draw effects
}
...
if(!isEditingLevel) {
... // draw fog
}
}
As you can see, there's some coupling going on between LevelEditor and RenderingSystem which doesn't feel right. It also hurts readability because rendering code is now polluted with level editor stuff.
The only solution I have in mind is to have two functions:
render and
renderInLevelEditor but this may produce a lot of code duplication which is even worse.
So, what are some common ways to keep level editor code separate from main game/engine code? (Not only in rendering but everywhere else too). Maybe there are some patterns/cool articles about level editors which I need to read?