mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-04 05:13:19 +00:00
Update Aquaria/BBGE/External sources to comply with the new ttvfs API
This commit is contained in:
parent
8026cdd905
commit
6203bc7ce4
17 changed files with 179 additions and 390 deletions
|
@ -43,6 +43,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
ttvfs::Root vfs; // extern
|
||||
#endif
|
||||
|
||||
Vector getDirVector(Direction dir)
|
||||
{
|
||||
switch(dir)
|
||||
|
@ -489,26 +493,15 @@ void debugLog(const std::string &s)
|
|||
// delete[] when no longer needed.
|
||||
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;
|
||||
char *buffer = (char*)vf->getBuf(NULL, NULL);
|
||||
fileSize = vf->size();
|
||||
vf->dropBuf(false); // unlink buffer from file
|
||||
#else
|
||||
FILE *f = fopen(path.c_str(), "rb");
|
||||
VFILE *f = vfopen(path.c_str(), "rb");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (fseek(f, 0, SEEK_END) != 0
|
||||
|| (fileSize = ftell(f)) < 0
|
||||
|| fseek(f, 0, SEEK_SET) != 0)
|
||||
size_t fileSize = 0;
|
||||
if(vfsize(f, &fileSize) < 0)
|
||||
{
|
||||
debugLog(path + ": Failed to get file size");
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -519,23 +512,22 @@ char *readFile(const std::string& path, unsigned long *size_ret)
|
|||
os << path << ": Not enough memory for file ("
|
||||
<< (fileSize+1) << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
long bytesRead = fread(buffer, 1, fileSize, f);
|
||||
long bytesRead = vfread(buffer, 1, fileSize, f);
|
||||
if (bytesRead != fileSize)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << path << ": Failed to read file (only got "
|
||||
<< bytesRead << " of " << fileSize << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
buffer[fileSize] = 0;
|
||||
#endif
|
||||
|
||||
if (size_ret)
|
||||
*size_ret = fileSize;
|
||||
|
@ -630,21 +622,19 @@ void forEachFile(std::string path, std::string type, void callback(const std::st
|
|||
{
|
||||
if (path.empty()) return;
|
||||
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
ttvfs::VFSDir *vd = vfs.GetDir(path.c_str(), true); // add to tree if it wasn't loaded before
|
||||
if(!vd)
|
||||
ttvfs::DirView view;
|
||||
if(!vfs.FillDirView(path.c_str(), view))
|
||||
{
|
||||
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);
|
||||
view.forEachFile(forEachFile_vfscallback, &dat, true);
|
||||
|
||||
return;
|
||||
// -------------------------------------
|
||||
|
|
15
BBGE/Base.h
15
BBGE/Base.h
|
@ -141,7 +141,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "Rect.h"
|
||||
|
||||
#include "math.h"
|
||||
#include "FileAPI.h"
|
||||
#include "ttvfs_stdio.h"
|
||||
|
||||
#ifdef BBGE_BUILD_LINUX
|
||||
# include <sys/types.h>
|
||||
|
@ -173,16 +173,6 @@ enum Direction
|
|||
#include "Vector.h"
|
||||
|
||||
|
||||
#define FOR_ALL(object, type, object_iterator)\
|
||||
{\
|
||||
for (type::iterator object_iterator = object.begin(); object_iterator != object.end(); ++object_iterator)\
|
||||
{\
|
||||
|
||||
#define END_FOR_ALL\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
const float SQRT2 = 1.41421356;
|
||||
|
||||
const float PI = 3.14159265;
|
||||
|
@ -304,5 +294,8 @@ void triggerBreakpoint();
|
|||
|
||||
bool createDir(const std::string& d);
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
extern ttvfs::Root vfs; // in Base.cpp
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5136,34 +5136,22 @@ void Core::setupFileAccess()
|
|||
if(!ttvfs::checkCompat())
|
||||
exit_error("ttvfs not compatible");
|
||||
|
||||
ttvfs_setroot(&vfs);
|
||||
|
||||
vfs.AddLoader(new ttvfs::DiskLoader);
|
||||
vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader);
|
||||
|
||||
if(!vfs.LoadFileSysRoot(false))
|
||||
{
|
||||
exit_error("Failed to setup file access");
|
||||
}
|
||||
|
||||
vfs.Prepare();
|
||||
|
||||
|
||||
ttvfs::VFSDir *override = vfs.GetDir("override");
|
||||
if(override)
|
||||
{
|
||||
debugLog("Mounting override dir...");
|
||||
override->load(true);
|
||||
vfs.Mount("override", "", true);
|
||||
}
|
||||
vfs.Mount("override", "");
|
||||
|
||||
// If we ever want to read from a container...
|
||||
//vfs.AddArchive("aqfiles.zip", false, "");
|
||||
//vfs.AddArchive("aqfiles.zip");
|
||||
|
||||
if(_extraDataDir.length())
|
||||
{
|
||||
debugLog("Mounting extra data dir: " + _extraDataDir);
|
||||
vfs.MountExternalPath(_extraDataDir.c_str(), "", true, true);
|
||||
vfs.Mount(_extraDataDir.c_str(), "");
|
||||
}
|
||||
|
||||
|
||||
debugLog("Done");
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ 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
|
||||
|
@ -1488,7 +1487,6 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
|
|||
|
||||
long nread = vfread(data, 1, size, io);
|
||||
vfclose(io);
|
||||
vfclear(io);
|
||||
if (nread != size)
|
||||
{
|
||||
debugLog("Failed to read data from " + std::string(fname));
|
||||
|
|
|
@ -437,19 +437,11 @@ void Texture::loadPNG(const std::string &file)
|
|||
pngType = PNG_LUMINANCEALPHA;
|
||||
}
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
ttvfs::VFSFile *vf = vfs.GetFile(file.c_str());
|
||||
const char *memptr = vf ? (const char*)vf->getBuf() : NULL;
|
||||
if(!memptr)
|
||||
{
|
||||
debugLog("Can't load PNG file: " + file);
|
||||
width = 64;
|
||||
height = 64;
|
||||
Texture::textureError = TEXERR_FILENOTFOUND;
|
||||
return;
|
||||
}
|
||||
unsigned long memsize = 0;
|
||||
const char *memptr = readFile(file, &memsize);
|
||||
if(!memptr || !memsize)
|
||||
goto fail;
|
||||
|
||||
int memsize = vf->size();
|
||||
if (filter == GL_NEAREST)
|
||||
{
|
||||
textures[0] = pngBindMem(memptr, memsize, PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter);
|
||||
|
@ -458,18 +450,6 @@ void Texture::loadPNG(const std::string &file)
|
|||
{
|
||||
textures[0] = pngBindMem(memptr, memsize, PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter);
|
||||
}
|
||||
vf->dropBuf(true);
|
||||
|
||||
#else
|
||||
if (filter == GL_NEAREST)
|
||||
{
|
||||
textures[0] = pngBind(file.c_str(), PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
textures[0] = pngBind(file.c_str(), PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (textures[0] != 0)
|
||||
{
|
||||
|
@ -478,12 +458,16 @@ void Texture::loadPNG(const std::string &file)
|
|||
}
|
||||
else
|
||||
{
|
||||
fail:
|
||||
|
||||
debugLog("Can't load PNG file: " + file);
|
||||
width = 64;
|
||||
height = 64;
|
||||
Texture::textureError = TEXERR_FILENOTFOUND;
|
||||
}
|
||||
|
||||
if(memptr)
|
||||
delete [] memptr;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue