diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/resourcemanager.cpp | 74 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 6 |
2 files changed, 21 insertions, 59 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a884f63e..50d0f4b8 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -84,82 +84,44 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath) logger->log("ResourceManager::get(%s)", idPath.c_str()); + int fileSize; + void *buffer = loadFile(idPath, fileSize); + + if (!buffer) { + logger->log("Warning: resource doesn't exist!"); + return NULL; + } + Resource *resource = NULL; // Create an object of the specified type. switch (type) { - case MAP: - logger->log("Warning: Map resource not supported."); - break; case MUSIC: { - // Load the music resource file - int fileSize; - void *buffer = loadFile(idPath, fileSize); - - if (buffer != NULL) - { - // Let the music class load it - resource = Music::load(buffer, fileSize); - - // Cleanup - free(buffer); - } - else { - logger->log("Warning: resource doesn't exist!"); - } + // Let the music class load it + resource = Music::load(buffer, fileSize); } break; case IMAGE: { - // Load the image resource file - int fileSize; - void *buffer = loadFile(idPath, fileSize); - - if (buffer != NULL) - { - // Let the image class load it - resource = Image::load(buffer, fileSize); - - // Cleanup - free(buffer); - } - else { - logger->log("Warning: resource doesn't exist!"); - } + // Let the image class load it + resource = Image::load(buffer, fileSize); } break; - case SCRIPT: - logger->log("Warning: Script resource not supported."); - break; - case TILESET: - logger->log("Warning: Tileset resource not supported."); - break; case SOUND_EFFECT: { - // Load the sample resource file - int fileSize; - void *buffer = loadFile(idPath, fileSize); - - if (buffer != NULL) - { - // Let the sound effect class load it - resource = SoundEffect::load(buffer, fileSize); - - // Cleanup - free(buffer); - } - else { - logger->log("Warning: resource doesn't exist!"); - } + // Let the sound effect class load it + resource = SoundEffect::load(buffer, fileSize); } break; - default: - logger->log("Warning: Unknown resource type"); + default: + /* Nothing to do here, just avoid compiler warnings... */ break; } + free(buffer); + if (resource) { resource->incRef(); resource->setIdPath(idPath); diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index f95acadc..e3ad1e94 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -42,11 +42,11 @@ class ResourceManager */ enum E_RESOURCE_TYPE { - MAP, + //MAP, MUSIC, IMAGE, - SCRIPT, - TILESET, + //SCRIPT, + //TILESET, SOUND_EFFECT }; |