Merge
This commit is contained in:
commit
4599f903e8
@ -11,5 +11,5 @@
|
|||||||
"hitbox": [0.0, 0.0, 0.0, 1.0, 1.0, 0.2],
|
"hitbox": [0.0, 0.0, 0.0, 1.0, 1.0, 0.2],
|
||||||
"light-passing": true,
|
"light-passing": true,
|
||||||
"sky-light-passing": true,
|
"sky-light-passing": true,
|
||||||
"rotation": "pipe"
|
"rotation": "pane"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,20 +27,14 @@ Content* ContentBuilder::build() {
|
|||||||
// Generating runtime info
|
// Generating runtime info
|
||||||
def->rt.id = blockDefsIndices.size();
|
def->rt.id = blockDefsIndices.size();
|
||||||
def->rt.emissive = *((uint32_t*)def->emission);
|
def->rt.emissive = *((uint32_t*)def->emission);
|
||||||
|
def->rt.solid = def->model == BlockModel::block;
|
||||||
// building hitbox grid 3d for raycasts
|
|
||||||
const AABB& hitbox = def->hitbox;
|
if (def->rotatable) {
|
||||||
for (uint gy = 0; gy < BLOCK_AABB_GRID; gy++) {
|
const AABB& hitbox = def->hitbox;
|
||||||
for (uint gz = 0; gz < BLOCK_AABB_GRID; gz++) {
|
for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) {
|
||||||
for (uint gx = 0; gx < BLOCK_AABB_GRID; gx++) {
|
AABB aabb = hitbox;
|
||||||
float x = gx / float(BLOCK_AABB_GRID);
|
def->rotations.variants[i].transform(aabb);
|
||||||
float y = gy / float(BLOCK_AABB_GRID);
|
def->rt.hitboxes[i] = aabb;
|
||||||
float z = gz / float(BLOCK_AABB_GRID);
|
|
||||||
bool flag = hitbox.inside({x, y, z});
|
|
||||||
if (!flag)
|
|
||||||
def->rt.solid = false;
|
|
||||||
def->rt.hitboxGrid[gy][gz][gx] = flag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +42,8 @@ Content* ContentBuilder::build() {
|
|||||||
if (groups->find(def->drawGroup) == groups->end()) {
|
if (groups->find(def->drawGroup) == groups->end()) {
|
||||||
groups->insert(def->drawGroup);
|
groups->insert(def->drawGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
||||||
return new Content(indices, groups, blockDefs);
|
return new Content(indices, groups, blockDefs);
|
||||||
|
|||||||
@ -59,6 +59,8 @@ Block* ContentLoader::loadBlock(string name, path file) {
|
|||||||
def->rotatable = profile != "none";
|
def->rotatable = profile != "none";
|
||||||
if (profile == "pipe") {
|
if (profile == "pipe") {
|
||||||
def->rotations = BlockRotProfile::PIPE;
|
def->rotations = BlockRotProfile::PIPE;
|
||||||
|
} else if (profile == "pane") {
|
||||||
|
def->rotations = BlockRotProfile::PANE;
|
||||||
} else if (profile != "none") {
|
} else if (profile != "none") {
|
||||||
cerr << "unknown rotation profile " << profile << endl;
|
cerr << "unknown rotation profile " << profile << endl;
|
||||||
def->rotatable = false;
|
def->rotatable = false;
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
const int BLOCK_AIR = 0;
|
const int BLOCK_AIR = 0;
|
||||||
|
|
||||||
|
const std::string TEXTURE_NOTFOUND = "notfound";
|
||||||
|
|
||||||
const std::string BIND_MOVE_FORWARD = "movement.forward";
|
const std::string BIND_MOVE_FORWARD = "movement.forward";
|
||||||
const std::string BIND_MOVE_BACK = "movement.back";
|
const std::string BIND_MOVE_BACK = "movement.back";
|
||||||
const std::string BIND_MOVE_LEFT = "movement.left";
|
const std::string BIND_MOVE_LEFT = "movement.left";
|
||||||
|
|||||||
@ -128,7 +128,7 @@ void WorldRenderer::drawChunks(Chunks* chunks,
|
|||||||
void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
|
void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
|
||||||
EngineSettings& settings = engine->getSettings();
|
EngineSettings& settings = engine->getSettings();
|
||||||
skybox->refresh(level->world->daytime,
|
skybox->refresh(level->world->daytime,
|
||||||
fmax(1.0f, 10.0f/(settings.chunks.loadDistance-2)), 4);
|
fmax(1.0f, 10.0f/(settings.chunks.loadDistance-2))+fog*2.0f, 4);
|
||||||
|
|
||||||
const Content* content = level->content;
|
const Content* content = level->content;
|
||||||
const ContentIndices* contentIds = content->indices;
|
const ContentIndices* contentIds = content->indices;
|
||||||
@ -290,4 +290,6 @@ void WorldRenderer::drawBorders(int sx, int sy, int sz, int ex, int ey, int ez)
|
|||||||
sx, i, sz, 0, 0.8f, 0, 1);
|
sx, i, sz, 0, 0.8f, 0, 1);
|
||||||
}
|
}
|
||||||
lineBatch->render();
|
lineBatch->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float WorldRenderer::fog = 0.0f;
|
||||||
@ -40,6 +40,8 @@ public:
|
|||||||
void draw(const GfxContext& context, Camera* camera);
|
void draw(const GfxContext& context, Camera* camera);
|
||||||
void drawDebug(const GfxContext& context, Camera* camera);
|
void drawDebug(const GfxContext& context, Camera* camera);
|
||||||
void drawBorders(int sx, int sy, int sz, int ex, int ey, int ez);
|
void drawBorders(int sx, int sy, int sz, int ex, int ey, int ez);
|
||||||
|
|
||||||
|
static float fog;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -214,8 +214,17 @@ void InputBindBox::keyPressed(int key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================ TrackBar ==================================
|
// ================================ TrackBar ==================================
|
||||||
TrackBar::TrackBar(double min, double max, double value, double step, int trackWidth)
|
TrackBar::TrackBar(double min,
|
||||||
: UINode(vec2(), vec2(32)), min(min), max(max), value(value), step(step), trackWidth(trackWidth) {
|
double max,
|
||||||
|
double value,
|
||||||
|
double step,
|
||||||
|
int trackWidth)
|
||||||
|
: UINode(vec2(), vec2(26)),
|
||||||
|
min(min),
|
||||||
|
max(max),
|
||||||
|
value(value),
|
||||||
|
step(step),
|
||||||
|
trackWidth(trackWidth) {
|
||||||
color(vec4(0.f, 0.f, 0.f, 0.4f));
|
color(vec4(0.f, 0.f, 0.f, 0.4f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +241,8 @@ void TrackBar::draw(Batch2D* batch, Assets* assets) {
|
|||||||
float t = (value - min) / (max-min+trackWidth*step);
|
float t = (value - min) / (max-min+trackWidth*step);
|
||||||
|
|
||||||
batch->color = trackColor;
|
batch->color = trackColor;
|
||||||
batch->rect(coord.x + width * t, coord.y, size_.x * (trackWidth / (max-min+trackWidth*step) * step), size_.y);
|
int actualWidth = size_.x * (trackWidth / (max-min+trackWidth*step) * step);
|
||||||
|
batch->rect(coord.x + width * t, coord.y, actualWidth, size_.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackBar::supplier(doublesupplier supplier) {
|
void TrackBar::supplier(doublesupplier supplier) {
|
||||||
|
|||||||
@ -56,14 +56,12 @@ inline Label* create_label(gui::wstringsupplier supplier) {
|
|||||||
|
|
||||||
HudRenderer::HudRenderer(Engine* engine,
|
HudRenderer::HudRenderer(Engine* engine,
|
||||||
Level* level,
|
Level* level,
|
||||||
const ContentGfxCache* cache,
|
const ContentGfxCache* cache)
|
||||||
WorldRenderer* renderer)
|
|
||||||
: level(level),
|
: level(level),
|
||||||
assets(engine->getAssets()),
|
assets(engine->getAssets()),
|
||||||
batch(new Batch2D(1024)),
|
batch(new Batch2D(1024)),
|
||||||
gui(engine->getGUI()),
|
gui(engine->getGUI()),
|
||||||
cache(cache),
|
cache(cache) {
|
||||||
renderer(renderer) {
|
|
||||||
auto menu = gui->getMenu();
|
auto menu = gui->getMenu();
|
||||||
blocksPreview = new BlocksPreview(assets->getShader("ui3d"),
|
blocksPreview = new BlocksPreview(assets->getShader("ui3d"),
|
||||||
assets->getAtlas("blocks"),
|
assets->getAtlas("blocks"),
|
||||||
@ -160,6 +158,16 @@ HudRenderer::HudRenderer(Engine* engine,
|
|||||||
});
|
});
|
||||||
panel->add(bar);
|
panel->add(bar);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
TrackBar* bar = new TrackBar(0.0f, 1.0f, 0.0f, 0.005f, 8);
|
||||||
|
bar->supplier([=]() {
|
||||||
|
return WorldRenderer::fog;
|
||||||
|
});
|
||||||
|
bar->consumer([=](double val) {
|
||||||
|
WorldRenderer::fog = val;
|
||||||
|
});
|
||||||
|
panel->add(bar);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f);
|
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f);
|
||||||
checkpanel->color(vec4(0.0f));
|
checkpanel->color(vec4(0.0f));
|
||||||
|
|||||||
@ -42,13 +42,10 @@ class HudRenderer {
|
|||||||
std::shared_ptr<gui::UINode> debugPanel;
|
std::shared_ptr<gui::UINode> debugPanel;
|
||||||
gui::GUI* gui;
|
gui::GUI* gui;
|
||||||
const ContentGfxCache* const cache;
|
const ContentGfxCache* const cache;
|
||||||
WorldRenderer* renderer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HudRenderer(Engine* engine,
|
HudRenderer(Engine* engine,
|
||||||
Level* level,
|
Level* level,
|
||||||
const ContentGfxCache* cache,
|
const ContentGfxCache* cache);
|
||||||
WorldRenderer* renderer);
|
|
||||||
~HudRenderer();
|
~HudRenderer();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@ -96,7 +96,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level)
|
|||||||
controller = new LevelController(settings, level);
|
controller = new LevelController(settings, level);
|
||||||
cache = new ContentGfxCache(level->content, engine->getAssets());
|
cache = new ContentGfxCache(level->content, engine->getAssets());
|
||||||
worldRenderer = new WorldRenderer(engine, level, cache);
|
worldRenderer = new WorldRenderer(engine, level, cache);
|
||||||
hud = new HudRenderer(engine, level, cache, worldRenderer);
|
hud = new HudRenderer(engine, level, cache);
|
||||||
backlight = settings.graphics.backlight;
|
backlight = settings.graphics.backlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,9 +126,9 @@ void BlocksRenderer::face(const ivec3& coord,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vec3 sunVector = vec3(0.431934f, 0.863868f, 0.259161f);
|
const vec3 sunVector = vec3(0.411934f, 0.863868f, 0.279161f);
|
||||||
float d = glm::dot(vec3(axisZ.x, axisZ.y, axisZ.z), sunVector);
|
float d = glm::dot(vec3(axisZ.x, axisZ.y, axisZ.z), sunVector);
|
||||||
d = 0.75f + d*0.25f;
|
d = 0.7f + d*0.3f;
|
||||||
|
|
||||||
vec4 tint(d);
|
vec4 tint(d);
|
||||||
|
|
||||||
@ -251,21 +251,18 @@ void BlocksRenderer::blockCubeShaded(const ivec3& icoord,
|
|||||||
coord += orient.fix;
|
coord += orient.fix;
|
||||||
loff -= orient.fix;
|
loff -= orient.fix;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 fX(X);
|
|
||||||
vec3 fY(Y);
|
|
||||||
vec3 fZ(Z);
|
vec3 fZ(Z);
|
||||||
|
|
||||||
vec3 local = offset.x*vec3(X)+offset.y*vec3(Y)+offset.z*vec3(-Z);
|
vec3 local = offset.x*vec3(X)+offset.y*vec3(Y)+offset.z*-fZ;
|
||||||
//local -= loff;
|
|
||||||
face(coord, X, Y, Z, Z+loff, local-size.z*fZ, size.x, size.y, size.z, texfaces[5]);
|
face(coord, X, Y, Z, Z+loff, local-size.z*fZ, size.x, size.y, size.z, texfaces[5]);
|
||||||
face(coord+X, -X, Y, -Z, Z-Z-X+loff, local-size.z*fZ, size.x, size.y, 0.0f, texfaces[4]);
|
face(coord+X, -X, Y, -Z, Z-Z-X+loff, local-size.z*fZ, size.x, size.y, 0.0f, texfaces[4]);
|
||||||
|
|
||||||
face(coord+Y, X, -Z, Y, Y-Y+loff, local, size.x, size.z, 0.0f, texfaces[3]); //;
|
face(coord+Y, X, -Z, Y, Y-Y+loff, local, size.x, size.z, 0.0f, texfaces[3]);
|
||||||
face(coord+X, -X, -Z, -Y, -Y+Z+loff, local, size.x, size.z, 0.0f, texfaces[2]); //;
|
face(coord+X, -X, -Z, -Y, -X-Y+loff, local, size.x, size.z, 0.0f, texfaces[2]);
|
||||||
|
|
||||||
face(coord+X, -Z, Y, X, X-X+loff, local, size.z, size.y, 0.0f, texfaces[1]); //;
|
face(coord+X, -Z, Y, X, X-X+loff, local, size.z, size.y, 0.0f, texfaces[1]);
|
||||||
face(coord+Y, -Z, -Y, -X, -X+Z+loff, local, size.z, size.y, 0.0f, texfaces[0]); //;
|
face(coord+Y, -Z, -Y, -X, -X-Y+loff, local, size.z, size.y, 0.0f, texfaces[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fastest solid shaded blocks render method */
|
/* Fastest solid shaded blocks render method */
|
||||||
@ -372,7 +369,6 @@ vec4 BlocksRenderer::pickSoftLight(float x, float y, float z,
|
|||||||
return pickSoftLight({int(round(x)), int(round(y)), int(round(z))}, right, up);
|
return pickSoftLight({int(round(x)), int(round(y)), int(round(z))}, right, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
void BlocksRenderer::render(const voxel* voxels) {
|
void BlocksRenderer::render(const voxel* voxels) {
|
||||||
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
||||||
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
||||||
@ -410,14 +406,9 @@ void BlocksRenderer::render(const voxel* voxels) {
|
|||||||
AABB hitbox = def.hitbox;
|
AABB hitbox = def.hitbox;
|
||||||
hitbox.a = vec3(1.0f)-hitbox.a;
|
hitbox.a = vec3(1.0f)-hitbox.a;
|
||||||
hitbox.b = vec3(1.0f)-hitbox.b;
|
hitbox.b = vec3(1.0f)-hitbox.b;
|
||||||
std::cout << hitbox.a.x << " " << hitbox.a.y << " " << hitbox.a.z << " --- ";
|
|
||||||
std::cout << hitbox.b.x << " " << hitbox.b.y << " " << hitbox.b.z << std::endl;
|
|
||||||
|
|
||||||
vec3 size = hitbox.size();
|
vec3 size = hitbox.size();
|
||||||
|
|
||||||
std::cout << "s " << size.x << " " << size.y << " " << size.z << std::endl;
|
|
||||||
vec3 off = hitbox.min();
|
vec3 off = hitbox.min();
|
||||||
std::cout << "m " << off.x << " " << off.y << " " << off.z << std::endl;
|
|
||||||
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.states);
|
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.states);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ const float CROUCH_SHIFT_Y = -0.2f;
|
|||||||
|
|
||||||
using glm::vec2;
|
using glm::vec2;
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
CameraControl::CameraControl(Player* player, const CameraSettings& settings)
|
CameraControl::CameraControl(Player* player, const CameraSettings& settings)
|
||||||
: player(player),
|
: player(player),
|
||||||
@ -218,13 +219,29 @@ void PlayerController::updateInteraction(){
|
|||||||
int z = (int)iend.z;
|
int z = (int)iend.z;
|
||||||
uint8_t states = 0;
|
uint8_t states = 0;
|
||||||
|
|
||||||
if (contentIds->getBlockDef(player->choosenBlock)->rotatable){
|
Block* def = contentIds->getBlockDef(player->choosenBlock);
|
||||||
if (norm.x > 0) states = BLOCK_DIR_PX;
|
if (def->rotatable){
|
||||||
else if (norm.x < 0) states = BLOCK_DIR_MX;
|
const string& name = def->rotations.name;
|
||||||
else if (norm.y > 0) states = BLOCK_DIR_PY;
|
if (name == "pipe") {
|
||||||
else if (norm.y < 0) states = BLOCK_DIR_MY;
|
if (abs(norm.x) > abs(norm.z)){
|
||||||
else if (norm.z > 0) states = BLOCK_DIR_PZ;
|
if (abs(norm.x) > abs(norm.y)) states = BLOCK_DIR_X;
|
||||||
else if (norm.z < 0) states = BLOCK_DIR_MZ;
|
if (abs(norm.x) < abs(norm.y)) states = BLOCK_DIR_Y;
|
||||||
|
}
|
||||||
|
if (abs(norm.x) < abs(norm.z)){
|
||||||
|
if (abs(norm.z) > abs(norm.y)) states = BLOCK_DIR_Z;
|
||||||
|
if (abs(norm.z) < abs(norm.y)) states = BLOCK_DIR_Y;
|
||||||
|
}
|
||||||
|
} else if (name == "pane") {
|
||||||
|
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 (abs(vec.x) < abs(vec.z)){
|
||||||
|
if (vec.z > 0.0f) states = BLOCK_DIR_SOUTH;
|
||||||
|
if (vec.z < 0.0f) states = BLOCK_DIR_NORTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Block* block = contentIds->getBlockDef(vox->id);
|
Block* block = contentIds->getBlockDef(vox->id);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
|
|
||||||
|
#include "../core_defs.h"
|
||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
|
|
||||||
void CoordSystem::transform(AABB& aabb) {
|
void CoordSystem::transform(AABB& aabb) {
|
||||||
@ -12,7 +14,7 @@ void CoordSystem::transform(AABB& aabb) {
|
|||||||
aabb.b += fix2;
|
aabb.b += fix2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockRotProfile BlockRotProfile::PIPE {{
|
const BlockRotProfile BlockRotProfile::PIPE {"pipe", {
|
||||||
// Vertical
|
// Vertical
|
||||||
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}},
|
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||||
// X-Aligned
|
// 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}},
|
{{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)
|
Block::Block(std::string name)
|
||||||
: name(name),
|
: name(name),
|
||||||
textureFaces {"notfound","notfound","notfound",
|
textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,
|
||||||
"notfound","notfound","notfound",} {
|
TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,} {
|
||||||
rotations = BlockRotProfile::PIPE;
|
rotations = BlockRotProfile::PIPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::Block(std::string name, std::string texture) : name(name),
|
Block::Block(std::string name, std::string texture) : name(name),
|
||||||
textureFaces{texture,texture,texture,texture,texture,texture} {
|
textureFaces{texture,texture,texture,texture,texture,texture} {
|
||||||
|
rotations = BlockRotProfile::PIPE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,12 +28,14 @@ struct CoordSystem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BlockRotProfile {
|
struct BlockRotProfile {
|
||||||
CoordSystem variants[16];
|
static const int MAX_COUNT = 16;
|
||||||
|
std::string name;
|
||||||
|
CoordSystem variants[MAX_COUNT];
|
||||||
|
|
||||||
/* Wood logs, pillars, pipes
|
/* Wood logs, pillars, pipes */
|
||||||
3 orientations supported
|
|
||||||
*/
|
|
||||||
static const BlockRotProfile PIPE;
|
static const BlockRotProfile PIPE;
|
||||||
|
/* Doors, signs and other panes */
|
||||||
|
static const BlockRotProfile PANE;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BlockModel {
|
enum class BlockModel {
|
||||||
@ -65,7 +67,7 @@ public:
|
|||||||
blockid_t id;
|
blockid_t id;
|
||||||
bool solid = true;
|
bool solid = true;
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
bool hitboxGrid[BLOCK_AABB_GRID][BLOCK_AABB_GRID][BLOCK_AABB_GRID];
|
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
||||||
} rt;
|
} rt;
|
||||||
|
|
||||||
Block(std::string name);
|
Block(std::string name);
|
||||||
|
|||||||
@ -73,11 +73,14 @@ const AABB* Chunks::isObstacle(float x, float y, float z){
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
const Block* def = contentIds->getBlockDef(v->id);
|
const Block* def = contentIds->getBlockDef(v->id);
|
||||||
if (def->obstacle) {
|
if (def->obstacle) {
|
||||||
|
const AABB& hitbox = def->rotatable
|
||||||
|
? def->rt.hitboxes[v->states & BLOCK_ROT_MASK]
|
||||||
|
: def->hitbox;
|
||||||
if (def->rt.solid) {
|
if (def->rt.solid) {
|
||||||
return &def->hitbox;
|
return &hitbox;
|
||||||
} else {
|
} else {
|
||||||
if (def->hitbox.inside({x - ix, y - iy, z - iz}))
|
if (hitbox.inside({x - ix, y - iy, z - iz}))
|
||||||
return &def->hitbox;
|
return &hitbox;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +225,7 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
// TODO: replace this dumb solution with something better
|
// TODO: replace this dumb solution with something better
|
||||||
if (def && !def->rt.solid) {
|
if (def && !def->rt.solid) {
|
||||||
const int gridSize = BLOCK_AABB_GRID * 2;
|
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;
|
const int subs = gridSize;
|
||||||
iend = vec3(ix, iy, iz);
|
iend = vec3(ix, iy, iz);
|
||||||
end -= iend;
|
end -= iend;
|
||||||
|
|||||||
@ -7,6 +7,11 @@
|
|||||||
#define BLOCK_DIR_Y 0x0
|
#define BLOCK_DIR_Y 0x0
|
||||||
#define BLOCK_DIR_Z 0x2
|
#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
|
// limited to 16 block orientations
|
||||||
const int BLOCK_ROT_MASK = 0xF;
|
const int BLOCK_ROT_MASK = 0xF;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user