|
@@ -69,6 +69,8 @@ void GameClient::sendWorldUpdate( WorldUpdate* update )
|
|
break;
|
|
break;
|
|
index++;
|
|
index++;
|
|
}
|
|
}
|
|
|
|
+ if( update->getType() == AddChunkUpdateType::ID )
|
|
|
|
+ ((AddChunkUpdate*)update)->zChunk()->addView( zPlayer );
|
|
updateQueue.add( update, index );
|
|
updateQueue.add( update, index );
|
|
other.unlock();
|
|
other.unlock();
|
|
updateSync.notify();
|
|
updateSync.notify();
|
|
@@ -106,13 +108,17 @@ void GameClient::reply( Game* zGame )
|
|
if( first )
|
|
if( first )
|
|
{
|
|
{
|
|
first = 0;
|
|
first = 0;
|
|
- for( int xP = x - CHUNK_SIZE * viewDistance; xP <= x + CHUNK_SIZE * viewDistance; xP += CHUNK_SIZE )
|
|
|
|
|
|
+ Dimension* dim = zGame->zDimension( d );
|
|
|
|
+ if( dim )
|
|
{
|
|
{
|
|
- for( int yP = y - CHUNK_SIZE * viewDistance; yP <= y + CHUNK_SIZE * viewDistance; yP += CHUNK_SIZE )
|
|
|
|
|
|
+ for( int xP = x - CHUNK_SIZE * viewDistance; xP <= x + CHUNK_SIZE * viewDistance; xP += CHUNK_SIZE )
|
|
{
|
|
{
|
|
- Chunk* chunk = zGame->zDimension( d )->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
|
- if( chunk )
|
|
|
|
- sendWorldUpdate( new AddChunkUpdate( dynamic_cast<Chunk*>(chunk->getThis()) ) );
|
|
|
|
|
|
+ for( int yP = y - CHUNK_SIZE * viewDistance; yP <= y + CHUNK_SIZE * viewDistance; yP += CHUNK_SIZE )
|
|
|
|
+ {
|
|
|
|
+ Chunk* chunk = dim->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
|
+ if( chunk )
|
|
|
|
+ sendWorldUpdate( new AddChunkUpdate( dynamic_cast<Chunk*>(chunk->getThis()) ) );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
zGame->requestArea( { x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance, x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance, d } );
|
|
zGame->requestArea( { x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance, x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance, d } );
|
|
@@ -123,17 +129,33 @@ void GameClient::reply( Game* zGame )
|
|
Punkt curMin = zGame->getChunkCenter( x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance );
|
|
Punkt curMin = zGame->getChunkCenter( x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance );
|
|
Punkt lastMax = zGame->getChunkCenter( (int)lastPos.x + CHUNK_SIZE * viewDistance, (int)lastPos.y + CHUNK_SIZE * viewDistance );
|
|
Punkt lastMax = zGame->getChunkCenter( (int)lastPos.x + CHUNK_SIZE * viewDistance, (int)lastPos.y + CHUNK_SIZE * viewDistance );
|
|
Punkt curMax = zGame->getChunkCenter( x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance );
|
|
Punkt curMax = zGame->getChunkCenter( x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance );
|
|
- for( int xP = curMin.x; xP <= curMax.x; xP += CHUNK_SIZE )
|
|
|
|
|
|
+ Dimension* dim = zGame->zDimension( d );
|
|
|
|
+ if( dim )
|
|
{
|
|
{
|
|
- for( int yP = curMin.y; yP <= curMax.y; yP += CHUNK_SIZE )
|
|
|
|
|
|
+ for( int xP = curMin.x; xP <= curMax.x; xP += CHUNK_SIZE )
|
|
{
|
|
{
|
|
- if( xP < lastMin.x || xP > lastMax.x || yP < lastMin.y || yP > lastMax.y )
|
|
|
|
|
|
+ for( int yP = curMin.y; yP <= curMax.y; yP += CHUNK_SIZE )
|
|
{
|
|
{
|
|
- Chunk* chunk = zGame->zDimension( d )->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
|
- if( chunk )
|
|
|
|
- sendWorldUpdate( new AddChunkUpdate( dynamic_cast<Chunk*>(chunk->getThis()) ) );
|
|
|
|
- else
|
|
|
|
- zGame->requestArea( zGame->getChunckArea( zGame->getChunkCenter( xP, yP ) ) );
|
|
|
|
|
|
+ if( xP < lastMin.x || xP > lastMax.x || yP < lastMin.y || yP > lastMax.y )
|
|
|
|
+ {
|
|
|
|
+ Chunk* chunk = dim->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
|
+ if( chunk )
|
|
|
|
+ sendWorldUpdate( new AddChunkUpdate( dynamic_cast<Chunk*>(chunk->getThis()) ) );
|
|
|
|
+ else
|
|
|
|
+ zGame->requestArea( zGame->getChunckArea( zGame->getChunkCenter( xP, yP ) ) );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for( int xP = lastMin.x; xP <= lastMax.x; xP += CHUNK_SIZE )
|
|
|
|
+ {
|
|
|
|
+ for( int yP = lastMin.y; yP <= lastMax.y; yP += CHUNK_SIZE )
|
|
|
|
+ {
|
|
|
|
+ if( xP < curMin.x || xP > curMax.x || yP < curMin.y || yP > curMax.y )
|
|
|
|
+ {
|
|
|
|
+ Chunk* chunk = dim->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
|
+ if( chunk )
|
|
|
|
+ chunk->removeView( zPlayer );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -275,6 +297,10 @@ void Game::thread()
|
|
cs.unlock();
|
|
cs.unlock();
|
|
for( auto client : *clients )
|
|
for( auto client : *clients )
|
|
client->reply( this );
|
|
client->reply( this );
|
|
|
|
+ cs.lock();
|
|
|
|
+ for( auto dim : *dimensions )
|
|
|
|
+ dim->removeOldChunks();
|
|
|
|
+ cs.unlock();
|
|
m.messungEnde();
|
|
m.messungEnde();
|
|
double sec = m.getSekunden();
|
|
double sec = m.getSekunden();
|
|
if( sec < 0.05 )
|
|
if( sec < 0.05 )
|
|
@@ -349,13 +375,16 @@ GameClient* Game::addPlayer( FCKlient* client, Framework::Text name )
|
|
player = (Player*)PlayerEntityType::INSTANCE->loadEntity( this, &pFile );
|
|
player = (Player*)PlayerEntityType::INSTANCE->loadEntity( this, &pFile );
|
|
pFile.close();
|
|
pFile.close();
|
|
}
|
|
}
|
|
- requestArea( { (int)player->getPosition().x - DEFAULT_VIEW_DISTANCE * CHUNK_SIZE, (int)player->getPosition().y - DEFAULT_VIEW_DISTANCE * CHUNK_SIZE, (int)player->getPosition().x + DEFAULT_VIEW_DISTANCE * CHUNK_SIZE, (int)player->getPosition().y + DEFAULT_VIEW_DISTANCE * CHUNK_SIZE, player->getCurrentDimensionId() } );
|
|
|
|
- while( !zDimension( OverworldDimension::ID ) || (isNew && !zDimension( OverworldDimension::ID )->zChunk( getChunkCenter( (int)player->getPosition().x, (int)player->getPosition().y ) )) )
|
|
|
|
|
|
+ GameClient* gameClient = new GameClient( player, client );
|
|
|
|
+ clients->add( gameClient );
|
|
|
|
+ requestArea( getChunckArea( getChunkCenter( (int)player->getPosition().x, (int)player->getPosition().y ) ) );
|
|
|
|
+ while( !zDimension( player->getCurrentDimensionId() ) || (isNew && !zDimension( player->getCurrentDimensionId() )->zChunk( getChunkCenter( (int)player->getPosition().x, (int)player->getPosition().y ) )) )
|
|
{
|
|
{
|
|
cs.unlock();
|
|
cs.unlock();
|
|
Sleep( 1000 );
|
|
Sleep( 1000 );
|
|
cs.lock();
|
|
cs.lock();
|
|
}
|
|
}
|
|
|
|
+ zDimension( player->getCurrentDimensionId() )->addEntity( player );
|
|
if( isNew )
|
|
if( isNew )
|
|
{
|
|
{
|
|
Either<Block*, int> b = AirBlockBlockType::ID;
|
|
Either<Block*, int> b = AirBlockBlockType::ID;
|
|
@@ -364,9 +393,6 @@ GameClient* Game::addPlayer( FCKlient* client, Framework::Text name )
|
|
b = zBlockAt( { (int)player->getPosition().x, (int)player->getPosition().y, --h }, player->getCurrentDimensionId() );
|
|
b = zBlockAt( { (int)player->getPosition().x, (int)player->getPosition().y, --h }, player->getCurrentDimensionId() );
|
|
player->setPosition( { player->getPosition().x, player->getPosition().y, (float)h + 1.f } );
|
|
player->setPosition( { player->getPosition().x, player->getPosition().y, (float)h + 1.f } );
|
|
}
|
|
}
|
|
- zDimension( OverworldDimension::ID )->addEntity( player );
|
|
|
|
- GameClient* gameClient = new GameClient( player, client );
|
|
|
|
- clients->add( gameClient );
|
|
|
|
cs.unlock();
|
|
cs.unlock();
|
|
return dynamic_cast<GameClient*>(gameClient->getThis());
|
|
return dynamic_cast<GameClient*>(gameClient->getThis());
|
|
}
|
|
}
|
|
@@ -386,7 +412,7 @@ bool Game::doesChunkExist( int x, int y, int dimension )
|
|
for( WorldUpdate* update : *updates )
|
|
for( WorldUpdate* update : *updates )
|
|
{
|
|
{
|
|
if( update->getType() == AddChunkUpdateType::ID )
|
|
if( update->getType() == AddChunkUpdateType::ID )
|
|
- result |= ((AddChunkUpdate*)update)->zChunk()->getClock() == Framework::Punkt( x, y );
|
|
|
|
|
|
+ result |= ((AddChunkUpdate*)update)->zChunk()->getCenter() == Framework::Punkt( x, y );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cs.unlock();
|
|
cs.unlock();
|