From 8310b1b768825a5ee776744ac17f3f14806459ad Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 16 Nov 2023 13:07:05 +0300 Subject: [PATCH] Windows build fix --- src/coders/commons.h | 1 + src/engine.cpp | 2 +- src/files/WorldFiles.cpp | 12 ++++++------ src/files/WorldFiles.h | 6 +++--- src/files/engine_files.cpp | 2 ++ src/files/files.cpp | 13 +++++++------ src/files/files.h | 15 ++++++++------- src/world/World.cpp | 4 ++-- src/world/World.h | 5 +++-- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/coders/commons.h b/src/coders/commons.h index 136c5817..a7769ff3 100644 --- a/src/coders/commons.h +++ b/src/coders/commons.h @@ -3,6 +3,7 @@ #include #include +#include "../typedefs.h" inline int is_box(int c) { switch (c) { diff --git a/src/engine.cpp b/src/engine.cpp index 6fa6251d..438652ae 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -77,7 +77,7 @@ void Engine::updateHotkeys() { unique_ptr image(Window::takeScreenshot()); image->flipY(); path filename = enginefs::get_screenshot_file("png"); - png::write_image(filename, image.get()); + png::write_image(filename.string(), image.get()); std::cout << "saved screenshot as " << filename << std::endl; } } diff --git a/src/files/WorldFiles.cpp b/src/files/WorldFiles.cpp index 1e939390..c09d6b90 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -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); } -} +} \ No newline at end of file diff --git a/src/files/WorldFiles.h b/src/files/WorldFiles.h index a650b013..eb219a7d 100644 --- a/src/files/WorldFiles.h +++ b/src/files/WorldFiles.h @@ -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_ */ \ No newline at end of file diff --git a/src/files/engine_files.cpp b/src/files/engine_files.cpp index f2d5a53b..a7e79c18 100644 --- a/src/files/engine_files.cpp +++ b/src/files/engine_files.cpp @@ -1,6 +1,8 @@ #include "engine_files.h" #include +#include +#include "../typedefs.h" namespace filesystem = std::filesystem; using std::string; diff --git a/src/files/files.cpp b/src/files/files.cpp index a36fc42c..a6b8fa72 100644 --- a/src/files/files.cpp +++ b/src/files/files.cpp @@ -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 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; diff --git a/src/files/files.h b/src/files/files.h index 8c473b69..23d4427a 100644 --- a/src/files/files.h +++ b/src/files/files.h @@ -2,15 +2,16 @@ #define FILES_FILES_H_ #include +#include #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_ */ \ No newline at end of file diff --git a/src/world/World.cpp b/src/world/World.cpp index 0bfa5be7..f063ef93 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -16,7 +16,7 @@ using glm::vec3; using std::shared_ptr; -World::World(std::string name, std::string directory, int seed, EngineSettings& settings) : name(name), seed(seed) { +World::World(std::string name, std::filesystem::path directory, int seed, EngineSettings& settings) : name(name), seed(seed) { wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_DATA_LEN * 2 + 8), settings.debug.generatorTestMode); } @@ -51,4 +51,4 @@ Level* World::loadLevel(EngineSettings& settings) { camera->rotation = mat4(1.0f); camera->rotate(player->camY, player->camX, 0); return level; -} +} \ No newline at end of file diff --git a/src/world/World.h b/src/world/World.h index a35903de..68427996 100644 --- a/src/world/World.h +++ b/src/world/World.h @@ -2,6 +2,7 @@ #define WORLD_WORLD_H_ #include +#include #include "../typedefs.h" #include "../settings.h" @@ -16,11 +17,11 @@ public: WorldFiles* wfile; int seed; - World(std::string name, std::string directory, int seed, EngineSettings& settings); + World(std::string name, std::filesystem::path directory, int seed, EngineSettings& settings); ~World(); void write(Level* level, bool writeChunks); Level* loadLevel(EngineSettings& settings); }; -#endif /* WORLD_WORLD_H_ */ +#endif /* WORLD_WORLD_H_ */ \ No newline at end of file