More tabs unification

This commit is contained in:
Henrik Rydgard
2012-05-08 22:29:28 +02:00
parent caf0580c38
commit 17f1e71da2
10 changed files with 480 additions and 480 deletions
+174 -174
View File
@@ -5,270 +5,270 @@
//#define CHUNKDEBUG
ChunkFile::ChunkFile(const char *filename, bool _read) {
data=0;
data=0;
fn = filename;
fastMode=false;
numLevels=0;
read=_read;
pos=0;
didFail=false;
fastMode=false;
numLevels=0;
read=_read;
pos=0;
didFail=false;
fastMode = read ? true : false;
if (fastMode) {
if (fastMode) {
size_t size;
data = (uint8 *)VFSReadFile(filename, &size);
if (!data) {
ELOG("Chunkfile fail: %s", filename);
didFail = true;
data = (uint8 *)VFSReadFile(filename, &size);
if (!data) {
ELOG("Chunkfile fail: %s", filename);
didFail = true;
return;
}
eof = size;
return;
}
if (file.open(filename, FILE_WRITE)) {
didFail=false;
eof=file.fileSize();
} else {
didFail=true;
return;
}
if (file.open(filename, FILE_WRITE)) {
didFail=false;
eof=file.fileSize();
} else {
didFail=true;
return;
}
}
ChunkFile::~ChunkFile() {
if (fastMode && data)
delete [] data;
else
file.close();
if (fastMode && data)
delete [] data;
else
file.close();
}
int ChunkFile::readInt() {
if (pos<eof) {
/*
int temp = *(int *)(data+pos);
pos+=4;
*/
pos+=4;
if (fastMode)
return *(int *)(data+pos-4);
else
return file.readInt();
} else {
return 0;
}
if (pos<eof) {
/*
int temp = *(int *)(data+pos);
pos+=4;
*/
pos+=4;
if (fastMode)
return *(int *)(data+pos-4);
else
return file.readInt();
} else {
return 0;
}
}
void ChunkFile::writeInt(int i) {
/*
*(int *)(data+pos) = i;
pos+=4;
*/
/*
*(int *)(data+pos) = i;
pos+=4;
*/
#ifndef DEMO_VERSION //if this is missing.. heheh
file.writeInt(i);
pos+=4;
file.writeInt(i);
pos+=4;
#endif
}
//let's get into the business
bool ChunkFile::descend(uint32 id) {
id=flipID(id);
if (read) {
bool found = false;
id=flipID(id);
if (read) {
bool found = false;
//save information to restore after the next Ascend
stack[numLevels].parentStartLocation = pos;
stack[numLevels].parentEOF = eof;
//save information to restore after the next Ascend
stack[numLevels].parentStartLocation = pos;
stack[numLevels].parentEOF = eof;
ChunkInfo temp = stack[numLevels];
ChunkInfo temp = stack[numLevels];
int firstID = 0;
//let's search through children..
while(pos<eof) {
stack[numLevels].ID = readInt();
if (firstID == 0) firstID=stack[numLevels].ID|1;
stack[numLevels].length = readInt();
stack[numLevels].startLocation = pos;
int firstID = 0;
//let's search through children..
while(pos<eof) {
stack[numLevels].ID = readInt();
if (firstID == 0) firstID=stack[numLevels].ID|1;
stack[numLevels].length = readInt();
stack[numLevels].startLocation = pos;
if (stack[numLevels].ID == id)
{
found = true;
break;
} else {
seekTo(pos + stack[numLevels].length); //try next block
}
}
if (stack[numLevels].ID == id)
{
found = true;
break;
} else {
seekTo(pos + stack[numLevels].length); //try next block
}
}
//if we found nothing, return false so the caller can skip this
if (!found) {
//if we found nothing, return false so the caller can skip this
if (!found) {
#ifdef CHUNKDEBUG
ILOG("Couldn't find %c%c%c%c", id, id>>8, id>>16, id>>24);
#endif
stack[numLevels]=temp;
seekTo(stack[numLevels].parentStartLocation);
return false;
}
stack[numLevels]=temp;
seekTo(stack[numLevels].parentStartLocation);
return false;
}
//descend into it
//pos was set inside the loop above
eof = stack[numLevels].startLocation + stack[numLevels].length;
numLevels++;
//descend into it
//pos was set inside the loop above
eof = stack[numLevels].startLocation + stack[numLevels].length;
numLevels++;
#ifdef CHUNKDEBUG
ILOG("Descended into %c%c%c%c", id, id>>8, id>>16, id>>24);
#endif
return true;
} else {
return true;
} else {
#ifndef DEMO_VERSION //if this is missing.. heheh
//write a chunk id, and prepare for filling in length later
writeInt(id);
writeInt(0); //will be filled in by Ascend
stack[numLevels].startLocation=pos;
numLevels++;
return true;
//write a chunk id, and prepare for filling in length later
writeInt(id);
writeInt(0); //will be filled in by Ascend
stack[numLevels].startLocation=pos;
numLevels++;
return true;
#else
return true;
return true;
#endif
}
}
}
void ChunkFile::seekTo(int _pos) {
if (!fastMode)
file.seekBeg(_pos);
pos=_pos;
if (!fastMode)
file.seekBeg(_pos);
pos=_pos;
}
//let's ascend out
void ChunkFile::ascend() {
if (read) {
//ascend, and restore information
numLevels--;
seekTo(stack[numLevels].parentStartLocation);
eof = stack[numLevels].parentEOF;
if (read) {
//ascend, and restore information
numLevels--;
seekTo(stack[numLevels].parentStartLocation);
eof = stack[numLevels].parentEOF;
#ifdef CHUNKDEBUG
int id = stack[numLevels].ID;
ILOG("Ascended out of %c%c%c%c", id, id>>8, id>>16, id>>24);
#endif
} else {
numLevels--;
//now fill in the written length automatically
int posNow = pos;
seekTo(stack[numLevels].startLocation - 4);
writeInt(posNow-stack[numLevels].startLocation);
seekTo(posNow);
}
} else {
numLevels--;
//now fill in the written length automatically
int posNow = pos;
seekTo(stack[numLevels].startLocation - 4);
writeInt(posNow-stack[numLevels].startLocation);
seekTo(posNow);
}
}
//read a block
void ChunkFile::readData(void *what, int count) {
if (fastMode)
memcpy(what, data + pos, count);
else
file.read(what,count);
if (fastMode)
memcpy(what, data + pos, count);
else
file.read(what,count);
pos+=count;
char temp[4]; //discarded
count &= 3;
if (count) {
count=4-count;
if (!fastMode)
file.read(temp,count);
pos+=count;
}
pos+=count;
char temp[4]; //discarded
count &= 3;
if (count) {
count=4-count;
if (!fastMode)
file.read(temp,count);
pos+=count;
}
}
//write a block
void ChunkFile::writeData(const void *what, int count) {
file.write(what, count);
pos+=count;
char temp[5]={0,0,0,0,0};
count &= 3;
if (count)
{
count=4-count;
file.write(temp,count);
pos+=count;
}
file.write(what, count);
pos+=count;
char temp[5]={0,0,0,0,0};
count &= 3;
if (count)
{
count=4-count;
file.write(temp,count);
pos+=count;
}
}
void ChunkFile::writeWString(String str) {
wchar_t *text;
int len=str.length();
wchar_t *text;
int len=str.length();
#ifdef UNICODE
text = str.getPointer();
text = str.getPointer();
#else
text=new wchar_t[len+1];
str.toUnicode(text);
text=new wchar_t[len+1];
str.toUnicode(text);
#endif
writeInt(len);
writeData((char *)text,len*sizeof(wchar_t));
writeInt(len);
writeData((char *)text,len*sizeof(wchar_t));
#ifndef UNICODE
delete [] text;
delete [] text;
#endif
}
String ChunkFile::readWString() {
int len=readInt();
wchar_t *text = new wchar_t[len+1];
readData((char *)text,len*sizeof(wchar_t));
text[len]=0;
int len=readInt();
wchar_t *text = new wchar_t[len+1];
readData((char *)text,len*sizeof(wchar_t));
text[len]=0;
#ifdef UNICODE
String s(text);
delete [] text;
return s;
String s(text);
delete [] text;
return s;
#else
String temp;
temp.fromUnicode(text);
delete [] text;
return temp;
String temp;
temp.fromUnicode(text);
delete [] text;
return temp;
#endif
}
static void toUnicode(const std::string &str, uint16 *t) {
for (int i=0; i<(int)str.size(); i++) {
*t++ = str[i];
}
*t++ = '\0';
for (int i=0; i<(int)str.size(); i++) {
*t++ = str[i];
}
*t++ = '\0';
}
static std::string fromUnicode(const uint16 *src, int len) {
struct Local {
static int clamp(int i) {
return i>255?' ':i;
}
};
struct Local {
static int clamp(int i) {
return i>255?' ':i;
}
};
std::string str;
str.resize(len);
std::string str;
str.resize(len);
for (int i=0; i<len; i++) {
str[i] = Local::clamp(src[i]);
}
return str;
for (int i=0; i<len; i++) {
str[i] = Local::clamp(src[i]);
}
return str;
}
void ChunkFile::writeString(const std::string &str) {
uint16_t *text;
int len = str.size();
text=new uint16_t[len+1];
toUnicode(str, text);
writeInt(len);
writeData((char *)text,len*sizeof(uint16_t));
delete [] text;
uint16_t *text;
int len = str.size();
text=new uint16_t[len+1];
toUnicode(str, text);
writeInt(len);
writeData((char *)text,len*sizeof(uint16_t));
delete [] text;
}
std::string ChunkFile::readString() {
int len=readInt();
uint16_t *text = new uint16_t[len+1];
readData((char *)text,len*sizeof(uint16_t));
text[len]=0;
std::string temp = fromUnicode(text, len);
delete [] text;
return temp;
int len=readInt();
uint16_t *text = new uint16_t[len+1];
readData((char *)text,len*sizeof(uint16_t));
text[len]=0;
std::string temp = fromUnicode(text, len);
delete [] text;
return temp;
}
int ChunkFile::getCurrentChunkSize() {
if (numLevels)
return stack[numLevels-1].length;
else
return 0;
if (numLevels)
return stack[numLevels-1].length;
else
return 0;
}
+33 -33
View File
@@ -15,53 +15,53 @@
#include "file/easy_file.h"
inline uint32 flipID(uint32 id) {
return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000);
return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000);
}
class ChunkFile {
public:
ChunkFile(const char *filename, bool _read);
~ChunkFile();
ChunkFile(const char *filename, bool _read);
~ChunkFile();
bool descend(uint32 id);
void ascend();
bool descend(uint32 id);
void ascend();
int readInt();
void readInt(int &i) {i = readInt();}
void readData(void *data, int count);
String readWString();
int readInt();
void readInt(int &i) {i = readInt();}
void readData(void *data, int count);
String readWString();
void writeString(const std::string &str);
std::string readString();
void writeInt(int i);
void writeWString(String str);
void writeData(const void *data, int count);
void writeInt(int i);
void writeWString(String str);
void writeData(const void *data, int count);
int getCurrentChunkSize();
bool failed() const {return didFail;}
int getCurrentChunkSize();
bool failed() const {return didFail;}
std::string filename() const { return fn; }
private:
std::string fn;
LAMEFile file;
struct ChunkInfo {
int startLocation;
int parentStartLocation;
int parentEOF;
unsigned int ID;
int length;
};
ChunkInfo stack[8];
int numLevels;
uint8 *data;
int pos,eof;
bool fastMode;
bool read;
bool didFail;
void seekTo(int _pos);
int getPos() const {return pos;}
LAMEFile file;
struct ChunkInfo {
int startLocation;
int parentStartLocation;
int parentEOF;
unsigned int ID;
int length;
};
ChunkInfo stack[8];
int numLevels;
uint8 *data;
int pos,eof;
bool fastMode;
bool read;
bool didFail;
void seekTo(int _pos);
int getPos() const {return pos;}
};
+43 -43
View File
@@ -10,55 +10,55 @@
// An false returned means cancel;
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
{
OPENFILENAME of;
memset(&of, 0, sizeof(of));
char buffer[512] = {0};
of.lStructSize = sizeof(OPENFILENAME);
of.hInstance = 0;
of.hwndOwner = GetActiveWindow();
OPENFILENAME of;
memset(&of, 0, sizeof(of));
char buffer[512] = {0};
of.lStructSize = sizeof(OPENFILENAME);
of.hInstance = 0;
of.hwndOwner = GetActiveWindow();
// These weird strings with zeroes in them can't be dealt with using normal string
// functions, so here we go - evil hackery.
char filter[256] = "XXX files\0*.XXX\0\0";
memcpy(filter, extension, 3);
memcpy(filter + 12, extension, 3);
of.lpstrFilter = filter;
// These weird strings with zeroes in them can't be dealt with using normal string
// functions, so here we go - evil hackery.
char filter[256] = "XXX files\0*.XXX\0\0";
memcpy(filter, extension, 3);
memcpy(filter + 12, extension, 3);
of.lpstrFilter = filter;
of.lpstrDefExt = extension;
of.lpstrFile = buffer;
of.nMaxFile = 511;
of.lpstrDefExt = extension;
of.lpstrFile = buffer;
of.nMaxFile = 511;
of.Flags = OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&of)) return false;
*filename = of.lpstrFile;
return true;
of.Flags = OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&of)) return false;
*filename = of.lpstrFile;
return true;
}
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
{
OPENFILENAME of;
memset(&of, 0, sizeof(of));
char buffer[512] = {0};
of.lStructSize = sizeof(OPENFILENAME);
of.hInstance = 0;
of.hwndOwner = GetActiveWindow();
OPENFILENAME of;
memset(&of, 0, sizeof(of));
char buffer[512] = {0};
of.lStructSize = sizeof(OPENFILENAME);
of.hInstance = 0;
of.hwndOwner = GetActiveWindow();
// These weird strings with zeroes in them can't be dealt with using normal string
// functions, so here we go - evil hackery.
char filter[256] = "XXX files\0*.XXX\0\0";
memcpy(filter, extension, 3);
memcpy(filter + 12, extension, 3);
of.lpstrFilter = filter;
// These weird strings with zeroes in them can't be dealt with using normal string
// functions, so here we go - evil hackery.
char filter[256] = "XXX files\0*.XXX\0\0";
memcpy(filter, extension, 3);
memcpy(filter + 12, extension, 3);
of.lpstrFilter = filter;
of.lpstrDefExt = extension;
of.lpstrFile = buffer;
of.nMaxFile = 511;
of.lpstrDefExt = extension;
of.lpstrFile = buffer;
of.nMaxFile = 511;
of.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
if (!GetSaveFileName(&of))
return false;
*filename = of.lpstrFile;
return true;
of.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
if (!GetSaveFileName(&of))
return false;
*filename = of.lpstrFile;
return true;
}
#else
@@ -69,14 +69,14 @@ bool SaveFileDialog(const char *title, const char *extension, std::string *filen
bool OpenFileDialog(const char *title, const char *extension, std::string *filename)
{
ELOG("Asked for OpenFileDialog, not present on this platform.");
return false;
ELOG("Asked for OpenFileDialog, not present on this platform.");
return false;
}
bool SaveFileDialog(const char *title, const char *extension, std::string *filename)
{
ELOG("Asked for SaveFileDialog, not present on this platform.");
return false;
ELOG("Asked for SaveFileDialog, not present on this platform.");
return false;
}
#endif
+50 -50
View File
@@ -5,87 +5,87 @@
#include "file/easy_file.h"
LAMEFile::LAMEFile() : file_(NULL) {
isOpen = false;
isOpen = false;
}
LAMEFile::~LAMEFile() { }
bool LAMEFile::open(const char *filename, eFileMode mode) {
file_ = fopen(filename, mode == FILE_READ ? "rb" : "wb");
file_ = fopen(filename, mode == FILE_READ ? "rb" : "wb");
if (!file_) {
isOpen = false;
} else {
isOpen = true;
if (mode == FILE_READ) {
fseek(file_, 0, SEEK_END);
size_ = ftell(file_);
fseek(file_, 0, SEEK_SET);
}
}
return isOpen;
if (!file_) {
isOpen = false;
} else {
isOpen = true;
if (mode == FILE_READ) {
fseek(file_, 0, SEEK_END);
size_ = ftell(file_);
fseek(file_, 0, SEEK_SET);
}
}
return isOpen;
}
void LAMEFile::close() {
if (isOpen) {
//close the file and reset variables
fclose(file_);
file_ = NULL;
isOpen=false;
}
if (isOpen) {
//close the file and reset variables
fclose(file_);
file_ = NULL;
isOpen=false;
}
}
int LAMEFile::fileSize() {
if (!isOpen) //of course
return 0;
else
return size_;
if (!isOpen) //of course
return 0;
else
return size_;
}
std::string LAMEFile::readAll() {
std::string s;
size_t size = fileSize();
s.resize(size);
read(&s[0], size);
return s;
std::string s;
size_t size = fileSize();
s.resize(size);
read(&s[0], size);
return s;
}
int LAMEFile::write(const void *data, int size) {
if (isOpen) {
return fwrite(data, 1, size, file_); //we return the number of bytes that actually got written
} else {
return 0;
}
if (isOpen) {
return fwrite(data, 1, size, file_); //we return the number of bytes that actually got written
} else {
return 0;
}
}
int LAMEFile::read(void *data, int size) {
if (isOpen) {
return fread(data, 1, size, file_);
} else {
return 0;
}
if (isOpen) {
return fread(data, 1, size, file_);
} else {
return 0;
}
}
int LAMEFile::readInt() {
int temp;
if (read(&temp, sizeof(int)))
return temp;
else
return 0;
int temp;
if (read(&temp, sizeof(int)))
return temp;
else
return 0;
}
void LAMEFile::writeInt(int i) {
write(&i, sizeof(int));
write(&i, sizeof(int));
}
char LAMEFile::readChar() {
char temp;
if (read(&temp, sizeof(char)))
return temp;
else
return 0;
char temp;
if (read(&temp, sizeof(char)))
return temp;
else
return 0;
}
void LAMEFile::writeChar(char i) {
write(&i,sizeof(char));
write(&i,sizeof(char));
}
+32 -32
View File
@@ -11,48 +11,48 @@
// Raw file paths, does not go through VFS.
enum eFileMode {
FILE_READ=5,
FILE_WRITE=6
FILE_READ=5,
FILE_WRITE=6
};
// TODO: Rename.
class LAMEFile {
public:
LAMEFile();
virtual ~LAMEFile();
LAMEFile();
virtual ~LAMEFile();
bool open(const char *filename, eFileMode mode);
bool open(std::string filename, eFileMode mode) {
return open(filename.c_str(), mode);
}
void close();
bool open(const char *filename, eFileMode mode);
bool open(std::string filename, eFileMode mode) {
return open(filename.c_str(), mode);
}
void close();
void writeInt(int i);
void writeChar(char i);
int write(const void *data, int size);
void write(const std::string &str) {
write((void *)str.data(), str.size());
}
void writeInt(int i);
void writeChar(char i);
int write(const void *data, int size);
void write(const std::string &str) {
write((void *)str.data(), str.size());
}
int readInt();
char readChar();
int read(void *data, int size);
int readInt();
char readChar();
int read(void *data, int size);
std::string readAll();
std::string readAll();
int fileSize();
int fileSize();
void seekBeg(int pos) {
if (isOpen) fseek(file_,pos,SEEK_SET);
}
void seekEnd(int pos) {
if (isOpen) fseek(file_,pos,SEEK_END);
}
void seekCurrent(int pos) {
if (isOpen) fseek(file_,pos,SEEK_CUR);
}
void seekBeg(int pos) {
if (isOpen) fseek(file_,pos,SEEK_SET);
}
void seekEnd(int pos) {
if (isOpen) fseek(file_,pos,SEEK_END);
}
void seekCurrent(int pos) {
if (isOpen) fseek(file_,pos,SEEK_CUR);
}
private:
FILE *file_;
bool isOpen;
int size_;
FILE *file_;
bool isOpen;
int size_;
};
+79 -79
View File
@@ -14,47 +14,47 @@
bool writeStringToFile(bool text_file, const std::string &str, const char *filename)
{
FILE *f = fopen(filename, text_file ? "w" : "wb");
if (!f)
return false;
size_t len = str.size();
if (len != fwrite(str.data(), 1, str.size(), f))
{
fclose(f);
return false;
}
fclose(f);
return true;
FILE *f = fopen(filename, text_file ? "w" : "wb");
if (!f)
return false;
size_t len = str.size();
if (len != fwrite(str.data(), 1, str.size(), f))
{
fclose(f);
return false;
}
fclose(f);
return true;
}
uint64_t GetSize(FILE *f)
{
// can't use off_t here because it can be 32-bit
uint64_t pos = ftell(f);
if (fseek(f, 0, SEEK_END) != 0) {
return 0;
}
uint64_t size = ftell(f);
// can't use off_t here because it can be 32-bit
uint64_t pos = ftell(f);
if (fseek(f, 0, SEEK_END) != 0) {
return 0;
}
uint64_t size = ftell(f);
// Reset the seek position to where it was when we started.
if ((size != pos) && (fseek(f, pos, SEEK_SET) != 0)) {
if ((size != pos) && (fseek(f, pos, SEEK_SET) != 0)) {
// Should error here
return 0;
}
return size;
return 0;
}
return size;
}
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
{
FILE *f = fopen(filename, text_file ? "r" : "rb");
if (!f)
return false;
size_t len = (size_t)GetSize(f);
char *buf = new char[len + 1];
buf[fread(buf, 1, len, f)] = 0;
str = std::string(buf, len);
fclose(f);
delete [] buf;
return true;
FILE *f = fopen(filename, text_file ? "r" : "rb");
if (!f)
return false;
size_t len = (size_t)GetSize(f);
char *buf = new char[len + 1];
buf[fread(buf, 1, len, f)] = 0;
str = std::string(buf, len);
fclose(f);
delete [] buf;
return true;
}
#define DIR_SEP "/"
@@ -63,77 +63,77 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str)
size_t getFilesInDir(const char *directory, std::vector<std::string> *files)
{
size_t foundEntries = 0;
size_t foundEntries = 0;
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
#ifdef UNICODE
HANDLE hFind = FindFirstFile((std::wstring(directory) + "\\*").c_str(), &ffd);
HANDLE hFind = FindFirstFile((std::wstring(directory) + "\\*").c_str(), &ffd);
#else
HANDLE hFind = FindFirstFile((std::string(directory) + "\\*").c_str(), &ffd);
HANDLE hFind = FindFirstFile((std::string(directory) + "\\*").c_str(), &ffd);
#endif
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return foundEntries;
}
// windows loop
do
{
const std::string virtualName(ffd.cFileName);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return foundEntries;
}
// windows loop
do
{
const std::string virtualName(ffd.cFileName);
#else
struct dirent dirent, *result = NULL;
struct dirent dirent, *result = NULL;
DIR *dirp = opendir(directory);
if (!dirp)
return 0;
DIR *dirp = opendir(directory);
if (!dirp)
return 0;
// non windows loop
while (!readdir_r(dirp, &dirent, &result) && result)
{
const std::string virtualName(result->d_name);
// non windows loop
while (!readdir_r(dirp, &dirent, &result) && result)
{
const std::string virtualName(result->d_name);
#endif
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
continue;
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
continue;
files->push_back(std::string(directory) + virtualName);
files->push_back(std::string(directory) + virtualName);
#ifdef _WIN32
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#else
}
}
closedir(dirp);
#endif
return foundEntries;
return foundEntries;
}
void deleteFile(const char *file)
{
#ifdef _WIN32
if (!DeleteFile(file)) {
ELOG("Error deleting %s: %i", file, GetLastError());
}
if (!DeleteFile(file)) {
ELOG("Error deleting %s: %i", file, GetLastError());
}
#else
int err = unlink(file);
if (err) {
ELOG("Error unlinking %s: %i", file, err);
}
int err = unlink(file);
if (err) {
ELOG("Error unlinking %s: %i", file, err);
}
#endif
}
#endif
std::string getDir(const std::string &path)
{
int n = path.size() - 1;
while (n >= 0 && path[n] != '\\' && path[n] != '/')
n--;
std::string cutpath = path.substr(0, n);
for (size_t i = 0; i < cutpath.size(); i++)
{
if (cutpath[i] == '\\') cutpath[i] = '/';
}
return cutpath;
int n = path.size() - 1;
while (n >= 0 && path[n] != '\\' && path[n] != '/')
n--;
std::string cutpath = path.substr(0, n);
for (size_t i = 0; i < cutpath.size(); i++)
{
if (cutpath[i] == '\\') cutpath[i] = '/';
}
return cutpath;
}
+11 -11
View File
@@ -83,13 +83,13 @@ uint8_t *ZipAssetReader::ReadAsset(const char *path, size_t *size) {
#endif
uint8_t *DirectoryAssetReader::ReadAsset(const char *path, size_t *size) {
char new_path[256] = {0};
// Check if it already contains the path
char new_path[256] = {0};
// Check if it already contains the path
if (strlen(path) > strlen(path_) && 0 == memcmp(path, path_, strlen(path_))) {
}
else {
strcpy(new_path, path_);
}
}
else {
strcpy(new_path, path_);
}
strcat(new_path, path);
// ILOG("New path: %s", new_path);
return ReadLocalFile(new_path, size);
@@ -125,11 +125,11 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) {
if (0 == memcmp(filename, entries[i].prefix, prefix_len)) {
// ILOG("Prefix match: %s (%s) -> %s", entries[i].prefix, filename, filename + prefix_len);
uint8_t *data = entries[i].reader->ReadAsset(filename + prefix_len, size);
if (data)
return data;
else
continue;
// Else try the other registered file systems.
if (data)
return data;
else
continue;
// Else try the other registered file systems.
}
}
ELOG("Missing filesystem for %s", filename);
+35 -35
View File
@@ -7,17 +7,17 @@
namespace GestureDetector {
struct Finger {
bool down;
float X;
float Y;
float lastX;
float lastY;
float downX;
float downY;
float deltaX;
float deltaY;
float smoothDeltaX;
float smoothDeltaY;
bool down;
float X;
float Y;
float lastX;
float lastY;
float downX;
float downY;
float deltaX;
float deltaY;
float smoothDeltaX;
float smoothDeltaY;
};
// State
@@ -26,43 +26,43 @@ struct Finger {
static Finger fingers[MAX_FINGERS];
void update(const InputState &state) {
// Mouse / 1-finger-touch control.
if (state.mouse_down[0]) {
fingers[0].down = true;
fingers[0].downX = state.mouse_x[0];
fingers[0].downY = state.mouse_y[0];
} else {
fingers[0].down = false;
}
// Mouse / 1-finger-touch control.
if (state.mouse_down[0]) {
fingers[0].down = true;
fingers[0].downX = state.mouse_x[0];
fingers[0].downY = state.mouse_y[0];
} else {
fingers[0].down = false;
}
fingers[0].lastX = fingers[0].X;
fingers[0].lastY = fingers[0].Y;
fingers[0].lastX = fingers[0].X;
fingers[0].lastY = fingers[0].Y;
// TODO: real multitouch
// TODO: real multitouch
}
bool down(int i, float *xdelta, float *ydelta) {
if (!fingers[i].down) {
return false;
}
*xdelta = fingers[i].downX;
*ydelta = fingers[i].downY;
if (!fingers[i].down) {
return false;
}
*xdelta = fingers[i].downX;
*ydelta = fingers[i].downY;
}
bool dragDistance(int i, float *xdelta, float *ydelta) {
if (!fingers[i].down)
return false;
if (!fingers[i].down)
return false;
*xdelta = fingers[i].X - fingers[i].downX;
*ydelta = fingers[i].Y - fingers[i].downY;
*xdelta = fingers[i].X - fingers[i].downX;
*ydelta = fingers[i].Y - fingers[i].downY;
}
bool dragDelta(int i, float *xdelta, float *ydelta) {
if (!fingers[i].down)
return false;
if (!fingers[i].down)
return false;
*xdelta = fingers[i].X - fingers[i].lastX;
*ydelta = fingers[i].Y - fingers[i].lastY;
*xdelta = fingers[i].X - fingers[i].lastX;
*ydelta = fingers[i].Y - fingers[i].lastY;
}
}
+9 -9
View File
@@ -5,17 +5,17 @@
namespace GestureDetector
{
void update(const InputState &state);
void update(const InputState &state);
bool down(int finger, float *xdown, float *ydown);
bool down(int finger, float *xdown, float *ydown);
// x/ydelta is difference from current location to the start of the drag.
// Returns true if button/finger is down, for convenience.
bool dragDistance(int finger, float *xdelta, float *ydelta);
// x/ydelta is (smoothed?) difference from current location to the position from the last frame.
// Returns true if button/finger is down, for convenience.
bool dragDelta(int finger, float *xdelta, float *ydelta);
// x/ydelta is difference from current location to the start of the drag.
// Returns true if button/finger is down, for convenience.
bool dragDistance(int finger, float *xdelta, float *ydelta);
// x/ydelta is (smoothed?) difference from current location to the position from the last frame.
// Returns true if button/finger is down, for convenience.
bool dragDelta(int finger, float *xdelta, float *ydelta);
};
+14 -14
View File
@@ -21,22 +21,22 @@ enum {
#ifndef MAX_POINTERS
#define MAX_POINTERS 8
#endif
// Agglomeration of all possible inputs, and automatically computed
// deltas where applicable.
struct InputState {
// Lock this whenever you access the data in this struct.
mutable recursive_mutex lock;
InputState()
: pad_buttons(0),
pad_last_buttons(0),
pad_buttons_down(0),
pad_buttons_up(0),
mouse_valid(false),
accelerometer_valid(false) {
memset(mouse_down, 0, sizeof(mouse_down));
memset(mouse_last, 0, sizeof(mouse_last));
}
// Lock this whenever you access the data in this struct.
mutable recursive_mutex lock;
InputState()
: pad_buttons(0),
pad_last_buttons(0),
pad_buttons_down(0),
pad_buttons_up(0),
mouse_valid(false),
accelerometer_valid(false) {
memset(mouse_down, 0, sizeof(mouse_down));
memset(mouse_last, 0, sizeof(mouse_last));
}
// Gamepad style input
int pad_buttons; // bitfield
@@ -51,7 +51,7 @@ struct InputState {
float pad_rtrigger;
// Mouse/touch style input
// There are up to 8 mice / fingers.
// There are up to 8 mice / fingers.
volatile bool mouse_valid;
int mouse_x[MAX_POINTERS];