1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Revert "added partial VFS support - enough to read static data from any source"

This reverts commit fa3e9e7329.
This commit is contained in:
fgenesis 2011-09-15 19:18:53 +02:00
parent fa3e9e7329
commit 56c6833220
56 changed files with 608 additions and 4023 deletions

View file

@ -34,8 +34,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base.h"
#include "Core.h"
#include "VFSFile.h"
#include "FmodOpenALBridge.h"
#include "al.h"
@ -55,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
class OggDecoder {
public:
// Create a decoder that streams from a file.
OggDecoder(ttvfs::VFSFile *fp);
OggDecoder(FILE *fp);
// Create a decoder that streams from a memory buffer.
OggDecoder(const void *data, long data_size);
@ -100,7 +98,7 @@ private:
// Data source. If fp != NULL, the source is that file; otherwise, the
// source is the buffer pointed to by "data" with size "data_size" bytes.
ttvfs::VFSFile *fp;
FILE *fp;
const char *data;
long data_size;
long data_pos; // Current read position for memory buffers
@ -131,38 +129,22 @@ private:
// ov_open_callbacks() call. Note that we rename the fseek() wrapper
// to avoid an identifier collision when building with more recent
// versions of libvorbis.
static int BBGE_ov_header_fseek_wrap(void *f,ogg_int64_t off,int whence){
static int BBGE_ov_header_fseek_wrap(FILE *f,ogg_int64_t off,int whence){
if(f==NULL)return(-1);
ttvfs::VFSFile *vf = (ttvfs::VFSFile*)f;
switch(whence)
{
case SEEK_SET: return vf->seek(off);
case SEEK_CUR: return vf->seekRel(off);
case SEEK_END: return vf->seek(vf->size() - off);
}
return -1;
#ifdef __MINGW32__
return fseeko64(f,off,whence);
#elif defined (_WIN32)
return _fseeki64(f,off,whence);
#else
return fseek(f,off,whence);
#endif
}
static size_t BBGE_ov_fread_wrap(void *ptr, size_t s, size_t count, void *f)
{
if(f==NULL)return(-1);
ttvfs::VFSFile *vf = (ttvfs::VFSFile*)f;
size_t done = vf->read(ptr, s * count);
return done / s;
}
static long BBGE_ov_ftell_wrap(void *f)
{
if(f==NULL)return(-1);
ttvfs::VFSFile *vf = (ttvfs::VFSFile*)f;
return vf->getpos();
}
static int noclose(void *f) {return 0;}
static int noclose(FILE *f) {return 0;}
static const ov_callbacks local_OV_CALLBACKS_NOCLOSE = {
(size_t (*)(void *, size_t, size_t, void *)) BBGE_ov_fread_wrap,
(size_t (*)(void *, size_t, size_t, void *)) fread,
(int (*)(void *, ogg_int64_t, int)) BBGE_ov_header_fseek_wrap,
(int (*)(void *)) noclose, // NULL doesn't work in libvorbis-1.1.2
(long (*)(void *)) BBGE_ov_ftell_wrap
(long (*)(void *)) ftell
};
// Memory I/O callback set.
@ -174,7 +156,7 @@ static const ov_callbacks ogg_memory_callbacks = {
};
OggDecoder::OggDecoder(ttvfs::VFSFile *fp)
OggDecoder::OggDecoder(FILE *fp)
{
for (int i = 0; i < NUM_BUFFERS; i++)
{
@ -535,9 +517,9 @@ static ALenum GVorbisFormat = AL_NONE;
class OpenALSound
{
public:
OpenALSound(ttvfs::VFSFile *_fp, const bool _looping);
OpenALSound(FILE *_fp, const bool _looping);
OpenALSound(void *_data, long _size, const bool _looping);
ttvfs::VFSFile *getFile() const { return fp; }
FILE *getFile() const { return fp; }
const void *getData() const { return data; }
long getSize() const { return size; }
bool isLooping() const { return looping; }
@ -545,21 +527,20 @@ public:
void reference() { refcount++; }
private:
ttvfs::VFSFile * const fp;
FILE * const fp;
void * const data; // Only used if fp==NULL
const long size; // Only used if fp==NULL
const bool looping;
int refcount;
};
OpenALSound::OpenALSound(ttvfs::VFSFile *_fp, const bool _looping)
OpenALSound::OpenALSound(FILE *_fp, const bool _looping)
: fp(_fp)
, data(NULL)
, size(0)
, looping(_looping)
, refcount(1)
{
fp->ref++;
}
OpenALSound::OpenALSound(void *_data, long _size, const bool _looping)
@ -578,11 +559,7 @@ FMOD_RESULT OpenALSound::release()
if (refcount <= 0)
{
if (fp)
{
fp->close();
fp->dropBuf(true); // just in case there is a buffer...
fp->ref--;
}
fclose(fp);
else
free(data);
delete this;
@ -1067,6 +1044,8 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
{
assert(!exinfo);
FMOD_RESULT retval = FMOD_ERR_INTERNAL;
// !!! FIXME: if it's not Ogg, we don't have a decoder. I'm lazy. :/
char *fname = (char *) alloca(strlen(name_or_data) + 16);
strcpy(fname, name_or_data);
@ -1074,39 +1053,50 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
if (ptr) *ptr = '\0';
strcat(fname, ".ogg");
ttvfs::VFSFile *vf = core->vfs.GetFile(fname);
if(!vf)
// just in case...
#undef fopen
FILE *io = fopen(core->adjustFilenameCase(fname).c_str(), "rb");
if (io == NULL)
return FMOD_ERR_INTERNAL;
if(mode & FMOD_CREATESTREAM)
if (mode & FMOD_CREATESTREAM)
{
// does it make sense to try to stream from anything else than an actual file on disk?
// Files inside containers are always loaded into memory, unless on-the-fly partial decompression is implemented...
// A typical ogg is < 3 MB in size, if that is preloaded and then decoded over time it should still be a big gain.
if(!vf->isopen())
vf->open(NULL, "rb");
else
vf->seek(0);
*sound = (Sound *) new OpenALSound(io, (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
retval = FMOD_OK;
}
else
{
fseek(io, 0, SEEK_END);
long size = ftell(io);
if (fseek(io, 0, SEEK_SET) != 0)
{
debugLog("Seek error on " + std::string(fname));
fclose(io);
return FMOD_ERR_INTERNAL;
}
*sound = (Sound *) new OpenALSound(vf, (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
return FMOD_OK;
void *data = malloc(size);
if (data == NULL)
{
debugLog("Out of memory for " + std::string(fname));
fclose(io);
return FMOD_ERR_INTERNAL;
}
long nread = fread(data, 1, size, io);
fclose(io);
if (nread != size)
{
debugLog("Failed to read data from " + std::string(fname));
free(data);
return FMOD_ERR_INTERNAL;
}
*sound = (Sound *) new OpenALSound(data, size, (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
retval = FMOD_OK;
}
// if we are here, create & preload & pre-decode full buffer
vf->getBuf(); // force early size detection
void *data = malloc(vf->size()); // because release() will use free() ...
if (!(data && vf->getBuf()))
{
debugLog("Out of memory for " + std::string(fname));
vf->close();
vf->dropBuf(true);
return FMOD_ERR_INTERNAL;
}
memcpy(data, vf->getBuf(), vf->size());
core->addVFSFileForDrop(vf);
*sound = (Sound *) new OpenALSound(data, vf->size(), (((mode & FMOD_LOOP_OFF) == 0) && (mode & FMOD_LOOP_NORMAL)));
return FMOD_OK;
return retval;
}
ALBRIDGE(System,createStream,(const char *name_or_data, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO *exinfo, Sound **sound),(name_or_data,mode,exinfo,sound))