Windows build fix

This commit is contained in:
MihailRis 2023-11-16 13:07:05 +03:00
parent d349b4b65a
commit 8310b1b768
9 changed files with 33 additions and 27 deletions

View File

@ -3,6 +3,7 @@
#include <string>
#include <stdexcept>
#include "../typedefs.h"
inline int is_box(int c) {
switch (c) {

View File

@ -77,7 +77,7 @@ void Engine::updateHotkeys() {
unique_ptr<ImageData> 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;
}
}

View File

@ -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);
}
}
}

View File

@ -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_ */

View File

@ -1,6 +1,8 @@
#include "engine_files.h"
#include <filesystem>
#include <sstream>
#include "../typedefs.h"
namespace filesystem = std::filesystem;
using std::string;

View File

@ -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;

View File

@ -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_ */

View File

@ -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;
}
}

View File

@ -2,6 +2,7 @@
#define WORLD_WORLD_H_
#include <string>
#include <filesystem>
#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_ */