1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-04 13:27:14 +00:00

[vfs, #2] Move around some files (cleanup only)

This commit is contained in:
fgenesis 2012-06-01 17:26:13 +02:00
commit 1709503344
8 changed files with 523 additions and 660 deletions

View file

@ -7,9 +7,8 @@
//STL headers
#include <string>
#include <utility>
#include <iostream>
#include <fstream>
#include "FileAPI.h"
#include "ByteBuffer.h"
using namespace std;
//OpenGL headers
@ -22,33 +21,10 @@ using namespace std;
#include "GL/gl.h"
#include "SDL_endian.h"
//glFont header
#include "glfont2.h"
using namespace glfont;
static int read_int(ifstream &input)
{
int buffer;
input.read((char *)&buffer, 4);
return SDL_SwapLE32(buffer);
}
static float read_float(ifstream &input)
{
union
{
int i;
float f;
} buffer;
input.read((char *)&buffer.i, 4);
buffer.i = SDL_SwapLE32(buffer.i);
return buffer.f;
}
//*******************************************************************
//GLFont Class Implementation
//*******************************************************************
@ -71,27 +47,44 @@ GLFont::~GLFont ()
//*******************************************************************
bool GLFont::Create (const char *file_name, int tex, bool loadTexture)
{
ifstream input;
int num_chars, num_tex_bytes;
char *tex_bytes;
//Destroy the old font if there was one, just to be safe
Destroy();
#ifdef BBGE_BUILD_VFS
//Open input file
input.open(file_name, ios::in | ios::binary);
if (!input)
ttvfs::VFSFile *vf = vfs.GetFile(file_name);
if (!vf)
return false;
ByteBuffer bb((void*)vf->getBuf(), vf->size(), ByteBuffer::TAKE_OVER);
vf->dropBuf(false);
#else
VFILE *fh = vfopen(file_name, "rb");
if (!fh)
return false;
vfseek(fh, 0, SEEK_END);
long int sz = vftell(fh);
vfseek(fh, 0, SEEK_SET);
ByteBuffer bb(sz);
bb.resize(sz);
vfread(bb.contents(), 1, sz, fh);
vfclose(fh);
#endif
int dummy;
// Read the header from file
header.tex = tex;
input.seekg(4, ios::cur); // skip tex field
header.tex_width = read_int(input);
header.tex_height = read_int(input);
header.start_char = read_int(input);
header.end_char = read_int(input);
input.seekg(4, ios::cur); // skip chars field
bb >> dummy; // skip tex field
bb >> header.tex_width;
bb >> header.tex_height;
bb >> header.start_char;
bb >> header.end_char;
bb >> dummy; // skip chars field
//Allocate space for character array
num_chars = header.end_char - header.start_char + 1;
if ((header.chars = new GLFontChar[num_chars]) == NULL)
@ -100,19 +93,19 @@ bool GLFont::Create (const char *file_name, int tex, bool loadTexture)
//Read character array
for (int i = 0; i < num_chars; i++)
{
header.chars[i].dx = read_float(input);
header.chars[i].dy = read_float(input);
header.chars[i].tx1 = read_float(input);
header.chars[i].ty1 = read_float(input);
header.chars[i].tx2 = read_float(input);
header.chars[i].ty2 = read_float(input);
bb >> header.chars[i].dx;
bb >> header.chars[i].dy;
bb >> header.chars[i].tx1;
bb >> header.chars[i].ty1;
bb >> header.chars[i].tx2;
bb >> header.chars[i].ty2;
}
//Read texture pixel data
num_tex_bytes = header.tex_width * header.tex_height * 2;
tex_bytes = new char[num_tex_bytes];
input.read(tex_bytes, num_tex_bytes);
//input.read(tex_bytes, num_tex_bytes);
bb.read(tex_bytes, num_tex_bytes);
//Build2DMipmaps(3, header.tex_width, header.tex_height, GL_UNSIGNED_BYTE, tex_bytes, 1);
@ -147,9 +140,6 @@ bool GLFont::Create (const char *file_name, int tex, bool loadTexture)
//Free texture pixels memory
delete[] tex_bytes;
//Close input file
input.close();
//Return successfully
return true;
}