Skip to content

Commit

Permalink
Revert "gotta figure out how to do block data"
Browse files Browse the repository at this point in the history
This reverts commit e2f6815.
  • Loading branch information
Kade-github committed Apr 19, 2024
1 parent e2f6815 commit ffa654c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 48 deletions.
14 changes: 7 additions & 7 deletions src/Game/Data/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool Data::Region::doesBlockExistInRange(int x, int y, int z, int type, int rang
{
for (int _y = 0; _y < CHUNK_HEIGHT; _y++)
{
if (c.blocks[_x][_z][_y].type == type)
if (c.blocks[_x][_z][_y] == type)
{
if (abs(c.x + _x - x) < range && abs(c.z + _z - z) < range && abs(_y - y) < range)
return true;
Expand Down Expand Up @@ -240,7 +240,7 @@ Data::Chunk Data::Region::generateChunk(int x, int z)
{
for (int _y = 0; _y < CHUNK_HEIGHT; _y++)
{
chunk.blocks[_x][_z][_y].type = 0;
chunk.blocks[_x][_z][_y] = 0;
}
}
}
Expand All @@ -267,11 +267,11 @@ Data::Chunk Data::Region::generateChunk(int x, int z)
for (int _y = rY; _y > -1; _y--)
{
if (_y == rY) // grass
chunk.blocks[_x][_z][_y].type = GRASS;
chunk.blocks[_x][_z][_y] = GRASS;
else if (_y > rY - 5) // dirt
chunk.blocks[_x][_z][_y].type = DIRT;
chunk.blocks[_x][_z][_y] = DIRT;
else // stone
chunk.blocks[_x][_z][_y].type = STONE;
chunk.blocks[_x][_z][_y] = STONE;
}
}
}
Expand Down Expand Up @@ -300,12 +300,12 @@ void Data::Region::generateStructures()
{
for (int _y = CHUNK_HEIGHT - 1; _y > -1; _y--)
{
if (c.blocks[_x][_z][_y].type <= 0)
if (c.blocks[_x][_z][_y] <= 0)
continue;

// trees

if (c.blocks[_x][_z][_y].type == GRASS)
if (c.blocks[_x][_z][_y] == GRASS)
{
int _rx = c.x + _x;
int _rz = c.z + _z;
Expand Down
30 changes: 4 additions & 26 deletions src/Game/Data/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,23 @@
#include <mutex>
#include <bitset>

#include <vector>

namespace Data
{
struct DataTag
{
char name[32];
char value[64];

MSGPACK_DEFINE_ARRAY(name, value);
};

struct BlockData
{
uint8_t x = 0, y = 0, z = 0;
uint8_t type = 0;

std::vector<DataTag> tags;

MSGPACK_DEFINE_ARRAY(x, y, z, type, tags);

};

struct Chunk
{
bool isGenerated = false;
BlockData blocks[CHUNK_SIZE][CHUNK_SIZE][CHUNK_HEIGHT];
uint8_t blocks[CHUNK_SIZE][CHUNK_SIZE][CHUNK_HEIGHT];
int32_t x, z;

void placeBlock(int x, int y, int z, int type)
void placeBlock(int x, int y, int z, uint8_t block)
{
BlockData d;
d.type = type;
blocks[x][z][y] = d;
blocks[x][z][y] = block;
}

void removeBlock(int x, int y, int z)
{
blocks[x][z][y] = {};
blocks[x][z][y] = 0;
}

MSGPACK_DEFINE_ARRAY(blocks, x, z);
Expand Down
4 changes: 2 additions & 2 deletions src/Game/Objects/Base/Blocks/Water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void Water::PlaceWater(glm::vec3 _pos, int _strength)

Chunk* c = WorldManager::instance->GetChunk(_pos.x, _pos.z);

_pos -= c->position;

Water* b = (Water*)c->CreateBlock(_pos.x, _pos.y, _pos.z, WATER);

b->position -= c->position; // this gets added in CreateBlock

b->source = false;
b->strength = _strength;

Expand Down
26 changes: 13 additions & 13 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int Chunk::GetBlock(float x, float y, float z)
if (y < 0 || y > CHUNK_HEIGHT - 1)
return 0;

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

int Chunk::GetHighestBlock(float x, float z)
Expand Down Expand Up @@ -105,7 +105,7 @@ int Chunk::GetHighestBlock(float x, float z)

for (int y = CHUNK_HEIGHT - 1; y > -1; y--)
{
if (myData.blocks[_x][_z][y].type > 0)
if (myData.blocks[_x][_z][y] > 0)
return y;
}

Expand Down Expand Up @@ -201,7 +201,7 @@ int Chunk::GetBlockNoCheck(float x, float y, float z)
if (y < 0 || y > CHUNK_HEIGHT - 1)
return 0;

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

bool Chunk::DoesBlockExist(float x, float y, float z)
Expand Down Expand Up @@ -328,7 +328,7 @@ void Chunk::ModifyBlock(float x, float y, float z, int id)
{
// create subchunk

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = id;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = id;

sbc = CreateSubChunk(y);

Expand All @@ -348,7 +348,7 @@ void Chunk::ModifyBlock(float x, float y, float z, int id)
if (id <= 0) // destroyed block
{
sbc->blocks[(int)w.x][(int)w.z] = nullptr;
myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = 0;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = 0;
}
else
{
Expand All @@ -362,7 +362,7 @@ void Chunk::ModifyBlock(float x, float y, float z, int id)

sbc->blocks[(int)w.x][(int)w.z] = _b;

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = id;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = id;
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ void Chunk::PlaceBlock(float x, float y, float z, Block* b)
{
// create subchunk

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = b->type;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = b->type;

sbc = CreateSubChunk(y);

Expand All @@ -434,7 +434,7 @@ void Chunk::PlaceBlock(float x, float y, float z, Block* b)

sbc->blocks[(int)w.x][(int)w.z] = b;

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = b->type;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = b->type;
}


Expand Down Expand Up @@ -493,7 +493,7 @@ void Chunk::BlitPlaceBlock(std::vector<Block*> bs)
{
// create subchunk

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = b->type;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = b->type;

sbc = CreateSubChunk(b->position.y);

Expand All @@ -509,7 +509,7 @@ void Chunk::BlitPlaceBlock(std::vector<Block*> bs)

sbc->blocks[(int)w.x][(int)w.z] = b;

myData.blocks[(int)w.x][(int)w.z][(int)w.y].type = b->type;
myData.blocks[(int)w.x][(int)w.z][(int)w.y] = b->type;
}

CreateOtherSubchunks(b->position.x, b->position.y, b->position.z, w);
Expand Down Expand Up @@ -718,9 +718,9 @@ Data::Chunk Chunk::GetChunkData()
for (int z = 0; z < CHUNK_SIZE; z++)
{
if (sbc->blocks[x][z] != nullptr)
c.blocks[x][z][y].type = sbc->blocks[x][z]->type;
c.blocks[x][z][y] = sbc->blocks[x][z]->type;
else
c.blocks[x][z][y].type = 0;
c.blocks[x][z][y] = 0;
}
}
}
Expand Down Expand Up @@ -821,7 +821,7 @@ subChunk* Chunk::CreateSubChunk(int y)
{
for (int z = 0; z < CHUNK_SIZE; z++)
{
int id = myData.blocks[x][z][y].type;
int id = myData.blocks[x][z][y];

if (id <= 0)
continue;
Expand Down

0 comments on commit ffa654c

Please sign in to comment.