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],
|
||||
"light-passing": true,
|
||||
"sky-light-passing": true,
|
||||
"rotation": "pipe"
|
||||
"rotation": "pane"
|
||||
}
|
||||
|
||||
@ -27,20 +27,14 @@ Content* ContentBuilder::build() {
|
||||
// Generating runtime info
|
||||
def->rt.id = blockDefsIndices.size();
|
||||
def->rt.emissive = *((uint32_t*)def->emission);
|
||||
|
||||
// building hitbox grid 3d for raycasts
|
||||
const AABB& hitbox = def->hitbox;
|
||||
for (uint gy = 0; gy < BLOCK_AABB_GRID; gy++) {
|
||||
for (uint gz = 0; gz < BLOCK_AABB_GRID; gz++) {
|
||||
for (uint gx = 0; gx < BLOCK_AABB_GRID; gx++) {
|
||||
float x = gx / float(BLOCK_AABB_GRID);
|
||||
float y = gy / float(BLOCK_AABB_GRID);
|
||||
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;
|
||||
}
|
||||
def->rt.solid = def->model == BlockModel::block;
|
||||
|
||||
if (def->rotatable) {
|
||||
const AABB& hitbox = def->hitbox;
|
||||
for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) {
|
||||
AABB aabb = hitbox;
|
||||
def->rotations.variants[i].transform(aabb);
|
||||
def->rt.hitboxes[i] = aabb;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +42,8 @@ Content* ContentBuilder::build() {
|
||||
if (groups->find(def->drawGroup) == groups->end()) {
|
||||
groups->insert(def->drawGroup);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
||||
return new Content(indices, groups, blockDefs);
|
||||
|
||||
@ -59,6 +59,8 @@ Block* ContentLoader::loadBlock(string name, path file) {
|
||||
def->rotatable = profile != "none";
|
||||
if (profile == "pipe") {
|
||||
def->rotations = BlockRotProfile::PIPE;
|
||||
} else if (profile == "pane") {
|
||||
def->rotations = BlockRotProfile::PANE;
|
||||
} else if (profile != "none") {
|
||||
cerr << "unknown rotation profile " << profile << endl;
|
||||
def->rotatable = false;
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
const int BLOCK_AIR = 0;
|
||||
|
||||
const std::string TEXTURE_NOTFOUND = "notfound";
|
||||
|
||||
const std::string BIND_MOVE_FORWARD = "movement.forward";
|
||||
const std::string BIND_MOVE_BACK = "movement.back";
|
||||
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){
|
||||
EngineSettings& settings = engine->getSettings();
|
||||
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 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);
|
||||
}
|
||||
lineBatch->render();
|
||||
}
|
||||
}
|
||||
|
||||
float WorldRenderer::fog = 0.0f;
|
||||
@ -40,6 +40,8 @@ public:
|
||||
void draw(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);
|
||||
|
||||
static float fog;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -214,8 +214,17 @@ void InputBindBox::keyPressed(int key) {
|
||||
}
|
||||
|
||||
// ================================ TrackBar ==================================
|
||||
TrackBar::TrackBar(double min, double max, double value, double step, int trackWidth)
|
||||
: UINode(vec2(), vec2(32)), min(min), max(max), value(value), step(step), trackWidth(trackWidth) {
|
||||
TrackBar::TrackBar(double min,
|
||||
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));
|
||||
}
|
||||
|
||||
@ -232,7 +241,8 @@ void TrackBar::draw(Batch2D* batch, Assets* assets) {
|
||||
float t = (value - min) / (max-min+trackWidth*step);
|
||||
|
||||
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) {
|
||||
|
||||
@ -56,14 +56,12 @@ inline Label* create_label(gui::wstringsupplier supplier) {
|
||||
|
||||
HudRenderer::HudRenderer(Engine* engine,
|
||||
Level* level,
|
||||
const ContentGfxCache* cache,
|
||||
WorldRenderer* renderer)
|
||||
const ContentGfxCache* cache)
|
||||
: level(level),
|
||||
assets(engine->getAssets()),
|
||||
batch(new Batch2D(1024)),
|
||||
gui(engine->getGUI()),
|
||||
cache(cache),
|
||||
renderer(renderer) {
|
||||
cache(cache) {
|
||||
auto menu = gui->getMenu();
|
||||
blocksPreview = new BlocksPreview(assets->getShader("ui3d"),
|
||||
assets->getAtlas("blocks"),
|
||||
@ -160,6 +158,16 @@ HudRenderer::HudRenderer(Engine* engine,
|
||||
});
|
||||
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);
|
||||
checkpanel->color(vec4(0.0f));
|
||||
|
||||
@ -42,13 +42,10 @@ class HudRenderer {
|
||||
std::shared_ptr<gui::UINode> debugPanel;
|
||||
gui::GUI* gui;
|
||||
const ContentGfxCache* const cache;
|
||||
WorldRenderer* renderer;
|
||||
|
||||
public:
|
||||
HudRenderer(Engine* engine,
|
||||
Level* level,
|
||||
const ContentGfxCache* cache,
|
||||
WorldRenderer* renderer);
|
||||
const ContentGfxCache* cache);
|
||||
~HudRenderer();
|
||||
|
||||
void update();
|
||||
|
||||
@ -96,7 +96,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level)
|
||||
controller = new LevelController(settings, level);
|
||||
cache = new ContentGfxCache(level->content, engine->getAssets());
|
||||
worldRenderer = new WorldRenderer(engine, level, cache);
|
||||
hud = new HudRenderer(engine, level, cache, worldRenderer);
|
||||
hud = new HudRenderer(engine, level, cache);
|
||||
backlight = settings.graphics.backlight;
|
||||
}
|
||||
|
||||
|
||||
@ -126,9 +126,9 @@ void BlocksRenderer::face(const ivec3& coord,
|
||||
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);
|
||||
d = 0.75f + d*0.25f;
|
||||
d = 0.7f + d*0.3f;
|
||||
|
||||
vec4 tint(d);
|
||||
|
||||
@ -251,21 +251,18 @@ void BlocksRenderer::blockCubeShaded(const ivec3& icoord,
|
||||
coord += orient.fix;
|
||||
loff -= orient.fix;
|
||||
}
|
||||
|
||||
vec3 fX(X);
|
||||
vec3 fY(Y);
|
||||
vec3 fZ(Z);
|
||||
|
||||
vec3 local = offset.x*vec3(X)+offset.y*vec3(Y)+offset.z*vec3(-Z);
|
||||
//local -= loff;
|
||||
vec3 local = offset.x*vec3(X)+offset.y*vec3(Y)+offset.z*-fZ;
|
||||
|
||||
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+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+Y, X, -Z, Y, Y-Y+loff, local, size.x, size.z, 0.0f, texfaces[3]);
|
||||
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+Y, -Z, -Y, -X, -X+Z+loff, local, size.z, size.y, 0.0f, texfaces[0]); //;
|
||||
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-Y+loff, local, size.z, size.y, 0.0f, texfaces[0]);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void BlocksRenderer::render(const voxel* voxels) {
|
||||
int begin = chunk->bottom * (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;
|
||||
hitbox.a = vec3(1.0f)-hitbox.a;
|
||||
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();
|
||||
|
||||
std::cout << "s " << size.x << " " << size.y << " " << size.z << std::endl;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ const float CROUCH_SHIFT_Y = -0.2f;
|
||||
|
||||
using glm::vec2;
|
||||
using glm::vec3;
|
||||
using std::string;
|
||||
|
||||
CameraControl::CameraControl(Player* player, const CameraSettings& settings)
|
||||
: player(player),
|
||||
@ -218,13 +219,29 @@ void PlayerController::updateInteraction(){
|
||||
int z = (int)iend.z;
|
||||
uint8_t states = 0;
|
||||
|
||||
if (contentIds->getBlockDef(player->choosenBlock)->rotatable){
|
||||
if (norm.x > 0) states = BLOCK_DIR_PX;
|
||||
else if (norm.x < 0) states = BLOCK_DIR_MX;
|
||||
else if (norm.y > 0) states = BLOCK_DIR_PY;
|
||||
else if (norm.y < 0) states = BLOCK_DIR_MY;
|
||||
else if (norm.z > 0) states = BLOCK_DIR_PZ;
|
||||
else if (norm.z < 0) states = BLOCK_DIR_MZ;
|
||||
Block* def = contentIds->getBlockDef(player->choosenBlock);
|
||||
if (def->rotatable){
|
||||
const string& name = def->rotations.name;
|
||||
if (name == "pipe") {
|
||||
if (abs(norm.x) > abs(norm.z)){
|
||||
if (abs(norm.x) > abs(norm.y)) states = BLOCK_DIR_X;
|
||||
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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user