summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2005-04-10 14:16:58 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2005-04-10 14:16:58 +0000
commit26d50af0fb1b07e662978f7c341a3c2548074840 (patch)
tree548619f2a360bcef9227bbde4aa1592128a48e53 /src/resources/resourcemanager.cpp
parentb42e9e23fd6fe4819d34f04124ba66eca6a6c020 (diff)
downloadmana-26d50af0fb1b07e662978f7c341a3c2548074840.tar.gz
mana-26d50af0fb1b07e662978f7c341a3c2548074840.tar.bz2
mana-26d50af0fb1b07e662978f7c341a3c2548074840.tar.xz
mana-26d50af0fb1b07e662978f7c341a3c2548074840.zip
Resource manager can now load sfx and music as samples.
(added a new sfx to test the sound engine)
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index cc5c9562..47c4daa4 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -95,7 +95,24 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
logger.log("Warning: Map resource not supported.");
break;
case MUSIC:
- logger.log("Warning: Music resource not supported.");
+ {
+ // Load the music resource file
+ int fileSize;
+ void *buffer = loadFile(idPath, fileSize);
+
+ if (buffer != NULL)
+ {
+ // Let the music class load it
+ resource = reinterpret_cast<Resource*>(Music::load(buffer,
+ fileSize));
+
+ // Cleanup
+ free(buffer);
+ }
+ else {
+ logger.log("Warning: resource doesn't exist!");
+ }
+ }
break;
case IMAGE:
{
@@ -115,9 +132,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
else {
logger.log("Warning: resource doesn't exist!");
}
-
}
-
break;
case SCRIPT:
logger.log("Warning: Script resource not supported.");
@@ -126,7 +141,24 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
logger.log("Warning: Tileset resource not supported.");
break;
case SOUND_EFFECT:
- logger.log("Warning: Sound FX resource not supported.");
+ {
+ // Load the sample resource file
+ int fileSize;
+ void *buffer = loadFile(idPath, fileSize);
+
+ if (buffer != NULL)
+ {
+ // Let the sound effect class load it
+ resource = reinterpret_cast<Resource*>(SoundEffect::load(
+ buffer, fileSize));
+
+ // Cleanup
+ free(buffer);
+ }
+ else {
+ logger.log("Warning: resource doesn't exist!");
+ }
+ }
break;
default:
logger.log("Warning: Unknown resource type");
@@ -153,6 +185,16 @@ Image *ResourceManager::getImage(const std::string &idPath, int flags)
return (Image*)get(IMAGE, idPath, flags);
}
+Music *ResourceManager::getMusic(const std::string &idPath)
+{
+ return (Music*)get(MUSIC, idPath, 0);
+}
+
+SoundEffect *ResourceManager::getSoundEffect(const std::string &idPath)
+{
+ return (SoundEffect*)get(SOUND_EFFECT, idPath, 0);
+}
+
ResourceManager* ResourceManager::getInstance()
{
// Create a new instance if necessary.