|
@@ -104,62 +104,175 @@ void Chunk::removeLightSource(int index)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Chunk::sendLightToClient(Framework::StreamWriter* zWriter)
|
|
|
|
|
|
|
+void Chunk::sendToClient(Framework::StreamWriter* zWriter, bool* instanceMap)
|
|
|
{
|
|
{
|
|
|
- for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
|
|
+ for (int x = 0; x < CHUNK_SIZE; x++)
|
|
|
{
|
|
{
|
|
|
- for (int x = -1; x <= CHUNK_SIZE; x++)
|
|
|
|
|
|
|
+ for (int y = 0; y < CHUNK_SIZE; y++)
|
|
|
{
|
|
{
|
|
|
- for (int y = -1; y <= CHUNK_SIZE; y++)
|
|
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
{
|
|
{
|
|
|
- if ((x < 0 || x == CHUNK_SIZE) && (y < 0 || y > CHUNK_SIZE))
|
|
|
|
|
|
|
+ int index = Chunk::index({x, y, z});
|
|
|
|
|
+ const BlockType* type
|
|
|
|
|
+ = Game::INSTANCE->zBlockType(blockIds[index]);
|
|
|
|
|
+ if (isVisible(index) && type->doesNeedClientInstance())
|
|
|
{
|
|
{
|
|
|
- continue;
|
|
|
|
|
|
|
+ if (z > 0 && z < WORLD_HEIGHT - 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ instanceMap[index + (CHUNK_SIZE + 1) * WORLD_HEIGHT + 1]
|
|
|
|
|
+ = 1;
|
|
|
|
|
+ instanceMap[index + (CHUNK_SIZE + 1) * WORLD_HEIGHT - 1]
|
|
|
|
|
+ = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ instanceMap[index + WORLD_HEIGHT] = 1;
|
|
|
|
|
+ instanceMap[index + (2 * CHUNK_SIZE + 1) * WORLD_HEIGHT]
|
|
|
|
|
+ = 1;
|
|
|
|
|
+ instanceMap[index + CHUNK_SIZE * WORLD_HEIGHT] = 1;
|
|
|
|
|
+ instanceMap[index + (CHUNK_SIZE + 2) * WORLD_HEIGHT] = 1;
|
|
|
|
|
+ zWriter->schreibe((char*)&blockIds[index], 2);
|
|
|
|
|
+ zWriter->schreibe((char*)&index, 4);
|
|
|
|
|
+ char state = 0;
|
|
|
|
|
+ if (type->isFluid())
|
|
|
|
|
+ {
|
|
|
|
|
+ state |= 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((blocks[index] && blocks[index]->isPassable())
|
|
|
|
|
+ || (type->zDefault()->isPassable()))
|
|
|
|
|
+ {
|
|
|
|
|
+ state |= 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ zWriter->schreibe((char*)&state, 1);
|
|
|
|
|
+ if ((state | 1) == state)
|
|
|
|
|
+ {
|
|
|
|
|
+ FluidBlock* fluidBlock
|
|
|
|
|
+ = dynamic_cast<FluidBlock*>(blocks[index]);
|
|
|
|
|
+ char data
|
|
|
|
|
+ = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
|
|
|
+ zWriter->schreibe(&data, 1);
|
|
|
|
|
+ data = fluidBlock ? fluidBlock->getDistanceToSource()
|
|
|
|
|
+ : 0;
|
|
|
|
|
+ zWriter->schreibe(&data, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((state | 2) == state)
|
|
|
|
|
+ {
|
|
|
|
|
+ float speedModifier
|
|
|
|
|
+ = blocks[index]
|
|
|
|
|
+ ? blocks[index]->getSpeedModifier()
|
|
|
|
|
+ : type->zDefault()->getSpeedModifier();
|
|
|
|
|
+ zWriter->schreibe((char*)&speedModifier, 4);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- bool needSend = 0;
|
|
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ unsigned short end = 0;
|
|
|
|
|
+ zWriter->schreibe((char*)&end, 2);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Chunk::sendLightToClient(
|
|
|
|
|
+ Framework::StreamWriter* zWriter, bool* instanceMap)
|
|
|
|
|
+{
|
|
|
|
|
+ cs.lock();
|
|
|
|
|
+ Chunk* zNeighbours[4];
|
|
|
|
|
+ for (int i = 0; i < 4; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ zNeighbours[i]
|
|
|
|
|
+ = this->zNeighbours[i]
|
|
|
|
|
+ ? dynamic_cast<Chunk*>(this->zNeighbours[i]->getThis())
|
|
|
|
|
+ : 0;
|
|
|
|
|
+ if (zNeighbours[i])
|
|
|
|
|
+ {
|
|
|
|
|
+ Direction dir = getDirectionFromIndex(i);
|
|
|
|
|
+ switch (dir)
|
|
|
|
|
+ {
|
|
|
|
|
+ case WEST:
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
{
|
|
{
|
|
|
- Framework::Vec3<int> pos
|
|
|
|
|
- = Framework::Vec3<int>(x, y, z)
|
|
|
|
|
- + getDirection(getDirectionFromIndex(i));
|
|
|
|
|
- if (pos.z >= 0 && pos.z < WORLD_HEIGHT)
|
|
|
|
|
|
|
+ for (int j = 0; j < CHUNK_SIZE; j++)
|
|
|
{
|
|
{
|
|
|
- if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
|
|
|
|
|
- && pos.y < CHUNK_SIZE)
|
|
|
|
|
|
|
+ int type = zNeighbours[i]->getBlockTypeAt(
|
|
|
|
|
+ {CHUNK_SIZE - 1, j, z});
|
|
|
|
|
+ if (type
|
|
|
|
|
+ && Game::INSTANCE->zBlockType(type)
|
|
|
|
|
+ ->doesNeedClientInstance())
|
|
|
{
|
|
{
|
|
|
- int bi = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT
|
|
|
|
|
- + pos.z;
|
|
|
|
|
- int type = blockIds[bi];
|
|
|
|
|
- needSend |= type != BlockTypeEnum::NO_BLOCK
|
|
|
|
|
- && Game::INSTANCE->zBlockType(type)
|
|
|
|
|
- ->doesNeedClientInstance();
|
|
|
|
|
|
|
+ instanceMap[(CHUNK_SIZE + j + 1) * WORLD_HEIGHT + z]
|
|
|
|
|
+ = 1;
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case NORTH:
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int j = 0; j < CHUNK_SIZE; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ int type = zNeighbours[i]->getBlockTypeAt(
|
|
|
|
|
+ {j, CHUNK_SIZE - 1, z});
|
|
|
|
|
+ if (type
|
|
|
|
|
+ && Game::INSTANCE->zBlockType(type)
|
|
|
|
|
+ ->doesNeedClientInstance())
|
|
|
{
|
|
{
|
|
|
- if (x >= 0 && x < CHUNK_SIZE && y >= 0
|
|
|
|
|
- && y < CHUNK_SIZE)
|
|
|
|
|
- {
|
|
|
|
|
- cs.lock();
|
|
|
|
|
- if (i < 4 && zNeighbours[i])
|
|
|
|
|
- {
|
|
|
|
|
- Framework::Vec3<int> offset
|
|
|
|
|
- = getDirection(getDirectionFromIndex(i))
|
|
|
|
|
- * 16;
|
|
|
|
|
- int bi = ((pos.x - offset.x) * CHUNK_SIZE
|
|
|
|
|
- + (pos.y - offset.y))
|
|
|
|
|
- * WORLD_HEIGHT
|
|
|
|
|
- + (pos.z - offset.z);
|
|
|
|
|
- int type = zNeighbours[i]->blockIds[bi];
|
|
|
|
|
- needSend |= Game::INSTANCE->zBlockType(type)
|
|
|
|
|
- ->doesNeedClientInstance();
|
|
|
|
|
- }
|
|
|
|
|
- cs.unlock();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ instanceMap[((j + 1) * CHUNK_SIZE + 1)
|
|
|
|
|
+ * WORLD_HEIGHT
|
|
|
|
|
+ + z]
|
|
|
|
|
+ = 1;
|
|
|
}
|
|
}
|
|
|
- if (needSend) break;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (needSend)
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case EAST:
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int j = 0; j < CHUNK_SIZE; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ int type = zNeighbours[i]->getBlockTypeAt({0, j, z});
|
|
|
|
|
+ if (type
|
|
|
|
|
+ && Game::INSTANCE->zBlockType(type)
|
|
|
|
|
+ ->doesNeedClientInstance())
|
|
|
|
|
+ {
|
|
|
|
|
+ instanceMap[((CHUNK_SIZE)*CHUNK_SIZE + j + 1)
|
|
|
|
|
+ * WORLD_HEIGHT
|
|
|
|
|
+ + z]
|
|
|
|
|
+ = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case SOUTH:
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int j = 0; j < CHUNK_SIZE; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ int type = zNeighbours[i]->getBlockTypeAt({j, 0, z});
|
|
|
|
|
+ if (type
|
|
|
|
|
+ && Game::INSTANCE->zBlockType(type)
|
|
|
|
|
+ ->doesNeedClientInstance())
|
|
|
|
|
+ {
|
|
|
|
|
+ instanceMap[((j + 1) * CHUNK_SIZE + CHUNK_SIZE)
|
|
|
|
|
+ * WORLD_HEIGHT
|
|
|
|
|
+ + z]
|
|
|
|
|
+ = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ cs.unlock();
|
|
|
|
|
+ for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int x = -1; x <= CHUNK_SIZE; x++)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int y = -1; y <= CHUNK_SIZE; y++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ((x < 0 || x == CHUNK_SIZE) && (y < 0 || y > CHUNK_SIZE))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (instanceMap[((x + 1) * CHUNK_SIZE + y + 1) * WORLD_HEIGHT
|
|
|
|
|
+ + z])
|
|
|
{
|
|
{
|
|
|
if (x >= 0 && x < CHUNK_SIZE && y >= 0 && y < CHUNK_SIZE)
|
|
if (x >= 0 && x < CHUNK_SIZE && y >= 0 && y < CHUNK_SIZE)
|
|
|
{
|
|
{
|
|
@@ -196,7 +309,6 @@ void Chunk::sendLightToClient(Framework::StreamWriter* zWriter)
|
|
|
dir = getDirectionIndex(SOUTH);
|
|
dir = getDirectionIndex(SOUTH);
|
|
|
index = (x * CHUNK_SIZE) * WORLD_HEIGHT + z;
|
|
index = (x * CHUNK_SIZE) * WORLD_HEIGHT + z;
|
|
|
}
|
|
}
|
|
|
- cs.lock();
|
|
|
|
|
if (zNeighbours[dir])
|
|
if (zNeighbours[dir])
|
|
|
{
|
|
{
|
|
|
int i = -1;
|
|
int i = -1;
|
|
@@ -209,7 +321,6 @@ void Chunk::sendLightToClient(Framework::StreamWriter* zWriter)
|
|
|
+ index * 6),
|
|
+ index * 6),
|
|
|
6);
|
|
6);
|
|
|
}
|
|
}
|
|
|
- cs.unlock();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -217,68 +328,68 @@ void Chunk::sendLightToClient(Framework::StreamWriter* zWriter)
|
|
|
}
|
|
}
|
|
|
int end = -2;
|
|
int end = -2;
|
|
|
zWriter->schreibe((char*)&end, 4);
|
|
zWriter->schreibe((char*)&end, 4);
|
|
|
|
|
+ for (int i = 0; i < 4; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (zNeighbours[i])
|
|
|
|
|
+ {
|
|
|
|
|
+ zNeighbours[i]->release();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool Chunk::isVisible(int index) const
|
|
bool Chunk::isVisible(int index) const
|
|
|
{
|
|
{
|
|
|
- if (!blocks[index])
|
|
|
|
|
|
|
+ unsigned short blockType
|
|
|
|
|
+ = blocks[index] ? (unsigned short)blocks[index]->zBlockType()->getId()
|
|
|
|
|
+ : blockIds[index];
|
|
|
|
|
+ if (blockType)
|
|
|
{
|
|
{
|
|
|
- unsigned short blockType
|
|
|
|
|
- = blocks[index]
|
|
|
|
|
- ? (unsigned short)blocks[index]->zBlockType()->getId()
|
|
|
|
|
- : blockIds[index];
|
|
|
|
|
- if (blockType)
|
|
|
|
|
|
|
+ if (CONST_BLOCK(0, blockIds[index])->isTransparent()
|
|
|
|
|
+ || CONST_BLOCK(0, blockIds[index])->isPassable())
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- if (CONST_BLOCK(0, blockIds[index])->isTransparent()
|
|
|
|
|
- || CONST_BLOCK(0, blockIds[index])->isPassable())
|
|
|
|
|
- return 1;
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ Framework::Vec3<int> indexPos
|
|
|
|
|
+ = {(index / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
|
|
+ (index / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
|
|
+ index % WORLD_HEIGHT};
|
|
|
|
|
+ for (int d = 0; d < 6; d++)
|
|
|
{
|
|
{
|
|
|
- Framework::Vec3<int> indexPos
|
|
|
|
|
- = {(index / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
|
|
- (index / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
|
|
- index % WORLD_HEIGHT};
|
|
|
|
|
- for (int d = 0; d < 6; d++)
|
|
|
|
|
|
|
+ Framework::Either<Block*, int> n = BlockTypeEnum::NO_BLOCK;
|
|
|
|
|
+ Framework::Vec3<int> pos
|
|
|
|
|
+ = getDirection((Directions)getDirectionFromIndex(d))
|
|
|
|
|
+ + indexPos;
|
|
|
|
|
+ if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
|
|
|
|
|
+ && pos.y < CHUNK_SIZE && pos.z >= 0 && pos.z < WORLD_HEIGHT)
|
|
|
{
|
|
{
|
|
|
- Framework::Either<Block*, int> n = BlockTypeEnum::NO_BLOCK;
|
|
|
|
|
- Framework::Vec3<int> pos
|
|
|
|
|
- = getDirection((Directions)getDirectionFromIndex(d))
|
|
|
|
|
- + indexPos;
|
|
|
|
|
- if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
|
|
|
|
|
- && pos.y < CHUNK_SIZE && pos.z >= 0
|
|
|
|
|
- && pos.z < WORLD_HEIGHT)
|
|
|
|
|
- {
|
|
|
|
|
- n = zBlockAt(pos);
|
|
|
|
|
- }
|
|
|
|
|
- else if (pos.z >= 0 && pos.z < WORLD_HEIGHT && d < 4
|
|
|
|
|
- && zNeighbours[d])
|
|
|
|
|
- {
|
|
|
|
|
- if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
|
|
|
- if (pos.x >= CHUNK_SIZE) pos.x -= CHUNK_SIZE;
|
|
|
|
|
- if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
|
|
|
- if (pos.y >= CHUNK_SIZE) pos.y -= CHUNK_SIZE;
|
|
|
|
|
- n = zNeighbours[d]->zBlockAt(pos);
|
|
|
|
|
- }
|
|
|
|
|
- else if (pos.z >= 0 && pos.z < WORLD_HEIGHT && d < 4
|
|
|
|
|
- && !zNeighbours[d])
|
|
|
|
|
- {
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
- if (n.isA()
|
|
|
|
|
- && (((Block*)n)->isPassable()
|
|
|
|
|
- || ((Block*)n)->isTransparent()))
|
|
|
|
|
- return 1;
|
|
|
|
|
- if (n.isB()
|
|
|
|
|
- && (CONST_BLOCK(0, n)->isTransparent()
|
|
|
|
|
- || CONST_BLOCK(0, n)->isPassable()))
|
|
|
|
|
- return 1;
|
|
|
|
|
|
|
+ n = zBlockAt(pos);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (pos.z >= 0 && pos.z < WORLD_HEIGHT && d < 4
|
|
|
|
|
+ && zNeighbours[d])
|
|
|
|
|
+ {
|
|
|
|
|
+ if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
|
|
|
+ if (pos.x >= CHUNK_SIZE) pos.x -= CHUNK_SIZE;
|
|
|
|
|
+ if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
|
|
|
+ if (pos.y >= CHUNK_SIZE) pos.y -= CHUNK_SIZE;
|
|
|
|
|
+ n = zNeighbours[d]->zBlockAt(pos);
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (pos.z >= 0 && pos.z < WORLD_HEIGHT && d < 4
|
|
|
|
|
+ && !zNeighbours[d])
|
|
|
|
|
+ {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (n.isA()
|
|
|
|
|
+ && (((Block*)n)->isPassable()
|
|
|
|
|
+ || ((Block*)n)->isTransparent()))
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ if (n.isB()
|
|
|
|
|
+ && (CONST_BLOCK(0, n)->isTransparent()
|
|
|
|
|
+ || CONST_BLOCK(0, n)->isPassable()))
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return 0;
|
|
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
- return blocks[index]->isVisible();
|
|
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Chunk::broadcastLightData(int index, bool foreground)
|
|
void Chunk::broadcastLightData(int index, bool foreground)
|
|
@@ -358,13 +469,17 @@ void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
|
buffer.schreibe("\4", 1);
|
|
buffer.schreibe("\4", 1);
|
|
|
buffer.schreibe((char*)&location.x, 4);
|
|
buffer.schreibe((char*)&location.x, 4);
|
|
|
buffer.schreibe((char*)&location.y, 4);
|
|
buffer.schreibe((char*)&location.y, 4);
|
|
|
- sendToClient(&buffer);
|
|
|
|
|
- sendLightToClient(&buffer);
|
|
|
|
|
|
|
+ bool instanceMap[(CHUNK_SIZE + 2) * (CHUNK_SIZE + 2) * WORLD_HEIGHT];
|
|
|
|
|
+ memset(instanceMap, 0, sizeof(instanceMap));
|
|
|
|
|
+ sendToClient(&buffer, instanceMap);
|
|
|
|
|
+ sendLightToClient(&buffer, instanceMap);
|
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
|
msg->addressDimension(Game::INSTANCE->zDimension(dimensionId));
|
|
msg->addressDimension(Game::INSTANCE->zDimension(dimensionId));
|
|
|
|
|
+#ifdef _DEBUG
|
|
|
Framework::Logging::debug()
|
|
Framework::Logging::debug()
|
|
|
<< "chunk size: " << location.x << ", " << location.y << ": "
|
|
<< "chunk size: " << location.x << ", " << location.y << ": "
|
|
|
<< buffer.getSize() << "b";
|
|
<< buffer.getSize() << "b";
|
|
|
|
|
+#endif
|
|
|
char* message = new char[buffer.getSize()];
|
|
char* message = new char[buffer.getSize()];
|
|
|
buffer.lese(message, (int)buffer.getSize());
|
|
buffer.lese(message, (int)buffer.getSize());
|
|
|
msg->setMessage(message, (int)buffer.getSize());
|
|
msg->setMessage(message, (int)buffer.getSize());
|
|
@@ -567,7 +682,9 @@ void Chunk::initializeLightning()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef _DEBUG
|
|
|
Framework::Logging::debug() << "goUps: " << goUps << " minZ: " << minZ;
|
|
Framework::Logging::debug() << "goUps: " << goUps << " minZ: " << minZ;
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Chunk::updateLightSources()
|
|
void Chunk::updateLightSources()
|
|
@@ -701,31 +818,6 @@ void Chunk::putBlockAt(Framework::Vec3<int> location, Block* block)
|
|
|
change = old != 0;
|
|
change = old != 0;
|
|
|
}
|
|
}
|
|
|
blocks[index] = block;
|
|
blocks[index] = block;
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
|
- {
|
|
|
|
|
- Direction d = getDirectionFromIndex(i);
|
|
|
|
|
- Chunk* zNeighborChunk = 0;
|
|
|
|
|
- Framework::Either<Block*, int> neighbor
|
|
|
|
|
- = zBlockNeighbor(location + getDirection(d), &zNeighborChunk);
|
|
|
|
|
- if (neighbor.isA())
|
|
|
|
|
- {
|
|
|
|
|
- if (block)
|
|
|
|
|
- {
|
|
|
|
|
- ((Block*)neighbor)
|
|
|
|
|
- ->setNeighbour(getOppositeDirection(d), block);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- ((Block*)neighbor)
|
|
|
|
|
- ->setNeighbour(getOppositeDirection(d), blockIds[index]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (block) block->setNeighbour(d, neighbor);
|
|
|
|
|
- if (zNeighborChunk && zNeighborChunk != this)
|
|
|
|
|
- {
|
|
|
|
|
- zNeighborChunk->worldUpdated = 1;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
if (old) old->release();
|
|
if (old) old->release();
|
|
|
if (block && block->isTickSource() != TickSourceType::NONE)
|
|
if (block && block->isTickSource() != TickSourceType::NONE)
|
|
|
{ // add to tick sources
|
|
{ // add to tick sources
|
|
@@ -780,20 +872,6 @@ void Chunk::putBlockTypeAt(Framework::Vec3<int> location, int type)
|
|
|
if (blockIds[index] != (unsigned short)type)
|
|
if (blockIds[index] != (unsigned short)type)
|
|
|
{
|
|
{
|
|
|
blockIds[index] = (unsigned short)type;
|
|
blockIds[index] = (unsigned short)type;
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
|
- {
|
|
|
|
|
- Direction d = getDirectionFromIndex(i);
|
|
|
|
|
- Chunk* zNeighborChunk = 0;
|
|
|
|
|
- Framework::Either<Block*, int> neighbor
|
|
|
|
|
- = zBlockNeighbor(location + getDirection(d), &zNeighborChunk);
|
|
|
|
|
- if (neighbor.isA())
|
|
|
|
|
- ((Block*)neighbor)
|
|
|
|
|
- ->setNeighbourType(getOppositeDirection(d), type);
|
|
|
|
|
- if (zNeighborChunk && zNeighborChunk != this)
|
|
|
|
|
- {
|
|
|
|
|
- zNeighborChunk->worldUpdated = 1;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
if (isLightSource != wasLightSource)
|
|
if (isLightSource != wasLightSource)
|
|
|
{
|
|
{
|
|
|
if (isLightSource)
|
|
if (isLightSource)
|
|
@@ -927,31 +1005,12 @@ void Chunk::setNeighbor(Direction dir, Chunk* zChunk)
|
|
|
j = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
|
|
j = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
|
|
|
}
|
|
}
|
|
|
bool needsTransmission = 0;
|
|
bool needsTransmission = 0;
|
|
|
- if (blocks[index])
|
|
|
|
|
- {
|
|
|
|
|
- bool visible = blocks[index]->isVisible();
|
|
|
|
|
- if (zChunk && zChunk->blocks[j])
|
|
|
|
|
- blocks[index]->setNeighbour(dir, zChunk->blocks[j]);
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- blocks[index]->setNeighbour(dir, 0);
|
|
|
|
|
- blocks[index]->setNeighbourType(
|
|
|
|
|
- dir, zChunk ? zChunk->blockIds[j] : 0);
|
|
|
|
|
- }
|
|
|
|
|
- if (!visible && blocks[index]->isVisible())
|
|
|
|
|
- {
|
|
|
|
|
- needsTransmission = 1;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
|
|
+ zNeighbours[dirIndex] = old;
|
|
|
|
|
+ bool visible = isVisible(index);
|
|
|
|
|
+ zNeighbours[dirIndex] = zChunk;
|
|
|
|
|
+ if (!visible && isVisible(index))
|
|
|
{
|
|
{
|
|
|
- zNeighbours[dirIndex] = old;
|
|
|
|
|
- bool visible = isVisible(index);
|
|
|
|
|
- zNeighbours[dirIndex] = zChunk;
|
|
|
|
|
- if (!visible && isVisible(index))
|
|
|
|
|
- {
|
|
|
|
|
- needsTransmission = 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ needsTransmission = 1;
|
|
|
}
|
|
}
|
|
|
if (zChunk)
|
|
if (zChunk)
|
|
|
{
|
|
{
|
|
@@ -1040,97 +1099,45 @@ void Chunk::save(Framework::StreamWriter* zWriter)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Chunk::sendToClient(Framework::StreamWriter* zWriter)
|
|
|
|
|
|
|
+void Chunk::removeUnusedBlocks()
|
|
|
{
|
|
{
|
|
|
- for (int x = 0; x < CHUNK_SIZE; x++)
|
|
|
|
|
|
|
+/* for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
|
|
|
+{
|
|
|
|
|
+ if (!blocks[i] && blockIds[i])
|
|
|
{
|
|
{
|
|
|
- for (int y = 0; y < CHUNK_SIZE; y++)
|
|
|
|
|
|
|
+ int x = (i / WORLD_HEIGHT) / CHUNK_SIZE;
|
|
|
|
|
+ int y = (i / WORLD_HEIGHT) % CHUNK_SIZE;
|
|
|
|
|
+ int z = i % WORLD_HEIGHT;
|
|
|
|
|
+ bool visible = 0;
|
|
|
|
|
+ if (CONST_BLOCK(0, blockIds[i])->isTransparent()
|
|
|
|
|
+ || CONST_BLOCK(0, blockIds[i])->isPassable())
|
|
|
|
|
+ visible = 1;
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
|
|
+ for (int d = 0; d < 6 && !visible; d++)
|
|
|
{
|
|
{
|
|
|
- int index = Chunk::index({x, y, z});
|
|
|
|
|
- const BlockType* type
|
|
|
|
|
- = Game::INSTANCE->zBlockType(blockIds[index]);
|
|
|
|
|
- if (isVisible(index) && type->doesNeedClientInstance())
|
|
|
|
|
- {
|
|
|
|
|
- zWriter->schreibe((char*)&blockIds[index], 2);
|
|
|
|
|
- zWriter->schreibe((char*)&index, 4);
|
|
|
|
|
- char state = 0;
|
|
|
|
|
- if (type->isFluid())
|
|
|
|
|
- {
|
|
|
|
|
- state |= 1;
|
|
|
|
|
- }
|
|
|
|
|
- if ((blocks[index] && blocks[index]->isPassable())
|
|
|
|
|
- || (type->zDefault()->isPassable()))
|
|
|
|
|
- {
|
|
|
|
|
- state |= 2;
|
|
|
|
|
- }
|
|
|
|
|
- zWriter->schreibe((char*)&state, 1);
|
|
|
|
|
- if ((state | 1) == state)
|
|
|
|
|
- {
|
|
|
|
|
- FluidBlock* fluidBlock
|
|
|
|
|
- = dynamic_cast<FluidBlock*>(blocks[index]);
|
|
|
|
|
- char data
|
|
|
|
|
- = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
|
|
|
- zWriter->schreibe(&data, 1);
|
|
|
|
|
- data = fluidBlock ? fluidBlock->getDistanceToSource()
|
|
|
|
|
- : 0;
|
|
|
|
|
- zWriter->schreibe(&data, 1);
|
|
|
|
|
- }
|
|
|
|
|
- if ((state | 2) == state)
|
|
|
|
|
- {
|
|
|
|
|
- float speedModifier
|
|
|
|
|
- = blocks[index]
|
|
|
|
|
- ? blocks[index]->getSpeedModifier()
|
|
|
|
|
- : type->zDefault()->getSpeedModifier();
|
|
|
|
|
- zWriter->schreibe((char*)&speedModifier, 4);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ auto n = zBlockNeighbor(
|
|
|
|
|
+ getDirection((Directions)getDirectionFromIndex(d))
|
|
|
|
|
+ + Framework::Vec3<int>(x, y, z),
|
|
|
|
|
+ 0);
|
|
|
|
|
+ if (n.isA()
|
|
|
|
|
+ && (((Block*)n)->isPassable()
|
|
|
|
|
+ || ((Block*)n)->isTransparent()))
|
|
|
|
|
+ visible = 1;
|
|
|
|
|
+ if (n.isB()
|
|
|
|
|
+ && (CONST_BLOCK(0, n)->isTransparent()
|
|
|
|
|
+ || CONST_BLOCK(0, n)->isPassable()))
|
|
|
|
|
+ visible = 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- unsigned short end = 0;
|
|
|
|
|
- zWriter->schreibe((char*)&end, 2);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Chunk::removeUnusedBlocks()
|
|
|
|
|
-{
|
|
|
|
|
- for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
|
|
|
- {
|
|
|
|
|
- if (!blocks[i] && blockIds[i])
|
|
|
|
|
|
|
+ if (!visible)
|
|
|
{
|
|
{
|
|
|
- int x = (i / WORLD_HEIGHT) / CHUNK_SIZE;
|
|
|
|
|
- int y = (i / WORLD_HEIGHT) % CHUNK_SIZE;
|
|
|
|
|
- int z = i % WORLD_HEIGHT;
|
|
|
|
|
- bool visible = 0;
|
|
|
|
|
- if (CONST_BLOCK(0, blockIds[i])->isTransparent()
|
|
|
|
|
- || CONST_BLOCK(0, blockIds[i])->isPassable())
|
|
|
|
|
- visible = 1;
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- for (int d = 0; d < 6 && !visible; d++)
|
|
|
|
|
- {
|
|
|
|
|
- auto n = zBlockNeighbor(
|
|
|
|
|
- getDirection((Directions)getDirectionFromIndex(d))
|
|
|
|
|
- + Framework::Vec3<int>(x, y, z),
|
|
|
|
|
- 0);
|
|
|
|
|
- if (n.isA()
|
|
|
|
|
- && (((Block*)n)->isPassable()
|
|
|
|
|
- || ((Block*)n)->isTransparent()))
|
|
|
|
|
- visible = 1;
|
|
|
|
|
- if (n.isB()
|
|
|
|
|
- && (CONST_BLOCK(0, n)->isTransparent()
|
|
|
|
|
- || CONST_BLOCK(0, n)->isPassable()))
|
|
|
|
|
- visible = 1;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (!visible)
|
|
|
|
|
- {
|
|
|
|
|
- putBlockAt({x, y, z}, 0);
|
|
|
|
|
- putBlockTypeAt({x, y, z}, 0);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ putBlockAt({x, y, z}, 0);
|
|
|
|
|
+ putBlockTypeAt({x, y, z}, 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+}*/
|
|
|
|
|
+#ifdef _DEBUG
|
|
|
int count = 0;
|
|
int count = 0;
|
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
|
{
|
|
{
|
|
@@ -1140,6 +1147,7 @@ void Chunk::removeUnusedBlocks()
|
|
|
Framework::Logging::debug()
|
|
Framework::Logging::debug()
|
|
|
<< "chunk " << location.x << ", " << location.y
|
|
<< "chunk " << location.x << ", " << location.y
|
|
|
<< " was generated with " << count << " blocks.";
|
|
<< " was generated with " << count << " blocks.";
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int Chunk::getDimensionId() const
|
|
int Chunk::getDimensionId() const
|