Sound loading from memory (by using a quick hack)
authorPerttu Ahola <celeron55@gmail.com>
Sun, 25 Mar 2012 12:52:43 +0000 (15:52 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 25 Mar 2012 12:52:43 +0000 (15:52 +0300)
src/game.cpp
src/sound_openal.cpp

index aff1f19845514a48f411069f22247ba6c11e8bca..d6c9910be0432c7688696fbd933b62adc0bae447 100644 (file)
@@ -972,31 +972,6 @@ void the_game(
        SoundMaker soundmaker(sound, nodedef);
        soundmaker.registerReceiver(&eventmgr);
        
-       // Preload sounds
-#if 0
-       sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_grass_walk1.ogg");
-       sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_grass_walk2.ogg");
-       sound->loadSound("default_grass_footstep", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_grass_walk3.ogg");
-       
-       sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_dig_crumbly1.ogg");
-       sound->loadSound("default_dig_crumbly", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_dig_crumbly2.ogg");
-       
-       sound->loadSound("default_dig_cracky", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_dig_cracky1.ogg");
-       
-       sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_place_node1.ogg");
-       sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_place_node2.ogg");
-       sound->loadSound("default_place_node", porting::path_share + DIR_DELIM
-                       + "sounds" + DIR_DELIM + "default_place_node3.ogg");
-#endif
-
        // Add chat log output for errors to be shown in chat
        LogOutputBuffer chat_log_error_buf(LMT_ERROR);
 
index f7bce6546d73d9ba1a371ec6684bf94b5084ed0f..e635e0fa17e840088e0aa3afa9e86b33b86dc241 100644 (file)
@@ -41,6 +41,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
 #include <map>
 #include <vector>
 #include "utility.h" // myrand()
+#include "filesys.h"
 
 #define BUFFER_SIZE 30000
 
@@ -434,9 +435,18 @@ public:
        bool loadSoundData(const std::string &name,
                        const std::string &filedata)
        {
-               errorstream<<"OpenALSoundManager: Loading from filedata not"
-                               " implemented"<<std::endl;
-               return false;
+               // The vorbis API sucks; just write it to a file and use vorbisfile
+               // TODO: Actually load it directly from memory
+               std::string basepath = porting::path_user + DIR_DELIM + "cache" +
+                               DIR_DELIM + "tmp";
+               std::string path = basepath + DIR_DELIM + "tmp.ogg";
+               verbosestream<<"OpenALSoundManager::loadSoundData(): Writing "
+                               <<"temporary file to ["<<path<<"]"<<std::endl;
+               fs::CreateAllDirs(basepath);
+               std::ofstream of(path.c_str(), std::ios::binary);
+               of.write(filedata.c_str(), filedata.size());
+               of.close();
+               return loadSoundFile(name, path);
        }
 
        void updateListener(v3f pos, v3f vel, v3f at, v3f up)