|
@@ -151,8 +151,14 @@ void Chunk::sendToClient(Framework::StreamWriter* zWriter, bool* instanceMap)
|
|
|
{
|
|
{
|
|
|
state |= 2;
|
|
state |= 2;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (blocks[z] && blocks[z][index]
|
|
|
|
|
+ && blocks[z][index]->getFrontDirection()
|
|
|
|
|
+ != type->getDefaultFrontDirection())
|
|
|
|
|
+ {
|
|
|
|
|
+ state |= 4;
|
|
|
|
|
+ }
|
|
|
zWriter->write((char*)&state, 1);
|
|
zWriter->write((char*)&state, 1);
|
|
|
- if ((state | 1) == state)
|
|
|
|
|
|
|
+ if (state & 1)
|
|
|
{
|
|
{
|
|
|
FluidBlock* fluidBlock
|
|
FluidBlock* fluidBlock
|
|
|
= blocks[z]
|
|
= blocks[z]
|
|
@@ -165,7 +171,7 @@ void Chunk::sendToClient(Framework::StreamWriter* zWriter, bool* instanceMap)
|
|
|
: 0;
|
|
: 0;
|
|
|
zWriter->write(&data, 1);
|
|
zWriter->write(&data, 1);
|
|
|
}
|
|
}
|
|
|
- if ((state | 2) == state)
|
|
|
|
|
|
|
+ if (state & 2)
|
|
|
{
|
|
{
|
|
|
float speedModifier
|
|
float speedModifier
|
|
|
= blocks[z] && blocks[z][index]
|
|
= blocks[z] && blocks[z][index]
|
|
@@ -173,6 +179,12 @@ void Chunk::sendToClient(Framework::StreamWriter* zWriter, bool* instanceMap)
|
|
|
: type->zDefault()->getSpeedModifier();
|
|
: type->zDefault()->getSpeedModifier();
|
|
|
zWriter->write((char*)&speedModifier, 4);
|
|
zWriter->write((char*)&speedModifier, 4);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (state & 4)
|
|
|
|
|
+ {
|
|
|
|
|
+ Direction frontDirection
|
|
|
|
|
+ = blocks[z][index]->getFrontDirection();
|
|
|
|
|
+ zWriter->write((char*)&frontDirection, 1);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -325,9 +337,8 @@ void Chunk::sendLightToClient(
|
|
|
zWriter->write((char*)&x, 4);
|
|
zWriter->write((char*)&x, 4);
|
|
|
zWriter->write((char*)&y, 4);
|
|
zWriter->write((char*)&y, 4);
|
|
|
zWriter->write((char*)&z, 4);
|
|
zWriter->write((char*)&z, 4);
|
|
|
- zWriter->write(
|
|
|
|
|
- (char*)(zNeighbours[dir]->lightData
|
|
|
|
|
- + index * 6),
|
|
|
|
|
|
|
+ zWriter->write((char*)(zNeighbours[dir]->lightData
|
|
|
|
|
+ + index * 6),
|
|
|
6);
|
|
6);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -362,8 +373,7 @@ bool Chunk::isVisible(int z, int index) const
|
|
|
{
|
|
{
|
|
|
Framework::Either<Block*, int> n = BlockTypeEnum::NO_BLOCK;
|
|
Framework::Either<Block*, int> n = BlockTypeEnum::NO_BLOCK;
|
|
|
Framework::Vec3<int> pos
|
|
Framework::Vec3<int> pos
|
|
|
- = getDirection((Directions)getDirectionFromIndex(d))
|
|
|
|
|
- + indexPos;
|
|
|
|
|
|
|
+ = getDirection(getDirectionFromIndex(d)) + indexPos;
|
|
|
if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
|
|
if (pos.x >= 0 && pos.x < CHUNK_SIZE && pos.y >= 0
|
|
|
&& pos.y < CHUNK_SIZE && pos.z >= 0 && pos.z < WORLD_HEIGHT)
|
|
&& pos.y < CHUNK_SIZE && pos.z >= 0 && pos.z < WORLD_HEIGHT)
|
|
|
{
|
|
{
|
|
@@ -961,40 +971,56 @@ void Chunk::putBlockTypeAt(Framework::Vec3<int> location, int type)
|
|
|
void Chunk::sendBlockInfo(Framework::Vec3<int> location)
|
|
void Chunk::sendBlockInfo(Framework::Vec3<int> location)
|
|
|
{
|
|
{
|
|
|
int index = Chunk::index(location.x, location.y);
|
|
int index = Chunk::index(location.x, location.y);
|
|
|
- char* msg = new char[14];
|
|
|
|
|
- msg[0] = 0; // set block
|
|
|
|
|
int typeId = blockIds[location.z] ? blockIds[location.z][index] : 0;
|
|
int typeId = blockIds[location.z] ? blockIds[location.z][index] : 0;
|
|
|
- *(unsigned short*)(msg + 1) = typeId;
|
|
|
|
|
- *(int*)(msg + 3) = index * WORLD_HEIGHT + location.z;
|
|
|
|
|
char state = 0;
|
|
char state = 0;
|
|
|
|
|
+ int size = 8;
|
|
|
const BlockType* type = Game::INSTANCE->zBlockType(typeId);
|
|
const BlockType* type = Game::INSTANCE->zBlockType(typeId);
|
|
|
if (type->isFluid())
|
|
if (type->isFluid())
|
|
|
{
|
|
{
|
|
|
state |= 1;
|
|
state |= 1;
|
|
|
|
|
+ size += 2;
|
|
|
}
|
|
}
|
|
|
if ((blocks[location.z] && blocks[location.z][index]
|
|
if ((blocks[location.z] && blocks[location.z][index]
|
|
|
&& blocks[location.z][index]->isPassable())
|
|
&& blocks[location.z][index]->isPassable())
|
|
|
|| (type->zDefault()->isPassable()))
|
|
|| (type->zDefault()->isPassable()))
|
|
|
{
|
|
{
|
|
|
state |= 2;
|
|
state |= 2;
|
|
|
|
|
+ size += 4;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (blocks[location.z] && blocks[location.z][index]
|
|
|
|
|
+ && blocks[location.z][index]->getFrontDirection()
|
|
|
|
|
+ != type->getDefaultFrontDirection())
|
|
|
|
|
+ {
|
|
|
|
|
+ state |= 4;
|
|
|
|
|
+ size += 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ char* msg = new char[size];
|
|
|
|
|
+ msg[0] = 0; // set block
|
|
|
|
|
+ *(unsigned short*)(msg + 1) = typeId;
|
|
|
|
|
+ *(int*)(msg + 3) = index * WORLD_HEIGHT + location.z;
|
|
|
msg[7] = state;
|
|
msg[7] = state;
|
|
|
- if ((state | 1) == state)
|
|
|
|
|
|
|
+ int i = 8;
|
|
|
|
|
+ if (state & 1)
|
|
|
{
|
|
{
|
|
|
FluidBlock* fluidBlock = dynamic_cast<FluidBlock*>(
|
|
FluidBlock* fluidBlock = dynamic_cast<FluidBlock*>(
|
|
|
blocks[location.z] ? blocks[location.z][index] : 0);
|
|
blocks[location.z] ? blocks[location.z][index] : 0);
|
|
|
- msg[8] = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
|
|
|
- msg[9] = fluidBlock ? fluidBlock->getDistanceToSource() : 0;
|
|
|
|
|
|
|
+ msg[i++] = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
|
|
|
+ msg[i++] = fluidBlock ? fluidBlock->getDistanceToSource() : 0;
|
|
|
}
|
|
}
|
|
|
- if ((state | 2) == state)
|
|
|
|
|
|
|
+ if (state & 2)
|
|
|
{
|
|
{
|
|
|
- *(float*)(msg + 10) = blocks[location.z] && blocks[location.z][index]
|
|
|
|
|
- ? blocks[location.z][index]->getSpeedModifier()
|
|
|
|
|
- : type->zDefault()->getSpeedModifier();
|
|
|
|
|
|
|
+ *(float*)(msg + i) = blocks[location.z] && blocks[location.z][index]
|
|
|
|
|
+ ? blocks[location.z][index]->getSpeedModifier()
|
|
|
|
|
+ : type->zDefault()->getSpeedModifier();
|
|
|
|
|
+ index += 4;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (state & 4)
|
|
|
|
|
+ {
|
|
|
|
|
+ *(msg + i++) = blocks[location.z][index]->getFrontDirection();
|
|
|
}
|
|
}
|
|
|
NetworkMessage* message = new NetworkMessage();
|
|
NetworkMessage* message = new NetworkMessage();
|
|
|
message->addressChunck(this);
|
|
message->addressChunck(this);
|
|
|
- message->setMessage(msg, 14);
|
|
|
|
|
|
|
+ message->setMessage(msg, size);
|
|
|
notifyObservers(message);
|
|
notifyObservers(message);
|
|
|
if (blocks[location.z] && blocks[location.z][index])
|
|
if (blocks[location.z] && blocks[location.z][index])
|
|
|
{
|
|
{
|