From d3477eedc113a2c126f36f41384b8921d610906a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 8 Feb 2008 19:24:12 +0000 Subject: updated filesystem, removed inifile, updated game and tga loader minor cleanups --- src/core/commandbuffer.cc | 2 +- src/core/cvar.cc | 2 +- src/core/func.cc | 2 +- src/filesystem/Makefile.am | 4 +- src/filesystem/diskfile.cc | 95 ++++++++++++++++++++++++++++ src/filesystem/diskfile.h | 43 +++++++++++++ src/filesystem/file.cc | 58 +---------------- src/filesystem/file.h | 43 +++++++------ src/filesystem/filesystem.cc | 59 +++++++++++++++--- src/filesystem/filesystem.h | 26 +++++--- src/filesystem/path.cc | 33 ---------- src/filesystem/path.h | 26 -------- src/filesystem/vfile.cc | 24 ------- src/filesystem/vfile.h | 31 --------- src/game/game.cc | 7 ++- src/render/render.cc | 11 +++- src/render/tga.cc | 145 +++++++++++++++++-------------------------- src/render/tga.h | 2 +- src/sys/sys.cc | 10 ++- src/sys/sys.h | 21 ++++--- 20 files changed, 328 insertions(+), 316 deletions(-) create mode 100644 src/filesystem/diskfile.cc create mode 100644 src/filesystem/diskfile.h delete mode 100644 src/filesystem/path.cc delete mode 100644 src/filesystem/path.h delete mode 100644 src/filesystem/vfile.cc delete mode 100644 src/filesystem/vfile.h (limited to 'src') diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index adb3bac..eaa8504 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -51,7 +51,7 @@ void exec(const char *text) return; } - con_print << "unknown command '" << cmdname << "'" << std::endl; + con_print << "Unknown command '" << cmdname << "'" << std::endl; } void execute() diff --git a/src/core/cvar.cc b/src/core/cvar.cc index ce31a49..9d1c167 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -160,7 +160,7 @@ void list() for (it = registry.begin(); it != registry.end(); it++) { con_print << " "<< (*it).first << " " << (*it).second->text() << std::endl; } - con_print << registry.size() << " registered variables." << std::endl; + con_print << registry.size() << " registered variables" << std::endl; } } // namespace cvar diff --git a/src/core/func.cc b/src/core/func.cc index 02e7f7d..664af4a 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -47,7 +47,7 @@ void list() for (it = registry.begin(); it != registry.end(); it++) { con_print << " " << (*it).first << std::endl; } - con_print << registry.size() << " registered functions." << std::endl; + con_print << registry.size() << " registered functions" << std::endl; } } // namespace func diff --git a/src/filesystem/Makefile.am b/src/filesystem/Makefile.am index 65540f1..20cd25a 100644 --- a/src/filesystem/Makefile.am +++ b/src/filesystem/Makefile.am @@ -1,9 +1,9 @@ METASOURCES = AUTO -libfilesystem_la_SOURCES = file.cc filesystem.cc inifile.cc path.cc vfile.cc +libfilesystem_la_SOURCES = diskfile.cc file.cc filesystem.cc libfilesystem_la_LDFLAGS = -avoid-version -no-undefined libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la noinst_LTLIBRARIES = libfilesystem.la -noinst_HEADERS = file.h filesystem.h inifile.h path.h vfile.h +noinst_HEADERS = diskfile.h file.h filesystem.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/filesystem/diskfile.cc b/src/filesystem/diskfile.cc new file mode 100644 index 0000000..85f6ccc --- /dev/null +++ b/src/filesystem/diskfile.cc @@ -0,0 +1,95 @@ +/* + filesystem/file.c + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "filesystem/diskfile.h" + +namespace filesystem { + +DiskFile::DiskFile() +{ + diskfile_handle = 0; +} + +DiskFile::~DiskFile() +{ + if (diskfile_handle) + fclose(diskfile_handle); +} + +bool DiskFile::open(const char *filename) +{ + if (diskfile_handle) { + con_warn << file_name << " already open!" << std::endl; + return false; + } + + file_name.assign(filename); + std::string fn; + + // if moddir is set, try the mods subdir first + if (moddir.size()) { + // try homedir + moddir + file_path = homedir; + file_path.append(moddir); + fn = file_path; + fn.append(filename); + diskfile_handle = fopen(fn.c_str(), "r"); + if (diskfile_handle) + return true; + + // try datadir + moddir + file_path = datadir; + file_path.append(moddir); + fn = file_path; + fn.append(filename); + diskfile_handle = fopen(fn.c_str(), "r"); + if (diskfile_handle) + return true; + } + // try homedir + basedir + file_path = homedir; + file_path.append(basedir); + fn = file_path; + fn.append(filename); + diskfile_handle = fopen(fn.c_str(), "r"); + if (diskfile_handle) + return true; + + // try datadir + basedir + file_path = datadir; + file_path.append(basedir); + fn = file_path; + fn.append(filename); + diskfile_handle = fopen(fn.c_str(), "r"); + if (diskfile_handle) + return true; + + con_warn << "Could not open " << filename << std::endl; + return false; +} + +void DiskFile::close() +{ + if (diskfile_handle) + fclose(diskfile_handle); + diskfile_handle = 0; +} + +size_t DiskFile::read(void *buffer, const size_t count) +{ + if (!diskfile_handle) + return 0; + + return (fread(buffer, count, 1, diskfile_handle)); +} + +void DiskFile::skip(size_t count) +{ + fseek(diskfile_handle, (long) count, SEEK_CUR); +} + +} // namespace filesystem + diff --git a/src/filesystem/diskfile.h b/src/filesystem/diskfile.h new file mode 100644 index 0000000..b71576d --- /dev/null +++ b/src/filesystem/diskfile.h @@ -0,0 +1,43 @@ +/* + filesystem/diskfile.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_FILESYSTEM_DISKFILE_H__ +#define __INCLUDED_FILESYSTEM_DISKFILE_H__ + +#include "filesystem/filesystem.h" +#include "sys/sys.h" + +#include + +#include + +namespace filesystem +{ + +/** + * @brief implementation of File for a file on disk + */ +class DiskFile : public File +{ +public: + DiskFile(); + virtual ~DiskFile(); + + virtual bool open(const char * filename); + virtual void close(); + + virtual size_t read(void *buffer, size_t count); + + void skip(size_t count); + +private: + FILE *diskfile_handle; +}; + +} // namespace filesystem + +#endif // __INCLUDED_FILESYSTEM_DISKFILE_H__ + diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc index f05e60c..07f8870 100644 --- a/src/filesystem/file.cc +++ b/src/filesystem/file.cc @@ -5,8 +5,7 @@ */ // project headers -#include "sys/sys.h" -#include "filesystem/filesystem.h" +#include "filesystem/file.h" namespace filesystem { @@ -14,60 +13,5 @@ File::File() {} File::~File() {} -void File::open(const char * filename, ios_base::openmode mode) { - file_name.assign(filename); - std::string fn; - - real_name.clear(); - - // if moddir is set, try the mods subdir first - if (moddir.size()) { - // try homedir + moddir - fn = homedir; - fn.append(moddir); - fn.append(filename); - std::ifstream::open(fn.c_str(), mode); - if (this->is_open()) { - real_name = fn; - con_debug << "File opened " << fn << std::endl; - return; - } - - // try datadir + moddir - fn = datadir; - fn.append(moddir); - std::ifstream::open(fn.c_str(), mode); - if (this->is_open()) { - con_debug << "File opened " << fn << std::endl; - real_name = fn; - return; - } - } - - // try homedir + basedir - fn = homedir; - fn.append(basedir); - fn.append(filename); - std::ifstream::open(fn.c_str(), mode); - if (this->is_open()) { - con_debug << "File opened " << fn << std::endl; - real_name = fn; - return; - } - - // try datadir + basedir - fn = datadir; - fn.append(basedir); - fn.append(filename); - std::ifstream::open(fn.c_str(), mode); - - if (!this->is_open()) { - con_warn << "Could not open " << filename << std::endl; - } else { - con_debug << "File opened " << fn << std::endl; - real_name = fn; - } -} - } // namespace filesystem diff --git a/src/filesystem/file.h b/src/filesystem/file.h index ba392de..37ac8b4 100644 --- a/src/filesystem/file.h +++ b/src/filesystem/file.h @@ -9,34 +9,41 @@ // C++ headers #include -#include namespace filesystem { -/// a class to open data files -class File : public std::ifstream { +/** + * @brief an abstract interface to handle file access + */ +class File +{ public: File(); virtual ~File(); - /// open the file for reading - virtual void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in); + /// open file for reading + virtual bool open(const char * filename) = 0; - /// current filename - inline std::string name() { - return file_name; - } - - /// current full path - inline std::string path() { - return real_name; - } + /// close file + virtual void close() = 0; -private: + /// read bytes + virtual size_t read(void *buffer, size_t count) = 0; + + /// skip bytes + virtual void skip(size_t count) = 0; + + /// name of the file in the virtual filesystem + inline const std::string name() const { return file_name; } + + /// the path holding the virtual filename + inline const std::string path() const { return file_path; } + +protected: std::string file_name; - std::string real_name; -} -; // class File + + std::string file_path; +}; } // namespace filesystem diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index da80ea5..f34ac42 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -5,15 +5,22 @@ */ // project headers + #include "filesystem/filesystem.h" +#include "filesystem/diskfile.h" +#include "filesystem/file.h" #include "sys/sys.h" -std::string filesystem::datadir = ""; -std::string filesystem::homedir = ""; -std::string filesystem::basedir = ""; -std::string filesystem::moddir = ""; +namespace filesystem +{ + +std::string datadir = ""; +std::string homedir = ""; +std::string basedir = ""; +std::string moddir = ""; +std::string writedir = ""; -void filesystem::init() +void init() { con_print << "Initializing filesystem..." << std::endl; @@ -27,14 +34,46 @@ void filesystem::init() // FIXME win32 homedir = getenv("HOME"); homedir = homedir + "/.osirion/"; - Path::create(homedir); - Path::create(homedir+basedir); - if (moddir.size() && !Path::exists(homedir+moddir)) - Path::create(homedir+moddir); + + sys::mkdir(homedir); + sys::mkdir(homedir+basedir); + + writedir = homedir; + if (moddir.size()) { + writedir.append(moddir); + } else + writedir.append(basedir); + + sys::mkdir(writedir); + + con_print << " files are created in " << writedir << std::endl; } -void filesystem::shutdown() +void shutdown() { con_print << "Shutting down filesystem..." << std::endl; } +File *open(const char *filename) +{ + // for now, File is always a DiskFile + DiskFile *f = new DiskFile(); + if (!f->open(filename)) { + delete f; + f = 0; + return 0; + } + return f; +} + +void close(File *file) +{ + if (!file) + return; + + file->close(); + delete file; +} + +} + diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h index 1685fd2..83e93c0 100644 --- a/src/filesystem/filesystem.h +++ b/src/filesystem/filesystem.h @@ -7,7 +7,9 @@ #ifndef __INCLUDED_FILESYSTEM_H__ #define __INCLUDED_FILESYSTEM_H__ -// C++ headers +#include "filesystem/file.h" +#include "filesystem/diskfile.h" + #include /// The filesystem namespace contains classes and functions for common file operations. @@ -17,25 +19,33 @@ namespace filesystem { /// location of the main data files, includes trailing / extern std::string datadir; + /// location of the personal data files, includes trailing / extern std::string homedir; + +/// writeable location +extern std::string writedir; + /// subdirectory with the base data files, includes trailing / extern std::string basedir; + /// subdirectory for the current mod, includes trailing / extern std::string moddir; -/// Initialize the filesystem subsystem +/// initialize the filesystem subsystem void init(); -/// Shutdown the filesystem subsystem +/// shutdown the filesystem subsystem void shutdown(); -} // namespace filesystem +/// open a file and return a pointer to a File instance +File *open(const char *filename); +/// open a file and return a pointer to a File instance +File *open(const std::string &filename); +/// close and delete a file instance +void close(File *file); -// project headers -#include "filesystem/file.h" -#include "filesystem/path.h" -#include "filesystem/inifile.h" +} // namespace filesystem #endif // __INCLUDED_FILYSYSTEM_H__ diff --git a/src/filesystem/path.cc b/src/filesystem/path.cc deleted file mode 100644 index 096825c..0000000 --- a/src/filesystem/path.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - filesystem/path.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -// project headers -#include "filesystem/path.h" -#include "sys/sys.h" - -namespace filesystem -{ - -void Path::create(std::string path) -{ - std::string tmp(path); - if (tmp[tmp.size()-1] == '/') - tmp = tmp.substr(0, tmp.size() - 1); - - if (!sys::mkdir(tmp.c_str())) - // FIXME check error value - con_warn << "Could not create directory " << tmp << std::endl; - else - con_debug << "Directory created " << tmp << std::endl; -} - -bool Path::exists(std::string path) -{ - // FIXME make it work - return false; -} - -} diff --git a/src/filesystem/path.h b/src/filesystem/path.h deleted file mode 100644 index 9b443b0..0000000 --- a/src/filesystem/path.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - common/path.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_FILESYSTEM_PATH_H__ -#define __INCLUDED_FILESYSTEM_PATH_H__ - -// C++ headers -#include -#include - -namespace filesystem { - -/// a class to create directories -class Path { -public: - static bool exists(std::string path); - static void create(std::string path); -}; // class Path - -} // namespace filesystem - -#endif // __INCLUDED_FILESYSTEM_PATH_H__ - diff --git a/src/filesystem/vfile.cc b/src/filesystem/vfile.cc deleted file mode 100644 index 9fcb2b3..0000000 --- a/src/filesystem/vfile.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - filesystem/vfile.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -// project headers -#include "filesystem/vfile.h" - -namespace filesystem -{ - -std::string VFile::find(const char *filename) -{ - return std::string(); -} - - -bool VFile::exists(const char *filename) -{ - return (find(filename).size() == 0); -} - -} diff --git a/src/filesystem/vfile.h b/src/filesystem/vfile.h deleted file mode 100644 index a64dbc6..0000000 --- a/src/filesystem/vfile.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - filesystem/vfile.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_FILESYSTEM_VFILE_H__ -#define __INCLUDED_FILESYSTEM_VFILE_H__ - -// project headers -#include "filesystem/filesystem.h" - -namespace filesystem { - -/// a file in the virtual file system -class VFile { - -public: - /// search the path for a file in the virtual - /** If the file can not be found in any of the data directories, - * an empty string will be returned - */ - static std::string find(const char *filename); - - /// returns true if a file exists in the virtual filesystem - static bool exists(const char *filename); -}; - -} - -#endif //__INCLUDED_FILESYSTEM_VFILE_H__ diff --git a/src/game/game.cc b/src/game/game.cc index 65e9450..f9c7aa4 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -21,10 +21,11 @@ namespace game bool Game::init() { using math::Vector3f; - using filesystem::IniFile; + //using filesystem::IniFile; con_print << "Initializing game..." << std::endl; + /* // read game.ini IniFile f; f.open("ini/game.ini"); @@ -90,14 +91,14 @@ bool Game::init() } f.close(); - /* + con_print << "Loading sectors..." << std::endl; for (unsigned n =0; n < sectors.size(); n++) con_print << " " << sectors[n]->label << " " << sectors[n]->name << std::endl; */ + star.location = Vector3f(256.0f, 0.0f, 256.0f); ship.location = Vector3f(0,0,0); - return true; } diff --git a/src/render/render.cc b/src/render/render.cc index fa26021..aafa9ba 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -6,6 +6,7 @@ // project headers #include "render/render.h" +#include "core/core.h" #include "sys/sys.h" namespace render { @@ -22,8 +23,14 @@ void init() con_print << "Loading textures..." << std::endl; - TGA::texture(textures, "bitmaps/loader.tga", 0); - TGA::texture(textures, "bitmaps/conchars.tga", 1); + if (!TGA::texture(textures, "bitmaps/loader.tga", 0)) { + con_error << "Essential file bitmaps/loader.tga missing" << std::endl; + core::application()->shutdown(); + } + if (!TGA::texture(textures, "bitmaps/conchars.tga", 1)) { + con_error << "Essential file bitmaps/conchars.tga missing" << std::endl; + core::application()->shutdown(); + } } void shutdown() diff --git a/src/render/tga.cc b/src/render/tga.cc index b863d9b..5aa3665 100644 --- a/src/render/tga.cc +++ b/src/render/tga.cc @@ -1,4 +1,4 @@ -/* +/* Ronny Andr�Reierstad http://www.morrowland.com http://www.morrowland.com/apron/tut_gl.php @@ -9,57 +9,48 @@ #include "render/tga.h" #include "sys/sys.h" #include "GL/gl.h" -#include +#include -namespace render +namespace render { ///////////////////////////////////////////////////////////////////////////////////////////////// // TGA TEXTURE LOADER ///////////////////////////////////////////////////////////////////////////////////////////////// -void TGA::texture(GLuint textureArray[], const char *filename, int ID) +bool TGA::texture(GLuint textureArray[], const char *filename, int ID) { - if(!filename) - return; - - filesystem::File f; - - f.open(filename); - - if (!f.is_open()) - return; - f.close(); - - image *pBitMap = load(f.path().c_str()); - - if(pBitMap == 0) { - con_warn << "could not load " << f.path().c_str() << std::endl; - return; + if (!filename) + return false; + + image *pBitMap = load(filename); + if (!pBitMap) { + con_warn << "Could not load " << filename << std::endl; + return false; } - + glGenTextures(1, &textureArray[ID]); glBindTexture(GL_TEXTURE_2D, textureArray[ID]); int textureType = GL_RGB; - if(pBitMap->channels == 4) textureType = GL_RGBA; + if (pBitMap->channels == 4) textureType = GL_RGBA; gluBuild2DMipmaps(GL_TEXTURE_2D, pBitMap->channels, pBitMap->size_x, pBitMap->size_y, textureType, GL_UNSIGNED_BYTE, pBitMap->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); - if (pBitMap) - { - if (pBitMap->data) - { - free(pBitMap->data); + if (pBitMap) { + if (pBitMap->data) { + free(pBitMap->data); } - free(pBitMap); + free(pBitMap); } + + return true; } TGA::image *TGA::load(const char *filename) { - image *pImgData = NULL; - FILE *pFile = NULL; + image *pImgData = NULL; + //FILE *pFile = NULL; GLushort width = 0; GLushort height = 0; GLubyte length = 0; @@ -68,56 +59,46 @@ TGA::image *TGA::load(const char *filename) GLushort channels = 0; GLushort stride = 0; - pFile = fopen(filename, "rb"); - if (!pFile) + filesystem::File *f = filesystem::open(filename); + if (!f) return 0; - + pImgData = (image*)malloc(sizeof(image)); - fread(&length, sizeof(GLubyte), 1, pFile); - - fseek(pFile,1,SEEK_CUR); - - fread(&imgType, sizeof(GLubyte), 1, pFile); + f->read((void *)&length, sizeof(GLubyte)); + f->skip(1); + f->read((void *)&imgType, sizeof(GLubyte)); + f->skip(9); + f->read((void *)&width, sizeof(GLushort)); + f->read((void *)&height, sizeof(GLushort)); + f->read((void *)&bits, sizeof(GLubyte)); + f->skip(length +1); - fseek(pFile, 9, SEEK_CUR); - - fread(&width, sizeof(GLushort), 1, pFile); - fread(&height, sizeof(GLushort), 1, pFile); - fread(&bits, sizeof(GLubyte), 1, pFile); - con_debug << "TGA loading " << width << "x" << height << " " << (int) bits << "bpp" << std::endl; - fseek(pFile, length + 1, SEEK_CUR); - - if(imgType != TGA_RLE) - { + if (imgType != TGA_RLE) { // Check for 24 or 32 Bit - if(bits == 24 || bits == 32) - { - + if (bits == 24 || bits == 32) { + channels = bits / 8; stride = channels * width; pImgData->data = new unsigned char[stride * height]; - for(GLushort y = 0; y < height; y++) - { + for (GLushort y = 0; y < height; y++) { unsigned char *pLine = &(pImgData->data[stride * y]); - fread(pLine, stride, 1, pFile); + f->read((void *)pLine, stride); - for(GLushort i = 0; i < stride; i += channels) - { + for (GLushort i = 0; i < stride; i += channels) { int temp = pLine[i]; pLine[i] = pLine[i + 2]; pLine[i + 2] = temp; } } } - + // Check for 16 Bit - else if(bits == 16) - { + else if (bits == 16) { unsigned short pixels = 0; int r=0, g=0, b=0; @@ -125,9 +106,8 @@ TGA::image *TGA::load(const char *filename) stride = channels * width; pImgData->data = new unsigned char[stride * height]; - for(int i = 0; i < width*height; i++) - { - fread(&pixels, sizeof(GLushort), 1, pFile); + for (int i = 0; i < width*height; i++) { + f->read((void *)&pixels, sizeof(GLushort)); b = (pixels & 0x1f) << 3; g = ((pixels >> 5) & 0x1f) << 3; @@ -137,14 +117,9 @@ TGA::image *TGA::load(const char *filename) pImgData->data[i * 3 + 1] = g; pImgData->data[i * 3 + 2] = b; } - } - - else + } else return NULL; - } - - else - { + } else { GLubyte rleID = 0; int colorsRead = 0; channels = bits / 8; @@ -154,44 +129,38 @@ TGA::image *TGA::load(const char *filename) GLubyte *pColors = new GLubyte [channels]; int i = 0; - while(i < width*height) - { - - fread(&rleID, sizeof(GLubyte), 1, pFile); + while (i < width*height) { + + f->read((void *)&rleID, sizeof(GLubyte)); - if(rleID < 128) { + if (rleID < 128) { rleID++; - while(rleID) - { - fread(pColors, sizeof(GLubyte) * channels, 1, pFile); + while (rleID) { + f->read((void *)pColors, sizeof(GLubyte) * channels); pImgData->data[colorsRead + 0] = pColors[2]; pImgData->data[colorsRead + 1] = pColors[1]; pImgData->data[colorsRead + 2] = pColors[0]; - if(bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; + if (bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; i++; rleID--; colorsRead += channels; } - } - - else - { + } else { rleID -= 127; - fread(pColors, sizeof(GLubyte) * channels, 1, pFile); + f->read((void *)pColors, sizeof(GLubyte) * channels); - while(rleID) - { + while (rleID) { pImgData->data[colorsRead + 0] = pColors[2]; pImgData->data[colorsRead + 1] = pColors[1]; pImgData->data[colorsRead + 2] = pColors[0]; - if(bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; + if (bits == 32) pImgData->data[colorsRead + 3] = pColors[3]; i++; rleID--; @@ -202,7 +171,7 @@ TGA::image *TGA::load(const char *filename) delete[] pColors; } - fclose(pFile); + filesystem::close(f); pImgData->channels = channels; diff --git a/src/render/tga.h b/src/render/tga.h index f24ab31..d4449a8 100644 --- a/src/render/tga.h +++ b/src/render/tga.h @@ -25,7 +25,7 @@ public: } image; - static void texture(GLuint textureArray[], const char *filename, int textureID); + static bool texture(GLuint textureArray[], const char *filename, int textureID); protected: static image *load(const char *filename); diff --git a/src/sys/sys.cc b/src/sys/sys.cc index 9957408..508756d 100644 --- a/src/sys/sys.cc +++ b/src/sys/sys.cc @@ -25,17 +25,21 @@ namespace sys { -bool mkdir(const char *path) +void mkdir(const char *path) { #ifdef _WIN32 ::mkdir(path); - // FIXME check return value return true; #else - return (::mkdir(path, 0777) == 0); + ::mkdir(path, 0777); #endif } +void mkdir(const std::string &path) +{ + mkdir(path.c_str()); +} + void signal(int signum, signalfunc handler) { #ifndef _WIN32 diff --git a/src/sys/sys.h b/src/sys/sys.h index 4769832..178fe60 100644 --- a/src/sys/sys.h +++ b/src/sys/sys.h @@ -9,6 +9,8 @@ #include "config.h" +#include + /// maximum line size throught the game #define MAXCMDSIZE 1024 @@ -20,19 +22,24 @@ namespace sys typedef void (* signalfunc)(int signum); /// create a directory -extern bool mkdir(const char *path); +void mkdir(const char *path); + +void mkdir(const std::string &path); + /// intercept OS signals -extern void signal(int signum, signalfunc handler); -/// quit -/** @param status return value +void signal(int signum, signalfunc handler); + +/** + * @brief operation system exit() application + * @param status return value */ -extern void quit(int status); +void quit(int status); /// suspend process for a number of seconds -extern void sleep(float seconds); +void sleep(float seconds); /// return the current system time of day, in seconds after midnight -extern unsigned long time(); +unsigned long time(); } -- cgit v1.2.3