16
General / [SOLVED]Reducing coupling between game code and level editor code?
« on: May 02, 2016, 12:39:23 pm »
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:
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?
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:...
if(drawObjects) {
... // draw objects
}
}
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....
if(!isEditingLevel) {
... // draw effects
}
...
if(!isEditingLevel) {
... // draw fog
}
}
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?