I didn’t realise you could use Graphics without Engine. Now it makes sense to me why SDL was initialised like that.
Might I suggest moving SDL_Init()
into the Context
class? Depending on whether SDL should be initialised in headless mode or not, SDL_Init()
could be called in the constructor or explicitly. For instance, here’s what the explicit method might look like:
Graphics::Graphics(Context* context) :
Object(context),
// more stuff
{
context_->RequireSDL(SDL_INIT_VIDEO);
}
Graphics::~Graphics()
{
context_->ReleaseSDL();
}
Context
would take care of initialising the various SDL systems by using SDL_WasInit()
and additionally keep a global “reference count” of how many times SDL was initialised, so it knows when to call SDL_Quit().
The audio subsystem would similarly call context_->RequireSDL()
but pass in SDL_INIT_AUDIO.
Of course, the lazy solution could be to call SDL_Init(SDL_INIT_EVERYTHING)
in the constructor of Context
and be done with it.