Skip to content

Commit

Permalink
oceans lakes and water
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed Apr 22, 2024
1 parent 7941449 commit 7eb6c1f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
44 changes: 22 additions & 22 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1043,7 +1043,7 @@ void Chunk::UpdateChunk(int tick)

gp->QueueLoadBlocks(this);

LightingManager::GetInstance()->RefreshShadows();
gp->QueueShadow(this);
modified = false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Game/Objects/Base/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Game/Objects/Base/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Entity : public GameObject

bool isCreature = true;

bool topWater = false;
bool inWater = false;

float gravity = 19.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/Game/Objects/Base/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void Player::Draw()
jumpCooldown = glfwGetTime();

downVelocity = jumpStrength;
if (inWater)
if (topWater)
downVelocity = jumpStrength / 2;
isOnGround = false;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Game/Scenes/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
{
Expand Down Expand Up @@ -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]()
{
Expand Down Expand Up @@ -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]()
{
Expand Down Expand Up @@ -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]()
{
Expand Down

0 comments on commit 7eb6c1f

Please sign in to comment.