This commit is contained in:
@clasher113
2023-12-05 09:27:00 +02:00
34 changed files with 485 additions and 410 deletions
+19 -7
View File
@@ -1,12 +1,24 @@
#include "Block.h"
BlockRotProfile BlockRotProfile::PIPE {{
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 } }, // BLOCK_DIR_PY
{ { 0,-1, 0 }, { 1, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 } }, // BLOCK_DIR_PX
{ { 1, 0, 0 }, { 0, 0, 1 }, { 0,-1, 0 }, { 0, 0,-1 } }, // BLOCK_DIR_PZ
{ { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0, 1 }, { 1, 0, 0 } }, // BLOCK_DIR_MX
{ {-1, 0, 0 }, { 0,-1, 0 }, { 0, 0, 1 }, { 1, 1, 0 } }, // BLOCK_DIR_MY
{ { 1, 0, 0 }, { 0, 0,-1 }, { 0, 1, 0 }, { 0, 1, 0 } }, // BLOCK_DIR_MZ
using glm::vec3;
void CoordSystem::transform(AABB& aabb) {
vec3 X(axisX);
vec3 Y(axisY);
vec3 Z(axisZ);
aabb.a = X * aabb.a.x + Y * aabb.a.y + Z * aabb.a.z;
aabb.b = X * aabb.b.x + Y * aabb.b.y + Z * aabb.b.z;
aabb.a += fix2;
aabb.b += fix2;
}
const BlockRotProfile BlockRotProfile::PIPE {{
// Vertical
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}},
// X-Aligned
{{0, -1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 0}},
// Z-Aligned
{{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, -1}, {0, 1, 0}},
}};
Block::Block(std::string name)
+11 -8
View File
@@ -7,14 +7,14 @@
#include "../maths/aabb.h"
#include "../typedefs.h"
#define FACE_MX 0
#define FACE_PX 1
#define FACE_MY 2
#define FACE_PY 3
#define FACE_MZ 4
#define FACE_PZ 5
const uint FACE_MX = 0;
const uint FACE_PX = 1;
const uint FACE_MY = 2;
const uint FACE_PY = 3;
const uint FACE_MZ = 4;
const uint FACE_PZ = 5;
#define BLOCK_AABB_GRID 16
const uint BLOCK_AABB_GRID = 16;
struct CoordSystem {
glm::ivec3 axisX;
@@ -22,6 +22,9 @@ struct CoordSystem {
glm::ivec3 axisZ;
// Grid 3d position fix offset (for negative vectors)
glm::ivec3 fix;
glm::ivec3 fix2;
void transform(AABB& aabb);
};
struct BlockRotProfile {
@@ -30,7 +33,7 @@ struct BlockRotProfile {
/* Wood logs, pillars, pipes
3 orientations supported
*/
static BlockRotProfile PIPE;
static const BlockRotProfile PIPE;
};
enum class BlockModel {
+24 -19
View File
@@ -4,11 +4,13 @@
#include <stdlib.h>
#include "../constants.h"
#define CHUNK_MODIFIED 0x1
#define CHUNK_READY 0x2
#define CHUNK_LOADED 0x4
#define CHUNK_LIGHTED 0x8
#define CHUNK_UNSAVED 0x10
struct ChunkFlag{
static const int MODIFIED = 0x1;
static const int READY = 0x2;
static const int LOADED = 0x4;
static const int LIGHTED = 0x8;
static const int UNSAVED = 0x10;
};
#define CHUNK_DATA_LEN (CHUNK_VOL*2)
struct voxel;
@@ -19,10 +21,6 @@ struct RenderData {
size_t size;
};
#define BIT_ON(f,i) do{f|= i;} while(0)
#define BIT_OFF(f,i) do{f&=~(i);} while(0)
#define BITSET(f,i,s) if (s) BIT_ON(f,i); else BIT_OFF(f,i);
class Chunk {
public:
int x, z;
@@ -43,26 +41,33 @@ public:
Chunk* clone() const;
// flags getters/setters below
void SETFLAGS(int mask, bool value){
if (value)
flags |= mask;
else
flags &= ~(mask);
}
inline bool isUnsaved() const {return flags & CHUNK_UNSAVED;}
inline bool isUnsaved() const {return flags & ChunkFlag::UNSAVED;}
inline bool isModified() const {return flags & CHUNK_MODIFIED;}
inline bool isModified() const {return flags & ChunkFlag::MODIFIED;}
inline bool isLighted() const {return flags & CHUNK_LIGHTED;}
inline bool isLighted() const {return flags & ChunkFlag::LIGHTED;}
inline bool isLoaded() const {return flags & CHUNK_LOADED;}
inline bool isLoaded() const {return flags & ChunkFlag::LOADED;}
inline bool isReady() const {return flags & CHUNK_READY;}
inline bool isReady() const {return flags & ChunkFlag::READY;}
inline void setUnsaved(bool flag) {BITSET(flags, CHUNK_UNSAVED, flag);}
inline void setUnsaved(bool newState) {SETFLAGS(ChunkFlag::UNSAVED, newState);}
inline void setModified(bool flag) {BITSET(flags, CHUNK_MODIFIED, flag);}
inline void setModified(bool newState) {SETFLAGS(ChunkFlag::MODIFIED, newState);}
inline void setLoaded(bool flag) {BITSET(flags, CHUNK_LOADED, flag);}
inline void setLoaded(bool newState) {SETFLAGS(ChunkFlag::LOADED, newState);}
inline void setLighted(bool flag) {BITSET(flags, CHUNK_LIGHTED, flag);}
inline void setLighted(bool newState) {SETFLAGS(ChunkFlag::LIGHTED, newState);}
inline void setReady(bool flag) {BITSET(flags, CHUNK_READY, flag);}
inline void setReady(bool newState) {SETFLAGS(ChunkFlag::READY, newState);}
ubyte* encode() const;
bool decode(ubyte* data);
+1 -1
View File
@@ -16,7 +16,7 @@
#include "../maths/voxmaths.h"
#include "../core_defs.h"
#define SEA_LEVEL 55
const int SEA_LEVEL = 55;
class Map2D {
int x, z;
+4 -7
View File
@@ -3,15 +3,12 @@
#include "../typedefs.h"
#define BLOCK_DIR_PX 0x1
#define BLOCK_DIR_PY 0x0
#define BLOCK_DIR_PZ 0x2
#define BLOCK_DIR_MX 0x3
#define BLOCK_DIR_MY 0x4
#define BLOCK_DIR_MZ 0x5
#define BLOCK_DIR_X 0x1
#define BLOCK_DIR_Y 0x0
#define BLOCK_DIR_Z 0x2
// limited to 16 block orientations
#define BLOCK_ROT_MASK 0xF
const int BLOCK_ROT_MASK = 0xF;
struct voxel {
blockid_t id;