-- Annoying merges..

Merge branch 'master' of github.com:Allanis/LibD
This commit is contained in:
Rtch90 2012-09-08 17:26:25 +01:00
commit 55e78103c0
6 changed files with 17 additions and 169 deletions

View File

@ -88,8 +88,7 @@ HEADERS += ../src/Actor/Player.h \
../src/TMXParser/Tmx.h \ ../src/TMXParser/Tmx.h \
../src/TMXParser/base64/base64.h \ ../src/TMXParser/base64/base64.h \
../src/TMXParser/TmxUtil.h \ ../src/TMXParser/TmxUtil.h \
../src/System/Filesystem/SCCopyFile.h \ ../src/System/Filesystem/SCCopyFile.h
../src/System/Filesystem/FileReader.h
SOURCES += ../src/Actor/Player.cpp \ SOURCES += ../src/Actor/Player.cpp \
../src/Collision/AABB.cpp \ ../src/Collision/AABB.cpp \
@ -146,7 +145,6 @@ SOURCES += ../src/Actor/Player.cpp \
../src/TMXParser/TmxLayer.cpp \ ../src/TMXParser/TmxLayer.cpp \
../src/TMXParser/TmxImage.cpp \ ../src/TMXParser/TmxImage.cpp \
../src/TMXParser/base64/base64.cpp \ ../src/TMXParser/base64/base64.cpp \
../src/TMXParser/TmxUtil.cpp \ ../src/TMXParser/TmxUtil.cpp
../src/System/Filesystem/FileReader.cpp
QMAKE_CLEAN += LibD Debug.log QMAKE_CLEAN += LibD Debug.log

View File

@ -1,9 +1,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "../System/Debug.h" #include "../System/Debug.h"
#include "../System/Filesystem/InputStreamWrapper.h"
#include "AnimationSequence.h" #include "AnimationSequence.h"
using saracraft::util::Debug; using saracraft::util::Debug;
using namespace saracraft::filesystem;
/* /*
* Load and read a sequence file for an animating sprite then * 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 // is then sorted character by character arranging the data into
// usable animations using the scan method, each result is stored into an // usable animations using the scan method, each result is stored into an
// animation array. // 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; String name;
char* temp; char* temp = new char[fileSize + 1];
_file.OpenFile(_sequenceID, "rb"); temp[fileSize] = 0;
_file.ReadBuffer(temp); fread(temp, 1, fileSize, file);
_file.CloseFile(); fclose(file);
int counter = 0; int counter = 0;

View File

@ -2,7 +2,6 @@
#include <string> #include <string>
#include <assert.h> #include <assert.h>
#include "../System/Filesystem/FileReader.h"
#include "../System/String.h" #include "../System/String.h"
#define MAX_FRAMES 16 #define MAX_FRAMES 16
@ -11,7 +10,6 @@
#define SPACE 32 #define SPACE 32
using saracraft::util::String; using saracraft::util::String;
using saracraft::filesystem::FileReader;
struct Animation { struct Animation {
String _animationID; String _animationID;
@ -35,6 +33,5 @@ private:
const char* _sequenceID; const char* _sequenceID;
int _numberOfFrames; int _numberOfFrames;
FileReader _file;
Animation* _animations[MAX_FRAMES]; Animation* _animations[MAX_FRAMES];
}; };

View File

@ -1,117 +0,0 @@
#include <stdlib.h>
#include <assert.h>
#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.

View File

@ -1,38 +0,0 @@
#pragma once
#include <string.h>
#include <stdio.h>
#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.

View File

@ -41,8 +41,8 @@ SC_FILE* sc_fopen(const char* filename, const char*) {
InputStream stream = manager.GetFile(filename); InputStream stream = manager.GetFile(filename);
manager.SetInputStreamErrorReporting(true); manager.SetInputStreamErrorReporting(true);
if(stream.IsEof()) // if(stream.IsEof())
return 0; // return 0;
return new SC_FILE(stream); return new SC_FILE(stream);
} }