|
@@ -242,30 +242,27 @@ void Chunk::setNeighbor( Direction dir, Chunk* zChunk )
|
|
|
|
|
|
void Chunk::load( Framework::StreamReader* zReader )
|
|
|
{
|
|
|
- // TODO: adjust this to new way to save chunks
|
|
|
- zReader->lese( (char*)blockIds, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof( unsigned short ) );
|
|
|
- for( int x = 0; x < CHUNK_SIZE; x++ )
|
|
|
+ unsigned short id = 0;
|
|
|
+ zReader->lese( (char*)&id, 2 );
|
|
|
+ Framework::Vec3<int> pos;
|
|
|
+ bool d = 0;
|
|
|
+ while( id )
|
|
|
{
|
|
|
- for( int y = 0; y < CHUNK_SIZE; y++ )
|
|
|
- {
|
|
|
- for( int z = 0; z < WORLD_HEIGHT; z++ )
|
|
|
- {
|
|
|
- unsigned short blockType;
|
|
|
- zReader->lese( (char*)&blockType, 2 );
|
|
|
- Block* block = StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->loadBlock( Framework::Vec3<int>( x, y, z ), zGame, zReader );
|
|
|
- if( block )
|
|
|
- putBlockAt( { x, y, z }, block );
|
|
|
- else
|
|
|
- putBlockTypeAt( { x, y, z }, blockIds[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ] );
|
|
|
- }
|
|
|
- }
|
|
|
+ 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 ), zGame, zReader ) );
|
|
|
+ else
|
|
|
+ putBlockTypeAt( pos, id );
|
|
|
+
|
|
|
+ zReader->lese( (char*)&id, 2 );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Chunk::save( Framework::StreamWriter* zWriter )
|
|
|
+void Chunk::save( Framework::StreamWriter* zWriter, StreamTarget target )
|
|
|
{
|
|
|
- // TODO: check if target is client or file
|
|
|
- // if client then only transfer visible blocks
|
|
|
for( int x = 0; x < CHUNK_SIZE; x++ )
|
|
|
{
|
|
|
for( int y = 0; y < CHUNK_SIZE; y++ )
|
|
@@ -276,20 +273,45 @@ void Chunk::save( Framework::StreamWriter* zWriter )
|
|
|
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 visible = target == StreamTarget::FULL;
|
|
|
+ if( !visible )
|
|
|
{
|
|
|
- bool d = 1;
|
|
|
- zWriter->schreibe( (char*)&d, 1 );
|
|
|
- StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( blocks[ index ], zWriter );
|
|
|
+ if( !blocks[ index ] )
|
|
|
+ {
|
|
|
+ if( CONST_BLOCK( 0, blockIds[ index ] )->isTransparent() || CONST_BLOCK( 0, blockIds[ index ] )->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 ) );
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ visible = blocks[ index ]->isVisible();
|
|
|
}
|
|
|
- else
|
|
|
+ if( target == StreamTarget::FULL || (visible && (blocks[ index ] || blockType != AirBlockBlockType::ID)) )
|
|
|
{
|
|
|
- bool d = 0;
|
|
|
- zWriter->schreibe( (char*)&d, 1 );
|
|
|
+ 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 );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|