diff options
author | Alejandro Marzini | 2010-05-29 01:56:34 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-05-29 01:56:34 +0000 |
commit | 16c559a095af85a7f553912461cf4468366070a7 (patch) | |
tree | 3eeb87b664a87b1bb313c87139c655abf269080b /backends/platform | |
parent | 6b3d268e23713eba0356599e8ac6e926e3315148 (diff) | |
download | scummvm-rg350-16c559a095af85a7f553912461cf4468366070a7.tar.gz scummvm-rg350-16c559a095af85a7f553912461cf4468366070a7.tar.bz2 scummvm-rg350-16c559a095af85a7f553912461cf4468366070a7.zip |
Added again base-backend. Started sdl backend refatoring, file, mutex and timer subsystems created.
svn-id: r49305
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/sdl/file.cpp | 235 | ||||
-rw-r--r-- | backends/platform/sdl/file.h | 67 | ||||
-rw-r--r-- | backends/platform/sdl/mutex.cpp | 83 | ||||
-rw-r--r-- | backends/platform/sdl/mutex.h | 69 | ||||
-rw-r--r-- | backends/platform/sdl/timer.cpp | 121 | ||||
-rw-r--r-- | backends/platform/sdl/timer.h | 69 |
6 files changed, 644 insertions, 0 deletions
diff --git a/backends/platform/sdl/file.cpp b/backends/platform/sdl/file.cpp new file mode 100644 index 0000000000..a8dd230059 --- /dev/null +++ b/backends/platform/sdl/file.cpp @@ -0,0 +1,235 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#if defined(WIN32) +#include <windows.h> +// winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h +#undef ARRAYSIZE +#endif + +#include "backends/platform/sdl/file.h" +#include "common/archive.h" + +#ifdef UNIX + #include "backends/saves/posix/posix-saves.h" +#else + #include "backends/saves/default/default-saves.h" +#endif + +/* + * Include header files needed for the getFilesystemFactory() method. + */ +#if defined(__amigaos4__) + #include "backends/fs/amigaos4/amigaos4-fs-factory.h" +#elif defined(UNIX) + #include "backends/fs/posix/posix-fs-factory.h" +#elif defined(WIN32) + #include "backends/fs/windows/windows-fs-factory.h" +#endif + + +#if defined(UNIX) +#ifdef MACOSX +#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences" +#elif defined(SAMSUNGTV) +#define DEFAULT_CONFIG_FILE "/dtv/usb/sda1/.scummvmrc" +#else +#define DEFAULT_CONFIG_FILE ".scummvmrc" +#endif +#else +#define DEFAULT_CONFIG_FILE "scummvm.ini" +#endif + +SdlSubSys_File::SdlSubSys_File() + : + _inited(false), + _fsFactory(0), + _savefile(0) { + +} + +SdlSubSys_File::~SdlSubSys_File() { +} + +void SdlSubSys_File::fileInit(OSystem *mainSys) { + if (_inited) { + return; + } + _mainSys = mainSys; + + // Create the savefile manager, if none exists yet (we check for this to + // allow subclasses to provide their own). + if (_savefile == 0) { + #ifdef UNIX + _savefile = new POSIXSaveFileManager(); + #else + _savefile = new DefaultSaveFileManager(); + #endif + } + +#if defined(__amigaos4__) + _fsFactory = new AmigaOSFilesystemFactory(); +#elif defined(UNIX) + _fsFactory = new POSIXFilesystemFactory(); +#elif defined(WIN32) + _fsFactory = new WindowsFilesystemFactory(); +#elif defined(__SYMBIAN32__) + // Do nothing since its handled by the Symbian SDL inheritance +#else + #error Unknown and unsupported FS backend +#endif + + _inited = true; +} + +void SdlSubSys_File::fileDone() { + delete _savefile; +} + +bool SdlSubSys_File::hasFeature(Feature f) { + return false; +} + +void SdlSubSys_File::setFeatureState(Feature f, bool enable) { + +} + +bool SdlSubSys_File::getFeatureState(Feature f) { + return false; +} + +Common::SaveFileManager *SdlSubSys_File::getSavefileManager() { + assert(_savefile); + return _savefile; +} + +FilesystemFactory *SdlSubSys_File::getFilesystemFactory() { + assert(_fsFactory); + return _fsFactory; +} + +void SdlSubSys_File::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { + +#ifdef DATA_PATH + // Add the global DATA_PATH to the directory search list + // FIXME: We use depth = 4 for now, to match the old code. May want to change that + Common::FSNode dataNode(DATA_PATH); + if (dataNode.exists() && dataNode.isDirectory()) { + s.add(DATA_PATH, new Common::FSDirectory(dataNode, 4), priority); + } +#endif + +#ifdef MACOSX + // Get URL of the Resource directory of the .app bundle + CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); + if (fileUrl) { + // Try to convert the URL to an absolute path + UInt8 buf[MAXPATHLEN]; + if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) { + // Success: Add it to the search path + Common::String bundlePath((const char *)buf); + s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority); + } + CFRelease(fileUrl); + } + +#endif + +} + +static Common::String getDefaultConfigFileName() { + char configFile[MAXPATHLEN]; +#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) + OSVERSIONINFO win32OsVersion; + ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO)); + win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&win32OsVersion); + // Check for non-9X version of Windows. + if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) { + // Use the Application Data directory of the user profile. + if (win32OsVersion.dwMajorVersion >= 5) { + if (!GetEnvironmentVariable("APPDATA", configFile, sizeof(configFile))) + error("Unable to access application data directory"); + } else { + if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile))) + error("Unable to access user profile directory"); + + strcat(configFile, "\\Application Data"); + CreateDirectory(configFile, NULL); + } + + strcat(configFile, "\\ScummVM"); + CreateDirectory(configFile, NULL); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + + FILE *tmp = NULL; + if ((tmp = fopen(configFile, "r")) == NULL) { + // Check windows directory + char oldConfigFile[MAXPATHLEN]; + GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); + if ((tmp = fopen(oldConfigFile, "r"))) { + strcpy(configFile, oldConfigFile); + + fclose(tmp); + } + } else { + fclose(tmp); + } + } else { + // Check windows directory + GetWindowsDirectory(configFile, MAXPATHLEN); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); + } +#elif defined(UNIX) + // On UNIX type systems, by default we store the config file inside + // to the HOME directory of the user. + // + // GP2X is Linux based but Home dir can be read only so do not use + // it and put the config in the executable dir. + // + // On the iPhone, the home dir of the user when you launch the app + // from the Springboard, is /. Which we don't want. + const char *home = getenv("HOME"); + if (home != NULL && strlen(home) < MAXPATHLEN) + snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE); + else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#else + strcpy(configFile, DEFAULT_CONFIG_FILE); +#endif + + return configFile; +} + +Common::SeekableReadStream *SdlSubSys_File::createConfigReadStream() { + Common::FSNode file(getDefaultConfigFileName()); + return file.createReadStream(); +} + +Common::WriteStream *SdlSubSys_File::createConfigWriteStream() { + Common::FSNode file(getDefaultConfigFileName()); + return file.createWriteStream(); +} diff --git a/backends/platform/sdl/file.h b/backends/platform/sdl/file.h new file mode 100644 index 0000000000..4f23a06594 --- /dev/null +++ b/backends/platform/sdl/file.h @@ -0,0 +1,67 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_SDL_SUBSYS_FILE_H +#define BACKENDS_SDL_SUBSYS_FILE_H + +#include "backends/base-subsys-file.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +class SdlSubSys_File : public BaseSubSys_File { +public: + SdlSubSys_File(); + ~SdlSubSys_File(); + + virtual void fileInit(OSystem *mainSys); + virtual void fileDone(); + + bool hasFeature(Feature f); + void setFeatureState(Feature f, bool enable); + bool getFeatureState(Feature f); + + virtual Common::SeekableReadStream *createConfigReadStream(); + virtual Common::WriteStream *createConfigWriteStream(); + + virtual Common::SaveFileManager *getSavefileManager(); + virtual FilesystemFactory *getFilesystemFactory(); + virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); + +protected: + bool _inited; + + FilesystemFactory *_fsFactory; + Common::SaveFileManager *_savefile; + +private: + OSystem *_mainSys; +}; + + +#endif diff --git a/backends/platform/sdl/mutex.cpp b/backends/platform/sdl/mutex.cpp new file mode 100644 index 0000000000..ce9eef6a96 --- /dev/null +++ b/backends/platform/sdl/mutex.cpp @@ -0,0 +1,83 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "backends/platform/sdl/mutex.h" + +SdlSubSys_Mutex::SdlSubSys_Mutex() + : + _inited(false) { + +} + +SdlSubSys_Mutex::~SdlSubSys_Mutex() { + if (_inited) { + mutexDone(); + } +} + +void SdlSubSys_Mutex::mutexInit(OSystem *mainSys) { + if (_inited) { + return; + } + _mainSys = mainSys; + + _graphicsMutex = createMutex(); + + _inited = true; +} + +void SdlSubSys_Mutex::mutexDone() { + deleteMutex(_graphicsMutex); + + _inited = false; +} + +bool SdlSubSys_Mutex::hasFeature(Feature f) { + return false; +} + +void SdlSubSys_Mutex::setFeatureState(Feature f, bool enable) { + +} + +bool SdlSubSys_Mutex::getFeatureState(Feature f) { + return false; +} + +OSystem::MutexRef SdlSubSys_Mutex::createMutex() { + return (MutexRef) SDL_CreateMutex(); +} + +void SdlSubSys_Mutex::lockMutex(MutexRef mutex) { + SDL_mutexP((SDL_mutex *) mutex); +} + +void SdlSubSys_Mutex::unlockMutex(MutexRef mutex) { + SDL_mutexV((SDL_mutex *) mutex); +} + +void SdlSubSys_Mutex::deleteMutex(MutexRef mutex) { + SDL_DestroyMutex((SDL_mutex *) mutex); +} diff --git a/backends/platform/sdl/mutex.h b/backends/platform/sdl/mutex.h new file mode 100644 index 0000000000..9479aa9ece --- /dev/null +++ b/backends/platform/sdl/mutex.h @@ -0,0 +1,69 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_SDL_SUBSYS_MUTEX_H +#define BACKENDS_SDL_SUBSYS_MUTEX_H + +#include "backends/base-subsys-mutex.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +class SdlSubSys_Mutex : public BaseSubSys_Mutex { +public: + SdlSubSys_Mutex(); + ~SdlSubSys_Mutex(); + + virtual void mutexInit(OSystem *mainSys); + virtual void mutexDone(); + + bool hasFeature(Feature f); + void setFeatureState(Feature f, bool enable); + bool getFeatureState(Feature f); + + // Mutex handling + MutexRef createMutex(); + void lockMutex(MutexRef mutex); + void unlockMutex(MutexRef mutex); + void deleteMutex(MutexRef mutex); + +protected: + bool _inited; + + /** + * Mutex which prevents multiple threads from interfering with each other + * when accessing the screen. + */ + MutexRef _graphicsMutex; + +private: + OSystem *_mainSys; +}; + + +#endif diff --git a/backends/platform/sdl/timer.cpp b/backends/platform/sdl/timer.cpp new file mode 100644 index 0000000000..a6dfc67918 --- /dev/null +++ b/backends/platform/sdl/timer.cpp @@ -0,0 +1,121 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "backends/platform/sdl/timer.h" +#include "backends/timer/default/default-timer.h" +#include "common/EventRecorder.h" +#include <time.h> // for getTimeAndDate() + +static Uint32 timer_handler(Uint32 interval, void *param) { + ((DefaultTimerManager *)param)->handler(); + return interval; +} + +SdlSubSys_Timer::SdlSubSys_Timer() + : + _inited(false), + _timerID(), + _timer(0) { + +} + +SdlSubSys_Timer::~SdlSubSys_Timer() { + if (_inited) { + timerDone(); + } +} + +void SdlSubSys_Timer::timerInit(OSystem *mainSys) { + if (_inited) { + return; + } + _mainSys = mainSys; + + if (SDL_InitSubSystem(SDL_INIT_TIMER) == -1) { + error("Could not initialize SDL Timer: %s", SDL_GetError()); + } + + // Create and hook up the timer manager, if none exists yet (we check for + // this to allow subclasses to provide their own). + if (_timer == 0) { + // Note: We could implement a custom SDLTimerManager by using + // SDL_AddTimer. That might yield better timer resolution, but it would + // also change the semantics of a timer: Right now, ScummVM timers + // *never* run in parallel, due to the way they are implemented. If we + // switched to SDL_AddTimer, each timer might run in a separate thread. + // However, not all our code is prepared for that, so we can't just + // switch. Still, it's a potential future change to keep in mind. + _timer = new DefaultTimerManager(); + _timerID = SDL_AddTimer(10, &timer_handler, _timer); + } + + _inited = true; +} + +void SdlSubSys_Timer::timerDone() { + delete _timer; + SDL_RemoveTimer(_timerID); + SDL_QuitSubSystem(SDL_INIT_TIMER); + + _inited = false; +} + +bool SdlSubSys_Timer::hasFeature(Feature f) { + return false; +} + +void SdlSubSys_Timer::setFeatureState(Feature f, bool enable) { + +} + +bool SdlSubSys_Timer::getFeatureState(Feature f) { + return false; +} + +uint32 SdlSubSys_Timer::getMillis() { + uint32 millis = SDL_GetTicks(); + g_eventRec.processMillis(millis); + return millis; +} + +void SdlSubSys_Timer::delayMillis(uint msecs) { + SDL_Delay(msecs); +} + +void SdlSubSys_Timer::getTimeAndDate(TimeDate &td) const { + time_t curTime = time(0); + struct tm t = *localtime(&curTime); + td.tm_sec = t.tm_sec; + td.tm_min = t.tm_min; + td.tm_hour = t.tm_hour; + td.tm_mday = t.tm_mday; + td.tm_mon = t.tm_mon; + td.tm_year = t.tm_year; +} + +Common::TimerManager *SdlSubSys_Timer::getTimerManager() { + assert(_timer); + return _timer; +} diff --git a/backends/platform/sdl/timer.h b/backends/platform/sdl/timer.h new file mode 100644 index 0000000000..1d15b5ad98 --- /dev/null +++ b/backends/platform/sdl/timer.h @@ -0,0 +1,69 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_SDL_SUBSYS_TIMER_H +#define BACKENDS_SDL_SUBSYS_TIMER_H + +#include "backends/base-subsys-timer.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +class SdlSubSys_Timer : public BaseSubSys_Timer { +public: + SdlSubSys_Timer(); + ~SdlSubSys_Timer(); + + virtual void timerInit(OSystem *mainSys); + virtual void timerDone(); + + bool hasFeature(Feature f); + void setFeatureState(Feature f, bool enable); + bool getFeatureState(Feature f); + + // Get the number of milliseconds since the program was started. + uint32 getMillis(); + + // Delay for a specified amount of milliseconds + void delayMillis(uint msecs); + + virtual void getTimeAndDate(TimeDate &t) const; + virtual Common::TimerManager *getTimerManager(); + +protected: + bool _inited; + + SDL_TimerID _timerID; + Common::TimerManager *_timer; + +private: + OSystem *_mainSys; +}; + + +#endif |