Selaa lähdekoodia

remove unneeded chunks from memory

Kolja Strohm 3 vuotta sitten
vanhempi
commit
b4ccd85d6b

+ 3 - 3
FactoryCraft/AddChunkUpdate.cpp

@@ -5,7 +5,7 @@
 
 
 AddChunkUpdate::AddChunkUpdate( Chunk* chunk )
-    : WorldUpdate( AddChunkUpdateType::ID, chunk->getDimensionId(), Framework::Vec3<int>( chunk->getClock().x - CHUNK_SIZE / 2, chunk->getClock().y - CHUNK_SIZE / 2, 0 ), Framework::Vec3<int>( chunk->getClock().x + CHUNK_SIZE / 2, chunk->getClock().y + CHUNK_SIZE / 2, WORLD_HEIGHT - 1 ) ),
+    : WorldUpdate( AddChunkUpdateType::ID, chunk->getDimensionId(), Framework::Vec3<int>( chunk->getCenter().x - CHUNK_SIZE / 2, chunk->getCenter().y - CHUNK_SIZE / 2, 0 ), Framework::Vec3<int>( chunk->getCenter().x + CHUNK_SIZE / 2, chunk->getCenter().y + CHUNK_SIZE / 2, WORLD_HEIGHT - 1 ) ),
     chunk( chunk )
 {}
 
@@ -16,7 +16,7 @@ AddChunkUpdate::~AddChunkUpdate()
 
 void AddChunkUpdate::onUpdate( Dimension* zDimension )
 {
-    zDimension->addChunk( dynamic_cast<Chunk*>(chunk->getThis()) );
+    zDimension->setChunk( dynamic_cast<Chunk*>(chunk->getThis()), chunk->getCenter() );
 }
 
 void AddChunkUpdate::write( Framework::StreamWriter* zWriter )
@@ -24,7 +24,7 @@ void AddChunkUpdate::write( Framework::StreamWriter* zWriter )
     zWriter->schreibe( (char*)&AddChunkUpdateType::ID, 4 );
     int dimensionID = chunk->getDimensionId();
     zWriter->schreibe( (char*)&dimensionID, 4 );
-    Framework::Punkt center = chunk->getClock();
+    Framework::Punkt center = chunk->getCenter();
     zWriter->schreibe( (char*)&center.x, 4 );
     zWriter->schreibe( (char*)&center.y, 4 );
     chunk->save( zWriter );

+ 3 - 2
FactoryCraft/Area.cpp

@@ -1,6 +1,6 @@
 #include "Area.h"
 
-Direction opposite( Direction dir )
+Direction getOppositeDirection( Direction dir )
 {
     switch( dir )
     {
@@ -17,6 +17,7 @@ Direction opposite( Direction dir )
     case BOTTOM:
         return TOP;
     default:
+        assert( false );
         return NO_DIRECTION;
     }
 }
@@ -75,7 +76,7 @@ int getDirectionIndex( Direction dir )
     return -1;
 }
 
-Direction getFromIndex( int index )
+Direction getDirectionFromIndex( int index )
 {
     return (Direction)(1 << index);
 }

+ 2 - 2
FactoryCraft/Area.h

@@ -23,8 +23,8 @@ enum Direction
 };
 typedef int Directions;
 
-Direction opposite( Direction dir );
+Direction getOppositeDirection( Direction dir );
 Directions getDirections( Framework::Vec3<float> currentPos, Framework::Vec3<float> otherPos );
 Framework::Vec3<int> getDirection( Directions dir );
 int getDirectionIndex( Direction dir );
-Direction getFromIndex( int index );
+Direction getDirectionFromIndex( int index );

+ 103 - 9
FactoryCraft/Chunk.cpp

@@ -8,7 +8,8 @@ Chunk::Chunk( Framework::Punkt location, Game* zGame, int dimensionId )
     : ReferenceCounter(),
     zGame( zGame ),
     dimensionId( dimensionId ),
-    location( location )
+    location( location ),
+    added( 0 )
 {
     blocks = new Block * [ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
     blockIds = new unsigned short[ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
@@ -47,7 +48,7 @@ Framework::Either<Block*, int> Chunk::zBlockNeighbor( Framework::Vec3<int> locat
         else
             return (int)blockIds[ index ];
     }
-    if( location.z >= 0 && location.z < WORLD_HEIGHT )
+    if( added && location.z >= 0 && location.z < WORLD_HEIGHT )
         return zGame->zBlockAt( { location.x + this->location.x - CHUNK_SIZE / 2, location.y + this->location.y - CHUNK_SIZE / 2, location.z }, dimensionId );
     return 0;
 }
@@ -181,29 +182,59 @@ void Chunk::setNeighbor( Direction dir, Chunk* zChunk )
                 if( blocks[ index ] )
                 {
                     int j = (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z;
-                    if( zChunk->blocks[ j ] )
+                    if( zChunk && zChunk->blocks[ j ] )
                         blocks[ index ]->setNeighbour( NORTH, zChunk->blocks[ j ] );
                     else
-                        blocks[ index ]->setNeighbourType( NORTH, zChunk->blockIds[ j ] );
+                    {
+                        blocks[ index ]->setNeighbour( NORTH, 0 );
+                        blocks[ index ]->setNeighbourType( NORTH, zChunk ? zChunk->blockIds[ j ] : 0 );
+                    }
                 }
             }
             else if( dir == EAST )
             {
                 int index = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
                 if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( EAST, zChunk->blocks[ i * WORLD_HEIGHT + z ] );
+                {
+                    int j = i * WORLD_HEIGHT + z;
+                    if( zChunk && zChunk->blocks[ j ] )
+                        blocks[ index ]->setNeighbour( EAST, zChunk->blocks[ j ] );
+                    else
+                    {
+                        blocks[ index ]->setNeighbour( EAST, 0 );
+                        blocks[ index ]->setNeighbourType( EAST, zChunk ? zChunk->blockIds[ j ] : 0 );
+                    }
+                }
             }
             else if( dir == SOUTH )
             {
                 int index = (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z;
                 if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( SOUTH, zChunk->blocks[ i * CHUNK_SIZE * WORLD_HEIGHT + z ] );
+                {
+                    int j = i * CHUNK_SIZE * WORLD_HEIGHT + z;
+                    if( zChunk && zChunk->blocks[ j ] )
+                        blocks[ index ]->setNeighbour( SOUTH, zChunk->blocks[ j ] );
+                    else
+                    {
+                        blocks[ index ]->setNeighbour( SOUTH, 0 );
+                        blocks[ index ]->setNeighbourType( SOUTH, zChunk ? zChunk->blockIds[ j ] : 0 );
+                    }
+                }
             }
             else if( dir == WEST )
             {
                 int index = i * WORLD_HEIGHT + z;
                 if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z ] );
+                {
+                    int j = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
+                    if( zChunk && zChunk->blocks[ j ] )
+                        blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ j ] );
+                    else
+                    {
+                        blocks[ index ]->setNeighbour( WEST, 0 );
+                        blocks[ index ]->setNeighbourType( WEST, zChunk ? zChunk->blockIds[ j ] : 0 );
+                    }
+                }
             }
         }
     }
@@ -275,7 +306,7 @@ void Chunk::removeUnusedBlocks()
             {
                 for( int d = 0; d < 6 && !visible; d++ )
                 {
-                    auto n = zBlockNeighbor( getDirection( (Directions)getFromIndex( d ) ) + Framework::Vec3<int>( x, y, z ) );
+                    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()) )
@@ -289,6 +320,13 @@ void Chunk::removeUnusedBlocks()
             }
         }
     }
+    int count = 0;
+    for( int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++ )
+    {
+        if( blockIds[ i ] && blockIds[ i ] != AirBlockBlockType::ID )
+            count++;
+    }
+    std::cout << "chunk " << location.x << ", " << location.y << " was generated with " << count << " blocks.\n";
 }
 
 int Chunk::getDimensionId() const
@@ -296,7 +334,7 @@ int Chunk::getDimensionId() const
     return dimensionId;
 }
 
-Framework::Punkt Chunk::getClock() const
+Framework::Punkt Chunk::getCenter() const
 {
     return location;
 }
@@ -314,4 +352,60 @@ Framework::Vec3<int> Chunk::getMax() const
 Game* Chunk::zGameObj() const
 {
     return zGame;
+}
+
+void Chunk::prepareRemove()
+{
+    added = 0;
+    for( int i = 0; i < 4; i++ )
+    {
+        if( zNeighbours[ i ] )
+        {
+            zNeighbours[ i ]->setNeighbor( getOppositeDirection( getDirectionFromIndex( i ) ), 0 );
+            zNeighbours[ i ] = 0;
+        }
+    }
+}
+
+void Chunk::setAdded()
+{
+    added = 1;
+}
+
+void Chunk::addView( Entity* zEntity )
+{
+    cs.lock();
+    bool found = 0;
+    for( Entity* e : views )
+    {
+        if( e == zEntity )
+        {
+            found = 1;
+            break;
+        }
+    }
+    if( !found )
+        views.add( zEntity );
+    cs.unlock();
+}
+
+void Chunk::removeView( Entity* zEntity )
+{
+    cs.lock();
+    int i = 0;
+    for( Entity* e : views )
+    {
+        if( e == zEntity )
+        {
+            views.remove( i );
+            break;
+        }
+        i++;
+    }
+    cs.unlock();
+}
+
+bool Chunk::hasViews() const
+{
+    return views.getEintragAnzahl() > 0;
 }

+ 9 - 1
FactoryCraft/Chunk.h

@@ -20,6 +20,9 @@ private:
     Chunk* zNeighbours[ 4 ];
     unsigned short* blockIds;
     Framework::Either<Block*, int> zBlockNeighbor( Framework::Vec3<int> location );
+    bool added;
+    Framework::Critical cs;
+    Framework::Array<Entity*> views;
 
 public:
     Chunk( Framework::Punkt location, Game* zGame, int dimensionId );
@@ -39,8 +42,13 @@ public:
     void save( Framework::StreamWriter* zWriter );
     void removeUnusedBlocks();
     int getDimensionId() const;
-    Framework::Punkt getClock() const;
+    Framework::Punkt getCenter() const;
     Framework::Vec3<int> getMin() const;
     Framework::Vec3<int> getMax() const;
     Game* zGameObj() const;
+    void prepareRemove();
+    void setAdded();
+    void addView( Entity* zEntity );
+    void removeView( Entity* zEntity );
+    bool hasViews() const;
 };

+ 67 - 36
FactoryCraft/Dimension.cpp

@@ -83,47 +83,59 @@ void Dimension::addEntity( Entity* entity )
     entities->add( entity );
 }
 
-void Dimension::addChunk( Chunk* chunk )
+void Dimension::setChunk( Chunk* chunk, Punkt center )
 {
     char addr[ 8 ];
-    getAddrOfWorld( chunk->getClock(), addr );
-    if( !chunks->z( addr, 8 ) )
+    getAddrOfWorld( center, addr );
+    Chunk* old = chunks->z( addr, 8 );
+    if( old )
     {
-        chunks->set( addr, 8, chunk );
-        getAddrOfWorld( chunk->getClock() + Punkt( CHUNK_SIZE, 0 ), addr );
-        Chunk* zChunk = chunks->z( addr, 8 );
-        if( zChunk )
+        for( int i = 0; i < chunkList.getEintragAnzahl(); i++ )
         {
-            zChunk->setNeighbor( WEST, chunk );
-            chunk->setNeighbor( EAST, chunk );
-        }
-        getAddrOfWorld( chunk->getClock() + Punkt( -CHUNK_SIZE, 0 ), addr );
-        zChunk = chunks->z( addr, 8 );
-        if( zChunk )
-        {
-            zChunk->setNeighbor( EAST, chunk );
-            chunk->setNeighbor( WEST, chunk );
-        }
-        getAddrOfWorld( chunk->getClock() + Punkt( 0, CHUNK_SIZE ), addr );
-        zChunk = chunks->z( addr, 8 );
-        if( zChunk )
-        {
-            zChunk->setNeighbor( NORTH, chunk );
-            chunk->setNeighbor( SOUTH, chunk );
-        }
-        getAddrOfWorld( chunk->getClock() + Punkt( 0, -CHUNK_SIZE ), addr );
-        zChunk = chunks->z( addr, 8 );
-        if( zChunk )
-        {
-            zChunk->setNeighbor( SOUTH, chunk );
-            chunk->setNeighbor( NORTH, chunk );
+            if( chunkList.get( i ) == old )
+            {
+                chunkList.remove( i );
+                break;
+            }
         }
     }
-    else
+    chunks->set( addr, 8, chunk );
+    if( chunk )
+    {
+        chunkList.add( chunk );
+        chunk->setAdded();
+    }
+    getAddrOfWorld( center + Punkt( CHUNK_SIZE, 0 ), addr );
+    Chunk* zChunk = chunks->z( addr, 8 );
+    if( zChunk )
+    {
+        zChunk->setNeighbor( WEST, chunk );
+        if( chunk )
+            chunk->setNeighbor( EAST, zChunk );
+    }
+    getAddrOfWorld( center + Punkt( -CHUNK_SIZE, 0 ), addr );
+    zChunk = chunks->z( addr, 8 );
+    if( zChunk )
+    {
+        zChunk->setNeighbor( EAST, chunk );
+        if( chunk )
+            chunk->setNeighbor( WEST, zChunk );
+    }
+    getAddrOfWorld( center + Punkt( 0, CHUNK_SIZE ), addr );
+    zChunk = chunks->z( addr, 8 );
+    if( zChunk )
     {
-        std::cout << "WARNING: chunk duplication at dimension " << dimensionId << " at chunk " << chunk->getClock().x << ", " << chunk->getClock().y << "\n";
-        assert( false );
-        chunk->release();
+        zChunk->setNeighbor( NORTH, chunk );
+        if( chunk )
+            chunk->setNeighbor( SOUTH, zChunk );
+    }
+    getAddrOfWorld( center + Punkt( 0, -CHUNK_SIZE ), addr );
+    zChunk = chunks->z( addr, 8 );
+    if( zChunk )
+    {
+        zChunk->setNeighbor( SOUTH, chunk );
+        if( chunk )
+            chunk->setNeighbor( NORTH, zChunk );
     }
 }
 
@@ -135,9 +147,9 @@ void Dimension::save( Text worldDir ) const
             continue;
         Datei* file = new Datei();
         Text filePath = worldDir + "/dim/" + dimensionId + "/";
-        filePath.appendHex( chunk->getClock().x );
+        filePath.appendHex( chunk->getCenter().x );
         filePath += "_";
-        filePath.appendHex( chunk->getClock().y );
+        filePath.appendHex( chunk->getCenter().y );
         filePath += ".chunk";
         file->setDatei( filePath );
         if( file->open( Datei::Style::schreiben ) )
@@ -181,4 +193,23 @@ int Dimension::getDimensionId() const
 bool Dimension::hasChunck( int x, int y ) const
 {
     return zChunk( Punkt( x, y ) );
+}
+
+void Dimension::removeOldChunks()
+{
+    Array<int> removed;
+    int index = 0;
+    for( Chunk* chunk : chunkList )
+    {
+        if( !chunk->hasViews() )
+            removed.add( index, 0 );
+        index++;
+    }
+    for( int i : removed )
+    {
+        Chunk* chunk = chunkList.get( i );
+        // TODO: save chunk
+        chunk->prepareRemove();
+        setChunk( 0, chunk->getCenter() );
+    }
 }

+ 3 - 1
FactoryCraft/Dimension.h

@@ -11,6 +11,7 @@ class Dimension : public virtual Framework::ReferenceCounter
 private:
     int dimensionId;
     Framework::Trie<Chunk>* chunks;
+    Framework::Array<Chunk*> chunkList;
     Framework::RCArray<Entity>* entities;
     void getAddrOf( Framework::Punkt cPos, char* addr ) const;
     void getAddrOfWorld( Framework::Punkt wPos, char* addr ) const;
@@ -24,9 +25,10 @@ public:
 
     Framework::Either<Block*, int> zBlock( Framework::Vec3<int> location, const Game* zGame );
     void addEntity( Entity* entity );
-    void addChunk( Chunk* chunk );
+    void setChunk( Chunk* chunk, Framework::Punkt center );
     void save( Framework::Text worldDir ) const;
     int getDimensionId() const;
     bool hasChunck( int x, int y ) const;
     Chunk* zChunk( Framework::Punkt wPos ) const;
+    void removeOldChunks();
 };

+ 45 - 19
FactoryCraft/Game.cpp

@@ -69,6 +69,8 @@ void GameClient::sendWorldUpdate( WorldUpdate* update )
                     break;
                 index++;
             }
+            if( update->getType() == AddChunkUpdateType::ID )
+                ((AddChunkUpdate*)update)->zChunk()->addView( zPlayer );
             updateQueue.add( update, index );
             other.unlock();
             updateSync.notify();
@@ -106,13 +108,17 @@ void GameClient::reply( Game* zGame )
     if( first )
     {
         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 } );
@@ -123,17 +129,33 @@ void GameClient::reply( Game* zGame )
         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 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();
         for( auto client : *clients )
             client->reply( this );
+        cs.lock();
+        for( auto dim : *dimensions )
+            dim->removeOldChunks();
+        cs.unlock();
         m.messungEnde();
         double sec = m.getSekunden();
         if( sec < 0.05 )
@@ -349,13 +375,16 @@ GameClient* Game::addPlayer( FCKlient* client, Framework::Text name )
         player = (Player*)PlayerEntityType::INSTANCE->loadEntity( this, &pFile );
         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();
         Sleep( 1000 );
         cs.lock();
     }
+    zDimension( player->getCurrentDimensionId() )->addEntity( player );
     if( isNew )
     {
         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() );
         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();
     return dynamic_cast<GameClient*>(gameClient->getThis());
 }
@@ -386,7 +412,7 @@ bool Game::doesChunkExist( int x, int y, int dimension )
         for( WorldUpdate* update : *updates )
         {
             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();

+ 2 - 2
FactoryCraft/Inventory.cpp

@@ -187,13 +187,13 @@ void InventoryInteraction::endInteraction()
 void InventoryInteraction::pullItems( int count, ItemFilter* zFilter )
 {
     if( !current || !other ) return;
-    transaction( other, current, zFilter, opposite( dir ), dir, count );
+    transaction( other, current, zFilter, getOppositeDirection( dir ), dir, count );
 }
 
 void InventoryInteraction::pushItems( int count, ItemFilter* zFilter )
 {
     if( !current || !other ) return;
-    transaction( current, other, zFilter, dir, opposite( dir ), count );
+    transaction( current, other, zFilter, dir, getOppositeDirection( dir ), count );
 }
 
 

+ 1 - 1
FactoryCraft/NetworkResponse.cpp

@@ -28,7 +28,7 @@ void NetworkResponse::adressChunck( Chunk* zChunk )
     adress[ 0 ] = 1; // world response
     *(int*)(adress + 1) = zChunk->getDimensionId();
     adress[ 5 ] = 1; // chunck
-    Framework::Punkt center = zChunk->getClock();
+    Framework::Punkt center = zChunk->getCenter();
     *(int*)(adress + 6) = center.x;
     *(int*)(adress + 10) = center.y;
     minPosition = zChunk->getMin();