Skip to content

Commit

Permalink
fixing tiny issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed Apr 22, 2024
1 parent fe958c2 commit ea9ca42
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/Engine/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Logging

logs.push_back(log);

if (logs.size() > 10)
if (logs.size() > 30)
logs.erase(logs.begin());
}

Expand Down
18 changes: 14 additions & 4 deletions src/Game/Data/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,20 @@ Data::Chunk Data::Region::generateChunk(int x, int z)

for (int _y = rY; _y > -1; _y--)
{
if (_y == rY) // grass
chunk.bChunk.blocks[_x][_z][_y] = GRASS;
else if (_y > rY - 5) // dirt
chunk.bChunk.blocks[_x][_z][_y] = DIRT;
if (_y == rY) // grass or sand
{
if (rY <= staticWaterLevel)
chunk.bChunk.blocks[_x][_z][_y] = SAND;
else
chunk.bChunk.blocks[_x][_z][_y] = GRASS;
}
else if (_y > rY - 5) // dirt or sand
{
if (rY <= staticWaterLevel)
chunk.bChunk.blocks[_x][_z][_y] = SAND;
else
chunk.bChunk.blocks[_x][_z][_y] = DIRT;
}
else // stone
chunk.bChunk.blocks[_x][_z][_y] = STONE;
}
Expand Down
85 changes: 38 additions & 47 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ Block* subChunk::getBlock(int x, int z)

int Chunk::GetBlock(float x, float y, float z)
{
int _x = x;
int _z = z;
float _x = x;
float _z = z;

glm::vec3 w = WorldToChunk(glm::vec3(x, y, z));

if (_x >= CHUNK_SIZE || _x < 0)
_x = w.x;
_x = (int)w.x;

if (_z >= CHUNK_SIZE || _z < 0)
_z = w.z;

if (_x == 16)
_x = 15;

if (_z == 16)
_z = 15;
_z = (int)w.z;

if (_x >= CHUNK_SIZE)
return 0;
Expand All @@ -63,7 +57,7 @@ int Chunk::GetBlock(float x, float y, float z)
if (y < 0 || y > CHUNK_HEIGHT - 1)
return 0;

return myData.bChunk.blocks[_x][_z][(int)y];
return myData.bChunk.blocks[(int)_x][(int)_z][(int)y];
}

int Chunk::GetHighestBlock(float x, float z)
Expand All @@ -82,12 +76,6 @@ int Chunk::GetHighestBlock(float x, float z)
_x = w.x;
_z = w.z;

if (_x == 16)
_x = 15;

if (_z == 16)
_z = 15;

if (_x >= CHUNK_SIZE)
return 0;

Expand Down Expand Up @@ -122,7 +110,7 @@ bool Chunk::InterchunkDoesBlockExist(float x, float y, float z)
left = WorldManager::instance->GetChunk(position.x - CHUNK_SIZE, position.z);

if (left != nullptr)
return left->GetBlock(CHUNK_SIZE - 1, y, _z) > 0;
return left->GetBlock(0, y, _z) > 0;
else
return true;
}
Expand All @@ -134,7 +122,7 @@ bool Chunk::InterchunkDoesBlockExist(float x, float y, float z)
right = WorldManager::instance->GetChunk(position.x + CHUNK_SIZE, position.z);

if (right != nullptr)
return right->GetBlock(0, y, z) > 0;
return right->GetBlock(CHUNK_SIZE - 1, y, z) > 0;
else
return true;

Expand Down Expand Up @@ -179,7 +167,7 @@ int Chunk::GetBlockInterchunk(float x, float y, float z)
left = WorldManager::instance->GetChunk(position.x - CHUNK_SIZE, position.z);

if (left != nullptr)
return left->GetBlock(CHUNK_SIZE - 1, y, _z);
return left->GetBlock(0, y, _z);
else
return 0;
}
Expand All @@ -191,7 +179,7 @@ int Chunk::GetBlockInterchunk(float x, float y, float z)
right = WorldManager::instance->GetChunk(position.x + CHUNK_SIZE, position.z);

if (right != nullptr)
return right->GetBlock(0, y, z);
return right->GetBlock(CHUNK_SIZE - 1, y, z);
else
return 0;

Expand Down Expand Up @@ -389,24 +377,24 @@ void Chunk::CreateFaces(Block* b)
int y = b->position.y;
int z = b->position.z - position.z;

int t = GetBlockInterchunk(x, y + 1, z);
int t = GetBlock(x, y + 1, z);
// in our chunk
if (t > 0 && (b->transparent))
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
top = false;
t = GetBlockInterchunk(x, y - 1, z);
if (t > 0 && ( b->transparent))
t = GetBlock(x, y - 1, z);
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
bottom = false;
t = GetBlockInterchunk(x + 1, y, z);
if (t > 0 && (b->transparent))
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
left = false;
t = GetBlockInterchunk(x - 1, y, z);
if (t > 0 && (b->transparent))
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
right = false;
t = GetBlockInterchunk(x, y, z - 1);
if (t > 0 && (b->transparent))
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
front = false;
t = GetBlockInterchunk(x, y, z + 1);
if (t > 0 && (b->transparent))
if (t > 0 && ((t != WATER && t != GLASS) || b->transparent))
back = false;

// create faces
Expand Down Expand Up @@ -679,15 +667,15 @@ subChunk* Chunk::CreateSubChunk(int y)

if (type <= 0 || (type == WATER || type == GLASS))
isOccluded = false;
else if (type2 <= 0 || (type == WATER || type == GLASS))
if (type2 <= 0 || (type2 == WATER || type2 == GLASS))
isOccluded = false;
else if (type3 <= 0 || (type == WATER || type == GLASS))
if (type3 <= 0 || (type3 == WATER || type3 == GLASS))
isOccluded = false;
else if (type4 <= 0 || (type == WATER || type == GLASS))
if (type4 <= 0 || (type4 == WATER || type4 == GLASS))
isOccluded = false;
else if (type5 <= 0 || (type == WATER || type == GLASS))
if (type5 <= 0 || (type5 == WATER || type5 == GLASS))
isOccluded = false;
else if (type6 <= 0 || (type == WATER || type == GLASS))
if (type6 <= 0 || (type6 == WATER || type6 == GLASS))
isOccluded = false;
bool hasBlocks = false;

Expand Down Expand Up @@ -1030,6 +1018,8 @@ void Chunk::DrawShadows()

void Chunk::UpdateChunk(int tick)
{
bool wasModified = modified;

if (modified)
{
Gameplay* gp = (Gameplay*)Game::instance->currentScene;
Expand All @@ -1040,24 +1030,25 @@ void Chunk::UpdateChunk(int tick)
modified = false;
}

for (int i = 0; i < subChunks.size(); i++)
{
subChunk* sbc = subChunks[i];
if (wasModified)
for (int i = 0; i < subChunks.size(); i++)
{
subChunk* sbc = subChunks[i];

if (sbc == nullptr)
continue;
if (sbc == nullptr)
continue;

for (int x = 0; x < CHUNK_SIZE; x++)
{
for (int z = 0; z < CHUNK_SIZE; z++)
for (int x = 0; x < CHUNK_SIZE; x++)
{
Block* b = sbc->blocks[x][z];
for (int z = 0; z < CHUNK_SIZE; z++)
{
Block* b = sbc->blocks[x][z];

if (b == nullptr)
continue;
if (b == nullptr)
continue;

b->Update(tick);
b->Update(tick);
}
}
}
}
}
22 changes: 6 additions & 16 deletions src/Game/Objects/Base/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,15 @@ void Entity::CheckCollision(glm::vec3& motion, float down)
float toX = motion.x;
float toZ = motion.z;

float initialX = motion.x;
float initialZ = motion.z;

float pX = position.x;
float pZ = position.z;

glm::vec3 ray = position;
ray.y = toY;

glm::vec3 _world = currentChunk->WorldToChunk(ray);

if (_world.x == 16)
toX--;

if (_world.z == 16)
toZ--;

bool hit = false;

float progress = 0;
Expand All @@ -132,7 +126,9 @@ void Entity::CheckCollision(glm::vec3& motion, float down)
}

if (hit)
{
break;
}

progress += 0.1;
}
Expand Down Expand Up @@ -163,7 +159,9 @@ void Entity::CheckCollision(glm::vec3& motion, float down)
}

if (hit)
{
break;
}

progress += 0.1;
}
Expand Down Expand Up @@ -217,14 +215,6 @@ void Entity::CheckVerticalCollision(glm::vec3& motion)
float toX = position.x;
float toZ = position.z;

glm::vec3 _world = currentChunk->WorldToChunk(ray);

if (_world.x == 16)
toX--;

if (_world.z == 16)
toZ--;

int _lastY = -1;

bool hit = false;
Expand Down
3 changes: 3 additions & 0 deletions src/Game/Scenes/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ void Gameplay::Draw()

realTPS /= tickTimes.size();

Chunk* currentChunk = wm->GetChunk(player->position.x, player->position.z);

c2d->DrawDebugText("Player Position: " + StringTools::ToTheDecimial(player->position.x, 2) + ", " + StringTools::ToTheDecimial(player->position.y, 2) + ", " + StringTools::ToTheDecimial(player->position.z, 2), glm::vec2(4, 4), 24);
c2d->DrawDebugText("TPS: " + StringTools::ToTheDecimial(tps, 2), glm::vec2(4, 28), 24);
c2d->DrawDebugText("Player in water: " + std::to_string(player->inWater), glm::vec2(4, 52), 24);
if (currentChunk != nullptr)
c2d->DrawDebugText("Subchunks in chunk: " + std::to_string(currentChunk->subChunks.size()), glm::vec2(4, 76), 24);

MusicManager::GetInstance()->Update();

Expand Down

0 comments on commit ea9ca42

Please sign in to comment.