diff --git a/src/engine.cpp b/src/engine.cpp index a4d46fa1..ca09188b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -52,6 +52,7 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths) auto resdir = paths->getResources(); contentPacks.push_back(ContentPack::read(resdir/path("content/base"))); + contentPacks.push_back(ContentPack::read(resdir / path("content/mcclassic"))); loadContent(); Audio::initialize(); diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 9e11e063..ace6972c 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -125,7 +125,7 @@ HudRenderer::HudRenderer(Engine* engine, TextBox* box = new TextBox(L""); box->textSupplier([this, ax]() { Hitbox* hitbox = this->level->player->hitbox; - return std::to_wstring((int)hitbox->position[ax]); + return std::to_wstring(hitbox->position[ax]); }); box->textConsumer([this, ax](wstring text) { try { diff --git a/src/graphics/BlocksRenderer.cpp b/src/graphics/BlocksRenderer.cpp index 68337b30..8629a184 100644 --- a/src/graphics/BlocksRenderer.cpp +++ b/src/graphics/BlocksRenderer.cpp @@ -139,12 +139,11 @@ void BlocksRenderer::face(const ivec3& coord, index(0, 1, 2, 0, 2, 3); } -void BlocksRenderer::face(const ivec3& coord_, +void BlocksRenderer::face(const vec3& coord, const ivec3& axisX, const ivec3& axisY, const ivec3& axisZ, const ivec3& laxisZ, - const vec3& offset, float width, float height, float depth, @@ -158,8 +157,6 @@ void BlocksRenderer::face(const ivec3& coord_, const vec3 X(axisX); const vec3 Y(axisY); const vec3 Z(axisZ); - - vec3 coord(vec3(coord_) + offset); if (lights) { const vec3 sunVector = vec3(0.431934f, 0.863868f, 0.259161f); @@ -242,17 +239,21 @@ void BlocksRenderer::blockXSprite(int x, int y, int z, /* AABB blocks render method (WIP) */ void BlocksRenderer::blockAABB(const ivec3& icoord, - const vec3& offset, - const vec3& size, - const UVRegion(&texfaces)[6], - const Block* block, ubyte rotation, - bool lights) { + const UVRegion(&texfaces)[6], + const Block* block, ubyte rotation, + bool lights) { + AABB inversedHitbox = block->hitbox; + inversedHitbox.a = vec3(1.0f) - inversedHitbox.a; + inversedHitbox.b = vec3(1.0f) - inversedHitbox.b; + + vec3 size = inversedHitbox.size(); + vec3 offset = inversedHitbox.min(); ivec3 X(1, 0, 0); ivec3 Y(0, 1, 0); ivec3 Z(0, 0, 1); ivec3 loff(0); - ivec3 coord = icoord; + vec3 coord(icoord); if (block->rotatable) { auto& rotations = block->rotations; auto& orient = rotations.variants[rotation]; @@ -267,25 +268,25 @@ void BlocksRenderer::blockAABB(const ivec3& icoord, vec3 fZ(Z); // TODO: simplify this pile of magic calculations and fix 5th arg (laxisZ) - face(coord, X, Y, Z, Z+loff, - (1.0f - offset.x - size.x) * fX - (offset.z + size.z)*fZ, + face(coord + (1.0f - offset.x - size.x) * fX - (offset.z + size.z) * fZ, + X, Y, Z, Z+loff, size.x, size.y, size.z, texfaces[5], lights); // north - face(coord, -X, Y, -Z, Z-Z-X+loff, - (1.0f - offset.x) * fX - (offset.z + size.z) * fZ, + face(coord + (1.0f - offset.x) * fX - (offset.z + size.z) * fZ, + -X, Y, -Z, Z-Z-X+loff, size.x, size.y, 0.0f, texfaces[4], lights); // south - face(coord, X, -Z, Y, Y-Y+loff, - (1.0f - offset.x - size.x) * fX - offset.z * fZ + size.y*fY, + face(coord + (1.0f - offset.x - size.x) * fX - offset.z * fZ + size.y * fY, + X, -Z, Y, Y-Y+loff, size.x, size.z, 0.0f, texfaces[3], lights); // top - face(coord, -X, -Z, -Y, -X-Y+loff, - (1.0f - offset.x) * fX - offset.z * fZ, + face(coord + (1.0f - offset.x) * fX - offset.z * fZ, + -X, -Z, -Y, -X-Y+loff, size.x, size.z, 0.0f, texfaces[2], lights); // bottom - face(coord, -Z, Y, X, X-X+loff, - (1.0f - offset.x) * fX - offset.z * fZ, + face(coord + (1.0f - offset.x) * fX - offset.z * fZ, + -Z, Y, X, X-X+loff, size.z, size.y, 0.0f, texfaces[1], lights); // west - face(coord, Z, Y, -X, -X-Y+loff, - (1.0f - offset.x - size.x) * fX - (offset.z + size.z) * fZ, + face(coord + (1.0f - offset.x - size.x) * fX - (offset.z + size.z) * fZ, + Z, Y, -X, -X-Y+loff, size.z, size.y, 0.0f, texfaces[0], lights); // east } @@ -427,13 +428,7 @@ void BlocksRenderer::render(const voxel* voxels) { break; } case BlockModel::aabb: { - AABB inversedHitbox = def.hitbox; - inversedHitbox.a = vec3(1.0f) - inversedHitbox.a; - inversedHitbox.b = vec3(1.0f) - inversedHitbox.b; - - vec3 size = inversedHitbox.size(); - vec3 off = inversedHitbox.min(); - blockAABB(ivec3(x,y,z), off, size, texfaces, &def, vox.rotation(), !def.rt.emissive); + blockAABB(ivec3(x,y,z), texfaces, &def, vox.rotation(), !def.rt.emissive); break; } default: diff --git a/src/graphics/BlocksRenderer.h b/src/graphics/BlocksRenderer.h index 301a3678..9938c2b6 100644 --- a/src/graphics/BlocksRenderer.h +++ b/src/graphics/BlocksRenderer.h @@ -64,12 +64,11 @@ class BlocksRenderer { const glm::ivec3& laxisZ, const UVRegion& region); - void face(const glm::ivec3& coord, + void face(const glm::vec3& coord, const glm::ivec3& axisX, const glm::ivec3& axisY, const glm::ivec3& axisZ, const glm::ivec3& laxisZ, - const glm::vec3& offset, float width, float height, float depth, @@ -87,9 +86,7 @@ class BlocksRenderer { void blockCube(int x, int y, int z, const UVRegion(&faces)[6], ubyte group); void blockCubeShaded(int x, int y, int z, const UVRegion(&faces)[6], const Block* block, ubyte states); - void blockAABB(const glm::ivec3& coord, - const glm::vec3& offset, - const glm::vec3& size, + void blockAABB(const glm::ivec3& coord, const UVRegion(&faces)[6], const Block* block, ubyte rotation, diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index 8ffec617..389c839b 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -4,6 +4,15 @@ using glm::vec3; +CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ, glm::ivec3 fix) + : axisX(axisX), axisY(axisY), axisZ(axisZ), fix(fix) +{ + fix2 = glm::ivec3(0); + if (isVectorHasNegatives(axisX)) fix2 -= axisX; + if (isVectorHasNegatives(axisY)) fix2 -= axisY; + if (isVectorHasNegatives(axisZ)) fix2 -= axisZ; +} + void CoordSystem::transform(AABB& aabb) { vec3 X(axisX); vec3 Y(axisY); @@ -14,26 +23,26 @@ void CoordSystem::transform(AABB& aabb) { aabb.b += fix2; } -const BlockRotProfile BlockRotProfile::PIPE {"pipe", {//TODO consexpr or init-time fix and fix2 calculations - { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, 0, -1 }, { 0, 1, 0 } }, // North - { { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }, { 1, 0, -1 }, { 1, 1, 0 } }, // East - { { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }, { 1, 0, 0 }, { 1, 1, 1 } }, // South - { { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 0, 0 }, { 0, 1, 1 } }, // West - { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }, // Up - { { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1,-1 }, { 0, 1, 1 } }, // Down +const BlockRotProfile BlockRotProfile::PIPE {"pipe", {//TODO consexpr or init-time fix calculations + { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, 0, -1 }}, // North + { { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }, { 1, 0, -1 }}, // East + { { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }, { 1, 0, 0 }}, // South + { { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 0, 0 }}, // West + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 } }, // Up + { { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1,-1 } }, // Down }}; const BlockRotProfile BlockRotProfile::PANE {"pane", { - { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }, // North - { { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }, { 0, 0, 1 } }, // East - { {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }, { 1, 0,-1 }, { 1, 0, 1 } }, // South - { { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0,-1 }, { 1, 0, 0 } }, // West + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }}, // North + { { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }}, // East + { {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }, { 1, 0,-1 }}, // South + { { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0,-1 }}, // West }}; Block::Block(std::string name) : name(name), textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND, - TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,} { + TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND} { rotations = BlockRotProfile::PIPE; } diff --git a/src/voxels/Block.h b/src/voxels/Block.h index 565bc43b..1dc9e34a 100644 --- a/src/voxels/Block.h +++ b/src/voxels/Block.h @@ -24,7 +24,17 @@ struct CoordSystem { glm::ivec3 fix; glm::ivec3 fix2; + CoordSystem() = default; + CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ, glm::ivec3 fix); + void transform(AABB& aabb); + + static bool CoordSystem::isVectorHasNegatives(glm::ivec3 vec) { + if (vec.x < 0 || vec.y < 0 || vec.z < 0) { + return true; + } + else return false; + } }; struct BlockRotProfile {