remove Engine::FileLoader

This commit is contained in:
Josh Holtrop 2011-05-19 22:55:09 -04:00
parent 89d98be780
commit 08dbe60b7b
2 changed files with 13 additions and 40 deletions

View File

@ -1260,52 +1260,36 @@ void Engine::drawObjects()
} }
} }
/******** Engine::EngineFileLoader functions ********/ int Engine::getFileSize(const char *fname)
Engine::EngineFileLoader::EngineFileLoader(Engine * engine)
{
m_engine = engine;
}
int Engine::EngineFileLoader::getSize(const Path & path)
{ {
struct stat st; struct stat st;
string file_path = resolvePath(path);
if (file_path == "") if (stat(fname, &st))
return -1;
if (stat(file_path.c_str(), &st))
return -2; return -2;
return st.st_size; return st.st_size;
} }
FileLoader::Buffer Engine::EngineFileLoader::load(const Path & path) const unsigned char *Engine::loadFile(const char *fname, unsigned int *len)
{ {
string file_path = resolvePath(path); string file_path = locateResource(fname);
int size = getSize(path); unsigned int size = getFileSize(file_path.c_str());
if (size > 0) if (size > 0)
{ {
FILE * fp = fopen(file_path.c_str(), "rb"); FILE * fp = fopen(file_path.c_str(), "rb");
if (fp != NULL) if (fp != NULL)
{ {
Buffer buf(size); unsigned char *data = malloc(size);
int num_read = fread(buf.data, size, 1, fp); int num_read = fread(data, size, 1, fp);
fclose(fp); fclose(fp);
if (num_read > 0) if (num_read > 0)
{ {
return buf; if (len != NULL)
*len = size;
return data;
} }
} }
} }
return Buffer(0); return NULL;
}
string Engine::EngineFileLoader::resolvePath(const Path & path)
{
string file_path = m_engine->locateResource(path.shortPath);
if (file_path == "")
file_path = path.fullPath;
return file_path;
} }

View File

@ -9,7 +9,6 @@
#include <SDL.h> #include <SDL.h>
#include "OdeWorld/OdeWorld.h" #include "OdeWorld/OdeWorld.h"
#include "TextureCache/TextureCache.h" #include "TextureCache/TextureCache.h"
#include "FileLoader/FileLoader.h"
#include "WFObj/WFObj.h" #include "WFObj/WFObj.h"
#include "AV.h" #include "AV.h"
#include "refptr/refptr.h" #include "refptr/refptr.h"
@ -131,17 +130,6 @@ class Engine
float m_texture_scale; float m_texture_scale;
}; };
class EngineFileLoader : public FileLoader
{
public:
EngineFileLoader(Engine * engine);
virtual int getSize(const Path & path);
virtual Buffer load(const Path & path);
protected:
std::string resolvePath(const Path & path);
Engine * m_engine;
};
class PickedObject class PickedObject
{ {
public: public:
@ -312,6 +300,8 @@ class Engine
protected: protected:
static Uint32 updateCallback(Uint32 interval, void * param); static Uint32 updateCallback(Uint32 interval, void * param);
int getFileSize(const char *fname);
const unsigned char *loadFile(const char *fname, unsigned int *len);
Uint32 updateCallback(Uint32 interval); Uint32 updateCallback(Uint32 interval);
void registerLibraries(); void registerLibraries();
@ -341,7 +331,6 @@ class Engine
bool m_script_cursor_visible; bool m_script_cursor_visible;
bool m_input_grabbed; bool m_input_grabbed;
TextureCache m_textureCache; TextureCache m_textureCache;
EngineFileLoader * m_fileLoader;
lua_State * m_luaState; lua_State * m_luaState;
std::string m_program_path; std::string m_program_path;
std::string m_program_directory; std::string m_program_directory;