|
@@ -25,8 +25,8 @@ void GameClient::sendWorldUpdate( WorldUpdate *zUpdate )
|
|
|
{
|
|
|
if( zPlayer->getCurrentDimensionId() == zUpdate->getAffectedDimension() )
|
|
|
{
|
|
|
- auto pos = ( Vec3<int> )zPlayer->getPosition();
|
|
|
- if( abs( pos.x - zUpdate->getMinAffectedPoint().x ) < viewDistance * CHUNK_SIZE || ( abs( pos.x - zUpdate->getMaxAffectedPoint().x ) < viewDistance * CHUNK_SIZE ) || abs( pos.y - zUpdate->getMinAffectedPoint().y ) < viewDistance * CHUNK_SIZE || ( abs( pos.y - zUpdate->getMaxAffectedPoint().y ) < viewDistance * CHUNK_SIZE ) )
|
|
|
+ auto pos = (Vec3<int>)zPlayer->getPosition();
|
|
|
+ if( abs( pos.x - zUpdate->getMinAffectedPoint().x ) < viewDistance * CHUNK_SIZE || (abs( pos.x - zUpdate->getMaxAffectedPoint().x ) < viewDistance * CHUNK_SIZE) || abs( pos.y - zUpdate->getMinAffectedPoint().y ) < viewDistance * CHUNK_SIZE || (abs( pos.y - zUpdate->getMaxAffectedPoint().y ) < viewDistance * CHUNK_SIZE) )
|
|
|
{
|
|
|
cs.Enter();
|
|
|
writer.schreibe( (char *)&Message::INGAME_MESSAGE, 1 );
|
|
@@ -47,6 +47,20 @@ void GameClient::reply( Game *zGame )
|
|
|
int x = (int)zPlayer->getPosition().x;
|
|
|
int y = (int)zPlayer->getPosition().y;
|
|
|
int d = zPlayer->getCurrentDimensionId();
|
|
|
+ cs.Enter();
|
|
|
+ writer.schreibe( (char *)&Message::INGAME_MESSAGE, 1 );
|
|
|
+ writer.schreibe( (char *)&Message::POSITION_UPDATE, 1 );
|
|
|
+ float f = zPlayer->getPosition().x;
|
|
|
+ writer.schreibe( (char *)&f, 4 );
|
|
|
+ f = zPlayer->getPosition().y;
|
|
|
+ writer.schreibe( (char *)&f, 4 );
|
|
|
+ f = zPlayer->getPosition().z;
|
|
|
+ writer.schreibe( (char *)&f, 4 );
|
|
|
+ f = zPlayer->getFaceDir().x;
|
|
|
+ writer.schreibe( (char *)&f, 4 );
|
|
|
+ f = zPlayer->getFaceDir().y;
|
|
|
+ writer.schreibe( (char *)&f, 4 );
|
|
|
+ cs.Leave();
|
|
|
// send world to client
|
|
|
if( first )
|
|
|
{
|
|
@@ -58,7 +72,7 @@ void GameClient::reply( Game *zGame )
|
|
|
Chunk *chunk = zGame->zDimension( d )->zChunk( zGame->getChunkCenter( xP, yP ) );
|
|
|
if( chunk )
|
|
|
{
|
|
|
- AddChunkUpdate update( dynamic_cast<Chunk *>( chunk->getThis() ) );
|
|
|
+ AddChunkUpdate update( dynamic_cast<Chunk *>(chunk->getThis()) );
|
|
|
sendWorldUpdate( &update );
|
|
|
}
|
|
|
}
|
|
@@ -80,7 +94,7 @@ void GameClient::reply( Game *zGame )
|
|
|
Chunk *chunk = zGame->zDimension( d )->zChunk( zGame->getChunkCenter( x, y ) );
|
|
|
if( chunk )
|
|
|
{
|
|
|
- AddChunkUpdate update( dynamic_cast<Chunk *>( chunk->getThis() ) );
|
|
|
+ AddChunkUpdate update( dynamic_cast<Chunk *>(chunk->getThis()) );
|
|
|
sendWorldUpdate( &update );
|
|
|
}
|
|
|
else
|
|
@@ -143,7 +157,7 @@ Game::Game( Framework::Text name, Framework::Text worldsDir )
|
|
|
updates( new RCArray<WorldUpdate>() ),
|
|
|
clients( new RCArray<GameClient>() ),
|
|
|
ticker( new TickOrganizer() ),
|
|
|
- path( (const char *)( worldsDir + "/" + name ) ),
|
|
|
+ path( (const char *)(worldsDir + "/" + name) ),
|
|
|
stop( 0 ),
|
|
|
tickId( 0 ),
|
|
|
nextEntityId( 0 ),
|
|
@@ -163,7 +177,7 @@ Game::Game( Framework::Text name, Framework::Text worldsDir )
|
|
|
int seed = 0;
|
|
|
int index = 0;
|
|
|
for( char *n = name; *n; n++ )
|
|
|
- seed += (int)pow( (float)*n * 31, ( float )++index );
|
|
|
+ seed += (int)pow( (float)*n * 31, (float)++index );
|
|
|
generator = new WorldGenerator( seed, this );
|
|
|
loader = new WorldLoader( this );
|
|
|
start();
|
|
@@ -219,7 +233,7 @@ void Game::thread()
|
|
|
m.messungEnde();
|
|
|
double sec = m.getSekunden();
|
|
|
if( sec < 0.05 )
|
|
|
- Sleep( (int)( ( 0.05 - sec ) * 1000 ) );
|
|
|
+ Sleep( (int)((0.05 - sec) * 1000) );
|
|
|
}
|
|
|
save();
|
|
|
}
|
|
@@ -272,9 +286,12 @@ GameClient *Game::addPlayer( FCKlient *client, Framework::Text name )
|
|
|
Datei pFile;
|
|
|
pFile.setDatei( path + "/player/" + name );
|
|
|
Player *player;
|
|
|
+ bool isNew = 0;
|
|
|
if( !pFile.existiert() || !pFile.open( Datei::Style::lesen ) )
|
|
|
{
|
|
|
player = (Player *)PlayerEntityType::INSTANCE->createEntityAt( Vec3<float>( 0, 0, 0 ), OverworldDimension::ID, this );
|
|
|
+ player->setName( name );
|
|
|
+ isNew = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -282,23 +299,36 @@ GameClient *Game::addPlayer( FCKlient *client, Framework::Text name )
|
|
|
pFile.close();
|
|
|
}
|
|
|
requestArea( { (int)player->getPosition().x - 100, (int)player->getPosition().y - 100, (int)player->getPosition().x + 100, (int)player->getPosition().y + 100, player->getCurrentDimensionId() } );
|
|
|
- while( !zDimension( OverworldDimension::ID ) )
|
|
|
+ while( !zDimension( OverworldDimension::ID ) || (isNew && !zDimension( OverworldDimension::ID )->zChunk( getChunkCenter( (int)player->getPosition().x, (int)player->getPosition().y ) )) )
|
|
|
{
|
|
|
cs.Leave();
|
|
|
Sleep( 1000 );
|
|
|
cs.Enter();
|
|
|
}
|
|
|
+ if( isNew )
|
|
|
+ {
|
|
|
+ Block *b = 0;
|
|
|
+ int h = WORLD_HEIGHT;
|
|
|
+ while( !IS_BLOCK( b ) && h > 0 )
|
|
|
+ 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 } );
|
|
|
+ }
|
|
|
zDimension( OverworldDimension::ID )->addEntity( player );
|
|
|
GameClient *gameClient = new GameClient( player, client );
|
|
|
clients->add( gameClient );
|
|
|
cs.Leave();
|
|
|
- return dynamic_cast<GameClient *>( gameClient->getThis() );
|
|
|
+ return dynamic_cast<GameClient *>(gameClient->getThis());
|
|
|
}
|
|
|
|
|
|
-bool Game::doesChunkExist( int x, int y, int dimension ) const
|
|
|
+bool Game::isChunkLoaded( int x, int y, int dimension ) const
|
|
|
{
|
|
|
Dimension *dim = zDimension( dimension );
|
|
|
- return ( dim && dim->hasChunck( x, y ) ) || loader->existsChunk( x, y, dimension );
|
|
|
+ return (dim && dim->hasChunck( x, y ));
|
|
|
+}
|
|
|
+
|
|
|
+bool Game::doesChunkExist( int x, int y, int dimension ) const
|
|
|
+{
|
|
|
+ return isChunkLoaded( x, y, dimension ) || loader->existsChunk( x, y, dimension );
|
|
|
}
|
|
|
|
|
|
Block *Game::zBlockAt( Framework::Vec3<int> location, int dimension ) const
|
|
@@ -321,7 +351,7 @@ Dimension *Game::zDimension( int id ) const
|
|
|
|
|
|
Framework::Punkt Game::getChunkCenter( int x, int y ) const
|
|
|
{
|
|
|
- return Punkt( (int)floor( ( (float)x + CHUNK_SIZE / 2 ) / CHUNK_SIZE ), (int)floor( ( (float)y + CHUNK_SIZE / 2 ) / CHUNK_SIZE ) );
|
|
|
+ return Punkt( (x / CHUNK_SIZE) * CHUNK_SIZE + (x < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2, (y / CHUNK_SIZE) * CHUNK_SIZE + (y < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2 );
|
|
|
}
|
|
|
|
|
|
Area Game::getChunckArea( Punkt center ) const
|