Windows build fix
This commit is contained in:
@@ -115,12 +115,12 @@ void WorldFiles::put(Chunk* chunk){
|
||||
region.compressedSizes[chunk_index] = compressedSize;
|
||||
}
|
||||
|
||||
std::string WorldFiles::getRegionFile(int x, int y) {
|
||||
return directory/(std::to_string(x) + "_" + std::to_string(y) + ".bin");
|
||||
path WorldFiles::getRegionFile(int x, int y) {
|
||||
return directory/path(std::to_string(x) + "_" + std::to_string(y) + ".bin");
|
||||
}
|
||||
|
||||
std::string WorldFiles::getPlayerFile() {
|
||||
return directory/"player.bin";
|
||||
path WorldFiles::getPlayerFile() {
|
||||
return directory/path("player.bin");
|
||||
}
|
||||
|
||||
ubyte* WorldFiles::getChunk(int x, int y){
|
||||
@@ -173,7 +173,7 @@ ubyte* WorldFiles::readChunkData(int x, int y, uint32_t& length){
|
||||
|
||||
int chunkIndex = localY * REGION_SIZE + localX;
|
||||
|
||||
std::string filename = getRegionFile(regionX, regionY);
|
||||
path filename = getRegionFile(regionX, regionY);
|
||||
std::ifstream input(filename, std::ios::binary);
|
||||
if (!input.is_open()){
|
||||
return nullptr;
|
||||
@@ -310,4 +310,4 @@ void WorldFiles::writeRegion(int x, int y, WorldRegion& entry){
|
||||
int2Bytes(offsets[i], (ubyte*)intbuf, 0);
|
||||
file.write(intbuf, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
void writePlayer(Player* player);
|
||||
void write();
|
||||
|
||||
std::string getRegionFile(int x, int y);
|
||||
std::string getPlayerFile();
|
||||
std::filesystem::path getRegionFile(int x, int y);
|
||||
std::filesystem::path getPlayerFile();
|
||||
};
|
||||
|
||||
#endif /* FILES_WORLDFILES_H_ */
|
||||
#endif /* FILES_WORLDFILES_H_ */
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "engine_files.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include "../typedefs.h"
|
||||
|
||||
namespace filesystem = std::filesystem;
|
||||
using std::string;
|
||||
|
||||
+7
-6
@@ -10,8 +10,9 @@ using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::ifstream;
|
||||
using std::ofstream;
|
||||
using std::filesystem::path;
|
||||
|
||||
bool files::write_bytes(string filename, const char* data, size_t size) {
|
||||
bool files::write_bytes(path filename, const char* data, size_t size) {
|
||||
ofstream output(filename, ios::binary);
|
||||
if (!output.is_open())
|
||||
return false;
|
||||
@@ -20,7 +21,7 @@ bool files::write_bytes(string filename, const char* data, size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint files::append_bytes(string filename, const char* data, size_t size) {
|
||||
uint files::append_bytes(path filename, const char* data, size_t size) {
|
||||
ofstream output(filename, ios::binary | ios::app);
|
||||
if (!output.is_open())
|
||||
return 0;
|
||||
@@ -30,7 +31,7 @@ uint files::append_bytes(string filename, const char* data, size_t size) {
|
||||
return position;
|
||||
}
|
||||
|
||||
bool files::read(string filename, char* data, size_t size) {
|
||||
bool files::read(path filename, char* data, size_t size) {
|
||||
ifstream output(filename, ios::binary);
|
||||
if (!output.is_open())
|
||||
return false;
|
||||
@@ -39,7 +40,7 @@ bool files::read(string filename, char* data, size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char* files::read_bytes(string filename, size_t& length) {
|
||||
char* files::read_bytes(path filename, size_t& length) {
|
||||
ifstream input(filename, ios::binary);
|
||||
if (!input.is_open())
|
||||
return nullptr;
|
||||
@@ -53,13 +54,13 @@ char* files::read_bytes(string filename, size_t& length) {
|
||||
return data.release();
|
||||
}
|
||||
|
||||
std::string files::read_string(string filename) {
|
||||
std::string files::read_string(path filename) {
|
||||
size_t size;
|
||||
unique_ptr<char> chars (read_bytes(filename, size));
|
||||
return string(chars.get(), size);
|
||||
}
|
||||
|
||||
bool files::write_string(string filename, const string content) {
|
||||
bool files::write_string(path filename, const string content) {
|
||||
ofstream file(filename);
|
||||
if (!file) {
|
||||
return false;
|
||||
|
||||
+8
-7
@@ -2,15 +2,16 @@
|
||||
#define FILES_FILES_H_
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include "../typedefs.h"
|
||||
|
||||
namespace files {
|
||||
extern bool write_bytes(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(std::string filename, char* data, size_t size);
|
||||
extern char* read_bytes(std::string filename, size_t& length);
|
||||
extern std::string read_string(std::string filename);
|
||||
extern bool write_string(std::string filename, const std::string content);
|
||||
extern bool write_bytes(std::filesystem::path, const char* data, size_t size);
|
||||
extern uint append_bytes(std::filesystem::path, const char* data, size_t size);
|
||||
extern bool read(std::filesystem::path, char* data, size_t size);
|
||||
extern char* read_bytes(std::filesystem::path, size_t& length);
|
||||
extern std::string read_string(std::filesystem::path filename);
|
||||
extern bool write_string(std::filesystem::path filename, const std::string content);
|
||||
}
|
||||
|
||||
#endif /* FILES_FILES_H_ */
|
||||
#endif /* FILES_FILES_H_ */
|
||||
Reference in New Issue
Block a user