aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl/sdl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/platform/sdl/sdl.cpp')
-rw-r--r--backends/platform/sdl/sdl.cpp99
1 files changed, 50 insertions, 49 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 5c3b87309d..9abaa3c6fb 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -196,6 +196,7 @@ OSystem_SDL::OSystem_SDL()
_soundMutex(0), _soundCond(0), _soundThread(0),
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
#endif
+ _fsFactory(0),
_savefile(0),
_mixer(0),
_timer(0),
@@ -213,6 +214,19 @@ OSystem_SDL::OSystem_SDL()
memset(&_mouseCurState, 0, sizeof(_mouseCurState));
_inited = false;
+
+
+ #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
}
OSystem_SDL::~OSystem_SDL() {
@@ -254,17 +268,8 @@ Common::SaveFileManager *OSystem_SDL::getSavefileManager() {
}
FilesystemFactory *OSystem_SDL::getFilesystemFactory() {
- #if defined(__amigaos4__)
- return &AmigaOSFilesystemFactory::instance();
- #elif defined(UNIX)
- return &POSIXFilesystemFactory::instance();
- #elif defined(WIN32)
- return &WindowsFilesystemFactory::instance();
- #elif defined(__SYMBIAN32__)
- // Do nothing since its handled by the Symbian SDL inheritance
- #else
- #error Unknown and unsupported backend in OSystem_SDL::getFilesystemFactory
- #endif
+ assert(_fsFactory);
+ return _fsFactory;
}
static Common::String getDefaultConfigFileName() {
@@ -292,20 +297,19 @@ static Common::String getDefaultConfigFileName() {
CreateDirectory(configFile, NULL);
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
- if (fopen(configFile, "r") == NULL) {
+ FILE *tmp = NULL;
+ if ((tmp = fopen(configFile, "r")) == NULL) {
// Check windows directory
char oldConfigFile[MAXPATHLEN];
GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
- if (fopen(oldConfigFile, "r")) {
- printf("The default location of the config file (scummvm.ini) in ScummVM has changed,\n");
- printf("under Windows NT4/2000/XP/Vista. You may want to consider moving your config\n");
- printf("file from the old default location:\n");
- printf("%s\n", oldConfigFile);
- printf("to the new default location:\n");
- printf("%s\n\n", configFile);
+ if ((tmp = fopen(oldConfigFile, "r"))) {
strcpy(configFile, oldConfigFile);
+
+ fclose(tmp);
}
+ } else {
+ fclose(tmp);
}
} else {
// Check windows directory
@@ -334,23 +338,13 @@ static Common::String getDefaultConfigFileName() {
}
Common::SeekableReadStream *OSystem_SDL::openConfigFileForReading() {
- Common::File *confFile = new Common::File();
- assert(confFile);
- if (!confFile->open(getDefaultConfigFileName())) {
- delete confFile;
- confFile = 0;
- }
- return confFile;
+ FilesystemNode file(getDefaultConfigFileName());
+ return file.openForReading();
}
Common::WriteStream *OSystem_SDL::openConfigFileForWriting() {
- Common::DumpFile *confFile = new Common::DumpFile();
- assert(confFile);
- if (!confFile->open(getDefaultConfigFileName())) {
- delete confFile;
- confFile = 0;
- }
- return confFile;
+ FilesystemNode file(getDefaultConfigFileName());
+ return file.openForWriting();
}
void OSystem_SDL::setWindowCaption(const char *caption) {
@@ -435,15 +429,21 @@ void OSystem_SDL::quit() {
}
void OSystem_SDL::setupIcon() {
- int w, h, ncols, nbytes, i;
- unsigned int rgba[256], icon[32 * 32];
- unsigned char mask[32][4];
+ int x, y, w, h, ncols, nbytes, i;
+ unsigned int rgba[256];
+ unsigned int *icon;
sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes);
- if ((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1)) {
- warning("Could not load the icon (%d %d %d %d)", w, h, ncols, nbytes);
+ if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) {
+ warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes);
+ return;
+ }
+ icon = (unsigned int*)malloc(w*h*sizeof(unsigned int));
+ if (!icon) {
+ warning("Could not allocate temp storage for the built-in icon");
return;
}
+
for (i = 0; i < ncols; i++) {
unsigned char code;
char color[32];
@@ -457,26 +457,27 @@ void OSystem_SDL::setupIcon() {
sscanf(color + 1, "%06x", &col);
col |= 0xFF000000;
} else {
- warning("Could not load the icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
+ warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
+ free(icon);
return;
}
rgba[code] = col;
}
- memset(mask, 0, sizeof(mask));
- for (h = 0; h < 32; h++) {
- const char *line = scummvm_icon[1 + ncols + h];
- for (w = 0; w < 32; w++) {
- icon[w + 32 * h] = rgba[(int)line[w]];
- if (rgba[(int)line[w]] & 0xFF000000) {
- mask[h][w >> 3] |= 1 << (7 - (w & 0x07));
- }
+ for (y = 0; y < h; y++) {
+ const char *line = scummvm_icon[1 + ncols + y];
+ for (x = 0; x < w; x++) {
+ icon[x + w * y] = rgba[(int)line[x]];
}
}
- SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32, 32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
- SDL_WM_SetIcon(sdl_surf, (unsigned char *) mask);
+ SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, w, h, 32, w * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
+ if (!sdl_surf) {
+ warning("SDL_CreateRGBSurfaceFrom(icon) failed");
+ }
+ SDL_WM_SetIcon(sdl_surf, NULL);
SDL_FreeSurface(sdl_surf);
+ free(icon);
}
OSystem::MutexRef OSystem_SDL::createMutex(void) {