|
@@ -84,13 +84,19 @@ void Chunk::sendLightToClient(Framework::StreamWriter* zWriter)
|
|
int bi = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
int bi = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
int type = blockIds[bi];
|
|
int type = blockIds[bi];
|
|
needSend |= type != NoBlockBlockType::ID && type != AirBlockBlockType::ID;
|
|
needSend |= type != NoBlockBlockType::ID && type != AirBlockBlockType::ID;
|
|
- if (needSend)
|
|
|
|
- break;
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- needSend = 1; // TODO: check if the block is visible
|
|
|
|
|
|
+ if (i < 4 && zNeighbours[i])
|
|
|
|
+ {
|
|
|
|
+ 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 |= type != NoBlockBlockType::ID && type != AirBlockBlockType::ID;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ if (needSend)
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (needSend)
|
|
if (needSend)
|
|
@@ -158,6 +164,7 @@ void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
sendLightToClient(&buffer);
|
|
sendLightToClient(&buffer);
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
NetworkMessage* msg = new NetworkMessage();
|
|
msg->addressDimension();
|
|
msg->addressDimension();
|
|
|
|
+ std::cout << "chunk size: " << buffer.getSize() << "b\n";
|
|
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());
|
|
@@ -239,7 +246,7 @@ void Chunk::initializeLightning()
|
|
for (int j = 0; j < 3; j++)
|
|
for (int j = 0; j < 3; j++)
|
|
newLight[j] = (unsigned char)MAX(newLight[j], i == getDirectionIndex(TOP) ? neighborLeight[j] : (unsigned char)((float)neighborLeight[j] * 0.8f));
|
|
newLight[j] = (unsigned char)MAX(newLight[j], i == getDirectionIndex(TOP) ? neighborLeight[j] : (unsigned char)((float)neighborLeight[j] * 0.8f));
|
|
for (int j = 3; j < 6; j++)
|
|
for (int j = 3; j < 6; j++)
|
|
- newLight[j] = (unsigned char)MAX(newLight[j], (unsigned char)((float)neighborLeight[j] * 0.8f));
|
|
|
|
|
|
+ newLight[j] = (unsigned char)MAX(newLight[j], (unsigned char)((float)neighborLeight[j] * 0.85f));
|
|
}
|
|
}
|
|
const Block* current = blocks[index] ? blocks[index] : StaticRegistry<BlockType>::INSTANCE.zElement(blockIds[index])->zDefault();
|
|
const Block* current = blocks[index] ? blocks[index] : StaticRegistry<BlockType>::INSTANCE.zElement(blockIds[index])->zDefault();
|
|
// add own light emission
|
|
// add own light emission
|
|
@@ -534,58 +541,49 @@ void Chunk::setNeighbor(Direction dir, Chunk* zChunk)
|
|
|
|
|
|
void Chunk::load(Framework::StreamReader* zReader)
|
|
void Chunk::load(Framework::StreamReader* zReader)
|
|
{
|
|
{
|
|
- unsigned short id = 0;
|
|
|
|
- zReader->lese((char*)&id, 2);
|
|
|
|
- Framework::Vec3<int> pos;
|
|
|
|
- bool d = 0;
|
|
|
|
- while (id)
|
|
|
|
|
|
+ for (int index = 0; index < WORLD_HEIGHT * CHUNK_SIZE * CHUNK_SIZE; index++)
|
|
{
|
|
{
|
|
- zReader->lese((char*)&pos.x, 4);
|
|
|
|
- zReader->lese((char*)&pos.y, 4);
|
|
|
|
- zReader->lese((char*)&pos.z, 4);
|
|
|
|
- zReader->lese((char*)&d, 1);
|
|
|
|
- if (d)
|
|
|
|
- putBlockAt(pos, StaticRegistry<BlockType>::INSTANCE.zElement(id)->loadBlock(Framework::Vec3<int>(pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z), zReader));
|
|
|
|
- else
|
|
|
|
- putBlockTypeAt(pos, id);
|
|
|
|
- zReader->lese((char*)&id, 2);
|
|
|
|
|
|
+ unsigned short blockType;
|
|
|
|
+ zReader->lese((char*)&blockType, 2);
|
|
|
|
+ if (blockType)
|
|
|
|
+ {
|
|
|
|
+ Framework::Vec3<int> pos = Framework::Vec3<int>((index / WORLD_HEIGHT) / CHUNK_SIZE, (index / WORLD_HEIGHT) % CHUNK_SIZE, index % WORLD_HEIGHT);
|
|
|
|
+ bool d;
|
|
|
|
+ zReader->lese((char*)&d, 1);
|
|
|
|
+ if (d)
|
|
|
|
+ {
|
|
|
|
+ putBlockAt(pos, StaticRegistry<BlockType>::INSTANCE.zElement(blockType)->loadBlock(Framework::Vec3<int>(pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z), zReader));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ putBlockTypeAt(pos, blockType);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
initializeLightning();
|
|
initializeLightning();
|
|
}
|
|
}
|
|
|
|
|
|
void Chunk::save(Framework::StreamWriter* zWriter)
|
|
void Chunk::save(Framework::StreamWriter* zWriter)
|
|
{
|
|
{
|
|
- for (int x = 0; x < CHUNK_SIZE; x++)
|
|
|
|
|
|
+ for (int index = 0; index < WORLD_HEIGHT * CHUNK_SIZE * CHUNK_SIZE; index++)
|
|
{
|
|
{
|
|
- for (int y = 0; y < CHUNK_SIZE; y++)
|
|
|
|
|
|
+ unsigned short blockType = blocks[index] ? (unsigned short)blocks[index]->zBlockType()->getId() : blockIds[index];
|
|
|
|
+ zWriter->schreibe((char*)&blockType, 2);
|
|
|
|
+ if (blockType)
|
|
{
|
|
{
|
|
- for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
|
|
|
+ if (blocks[index])
|
|
{
|
|
{
|
|
- int index = (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
|
|
|
|
- unsigned short blockType = blocks[index] ? (unsigned short)blocks[index]->zBlockType()->getId() : blockIds[index];
|
|
|
|
- if (blockType)
|
|
|
|
- {
|
|
|
|
- zWriter->schreibe((char*)&blockType, 2);
|
|
|
|
- zWriter->schreibe((char*)&x, 4);
|
|
|
|
- zWriter->schreibe((char*)&y, 4);
|
|
|
|
- zWriter->schreibe((char*)&z, 4);
|
|
|
|
- if (blocks[index])
|
|
|
|
- {
|
|
|
|
- bool d = 1;
|
|
|
|
- zWriter->schreibe((char*)&d, 1);
|
|
|
|
- StaticRegistry<BlockType>::INSTANCE.zElement(blockType)->saveBlock(blocks[index], zWriter);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- bool d = 0;
|
|
|
|
- zWriter->schreibe((char*)&d, 1);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ bool d = 1;
|
|
|
|
+ zWriter->schreibe((char*)&d, 1);
|
|
|
|
+ StaticRegistry<BlockType>::INSTANCE.zElement(blockType)->saveBlock(blocks[index], zWriter);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ bool d = 0;
|
|
|
|
+ zWriter->schreibe((char*)&d, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- unsigned short end = 0;
|
|
|
|
- zWriter->schreibe((char*)&end, 2);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Chunk::sendToClient(Framework::StreamWriter* zWriter)
|
|
void Chunk::sendToClient(Framework::StreamWriter* zWriter)
|
|
@@ -735,7 +733,7 @@ unsigned char* Chunk::getLightData(Framework::Vec3<int> location) const
|
|
return lightData + index;
|
|
return lightData + index;
|
|
}
|
|
}
|
|
|
|
|
|
-void Chunk::setLightData(Framework::Vec3<int> location, unsigned char* data)
|
|
|
|
|
|
+void Chunk::setLightData(Framework::Vec3<int> location, unsigned char* data, bool foreground)
|
|
{
|
|
{
|
|
int index = ((location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z) * 6;
|
|
int index = ((location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z) * 6;
|
|
memcpy(lightData + index, data, 6);
|
|
memcpy(lightData + index, data, 6);
|
|
@@ -769,7 +767,8 @@ void Chunk::setLightData(Framework::Vec3<int> location, unsigned char* data)
|
|
*(int*)(message + 1) = index / 6;
|
|
*(int*)(message + 1) = index / 6;
|
|
memcpy(message + 5, data, 6);
|
|
memcpy(message + 5, data, 6);
|
|
msg->setMessage(message, 11);
|
|
msg->setMessage(message, 11);
|
|
- msg->setUseBackground();
|
|
|
|
|
|
+ if (!foreground)
|
|
|
|
+ msg->setUseBackground();
|
|
notifyObservers(msg);
|
|
notifyObservers(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|