Minor refactor
This commit is contained in:
+4
-1
@@ -5,9 +5,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef unsigned char ubyte;
|
|
||||||
|
// use for bytes arrays
|
||||||
|
typedef uint8_t ubyte;
|
||||||
|
|
||||||
typedef uint8_t blockid_t;
|
typedef uint8_t blockid_t;
|
||||||
|
typedef uint8_t blockstate_t;
|
||||||
typedef uint16_t light_t;
|
typedef uint16_t light_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,22 +14,18 @@
|
|||||||
#include "../lighting/Lightmap.h"
|
#include "../lighting/Lightmap.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
using glm::ivec2;
|
|
||||||
using std::unique_ptr;
|
|
||||||
using std::shared_ptr;
|
|
||||||
|
|
||||||
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunksStorage::~ChunksStorage() {
|
ChunksStorage::~ChunksStorage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::store(shared_ptr<Chunk> chunk) {
|
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
|
||||||
chunksMap[ivec2(chunk->x, chunk->z)] = chunk;
|
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
|
std::shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
|
||||||
auto found = chunksMap.find(ivec2(x, z));
|
auto found = chunksMap.find(glm::ivec2(x, z));
|
||||||
if (found == chunksMap.end()) {
|
if (found == chunksMap.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -37,7 +33,7 @@ shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChunksStorage::remove(int x, int z) {
|
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()) {
|
if (found != chunksMap.end()) {
|
||||||
chunksMap.erase(found->first);
|
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) {
|
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||||
World* world = level->world;
|
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);
|
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) {
|
if (data) {
|
||||||
chunk->decode(data.get());
|
chunk->decode(data.get());
|
||||||
chunk->setLoaded(true);
|
chunk->setLoaded(true);
|
||||||
@@ -100,7 +96,7 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
|||||||
// cw*ch chunks will be scanned
|
// cw*ch chunks will be scanned
|
||||||
for (int cz = scz; cz < scz + ch; cz++) {
|
for (int cz = scz; cz < scz + ch; cz++) {
|
||||||
for (int cx = scx; cx < scx + cw; cx++) {
|
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()) {
|
if (found == chunksMap.end()) {
|
||||||
// no chunk loaded -> filling with BLOCK_VOID
|
// no chunk loaded -> filling with BLOCK_VOID
|
||||||
for (int ly = y; ly < y + h; ly++) {
|
for (int ly = y; ly < y + h; ly++) {
|
||||||
|
|||||||
+2
-2
@@ -17,13 +17,13 @@ const int BLOCK_VARIANT_MASK = 0xF0;
|
|||||||
|
|
||||||
struct voxel {
|
struct voxel {
|
||||||
blockid_t id;
|
blockid_t id;
|
||||||
uint8_t states;
|
blockstate_t states;
|
||||||
|
|
||||||
inline uint8_t rotation() const {
|
inline uint8_t rotation() const {
|
||||||
return states & BLOCK_ROT_MASK;
|
return states & BLOCK_ROT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int8_t variant() const {
|
inline uint8_t variant() const {
|
||||||
return (states & BLOCK_VARIANT_MASK) >> 4;
|
return (states & BLOCK_VARIANT_MASK) >> 4;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user