1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 14:34:34 +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

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Base.h"
#include "Core.h"
#include <algorithm>
#ifdef BBGE_BUILD_WINDOWS
#include <shellapi.h>
@ -272,31 +273,35 @@ std::string upperCase(const std::string &s1)
return ret;
}
bool exists(const std::string &f, bool makeFatal)
bool exists(const std::string &f, bool makeFatal, bool skipVFS)
{
/*
if (!PHYSFS_exists(f.c_str()))
{
*/
/*
std::ostringstream os;
os << "checking to see if [" << f << "] exists";
debugLog(os.str());
*/
bool e = false;
FILE *file = fopen(core->adjustFilenameCase(f).c_str(), "rb");
if (!file)
#ifdef BBGE_BUILD_VFS
if (!skipVFS)
{
e = !!vfs.GetFile(f.c_str());
}
else
#endif
if (!e)
{
std::string tmp = core->adjustFilenameCase(f);
FILE *file = fopen(tmp.c_str(), "rb");
if (file)
{
if (makeFatal)
{
errorLog(std::string("Could not open [" + f + "]"));
exit(0);
}
return false;
e = true;
fclose(file);
}
fclose(file);
//}
return true;
}
if (makeFatal && !e)
{
errorLog(std::string("Could not open [" + f + "]"));
exit(0);
}
return e;
}
void drawCircle(float radius, int stepSize)
@ -446,13 +451,22 @@ void debugLog(const std::string &s)
// also obtain the data length by passing a pointer to an unsigned long
// as the (optional) second parameter. The buffer should be freed with
// delete[] when no longer needed.
char *readFile(std::string path, unsigned long *size_ret)
char *readFile(const std::string& path, unsigned long *size_ret)
{
long fileSize;
#ifdef BBGE_BUILD_VFS
VFILE *vf = vfs.GetFile(path.c_str());
if (!vf)
return NULL;
fileSize = vf->size();
char *buffer = (char*)vf->getBuf(NULL, NULL);
vf->dropBuf(false);
#else
FILE *f = fopen(path.c_str(), "rb");
if (!f)
return NULL;
long fileSize;
if (fseek(f, 0, SEEK_END) != 0
|| (fileSize = ftell(f)) < 0
|| fseek(f, 0, SEEK_SET) != 0)
@ -483,11 +497,12 @@ char *readFile(std::string path, unsigned long *size_ret)
fclose(f);
return NULL;
}
fclose(f);
buffer[fileSize] = 0;
#endif
if (size_ret)
*size_ret = fileSize;
buffer[fileSize] = 0;
return buffer;
}
@ -551,13 +566,56 @@ std::string stripEndlineForUnix(const std::string &in)
return out;
}
#ifdef BBGE_BUILD_VFS
struct vfscallback_s
{
std::string *path;
const char *ext;
intptr_t param;
void (*callback)(const std::string &filename, intptr_t param);
};
void forEachFile_vfscallback(VFILE *vf, void *user)
{
vfscallback_s *d = (vfscallback_s*)user;
if(d->ext)
{
const char *e = strrchr(vf->name(), '.');
if(e && nocasecmp(d->ext, e))
return;
}
d->callback(*(d->path) + vf->name(), d->param);
}
#endif
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param)
{
if (path.empty()) return;
path = core->adjustFilenameCase(path);
#ifdef BBGE_BUILD_VFS
ttvfs::VFSDir *vd = vfs.GetDir(path.c_str(), true); // add to tree if it wasn't loaded before
if(!vd)
{
debugLog("Path '" + path + "' does not exist");
return;
}
vd->load(false);
vfscallback_s dat;
dat.path = &path;
dat.ext = type.length() ? type.c_str() : NULL;
dat.param = param;
dat.callback = callback;
vd->forEachFile(forEachFile_vfscallback, &dat, true);
return;
// -------------------------------------
#endif
stringToLower(type);
//HACK: MAC:
path = core->adjustFilenameCase(path);
debugLog("forEachFile - path: " + path + " type: " + type);
#if defined(BBGE_BUILD_UNIX)
@ -856,6 +914,8 @@ float lerp(const float &v1, const float &v2, float dt, int lerpType)
}
#if 0
#include <zlib.h>
#include <assert.h>
@ -1000,6 +1060,7 @@ int unpackFile(const std::string &sourcef, const std::string &destf)
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
#endif
void openURL(const std::string &url)
{