Browse Source

fixed some bugs

Kolja Strohm 3 years ago
parent
commit
5ece5d5ea1

+ 1 - 0
FactoryCraft/Block.cpp

@@ -20,6 +20,7 @@ Block::Block( const BlockType *zType, ItemType *zTool, Framework::Vec3<int> pos
     tickSource = 0;
     currentTickTimeout = 0;
     dimansionId = 0;
+    memset( zNeighbours, 0, sizeof( Block * ) * 6 );
 }
 
 Block::~Block()

+ 1 - 1
FactoryCraft/Block.h

@@ -16,7 +16,7 @@ class BasicBlockItemType;
 class TickQueue;
 
 #define AIR_BLOCK -1
-#define IS_BLOCK(b) b > 0
+#define IS_BLOCK(b) (((__int64)b) > 0)
 
 class Block : public Inventory
 {

+ 24 - 27
FactoryCraft/Chunk.cpp

@@ -10,7 +10,8 @@ Chunk::Chunk( Framework::Punkt location, Game *zGame, int dimensionId )
     location( location )
 {
     blocks = new Block * [ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
-    memset( blocks, AIR_BLOCK, sizeof( Block * ) * CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT );
+    Block *val = (Block*)AIR_BLOCK;
+    std::uninitialized_fill_n( blocks, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT, val );
     zNeighbours[ 0 ] = 0;
     zNeighbours[ 1 ] = 0;
     zNeighbours[ 2 ] = 0;
@@ -40,24 +41,20 @@ void Chunk::api( Framework::StreamReader *zRequest, NetworkResponse *zResponse )
 
 Block *Chunk::getBlockAt( Framework::Vec3<int> location ) const
 {
-    location.x += CHUNK_SIZE / 2;
-    location.y += CHUNK_SIZE / 2;
-    Block *result = dynamic_cast<Block *>( blocks[ ( location.x * CHUNK_SIZE + location.y ) * CHUNK_SIZE + location.z ]->getThis() );
-    return result;
+    Block *result = zBlockAt(location);
+    if( result )
+        return dynamic_cast<Block *>(result->getThis());
+    return 0;
 }
 
 Block *Chunk::zBlockAt( Framework::Vec3<int> location ) const
 {
-    location.x += CHUNK_SIZE / 2;
-    location.y += CHUNK_SIZE / 2;
-    return blocks[ ( location.x * CHUNK_SIZE + location.y ) * CHUNK_SIZE + location.z ];
+    return blocks[ (location.x * CHUNK_SIZE + location.y) * CHUNK_SIZE + location.z ];
 }
 
 void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
 {
-    location.x -= this->location.x - CHUNK_SIZE / 2;
-    location.y -= this->location.x - CHUNK_SIZE / 2;
-    int index = ( location.x * CHUNK_SIZE + location.y ) * CHUNK_SIZE + location.z;
+    int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
     Block *old = blocks[ index ];
     blocks[ index ] = block;
     Block *neighbor = zGame->zBlockAt( location + getDirection( NORTH ), dimensionId );
@@ -69,8 +66,8 @@ void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
         neighbor->setNeighbour( WEST, block );
     block->setNeighbour( EAST, neighbor );
     neighbor = zGame->zBlockAt( location + getDirection( SOUTH ), dimensionId );
-    if( IS_BLOCK( neighbor ) ) {}
-    neighbor->setNeighbour( NORTH, block );
+    if( IS_BLOCK( neighbor ) )
+        neighbor->setNeighbour( NORTH, block );
     block->setNeighbour( SOUTH, neighbor );
     neighbor = zGame->zBlockAt( location + getDirection( WEST ), dimensionId );
     if( IS_BLOCK( neighbor ) )
@@ -97,27 +94,27 @@ void Chunk::setNeighbor( Direction dir, Chunk *zChunk )
         {
             if( dir == NORTH )
             {
-                int index = i * CHUNK_SIZE * CHUNK_SIZE + z;
-                if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( NORTH, zChunk->blocks[ ( i * CHUNK_SIZE + CHUNK_SIZE - 1 ) * CHUNK_SIZE + z ] );
+                int index = i * CHUNK_SIZE * WORLD_HEIGHT + z;
+                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 ) * CHUNK_SIZE + z;
-                if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( EAST, zChunk->blocks[ i * CHUNK_SIZE + z ] );
+                int index = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
+                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 ) * CHUNK_SIZE + z;
-                if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( SOUTH, zChunk->blocks[ i * CHUNK_SIZE * CHUNK_SIZE + z ] );
+                int index = (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z;
+                if( IS_BLOCK(blocks[ index ]) )
+                    blocks[ index ]->setNeighbour( SOUTH, zChunk->blocks[ i * CHUNK_SIZE * WORLD_HEIGHT + z ] );
             }
             else if( dir == WEST )
             {
-                int index = i * CHUNK_SIZE + z;
-                if( blocks[ index ] )
-                    blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ ( ( CHUNK_SIZE - 1 ) * CHUNK_SIZE + i ) * CHUNK_SIZE + z ] );
+                int index = i * WORLD_HEIGHT + z;
+                if( IS_BLOCK(blocks[ index ]) )
+                    blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z ] );
             }
         }
     }
@@ -151,8 +148,8 @@ void Chunk::save( Framework::StreamWriter *zWriter )
         {
             for( int z = 0; z < WORLD_HEIGHT; z++ )
             {
-                int index = ( x * CHUNK_SIZE + y ) * CHUNK_SIZE + z;
-                int blockType = blocks[ index ] ? blocks[ ( x * CHUNK_SIZE + y ) * CHUNK_SIZE + z ]->zBlockType()->getId() : -1;
+                int index = (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
+                int blockType = blocks[ index ] ? blocks[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ]->zBlockType()->getId() : -1;
                 zWriter->schreibe( (char *)&blockType, 4 );
                 if( blockType >= 0 )
                     StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->saveBlock( blocks[ index ], zWriter );

+ 5 - 3
FactoryCraft/Dimension.cpp

@@ -47,8 +47,7 @@ void Dimension::getAddrOf( Punkt cPos, char *addr ) const
 
 void Dimension::getAddrOfWorld( Punkt wPos, char *addr ) const
 {
-    wPos.x = (int)floor( ( (float)wPos.x + CHUNK_SIZE / 2 ) / CHUNK_SIZE );
-    wPos.y = (int)floor( ( (float)wPos.y + CHUNK_SIZE / 2 ) / CHUNK_SIZE );
+    wPos /= CHUNK_SIZE;
     getAddrOf( wPos, addr );
 }
 
@@ -61,7 +60,10 @@ Chunk *Dimension::zChunk( Punkt wPos ) const
 
 Block *Dimension::zBlock( Vec3<int> location )
 {
-    return zChunk( Punkt( location.x, location.y ) )->zBlockAt( Vec3<int>( ( location.x + CHUNK_SIZE / 2 ) % CHUNK_SIZE, ( location.y + CHUNK_SIZE / 2 ) % CHUNK_SIZE, location.z ) );
+    Chunk *c = zChunk( Punkt( location.x, location.y ) );
+    if( c )
+        return c->zBlockAt( Vec3<int>( location.x % CHUNK_SIZE, location.y % CHUNK_SIZE, location.z ) );
+    return 0;
 }
 
 void Dimension::addEntity( Entity *entity )

+ 1 - 1
FactoryCraft/DimensionGenerator.cpp

@@ -70,7 +70,7 @@ Chunk *DimensionGenerator::generateChunk( Noise *zNoise, Game *zGame, int center
                 {
                     Block *actualBlock = actualBiom->getBlock( zNoise, x + centerX, y + centerY, z, zGame );
                     Block *neighborBlock = neighborBiom->getBlock( zNoise, x + centerX, y + centerY, z, zGame );
-                    chunk->putBlockAt( Framework::Vec3<int>( x + centerX, y + centerY, z ), interpolator->interpolateBlocks( actualBlock, neighborBlock, actualHeight, neighborWeight, zNoise ) );
+                    chunk->putBlockAt( Framework::Vec3<int>( x + CHUNK_SIZE / 2, y + CHUNK_SIZE / 2, z ), interpolator->interpolateBlocks( actualBlock, neighborBlock, actualHeight, neighborWeight, zNoise ) );
                 }
             }
         }

+ 7 - 0
FactoryCraft/Entity.cpp

@@ -2,6 +2,8 @@
 
 Entity::Entity( const EntityType *zType, Framework::Vec3<float> location, int dimensionId, int entityId )
     : Inventory( location ),
+    speed( 0, 0, 0 ),
+    faceDir( 1, 0 ),
     zEntityType( zType ),
     currentDimensionId( dimensionId ),
     removed( 0 ),
@@ -71,6 +73,11 @@ Framework::Vec3<float> Entity::getSpeed() const
     return speed;
 }
 
+Framework::Vec2<float> Entity::getFaceDir() const
+{
+    return faceDir;
+}
+
 Framework::Vec3<float> Entity::getPosition() const
 {
     return location;

+ 3 - 0
FactoryCraft/Entity.h

@@ -2,6 +2,7 @@
 
 #include <ReferenceCounter.h>
 #include <Vec3.h>
+#include <Vec2.h>
 
 #include "Effect.h"
 #include "Inventory.h"
@@ -23,6 +24,7 @@ protected:
     float thirst;
     float maxThirst;
     Framework::Vec3<float> speed;
+    Framework::Vec2<float> faceDir;
     const EntityType *zEntityType;
     int currentDimensionId;
     bool removed;
@@ -46,6 +48,7 @@ public:
     float getThirst() const;
     float getMaxThirst() const;
     Framework::Vec3<float> getSpeed() const;
+    Framework::Vec2<float> getFaceDir() const;
     Framework::Vec3<float> getPosition() const;
     int getCurrentDimensionId() const;
     bool isRemoved() const;

+ 4 - 0
FactoryCraft/EntityType.cpp

@@ -24,6 +24,8 @@ void EntityType::loadSuperEntity( Entity *zEntity, Framework::StreamReader *zRea
     zReader->lese( (char *)&zEntity->speed.x, 4 );
     zReader->lese( (char *)&zEntity->speed.y, 4 );
     zReader->lese( (char *)&zEntity->speed.z, 4 );
+    zReader->lese( (char *)&zEntity->faceDir.x, 4 );
+    zReader->lese( (char *)&zEntity->faceDir.y, 4 );
     zReader->lese( (char *)&zEntity->currentDimensionId, 4 );
 }
 
@@ -42,6 +44,8 @@ void EntityType::saveSuperEntity( Entity *zEntity, Framework::StreamWriter *zWri
     zWriter->schreibe( (char *)&zEntity->speed.x, 4 );
     zWriter->schreibe( (char *)&zEntity->speed.y, 4 );
     zWriter->schreibe( (char *)&zEntity->speed.z, 4 );
+    zWriter->schreibe( (char *)&zEntity->faceDir.x, 4 );
+    zWriter->schreibe( (char *)&zEntity->faceDir.y, 4 );
     zWriter->schreibe( (char *)&zEntity->currentDimensionId, 4 );
 }
 

+ 2 - 2
FactoryCraft/FactoryCraft.vcxproj

@@ -82,7 +82,7 @@
     <RemoteProjectDir>$(RemoteRootDir)/Server/$(ProjectName)/debug</RemoteProjectDir>
     <IncludePath>..\..\..\..\..\Allgemein\Framework;../../../Framework/debug;..\..\..\..\..\Allgemein\Network\Network;../../../Network/debug/Network;../../../KsgScript/debug/KsgScript;..\..\..\..\..\Allgemein\KSGScript\KSGScript\Include;$(IncludePath)</IncludePath>
     <RemoteTargetPath>$(RemoteProjectDir)/$(TargetName)$(TargetExt)</RemoteTargetPath>
-    <RemoteLinkLocalCopyOutput>false</RemoteLinkLocalCopyOutput>
+    <RemoteLinkLocalCopyOutput>true</RemoteLinkLocalCopyOutput>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <OutDir>$(RemoteRootDir)/Server/$(ProjectName)/release/</OutDir>
@@ -171,7 +171,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
     <Link>
       <AdditionalLibraryDirectories>$(RemoteRootDir)/sql/debug;$(RemoteRootDir)/Network/debug;$(RemoteRootDir)/Framework/debug;/usr/lib/;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <LibraryDependencies>dbgFramework;dbgNetwork;pthread;ssl</LibraryDependencies>
+      <LibraryDependencies>dbgFramework;dbgNetwork;dbgSQL;pq;pthread;ssl</LibraryDependencies>
       <AdditionalOptions>-Wl,-rpath,../lib %(AdditionalOptions)</AdditionalOptions>
       <OutputFile>$(RemoteProjectDir)/$(TargetName)$(TargetExt)</OutputFile>
     </Link>

+ 42 - 12
FactoryCraft/Game.cpp

@@ -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

+ 3 - 0
FactoryCraft/Game.h

@@ -47,8 +47,10 @@ private:
     {
     public:
         inline const static unsigned char INGAME_MESSAGE = 0;
+        inline const static unsigned char TERMINATE = 1;
         inline const static unsigned char WORLD_UPDATE = 2;
         inline const static unsigned char API_MESSAGE = 3;
+        inline const static unsigned char POSITION_UPDATE = 4;
     };
 };
 
@@ -77,6 +79,7 @@ public:
     void requestWorldUpdate( WorldUpdate *update );
     GameClient *addPlayer( FCKlient *client, Framework::Text name );
     bool doesChunkExist( int x, int y, int dimension ) const;
+    bool isChunkLoaded( int x, int y, int dimension ) const;
     Block *zBlockAt( Framework::Vec3<int> location, int dimension ) const;
     Dimension *zDimension( int id ) const;
     Framework::Punkt getChunkCenter( int x, int y ) const;

+ 2 - 1
FactoryCraft/GrasslandBiom.cpp

@@ -1,5 +1,6 @@
 #include "GrasslandBiom.h"
 #include "BlockType.h"
+#include "BasicBlocks.h"
 
 GrasslandBiom::GrasslandBiom()
     : GrasslandBiom( 1, 1, 1, 1, 1, 1 )
@@ -18,5 +19,5 @@ GrasslandBiom::GrasslandBiom( double biomXMultiplier, double biomYMultiplier, do
 
 Block *GrasslandBiom::getBlock( Noise *zNoise, int x, int y, int z, Game *zGame )
 {
-    return StaticRegistry<BlockType>::INSTANCE.zElement( 1 )->createBlockAt( Framework::Vec3<int>( x, y, z ), zGame, 0 );
+    return StaticRegistry<BlockType>::INSTANCE.zElement( DirtBlockType::ID )->createBlockAt( Framework::Vec3<int>( x, y, z ), zGame, 0 );
 }

+ 5 - 3
FactoryCraft/Inventory.cpp

@@ -133,7 +133,7 @@ void InventoryInteraction::transaction( Inventory *zSource, Inventory *zTarget,
             }
             else
             {
-                while( sourceSlot && ( !sourceSlot->zStack() || ( zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ) ) ) )
+                while( sourceSlot && (!sourceSlot->zStack() || (zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ))) )
                     sourceSlot++;
                 if( !sourceSlot )
                     return;
@@ -198,6 +198,8 @@ void InventoryInteraction::pushItems( int count, ItemFilter *zFilter )
 
 
 Inventory::Inventory( const Framework::Vec3<float> location )
+    : ReferenceCounter(),
+    location( location )
 {
     pullSlotsOrder = new Framework::RCArray<ItemSlot>();
     pushSlotsOrder = new Framework::RCArray<ItemSlot>();
@@ -245,7 +247,7 @@ void Inventory::addSlot( ItemSlot *slot )
         if( iterator->getPullPriority() > pullPrio )
             break;
     }
-    pullSlotsOrder->add( dynamic_cast<ItemSlot *>( slot->getThis() ), index );
+    pullSlotsOrder->add( dynamic_cast<ItemSlot *>(slot->getThis()), index );
     index = 0;
     for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++, index++ )
     {
@@ -364,7 +366,7 @@ void Inventory::localTransaction( Array< ItemSlot * > *zSourceSlots, Array< Item
             }
             else
             {
-                while( sourceSlot && ( !sourceSlot->zStack() || ( zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ) ) ) )
+                while( sourceSlot && (!sourceSlot->zStack() || (zFilter && !zFilter->matchItem( sourceSlot->zStack()->zItem() ))) )
                     sourceSlot++;
                 if( !sourceSlot )
                 {

+ 10 - 1
FactoryCraft/Player.cpp

@@ -3,7 +3,16 @@
 
 Player::Player( Framework::Vec3<float> location, int dimensionId, int entityId )
     : Entity( PlayerEntityType::INSTANCE, location, dimensionId, entityId )
-{}
+{
+    maxHP = 10;
+    currentHP = 10;
+    stamina = 10;
+    maxStamina = 10;
+    hunger = 10;
+    maxHunger = 10;
+    thirst = 10;
+    maxThirst = 10;
+}
 
 void Player::setName( Framework::Text name )
 {

+ 7 - 4
FactoryCraft/Server.cpp

@@ -20,7 +20,9 @@ FactoryCraftServer::FactoryCraftServer( InitDatei *zIni )
     server = new SSLServer();
     server->setPrivateKeyPassword( zIni->zWert( "SSLPasswort" )->getText() );
     server->setCertificateFile( zIni->zWert( "SSLCert" )->getText() );
+    std::cout << "using cert file " << zIni->zWert( "SSLCert" )->getText() << "\n";
     server->setPrivateKeyFile( zIni->zWert( "SSLKey" )->getText() );
+    std::cout << "using private key " << zIni->zWert( "SSLKey" )->getText() << "\n";
     game = new Game( zIni->zWert( "World" )->getText(), zIni->zWert( "SaveDir" )->getText() );
     InitializeCriticalSection( &cs );
 }
@@ -41,9 +43,10 @@ FactoryCraftServer::~FactoryCraftServer()
 // nicht constant 
 void FactoryCraftServer::run()
 {
-    if( server )
-        server->release();
-    server->verbinde( (unsigned short)TextZuInt( ini->zWert( "SSLPort" )->getText(), 10 ), 10 );
+    if( !server->verbinde( (unsigned short)TextZuInt( ini->zWert( "SSLPort" )->getText(), 10 ), 10 ) )
+        std::cout << "Der Server konnte nicht gestartet werden.\n";
+    else
+        std::cout << "Server Port: " << ini->zWert( "SSLPort" )->getText() << "\n";
     while( server->isConnected() )
     {
         SSLSKlient *klient = server->getKlient();
@@ -206,8 +209,8 @@ void FCKlient::thread()
                                     zGameClient->logout();
                                     zGameClient = (GameClient *)zGameClient->release();
                                 }
-                                zGameClient = ls->zGame()->addPlayer( dynamic_cast<FCKlient *>( getThis() ), Text( accountId ) );
                                 klient->sende( "\1", 1 );
+                                zGameClient = ls->zGame()->addPlayer( dynamic_cast<FCKlient *>( getThis() ), Text( accountId ) );
                                 ok = true;
                             }
                         }

+ 1 - 0
FactoryCraft/Start.cpp

@@ -75,6 +75,7 @@ int main()
     std::cout << "Der Server läuft. Startforgang beendet.\n";
     mserver->run();
     mserver->release();
+    mserver = 0;
     dat->release();
     std::cout << "Der Server ist heruntergefahren.\n";
     file.close();

+ 5 - 14
FactoryCraft/TickOrganizer.cpp

@@ -27,23 +27,14 @@ TickOrganizer::~TickOrganizer()
 
 void TickOrganizer::nextTick()
 {
-    bool waiting = 0;
-    do
-    {
-        if( waiting )
-            queue->waitForEmpty();
-        for( int i = 0; i < workerCount; i++ )
-            waiting |= workers[ i ]->isWaiting();
-    } while( waiting );
     queue->startNextTick( &tickSources );
-    waiting = 0;
+    bool notWaiting = 0;
     do
     {
-        if( waiting )
-            queue->waitForEmpty();
-        for( int i = 0; i < workerCount; i++ )
-            waiting |= workers[ i ]->isWaiting();
-    } while( waiting );
+        queue->waitForEmpty();
+        for (int i = 0; i < workerCount; i++)
+            notWaiting |= !workers[i]->isWaiting();
+    } while (notWaiting);
 }
 
 void TickOrganizer::addTickSource( Block *zBlock )

+ 2 - 1
FactoryCraft/WorldGenerator.cpp

@@ -26,11 +26,12 @@ void WorldGenerator::thread()
     {
         cs.Enter();
         Area next;
-        bool hasNext = false;
+        bool hasNext = 0;
         if( requestQueue.getEintragAnzahl() > 0 )
         {
             next = requestQueue.get( 0 );
             requestQueue.remove( 0 );
+            hasNext = 1;
         }
         cs.Leave();
         if( !hasNext )

+ 3 - 2
FactoryCraft/WorldLoader.cpp

@@ -47,11 +47,12 @@ void WorldLoader::thread()
     {
         cs.Enter();
         Area next;
-        bool hasNext = false;
+        bool hasNext = 0;
         if( requestQueue.getEintragAnzahl() > 0 )
         {
             next = requestQueue.get( 0 );
             requestQueue.remove( 0 );
+            hasNext = 1;
         }
         cs.Leave();
         if( !hasNext )
@@ -67,7 +68,7 @@ void WorldLoader::thread()
         {
             for( int y = start.y; y != end.y; y += CHUNK_SIZE * yDir )
             {
-                if( !zGame->doesChunkExist( x, y, next.dimensionId ) )
+                if( !zGame->isChunkLoaded( x, y, next.dimensionId ) )
                 {
                     Datei *file = new Datei();
                     Text filePath = zGame->getWorldDirectory() + "/dim/" + next.dimensionId + "/";