diff --git a/src/coders/json.cpp b/src/coders/json.cpp index 0f72a5bfb..e18209981 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, u_char8& dst) const { +void JObject::num(std::string key, u_char& dst) const { dst = getInteger(key, dst); } diff --git a/src/coders/json.h b/src/coders/json.h index 497a5edbd..51fc08db2 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, u_char8& dst) const; + void num(std::string key, u_char& 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 d022fd1da..61b2e3e7d 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -16,7 +16,7 @@ #include // returns 0 if all-right, 1 otherwise -int _png_write(const char* filename, u_int width, u_int height, const u_char8* data, bool alpha) { +int _png_write(const char* filename, u_int width, u_int height, const u_char* data, bool alpha) { u_int pixsize = alpha ? 4 : 3; // Open file for writing (binary mode) @@ -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 u_char8*)image->getData(), image->getFormat() == ImageFormat::rgba8888); + _png_write(filename.c_str(), image->getWidth(), image->getHeight(), (const u_char*)image->getData(), image->getFormat() == ImageFormat::rgba8888); } \ No newline at end of file diff --git a/src/constants.h b/src/constants.h index 0b135aa4a..0a03abb15 100644 --- a/src/constants.h +++ b/src/constants.h @@ -11,8 +11,8 @@ const int CHUNK_W = 16; const int CHUNK_H = 256; const int CHUNK_D = 16; -const uint VOXEL_USER_BITS = 8; -constexpr uint VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS; +const u_int VOXEL_USER_BITS = 8; +constexpr u_int VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS; /* Chunk volume (count of voxels per Chunk) */ constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D); @@ -21,7 +21,7 @@ constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D); const blockid_t BLOCK_VOID = std::numeric_limits::max(); const blockid_t MAX_BLOCKS = BLOCK_VOID; -inline uint vox_index(int x, int y, int z, int w=CHUNK_W, int d=CHUNK_D) { +inline u_int vox_index(int x, int y, int z, int w=CHUNK_W, int d=CHUNK_D) { return (y * d + z) * w + x; } diff --git a/src/engine.cpp b/src/engine.cpp index a125663ee..644840805 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -65,7 +65,7 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths) } } - Audio::initialize(); + // Audio::initialize(); gui = std::make_unique(); if (settings.ui.language == "auto") { settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources()); @@ -126,7 +126,7 @@ Engine::~Engine() { scripting::close(); screen = nullptr; - Audio::finalize(); + // Audio::finalize(); std::cout << "-- shutting down" << std::endl; assets.reset(); diff --git a/src/engine.h b/src/engine.h index 01d2cf073..c65303108 100644 --- a/src/engine.h +++ b/src/engine.h @@ -36,7 +36,7 @@ class Engine { EnginePaths* paths; std::unique_ptr resPaths = nullptr; - uint64_t frame = 0; + u_long frame = 0; double lastTime = 0.0; double delta = 0.0; diff --git a/src/files/WorldConverter.cpp b/src/files/WorldConverter.cpp index ea40387b8..26759ac96 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 59b28a5f5..47f5f010c 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -34,7 +34,7 @@ regfile::regfile(fs::path filename) : file(filename) { file.read(header, REGION_HEADER_SIZE); // avoid of use strcmp_s - if (std::string(header, strlen(REGION_FORMAT_MAGIC)) != REGION_FORMAT_MAGIC) { + if (std::string(header, std::strlen(REGION_FORMAT_MAGIC)) != REGION_FORMAT_MAGIC) { throw std::runtime_error("invalid region file magic number"); } version = header[8]; @@ -45,7 +45,7 @@ regfile::regfile(fs::path filename) : file(filename) { } WorldRegion::WorldRegion() { - chunksData = new u_char8*[REGION_CHUNKS_COUNT]{}; + chunksData = new u_char*[REGION_CHUNKS_COUNT]{}; sizes = new uint32_t[REGION_CHUNKS_COUNT]{}; } @@ -64,7 +64,7 @@ bool WorldRegion::isUnsaved() const { return unsaved; } -u_char8** WorldRegion::getChunks() const { +u_char** WorldRegion::getChunks() const { return chunksData; } @@ -72,14 +72,14 @@ uint32_t* WorldRegion::getSizes() const { return sizes; } -void WorldRegion::put(uint x, uint z, u_char8* data, uint32_t size) { +void WorldRegion::put(uint x, uint z, u_char* data, uint32_t size) { size_t chunk_index = z * REGION_SIZE + x; delete[] chunksData[chunk_index]; chunksData[chunk_index] = data; sizes[chunk_index] = size; } -u_char8* WorldRegion::getChunkData(uint x, uint z) { +u_char* 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 u_char8[CHUNK_DATA_LEN * 2]); + compressionBuffer.reset(new u_char[CHUNK_DATA_LEN * 2]); } WorldFiles::~WorldFiles(){ @@ -113,20 +113,20 @@ WorldRegion* WorldFiles::getOrCreateRegion(regionsmap& regions, int x, int z) { return region; } -u_char8* WorldFiles::compress(const u_char8* src, size_t srclen, size_t& len) { - u_char8* buffer = this->compressionBuffer.get(); +u_char* WorldFiles::compress(const u_char* src, size_t srclen, size_t& len) { + u_char* buffer = this->compressionBuffer.get(); - len = extrle::encode(src, srclen, buffer); - u_char8* data = new u_char8[len]; + len = rle::encode((voxel_t *)src, srclen, (voxel_t *)buffer); + u_char* data = new u_char[len]; for (size_t i = 0; i < len; i++) { data[i] = buffer[i]; } return data; } -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); +u_char* WorldFiles::decompress(const u_char* src, size_t srclen, size_t dstlen) { + u_char* decompressed = new u_char[dstlen]; + rle::decode((voxel_t *)src, srclen, (voxel_t *)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 u_char8* voxelData) { +void WorldFiles::put(int x, int z, const u_char* 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 u_char8* voxelData) { WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ); region->setUnsaved(true); size_t compressedSize; - u_char8* data = compress(voxelData, CHUNK_DATA_LEN, compressedSize); + u_char* 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()); - u_char8* data = compress(chunk_data.get(), CHUNK_DATA_LEN, compressedSize); + std::unique_ptr chunk_data (chunk->encode()); + u_char* 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()); - u_char8* data = compress(light_data.get(), LIGHTMAP_DATA_LEN, compressedSize); + std::unique_ptr light_data (chunk->lightmap->encode()); + u_char* 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"); } -u_char8* WorldFiles::getChunk(int x, int z){ +u_char* 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()); } -u_char8* WorldFiles::getData(regionsmap& regions, const fs::path& folder, +u_char* 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 @@ u_char8* WorldFiles::getData(regionsmap& regions, const fs::path& folder, int localZ = z - (regionZ * REGION_SIZE); WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ); - u_char8* data = region->getChunkData(localX, localZ); + u_char* 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(); } -u_char8* WorldFiles::readChunkData(int x, +u_char* WorldFiles::readChunkData(int x, int z, uint32_t& length, fs::path folder, @@ -339,14 +339,14 @@ u_char8* WorldFiles::readChunkData(int x, uint32_t offset; file.seekg(table_offset + chunkIndex * 4); file.read((char*)(&offset), 4); - offset = dataio::read_int32_big((const u_char8*)(&offset), 0); + offset = dataio::read_int32_big((const u_char*)(&offset), 0); if (offset == 0){ return nullptr; } file.seekg(offset); file.read((char*)(&offset), 4); - length = dataio::read_int32_big((const u_char8*)(&offset), 0); - u_char8* data = new u_char8[length]; + length = dataio::read_int32_big((const u_char*)(&offset), 0); + u_char* data = new u_char[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 @@ u_char8* WorldFiles::readChunkData(int x, * (see REGION_LAYER_* constants) */ void WorldFiles::fetchChunks(WorldRegion* region, int x, int z, fs::path folder, int layer) { - u_char8** chunks = region->getChunks(); + u_char** 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]{}; - u_char8** region = entry->getChunks(); + u_char** region = entry->getChunks(); uint32_t* sizes = entry->getSizes(); for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) { - u_char8* chunk = region[i]; + u_char* chunk = region[i]; if (chunk == nullptr){ offsets[i] = 0; } else { offsets[i] = offset; size_t compressedSize = sizes[i]; - dataio::write_int32_big(compressedSize, (u_char8*)intbuf, 0); + dataio::write_int32_big(compressedSize, (u_char*)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], (u_char8*)intbuf, 0); + dataio::write_int32_big(offsets[i], (u_char*)intbuf, 0); file.write(intbuf, 4); } } diff --git a/src/files/WorldFiles.h b/src/files/WorldFiles.h index b5f7cd008..33de31175 100644 --- a/src/files/WorldFiles.h +++ b/src/files/WorldFiles.h @@ -41,21 +41,21 @@ public: }; class WorldRegion { - u_char8** chunksData; + u_char** chunksData; uint32_t* sizes; bool unsaved = false; public: WorldRegion(); ~WorldRegion(); - void put(uint x, uint z, u_char8* data, uint32_t size); - u_char8* getChunkData(uint x, uint z); + void put(uint x, uint z, u_char* data, uint32_t size); + u_char* getChunkData(uint x, uint z); uint getChunkDataSize(uint x, uint z); void setUnsaved(bool unsaved); bool isUnsaved() const; - u_char8** getChunks() const; + u_char** 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 */ - u_char8* compress(const u_char8* src, size_t srclen, size_t& len); + u_char* compress(const u_char* 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 */ - u_char8* decompress(const u_char8* src, size_t srclen, size_t dstlen); + u_char* decompress(const u_char* src, size_t srclen, size_t dstlen); - u_char8* readChunkData(int x, int y, + u_char* 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); - u_char8* getData(regionsmap& regions, + u_char* 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 u_char8* voxelData); + void put(int x, int z, const u_char* voxelData); int getVoxelRegionVersion(int x, int z); int getVoxelRegionsVersion(); - u_char8* getChunk(int x, int z); + u_char* 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 a1a53b584..c49c6f43e 100644 --- a/src/files/binary_io.cpp +++ b/src/files/binary_io.cpp @@ -4,7 +4,7 @@ #include #include -void BinaryWriter::put(u_char8 b) { +void BinaryWriter::put(u_char 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 u_char8*)s.data(), len); + put((const u_char*)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 u_char8*)s.data(), len); + put((const u_char*)s.data(), len); } -void BinaryWriter::put(const u_char8* arr, size_t size) { +void BinaryWriter::put(const u_char* 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 u_char8* data, size_t size) +BinaryReader::BinaryReader(const u_char* 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] != (u_char8)data[i]){ + if (this->data[pos + i] != (u_char)data[i]){ throw std::runtime_error("invalid magic number"); } } pos += size; } -u_char8 BinaryReader::get() { +u_char BinaryReader::get() { if (pos == size) { throw std::underflow_error("buffer underflow"); } @@ -152,7 +152,7 @@ std::string BinaryReader::getString() { } std::string BinaryReader::getShortString() { - u_char8 length = get(); + u_char 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 b3d308b5b..a47140718 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(u_char8 b); + void put(u_char 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 u_char8* arr, size_t size); + void put(const u_char* arr, size_t size); void putShortStr(const std::string& s); inline size_t size() const { return buffer.size(); } - inline const u_char8* data() const { + inline const u_char* data() const { return buffer.data(); } }; class BinaryReader { - const u_char8* data; + const u_char* data; size_t size; size_t pos; public: - BinaryReader(const u_char8* data, size_t size); + BinaryReader(const u_char* data, size_t size); void checkMagic(const char* data, size_t size); - u_char8 get(); + u_char get(); int16_t getInt16(); int32_t getInt32(); int64_t getInt64(); diff --git a/src/files/rle.cpp b/src/files/rle.cpp index 87bece206..b38921ffc 100644 --- a/src/files/rle.cpp +++ b/src/files/rle.cpp @@ -1,90 +1,93 @@ #include "rle.h" +// template +// size_t rle::decode(const T* src, size_t srclen, T* dst) { +// size_t offset = 0; +// for (size_t i = 0; i < srclen;) { +// T len = src[i++]; +// T c = src[i++]; +// for (size_t j = 0; j <= len; j++) { +// dst[offset++] = c; +// } +// } +// return offset; +// } -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;) { - u_char8 len = src[i++]; - u_char8 c = src[i++]; - for (size_t j = 0; j <= len; j++) { - dst[offset++] = c; - } - } - return offset; -} - -size_t rle::encode(const u_char8* src, size_t srclen, u_char8* dst) { - if (srclen == 0) { - return 0; - } - size_t offset = 0; - u_char8 counter = 0; - u_char8 c = src[0]; - for (size_t i = 1; i < srclen; i++) { - u_char8 cnext = src[i]; - if (cnext != c || counter == 255) { - dst[offset++] = counter; - dst[offset++] = c; - c = cnext; - counter = 0; - } - else { - counter++; - } - } - dst[offset++] = counter; - dst[offset++] = c; - return offset; -} +// template +// size_t rle::encode(const T* src, size_t srclen, T* dst) { +// if (srclen == 0) { +// return 0; +// } +// size_t offset = 0; +// u_int counter = 0; +// T c = src[0]; +// for (size_t i = 1; i < srclen; i++) { +// T cnext = src[i]; +// if (cnext != c || counter == 255) { +// dst[offset++] = counter; +// dst[offset++] = c; +// c = cnext; +// counter = 0; +// } +// else { +// counter++; +// } +// } +// dst[offset++] = counter; +// dst[offset++] = c; +// return offset; +// } -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++]; - if (len & 0x80) { - len &= 0x7F; - len |= ((uint)src[i++]) << 7; - } - u_char8 c = src[i++]; - for (size_t j = 0; j <= len; j++) { - dst[offset++] = c; - } - } - return offset; -} +// template +// size_t extrle::decode(const T* src, size_t srclen, T* dst) { +// size_t offset = 0; +// for (size_t i = 0; i < srclen;) { +// T len = src[i++]; +// if (len & 0x80) { +// len &= 0x7F; +// len |= ((T)src[i++]) << 7; +// } +// T c = src[i++]; +// for (size_t j = 0; j <= len; j++) { +// dst[offset++] = c; +// } +// } +// return offset; +// } -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; - u_char8 c = src[0]; - for (size_t i = 1; i < srclen; i++) { - u_char8 cnext = src[i]; - if (cnext != c || counter == max_sequence) { - if (counter >= 0x80) { - dst[offset++] = 0x80 | (counter & 0x7F); - dst[offset++] = counter >> 7; - } - else { - dst[offset++] = counter; - } - dst[offset++] = c; - c = cnext; - counter = 0; - } - else { - counter++; - } - } - if (counter >= 0x80) { - dst[offset++] = 0x80 | (counter & 0x7F); - dst[offset++] = counter >> 7; - } - else { - dst[offset++] = counter; - } - dst[offset++] = c; - return offset; -} +// template +// size_t extrle::encode(const T* src, size_t srclen, T* dst) { +// if (srclen == 0) { +// return 0; +// } +// size_t offset = 0; +// u_int counter = 0; +// T c = src[0]; +// for (size_t i = 1; i < srclen; i++) { +// T cnext = src[i]; +// if (cnext != c || counter == max_sequence) { +// if (counter >= 0x80) { +// dst[offset++] = 0x80 | (counter & 0x7F); +// dst[offset++] = counter >> 7; +// } +// else { +// dst[offset++] = counter; +// } +// dst[offset++] = c; +// c = cnext; +// counter = 0; +// } +// else { +// counter++; +// } +// } +// if (counter >= 0x80) { +// dst[offset++] = 0x80 | (counter & 0x7F); +// dst[offset++] = counter >> 7; +// } +// else { +// dst[offset++] = counter; +// } +// dst[offset++] = c; +// return offset; +// } diff --git a/src/files/rle.h b/src/files/rle.h index b9f4c71af..d116e7a0e 100644 --- a/src/files/rle.h +++ b/src/files/rle.h @@ -4,14 +4,44 @@ #include "../typedefs.h" namespace rle { - 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); -} + + template + T decode(const T* src, T srclen, T* dst) { + T offset = 0; + for (T i = 0; i < srclen / sizeof(T);) { + T len = src[i++]; + T c = src[i++]; + for (T j = 0; j <= len; j++) { + dst[offset++] = c; + } + } + return offset*sizeof(T); + } -namespace extrle { - constexpr uint max_sequence = 0x7FFF; - 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); + template + T encode(const T* src, T srclen, T* dst) { + if (srclen == 0) { + return 0; + } + T offset = 0; + u_int counter = 0; + T c = src[0]; + for (T i = 1; i < srclen / sizeof(T); i++) { + T cnext = src[i]; + if (cnext != c || counter == 255) { + dst[offset++] = counter; + dst[offset++] = c; + c = cnext; + counter = 0; + } + else { + counter++; + } + } + dst[offset++] = counter; + dst[offset++] = c; + return offset*sizeof(T); + } } #endif // FILES_RLE_H_ diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 7f441af50..fa605f450 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -125,7 +125,7 @@ HudRenderer::HudRenderer(Engine* engine, panel->add(shared_ptr