Browse Source

fix some issues

Kolja Strohm 3 years ago
parent
commit
ee51723fd7

+ 10 - 0
FactoryCraft/Block.cpp

@@ -135,6 +135,16 @@ int Block::getDimensionId() const
     return dimansionId;
 }
 
+bool Block::isVisible() const
+{
+    for( int i = 0; i < 6; i++ )
+    {
+        if( zNeighbours[ i ] == (Block*)AIR_BLOCK || (IS_BLOCK( zNeighbours[ i ] ) && zNeighbours[ i ]->isTransparent()))
+            return 1;
+    }
+    return 0;
+}
+
 
 BasicBlockItem::BasicBlockItem( const ItemType *zType, const char *name )
     : Item( zType, name )

+ 1 - 0
FactoryCraft/Block.h

@@ -78,6 +78,7 @@ public:
     float getSpeedModifier() const;
     const Framework::Vec3<int> getPos() const;
     int getDimensionId() const;
+    bool isVisible() const;
 
     friend BlockType;
 };

+ 57 - 19
FactoryCraft/Chunk.cpp

@@ -10,7 +10,7 @@ Chunk::Chunk( Framework::Punkt location, Game *zGame, int dimensionId )
     location( location )
 {
     blocks = new Block * [ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
-    Block *val = (Block*)AIR_BLOCK;
+    Block *val = (Block *)AIR_BLOCK;
     std::uninitialized_fill_n( blocks, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT, val );
     zNeighbours[ 0 ] = 0;
     zNeighbours[ 1 ] = 0;
@@ -34,6 +34,15 @@ Chunk::~Chunk()
     delete[] blocks;
 }
 
+Block *Chunk::zBlockNeighbor( Framework::Vec3<int> location )
+{
+    if( location.x >= 0 && location.x < CHUNK_SIZE && location.y <= 0 && location.y < CHUNK_SIZE && location.z >= 0 && location.z < WORLD_HEIGHT )
+        return blocks[ (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z ];
+    if( 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;
+}
+
 void Chunk::api( Framework::StreamReader *zRequest, NetworkResponse *zResponse )
 {
     // TODO: answer api messages
@@ -41,7 +50,8 @@ void Chunk::api( Framework::StreamReader *zRequest, NetworkResponse *zResponse )
 
 Block *Chunk::getBlockAt( Framework::Vec3<int> location ) const
 {
-    Block *result = zBlockAt(location);
+    assert( (location.x * CHUNK_SIZE + location.y) * CHUNK_SIZE + location.z < CHUNK_SIZE *CHUNK_SIZE *WORLD_HEIGHT );
+    Block *result = zBlockAt( location );
     if( result )
         return dynamic_cast<Block *>(result->getThis());
     return 0;
@@ -49,38 +59,46 @@ Block *Chunk::getBlockAt( Framework::Vec3<int> location ) const
 
 Block *Chunk::zBlockAt( Framework::Vec3<int> location ) const
 {
+    assert( (location.x * CHUNK_SIZE + location.y) * CHUNK_SIZE + location.z < CHUNK_SIZE *CHUNK_SIZE *WORLD_HEIGHT );
     return blocks[ (location.x * CHUNK_SIZE + location.y) * CHUNK_SIZE + location.z ];
 }
 
 void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
 {
     int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
+    assert( index < CHUNK_SIZE *CHUNK_SIZE *WORLD_HEIGHT );
     Block *old = blocks[ index ];
     blocks[ index ] = block;
-    Block *neighbor = zGame->zBlockAt( location + getDirection( NORTH ), dimensionId );
+    Block *neighbor = zBlockNeighbor( location + getDirection( NORTH ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( SOUTH, block );
-    block->setNeighbour( NORTH, neighbor );
-    neighbor = zGame->zBlockAt( location + getDirection( EAST ), dimensionId );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( NORTH, neighbor );
+    neighbor = zBlockNeighbor( location + getDirection( EAST ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( WEST, block );
-    block->setNeighbour( EAST, neighbor );
-    neighbor = zGame->zBlockAt( location + getDirection( SOUTH ), dimensionId );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( EAST, neighbor );
+    neighbor = zBlockNeighbor( location + getDirection( SOUTH ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( NORTH, block );
-    block->setNeighbour( SOUTH, neighbor );
-    neighbor = zGame->zBlockAt( location + getDirection( WEST ), dimensionId );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( SOUTH, neighbor );
+    neighbor = zBlockNeighbor( location + getDirection( WEST ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( EAST, block );
-    block->setNeighbour( WEST, neighbor );
-    neighbor = zGame->zBlockAt( location + getDirection( TOP ), dimensionId );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( WEST, neighbor );
+    neighbor = zBlockNeighbor( location + getDirection( TOP ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( BOTTOM, block );
-    block->setNeighbour( TOP, neighbor );
-    neighbor = zGame->zBlockAt( location + getDirection( BOTTOM ), dimensionId );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( TOP, neighbor );
+    neighbor = zBlockNeighbor( location + getDirection( BOTTOM ) );
     if( IS_BLOCK( neighbor ) )
         neighbor->setNeighbour( TOP, block );
-    block->setNeighbour( BOTTOM, neighbor );
+    if( IS_BLOCK( block ) )
+        block->setNeighbour( BOTTOM, neighbor );
     if( IS_BLOCK( old ) )
         old->release();
 }
@@ -95,25 +113,25 @@ void Chunk::setNeighbor( Direction dir, Chunk *zChunk )
             if( dir == NORTH )
             {
                 int index = i * CHUNK_SIZE * WORLD_HEIGHT + z;
-                if( IS_BLOCK(blocks[ index ]) )
+                if( IS_BLOCK( blocks[ index ] ) )
                     blocks[ index ]->setNeighbour( NORTH, zChunk->blocks[ (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z ] );
             }
             else if( dir == EAST )
             {
                 int index = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
-                if( IS_BLOCK(blocks[ index ]) )
+                if( IS_BLOCK( blocks[ index ] ) )
                     blocks[ index ]->setNeighbour( EAST, zChunk->blocks[ i * WORLD_HEIGHT + z ] );
             }
             else if( dir == SOUTH )
             {
                 int index = (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z;
-                if( IS_BLOCK(blocks[ index ]) )
+                if( IS_BLOCK( blocks[ index ] ) )
                     blocks[ index ]->setNeighbour( SOUTH, zChunk->blocks[ i * CHUNK_SIZE * WORLD_HEIGHT + z ] );
             }
             else if( dir == WEST )
             {
                 int index = i * WORLD_HEIGHT + z;
-                if( IS_BLOCK(blocks[ index ]) )
+                if( IS_BLOCK( blocks[ index ] ) )
                     blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z ] );
             }
         }
@@ -149,7 +167,7 @@ void Chunk::save( Framework::StreamWriter *zWriter )
             for( int z = 0; z < WORLD_HEIGHT; z++ )
             {
                 int index = (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
-                int blockType = blocks[ index ] ? blocks[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ]->zBlockType()->getId() : -1;
+                int blockType = IS_BLOCK(blocks[ index ]) ? blocks[ index ]->zBlockType()->getId() : -1;
                 zWriter->schreibe( (char *)&blockType, 4 );
                 if( blockType >= 0 )
                     StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( blocks[ index ], zWriter );
@@ -158,6 +176,26 @@ void Chunk::save( Framework::StreamWriter *zWriter )
     }
 }
 
+void Chunk::removeUnusedBlocks()
+{
+    bool removed = true;
+    while( removed )
+    {
+        removed = false;
+        for( int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++ )
+        {
+            if( IS_BLOCK( blocks[ i ] ) && !blocks[ i ]->isVisible() )
+            {
+                int x = (i / WORLD_HEIGHT) / CHUNK_SIZE;
+                int y = (i / WORLD_HEIGHT) % CHUNK_SIZE;
+                int z = i % WORLD_HEIGHT;
+                putBlockAt( { x,y,z }, 0 );
+                removed = true;
+            }
+        }
+    }
+}
+
 int Chunk::getDimensionId() const
 {
     return dimensionId;

+ 2 - 0
FactoryCraft/Chunk.h

@@ -17,6 +17,7 @@ private:
     Framework::Punkt location;
     Block **blocks;
     Chunk *zNeighbours[ 4 ];
+    Block *zBlockNeighbor( Framework::Vec3<int> location );
 
 public:
     Chunk( Framework::Punkt location, Game *zGame, int dimensionId );
@@ -31,6 +32,7 @@ public:
     void setNeighbor( Direction dir, Chunk *zChunk );
     void load( Framework::StreamReader *zReader );
     void save( Framework::StreamWriter *zWriter );
+    void removeUnusedBlocks();
     int getDimensionId() const;
     Framework::Punkt getCenter() const;
     Framework::Vec3<int> getMin() const;

+ 1 - 1
FactoryCraft/Dimension.cpp

@@ -103,7 +103,7 @@ void Dimension::addChunk( Chunk *chunk )
         zChunk = chunks->z( addr );
         if( zChunk )
         {
-            zChunk->setNeighbor( SOUTH, chunk ); // TODO: correct this in setBlock
+            zChunk->setNeighbor( SOUTH, chunk );
             chunk->setNeighbor( NORTH, chunk );
         }
     }

+ 4 - 0
FactoryCraft/Game.cpp

@@ -218,16 +218,20 @@ void Game::thread()
         cs.Leave();
         for( auto dim = dimensions->getIterator(); dim; dim++ )
             dim->tickEntities( this );
+        cs.Enter();
         while( updates->z( 0 ) )
         {
             WorldUpdate *update = updates->z( 0 );
+            cs.Leave();
             for( auto client = clients->getIterator(); client; client++ )
                 client->sendWorldUpdate( update );
             if( !zDimension( update->getAffectedDimension() ) )
                 addDimension( new Dimension( update->getAffectedDimension() ) );
             update->onUpdate( zDimension( update->getAffectedDimension() ) );
+            cs.Enter();
             updates->remove( 0 );
         }
+        cs.Leave();
         for( auto client = clients->getIterator(); client; client++ )
             client->reply( this );
         m.messungEnde();

+ 117 - 94
FactoryCraft/Inventory.cpp

@@ -197,24 +197,38 @@ void InventoryInteraction::pushItems( int count, ItemFilter *zFilter )
 }
 
 
-Inventory::Inventory( const Framework::Vec3<float> location )
+Inventory::Inventory( const Framework::Vec3<float> location, bool hasInventory )
     : ReferenceCounter(),
     location( location )
 {
-    pullSlotsOrder = new Framework::RCArray<ItemSlot>();
-    pushSlotsOrder = new Framework::RCArray<ItemSlot>();
-    itemCache = new Framework::HashMap<int, Framework::Array<ItemSlot *> *>( ITEM_CACHE_SIZE, std::_Identity<int>() );
+    if( hasInventory )
+    {
+        pullSlotsOrder = new Framework::RCArray<ItemSlot>();
+        pushSlotsOrder = new Framework::RCArray<ItemSlot>();
+        itemCache = new Framework::HashMap<int, Framework::Array<ItemSlot *> *>( ITEM_CACHE_SIZE, std::_Identity<int>() );
+    }
+    else
+    {
+        pullSlotsOrder = 0;
+        pushSlotsOrder = 0;
+        itemCache = 0;
+    }
 }
 
 Inventory::~Inventory()
 {
-    pullSlotsOrder->release();
-    pushSlotsOrder->release();
-    itemCache->release();
+    if( pullSlotsOrder )
+        pullSlotsOrder->release();
+    if( pushSlotsOrder )
+        pushSlotsOrder->release();
+    if( itemCache )
+        itemCache->release();
 }
 
 void Inventory::updateCache( ItemSlot *zSlot, int beforeKey )
 {
+    if( !itemCache )
+        return;
     int key = zSlot->zStack()->zItem()->zItemType()->getId();
     if( key == beforeKey )
         return;
@@ -261,12 +275,12 @@ void Inventory::addSlot( ItemSlot *slot )
 
 bool Inventory::allowPullStack( ItemSlot *zSlot, Direction dir )
 {
-    return true;
+    return pullSlotsOrder;
 }
 
 bool Inventory::allowPushStack( ItemSlot *zSlot, Direction dir, const Item *zItem, int &count )
 {
-    return true;
+    return pushSlotsOrder;
 }
 
 void Inventory::afterPullStack( ItemSlot *zSlot, Direction dir, const Item *zItem, int count )
@@ -277,131 +291,140 @@ void Inventory::afterPushStack( ItemSlot *zSlot, Direction dir, const Item *zIte
 
 void Inventory::loadInventory( Framework::StreamReader *zReader )
 {
-    for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++ )
+    if( itemCache )
     {
-        int size = 0;
-        zReader->lese( (char *)&size, 4 );
-        if( size != 0 )
+        for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++ )
         {
-            int id = 0;
-            zReader->lese( (char *)&id, 4 );
-            Item *item = StaticRegistry<ItemType>::INSTANCE.zElement( id )->loadItem( zReader );
-            iterator->addItems( new ItemStack( item, size ), NO_DIRECTION );
+            int size = 0;
+            zReader->lese( (char *)&size, 4 );
+            if( size != 0 )
+            {
+                int id = 0;
+                zReader->lese( (char *)&id, 4 );
+                Item *item = StaticRegistry<ItemType>::INSTANCE.zElement( id )->loadItem( zReader );
+                iterator->addItems( new ItemStack( item, size ), NO_DIRECTION );
+            }
         }
     }
 }
 
 void Inventory::saveInventory( Framework::StreamWriter *zWriter )
 {
-    for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++ )
+    if( itemCache )
     {
-        const ItemStack *stack = iterator->zStack();
-        int value = 0;
-        if( !stack || !stack->zItem() )
+        for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++ )
         {
-            zWriter->schreibe( (char *)&value, 4 );
-        }
-        else
-        {
-            value = stack->getSize();
-            zWriter->schreibe( (char *)&value, 4 );
-            value = stack->zItem()->zItemType()->getId();
-            zWriter->schreibe( (char *)&value, 4 );
-            stack->zItem()->zItemType()->saveItem( stack->zItem(), zWriter );
+            const ItemStack *stack = iterator->zStack();
+            int value = 0;
+            if( !stack || !stack->zItem() )
+            {
+                zWriter->schreibe( (char *)&value, 4 );
+            }
+            else
+            {
+                value = stack->getSize();
+                zWriter->schreibe( (char *)&value, 4 );
+                value = stack->zItem()->zItemType()->getId();
+                zWriter->schreibe( (char *)&value, 4 );
+                stack->zItem()->zItemType()->saveItem( stack->zItem(), zWriter );
+            }
         }
     }
 }
 
 void Inventory::localTransaction( Array< ItemSlot * > *zSourceSlots, Array< ItemSlot * > *zTargetSlots, ItemFilter *zFilter, int count )
 {
-    cs.Enter();
-    auto sourceSlot = zSourceSlots->getIterator();
-    for( auto targetSlot = zTargetSlots->getIterator(); targetSlot; )
+    if( itemCache )
     {
-        int amount = count;
-        if( !targetSlot->isFull() )
+        cs.Enter();
+        auto sourceSlot = zSourceSlots->getIterator();
+        for( auto targetSlot = zTargetSlots->getIterator(); targetSlot; )
         {
-            if( targetSlot->zStack() )
+            int amount = count;
+            if( !targetSlot->isFull() )
             {
-                Array<ItemSlot *> *zSurceListe = itemCache->safeGet( targetSlot->zStack()->zItem()->zItemType()->getId(), 0 );
-                if( zSurceListe )
+                if( targetSlot->zStack() )
                 {
-                    Array<int> toDelete;
-                    int index = 0;
-                    for( auto sourceSlot = zSurceListe->getIterator(); sourceSlot; sourceSlot++, index++ )
+                    Array<ItemSlot *> *zSurceListe = itemCache->safeGet( targetSlot->zStack()->zItem()->zItemType()->getId(), 0 );
+                    if( zSurceListe )
                     {
-                        if( zSourceSlots->getWertIndex( sourceSlot ) < 0 )
-                            continue;
-                        if( zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ) )
-                            continue;
-                        int number = MIN( targetSlot->numberOfAddableItems( sourceSlot->zStack(), NO_DIRECTION ), count );
-                        if( number > 0 )
+                        Array<int> toDelete;
+                        int index = 0;
+                        for( auto sourceSlot = zSurceListe->getIterator(); sourceSlot; sourceSlot++, index++ )
                         {
-                            ItemStack *stack = sourceSlot->takeItemsOut( number, NO_DIRECTION );
-                            if( stack )
+                            if( zSourceSlots->getWertIndex( sourceSlot ) < 0 )
+                                continue;
+                            if( zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ) )
+                                continue;
+                            int number = MIN( targetSlot->numberOfAddableItems( sourceSlot->zStack(), NO_DIRECTION ), count );
+                            if( number > 0 )
                             {
-                                if( !sourceSlot->zStack() )
-                                    toDelete.add( index, 0 );
-                                targetSlot->addItems( stack, NO_DIRECTION );
-                                if( stack->getSize() )
+                                ItemStack *stack = sourceSlot->takeItemsOut( number, NO_DIRECTION );
+                                if( stack )
                                 {
-                                    cs.Leave();
-                                    throw stack;
+                                    if( !sourceSlot->zStack() )
+                                        toDelete.add( index, 0 );
+                                    targetSlot->addItems( stack, NO_DIRECTION );
+                                    if( stack->getSize() )
+                                    {
+                                        cs.Leave();
+                                        throw stack;
+                                    }
+                                    stack->release();
+                                    count -= number;
+                                    if( count == 0 )
+                                        break;
                                 }
-                                stack->release();
-                                count -= number;
-                                if( count == 0 )
-                                    break;
                             }
                         }
+                        for( auto indexToDelete = toDelete.getIterator(); indexToDelete; indexToDelete++ )
+                            zSurceListe->remove( indexToDelete );
+                        if( count == 0 )
+                        {
+                            cs.Leave();
+                            return;
+                        }
                     }
-                    for( auto indexToDelete = toDelete.getIterator(); indexToDelete; indexToDelete++ )
-                        zSurceListe->remove( indexToDelete );
-                    if( count == 0 )
+                }
+                else
+                {
+                    while( sourceSlot && (!sourceSlot->zStack() || (zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ))) )
+                        sourceSlot++;
+                    if( !sourceSlot )
                     {
                         cs.Leave();
                         return;
                     }
-                }
-            }
-            else
-            {
-                while( sourceSlot && (!sourceSlot->zStack() || (zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ))) )
-                    sourceSlot++;
-                if( !sourceSlot )
-                {
-                    cs.Leave();
-                    return;
-                }
-                int number = MIN( targetSlot->numberOfAddableItems( sourceSlot->zStack(), NO_DIRECTION ), count );
-                if( number > 0 )
-                {
-                    ItemStack *stack = sourceSlot->takeItemsOut( number, NO_DIRECTION );
-                    if( stack )
+                    int number = MIN( targetSlot->numberOfAddableItems( sourceSlot->zStack(), NO_DIRECTION ), count );
+                    if( number > 0 )
                     {
-                        updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
-                        targetSlot->addItems( stack, NO_DIRECTION );
-                        updateCache( targetSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
-                        if( stack->getSize() )
-                        {
-                            cs.Leave();
-                            throw stack;
-                        }
-                        stack->release();
-                        count -= number;
-                        if( count == 0 )
+                        ItemStack *stack = sourceSlot->takeItemsOut( number, NO_DIRECTION );
+                        if( stack )
                         {
-                            cs.Leave();
-                            return;
+                            updateCache( sourceSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
+                            targetSlot->addItems( stack, NO_DIRECTION );
+                            updateCache( targetSlot, targetSlot->zStack()->zItem()->zItemType()->getId() );
+                            if( stack->getSize() )
+                            {
+                                cs.Leave();
+                                throw stack;
+                            }
+                            stack->release();
+                            count -= number;
+                            if( count == 0 )
+                            {
+                                cs.Leave();
+                                return;
+                            }
                         }
                     }
                 }
             }
+            if( amount == count || targetSlot->isFull() )
+                targetSlot++;
         }
-        if( amount == count || targetSlot->isFull() )
-            targetSlot++;
+        cs.Leave();
     }
-    cs.Leave();
 }
 
 InventoryInteraction Inventory::interactWith( Inventory *zInventory, Direction dir )

+ 1 - 1
FactoryCraft/Inventory.h

@@ -51,7 +51,7 @@ protected:
     virtual void saveInventory( Framework::StreamWriter *zWriter );
 
 public:
-    Inventory( const Framework::Vec3<float> location );
+    Inventory( const Framework::Vec3<float> location, bool hasInventory );
     virtual ~Inventory();
     InventoryInteraction interactWith( Inventory *zInventory, Direction dir );
 

+ 2 - 1
FactoryCraft/PerlinNoise.cpp

@@ -37,7 +37,7 @@ double PerlinNoise::getNoise( double x, double y, double z ) const
     double u = fade( x );
     double v = fade( y );
     double w = fade( z );
-
+    
     // Hash coordinates of the 8 cube corners
     int A = p[ X ] + Y;
     int AA = p[ A ] + Z;
@@ -48,6 +48,7 @@ double PerlinNoise::getNoise( double x, double y, double z ) const
 
     // Add blended results from 8 corners of cube
     double res = lerp( w, lerp( v, lerp( u, grad( p[ AA ], x, y, z ), grad( p[ BA ], x - 1, y, z ) ), lerp( u, grad( p[ AB ], x, y - 1, z ), grad( p[ BB ], x - 1, y - 1, z ) ) ), lerp( v, lerp( u, grad( p[ AA + 1 ], x, y, z - 1 ), grad( p[ BA + 1 ], x - 1, y, z - 1 ) ), lerp( u, grad( p[ AB + 1 ], x, y - 1, z - 1 ), grad( p[ BB + 1 ], x - 1, y - 1, z - 1 ) ) ) );
+    // TODO: why is res here allways 0?
     return ( res + 1.0 ) / 2.0;
 }
 

+ 2 - 2
FactoryCraft/TickQueue.cpp

@@ -22,7 +22,7 @@ void TickQueue::startNextTick( Framework::Array<Block *> *zSources )
     readPosition = 0;
     writePosition = 0;
     int count = zSources->getEintragAnzahl();
-    if( count <= maxSize )
+    if( count >= maxSize )
     {
         Block **temp = new Block * [ count + 1000 ];
         memcpy( queue, temp, sizeof( Block * ) * maxSize );
@@ -40,7 +40,7 @@ void TickQueue::startNextTick( Framework::Array<Block *> *zSources )
 void TickQueue::addToQueue( Block *zBlock )
 {
     std::unique_lock<std::mutex> lk( mutex );
-    if( writePosition <= maxSize )
+    if( writePosition >= maxSize )
     {
         Block **temp = new Block * [ maxSize + 1000 ];
         memcpy( queue, temp, sizeof( Block * ) * maxSize );

+ 1 - 0
FactoryCraft/WorldGenerator.cpp

@@ -50,6 +50,7 @@ void WorldGenerator::thread()
                 if( !zGame->doesChunkExist( x, y, next.dimensionId ) )
                 {
                     Chunk *generatedChunk = StaticRegistry<DimensionGenerator>::INSTANCE.zElement( next.dimensionId )->generateChunk( noise, zGame, x, y );
+                    generatedChunk->removeUnusedBlocks();
                     zGame->requestWorldUpdate( new AddChunkUpdate( generatedChunk ) );
                 }
             }