From 307d7aeb4fc044d925295b6ed1d4c7c359a99920 Mon Sep 17 00:00:00 2001 From: Alejandro Marzini Date: Thu, 24 Jun 2010 17:37:09 +0000 Subject: Added a init function to OSystem_SDL for early backend setup, and so allowing better sub classing. svn-id: r50224 --- backends/platform/sdl/main.cpp | 6 ++++++ backends/platform/sdl/posix/main.cpp | 6 ++++++ backends/platform/sdl/posix/posix.cpp | 6 ++++++ backends/platform/sdl/posix/posix.h | 2 ++ backends/platform/sdl/sdl.cpp | 22 +++++++++++++--------- backends/platform/sdl/sdl.h | 6 ++++++ backends/platform/sdl/win32/main.cpp | 6 ++++++ backends/platform/sdl/win32/win32.cpp | 6 ++++++ backends/platform/sdl/win32/win32.h | 2 ++ 9 files changed, 53 insertions(+), 9 deletions(-) (limited to 'backends/platform/sdl') diff --git a/backends/platform/sdl/main.cpp b/backends/platform/sdl/main.cpp index 75e535428a..75d248841e 100644 --- a/backends/platform/sdl/main.cpp +++ b/backends/platform/sdl/main.cpp @@ -40,13 +40,19 @@ int main(int argc, char *argv[]) { g_system = new OSystem_SDL(); assert(g_system); + // Pre initialize the backend + ((OSystem_SDL *)g_system)->init(); + #ifdef DYNAMIC_MODULES PluginManager::instance().addPluginProvider(new SDLPluginProvider()); #endif // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); + + // Free OSystem delete (OSystem_SDL *)g_system; + return res; } diff --git a/backends/platform/sdl/posix/main.cpp b/backends/platform/sdl/posix/main.cpp index cf1bc6ff2f..5f734e6b0e 100644 --- a/backends/platform/sdl/posix/main.cpp +++ b/backends/platform/sdl/posix/main.cpp @@ -37,13 +37,19 @@ int main(int argc, char *argv[]) { g_system = new OSystem_POSIX(); assert(g_system); + // Pre initialize the backend + ((OSystem_POSIX *)g_system)->init(); + #ifdef DYNAMIC_MODULES PluginManager::instance().addPluginProvider(new SDLPluginProvider()); #endif // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); + + // Free OSystem delete (OSystem_POSIX *)g_system; + return res; } diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index aec36de910..e92a4398d9 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -44,8 +44,14 @@ #define DEFAULT_CONFIG_FILE ".scummvmrc" OSystem_POSIX::OSystem_POSIX() { +} + +void OSystem_Win32::init() { // Initialze File System Factory _fsFactory = new POSIXFilesystemFactory(); + + // Invoke parent implementation of this method + OSystem_SDL::init(); } void OSystem_POSIX::initBackend() { diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 2e87709598..a8d5e9a23b 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -33,6 +33,8 @@ public: OSystem_POSIX(); virtual ~OSystem_POSIX() {} + virtual void init(); + virtual void initBackend(); protected: diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index e9b35fae32..85506c9520 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -54,18 +54,25 @@ OSystem_SDL::~OSystem_SDL() { deinit(); } -void OSystem_SDL::initBackend() { - // Check if backend has not been initialized - assert(!_inited); - +void OSystem_SDL::init() { // Initialize SDL initSDL(); - // Creates the backend managers, if they don't exist yet (we check - // for this to allow subclasses to provide their own). + // Creates the early needed managers, if they don't exist yet + // (we check for this to allow subclasses to provide their own). if (_mutexManager == 0) _mutexManager = new SdlMutexManager(); + if (_timerManager == 0) + _timerManager = new SdlTimerManager(); +} + +void OSystem_SDL::initBackend() { + // Check if backend has not been initialized + assert(!_inited); + + // Creates the backend managers, if they don't exist yet (we check + // for this to allow subclasses to provide their own). if (_eventManager == 0) _eventManager = new SdlEventManager(this); @@ -79,9 +86,6 @@ void OSystem_SDL::initBackend() { _mixerManager->init(); } - if (_timerManager == 0) - _timerManager = new SdlTimerManager(); - if (_graphicsManager == 0) _graphicsManager = new SdlGraphicsManager(); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index ec6432830b..8740b82b9f 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -41,6 +41,12 @@ public: OSystem_SDL(); virtual ~OSystem_SDL(); + /** Pre-initialize backend, it should be called after + * instantiating the backend. Early needed managers + * are created here. + */ + virtual void init(); + virtual void initBackend(); virtual Common::HardwareKeySet *getHardwareKeySet(); diff --git a/backends/platform/sdl/win32/main.cpp b/backends/platform/sdl/win32/main.cpp index 6c0508835e..ffabeffc9d 100644 --- a/backends/platform/sdl/win32/main.cpp +++ b/backends/platform/sdl/win32/main.cpp @@ -50,13 +50,19 @@ int main(int argc, char *argv[]) { g_system = new OSystem_Win32(); assert(g_system); + // Pre initialize the backend + ((OSystem_Win32 *)g_system)->init(); + #ifdef DYNAMIC_MODULES PluginManager::instance().addPluginProvider(new SDLPluginProvider()); #endif // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); + + // Free OSystem delete (OSystem_Win32 *)g_system; + return res; } diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 0eb4c467b4..4d585add77 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -47,8 +47,14 @@ #define DEFAULT_CONFIG_FILE "scummvm.ini" OSystem_Win32::OSystem_Win32() { +} + +void OSystem_Win32::init() { // Initialze File System Factory _fsFactory = new WindowsFilesystemFactory(); + + // Invoke parent implementation of this method + OSystem_SDL::init(); } Common::String OSystem_Win32::getDefaultConfigFileName() { diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index 2bcb0c59b3..eea7f9ee12 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -33,6 +33,8 @@ public: OSystem_Win32(); ~OSystem_Win32() {} + void init(); + protected: Common::String getDefaultConfigFileName(); }; -- cgit v1.2.3