files module update
This commit is contained in:
parent
5d90501ce1
commit
bfc7c85856
@ -56,12 +56,10 @@ float bytes2Float(ubyte* src, uint offset){
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorldFiles::WorldFiles(std::string directory, size_t mainBufferCapacity) : directory(directory){
|
WorldFiles::WorldFiles(std::string directory, size_t mainBufferCapacity) : directory(directory){
|
||||||
mainBufferIn = new ubyte[CHUNK_DATA_LEN * 2];
|
|
||||||
compressionBuffer = new ubyte[CHUNK_DATA_LEN * 2];
|
compressionBuffer = new ubyte[CHUNK_DATA_LEN * 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldFiles::~WorldFiles(){
|
WorldFiles::~WorldFiles(){
|
||||||
delete[] mainBufferIn;
|
|
||||||
delete[] compressionBuffer;
|
delete[] compressionBuffer;
|
||||||
for (auto it = regions.begin(); it != regions.end(); it++){
|
for (auto it = regions.begin(); it != regions.end(); it++){
|
||||||
WorldRegion region = it->second;
|
WorldRegion region = it->second;
|
||||||
@ -224,12 +222,12 @@ void WorldFiles::writePlayer(Player* player){
|
|||||||
dst[offset++] = player->flight * PLAYER_FLAG_FLIGHT |
|
dst[offset++] = player->flight * PLAYER_FLAG_FLIGHT |
|
||||||
player->noclip * PLAYER_FLAG_NOCLIP;
|
player->noclip * PLAYER_FLAG_NOCLIP;
|
||||||
|
|
||||||
files::write_binary_file(getPlayerFile(), (const char*)dst, sizeof(dst));
|
files::write_bytes(getPlayerFile(), (const char*)dst, sizeof(dst));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldFiles::readPlayer(Player* player) {
|
bool WorldFiles::readPlayer(Player* player) {
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
ubyte* data = (ubyte*)files::read_binary_file(getPlayerFile(), length);
|
ubyte* data = (ubyte*)files::read_bytes(getPlayerFile(), length);
|
||||||
if (data == nullptr){
|
if (data == nullptr){
|
||||||
std::cerr << "could not to read player.bin (ignored)" << std::endl;
|
std::cerr << "could not to read player.bin (ignored)" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -29,7 +29,6 @@ class WorldFiles {
|
|||||||
public:
|
public:
|
||||||
std::unordered_map<glm::ivec2, WorldRegion> regions;
|
std::unordered_map<glm::ivec2, WorldRegion> regions;
|
||||||
std::string directory;
|
std::string directory;
|
||||||
ubyte* mainBufferIn;
|
|
||||||
ubyte* compressionBuffer;
|
ubyte* compressionBuffer;
|
||||||
|
|
||||||
WorldFiles(std::string directory, size_t mainBufferCapacity);
|
WorldFiles(std::string directory, size_t mainBufferCapacity);
|
||||||
|
|||||||
@ -11,7 +11,7 @@ using std::unique_ptr;
|
|||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
using std::ofstream;
|
using std::ofstream;
|
||||||
|
|
||||||
bool files::write_binary_file(string filename, const char* data, size_t size) {
|
bool files::write_bytes(string filename, const char* data, size_t size) {
|
||||||
ofstream output(filename, ios::binary);
|
ofstream output(filename, ios::binary);
|
||||||
if (!output.is_open())
|
if (!output.is_open())
|
||||||
return false;
|
return false;
|
||||||
@ -20,17 +20,17 @@ bool files::write_binary_file(string filename, const char* data, size_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int files::append_binary_file(string filename, const char* data, size_t size) {
|
uint files::append_bytes(string filename, const char* data, size_t size) {
|
||||||
ofstream output(filename, ios::binary | ios::app);
|
ofstream output(filename, ios::binary | ios::app);
|
||||||
if (!output.is_open())
|
if (!output.is_open())
|
||||||
return 0;
|
return 0;
|
||||||
unsigned int position = output.tellp();
|
uint position = output.tellp();
|
||||||
output.write(data, size);
|
output.write(data, size);
|
||||||
output.close();
|
output.close();
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool files::read_binary_file(string filename, char* data, size_t size) {
|
bool files::read(string filename, char* data, size_t size) {
|
||||||
ifstream output(filename, ios::binary);
|
ifstream output(filename, ios::binary);
|
||||||
if (!output.is_open())
|
if (!output.is_open())
|
||||||
return false;
|
return false;
|
||||||
@ -39,7 +39,7 @@ bool files::read_binary_file(string filename, char* data, size_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* files::read_binary_file(string filename, size_t& length) {
|
char* files::read_bytes(string filename, size_t& length) {
|
||||||
ifstream input(filename, ios::binary);
|
ifstream input(filename, ios::binary);
|
||||||
if (!input.is_open())
|
if (!input.is_open())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -55,7 +55,7 @@ char* files::read_binary_file(string filename, size_t& length) {
|
|||||||
|
|
||||||
std::string files::read_string(string filename) {
|
std::string files::read_string(string filename) {
|
||||||
size_t size;
|
size_t size;
|
||||||
unique_ptr<char> chars (read_binary_file(filename, size));
|
unique_ptr<char> chars (read_bytes(filename, size));
|
||||||
return string(chars.get(), size);
|
return string(chars.get(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,10 @@
|
|||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
namespace files {
|
namespace files {
|
||||||
extern bool write_binary_file(std::string filename, const char* data, size_t size);
|
extern bool write_bytes(std::string filename, const char* data, size_t size);
|
||||||
extern unsigned int append_binary_file(std::string filename, const char* data, size_t size);
|
extern uint append_bytes(std::string filename, const char* data, size_t size);
|
||||||
extern bool read_binary_file(std::string filename, char* data, size_t size);
|
extern bool read(std::string filename, char* data, size_t size);
|
||||||
extern char* read_binary_file(std::string filename, size_t& length);
|
extern char* read_bytes(std::string filename, size_t& length);
|
||||||
extern std::string read_string(std::string filename);
|
extern std::string read_string(std::string filename);
|
||||||
extern bool write_string(std::string filename, const std::string content);
|
extern bool write_string(std::string filename, const std::string content);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user