Minor refactor

This commit is contained in:
MihailRis 2024-01-03 22:51:48 +03:00
parent 2ad115a2a8
commit e7e2c16ee6
3 changed files with 14 additions and 15 deletions

View File

@ -5,9 +5,12 @@
#include <stdint.h>
typedef unsigned int uint;
typedef unsigned char ubyte;
// use for bytes arrays
typedef uint8_t ubyte;
typedef uint8_t blockid_t;
typedef uint8_t blockstate_t;
typedef uint16_t light_t;
#endif

View File

@ -14,22 +14,18 @@
#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(shared_ptr<Chunk> chunk) {
chunksMap[ivec2(chunk->x, chunk->z)] = chunk;
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
}
shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(ivec2(x, z));
std::shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(glm::ivec2(x, z));
if (found == chunksMap.end()) {
return nullptr;
}
@ -37,7 +33,7 @@ shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
}
void ChunksStorage::remove(int x, int z) {
auto found = chunksMap.find(ivec2(x, z));
auto found = chunksMap.find(glm::ivec2(x, z));
if (found != chunksMap.end()) {
chunksMap.erase(found->first);
}
@ -46,9 +42,9 @@ void ChunksStorage::remove(int x, int z) {
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
World* world = level->world;
auto chunk = shared_ptr<Chunk>(new Chunk(x, z));
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
store(chunk);
unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
std::unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
if (data) {
chunk->decode(data.get());
chunk->setLoaded(true);
@ -100,7 +96,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(ivec2(cx, cz));
auto found = chunksMap.find(glm::ivec2(cx, cz));
if (found == chunksMap.end()) {
// no chunk loaded -> filling with BLOCK_VOID
for (int ly = y; ly < y + h; ly++) {

View File

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