type-update

This commit is contained in:
alexei-zebra 2024-01-03 23:29:43 +03:00
parent e7e2c16ee6
commit 3c7f46987a
32 changed files with 161 additions and 153 deletions

View file

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

View file

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

View file

@ -18,7 +18,7 @@ using std::unique_ptr;
#include <png.h>
// returns 0 if all-right, 1 otherwise
int _png_write(const char* filename, uint width, uint height, const ubyte* data, bool alpha) {
int _png_write(const char* filename, uint width, uint height, const u_char8* data, bool alpha) {
png_structp png_ptr = nullptr;
png_infop info_ptr = nullptr;
uint pixsize = alpha ? 4 : 3;
@ -365,5 +365,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);
}

View file

@ -56,7 +56,7 @@ void WorldConverter::convertNext() {
for (uint cx = 0; cx < REGION_SIZE; cx++) {
int gx = cx + x * REGION_SIZE;
int gz = cz + y * REGION_SIZE;
unique_ptr<ubyte[]> data (wfile->getChunk(gx, gz));
unique_ptr<u_char8[]> data (wfile->getChunk(gx, gz));
if (data == nullptr)
continue;
Chunk::convert(data.get(), lut);

View file

@ -27,7 +27,7 @@
namespace fs = std::filesystem;
WorldRegion::WorldRegion() {
chunksData = new ubyte*[REGION_CHUNKS_COUNT]{};
chunksData = new u_char8*[REGION_CHUNKS_COUNT]{};
sizes = new uint32_t[REGION_CHUNKS_COUNT]{};
}
@ -46,7 +46,7 @@ bool WorldRegion::isUnsaved() const {
return unsaved;
}
ubyte** WorldRegion::getChunks() const {
u_char8** WorldRegion::getChunks() const {
return chunksData;
}
@ -54,14 +54,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];
}
@ -73,7 +73,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(){
@ -95,19 +95,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;
}
@ -117,7 +117,7 @@ ubyte* WorldFiles::decompress(const ubyte* src, size_t srclen, size_t dstlen) {
* @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);
@ -127,7 +127,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);
}
}
@ -145,8 +145,8 @@ void WorldFiles::put(Chunk* chunk){
/* Writing Voxels */ {
size_t compressedSize;
std::unique_ptr<ubyte[]> chunk_data (chunk->encode());
ubyte* data = compress(chunk_data.get(), CHUNK_DATA_LEN, compressedSize);
std::unique_ptr<u_char8[]> chunk_data (chunk->encode());
u_char8* data = compress(chunk_data.get(), CHUNK_DATA_LEN, compressedSize);
WorldRegion* region = getOrCreateRegion(regions, regionX, regionZ);
region->setUnsaved(true);
@ -154,8 +154,8 @@ void WorldFiles::put(Chunk* chunk){
}
if (doWriteLights && chunk->isLighted()) {
size_t compressedSize;
std::unique_ptr<ubyte[]> light_data (chunk->lightmap->encode());
ubyte* data = compress(light_data.get(), LIGHTMAP_DATA_LEN, compressedSize);
std::unique_ptr<u_char8[]> 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);
@ -214,20 +214,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<ubyte> data (getData(lights, getLightsFolder(), x, z, REGION_LAYER_LIGHTS));
std::unique_ptr<u_char8> 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);
@ -237,7 +237,7 @@ ubyte* WorldFiles::getData(regionsmap& regions, const fs::path& folder,
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);
@ -270,7 +270,7 @@ files::rafile* 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,
@ -296,14 +296,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;
@ -316,7 +316,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++) {
@ -353,18 +353,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);
@ -372,7 +372,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);
}
}

View file

@ -34,21 +34,21 @@ class ContentIndices;
class World;
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;
};
@ -75,16 +75,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);
@ -94,7 +94,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);
@ -107,7 +107,7 @@ public:
regionsmap regions;
regionsmap lights;
std::filesystem::path directory;
std::unique_ptr<ubyte[]> compressionBuffer;
std::unique_ptr<u_char8[]> compressionBuffer;
bool generatorTestMode;
bool doWriteLights;
@ -115,9 +115,9 @@ 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);
ubyte* getChunk(int x, int z);
u_char8* getChunk(int x, int z);
light_t* getLights(int x, int z);
bool readWorldInfo(World* world);

View file

@ -6,7 +6,7 @@
using std::string;
void BinaryWriter::put(ubyte b) {
void BinaryWriter::put(u_char8 b) {
buffer.push_back(b);
}
@ -24,7 +24,7 @@ void BinaryWriter::put(const 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 string& s) {
@ -33,10 +33,10 @@ void BinaryWriter::putShortStr(const 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]);
@ -77,7 +77,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) {
}
@ -86,14 +86,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");
}
@ -154,7 +154,7 @@ string BinaryReader::getString() {
}
string BinaryReader::getShortString() {
ubyte length = get();
u_char8 length = get();
if (pos+length > size) {
throw std::underflow_error("unexpected end");
}

View file

@ -6,35 +6,35 @@
#include "../typedefs.h"
class BinaryWriter {
std::vector<ubyte> buffer;
std::vector<u_char8> 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();

View file

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

View file

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

View file

@ -23,7 +23,7 @@ Batch3D::Batch3D(size_t capacity)
mesh = new Mesh(buffer, 0, attrs);
index = 0;
ubyte pixels[] = {
u_char8 pixels[] = {
255, 255, 255, 255,
};
blank = new Texture(pixels, 1, 1, GL_RGBA);

View file

@ -187,7 +187,7 @@ void BlocksRenderer::blockXSprite(int x, int y, int z,
/* AABB blocks render method */
void BlocksRenderer::blockAABB(const ivec3& icoord,
const UVRegion(&texfaces)[6],
const Block* block, ubyte rotation,
const Block* block, u_char8 rotation,
bool lights) {
AABB hitbox = block->hitbox;
vec3 size = hitbox.size();
@ -221,9 +221,9 @@ void BlocksRenderer::blockAABB(const ivec3& icoord,
void BlocksRenderer::blockCube(int x, int y, int z,
const UVRegion(&texfaces)[6],
const Block* block,
ubyte states,
u_char8 states,
bool lights) {
ubyte group = block->drawGroup;
u_char8 group = block->drawGroup;
vec3 X(1, 0, 0);
vec3 Y(0, 1, 0);
@ -258,7 +258,7 @@ void BlocksRenderer::blockCube(int x, int y, int z,
}
// Does block allow to see other blocks sides (is it transparent)
bool BlocksRenderer::isOpen(int x, int y, int z, ubyte group) const {
bool BlocksRenderer::isOpen(int x, int y, int z, u_char8 group) const {
blockid_t id = voxelsBuffer->pickBlockId(chunk->x * CHUNK_W + x,
y,
chunk->z * CHUNK_D + z);

View file

@ -60,16 +60,16 @@ class BlocksRenderer {
const UVRegion& region,
bool lights);
void blockCube(int x, int y, int z, const UVRegion(&faces)[6], const Block* block, ubyte states, bool lights);
void blockCube(int x, int y, int z, const UVRegion(&faces)[6], const Block* block, u_char8 states, bool lights);
void blockAABB(const glm::ivec3& coord,
const UVRegion(&faces)[6],
const Block* block,
ubyte rotation,
u_char8 rotation,
bool lights);
void blockXSprite(int x, int y, int z, const glm::vec3& size, const UVRegion& face1, const UVRegion& face2, float spread);
bool isOpenForLight(int x, int y, int z) const;
bool isOpen(int x, int y, int z, ubyte group) const;
bool isOpen(int x, int y, int z, u_char8 group) const;
glm::vec4 pickLight(int x, int y, int z) const;
glm::vec4 pickLight(const glm::ivec3& coord) const;

View file

@ -14,8 +14,8 @@ inline int max(int a, int b) {
ImageData::ImageData(ImageFormat format, uint width, uint height)
: format(format), width(width), height(height) {
switch (format) {
case ImageFormat::rgb888: data = new ubyte[width*height*3]{}; break;
case ImageFormat::rgba8888: data = new ubyte[width*height*4]{}; break;
case ImageFormat::rgb888: data = new u_char8[width*height*3]{}; break;
case ImageFormat::rgba8888: data = new u_char8[width*height*4]{}; break;
default:
throw std::runtime_error("format is not supported");
}
@ -29,7 +29,7 @@ ImageData::~ImageData() {
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::rgba8888:
delete[] (ubyte*)data;
delete[] (u_char8*)data;
break;
}
}
@ -40,11 +40,11 @@ void ImageData::flipX() {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
size = (format == ImageFormat::rgba8888) ? 4 : 3;
ubyte* pixels = (ubyte*)data;
u_char8* pixels = (u_char8*)data;
for (uint y = 0; y < height; y++) {
for (uint x = 0; x < width/2; x++) {
for (uint c = 0; c < size; c++) {
ubyte temp = pixels[(y * width + x) * size + c];
u_char8 temp = pixels[(y * width + x) * size + c];
pixels[(y * width + x) * size + c] = pixels[(y * width + (width - x - 1)) * size + c];
pixels[(y * width + (width - x - 1)) * size + c] = temp;
}
@ -63,11 +63,11 @@ void ImageData::flipY() {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
size = (format == ImageFormat::rgba8888) ? 4 : 3;
ubyte* pixels = (ubyte*)data;
u_char8* pixels = (u_char8*)data;
for (uint y = 0; y < height/2; y++) {
for (uint x = 0; x < width; x++) {
for (uint c = 0; c < size; c++) {
ubyte temp = pixels[(y * width + x) * size + c];
u_char8 temp = pixels[(y * width + x) * size + c];
pixels[(y * width + x) * size + c] =
pixels[((height-y-1) * width + x) * size + c];
pixels[((height-y-1) * width + x) * size + c] = temp;
@ -92,8 +92,8 @@ void ImageData::blit(const ImageData* image, int x, int y) {
default:
throw std::runtime_error("only unsigned byte formats supported");
}
ubyte* pixels = static_cast<ubyte*>(data);
ubyte* source = static_cast<ubyte*>(image->getData());
u_char8* pixels = static_cast<u_char8*>(data);
u_char8* source = static_cast<u_char8*>(image->getData());
uint srcwidth = image->getWidth();
uint srcheight = image->getHeight();
@ -120,7 +120,7 @@ void ImageData::extrude(int x, int y, int w, int h) {
default:
throw std::runtime_error("only unsigned byte formats supported");
}
ubyte* pixels = static_cast<ubyte*>(data);
u_char8* pixels = static_cast<u_char8*>(data);
int rx = x + w - 1;
int ry = y + h - 1;
@ -207,7 +207,7 @@ void ImageData::extrude(int x, int y, int w, int h) {
}
void ImageData::fixAlphaColor() {
ubyte* pixels = static_cast<ubyte*>(data);
u_char8* pixels = static_cast<u_char8*>(data);
// Fixing black transparent pixels for Mip-Mapping
for (uint ly = 0; ly < height-1; ly++) {
@ -235,8 +235,8 @@ ImageData* add_atlas_margins(ImageData* image, int grid_size) {
int dstwidth = srcwidth + grid_size * 2;
int dstheight = srcheight + grid_size * 2;
const ubyte* srcdata = (const ubyte*)image->getData();
ubyte* dstdata = new ubyte[dstwidth*dstheight * 4];
const u_char8* srcdata = (const u_char8*)image->getData();
u_char8* dstdata = new u_char8[dstwidth*dstheight * 4];
int imgres = image->getWidth() / grid_size;
for (int row = 0; row < grid_size; row++) {

View file

@ -5,7 +5,7 @@
#include "../typedefs.h"
struct vattr {
ubyte size;
u_char8 size;
};
class Mesh {

View file

@ -8,7 +8,7 @@ Texture::Texture(uint id, int width, int height)
: id(id), width(width), height(height) {
}
Texture::Texture(ubyte* data, int width, int height, uint format)
Texture::Texture(u_char8* data, int width, int height, uint format)
: width(width), height(height) {
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
@ -30,7 +30,7 @@ void Texture::bind(){
glBindTexture(GL_TEXTURE_2D, id);
}
void Texture::reload(ubyte* data){
void Texture::reload(u_char8* data){
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
@ -48,5 +48,5 @@ Texture* Texture::from(const ImageData* image) {
default:
throw std::runtime_error("unsupported image data format");
}
return new Texture((ubyte*)data, width, height, format);
return new Texture((u_char8*)data, width, height, format);
}

View file

@ -12,11 +12,11 @@ public:
int width;
int height;
Texture(uint id, int width, int height);
Texture(ubyte* data, int width, int height, uint format);
Texture(u_char8* data, int width, int height, uint format);
~Texture();
void bind();
void reload(ubyte* data);
void reload(u_char8* data);
static Texture* from(const ImageData* image);
};

View file

@ -27,18 +27,18 @@ void Lightmap::set(light_t* map) {
static_assert(sizeof(light_t) == 2, "replace dataio calls to new light_t");
ubyte* Lightmap::encode() const {
ubyte* buffer = new ubyte[LIGHTMAP_DATA_LEN];
u_char8* Lightmap::encode() const {
u_char8* buffer = new u_char8[LIGHTMAP_DATA_LEN];
for (uint i = 0; i < CHUNK_VOL; i+=2) {
buffer[i/2] = ((map[i] >> 12) & 0xF) | ((map[i+1] >> 8) & 0xF0);
}
return buffer;
}
light_t* Lightmap::decode(ubyte* buffer) {
light_t* Lightmap::decode(u_char8* buffer) {
light_t* lights = new light_t[CHUNK_VOL];
for (uint i = 0; i < CHUNK_VOL; i+=2) {
ubyte b = buffer[i/2];
u_char8 b = buffer[i/2];
lights[i] = ((b & 0xF) << 12);
lights[i+1] = ((b & 0xF0) << 8);
}

View file

@ -80,12 +80,12 @@ public:
return r | (g << 4) | (b << 8) | (s << 12);
}
static inline light_t extract(light_t light, ubyte channel) {
static inline light_t extract(light_t light, u_char8 channel) {
return (light >> (channel << 2)) & 0xF;
}
ubyte* encode() const;
static light_t* decode(ubyte* buffer);
u_char8* encode() const;
static light_t* decode(u_char8* buffer);
};
#endif /* LIGHTING_LIGHTMAP_H_ */

View file

@ -44,7 +44,7 @@ inline int fast_rand(void) {
return (g_seed >> 16) & 0x7FFF;
}
inline light_t light_pack(ubyte r, ubyte g, ubyte b, ubyte s) {
inline light_t light_pack(u_char8 r, u_char8 g, u_char8 b, u_char8 s) {
return r | (g << 4) | (b << 8) | (s << 12);
}

View file

@ -4,13 +4,17 @@
#include <stdlib.h>
#include <stdint.h>
typedef unsigned int uint;
// use for bytes arrays
typedef uint8_t ubyte;
typedef uint8_t u_char8;
typedef uint16_t u_short16;
typedef uint32_t u_int32;
typedef uint64_t u_long64;
typedef uint8_t blockid_t;
typedef uint8_t blockstate_t;
// typedef unsigned int uint;
// typedef unsigned short ushort;
// typedef unsigned char ubyte;
typedef uint16_t blockid_t;
typedef uint16_t light_t;
#endif

View file

@ -5,19 +5,19 @@
namespace dataio {
/* Read big-endian 16 bit signed integer from bytes */
inline int16_t read_int16_big(const ubyte* src, size_t offset) {
inline int16_t read_int16_big(const u_char8* src, size_t offset) {
return (src[offset] << 8) |
(src[offset+1]);
}
/* Read big-endian 32 bit signed integer from bytes */
inline int32_t read_int32_big(const ubyte* src, size_t offset) {
inline int32_t read_int32_big(const u_char8* src, size_t offset) {
return (src[offset] << 24) |
(src[offset+1] << 16) |
(src[offset+2] << 8) |
(src[offset+3]);
}
/* Read big-endian 64 bit signed integer from bytes */
inline int64_t read_int64_big(const ubyte* src, size_t offset) {
inline int64_t read_int64_big(const u_char8* src, size_t offset) {
return (int64_t(src[offset]) << 56) |
(int64_t(src[offset+1]) << 48) |
(int64_t(src[offset+2]) << 40) |
@ -28,19 +28,19 @@ namespace dataio {
(int64_t(src[offset+7]));
}
/* Write big-endian 16 bit signed integer to bytes */
inline void write_int16_big(int16_t value, ubyte* dest, size_t offset) {
inline void write_int16_big(int16_t value, u_char8* dest, size_t offset) {
dest[offset] = (char) (value >> 8 & 255);
dest[offset+1] = (char) (value >> 0 & 255);
}
/* Write big-endian 32 bit signed integer to bytes */
inline void write_int32_big(int32_t value, ubyte* dest, size_t offset) {
inline void write_int32_big(int32_t value, u_char8* dest, size_t offset) {
dest[offset] = (char) (value >> 24 & 255);
dest[offset+1] = (char) (value >> 16 & 255);
dest[offset+2] = (char) (value >> 8 & 255);
dest[offset+3] = (char) (value >> 0 & 255);
}
/* Write big-endian 64 bit signed integer to bytes */
inline void write_int64_big(int64_t value, ubyte* dest, size_t offset) {
inline void write_int64_big(int64_t value, u_char8* dest, size_t offset) {
dest[offset] = (char) (value >> 56 & 255);
dest[offset+1] = (char) (value >> 48 & 255);
dest[offset+2] = (char) (value >> 40 & 255);

View file

@ -36,7 +36,7 @@ wstring util::rfill(wstring s, uint length, wchar_t c) {
return ss.str();
}
uint util::encode_utf8(uint32_t c, ubyte* bytes) {
uint util::encode_utf8(uint32_t c, u_char8* bytes) {
if (c < 0x80) {
bytes[0] = ((c >> 0) & 0x7F) | 0x00;
return 1;
@ -77,7 +77,7 @@ const utf_t utf[] = {
};
inline uint utf8_len(ubyte cp) {
inline uint utf8_len(u_char8 cp) {
uint len = 0;
for (const utf_t* u = utf; u->mask; ++u) {
if((cp >= u->beg) && (cp <= u->end)) {
@ -107,7 +107,7 @@ string util::wstr2str_utf8(const wstring ws) {
vector<char> chars;
char buffer[4];
for (wchar_t wc : ws) {
uint size = encode_utf8((uint)wc, (ubyte*)buffer);
uint size = encode_utf8((uint)wc, (u_char8*)buffer);
for (uint i = 0; i < size; i++) {
chars.push_back(buffer[i]);
}

View file

@ -8,7 +8,7 @@ namespace util {
extern std::wstring lfill(std::wstring s, uint length, wchar_t c);
extern std::wstring rfill(std::wstring s, uint length, wchar_t c);
extern uint encode_utf8(uint32_t c, ubyte* bytes);
extern uint encode_utf8(uint32_t c, u_char8* bytes);
extern uint32_t decode_utf8(uint& size, const char* bytes);
extern std::string wstr2str_utf8(const std::wstring ws);
extern std::wstring str2wstr_utf8(const std::string s);

View file

@ -61,11 +61,11 @@ Chunk* Chunk::clone() const {
Current chunk format:
[voxel_ids...][voxel_states...];
*/
ubyte* Chunk::encode() const {
ubyte* buffer = new ubyte[CHUNK_DATA_LEN];
u_char8* Chunk::encode() const {
u_char8* buffer = new u_char8[CHUNK_DATA_LEN];
for (size_t i = 0; i < CHUNK_VOL; i++) {
buffer[i] = voxels[i].id;
buffer[CHUNK_VOL + i] = voxels[i].states;
((u_short16*)buffer)[i] = voxels[i].id;
((u_short16*)buffer)[CHUNK_VOL + i] = voxels[i].states;
}
return buffer;
}
@ -73,16 +73,16 @@ ubyte* Chunk::encode() const {
/**
@return true if all is fine
*/
bool Chunk::decode(ubyte* data) {
bool Chunk::decode(u_char8* data) {
for (size_t i = 0; i < CHUNK_VOL; i++) {
voxel& vox = voxels[i];
vox.id = data[i];
vox.states = data[CHUNK_VOL + i];
vox.id = ((u_short16*)data)[i];
vox.states = ((u_short16*)data)[CHUNK_VOL + i];
}
return true;
}
void Chunk::convert(ubyte* data, const ContentLUT* lut) {
void Chunk::convert(u_char8* data, const ContentLUT* lut) {
for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = data[i];
data[i] = lut->getBlockId(id);

View file

@ -12,7 +12,7 @@ struct ChunkFlag{
static const int UNSAVED = 0x10;
static const int LOADED_LIGHTS = 0x20;
};
#define CHUNK_DATA_LEN (CHUNK_VOL*2)
#define CHUNK_DATA_LEN (CHUNK_VOL*4)
struct voxel;
class Lightmap;
@ -75,10 +75,10 @@ public:
inline void setReady(bool newState) {SETFLAGS(ChunkFlag::READY, newState);}
ubyte* encode() const;
bool decode(ubyte* data);
u_char8* encode() const;
bool decode(u_char8* data);
static void convert(ubyte* data, const ContentLUT* lut);
static void convert(u_char8* data, const ContentLUT* lut);
};
#endif /* VOXELS_CHUNK_H_ */

View file

@ -104,7 +104,7 @@ bool Chunks::isReplaceable(int x, int y, int z) {
return contentIds->getBlockDef(v->id)->replaceable;
}
ubyte Chunks::getLight(int x, int y, int z, int channel){
u_char8 Chunks::getLight(int x, int y, int z, int channel){
x -= ox * CHUNK_W;
z -= oz * CHUNK_D;
int cx = floordiv(x, CHUNK_W);

View file

@ -41,7 +41,7 @@ public:
Chunk* getChunkByVoxel(int x, int y, int z);
voxel* get(int x, int y, int z);
light_t getLight(int x, int y, int z);
ubyte getLight(int x, int y, int z, int channel);
u_char8 getLight(int x, int y, int z, int channel);
void set(int x, int y, int z, int id, uint8_t states);
voxel* rayCast(glm::vec3 start,

View file

@ -14,18 +14,22 @@
#include "../lighting/Lightmap.h"
#include "../typedefs.h"
using glm::ivec2;
using std::unique_ptr;
using std::shared_ptr;
ChunksStorage::ChunksStorage(Level* level) : level(level) {
}
ChunksStorage::~ChunksStorage() {
}
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
void ChunksStorage::store(shared_ptr<Chunk> chunk) {
chunksMap[ivec2(chunk->x, chunk->z)] = chunk;
}
std::shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(glm::ivec2(x, z));
shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(ivec2(x, z));
if (found == chunksMap.end()) {
return nullptr;
}
@ -33,7 +37,7 @@ std::shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
}
void ChunksStorage::remove(int x, int z) {
auto found = chunksMap.find(glm::ivec2(x, z));
auto found = chunksMap.find(ivec2(x, z));
if (found != chunksMap.end()) {
chunksMap.erase(found->first);
}
@ -42,9 +46,9 @@ void ChunksStorage::remove(int x, int z) {
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
World* world = level->world;
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
auto chunk = shared_ptr<Chunk>(new Chunk(x, z));
store(chunk);
std::unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
unique_ptr<u_char8> data(world->wfile->getChunk(chunk->x, chunk->z));
if (data) {
chunk->decode(data.get());
chunk->setLoaded(true);
@ -96,7 +100,7 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
// cw*ch chunks will be scanned
for (int cz = scz; cz < scz + ch; cz++) {
for (int cx = scx; cx < scx + cw; cx++) {
auto found = chunksMap.find(glm::ivec2(cx, cz));
auto found = chunksMap.find(ivec2(cx, cz));
if (found == chunksMap.end()) {
// no chunk loaded -> filling with BLOCK_VOID
for (int ly = y; ly < y + h; ly++) {

View file

@ -26,7 +26,7 @@ public:
void getVoxels(VoxelsVolume* volume, bool backlight=false) const;
std::shared_ptr<Chunk> create(int x, int z);
light_t getLight(int x, int y, int z, ubyte channel) const;
light_t getLight(int x, int y, int z, u_char8 channel) const;
};

View file

@ -17,13 +17,13 @@ const int BLOCK_VARIANT_MASK = 0xF0;
struct voxel {
blockid_t id;
blockstate_t states;
u_short16 states;
inline uint8_t rotation() const {
inline u_char8 rotation() const {
return states & BLOCK_ROT_MASK;
}
inline uint8_t variant() const {
inline u_char8 variant() const {
return (states & BLOCK_VARIANT_MASK) >> 4;
}
};

View file

@ -292,7 +292,7 @@ DisplaySettings* Window::getSettings() {
}
ImageData* Window::takeScreenshot() {
ubyte* data = new ubyte[width * height * 3];
u_char8* data = new u_char8[width * height * 3];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
return new ImageData(ImageFormat::rgb888, width, height, data);