diff --git a/Bin/LibD.pro b/Bin/LibD.pro index 0077d10..d2f5aae 100644 --- a/Bin/LibD.pro +++ b/Bin/LibD.pro @@ -84,8 +84,7 @@ HEADERS += ../src/Actor/Player.h \ ../src/TMXParser/Tmx.h \ ../src/TMXParser/base64/base64.h \ ../src/TMXParser/TmxUtil.h \ - ../src/System/Filesystem/SCCopyFile.h \ - ../src/System/Filesystem/FileReader.h + ../src/System/Filesystem/SCCopyFile.h SOURCES += ../src/Actor/Player.cpp \ ../src/Collision/AABB.cpp \ @@ -140,7 +139,6 @@ SOURCES += ../src/Actor/Player.cpp \ ../src/TMXParser/TmxLayer.cpp \ ../src/TMXParser/TmxImage.cpp \ ../src/TMXParser/base64/base64.cpp \ - ../src/TMXParser/TmxUtil.cpp \ - ../src/System/Filesystem/FileReader.cpp + ../src/TMXParser/TmxUtil.cpp QMAKE_CLEAN += LibD Debug.log diff --git a/src/Animation/AnimationSequence.cpp b/src/Animation/AnimationSequence.cpp index f38acf1..3a6ec61 100644 --- a/src/Animation/AnimationSequence.cpp +++ b/src/Animation/AnimationSequence.cpp @@ -1,9 +1,12 @@ #include +#include #include "../System/Debug.h" +#include "../System/Filesystem/InputStreamWrapper.h" #include "AnimationSequence.h" using saracraft::util::Debug; +using namespace saracraft::filesystem; /* * Load and read a sequence file for an animating sprite then @@ -39,12 +42,17 @@ void AnimationSequence::ReadFile(void) { // is then sorted character by character arranging the data into // usable animations using the scan method, each result is stored into an // animation array. - if(_file.Exists(_sequenceID)) { + FILE* file = fopen(_sequenceID, "rb"); + if(file) { + fseek(file, 0, SEEK_END); + int fileSize = ftell(file); + rewind(file); + String name; - char* temp; - _file.OpenFile(_sequenceID, "rb"); - _file.ReadBuffer(temp); - _file.CloseFile(); + char* temp = new char[fileSize + 1]; + temp[fileSize] = 0; + fread(temp, 1, fileSize, file); + fclose(file); int counter = 0; diff --git a/src/Animation/AnimationSequence.h b/src/Animation/AnimationSequence.h index 8be26e3..e7b004b 100644 --- a/src/Animation/AnimationSequence.h +++ b/src/Animation/AnimationSequence.h @@ -2,7 +2,6 @@ #include #include -#include "../System/Filesystem/FileReader.h" #include "../System/String.h" #define MAX_FRAMES 16 @@ -11,7 +10,6 @@ #define SPACE 32 using saracraft::util::String; -using saracraft::filesystem::FileReader; struct Animation { String _animationID; @@ -35,6 +33,5 @@ private: const char* _sequenceID; int _numberOfFrames; - FileReader _file; Animation* _animations[MAX_FRAMES]; }; diff --git a/src/System/Filesystem/FileReader.cpp b/src/System/Filesystem/FileReader.cpp deleted file mode 100644 index 561e94e..0000000 --- a/src/System/Filesystem/FileReader.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include - -#include "../Debug.h" -#include "FileReader.h" - -namespace saracraft { -namespace filesystem { - -FileReader::FileReader(void) { - -} - -FileReader::~FileReader(void) { - -} - -bool FileReader::Exists(const char* filename) { - // Check to see if _filename is existent in memory, - _file = fopen(filename, "rb"); - - if(_file) { - // Close the file we have. - fclose(_file); - _file = NULL; - return true; - } else { - // Create the file. - _file = fopen(filename, "w"); - fclose(_file); - _file = NULL; - return true; - } - return false; -} - -void FileReader::OpenFile(const char* filename, const char* accessType) { - // Open _filename into memory, passing in the access type. - _filename = filename; - _accessType = accessType; - _file = fopen(filename, accessType); -} - -void FileReader::CloseFile(void) { - if(_file) { - fclose(_file); - _file = NULL; - } -} - -void FileReader::Write(const char* buffer) { - if(_file) { - fprintf(_file, "%s", buffer); - } else { - // _filename does not exist or we have the wrong accessType. - assert(false); - } -} - -void FileReader::Write(const int buffer) { - if((_file) && (_accessType == "w")) { - fprintf(_file, "%i", buffer); - } else { - // _filename does not exist or we have the wrong accessType. - assert(false); - } -} - -void FileReader::Read(const int &value) { - if((_file) && (_accessType == "rb")) { - fscanf(_file, "%i", &value); - } else { - // _filename does not exist or we have the wrong accessType. - assert(false); - } -} - -void FileReader::WriteBuffer(const char* buffer) { - if((_file) && (_accessType == "w")) { - fwrite(buffer, 1, strlen(buffer), _file); - } -} - -void FileReader::WriteBuffer(const char* buffer, int count) { - if((_file) && (_accessType == "w")) { - fwrite(buffer, 1, count, _file); - } -} - -void FileReader::ReadBuffer(char* &buffer) { - if((_file) && (_accessType == "rb")) { - size_t size = 0; - fseek(_file, 0, SEEK_END); - size = ftell(_file); - rewind(_file); - - buffer = (char*)malloc(sizeof(char)* size + sizeof(char)); - buffer[size] = 0; - - if(buffer != NULL) { - fread(buffer, 1, size, _file); - } - } -} - -void FileReader::ReadBuffer(const char* buffer, int count) { - if((_file) && (_accessType == "r")) { - buffer = (char*)malloc(sizeof(char)*count); - - if(buffer != NULL) { - fread((char*) buffer, 1, count, _file); - } - } -} - -} // Namespace filesystem. -} // Namespace saracraft. diff --git a/src/System/Filesystem/FileReader.h b/src/System/Filesystem/FileReader.h deleted file mode 100644 index d10eb4f..0000000 --- a/src/System/Filesystem/FileReader.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include -#include - -#include "../String.h" - -namespace saracraft { -namespace filesystem { - -using util::String; - -class FileReader { -public: - FileReader(void); - ~FileReader(void); - - void OpenFile(const char* filename, const char* accessType); - void CloseFile(void); - void Write(const char* buffer); - void Write(const int value); - void Read(const char* buffer); - void Read(const int &value); - - void WriteBuffer(const char* buffer); - void WriteBuffer(const char* buffer, int count); - void ReadBuffer(char* &buffer); - void ReadBuffer(const char* buffer, int count); - - bool Exists(const char* filename); - -private: - FILE* _file; - String _filename; - String _accessType; -}; - -} // Namespace filesystem. -} // Namespace saracraft. diff --git a/src/System/Filesystem/InputStreamWrapper.cpp b/src/System/Filesystem/InputStreamWrapper.cpp index bbda110..a5dc419 100644 --- a/src/System/Filesystem/InputStreamWrapper.cpp +++ b/src/System/Filesystem/InputStreamWrapper.cpp @@ -41,8 +41,8 @@ SC_FILE* sc_fopen(const char* filename, const char*) { InputStream stream = manager.GetFile(filename); manager.SetInputStreamErrorReporting(true); - if(stream.IsEof()) - return 0; +// if(stream.IsEof()) +// return 0; return new SC_FILE(stream); }