diff --git a/src/coders/json.cpp b/src/coders/json.cpp index 3cfd37659..0f72a5bfb 100644 --- a/src/coders/json.cpp +++ b/src/coders/json.cpp @@ -302,7 +302,7 @@ void JObject::num(std::string key, float& dst) const { dst = getNum(key, dst); } -void JObject::num(std::string key, ubyte& dst) const { +void JObject::num(std::string key, u_char8& dst) const { dst = getInteger(key, dst); } diff --git a/src/coders/json.h b/src/coders/json.h index dd1708640..497a5edbd 100644 --- a/src/coders/json.h +++ b/src/coders/json.h @@ -86,7 +86,7 @@ namespace json { void num(std::string key, uint& dst) const; void num(std::string key, int64_t& dst) const; void num(std::string key, uint64_t& dst) const; - void num(std::string key, ubyte& dst) const; + void num(std::string key, u_char8& dst) const; void num(std::string key, double& dst) const; JObject* obj(std::string key) const; JArray* arr(std::string key) const; diff --git a/src/coders/png.cpp b/src/coders/png.cpp index 411df7a74..d022fd1da 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -16,8 +16,8 @@ #include // returns 0 if all-right, 1 otherwise -int _png_write(const char* filename, uint width, uint height, const ubyte* data, bool alpha) { - uint pixsize = alpha ? 4 : 3; +int _png_write(const char* filename, u_int width, u_int height, const u_char8* data, bool alpha) { + u_int pixsize = alpha ? 4 : 3; // Open file for writing (binary mode) FILE* fp = fopen(filename, "wb"); @@ -355,5 +355,5 @@ Texture* png::load_texture(std::string filename) { } void png::write_image(std::string filename, const ImageData* image) { - _png_write(filename.c_str(), image->getWidth(), image->getHeight(), (const ubyte*)image->getData(), image->getFormat() == ImageFormat::rgba8888); + _png_write(filename.c_str(), image->getWidth(), image->getHeight(), (const u_char8*)image->getData(), image->getFormat() == ImageFormat::rgba8888); } \ No newline at end of file diff --git a/src/files/WorldConverter.cpp b/src/files/WorldConverter.cpp index de171ab30..ea40387b8 100644 --- a/src/files/WorldConverter.cpp +++ b/src/files/WorldConverter.cpp @@ -53,7 +53,7 @@ void WorldConverter::convertNext() { for (uint cx = 0; cx < REGION_SIZE; cx++) { int gx = cx + x * REGION_SIZE; int gz = cz + z * REGION_SIZE; - std::unique_ptr data (wfile->getChunk(gx, gz)); + std::unique_ptr data (wfile->getChunk(gx, gz)); if (data == nullptr) continue; if (wfile->getVoxelRegionVersion(x, z) != REGION_FORMAT_VERSION) { diff --git a/src/files/WorldFiles.cpp b/src/files/WorldFiles.cpp index 10ceb1ec8..59b28a5f5 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -45,7 +45,7 @@ regfile::regfile(fs::path filename) : file(filename) { } WorldRegion::WorldRegion() { - chunksData = new ubyte*[REGION_CHUNKS_COUNT]{}; + chunksData = new u_char8*[REGION_CHUNKS_COUNT]{}; sizes = new uint32_t[REGION_CHUNKS_COUNT]{}; } @@ -64,7 +64,7 @@ bool WorldRegion::isUnsaved() const { return unsaved; } -ubyte** WorldRegion::getChunks() const { +u_char8** WorldRegion::getChunks() const { return chunksData; } @@ -72,14 +72,14 @@ uint32_t* WorldRegion::getSizes() const { return sizes; } -void WorldRegion::put(uint x, uint z, ubyte* data, uint32_t size) { +void WorldRegion::put(uint x, uint z, u_char8* data, uint32_t size) { size_t chunk_index = z * REGION_SIZE + x; delete[] chunksData[chunk_index]; chunksData[chunk_index] = data; sizes[chunk_index] = size; } -ubyte* WorldRegion::getChunkData(uint x, uint z) { +u_char8* WorldRegion::getChunkData(uint x, uint z) { return chunksData[z * REGION_SIZE + x]; } @@ -91,7 +91,7 @@ WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings) : directory(directory), generatorTestMode(settings.generatorTestMode), doWriteLights(settings.doWriteLights) { - compressionBuffer.reset(new ubyte[CHUNK_DATA_LEN * 2]); + compressionBuffer.reset(new u_char8[CHUNK_DATA_LEN * 2]); } WorldFiles::~WorldFiles(){ @@ -113,19 +113,19 @@ WorldRegion* WorldFiles::getOrCreateRegion(regionsmap& regions, int x, int z) { return region; } -ubyte* WorldFiles::compress(const ubyte* src, size_t srclen, size_t& len) { - ubyte* buffer = this->compressionBuffer.get(); +u_char8* WorldFiles::compress(const u_char8* src, size_t srclen, size_t& len) { + u_char8* buffer = this->compressionBuffer.get(); len = extrle::encode(src, srclen, buffer); - ubyte* data = new ubyte[len]; + u_char8* data = new u_char8[len]; for (size_t i = 0; i < len; i++) { data[i] = buffer[i]; } return data; } -ubyte* WorldFiles::decompress(const ubyte* src, size_t srclen, size_t dstlen) { - ubyte* decompressed = new ubyte[dstlen]; +u_char8* WorldFiles::decompress(const u_char8* src, size_t srclen, size_t dstlen) { + u_char8* decompressed = new u_char8[dstlen]; extrle::decode(src, srclen, decompressed); return decompressed; } @@ -160,7 +160,7 @@ int WorldFiles::getVoxelRegionsVersion() { * @param x chunk.x * @param z chunk.z */ -void WorldFiles::put(int x, int z, const ubyte* voxelData) { +void WorldFiles::put(int x, int z, const u_char8* voxelData) { int regionX = floordiv(x, REGION_SIZE); int regionZ = floordiv(z, REGION_SIZE); int localX = x - (regionX * REGION_SIZE); @@ -170,7 +170,7 @@ void WorldFiles::put(int x, int z, const ubyte* voxelData) { WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ); region->setUnsaved(true); size_t compressedSize; - ubyte* data = compress(voxelData, CHUNK_DATA_LEN, compressedSize); + u_char8* data = compress(voxelData, CHUNK_DATA_LEN, compressedSize); region->put(localX, localZ, data, compressedSize); } } @@ -188,8 +188,8 @@ void WorldFiles::put(Chunk* chunk){ /* Writing Voxels */ { size_t compressedSize; - std::unique_ptr chunk_data (chunk->encode()); - ubyte* data = compress(chunk_data.get(), CHUNK_DATA_LEN, compressedSize); + std::unique_ptr chunk_data (chunk->encode()); + u_char8* data = compress(chunk_data.get(), CHUNK_DATA_LEN, compressedSize); WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ); region->setUnsaved(true); @@ -197,8 +197,8 @@ void WorldFiles::put(Chunk* chunk){ } if (doWriteLights && chunk->isLighted()) { size_t compressedSize; - std::unique_ptr light_data (chunk->lightmap->encode()); - ubyte* data = compress(light_data.get(), LIGHTMAP_DATA_LEN, compressedSize); + std::unique_ptr light_data (chunk->lightmap->encode()); + u_char8* data = compress(light_data.get(), LIGHTMAP_DATA_LEN, compressedSize); WorldRegion* region = getOrCreateRegion(lights, regionX, regionZ); region->setUnsaved(true); @@ -256,20 +256,20 @@ fs::path WorldFiles::getPacksFile() const { return directory/fs::path("packs.list"); } -ubyte* WorldFiles::getChunk(int x, int z){ +u_char8* WorldFiles::getChunk(int x, int z){ return getData(regions, getRegionsFolder(), x, z, REGION_LAYER_VOXELS); } /* Get cached lights for chunk at x,z * @return lights data or nullptr */ light_t* WorldFiles::getLights(int x, int z) { - std::unique_ptr data (getData(lights, getLightsFolder(), x, z, REGION_LAYER_LIGHTS)); + std::unique_ptr data (getData(lights, getLightsFolder(), x, z, REGION_LAYER_LIGHTS)); if (data == nullptr) return nullptr; return Lightmap::decode(data.get()); } -ubyte* WorldFiles::getData(regionsmap& regions, const fs::path& folder, +u_char8* WorldFiles::getData(regionsmap& regions, const fs::path& folder, int x, int z, int layer) { int regionX = floordiv(x, REGION_SIZE); int regionZ = floordiv(z, REGION_SIZE); @@ -278,7 +278,7 @@ ubyte* WorldFiles::getData(regionsmap& regions, const fs::path& folder, int localZ = z - (regionZ * REGION_SIZE); WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ); - ubyte* data = region->getChunkData(localX, localZ); + u_char8* data = region->getChunkData(localX, localZ); if (data == nullptr) { uint32_t size; data = readChunkData(x, z, size, folder, layer); @@ -312,7 +312,7 @@ regfile* WorldFiles::getRegFile(glm::ivec3 coord, const fs::path& folder) { return openRegFiles[coord].get(); } -ubyte* WorldFiles::readChunkData(int x, +u_char8* WorldFiles::readChunkData(int x, int z, uint32_t& length, fs::path folder, @@ -339,14 +339,14 @@ ubyte* WorldFiles::readChunkData(int x, uint32_t offset; file.seekg(table_offset + chunkIndex * 4); file.read((char*)(&offset), 4); - offset = dataio::read_int32_big((const ubyte*)(&offset), 0); + offset = dataio::read_int32_big((const u_char8*)(&offset), 0); if (offset == 0){ return nullptr; } file.seekg(offset); file.read((char*)(&offset), 4); - length = dataio::read_int32_big((const ubyte*)(&offset), 0); - ubyte* data = new ubyte[length]; + length = dataio::read_int32_big((const u_char8*)(&offset), 0); + u_char8* data = new u_char8[length]; file.read((char*)data, length); if (data == nullptr) { std::cerr << "ERROR: failed to read data of chunk x("<< x <<"), z("<< z <<")" << std::endl; @@ -359,7 +359,7 @@ ubyte* WorldFiles::readChunkData(int x, * (see REGION_LAYER_* constants) */ void WorldFiles::fetchChunks(WorldRegion* region, int x, int z, fs::path folder, int layer) { - ubyte** chunks = region->getChunks(); + u_char8** chunks = region->getChunks(); uint32_t* sizes = region->getSizes(); for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) { @@ -396,18 +396,18 @@ void WorldFiles::writeRegion(int x, int z, WorldRegion* entry, fs::path folder, char intbuf[4]{}; uint offsets[REGION_CHUNKS_COUNT]{}; - ubyte** region = entry->getChunks(); + u_char8** region = entry->getChunks(); uint32_t* sizes = entry->getSizes(); for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) { - ubyte* chunk = region[i]; + u_char8* chunk = region[i]; if (chunk == nullptr){ offsets[i] = 0; } else { offsets[i] = offset; size_t compressedSize = sizes[i]; - dataio::write_int32_big(compressedSize, (ubyte*)intbuf, 0); + dataio::write_int32_big(compressedSize, (u_char8*)intbuf, 0); offset += 4 + compressedSize; file.write(intbuf, 4); @@ -415,7 +415,7 @@ void WorldFiles::writeRegion(int x, int z, WorldRegion* entry, fs::path folder, } } for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) { - dataio::write_int32_big(offsets[i], (ubyte*)intbuf, 0); + dataio::write_int32_big(offsets[i], (u_char8*)intbuf, 0); file.write(intbuf, 4); } } diff --git a/src/files/WorldFiles.h b/src/files/WorldFiles.h index d85b02210..b5f7cd008 100644 --- a/src/files/WorldFiles.h +++ b/src/files/WorldFiles.h @@ -41,21 +41,21 @@ public: }; class WorldRegion { - ubyte** chunksData; + u_char8** chunksData; uint32_t* sizes; bool unsaved = false; public: WorldRegion(); ~WorldRegion(); - void put(uint x, uint z, ubyte* data, uint32_t size); - ubyte* getChunkData(uint x, uint z); + void put(uint x, uint z, u_char8* data, uint32_t size); + u_char8* getChunkData(uint x, uint z); uint getChunkDataSize(uint x, uint z); void setUnsaved(bool unsaved); bool isUnsaved() const; - ubyte** getChunks() const; + u_char8** getChunks() const; uint32_t* getSizes() const; }; @@ -89,16 +89,16 @@ class WorldFiles { @param src source buffer @param srclen length of source buffer @param len (out argument) length of result buffer */ - ubyte* compress(const ubyte* src, size_t srclen, size_t& len); + u_char8* compress(const u_char8* src, size_t srclen, size_t& len); /* Decompress buffer with extrle @param src compressed buffer @param srclen length of compressed buffer @param dstlen max expected length of source buffer */ - ubyte* decompress(const ubyte* src, size_t srclen, size_t dstlen); + u_char8* decompress(const u_char8* src, size_t srclen, size_t dstlen); - ubyte* readChunkData(int x, int y, + u_char8* readChunkData(int x, int y, uint32_t& length, std::filesystem::path folder, int layer); @@ -108,7 +108,7 @@ class WorldFiles { void writeRegions(regionsmap& regions, const std::filesystem::path& folder, int layer); - ubyte* getData(regionsmap& regions, + u_char8* getData(regionsmap& regions, const std::filesystem::path& folder, int x, int z, int layer); @@ -121,7 +121,7 @@ public: regionsmap regions; regionsmap lights; std::filesystem::path directory; - std::unique_ptr compressionBuffer; + std::unique_ptr compressionBuffer; bool generatorTestMode; bool doWriteLights; @@ -129,12 +129,12 @@ public: ~WorldFiles(); void put(Chunk* chunk); - void put(int x, int z, const ubyte* voxelData); + void put(int x, int z, const u_char8* voxelData); int getVoxelRegionVersion(int x, int z); int getVoxelRegionsVersion(); - ubyte* getChunk(int x, int z); + u_char8* getChunk(int x, int z); light_t* getLights(int x, int z); bool readWorldInfo(World* world); diff --git a/src/files/binary_io.cpp b/src/files/binary_io.cpp index c16083a3b..a1a53b584 100644 --- a/src/files/binary_io.cpp +++ b/src/files/binary_io.cpp @@ -4,7 +4,7 @@ #include #include -void BinaryWriter::put(ubyte b) { +void BinaryWriter::put(u_char8 b) { buffer.push_back(b); } @@ -22,7 +22,7 @@ void BinaryWriter::put(const std::string& s) { throw std::domain_error("length > INT16_MAX"); } putInt16(len); - put((const ubyte*)s.data(), len); + put((const u_char8*)s.data(), len); } void BinaryWriter::putShortStr(const std::string& s) { @@ -31,10 +31,10 @@ void BinaryWriter::putShortStr(const std::string& s) { throw std::domain_error("length > 255"); } put(len); - put((const ubyte*)s.data(), len); + put((const u_char8*)s.data(), len); } -void BinaryWriter::put(const ubyte* arr, size_t size) { +void BinaryWriter::put(const u_char8* arr, size_t size) { buffer.reserve(buffer.size() + size); for (size_t i = 0; i < size; i++) { buffer.push_back(arr[i]); @@ -75,7 +75,7 @@ void BinaryWriter::putFloat32(float val) { putInt32(value.vali32); } -BinaryReader::BinaryReader(const ubyte* data, size_t size) +BinaryReader::BinaryReader(const u_char8* data, size_t size) : data(data), size(size), pos(0) { } @@ -84,14 +84,14 @@ void BinaryReader::checkMagic(const char* data, size_t size) { throw std::runtime_error("invalid magic number"); } for (size_t i = 0; i < size; i++) { - if (this->data[pos + i] != (ubyte)data[i]){ + if (this->data[pos + i] != (u_char8)data[i]){ throw std::runtime_error("invalid magic number"); } } pos += size; } -ubyte BinaryReader::get() { +u_char8 BinaryReader::get() { if (pos == size) { throw std::underflow_error("buffer underflow"); } @@ -152,7 +152,7 @@ std::string BinaryReader::getString() { } std::string BinaryReader::getShortString() { - ubyte length = get(); + u_char8 length = get(); if (pos+length > size) { throw std::underflow_error("unexpected end"); } diff --git a/src/files/binary_io.h b/src/files/binary_io.h index ac7a7299f..b3d308b5b 100644 --- a/src/files/binary_io.h +++ b/src/files/binary_io.h @@ -6,35 +6,35 @@ #include "../typedefs.h" class BinaryWriter { - std::vector buffer; + std::vector buffer; public: - void put(ubyte b); + void put(u_char8 b); void putCStr(const char* str); void putInt16(int16_t val); void putInt32(int32_t val); void putInt64(int64_t val); void putFloat32(float val); void put(const std::string& s); - void put(const ubyte* arr, size_t size); + void put(const u_char8* arr, size_t size); void putShortStr(const std::string& s); inline size_t size() const { return buffer.size(); } - inline const ubyte* data() const { + inline const u_char8* data() const { return buffer.data(); } }; class BinaryReader { - const ubyte* data; + const u_char8* data; size_t size; size_t pos; public: - BinaryReader(const ubyte* data, size_t size); + BinaryReader(const u_char8* data, size_t size); void checkMagic(const char* data, size_t size); - ubyte get(); + u_char8 get(); int16_t getInt16(); int32_t getInt32(); int64_t getInt64(); diff --git a/src/files/rle.cpp b/src/files/rle.cpp index 5a5c57143..87bece206 100644 --- a/src/files/rle.cpp +++ b/src/files/rle.cpp @@ -1,10 +1,10 @@ #include "rle.h" -size_t rle::decode(const ubyte* src, size_t srclen, ubyte* dst) { +size_t rle::decode(const u_char8* src, size_t srclen, u_char8* dst) { size_t offset = 0; for (size_t i = 0; i < srclen;) { - ubyte len = src[i++]; - ubyte c = src[i++]; + u_char8 len = src[i++]; + u_char8 c = src[i++]; for (size_t j = 0; j <= len; j++) { dst[offset++] = c; } @@ -12,15 +12,15 @@ size_t rle::decode(const ubyte* src, size_t srclen, ubyte* dst) { return offset; } -size_t rle::encode(const ubyte* src, size_t srclen, ubyte* dst) { +size_t rle::encode(const u_char8* src, size_t srclen, u_char8* dst) { if (srclen == 0) { return 0; } size_t offset = 0; - ubyte counter = 0; - ubyte c = src[0]; + u_char8 counter = 0; + u_char8 c = src[0]; for (size_t i = 1; i < srclen; i++) { - ubyte cnext = src[i]; + u_char8 cnext = src[i]; if (cnext != c || counter == 255) { dst[offset++] = counter; dst[offset++] = c; @@ -37,7 +37,7 @@ size_t rle::encode(const ubyte* src, size_t srclen, ubyte* dst) { } -size_t extrle::decode(const ubyte* src, size_t srclen, ubyte* dst) { +size_t extrle::decode(const u_char8* src, size_t srclen, u_char8* dst) { size_t offset = 0; for (size_t i = 0; i < srclen;) { uint len = src[i++]; @@ -45,7 +45,7 @@ size_t extrle::decode(const ubyte* src, size_t srclen, ubyte* dst) { len &= 0x7F; len |= ((uint)src[i++]) << 7; } - ubyte c = src[i++]; + u_char8 c = src[i++]; for (size_t j = 0; j <= len; j++) { dst[offset++] = c; } @@ -53,15 +53,15 @@ size_t extrle::decode(const ubyte* src, size_t srclen, ubyte* dst) { return offset; } -size_t extrle::encode(const ubyte* src, size_t srclen, ubyte* dst) { +size_t extrle::encode(const u_char8* src, size_t srclen, u_char8* dst) { if (srclen == 0) { return 0; } size_t offset = 0; uint counter = 0; - ubyte c = src[0]; + u_char8 c = src[0]; for (size_t i = 1; i < srclen; i++) { - ubyte cnext = src[i]; + u_char8 cnext = src[i]; if (cnext != c || counter == max_sequence) { if (counter >= 0x80) { dst[offset++] = 0x80 | (counter & 0x7F); diff --git a/src/files/rle.h b/src/files/rle.h index 0dcbe0427..b9f4c71af 100644 --- a/src/files/rle.h +++ b/src/files/rle.h @@ -4,14 +4,14 @@ #include "../typedefs.h" namespace rle { - size_t encode(const ubyte* src, size_t length, ubyte* dst); - size_t decode(const ubyte* src, size_t length, ubyte* dst); + size_t encode(const u_char8* src, size_t length, u_char8* dst); + size_t decode(const u_char8* src, size_t length, u_char8* dst); } namespace extrle { constexpr uint max_sequence = 0x7FFF; - size_t encode(const ubyte* src, size_t length, ubyte* dst); - size_t decode(const ubyte* src, size_t length, ubyte* dst); + size_t encode(const u_char8* src, size_t length, u_char8* dst); + size_t decode(const u_char8* src, size_t length, u_char8* dst); } #endif // FILES_RLE_H_ diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 2e8b7b3ca..7f441af50 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -87,7 +87,7 @@ HudRenderer::HudRenderer(Engine* engine, uicamera->perspective = false; uicamera->flipped = true; - Panel* panel = new Panel(vec2(250, 200), vec4(5.0f), 1.0f); + Panel* panel = new Panel(vec2(350, 300), vec4(5.0f), 1.0f); debugPanel = shared_ptr(panel); panel->listenInterval(1.0f, [this]() { fpsString = std::to_wstring(fpsMax)+L" / "+std::to_wstring(fpsMin); @@ -115,12 +115,18 @@ HudRenderer::HudRenderer(Engine* engine, auto indices = this->level->content->indices; auto def = indices->getBlockDef(player->selectedVoxel.id); std::wstringstream stream; - stream << std::hex << this->level->player->selectedVoxel.states; - if (def) { + + if (def) stream << L" (" << util::str2wstr_utf8(def->name) << L")"; - } - return L"block: "+std::to_wstring(player->selectedVoxel.id)+ - L" "+stream.str(); + + return L"block: "+std::to_wstring(player->selectedVoxel.id)+ + L" "+stream.str(); + }))); + panel->add(shared_ptr