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:
parent
1709503344
commit
6dc1c1e8d1
41 changed files with 2966 additions and 468 deletions
|
@ -440,21 +440,3 @@ void ActionMapper::removeAllActions()
|
|||
}
|
||||
actionData.clear();
|
||||
}
|
||||
//
|
||||
//void ActionMapper::loadActionSet(const std::string &fn)
|
||||
//{
|
||||
// std::ifstream in(std::string("actionSets/"+fn+".txt").c_str());
|
||||
// std::string key;
|
||||
// std::string action;
|
||||
// while (in >> key)
|
||||
// {
|
||||
// in >> action;
|
||||
// if (key != " " && !key.empty() && key.size()==1)
|
||||
// {
|
||||
// char ckey = key[0];
|
||||
// addAction(action, ckey);
|
||||
// //msg (action+" key:"+ckey);
|
||||
// }
|
||||
// }
|
||||
// in.close();
|
||||
//}
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
#define BBGE_BUILD_SDL 1
|
||||
#define BBGE_BUILD_FRAMEBUFFER 1
|
||||
#define BBGE_BUILD_SHADERS 1
|
||||
//#define BBGE_BUILD_SHADERS 1
|
||||
#define BBGE_BUILD_OPENGL 1
|
||||
#define BBGE_BUILD_OPENGL_DYNAMIC 1
|
||||
#define BBGE_BUILD_FMOD_OPENAL_BRIDGE 1
|
||||
#define BBGE_BUILD_ACHIEVEMENTS_INTERNAL 1
|
||||
#define BBGE_BUILD_VFS 1
|
||||
|
||||
#endif
|
||||
|
||||
|
|
115
BBGE/Base.cpp
115
BBGE/Base.cpp
|
@ -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)
|
||||
{
|
||||
|
|
13
BBGE/Base.h
13
BBGE/Base.h
|
@ -137,6 +137,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "Rect.h"
|
||||
|
||||
#include "math.h"
|
||||
#include "FileAPI.h"
|
||||
|
||||
// dumb win32 includes/defines cleanup
|
||||
#undef GetCharWidth
|
||||
|
||||
|
||||
enum Align { ALIGN_CENTER=0, ALIGN_LEFT };
|
||||
|
||||
|
@ -195,10 +200,10 @@ void stringToLower(std::string &s);
|
|||
void stringToLowerUserData(std::string &s);
|
||||
void glColor3_256(int r, int g, int b);
|
||||
float sqr(float x);
|
||||
bool exists(const std::string &f, bool makeFatal = false);
|
||||
bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
|
||||
void errorLog(const std::string &s);
|
||||
void debugLog(const std::string &s);
|
||||
char *readFile(std::string path, unsigned long *size_ret = 0);
|
||||
char *readFile(const std::string& path, unsigned long *size_ret = 0);
|
||||
char *readCompressedFile(std::string path, unsigned long *size_ret = 0);
|
||||
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
|
||||
std::string stripEndlineForUnix(const std::string &in);
|
||||
|
@ -280,8 +285,8 @@ enum LerpType
|
|||
|
||||
float lerp(const float &v1, const float &v2, float dt, int lerpType);
|
||||
|
||||
int packFile(const std::string &sourcef, const std::string &destf, int level);
|
||||
int unpackFile(const std::string &sourcef, const std::string &destf);
|
||||
//int packFile(const std::string &sourcef, const std::string &destf, int level);
|
||||
//int unpackFile(const std::string &sourcef, const std::string &destf);
|
||||
|
||||
void openURL(const std::string &url);
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ void BitmapText::autoKern()
|
|||
void BitmapText::loadSpacingMap(const std::string &file)
|
||||
{
|
||||
spacingMap.clear();
|
||||
std::ifstream inFile(file.c_str());
|
||||
InStream inFile(file.c_str());
|
||||
std::string line;
|
||||
while (std::getline(inFile, line))
|
||||
{
|
||||
|
|
109
BBGE/Core.cpp
109
BBGE/Core.cpp
|
@ -1252,6 +1252,8 @@ bool Core::isShuttingDown()
|
|||
|
||||
void Core::init()
|
||||
{
|
||||
setupFileAccess();
|
||||
|
||||
flags.set(CF_CLEARBUFFERS);
|
||||
quitNestedMainFlag = false;
|
||||
#ifdef BBGE_BUILD_GLFW
|
||||
|
@ -2880,7 +2882,7 @@ void Core::main(float runTime)
|
|||
*/
|
||||
}
|
||||
|
||||
#if (!defined(_DEBUG) || defined(BBGE_BUILD_UNIX)) && defined(BBGE_BUILD_SDL)
|
||||
#if !defined(_DEBUG) && defined(BBGE_BUILD_SDL)
|
||||
if (verbose) debugLog("checking window active");
|
||||
|
||||
if (lib_graphics && (wasInactive || !settings.runInBackground))
|
||||
|
@ -4078,6 +4080,11 @@ void Core::shutdown()
|
|||
debugLog("OK");
|
||||
#endif
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
debugLog("Unload VFS...");
|
||||
vfs.Clear();
|
||||
debugLog("OK");
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BBGE_BUILD_SDL
|
||||
|
@ -4757,3 +4764,103 @@ int Core::tgaSaveSeries(char *filename,
|
|||
// ilutGLScreenie();
|
||||
}
|
||||
|
||||
|
||||
#include "DeflateCompressor.h"
|
||||
|
||||
// saves an array of pixels as a TGA image (frees the image data passed in)
|
||||
int Core::zgaSave( const char *filename,
|
||||
short int w,
|
||||
short int h,
|
||||
unsigned char depth,
|
||||
unsigned char *imageData) {
|
||||
|
||||
ByteBuffer::uint8 type,mode,aux, pixelDepth = depth;
|
||||
ByteBuffer::uint8 cGarbage = 0;
|
||||
ByteBuffer::uint16 iGarbage = 0;
|
||||
ByteBuffer::uint16 width = w, height = h;
|
||||
|
||||
// open file and check for errors
|
||||
FILE *file = fopen(adjustFilenameCase(filename).c_str(), "wb");
|
||||
if (file == NULL) {
|
||||
delete [] imageData;
|
||||
return (int)false;
|
||||
}
|
||||
|
||||
// compute image type: 2 for RGB(A), 3 for greyscale
|
||||
mode = pixelDepth / 8;
|
||||
if ((pixelDepth == 24) || (pixelDepth == 32))
|
||||
type = 2;
|
||||
else
|
||||
type = 3;
|
||||
|
||||
// convert the image data from RGB(A) to BGR(A)
|
||||
if (mode >= 3)
|
||||
for (int i=0; i < width * height * mode ; i+= mode) {
|
||||
aux = imageData[i];
|
||||
imageData[i] = imageData[i+2];
|
||||
imageData[i+2] = aux;
|
||||
}
|
||||
|
||||
ZlibCompressor z;
|
||||
z.SetForceCompression(true);
|
||||
z.reserve(width * height * mode + 30);
|
||||
z << cGarbage
|
||||
<< cGarbage
|
||||
<< type
|
||||
<< iGarbage
|
||||
<< iGarbage
|
||||
<< cGarbage
|
||||
<< iGarbage
|
||||
<< iGarbage
|
||||
<< width
|
||||
<< height
|
||||
<< pixelDepth
|
||||
<< cGarbage;
|
||||
|
||||
z.append(imageData, width * height * mode);
|
||||
z.Compress(3);
|
||||
|
||||
// save the image data
|
||||
if (fwrite(z.contents(), 1, z.size(), file) != z.size())
|
||||
{
|
||||
fclose(file);
|
||||
delete [] imageData;
|
||||
return (int)false;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
delete [] imageData;
|
||||
|
||||
return (int)true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "ttvfs_zip/VFSZipArchiveLoader.h"
|
||||
|
||||
void Core::setupFileAccess()
|
||||
{
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
debugLog("Init VFS...");
|
||||
|
||||
if(!ttvfs::checkCompat())
|
||||
exit(1);
|
||||
|
||||
vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader);
|
||||
|
||||
if(!vfs.LoadFileSysRoot(false))
|
||||
{
|
||||
errorLog("Failed to setup file access");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
vfs.Prepare();
|
||||
|
||||
// TODO: mount and other stuff
|
||||
|
||||
//vfs.AddArchive("aqfiles.zip", false, "");
|
||||
|
||||
|
||||
debugLog("Done");
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1306,6 +1306,7 @@ public:
|
|||
CoreSettings settings;
|
||||
|
||||
int tgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
||||
int zgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
||||
|
||||
volatile int dbg_numThreadDecoders;
|
||||
|
||||
|
@ -1398,6 +1399,8 @@ protected:
|
|||
int tgaSaveSeries(char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
|
||||
virtual void onUpdate(float dt);
|
||||
virtual void onRender(){}
|
||||
|
||||
void setupFileAccess();
|
||||
};
|
||||
|
||||
extern Core *core;
|
||||
|
|
|
@ -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));
|
||||
|
|
13
BBGE/MT.h
13
BBGE/MT.h
|
@ -95,19 +95,6 @@ public:
|
|||
unlock();
|
||||
return e;
|
||||
}
|
||||
bool popIfPossible(T& e)
|
||||
{
|
||||
lock();
|
||||
if(!_q.empty())
|
||||
{
|
||||
e = _q.front();
|
||||
_q.pop();
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::queue<T> _q;
|
||||
|
|
|
@ -123,7 +123,7 @@ void Precacher::precacheTex(const std::string &tex)
|
|||
void Precacher::precacheList(const std::string &list, void progressCallback())
|
||||
{
|
||||
loadProgressCallback = progressCallback;
|
||||
std::ifstream in(list.c_str());
|
||||
InStream in(list.c_str());
|
||||
std::string t;
|
||||
while (std::getline(in, t))
|
||||
{
|
||||
|
|
|
@ -181,7 +181,7 @@ unsigned char *readShaderFile( const char *fileName )
|
|||
{
|
||||
debugLog("readShaderFile()");
|
||||
#ifdef BBGE_BUILD_WINDOWS
|
||||
FILE *file = fopen( fileName, "r" );
|
||||
FILE *file = fopen( fileName, "r" ); // FIXME: should this code ever be re-activated, adjust to VFS! -- fg
|
||||
|
||||
if( file == NULL )
|
||||
{
|
||||
|
|
|
@ -134,17 +134,21 @@ FMOD_RESULT F_CALLBACK myopen(const char *name, int unicode, unsigned int *files
|
|||
{
|
||||
if (name)
|
||||
{
|
||||
FILE *fp;
|
||||
VFILE *fp;
|
||||
|
||||
fp = fopen(name, "rb");
|
||||
fp = vfopen(name, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
return FMOD_ERR_FILE_NOTFOUND;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
*filesize = fp->size();
|
||||
#else
|
||||
vfseek(fp, 0, SEEK_END);
|
||||
*filesize = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
vfseek(fp, 0, SEEK_SET);
|
||||
#endif
|
||||
|
||||
*userdata = (void *)0x12345678;
|
||||
*handle = fp;
|
||||
|
@ -160,7 +164,7 @@ FMOD_RESULT F_CALLBACK myclose(void *handle, void *userdata)
|
|||
return FMOD_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fclose((FILE *)handle);
|
||||
vfclose((VFILE *)handle);
|
||||
|
||||
return FMOD_OK;
|
||||
}
|
||||
|
@ -174,7 +178,7 @@ FMOD_RESULT F_CALLBACK myread(void *handle, void *buffer, unsigned int sizebytes
|
|||
|
||||
if (bytesread)
|
||||
{
|
||||
*bytesread = (int)fread(buffer, 1, sizebytes, (FILE *)handle);
|
||||
*bytesread = (int)vfread(buffer, 1, sizebytes, (VFILE *)handle);
|
||||
|
||||
if (*bytesread < sizebytes)
|
||||
{
|
||||
|
@ -192,7 +196,7 @@ FMOD_RESULT F_CALLBACK myseek(void *handle, unsigned int pos, void *userdata)
|
|||
return FMOD_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
fseek((FILE *)handle, pos, SEEK_SET);
|
||||
vfseek((VFILE *)handle, pos, SEEK_SET);
|
||||
|
||||
return FMOD_OK;
|
||||
}
|
||||
|
|
|
@ -294,11 +294,11 @@ void Texture::reload()
|
|||
unload();
|
||||
load(loadName);
|
||||
|
||||
if (ow != -1 && oh != -1)
|
||||
/*if (ow != -1 && oh != -1)
|
||||
{
|
||||
width = ow;
|
||||
height = oh;
|
||||
}
|
||||
}*/
|
||||
debugLog("DONE");
|
||||
}
|
||||
|
||||
|
@ -466,6 +466,31 @@ 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;
|
||||
//exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
int memsize = vf->size();
|
||||
if (filter == GL_NEAREST)
|
||||
{
|
||||
textures[0] = pngBindMem(memptr, memsize, PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
|
@ -474,6 +499,7 @@ void Texture::loadPNG(const std::string &file)
|
|||
{
|
||||
textures[0] = pngBind(file.c_str(), PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (textures[0] != 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue