Some warning cleanup involving (seemlingly unintended) bool to int conversions. It seems that the original design intent was to pass down IDs to the base class JGuiObject, but certain classes broke the pattern with their constructors.

(One could argue that this ID is completely meaningless and could be entirely ripped out, as the IDs obviously never made it to their intended target...)
This commit is contained in:
wrenczes@gmail.com
2011-06-02 05:33:45 +00:00
parent dcfbff6216
commit a06558be55
6 changed files with 207 additions and 12 deletions

View File

@@ -28,6 +28,61 @@
using namespace std;
class JFile
{
public:
JFile();
virtual ~JFile();
virtual bool OpenFile(const string &filename);
virtual int ReadFile(void *buffer, int size);
virtual int GetFileSize();
virtual void CloseFile();
protected:
std::string mFilename;
#if defined (PSP)
SceUID mFile;
#else
FILE *mFile;
#endif
int mFileSize;
};
class JZipFile : public JFile
{
public:
JZipFile(const std::string& inZipFilename);
virtual ~JZipFile();
/*
** Access filename within the zip.
*/
virtual bool OpenFile(const string &filename);
virtual int ReadFile(void *buffer, int size);
virtual int GetFileSize();
virtual void CloseFile();
private:
std::string mZipFilename;
unzFile mZipFile;
};
//////////////////////////////////////////////////////////////////////////
/// Interface for low level file access with ZIP archive support. All
/// file operations in JGE are handled through this class so if a ZIP

View File

@@ -24,6 +24,136 @@
#include <map>
#include <string>
#include "../include/DebugRoutines.h"
#include <fstream>
JFile::JFile() : mFile(0), mFileSize(0)
{
}
JFile::~JFile()
{
}
bool JFile::OpenFile(const string &filename)
{
bool result = false;
mFilename = JFileSystem::GetInstance()->GetResourceRoot() + filename;
#if defined (PSP)
mFile = sceIoOpen(mFilename.c_str(), PSP_O_RDONLY, 0777);
if (mFile > 0)
{
mFileSize = sceIoLseek(mFile, 0, PSP_SEEK_END);
sceIoLseek(mFile, 0, PSP_SEEK_SET);
result = true;
}
#else
mFile = fopen(mFilename.c_str(), "rb");
if (mFile != NULL)
{
fseek(mFile, 0, SEEK_END);
mFileSize = ftell(mFile);
fseek(mFile, 0, SEEK_SET);
result = true;
}
#endif
return result;
}
int JFile::ReadFile(void *buffer, int size)
{
#if defined (PSP)
return sceIoRead(mFile, buffer, size);
#else
return fread(buffer, 1, size, mFile);
#endif
}
int JFile::GetFileSize()
{
return mFileSize;
}
void JFile::CloseFile()
{
#if defined (PSP)
if (mFile > 0)
sceIoClose(mFile);
#else
if (mFile != NULL)
fclose(mFile);
#endif
mFile = 0;
mFileSize = 0;
}
JZipFile::JZipFile(const std::string& inZipFilename)
: mZipFilename(inZipFilename)
{
mZipFile = unzOpen(mZipFilename.c_str());
assert(mZipFile);
if (mZipFile == NULL)
throw;
}
JZipFile::~JZipFile()
{
unzClose(mZipFile);
}
const int kCaseInsensitive = 2;
bool JZipFile::OpenFile(const string &filename)
{
bool result = false;
mFilename = JFileSystem::GetInstance()->GetResourceRoot() + filename;
if (mZipFile)
{
int fileAttempt = unzLocateFile(mZipFile, mFilename.c_str(), kCaseInsensitive);
if (fileAttempt != UNZ_END_OF_LIST_OF_FILE)
{
result = (unzOpenCurrentFile(mZipFile) == UNZ_OK);
}
}
return result;
}
int JZipFile::ReadFile(void *buffer, int size)
{
return unzReadCurrentFile(mZipFile, buffer, size);
}
int JZipFile::GetFileSize()
{
int result = 0;
if (mZipFile != NULL)
{
unz_file_info info;
unzGetCurrentFileInfo(mZipFile, &info, NULL, 0, NULL, 0, NULL, 0);
result = info.uncompressed_size;
}
return result;
}
void JZipFile::CloseFile()
{
if (mZipFile != NULL)
{
unzCloseCurrentFile(mZipFile);
}
}
JZipCache::JZipCache()
{}
@@ -281,7 +411,16 @@ void JFileSystem::SetResourceRoot(const string& resourceRoot)
mResourceRoot = [documentsDirectory cStringUsingEncoding:1];
mResourceRoot += "/";
#elif defined (ANDROID)
mResourceRoot = "/sdcard/Wagic/Res/";
mResourceRoot = "/mnt/sdcard-ext/Wagic/Res/";
DebugTrace("test: writing to /sdcard-ext/ ");
std::ofstream file("/mnt/sdcard-ext/Foo.txt");
if (file)
{
DebugTrace("successfully opened foo.txt...");
file << "test";
file.close();
}
#else
mResourceRoot = resourceRoot;
#endif

View File

@@ -83,11 +83,9 @@ public:
return TARGET_STACKACTION;
}
Interruptible(bool hasFocus = false) : PlayGuiObject(40,x,y,hasFocus)
Interruptible(int inID = 0, bool hasFocus = false)
: PlayGuiObject(40, x, y, inID, hasFocus), state(NOT_RESOLVED), display(0), source(NULL)
{
state = NOT_RESOLVED;
display = 0;
source = NULL;
}
virtual const string getDisplayName() const;

View File

@@ -51,8 +51,11 @@ public:
;
virtual void Render();
virtual void Update(float dt);
PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus);
PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus);
PlayGuiObject(float desiredHeight, float x, float y, int inID, bool hasFocus);
PlayGuiObject(float desiredHeight, const Pos& ref, int inID, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId) {}
virtual bool getTopLeft(float& top, float& left)
{

View File

@@ -4,7 +4,7 @@
#include "GuiStatic.h"
GuiStatic::GuiStatic(float desiredHeight, float x, float y, bool hasFocus, GuiAvatars* parent) :
PlayGuiObject(desiredHeight, x, y, hasFocus), parent(parent)
PlayGuiObject(desiredHeight, x, y, 0, hasFocus), parent(parent)
{
}

View File

@@ -4,8 +4,8 @@
using namespace std;
PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus) :
JGuiObject(0), Pos(x, y, 1.0, 0.0, 255)
PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, int inID, bool hasFocus)
: JGuiObject(inID), Pos(x, y, 1.0, 0.0, 255)
{
defaultHeight = desiredHeight;
mHeight = desiredHeight;
@@ -13,8 +13,8 @@ PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocu
type = 0;
wave = 0;
}
PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus) :
JGuiObject(0), Pos(ref)
PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, int inID, bool hasFocus)
: JGuiObject(inID), Pos(ref)
{
defaultHeight = desiredHeight;
mHeight = desiredHeight;