1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| struct Block {
char type;
// Mets ce que tu veux là dedans (attention à l'occupation mémoire)
};
// Choisis la taille que tu veux
const std::size_t CHUNK_SIZE = 64;
struct Chunk {
char x, y, z; // NB: a priori tu n'as pas besoin de ça : tu peux le stocker directement dans le nom du fichier (et c'est plus pratique pour le retrouver après !)
Block blocs[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE];
};
void save(const std::string& file_name, const Chunk& c) {
std::ofstream file(file_name, std::ios::binary);
char* compressed;
std::size_t size_compressed;
compress(reinterpret_cast<const char*>(&c), sizeof(c), compressed, size_compressed);
file.write(reinterpret_cast<char*>(&size_compressed), sizeof(size_compressed));
file.write(compressed, size_compressed);
}
void load(const std::string& file_name, Chunk& c) {
std::ifstream file(file_name, std::ios::binary);
std::size_t size_compressed;
file.read(reinterpret_cast<char*>(&size_compressed), sizeof(size_compressed));
char* compressed;
file.read(compressed, size_compressed);
decompress(compressed, size_compressed, reinterpret_cast<char*>(&c));
} |
Partager