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

[vfs, #3] All file reading code goes through the VFS now, new mod downloader & mod selector in place. Also a bunch of other stuff. (...)

- HTTP networking support, mods can be downloaded via the builtin downloader.
  All network activity runs in a seperate thread, which is started
  as soon as any network activity is requested.
- The master server is hard-coded to fg.wzff.de/aqmods/ if not specified otherwise;
  this setting can be overridden in the config file.
- The mod selector screen is now a grid-view for much better navigation;
  also works with joystick.
- VFS code is functionally similar to the old molebox-packed release
  for win32. The game could also have its data shipped in a Zip file
  or any other kind of archive.
- It is still possible to build without VFS support, but then the mod
  downloader and soft-patching will not be available.

The full commit history can be found here:
https://github.com/fgenesis/Aquaria_clean/compare/master...vfs

The most important commit messages follow:
[...]
    This replaces all std::ifstream with InStream, and fopen(), ... with vfopen(), ...
    Some code is #ifdef'd for better performance and less memory-copying.
    VFILE is defined to whatever type of file is in use:
    - FILE if BBGE_BUILD_VFS is not defined
    - tttvfs::VFSFile if it is.

    Other changes:
    - [un]packFile() is now unused and obsolete. That code has not been adjusted to use VFILE.
    - glpng can now load from a memory buffer.
    - TinyXML uses the VFS for reading operations now.
    - The rather clunky binary stream loading of glfont2 got replaced with ByteBuffer,
      which gets its data in one block (necessary to use the VFS without implementing
      a somewhat STL-compliant std::ifstream replacement.)
-------------
Implement loading mods from zip files.
-------------
Implement soft-patching game data files. (Replacing textures/audio/... on the fly)
-------------
Misc bits:
- Extended GUI focus handling a bit
- Fixed weirdness in texture loading... not sure but this seems more correct to me.
  Actually, considering that the texture will have its native size after restarting the game,
  the lines removed with this commit seem pretty useless.
This commit is contained in:
fgenesis 2012-06-01 17:52:19 +02:00
parent 1709503344
commit 6dc1c1e8d1
41 changed files with 2966 additions and 468 deletions

View file

@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ogg/ogg.h"
#include "vorbis/vorbisfile.h"
#include "FileAPI.h"
#include "MT.h"
#ifndef _DEBUG
@ -55,7 +56,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(FILE *fp);
OggDecoder(VFILE *fp);
// Create a decoder that streams from a memory buffer.
OggDecoder(const void *data, long data_size);
@ -106,7 +107,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.
FILE *fp;
VFILE *fp;
const char *data;
long data_size;
long data_pos; // Current read position for memory buffers
@ -145,22 +146,16 @@ 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(FILE *f,ogg_int64_t off,int whence){
static int BBGE_ov_header_fseek_wrap(VFILE *f,ogg_int64_t off,int whence){
if(f==NULL)return(-1);
#ifdef __MINGW32__
return fseeko64(f,off,whence);
#elif defined (_WIN32)
return _fseeki64(f,off,whence);
#else
return fseek(f,off,whence);
#endif
return vfseek(f,(long int)off,whence); // no ogg file is larger than 4 GB, int-cast should be ok
}
static int noclose(FILE *f) {return 0;}
static const ov_callbacks local_OV_CALLBACKS_NOCLOSE = {
(size_t (*)(void *, size_t, size_t, void *)) fread,
(size_t (*)(void *, size_t, size_t, void *)) vfread,
(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 *)) ftell
(long (*)(void *)) vftell
};
// Memory I/O callback set.
@ -256,7 +251,7 @@ void OggDecoder::decode_loop(OggDecoder *this_)
}
OggDecoder::OggDecoder(FILE *fp)
OggDecoder::OggDecoder(VFILE *fp)
{
for (int i = 0; i < NUM_BUFFERS; i++)
{
@ -586,10 +581,10 @@ namespace FMOD {
class OpenALSound
{
public:
OpenALSound(FILE *_fp, const bool _looping); // ctor for ogg streamed from file
OpenALSound(VFILE *_fp, const bool _looping); // ctor for ogg streamed from file
OpenALSound(void *_data, long _size, const bool _looping); // ctor for ogg streamed from memory
OpenALSound(ALuint _bid, const bool _looping); // ctor for raw samples already assigned an opanAL buffer ID
FILE *getFile() const { return fp; }
VFILE *getFile() const { return fp; }
const void *getData() const { return data; }
long getSize() const { return size; }
bool isLooping() const { return looping; }
@ -599,7 +594,7 @@ public:
ALuint getBufferName() const { return bid; }
private:
FILE * const fp;
VFILE * const fp;
void * const data; // Only used if fp==NULL
const long size; // Only used if fp==NULL
const bool looping;
@ -608,7 +603,7 @@ private:
ALuint bid; // only used if raw == true
};
OpenALSound::OpenALSound(FILE *_fp, const bool _looping)
OpenALSound::OpenALSound(VFILE *_fp, const bool _looping)
: fp(_fp)
, data(NULL)
, size(0)
@ -654,7 +649,7 @@ FMOD_RESULT OpenALSound::release()
else
{
if (fp)
fclose(fp);
vfclose(fp);
else
free(data);
}
@ -1155,14 +1150,14 @@ FMOD_RESULT OpenALSystem::createDSPByType(const FMOD_DSP_TYPE type, DSP **dsp)
return FMOD_ERR_INTERNAL;
}
static void *decode_to_pcm(FILE *io, ALenum &format, ALsizei &size, ALuint &freq)
static void *decode_to_pcm(VFILE *io, ALenum &format, ALsizei &size, ALuint &freq)
{
ALubyte *retval = NULL;
// Uncompress and feed to the AL.
OggVorbis_File vf;
memset(&vf, '\0', sizeof (vf));
if (ov_open(io, &vf, NULL, 0) == 0)
if (ov_open_callbacks(io, &vf, NULL, 0, local_OV_CALLBACKS_NOCLOSE) == 0)
{
int bitstream = 0;
vorbis_info *info = ov_info(&vf, -1);
@ -1222,8 +1217,7 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
strcat(fname, ".ogg");
// just in case...
#undef fopen
FILE *io = fopen(core->adjustFilenameCase(fname).c_str(), "rb");
VFILE *io = vfopen(core->adjustFilenameCase(fname).c_str(), "rb");
if (io == NULL)
return FMOD_ERR_INTERNAL;
@ -1240,7 +1234,7 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
ALsizei size = 0;
ALuint freq = 0;
void *data = decode_to_pcm(io, format, size, freq);
fclose(io);
vfclose(io);
ALuint bid = 0;
alGenBuffers(1, &bid);
@ -1255,12 +1249,12 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
else
{
// Create streaming memory decoder
fseek(io, 0, SEEK_END);
long size = ftell(io);
if (fseek(io, 0, SEEK_SET) != 0)
vfseek(io, 0, SEEK_END);
long size = vftell(io);
if (vfseek(io, 0, SEEK_SET) != 0)
{
debugLog("Seek error on " + std::string(fname));
fclose(io);
vfclose(io);
return FMOD_ERR_INTERNAL;
}
@ -1268,12 +1262,13 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
if (data == NULL)
{
debugLog("Out of memory for " + std::string(fname));
fclose(io);
vfclose(io);
return FMOD_ERR_INTERNAL;
}
long nread = fread(data, 1, size, io);
fclose(io);
long nread = vfread(data, 1, size, io);
vfclose(io);
vfclear(io);
if (nread != size)
{
debugLog("Failed to read data from " + std::string(fname));