Thanks, Jabberwocky!
Yeah, let's not discuss singletones.
Here's a thing I want to discuss: Manager classes.
There are some useful managers in my game: ResourceManager, LogManager, LuaScriptManager, etc.
I store pointers to them in a global structure named
engine_system.
struct EngineSystem {
LogManager* log;
... // etc.
}
To write something in log, I need to do it like this:
engine_system.log->write("Something happened");
This allows me to do some cool stuff, like making FileLogManager and ConsoleLogManager and then replace simple LogManager with FileLogManager which writes to file. Or, I can create NullLog which will ignore all the messages.
This is a Service Locator pattern. So, here are the things I want to discuss
1) How do I make a better interface to this? Maybe I should do something like this?
engine_system.getLog()->write(...);
Or maybe there are better alternatives?
2) Avoiding usage of global engine_system.
Sometimes I can pass needed managers to functions, like this:
void handleInput(const InputManager& inputManager);
But sometimes there's no such possibility, because it's hard to predict which managers will be needed (especially hard with virtual functions!)
So, what are your tips on dealing with this?