Remove no-op mapgen::add_random_objects
[oweals/minetest.git] / src / sound_openal.cpp
index f7bce6546d73d9ba1a371ec6684bf94b5084ed0f..8d76b69e16621105b6fdb0cbb8048fa1e8721589 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
 
@@ -115,9 +116,14 @@ SoundBuffer* loadOggFile(const std::string &filepath)
        char array[BUFFER_SIZE]; // Local fixed size array
        vorbis_info *pInfo;
        OggVorbis_File oggFile;
-
+       
+       // Do a dumb-ass static string copy for old versions of ov_fopen
+       // because they expect a non-const char*
+       char nonconst[10000];
+       snprintf(nonconst, 10000, "%s", filepath.c_str());
        // Try opening the given file
-       if(ov_fopen(filepath.c_str(), &oggFile) != 0)
+       //if(ov_fopen(filepath.c_str(), &oggFile) != 0)
+       if(ov_fopen(nonconst, &oggFile) != 0)
        {
                infostream<<"Audio: Error opening "<<filepath<<" for decoding"<<std::endl;
                return NULL;
@@ -434,9 +440,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)