From 08dbe60b7b7f552d9c3bc124ea091a7c55148cf4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 19 May 2011 22:55:09 -0400 Subject: [PATCH] remove Engine::FileLoader --- src/Engine.cc | 38 +++++++++++--------------------------- src/Engine.h | 15 ++------------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/Engine.cc b/src/Engine.cc index 661956f..bed1c62 100644 --- a/src/Engine.cc +++ b/src/Engine.cc @@ -1260,52 +1260,36 @@ void Engine::drawObjects() } } -/******** Engine::EngineFileLoader functions ********/ - -Engine::EngineFileLoader::EngineFileLoader(Engine * engine) -{ - m_engine = engine; -} - -int Engine::EngineFileLoader::getSize(const Path & path) +int Engine::getFileSize(const char *fname) { struct stat st; - string file_path = resolvePath(path); - if (file_path == "") - return -1; - if (stat(file_path.c_str(), &st)) + if (stat(fname, &st)) return -2; 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); - int size = getSize(path); + string file_path = locateResource(fname); + unsigned int size = getFileSize(file_path.c_str()); if (size > 0) { FILE * fp = fopen(file_path.c_str(), "rb"); if (fp != NULL) { - Buffer buf(size); - int num_read = fread(buf.data, size, 1, fp); + unsigned char *data = malloc(size); + int num_read = fread(data, size, 1, fp); fclose(fp); if (num_read > 0) { - return buf; + if (len != NULL) + *len = size; + return data; } } } - return Buffer(0); -} - -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; + return NULL; } diff --git a/src/Engine.h b/src/Engine.h index 71a1d61..2a27ef5 100644 --- a/src/Engine.h +++ b/src/Engine.h @@ -9,7 +9,6 @@ #include #include "OdeWorld/OdeWorld.h" #include "TextureCache/TextureCache.h" -#include "FileLoader/FileLoader.h" #include "WFObj/WFObj.h" #include "AV.h" #include "refptr/refptr.h" @@ -131,17 +130,6 @@ class Engine 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 { public: @@ -312,6 +300,8 @@ class Engine protected: 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); void registerLibraries(); @@ -341,7 +331,6 @@ class Engine bool m_script_cursor_visible; bool m_input_grabbed; TextureCache m_textureCache; - EngineFileLoader * m_fileLoader; lua_State * m_luaState; std::string m_program_path; std::string m_program_directory;