mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-16 14:50:01 +00:00
Merge branch 'master' of file:///Users/User/code/coding/Aquaria_fg_clean
This commit is contained in:
commit
488ec5a1bf
7 changed files with 104 additions and 139 deletions
|
@ -1977,8 +1977,8 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim)
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
||||||
int size = w*h*4;
|
unsigned int size = w*h*4;
|
||||||
if(size <= 0)
|
if (!size || w <= 0 || h <= 0)
|
||||||
return;
|
return;
|
||||||
unsigned char *data = (unsigned char*)malloc(size + 6);
|
unsigned char *data = (unsigned char*)malloc(size + 6);
|
||||||
memcpy(data + size, "SAFE", 5);
|
memcpy(data + size, "SAFE", 5);
|
||||||
|
@ -2014,12 +2014,12 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim)
|
||||||
{
|
{
|
||||||
// starting position =
|
// starting position =
|
||||||
// tx / scale.x
|
// tx / scale.x
|
||||||
int px = int(tx/q->scale.x) + x;
|
unsigned int px = int(tx/q->scale.x) + x;
|
||||||
int py = int(ty/q->scale.y) + y;
|
unsigned int py = int(ty/q->scale.y) + y;
|
||||||
if (px < w && py < h)
|
if (px < unsigned(w) && py < unsigned(h))
|
||||||
{
|
{
|
||||||
int p = (py*w*4) + px*4;
|
unsigned int p = (py*unsigned(w)*4) + (px*4) + 3; // position of alpha component
|
||||||
if (data[p+3] >= 254)
|
if (p < size && data[p] >= 254)
|
||||||
{
|
{
|
||||||
num ++;
|
num ++;
|
||||||
}
|
}
|
||||||
|
@ -2794,32 +2794,27 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius)
|
||||||
else
|
else
|
||||||
q->collideRadius = TILE_SIZE/2;
|
q->collideRadius = TILE_SIZE/2;
|
||||||
q->collisionMask.clear();
|
q->collisionMask.clear();
|
||||||
std::vector<TileVector> obs;
|
|
||||||
TileVector tpos(q->position);
|
TileVector tpos(q->position);
|
||||||
int w2 = int(q->getWidth()*q->scale.x)>>1;
|
int widthscale = q->getWidth()*q->scale.x;
|
||||||
int h2 = int(q->getHeight()*q->scale.y)>>1;
|
int heightscale = q->getHeight()*q->scale.y;
|
||||||
|
int w2 = widthscale/2;
|
||||||
|
int h2 = heightscale/2;
|
||||||
w2/=TILE_SIZE;
|
w2/=TILE_SIZE;
|
||||||
h2/=TILE_SIZE;
|
h2/=TILE_SIZE;
|
||||||
tpos.x -= w2;
|
tpos.x -= w2;
|
||||||
tpos.y -= h2;
|
tpos.y -= h2;
|
||||||
GLuint id = q->texture->textures[0];
|
GLuint id = q->texture->textures[0];
|
||||||
float w, h, c=4;
|
int w = 0, h = 0;
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
//glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
||||||
int size = w*h*c;
|
|
||||||
unsigned char *data=0;
|
|
||||||
|
|
||||||
int sz = size*sizeof(unsigned char);
|
unsigned int size = w*h*4;
|
||||||
|
if (!size || w <= 0 || h <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
/*
|
unsigned char *data = (unsigned char*)malloc(size);
|
||||||
std::ostringstream os;
|
|
||||||
os << "size: " << sz;
|
|
||||||
debugLog(os.str());
|
|
||||||
*/
|
|
||||||
|
|
||||||
data = (unsigned char*)malloc(sz);
|
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
|
@ -2832,15 +2827,16 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius)
|
||||||
|
|
||||||
Vector collisionMaskHalfVector = Vector(q->getWidth()/2, q->getHeight()/2);
|
Vector collisionMaskHalfVector = Vector(q->getWidth()/2, q->getHeight()/2);
|
||||||
|
|
||||||
for (int tx = 0; tx < (q->getWidth()*q->scale.x); tx+=TILE_SIZE)
|
int szx = TILE_SIZE/q->scale.x;
|
||||||
|
int szy = TILE_SIZE/q->scale.y;
|
||||||
|
if (szx < 1) szx = 1;
|
||||||
|
if (szy < 1) szy = 1;
|
||||||
|
|
||||||
|
for (int tx = 0; tx < widthscale; tx+=TILE_SIZE)
|
||||||
{
|
{
|
||||||
for (int ty = 0; ty < (q->getHeight()*q->scale.y); ty+=TILE_SIZE)
|
for (int ty = 0; ty < heightscale; ty+=TILE_SIZE)
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
int szx = TILE_SIZE/q->scale.x;
|
|
||||||
int szy = TILE_SIZE/q->scale.y;
|
|
||||||
if (szx < 1) szx = 1;
|
|
||||||
if (szy < 1) szy = 1;
|
|
||||||
|
|
||||||
for (int x = 0; x < szx; x++)
|
for (int x = 0; x < szx; x++)
|
||||||
{
|
{
|
||||||
|
@ -2848,18 +2844,12 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius)
|
||||||
{
|
{
|
||||||
// starting position =
|
// starting position =
|
||||||
// tx / scale.x
|
// tx / scale.x
|
||||||
int px = int(tx/q->scale.x) + x;
|
unsigned int px = int(tx/q->scale.x) + x;
|
||||||
int py = int(ty/q->scale.y) + y;
|
unsigned int py = int(ty/q->scale.y) + y;
|
||||||
if (px < w && py < h)
|
if (px < unsigned(w) && py < unsigned(h))
|
||||||
{
|
{
|
||||||
int p = (py*w*c) + px*c;
|
unsigned int p = (py*unsigned(w)*4) + (px*4) + 3; // position of alpha component
|
||||||
/*
|
if (p < size && data[p] >= 250)
|
||||||
std::ostringstream os;
|
|
||||||
os << "data(" << int(data[p]) << ", " << int(data[p+1]);
|
|
||||||
os << ", " << int(data[p+2]) << ", " << int(data[p+3]) << ")";
|
|
||||||
debugLog(os.str());
|
|
||||||
*/
|
|
||||||
if (int(data[p+3]) >= 250)
|
|
||||||
{
|
{
|
||||||
num ++;
|
num ++;
|
||||||
}
|
}
|
||||||
|
@ -2869,9 +2859,6 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius)
|
||||||
if (num >= int((szx*szy)*0.25f))
|
if (num >= int((szx*szy)*0.25f))
|
||||||
{
|
{
|
||||||
TileVector tile(int((tx+TILE_SIZE/2)/TILE_SIZE), int((ty+TILE_SIZE/2)/TILE_SIZE));
|
TileVector tile(int((tx+TILE_SIZE/2)/TILE_SIZE), int((ty+TILE_SIZE/2)/TILE_SIZE));
|
||||||
|
|
||||||
obs.push_back(tile);
|
|
||||||
|
|
||||||
// + Vector(0,TILE_SIZE)
|
// + Vector(0,TILE_SIZE)
|
||||||
q->collisionMask.push_back(tile.worldVector() - collisionMaskHalfVector);
|
q->collisionMask.push_back(tile.worldVector() - collisionMaskHalfVector);
|
||||||
}
|
}
|
||||||
|
@ -2903,7 +2890,7 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius)
|
||||||
q->collisionMaskRadius = 512;
|
q->collisionMaskRadius = 512;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
if (data) free(data);
|
free(data);
|
||||||
/*
|
/*
|
||||||
int rot = rotation.z;
|
int rot = rotation.z;
|
||||||
while (rot > 360)
|
while (rot > 360)
|
||||||
|
|
|
@ -458,9 +458,9 @@ char *readFile(const std::string& path, unsigned long *size_ret)
|
||||||
VFILE *vf = vfs.GetFile(path.c_str());
|
VFILE *vf = vfs.GetFile(path.c_str());
|
||||||
if (!vf)
|
if (!vf)
|
||||||
return NULL;
|
return NULL;
|
||||||
fileSize = vf->size();
|
|
||||||
char *buffer = (char*)vf->getBuf(NULL, NULL);
|
char *buffer = (char*)vf->getBuf(NULL, NULL);
|
||||||
vf->dropBuf(false);
|
fileSize = vf->size();
|
||||||
|
vf->dropBuf(false); // unlink buffer from file
|
||||||
#else
|
#else
|
||||||
FILE *f = fopen(path.c_str(), "rb");
|
FILE *f = fopen(path.c_str(), "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
|
@ -1128,6 +1128,8 @@ char *readCompressedFile(std::string path, unsigned long *size_ret)
|
||||||
{
|
{
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
char *buf = readFile(path, &size);
|
char *buf = readFile(path, &size);
|
||||||
|
if(!buf)
|
||||||
|
return NULL;
|
||||||
ZlibCompressor z; // allocates with new[] by default
|
ZlibCompressor z; // allocates with new[] by default
|
||||||
z.init(buf, size, ByteBuffer::TAKE_OVER);
|
z.init(buf, size, ByteBuffer::TAKE_OVER);
|
||||||
z.Compressed(true);
|
z.Compressed(true);
|
||||||
|
|
|
@ -925,15 +925,13 @@ bool SoundManager::playVoice(const std::string &name, SoundVoiceType svt, float
|
||||||
|
|
||||||
if (!voicePath2.empty())
|
if (!voicePath2.empty())
|
||||||
{
|
{
|
||||||
fn = voicePath2 + name + fileType;
|
fn = core->adjustFilenameCase(voicePath2 + name + fileType);
|
||||||
stringToLower(fn);
|
|
||||||
if (exists(fn)) checkOther = false;
|
if (exists(fn)) checkOther = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOther)
|
if (checkOther)
|
||||||
{
|
{
|
||||||
fn = voicePath + name + fileType;
|
fn = core->adjustFilenameCase(voicePath + name + fileType);
|
||||||
stringToLower(fn);
|
|
||||||
if (!exists(fn))
|
if (!exists(fn))
|
||||||
{
|
{
|
||||||
debugLog("Could not find voice file [" + fn + "]");
|
debugLog("Could not find voice file [" + fn + "]");
|
||||||
|
@ -1281,27 +1279,25 @@ bool SoundManager::playMusic(const std::string &name, SoundLoopType slt, SoundFa
|
||||||
if (!name.empty() && name[0] == '.')
|
if (!name.empty() && name[0] == '.')
|
||||||
{
|
{
|
||||||
fn = name;
|
fn = name;
|
||||||
stringToLower(fn);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!audioPath2.empty())
|
if (!audioPath2.empty())
|
||||||
{
|
{
|
||||||
fn = audioPath2 + name + fileType;
|
fn = audioPath2 + name + fileType;
|
||||||
stringToLower(fn);
|
|
||||||
if (!exists(fn))
|
if (!exists(fn))
|
||||||
{
|
{
|
||||||
fn = musicPath + name + fileType;
|
fn = musicPath + name + fileType;
|
||||||
stringToLower(fn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fn = musicPath + name + fileType;
|
fn = musicPath + name + fileType;
|
||||||
stringToLower(fn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn = core->adjustFilenameCase(fn);
|
||||||
|
|
||||||
lastMusic = name;
|
lastMusic = name;
|
||||||
stringToLower(lastMusic);
|
stringToLower(lastMusic);
|
||||||
|
|
||||||
|
@ -1498,14 +1494,8 @@ void loadCacheSoundsCallback (const std::string &filename, intptr_t param)
|
||||||
}
|
}
|
||||||
if (fileType==".ogg")
|
if (fileType==".ogg")
|
||||||
{
|
{
|
||||||
|
debugLog("trying to load sound " + filename);
|
||||||
std::string f = filename;
|
sm->loadSoundIntoBank(filename, "", "");
|
||||||
stringToLower(f);
|
|
||||||
|
|
||||||
debugLog("trying to load sound " + f);
|
|
||||||
|
|
||||||
sm->loadSoundIntoBank(f, "", "");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1525,21 +1515,18 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s
|
||||||
|
|
||||||
// WARNING: local sounds should go here!
|
// WARNING: local sounds should go here!
|
||||||
|
|
||||||
debugLog(filename);
|
debugLog(filename);
|
||||||
if (slt == SFXLOAD_LOCAL && !audioPath2.empty())
|
if (slt == SFXLOAD_LOCAL && !audioPath2.empty())
|
||||||
{
|
{
|
||||||
f = audioPath2 + filename + format;
|
f = core->adjustFilenameCase(audioPath2 + filename + format);
|
||||||
stringToLower(f);
|
|
||||||
if (!exists(f))
|
if (!exists(f))
|
||||||
{
|
{
|
||||||
f = path + filename + format;
|
f = core->adjustFilenameCase(path + filename + format);
|
||||||
stringToLower(f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f = path + filename + format;
|
f = core->adjustFilenameCase(path + filename + format);
|
||||||
stringToLower(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loop = false;
|
bool loop = false;
|
||||||
|
@ -1561,6 +1548,8 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s
|
||||||
return Buffer();
|
return Buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stringToLower(name);
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_FMODEX
|
#ifdef BBGE_BUILD_FMODEX
|
||||||
|
|
||||||
FMOD::Sound * sound = SoundCore::soundMap[name];
|
FMOD::Sound * sound = SoundCore::soundMap[name];
|
||||||
|
|
|
@ -194,34 +194,31 @@ void Texture::destroy()
|
||||||
int Texture::getPixelWidth()
|
int Texture::getPixelWidth()
|
||||||
{
|
{
|
||||||
#ifdef BBGE_BUILD_OPENGL
|
#ifdef BBGE_BUILD_OPENGL
|
||||||
float w, h, c;
|
int w = 0, h = 0;
|
||||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
||||||
int size = w*h*c;
|
unsigned int size = w*h*4;
|
||||||
unsigned char *data=0;
|
if (!size || w <= 0 || h <= 0)
|
||||||
data = (unsigned char*)malloc(size*sizeof(char));
|
return 0;
|
||||||
if (c == 4)
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
unsigned char *data = (unsigned char*)malloc(size*sizeof(char));
|
||||||
/*
|
if (!data)
|
||||||
else if (c == 3)
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
|
||||||
*/
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (data)
|
debugLog("Texture::getPixelWidth() malloc failed");
|
||||||
free(data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
|
|
||||||
int smallestx = -1, largestx = -1;
|
int smallestx = -1, largestx = -1;
|
||||||
for (int x = 0; x < w; x++)
|
for (unsigned int x = 0; x < unsigned(w); x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < h; y++)
|
for (unsigned int y = 0; y < unsigned(h); y++)
|
||||||
{
|
{
|
||||||
int p = (y*w*c) + x*c;
|
unsigned int p = (y*unsigned(w)*4) + (x*4) + 3;
|
||||||
if (data[p+3] >= 254)
|
if (p < size && data[p] >= 254)
|
||||||
{
|
{
|
||||||
if (smallestx == -1 || x < smallestx)
|
if (smallestx == -1 || x < smallestx)
|
||||||
smallestx = x;
|
smallestx = x;
|
||||||
|
@ -241,33 +238,28 @@ int Texture::getPixelWidth()
|
||||||
int Texture::getPixelHeight()
|
int Texture::getPixelHeight()
|
||||||
{
|
{
|
||||||
#ifdef BBGE_BUILD_OPENGL
|
#ifdef BBGE_BUILD_OPENGL
|
||||||
float w, h, c;
|
int w = 0, h = 0;
|
||||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||||
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &c);// assume 4
|
||||||
int size = w*h*c;
|
unsigned int size = w*h*4;
|
||||||
unsigned char *data=0;
|
if (!size || w <= 0 || h <= 0)
|
||||||
data = (unsigned char*)malloc(size*sizeof(char));
|
return 0;
|
||||||
if (c == 4)
|
unsigned char *data = (unsigned char*)malloc(size*sizeof(char));
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
if (!data)
|
||||||
/*
|
|
||||||
else if (c == 3)
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
|
||||||
*/
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (data)
|
debugLog("Texture::getPixelHeight() malloc failed");
|
||||||
free(data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
int smallesty = -1, largesty = -1;
|
int smallesty = -1, largesty = -1;
|
||||||
for (int x = 0; x < w; x++)
|
for (unsigned int x = 0; x < unsigned(w); x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < h; y++)
|
for (unsigned int y = 0; y < unsigned(h); y++)
|
||||||
{
|
{
|
||||||
int p = (y*w*c) + x*c;
|
int p = (y*unsigned(w)*4) + (x*4) + 3;
|
||||||
if (data[p+3] >= 254)
|
if (p < size && data[p] >= 254)
|
||||||
{
|
{
|
||||||
if (smallesty == -1 || y < smallesty)
|
if (smallesty == -1 || y < smallesty)
|
||||||
smallesty = y;
|
smallesty = y;
|
||||||
|
@ -277,8 +269,7 @@ int Texture::getPixelHeight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
if (data)
|
free(data);
|
||||||
free(data);
|
|
||||||
return largesty - smallesty;
|
return largesty - smallesty;
|
||||||
#elif defined(BBGE_BUILD_DIRECTX)
|
#elif defined(BBGE_BUILD_DIRECTX)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -76,7 +76,7 @@ void VFSFile::dropBuf(bool del)
|
||||||
}
|
}
|
||||||
|
|
||||||
VFSFileReal::VFSFileReal(const char *name /* = NULL */)
|
VFSFileReal::VFSFileReal(const char *name /* = NULL */)
|
||||||
: VFSFile(name), _fh(NULL), _size(npos), _buf(NULL)
|
: VFSFile(name), _fh(NULL), _buf(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,14 +94,8 @@ bool VFSFileReal::open(const char *mode /* = NULL */)
|
||||||
dropBuf(true);
|
dropBuf(true);
|
||||||
|
|
||||||
_fh = real_fopen(fullname(), mode ? mode : "rb");
|
_fh = real_fopen(fullname(), mode ? mode : "rb");
|
||||||
if(!_fh)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
real_fseek((FILE*)_fh, 0, SEEK_END);
|
return !!_fh;
|
||||||
_size = getpos();
|
|
||||||
real_fseek((FILE*)_fh, 0, SEEK_SET);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFSFileReal::isopen(void) const
|
bool VFSFileReal::isopen(void) const
|
||||||
|
@ -177,13 +171,7 @@ unsigned int VFSFileReal::write(const void *src, unsigned int bytes)
|
||||||
|
|
||||||
vfspos VFSFileReal::size(void)
|
vfspos VFSFileReal::size(void)
|
||||||
{
|
{
|
||||||
VFS_GUARD_OPT(this);
|
return GetFileSize(fullname());
|
||||||
if(_size != npos)
|
|
||||||
return _size;
|
|
||||||
open();
|
|
||||||
close();
|
|
||||||
// now size is known.
|
|
||||||
return _size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------- VFSFileMem -----------------------
|
// ------------- VFSFileMem -----------------------
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
virtual const void *getBuf(allocator_func alloc = NULL, delete_func del = NULL);
|
virtual const void *getBuf(allocator_func alloc = NULL, delete_func del = NULL);
|
||||||
|
|
||||||
/** If del is true, delete internal buffer. If false, unregister internal buffer from the file,
|
/** If del is true, delete internal buffer. If false, unregister internal buffer from the file,
|
||||||
but do not delete. Use free() or an appropriate deletion function later. */
|
but do not delete. Use delete[] or an appropriate deletion function later. */
|
||||||
virtual void dropBuf(bool del);
|
virtual void dropBuf(bool del);
|
||||||
|
|
||||||
/** Basic RTTI, for debugging purposes */
|
/** Basic RTTI, for debugging purposes */
|
||||||
|
@ -117,7 +117,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void *_fh; // FILE*
|
void *_fh; // FILE*
|
||||||
vfspos _size;
|
|
||||||
void *_buf;
|
void *_buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#else
|
#else
|
||||||
# include <sys/dir.h>
|
# include <sys/dir.h>
|
||||||
# include <sys/stat.h>
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
VFS_NAMESPACE_START
|
VFS_NAMESPACE_START
|
||||||
|
|
||||||
std::string stringToLower(std::string s)
|
std::string stringToLower(std::string s)
|
||||||
|
@ -259,16 +260,24 @@ bool CreateDirRec(const char *dir)
|
||||||
|
|
||||||
vfspos GetFileSize(const char* fn)
|
vfspos GetFileSize(const char* fn)
|
||||||
{
|
{
|
||||||
if(!fn || !*fn)
|
#ifdef VFS_LARGEFILE_SUPPORT
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
struct _stat64 st;
|
||||||
|
if(_stat64(fn, &st))
|
||||||
return 0;
|
return 0;
|
||||||
void *fp = real_fopen(fn, "rb");
|
return st.st_size;
|
||||||
if(!fp)
|
# else // _MSC_VER
|
||||||
|
struct stat64 st;
|
||||||
|
if(stat64(fn, &st))
|
||||||
return 0;
|
return 0;
|
||||||
real_fseek(fp, 0, SEEK_END);
|
return st.st_size;
|
||||||
vfspos s = real_ftell(fp);
|
# endif
|
||||||
real_fclose(fp);
|
#else // VFS_LARGEFILE_SUPPORT
|
||||||
|
struct stat st;
|
||||||
return s == npos ? 0 : s;
|
if(stat(fn, &st))
|
||||||
|
return 0;
|
||||||
|
return st.st_size;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FixSlashes(const std::string& s)
|
std::string FixSlashes(const std::string& s)
|
||||||
|
|
Loading…
Reference in a new issue