Merge
This commit is contained in:
+17
-3
@@ -1,5 +1,7 @@
|
||||
#include "Block.h"
|
||||
|
||||
#include "../core_defs.h"
|
||||
|
||||
using glm::vec3;
|
||||
|
||||
void CoordSystem::transform(AABB& aabb) {
|
||||
@@ -12,7 +14,7 @@ void CoordSystem::transform(AABB& aabb) {
|
||||
aabb.b += fix2;
|
||||
}
|
||||
|
||||
const BlockRotProfile BlockRotProfile::PIPE {{
|
||||
const BlockRotProfile BlockRotProfile::PIPE {"pipe", {
|
||||
// Vertical
|
||||
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||
// X-Aligned
|
||||
@@ -21,13 +23,25 @@ const BlockRotProfile BlockRotProfile::PIPE {{
|
||||
{{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, -1}, {0, 1, 0}},
|
||||
}};
|
||||
|
||||
const BlockRotProfile BlockRotProfile::PANE {"pane", {
|
||||
// North
|
||||
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||
// East
|
||||
{{0, 0, -1}, {0, 1, 0}, {1, 0, 0}, {1, 0, 0}, {0, 0, 1}},
|
||||
// South
|
||||
{{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, -1}, {1, 0, 1}},
|
||||
// West
|
||||
{{0, 0, 1}, {0, 1, 0}, {-1, 0, 0}, {0, 0, -1}, {1, 0, 0}},
|
||||
}};
|
||||
|
||||
Block::Block(std::string name)
|
||||
: name(name),
|
||||
textureFaces {"notfound","notfound","notfound",
|
||||
"notfound","notfound","notfound",} {
|
||||
textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,
|
||||
TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,} {
|
||||
rotations = BlockRotProfile::PIPE;
|
||||
}
|
||||
|
||||
Block::Block(std::string name, std::string texture) : name(name),
|
||||
textureFaces{texture,texture,texture,texture,texture,texture} {
|
||||
rotations = BlockRotProfile::PIPE;
|
||||
}
|
||||
|
||||
+7
-5
@@ -28,12 +28,14 @@ struct CoordSystem {
|
||||
};
|
||||
|
||||
struct BlockRotProfile {
|
||||
CoordSystem variants[16];
|
||||
static const int MAX_COUNT = 16;
|
||||
std::string name;
|
||||
CoordSystem variants[MAX_COUNT];
|
||||
|
||||
/* Wood logs, pillars, pipes
|
||||
3 orientations supported
|
||||
*/
|
||||
/* Wood logs, pillars, pipes */
|
||||
static const BlockRotProfile PIPE;
|
||||
/* Doors, signs and other panes */
|
||||
static const BlockRotProfile PANE;
|
||||
};
|
||||
|
||||
enum class BlockModel {
|
||||
@@ -65,7 +67,7 @@ public:
|
||||
blockid_t id;
|
||||
bool solid = true;
|
||||
bool emissive = false;
|
||||
bool hitboxGrid[BLOCK_AABB_GRID][BLOCK_AABB_GRID][BLOCK_AABB_GRID];
|
||||
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
||||
} rt;
|
||||
|
||||
Block(std::string name);
|
||||
|
||||
@@ -73,11 +73,14 @@ const AABB* Chunks::isObstacle(float x, float y, float z){
|
||||
return nullptr;
|
||||
const Block* def = contentIds->getBlockDef(v->id);
|
||||
if (def->obstacle) {
|
||||
const AABB& hitbox = def->rotatable
|
||||
? def->rt.hitboxes[v->states & BLOCK_ROT_MASK]
|
||||
: def->hitbox;
|
||||
if (def->rt.solid) {
|
||||
return &def->hitbox;
|
||||
return &hitbox;
|
||||
} else {
|
||||
if (def->hitbox.inside({x - ix, y - iy, z - iz}))
|
||||
return &def->hitbox;
|
||||
if (hitbox.inside({x - ix, y - iy, z - iz}))
|
||||
return &hitbox;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +225,7 @@ voxel* Chunks::rayCast(vec3 start,
|
||||
// TODO: replace this dumb solution with something better
|
||||
if (def && !def->rt.solid) {
|
||||
const int gridSize = BLOCK_AABB_GRID * 2;
|
||||
const AABB& box = def->hitbox;
|
||||
const AABB& box = def->rotatable ? def->rt.hitboxes[voxel->states & BLOCK_ROT_MASK] : def->hitbox;
|
||||
const int subs = gridSize;
|
||||
iend = vec3(ix, iy, iz);
|
||||
end -= iend;
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
#define BLOCK_DIR_Y 0x0
|
||||
#define BLOCK_DIR_Z 0x2
|
||||
|
||||
const int BLOCK_DIR_NORTH = 0x0;
|
||||
const int BLOCK_DIR_WEST = 0x1;
|
||||
const int BLOCK_DIR_SOUTH = 0x2;
|
||||
const int BLOCK_DIR_EAST = 0x3;
|
||||
|
||||
// limited to 16 block orientations
|
||||
const int BLOCK_ROT_MASK = 0xF;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user