mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
Merge branch 'voxel-upd' into vixel-upd-2
This commit is contained in:
commit
d9e1d353d5
36 changed files with 498 additions and 286 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
#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) {
|
||||
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);
|
||||
}
|
||||
|
|
@ -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<ubyte[]> data (wfile->getChunk(gx, gz));
|
||||
std::unique_ptr<u_char8[]> data (wfile->getChunk(gx, gz));
|
||||
if (data == nullptr)
|
||||
continue;
|
||||
if (wfile->getVoxelRegionVersion(x, z) != REGION_FORMAT_VERSION) {
|
||||
|
|
|
|||
|
|
@ -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<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);
|
||||
|
|
@ -197,8 +197,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);
|
||||
|
|
@ -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<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);
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ubyte[]> compressionBuffer;
|
||||
std::unique_ptr<u_char8[]> 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);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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<UINode>(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<Label>(create_label([this](){
|
||||
auto player = this->level->player;
|
||||
auto indices = this->level->content->indices;
|
||||
auto str_ = L"dir: "+std::to_wstring(player->selectedVoxel.getDir()) + L" signal: "+std::to_wstring(player->selectedVoxel.getSig());
|
||||
return str_;
|
||||
})));
|
||||
panel->add(shared_ptr<Label>(create_label([this](){
|
||||
return L"seed: "+std::to_wstring(this->level->world->seed);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -231,7 +231,7 @@ void BlocksRenderer::blockCube(int x, int y, int z,
|
|||
vec3 coord(x, y, z);
|
||||
if (block->rotatable) {
|
||||
auto& rotations = block->rotations;
|
||||
auto& orient = rotations.variants[states & BLOCK_ROT_MASK];
|
||||
auto& orient = rotations.variants[states & BLOCK_DIR_MASK];
|
||||
X = orient.axisX;
|
||||
Y = orient.axisY;
|
||||
Z = orient.axisZ;
|
||||
|
|
@ -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);
|
||||
|
|
@ -348,7 +348,7 @@ void BlocksRenderer::render(const voxel* voxels) {
|
|||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.rotation(), !def.rt.emissive);
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.getDir(), !def.rt.emissive);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -122,8 +122,8 @@ void ImageData::blitMatchingFormat(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();
|
||||
|
||||
|
|
@ -150,7 +150,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;
|
||||
|
|
@ -237,7 +237,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++) {
|
||||
|
|
@ -265,8 +265,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++) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "../typedefs.h"
|
||||
|
||||
struct vattr {
|
||||
ubyte size;
|
||||
u_char8 size;
|
||||
};
|
||||
|
||||
class Mesh {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ void BlocksController::updateSides(int x, int y, int z) {
|
|||
}
|
||||
|
||||
void BlocksController::breakBlock(Player* player, const Block* def, int x, int y, int z) {
|
||||
chunks->set(x,y,z, 0, 0);
|
||||
chunks->set(x,y,z, voxel{0,0});
|
||||
lighting->onBlockSet(x,y,z, 0);
|
||||
if (def->rt.funcsset.onbroken) {
|
||||
scripting::on_block_broken(player, def, x, y, z);
|
||||
|
|
@ -75,7 +75,11 @@ void BlocksController::updateBlock(int x, int y, int z) {
|
|||
return;
|
||||
}
|
||||
if (def->rt.funcsset.update) {
|
||||
int states = vox->states;
|
||||
int id = vox->id;
|
||||
scripting::update_block(def, x, y, z);
|
||||
if (states != vox->states || id!= vox->id)
|
||||
updateSides(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -236,27 +236,27 @@ void PlayerController::updateInteraction(){
|
|||
int x = iend.x;
|
||||
int y = iend.y;
|
||||
int z = iend.z;
|
||||
uint8_t states = 0;
|
||||
voxel voxel;
|
||||
|
||||
Block* def = contentIds->getBlockDef(player->chosenBlock);
|
||||
if (def->rotatable){
|
||||
const std::string& name = def->rotations.name;
|
||||
if (name == "pipe") {
|
||||
if (norm.x < 0.0f) states = BLOCK_DIR_WEST;
|
||||
else if (norm.x > 0.0f) states = BLOCK_DIR_EAST;
|
||||
else if (norm.y > 0.0f) states = BLOCK_DIR_UP;
|
||||
else if (norm.y < 0.0f) states = BLOCK_DIR_DOWN;
|
||||
else if (norm.z > 0.0f) states = BLOCK_DIR_NORTH;
|
||||
else if (norm.z < 0.0f) states = BLOCK_DIR_SOUTH;
|
||||
if (norm.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
|
||||
else if (norm.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
|
||||
else if (norm.y > 0.0f) voxel.setDir(BLOCK_DIR_UP);
|
||||
else if (norm.y < 0.0f) voxel.setDir(BLOCK_DIR_DOWN);
|
||||
else if (norm.z > 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
|
||||
else if (norm.z < 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
|
||||
} else if (name == "pane") {
|
||||
glm::vec3 vec = camera->dir;
|
||||
if (abs(vec.x) > abs(vec.z)){
|
||||
if (vec.x > 0.0f) states = BLOCK_DIR_EAST;
|
||||
if (vec.x < 0.0f) states = BLOCK_DIR_WEST;
|
||||
if (vec.x > 0.0f) voxel.setDir(BLOCK_DIR_EAST);
|
||||
if (vec.x < 0.0f) voxel.setDir(BLOCK_DIR_WEST);
|
||||
}
|
||||
if (abs(vec.x) < abs(vec.z)){
|
||||
if (vec.z > 0.0f) states = BLOCK_DIR_SOUTH;
|
||||
if (vec.z < 0.0f) states = BLOCK_DIR_NORTH;
|
||||
if (vec.z > 0.0f) voxel.setDir(BLOCK_DIR_SOUTH);
|
||||
if (vec.z < 0.0f) voxel.setDir(BLOCK_DIR_NORTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -285,7 +285,8 @@ void PlayerController::updateInteraction(){
|
|||
chosenBlock = 0;
|
||||
}
|
||||
if (chosenBlock != vox->id) {
|
||||
chunks->set(x, y, z, chosenBlock, states);
|
||||
voxel.id = chosenBlock;
|
||||
chunks->set(x, y, z, voxel);
|
||||
lighting->onBlockSet(x,y,z, chosenBlock);
|
||||
if (def->rt.funcsset.onplaced) {
|
||||
scripting::on_block_placed(player, def, x, y, z);
|
||||
|
|
@ -299,6 +300,7 @@ void PlayerController::updateInteraction(){
|
|||
player->chosenBlock = chunks->get(x,y,z)->id;
|
||||
}
|
||||
} else {
|
||||
player->selectedVoxel = voxel{0, 0};
|
||||
selectedBlockId = -1;
|
||||
selectedBlockStates = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,13 +39,14 @@ int l_block_index(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_set_block(lua_State* L) {
|
||||
voxel voxel;
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int id = lua_tointeger(L, 4);
|
||||
int states = lua_tointeger(L, 5);
|
||||
scripting::level->chunks->set(x, y, z, id, states);
|
||||
scripting::level->lighting->onBlockSet(x,y,z, id);
|
||||
voxel.id = lua_tointeger(L, 4);
|
||||
voxel.states = lua_tointeger(L, 5);
|
||||
scripting::level->chunks->set(x, y, z, voxel);
|
||||
scripting::level->lighting->onBlockSet(x,y,z, voxel.id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -66,57 +67,6 @@ inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
int l_get_block_x(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_y(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_z(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->rotation()];
|
||||
return lua_pushivec3(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_player_pos(lua_State* L) {
|
||||
glm::vec3 pos = scripting::level->player->hitbox->position;
|
||||
lua_pushnumber(L, pos.x);
|
||||
|
|
@ -149,6 +99,7 @@ int l_set_player_pos(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// old functions, not recommended to use
|
||||
int l_get_block_states(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
|
|
@ -159,41 +110,6 @@ int l_get_block_states(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int l_get_block_user_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4) + VOXEL_USER_BITS_OFFSET;
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
lua_pushinteger(L, 0);
|
||||
return 1;
|
||||
}
|
||||
uint mask = ((1 << bits) - 1) << offset;
|
||||
uint data = (vox->states & mask) >> offset;
|
||||
lua_pushinteger(L, data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block_user_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4) + VOXEL_USER_BITS_OFFSET;
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
uint mask = (1 << bits) - 1;
|
||||
int value = lua_tointeger(L, 6) & mask;
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
vox->states = (vox->states & (~mask)) | (value << offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_is_replaceable_at(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
|
|
@ -204,6 +120,172 @@ int l_is_replaceable_at(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int l_get_block_dir(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int states = vox->getDir();
|
||||
lua_pushinteger(L, states);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_dir(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
s = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setDir(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_sig(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
bool sig = vox->getSig();
|
||||
lua_pushboolean(L, sig);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_sig(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
bool s = lua_toboolean(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setSig(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_custom_state(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
i = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
bool state = vox->getCustomState(i);
|
||||
lua_pushboolean(L, state);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_state(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
i = lua_tointeger(L, 4);
|
||||
bool s = lua_toboolean(L, 5);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setCustomState(i, s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_custom_value(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
int state = vox->getCustomValue();
|
||||
lua_pushinteger(L, state);
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_value(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1),
|
||||
y = lua_tointeger(L, 2),
|
||||
z = lua_tointeger(L, 3),
|
||||
v = lua_tointeger(L, 4);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
vox->setCustomValue(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// for specific modes
|
||||
int l_get_block_custom_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4);
|
||||
int bits = lua_tointeger(L, 5);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr)
|
||||
lua_pushinteger(L, 0);
|
||||
else
|
||||
lua_pushinteger(L, vox->getCustomBits(offset, bits));
|
||||
return 1;
|
||||
}
|
||||
int l_set_block_custom_bits(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
int offset = lua_tointeger(L, 4);
|
||||
int bits = lua_tointeger(L, 5);
|
||||
int value = lua_tointeger(L, 6);
|
||||
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox != nullptr)
|
||||
vox->setCustomBits(offset, bits, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
lua_pushinteger(L, z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int l_get_block_x(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
int l_get_block_y(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
int l_get_block_z(lua_State* L) {
|
||||
int x = lua_tointeger(L, 1);
|
||||
int y = lua_tointeger(L, 2);
|
||||
int z = lua_tointeger(L, 3);
|
||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
}
|
||||
const Block* def = scripting::level->content->indices->getBlockDef(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua_pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->getDir()];
|
||||
return lua_pushivec3(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
|
||||
lua_setglobal(L, NAME))
|
||||
|
||||
|
|
@ -222,7 +304,20 @@ void apilua::create_funcs(lua_State* L) {
|
|||
lua_addfunc(L, l_set_player_pos, "set_player_pos");
|
||||
lua_addfunc(L, l_get_player_rot, "get_player_rot");
|
||||
lua_addfunc(L, l_set_player_rot, "set_player_rot");
|
||||
lua_addfunc(L, l_get_block_states, "get_block_states");
|
||||
lua_addfunc(L, l_get_block_user_bits, "get_block_user_bits");
|
||||
lua_addfunc(L, l_set_block_user_bits, "set_block_user_bits");
|
||||
|
||||
lua_addfunc(L, l_get_block_states, "get_block_states"); // old function
|
||||
|
||||
lua_addfunc(L, l_get_block_dir, "get_block_dir");
|
||||
lua_addfunc(L, l_set_block_dir, "set_block_dir");
|
||||
lua_addfunc(L, l_get_block_custom_state, "get_block_custom_state");
|
||||
lua_addfunc(L, l_set_block_custom_state, "set_block_custom_state");
|
||||
lua_addfunc(L, l_get_block_custom_value, "get_block_custom_value");
|
||||
lua_addfunc(L, l_set_block_custom_value, "set_block_custom_value");
|
||||
lua_addfunc(L, l_get_block_sig, "get_block_sig");
|
||||
lua_addfunc(L, l_set_block_sig, "set_block_sig");
|
||||
lua_addfunc(L, l_get_block_x, "get_block_X");
|
||||
lua_addfunc(L, l_get_block_y, "get_block_Y");
|
||||
lua_addfunc(L, l_get_block_z, "get_block_Z");
|
||||
lua_addfunc(L, l_get_block_custom_bits, "get_block_custom_bits");
|
||||
lua_addfunc(L, l_set_block_custom_bits, "set_block_custom_bits");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
#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 uint16_t blockid_t;
|
||||
typedef uint16_t blockstate_t;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ std::wstring util::rfill(std::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;
|
||||
|
|
@ -71,7 +71,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)) {
|
||||
|
|
@ -101,7 +101,7 @@ std::string util::wstr2str_utf8(const std::wstring ws) {
|
|||
std::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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ Chunk* Chunk::clone() const {
|
|||
|
||||
Total size: (CHUNK_VOL * 4) bytes
|
||||
*/
|
||||
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 >> 8;
|
||||
buffer[CHUNK_VOL+i] = voxels[i].id & 0xFF;
|
||||
|
|
@ -85,18 +85,19 @@ ubyte* Chunk::encode() const {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @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];
|
||||
|
||||
ubyte bid1 = data[i];
|
||||
ubyte bid2 = data[CHUNK_VOL + i];
|
||||
u_char8 bid1 = data[i];
|
||||
u_char8 bid2 = data[CHUNK_VOL + i];
|
||||
|
||||
ubyte bst1 = data[CHUNK_VOL*2 + i];
|
||||
ubyte bst2 = data[CHUNK_VOL*3 + i];
|
||||
u_char8 bst1 = data[CHUNK_VOL*2 + i];
|
||||
u_char8 bst2 = data[CHUNK_VOL*3 + i];
|
||||
|
||||
vox.id = (blockid_t(bid1) << 8) | (blockid_t(bid2));
|
||||
vox.states = (blockstate_t(bst1) << 8) | (blockstate_t(bst2));
|
||||
|
|
@ -107,7 +108,7 @@ bool Chunk::decode(ubyte* data) {
|
|||
/*
|
||||
* Convert chunk voxels data from 16 bit to 32 bit
|
||||
*/
|
||||
void Chunk::fromOld(ubyte* data) {
|
||||
void Chunk::fromOld(u_char8* data) {
|
||||
for (size_t i = 0; i < CHUNK_VOL; i++) {
|
||||
data[i + CHUNK_VOL*3] = data[i + CHUNK_VOL];
|
||||
data[i + CHUNK_VOL] = data[i];
|
||||
|
|
@ -116,7 +117,7 @@ void Chunk::fromOld(ubyte* data) {
|
|||
}
|
||||
}
|
||||
|
||||
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++) {
|
||||
// see encode method to understand what the hell is going on here
|
||||
blockid_t id = ((blockid_t(data[i]) << 8) |
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ 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 fromOld(ubyte* data);
|
||||
static void convert(ubyte* data, const ContentLUT* lut);
|
||||
static void fromOld(u_char8* data);
|
||||
static void convert(u_char8* data, const ContentLUT* lut);
|
||||
};
|
||||
|
||||
#endif /* VOXELS_CHUNK_H_ */
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ const AABB* Chunks::isObstacleAt(float x, float y, float z){
|
|||
const Block* def = contentIds->getBlockDef(v->id);
|
||||
if (def->obstacle) {
|
||||
const AABB& hitbox = def->rotatable
|
||||
? def->rt.hitboxes[v->rotation()]
|
||||
? def->rt.hitboxes[v->getDir()]
|
||||
: def->hitbox;
|
||||
if (def->rt.solid) {
|
||||
return &hitbox;
|
||||
|
|
@ -109,7 +109,7 @@ bool Chunks::isObstacleBlock(int x, int y, int z) {
|
|||
return contentIds->getBlockDef(v->id)->obstacle;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -163,7 +163,7 @@ Chunk* Chunks::getChunk(int x, int z){
|
|||
return chunks[z * w + x].get();
|
||||
}
|
||||
|
||||
void Chunks::set(int x, int y, int z, int id, uint8_t states){
|
||||
void Chunks::set(int x, int y, int z, voxel voxel) {
|
||||
if (y < 0 || y >= CHUNK_H)
|
||||
return;
|
||||
x -= ox * CHUNK_W;
|
||||
|
|
@ -177,14 +177,14 @@ void Chunks::set(int x, int y, int z, int id, uint8_t states){
|
|||
return;
|
||||
int lx = x - cx * CHUNK_W;
|
||||
int lz = z - cz * CHUNK_D;
|
||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = id;
|
||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].states = states;
|
||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = voxel.id;
|
||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].states = voxel.states;
|
||||
chunk->setUnsaved(true);
|
||||
chunk->setModified(true);
|
||||
|
||||
if (y < chunk->bottom) chunk->bottom = y;
|
||||
else if (y + 1 > chunk->top) chunk->top = y + 1;
|
||||
else if (id == 0) chunk->updateHeights();
|
||||
else if (voxel.id == 0) chunk->updateHeights();
|
||||
|
||||
if (lx == 0 && (chunk = getChunk(cx+ox-1, cz+oz)))
|
||||
chunk->setModified(true);
|
||||
|
|
@ -251,7 +251,7 @@ voxel* Chunks::rayCast(vec3 start,
|
|||
|
||||
if (!def->rt.solid) {
|
||||
const AABB& box = def->rotatable
|
||||
? def->rt.hitboxes[voxel->rotation()]
|
||||
? def->rt.hitboxes[voxel->getDir()]
|
||||
: def->hitbox;
|
||||
scalar_t distance;
|
||||
Ray ray(start, dir);
|
||||
|
|
@ -349,7 +349,7 @@ vec3 Chunks::rayCastToObstacle(vec3 start, vec3 dir, float maxDist) {
|
|||
if (def->obstacle) {
|
||||
if (!def->rt.solid) {
|
||||
const AABB& box = def->rotatable
|
||||
? def->rt.hitboxes[voxel->rotation()]
|
||||
? def->rt.hitboxes[voxel->getDir()]
|
||||
: def->hitbox;
|
||||
scalar_t distance;
|
||||
ivec3 norm;
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ 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);
|
||||
void set(int x, int y, int z, int id, uint8_t states);
|
||||
u_char8 getLight(int x, int y, int z, int channel);
|
||||
void set(int x, int y, int z, voxel voxel);
|
||||
|
||||
voxel* rayCast(glm::vec3 start,
|
||||
glm::vec3 dir,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -56,7 +60,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||
|
||||
auto chunk = std::make_shared<Chunk>(x, z);
|
||||
store(chunk);
|
||||
std::unique_ptr<ubyte[]> data(world->wfile->getChunk(chunk->x, chunk->z));
|
||||
std::unique_ptr<u_char8[]> data(world->wfile->getChunk(chunk->x, chunk->z));
|
||||
if (data) {
|
||||
chunk->decode(data.get());
|
||||
chunk->setLoaded(true);
|
||||
|
|
@ -97,7 +101,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++) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,28 +3,127 @@
|
|||
|
||||
#include "../typedefs.h"
|
||||
|
||||
const int BLOCK_DIR_NORTH = 0x0;
|
||||
const int BLOCK_DIR_WEST = 0x1;
|
||||
const int BLOCK_DIR_SOUTH = 0x2;
|
||||
const int BLOCK_DIR_EAST = 0x3;
|
||||
const int BLOCK_DIR_UP = 0x4;
|
||||
const int BLOCK_DIR_DOWN = 0x5;
|
||||
const u_int32 BLOCK_DIR_NORTH = 0x0;
|
||||
const u_int32 BLOCK_DIR_WEST = 0x1;
|
||||
const u_int32 BLOCK_DIR_SOUTH = 0x2;
|
||||
const u_int32 BLOCK_DIR_EAST = 0x3;
|
||||
const u_int32 BLOCK_DIR_UP = 0x4;
|
||||
const u_int32 BLOCK_DIR_DOWN = 0x5;
|
||||
|
||||
|
||||
const u_int32 BLOCK_DIR_MASK = 0b111;
|
||||
const u_int32 BLOCK_DIR_OFFSET = 0x0;
|
||||
|
||||
const u_int32 BLOCK_SIG_MASK = 0b1;
|
||||
const u_int32 BLOCK_SIG_OFFSET = 0x3;
|
||||
|
||||
const u_int32 BLOCK_VARIANT_MASK = 0b1111;
|
||||
const u_int32 BLOCK_VARIANT_OFFSET = 0x4;
|
||||
|
||||
const u_int32 BLOCK_BITS_MASK = 0b11111111;
|
||||
const u_int32 BLOCK_BITS_OFFSET = 0x8;
|
||||
const u_int32 BLOCK_VALUE_MASK = 0b1111;
|
||||
const u_int32 BLOCK_VALUE_OFFSET = 0x8;
|
||||
const u_int32 BLOCK_STATE_MASK = 0b1111;
|
||||
const u_int32 BLOCK_STATE_OFFSET = 0xC;
|
||||
|
||||
|
||||
//* VOXEL BIT MAP |
|
||||
//*-----------------------------------------------------------------------|
|
||||
//* 0 16 19 20 24 28 32 |
|
||||
//* | | | / | | | |
|
||||
//* |* * * * * * * * * * * * * * * *|* * *|*|* * * *|* * * *|*'*'*'*| |
|
||||
//* id dir / \ variant value 4states |
|
||||
//* |sig| |
|
||||
//*-----------------------------------------------------------------------|
|
||||
|
||||
|
||||
|
||||
//TODO NEW VOXEL BIT MAP |
|
||||
//*-------------------------------------------------------------------------------------------------------|
|
||||
//* 0 16 24 28 29 32 40 48 |
|
||||
//* | | | | / | 8 bool states | value | |
|
||||
//* |# # # # # # # # # # # # # # # #'# # # # # # # #|# # # #|#|# # #|#`#`#`#`#`#`#`#'# # # # # # # #| |
|
||||
//* id sub id variant/ \ dir dynamic bits states |
|
||||
//* |sig| |
|
||||
//*-------------------------------------------------------------------------------------------------------|
|
||||
|
||||
|
||||
// limited to 8 block orientations
|
||||
const int BLOCK_ROT_MASK = 0b0000'0111;
|
||||
// limited to 32 block variants
|
||||
const int BLOCK_VARIANT_MASK = 0b1111'1000;
|
||||
|
||||
struct voxel {
|
||||
blockid_t id;
|
||||
blockstate_t states;
|
||||
u_short16 states;
|
||||
|
||||
inline uint8_t rotation() const {
|
||||
return states & BLOCK_ROT_MASK;
|
||||
inline u_int32 getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
inline uint8_t variant() const {
|
||||
return (states & BLOCK_VARIANT_MASK) >> 3;
|
||||
inline u_char8 getDir() const {
|
||||
return (states >> BLOCK_DIR_OFFSET) & BLOCK_DIR_MASK;
|
||||
}
|
||||
|
||||
inline void setDir(u_char8 dir) {
|
||||
states &= ~BLOCK_DIR_MASK << BLOCK_DIR_OFFSET;
|
||||
states |= dir << BLOCK_DIR_OFFSET;
|
||||
}
|
||||
|
||||
inline u_char8 getVariant() const {
|
||||
return (states >> BLOCK_VALUE_OFFSET) & BLOCK_VARIANT_MASK;
|
||||
}
|
||||
|
||||
inline void setVariant(u_char8 variant) {
|
||||
states &= ~BLOCK_VARIANT_MASK << BLOCK_VARIANT_OFFSET;
|
||||
states |= variant << BLOCK_VARIANT_OFFSET;
|
||||
}
|
||||
|
||||
|
||||
inline u_char8 getCustomBits(u_char8 offset, u_char8 len) const {
|
||||
return (states >> (BLOCK_BITS_OFFSET + offset)) & ((1 << len) - 1);
|
||||
}
|
||||
|
||||
inline void setCustomBits(u_char8 offset, u_char8 len, u_char8 value) {
|
||||
int len_musk = ((1 << len) - 1);
|
||||
offset += BLOCK_BITS_OFFSET;
|
||||
value &= len_musk;
|
||||
states &= ~(len_musk << offset);
|
||||
states |= value << offset;
|
||||
}
|
||||
|
||||
|
||||
// id of the state in range 0 to 3
|
||||
inline bool getCustomState(u_char8 id) const {
|
||||
return states & (1 << id+24);
|
||||
}
|
||||
|
||||
// id of the state in range 0 to 3
|
||||
inline void setCustomState(u_char8 id, bool state) {
|
||||
if (state) {
|
||||
states |= (1 << id+24);
|
||||
} else {
|
||||
states &= ~(1 << id+24);
|
||||
}
|
||||
}
|
||||
|
||||
// can use value in range 0 to 15
|
||||
inline u_char8 getCustomValue() const {
|
||||
return states >> 20;
|
||||
}
|
||||
|
||||
/* if the block has a custom state you
|
||||
can use value in range 0 to 15 else
|
||||
you can use value in range 0 to 255 */
|
||||
inline void setCustomValue(u_char8 value) {
|
||||
states &= ~(0xF << 20);
|
||||
states |= (value << 20);
|
||||
}
|
||||
|
||||
inline bool getSig() const {
|
||||
return (states >> BLOCK_SIG_OFFSET) & BLOCK_SIG_MASK;
|
||||
}
|
||||
|
||||
inline void setSig(bool sig) {
|
||||
states &= ~(BLOCK_SIG_MASK << BLOCK_SIG_OFFSET);
|
||||
states |= sig << BLOCK_SIG_OFFSET;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue