diff --git a/src/Game/Objects/Base/Chunk.cpp b/src/Game/Objects/Base/Chunk.cpp index e18b33a..e65b1b5 100644 --- a/src/Game/Objects/Base/Chunk.cpp +++ b/src/Game/Objects/Base/Chunk.cpp @@ -67,19 +67,21 @@ int Chunk::GetBlock(float x, float y, float z) int Chunk::GetHighestBlock(float x, float z) { - int _x = x; - int _z = z; + float _x = x; + float _z = z; glm::vec3 w = WorldToChunk(glm::vec3(x, 0, z)); if (_x >= CHUNK_SIZE || _x < 0) - w.x = _x; + _x = (int)w.x; if (_z >= CHUNK_SIZE || _z < 0) - w.z = _z; + _z = (int)w.z; - _x = w.x; - _z = w.z; + if (_x == 16) + _x = 15; + if (_z == 16) + _z = 15; if (_x >= CHUNK_SIZE) return 0; @@ -95,7 +97,7 @@ int Chunk::GetHighestBlock(float x, float z) for (int y = CHUNK_HEIGHT - 1; y > -1; y--) { - if (myData.bChunk.blocks[_x][_z][y] > 0 && myData.bChunk.blocks[_x][_z][y] != WATER) + if (myData.bChunk.blocks[(int)_x][(int)_z][y] > 0 && myData.bChunk.blocks[(int)_x][(int)_z][y] != WATER) return y; } @@ -669,31 +671,29 @@ subChunk* Chunk::CreateSubChunk(int y) { int type = GetBlock(x, y + 1, z); int type2 = GetBlock(x, y - 1, z); + int type3 = GetBlockInterchunk(x + 1, y, z); + int type4 = GetBlockInterchunk(x - 1, y, z); + int type5 = GetBlockInterchunk(x, y, z + 1); + int type6 = GetBlockInterchunk(x, y, z - 1); if (type <= 0 || (type == WATER || type == GLASS)) isOccluded = false; else if (type2 <= 0 || (type2 == WATER || type2 == GLASS)) isOccluded = false; + else if (type3 <= 0 || (type3 == WATER || type3 == GLASS)) + isOccluded = false; + else if (type4 <= 0 || (type4 == WATER || type4 == GLASS)) + isOccluded = false; + else if (type5 <= 0 || (type5 == WATER || type5 == GLASS)) + isOccluded = false; + else if (type6 <= 0 || (type6 == WATER || type6 == GLASS)) + isOccluded = false; if (!isOccluded) break; } } - int type3 = GetBlockInterchunk(CHUNK_SIZE, y, 0); - int type4 = GetBlockInterchunk(-1, y, 0); - int type5 = GetBlockInterchunk(0, y, CHUNK_SIZE); - int type6 = GetBlockInterchunk(0, y, -1); - - if (type3 <= 0 || (type3 == WATER || type3 == GLASS)) - isOccluded = false; - else if (type4 <= 0 || (type4 == WATER || type4 == GLASS)) - isOccluded = false; - else if (type5 <= 0 || (type5 == WATER || type5 == GLASS)) - isOccluded = false; - else if (type6 <= 0 || (type6 == WATER || type6 == GLASS)) - isOccluded = false; - bool hasBlocks = false; if (!isOccluded) @@ -1043,7 +1043,7 @@ void Chunk::UpdateChunk(int tick) gp->QueueLoadBlocks(this); - LightingManager::GetInstance()->RefreshShadows(); + gp->QueueShadow(this); modified = false; } diff --git a/src/Game/Objects/Base/Entity.cpp b/src/Game/Objects/Base/Entity.cpp index 793c2ea..6cceaa2 100644 --- a/src/Game/Objects/Base/Entity.cpp +++ b/src/Game/Objects/Base/Entity.cpp @@ -351,10 +351,12 @@ void Entity::Draw() glm::vec3 ray = position + glm::vec3(0, 0.1, 0); glm::vec3 ray2 = position - glm::vec3(0, 0.8, 0); + + topWater = RayToIncludeWater(ray, true); if (isCreature) - inWater = RayToIncludeWater(ray, true) || RayToIncludeWater(ray2, true); + inWater = topWater || RayToIncludeWater(ray2, true); else - inWater = RayToIncludeWater(ray, true); + inWater = topWater; if (!Hud::GamePaused) { diff --git a/src/Game/Objects/Base/Entity.h b/src/Game/Objects/Base/Entity.h index b1c862a..cef8ff0 100644 --- a/src/Game/Objects/Base/Entity.h +++ b/src/Game/Objects/Base/Entity.h @@ -14,6 +14,7 @@ class Entity : public GameObject bool isCreature = true; + bool topWater = false; bool inWater = false; float gravity = 19.0f; diff --git a/src/Game/Objects/Base/Player.cpp b/src/Game/Objects/Base/Player.cpp index d3ae98d..5263390 100644 --- a/src/Game/Objects/Base/Player.cpp +++ b/src/Game/Objects/Base/Player.cpp @@ -260,7 +260,7 @@ void Player::Draw() jumpCooldown = glfwGetTime(); downVelocity = jumpStrength; - if (inWater) + if (topWater) downVelocity = jumpStrength / 2; isOnGround = false; } diff --git a/src/Game/Scenes/Gameplay.cpp b/src/Game/Scenes/Gameplay.cpp index a881437..ec4f269 100644 --- a/src/Game/Scenes/Gameplay.cpp +++ b/src/Game/Scenes/Gameplay.cpp @@ -305,6 +305,8 @@ void Gameplay::UpdateChunks() } if (!no) { + Game::instance->log->Write("Loading region: " + std::to_string(fakePosR.x) + ", " + std::to_string(fakePosR.z)); + toLoadedRegion.push_back(glm::vec2(fakePosR.x, fakePosR.z)); wm->_generatePool.detach_task([this, r, amount]() { @@ -359,6 +361,8 @@ void Gameplay::UpdateChunks() } if (!no) { + Game::instance->log->Write("Loading region: " + std::to_string(fakePosR.x) + ", " + std::to_string(fakePosR.z)); + toLoadedRegion.push_back(glm::vec2(fakePosR.x, fakePosR.z)); wm->_generatePool.detach_task([this, r, amount]() { @@ -412,6 +416,8 @@ void Gameplay::UpdateChunks() } if (!no) { + Game::instance->log->Write("Loading region: " + std::to_string(fakePosR.x) + ", " + std::to_string(fakePosR.z)); + toLoadedRegion.push_back(glm::vec2(fakePosR.x - amount, fakePosR.z)); wm->_generatePool.detach_task([this, r, amount]() { @@ -465,6 +471,8 @@ void Gameplay::UpdateChunks() } if (!no) { + Game::instance->log->Write("Loading region: " + std::to_string(fakePosR.x) + ", " + std::to_string(fakePosR.z)); + toLoadedRegion.push_back(glm::vec2(fakePosR.x, fakePosR.z - amount)); wm->_generatePool.detach_task([this, r, amount]() {