-- Annoying merges..
Merge branch 'master' of github.com:Allanis/LibD
This commit is contained in:
commit
55e78103c0
@ -88,8 +88,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 \
|
||||
@ -146,7 +145,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
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
|
||||
#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];
|
||||
};
|
||||
|
@ -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.
|
@ -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.
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user