Pārlūkot izejas kodu

add player model and improved safty of world updates

Kolja Strohm 3 gadi atpakaļ
vecāks
revīzija
e2e33d1631

+ 0 - 2
FactoryCraft/AddChunkUpdate.h

@@ -8,8 +8,6 @@ class AddChunkUpdateType : WorldUpdateType
 
 protected:
     AddChunkUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 0 - 2
FactoryCraft/AddEntityUpdate.h

@@ -8,8 +8,6 @@ class AddEntityUpdateType : public WorldUpdateType
 
 protected:
     AddEntityUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 1 - 146
FactoryCraft/BasicBlocks.cpp

@@ -10,152 +10,7 @@
 BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t )
     : Block( zType, zTool, pos, false )
 {
-    Model3DData* data = 0;
-    if( window->zBildschirm()->zGraphicsApi()->hasModel( "cube" ) )
-        data = window->zBildschirm()->zGraphicsApi()->getModel( "cube" );
-    else
-    {
-        data = window->zBildschirm()->zGraphicsApi()->createModel( "cube" );
-        data->setAmbientFactor( 0.8f );
-        data->setDiffusFactor( 0.1f );
-        data->setSpecularFactor( 0.1f );
-        float size = 1;
-        float left, right, top, bottom;
-        // Calculate the screen coordinates of the left side of the bitmap.
-        left = (float)((size / 2.0) * -1);
-        // Calculate the screen coordinates of the right side of the bitmap.
-        right = left + (float)size;
-        // Calculate the screen coordinates of the top of the bitmap.
-        top = (float)(size / 2.0);
-        // Calculate the screen coordinates of the bottom of the bitmap.
-        bottom = top - (float)size;
-        float front = -size / 2;
-        float back = front + size;
-
-        Vertex3D* vertecies = new Vertex3D[ 24 ];
-        for( int i = 0; i < 24; i++ )
-            vertecies[ i ].knochenId = 0;
-        vertecies[ 0 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 1 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 4 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 5 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        vertecies[ 8 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 9 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 12 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 13 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        vertecies[ 16 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 17 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 20 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 21 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        data->setVertecies( vertecies, 24 );
-        // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
-        // down side
-        Polygon3D* p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 6 + 16;
-        p->indexList[ 1 ] = 2 + 16;
-        p->indexList[ 2 ] = 3 + 16;
-        p->indexList[ 3 ] = 6 + 16;
-        p->indexList[ 4 ] = 3 + 16;
-        p->indexList[ 5 ] = 7 + 16;
-        data->addPolygon( p );
-        // right side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 1 + 8;
-        p->indexList[ 1 ] = 7 + 8;
-        p->indexList[ 2 ] = 3 + 8;
-        p->indexList[ 3 ] = 1 + 8;
-        p->indexList[ 4 ] = 5 + 8;
-        p->indexList[ 5 ] = 7 + 8;
-        data->addPolygon( p );
-        // top side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4 + 16;
-        p->indexList[ 1 ] = 1 + 16;
-        p->indexList[ 2 ] = 0 + 16;
-        p->indexList[ 3 ] = 4 + 16;
-        p->indexList[ 4 ] = 5 + 16;
-        p->indexList[ 5 ] = 1 + 16;
-        data->addPolygon( p );
-        // left side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 0 + 8;
-        p->indexList[ 1 ] = 2 + 8;
-        p->indexList[ 2 ] = 6 + 8;
-        p->indexList[ 3 ] = 0 + 8;
-        p->indexList[ 4 ] = 6 + 8;
-        p->indexList[ 5 ] = 4 + 8;
-        data->addPolygon( p );
-        // back side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4;
-        p->indexList[ 1 ] = 6;
-        p->indexList[ 2 ] = 7;
-        p->indexList[ 3 ] = 4;
-        p->indexList[ 4 ] = 7;
-        p->indexList[ 5 ] = 5;
-        data->addPolygon( p );
-        // front side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 0;
-        p->indexList[ 1 ] = 3;
-        p->indexList[ 2 ] = 2;
-        p->indexList[ 3 ] = 0;
-        p->indexList[ 4 ] = 1;
-        p->indexList[ 5 ] = 3;
-        data->addPolygon( p );
-        data->calculateNormals();
-    }
+    Model3DData* data = window->zBildschirm()->zGraphicsApi()->getModel( "cube" );
     setModelDaten( data );
     Bild* b = new Bild();
     b->neuBild( 10, 10, 0xFFFFFFFF );

+ 1 - 146
FactoryCraft/Block.cpp

@@ -78,152 +78,7 @@ void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zR
 
 Framework::Model3DData* BasicBlockItemType::getItemModel() const
 {
-    if( window->zBildschirm()->zGraphicsApi()->hasModel( "itemCube" ) )
-        return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
-    else
-    {
-        Framework::Model3DData* data = window->zBildschirm()->zGraphicsApi()->createModel( "itemCube" );
-        data->setAmbientFactor( 0.8f );
-        data->setDiffusFactor( 0.1f );
-        data->setSpecularFactor( 0.1f );
-        float size = 0.2f;
-        float left, right, top, bottom;
-        // Calculate the screen coordinates of the left side of the bitmap.
-        left = (float)((size / 2.0) * -1);
-        // Calculate the screen coordinates of the right side of the bitmap.
-        right = left + (float)size;
-        // Calculate the screen coordinates of the top of the bitmap.
-        top = (float)(size / 2.0);
-        // Calculate the screen coordinates of the bottom of the bitmap.
-        bottom = top - (float)size;
-        float front = -size / 2;
-        float back = front + size;
-
-        Vertex3D* vertecies = new Vertex3D[ 24 ];
-        for( int i = 0; i < 24; i++ )
-            vertecies[ i ].knochenId = 0;
-        vertecies[ 0 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 1 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 4 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 5 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        vertecies[ 8 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 9 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 12 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 13 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        vertecies[ 16 ].pos = Vec3<float >( left, top, front );
-        vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
-        vertecies[ 17 ].pos = Vec3<float >( right, top, front );
-        vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
-        vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
-        vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
-        vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
-        vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
-        vertecies[ 20 ].pos = Vec3<float >( left, top, back );
-        vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
-        vertecies[ 21 ].pos = Vec3<float >( right, top, back );
-        vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
-        vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
-        vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
-        vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
-        vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
-
-        data->setVertecies( vertecies, 24 );
-        // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
-        // down side
-        Polygon3D* p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 6 + 16;
-        p->indexList[ 1 ] = 2 + 16;
-        p->indexList[ 2 ] = 3 + 16;
-        p->indexList[ 3 ] = 6 + 16;
-        p->indexList[ 4 ] = 3 + 16;
-        p->indexList[ 5 ] = 7 + 16;
-        data->addPolygon( p );
-        // right side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 1 + 8;
-        p->indexList[ 1 ] = 7 + 8;
-        p->indexList[ 2 ] = 3 + 8;
-        p->indexList[ 3 ] = 1 + 8;
-        p->indexList[ 4 ] = 5 + 8;
-        p->indexList[ 5 ] = 7 + 8;
-        data->addPolygon( p );
-        // top side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4 + 16;
-        p->indexList[ 1 ] = 1 + 16;
-        p->indexList[ 2 ] = 0 + 16;
-        p->indexList[ 3 ] = 4 + 16;
-        p->indexList[ 4 ] = 5 + 16;
-        p->indexList[ 5 ] = 1 + 16;
-        data->addPolygon( p );
-        // left side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 0 + 8;
-        p->indexList[ 1 ] = 2 + 8;
-        p->indexList[ 2 ] = 6 + 8;
-        p->indexList[ 3 ] = 0 + 8;
-        p->indexList[ 4 ] = 6 + 8;
-        p->indexList[ 5 ] = 4 + 8;
-        data->addPolygon( p );
-        // back side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4;
-        p->indexList[ 1 ] = 6;
-        p->indexList[ 2 ] = 7;
-        p->indexList[ 3 ] = 4;
-        p->indexList[ 4 ] = 7;
-        p->indexList[ 5 ] = 5;
-        data->addPolygon( p );
-        // front side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 0;
-        p->indexList[ 1 ] = 3;
-        p->indexList[ 2 ] = 2;
-        p->indexList[ 3 ] = 0;
-        p->indexList[ 4 ] = 1;
-        p->indexList[ 5 ] = 3;
-        data->addPolygon( p );
-        data->calculateNormals();
-        return data;
-    }
+    return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
 }
 
 Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const

+ 0 - 2
FactoryCraft/BlockChangedUpdate.h

@@ -8,8 +8,6 @@ class BlockChangedUpdateType : WorldUpdateType
 
 protected:
     BlockChangedUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 0 - 2
FactoryCraft/BlockRemovedUpdate.h

@@ -8,8 +8,6 @@ class BlockRemovedUpdateType : WorldUpdateType
 
 protected:
     BlockRemovedUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 10 - 7
FactoryCraft/EntityChangedUpdate.cpp

@@ -12,13 +12,16 @@ void EntityChangedUpdateType::applyUpdate( Framework::StreamReader* zReader )
     int id;
     int type;
     zReader->lese( (char*)&id, 4 );
-    zReader->lese( (char*)&type, 4 );
-    Entity* e = currentGame->zEntity( id );
-    if( !e )
+    if( id >= 0 )
     {
-        e = STATIC_REGISTRY( EntityType ).zElement( type )->loadEntity( zReader );
-        currentGame->zDimensionOrCreate( e->getCurrentDimension() )->addEntity( e );
+        zReader->lese( (char*)&type, 4 );
+        Entity* e = currentGame->zEntity( id );
+        if( !e )
+        {
+            e = STATIC_REGISTRY( EntityType ).zElement( type )->loadEntity( zReader );
+            currentGame->zDimensionOrCreate( e->getCurrentDimension() )->addEntity( e );
+        }
+        else
+            STATIC_REGISTRY( EntityType ).zElement( type )->updateEntity( e, zReader );
     }
-    else
-        STATIC_REGISTRY( EntityType ).zElement( type )->updateEntity( e, zReader );
 }

+ 0 - 2
FactoryCraft/EntityChangedUpdate.h

@@ -8,8 +8,6 @@ class EntityChangedUpdateType : WorldUpdateType
 
 protected:
     EntityChangedUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 0 - 2
FactoryCraft/EntityRemovedUpdate.h

@@ -8,8 +8,6 @@ class EntityRemovedUpdateType : WorldUpdateType
 
 protected:
     EntityRemovedUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 443 - 0
FactoryCraft/Load.cpp

@@ -8,6 +8,448 @@
 #include "Globals.h"
 #include <Textur.h>
 
+void createDefaultCube( Bildschirm* zScreen )
+{
+    Model3DData* data = zScreen->zGraphicsApi()->createModel( "cube" );
+    data->setAmbientFactor( 0.8f );
+    data->setDiffusFactor( 0.1f );
+    data->setSpecularFactor( 0.1f );
+    float size = 1;
+    float left, right, top, bottom;
+    // Calculate the screen coordinates of the left side of the bitmap.
+    left = (float)((size / 2.0) * -1);
+    // Calculate the screen coordinates of the right side of the bitmap.
+    right = left + (float)size;
+    // Calculate the screen coordinates of the top of the bitmap.
+    top = (float)(size / 2.0);
+    // Calculate the screen coordinates of the bottom of the bitmap.
+    bottom = top - (float)size;
+    float front = -size / 2;
+    float back = front + size;
+
+    Vertex3D* vertecies = new Vertex3D[ 24 ];
+    for( int i = 0; i < 24; i++ )
+        vertecies[ i ].knochenId = 0;
+    vertecies[ 0 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 1 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 4 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 5 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 8 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 9 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 12 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 13 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 16 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 17 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 20 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 21 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    data->setVertecies( vertecies, 24 );
+    // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
+    // down side
+    Polygon3D* p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 6 + 16;
+    p->indexList[ 1 ] = 2 + 16;
+    p->indexList[ 2 ] = 3 + 16;
+    p->indexList[ 3 ] = 6 + 16;
+    p->indexList[ 4 ] = 3 + 16;
+    p->indexList[ 5 ] = 7 + 16;
+    data->addPolygon( p );
+    // right side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 1 + 8;
+    p->indexList[ 1 ] = 7 + 8;
+    p->indexList[ 2 ] = 3 + 8;
+    p->indexList[ 3 ] = 1 + 8;
+    p->indexList[ 4 ] = 5 + 8;
+    p->indexList[ 5 ] = 7 + 8;
+    data->addPolygon( p );
+    // top side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4 + 16;
+    p->indexList[ 1 ] = 1 + 16;
+    p->indexList[ 2 ] = 0 + 16;
+    p->indexList[ 3 ] = 4 + 16;
+    p->indexList[ 4 ] = 5 + 16;
+    p->indexList[ 5 ] = 1 + 16;
+    data->addPolygon( p );
+    // left side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0 + 8;
+    p->indexList[ 1 ] = 2 + 8;
+    p->indexList[ 2 ] = 6 + 8;
+    p->indexList[ 3 ] = 0 + 8;
+    p->indexList[ 4 ] = 6 + 8;
+    p->indexList[ 5 ] = 4 + 8;
+    data->addPolygon( p );
+    // back side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4;
+    p->indexList[ 1 ] = 6;
+    p->indexList[ 2 ] = 7;
+    p->indexList[ 3 ] = 4;
+    p->indexList[ 4 ] = 7;
+    p->indexList[ 5 ] = 5;
+    data->addPolygon( p );
+    // front side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0;
+    p->indexList[ 1 ] = 3;
+    p->indexList[ 2 ] = 2;
+    p->indexList[ 3 ] = 0;
+    p->indexList[ 4 ] = 1;
+    p->indexList[ 5 ] = 3;
+    data->addPolygon( p );
+    data->calculateNormals();
+    data->release();
+}
+
+void createCubeItem( Bildschirm* zScreen )
+{
+    Framework::Model3DData* data = window->zBildschirm()->zGraphicsApi()->createModel( "itemCube" );
+    data->setAmbientFactor( 0.8f );
+    data->setDiffusFactor( 0.1f );
+    data->setSpecularFactor( 0.1f );
+    float size = 0.2f;
+    float left, right, top, bottom;
+    // Calculate the screen coordinates of the left side of the bitmap.
+    left = (float)((size / 2.0) * -1);
+    // Calculate the screen coordinates of the right side of the bitmap.
+    right = left + (float)size;
+    // Calculate the screen coordinates of the top of the bitmap.
+    top = (float)(size / 2.0);
+    // Calculate the screen coordinates of the bottom of the bitmap.
+    bottom = top - (float)size;
+    float front = -size / 2;
+    float back = front + size;
+
+    Vertex3D* vertecies = new Vertex3D[ 24 ];
+    for( int i = 0; i < 24; i++ )
+        vertecies[ i ].knochenId = 0;
+    vertecies[ 0 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 1 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 4 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 5 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 8 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 9 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 12 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 13 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 16 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 17 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 20 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 21 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    data->setVertecies( vertecies, 24 );
+    // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
+    // down side
+    Polygon3D* p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 6 + 16;
+    p->indexList[ 1 ] = 2 + 16;
+    p->indexList[ 2 ] = 3 + 16;
+    p->indexList[ 3 ] = 6 + 16;
+    p->indexList[ 4 ] = 3 + 16;
+    p->indexList[ 5 ] = 7 + 16;
+    data->addPolygon( p );
+    // right side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 1 + 8;
+    p->indexList[ 1 ] = 7 + 8;
+    p->indexList[ 2 ] = 3 + 8;
+    p->indexList[ 3 ] = 1 + 8;
+    p->indexList[ 4 ] = 5 + 8;
+    p->indexList[ 5 ] = 7 + 8;
+    data->addPolygon( p );
+    // top side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4 + 16;
+    p->indexList[ 1 ] = 1 + 16;
+    p->indexList[ 2 ] = 0 + 16;
+    p->indexList[ 3 ] = 4 + 16;
+    p->indexList[ 4 ] = 5 + 16;
+    p->indexList[ 5 ] = 1 + 16;
+    data->addPolygon( p );
+    // left side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0 + 8;
+    p->indexList[ 1 ] = 2 + 8;
+    p->indexList[ 2 ] = 6 + 8;
+    p->indexList[ 3 ] = 0 + 8;
+    p->indexList[ 4 ] = 6 + 8;
+    p->indexList[ 5 ] = 4 + 8;
+    data->addPolygon( p );
+    // back side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4;
+    p->indexList[ 1 ] = 6;
+    p->indexList[ 2 ] = 7;
+    p->indexList[ 3 ] = 4;
+    p->indexList[ 4 ] = 7;
+    p->indexList[ 5 ] = 5;
+    data->addPolygon( p );
+    // front side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0;
+    p->indexList[ 1 ] = 3;
+    p->indexList[ 2 ] = 2;
+    p->indexList[ 3 ] = 0;
+    p->indexList[ 4 ] = 1;
+    p->indexList[ 5 ] = 3;
+    data->addPolygon( p );
+    data->calculateNormals();
+    data->release();
+}
+
+void createPlayer( Bildschirm* zScreen )
+{
+    Framework::Model3DData* data = window->zBildschirm()->zGraphicsApi()->createModel( "player" );
+    data->setAmbientFactor( 0.8f );
+    data->setDiffusFactor( 0.1f );
+    data->setSpecularFactor( 0.1f );
+    float size = 0.8f;
+    float left, right, top, bottom;
+    // Calculate the screen coordinates of the left side of the bitmap.
+    left = (float)((size / 2.0) * -1);
+    // Calculate the screen coordinates of the right side of the bitmap.
+    right = left + (float)size;
+    // Calculate the screen coordinates of the top of the bitmap.
+    top = (float)(size / 2.0);
+    // Calculate the screen coordinates of the bottom of the bitmap.
+    bottom = top - (float)size;
+    float front = -1.5f / 2;
+    float back = front + 1.5f;
+
+    Vertex3D* vertecies = new Vertex3D[ 24 ];
+    for( int i = 0; i < 24; i++ )
+        vertecies[ i ].knochenId = 0;
+    vertecies[ 0 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 1 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 4 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 5 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 8 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 9 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 12 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 13 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    vertecies[ 16 ].pos = Vec3<float >( left, top, front );
+    vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
+    vertecies[ 17 ].pos = Vec3<float >( right, top, front );
+    vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
+    vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
+    vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
+    vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
+    vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
+    vertecies[ 20 ].pos = Vec3<float >( left, top, back );
+    vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
+    vertecies[ 21 ].pos = Vec3<float >( right, top, back );
+    vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
+    vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
+    vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
+    vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
+    vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+    data->setVertecies( vertecies, 24 );
+    // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
+    // down side
+    Polygon3D* p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 6 + 16;
+    p->indexList[ 1 ] = 2 + 16;
+    p->indexList[ 2 ] = 3 + 16;
+    p->indexList[ 3 ] = 6 + 16;
+    p->indexList[ 4 ] = 3 + 16;
+    p->indexList[ 5 ] = 7 + 16;
+    data->addPolygon( p );
+    // right side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 1 + 8;
+    p->indexList[ 1 ] = 7 + 8;
+    p->indexList[ 2 ] = 3 + 8;
+    p->indexList[ 3 ] = 1 + 8;
+    p->indexList[ 4 ] = 5 + 8;
+    p->indexList[ 5 ] = 7 + 8;
+    data->addPolygon( p );
+    // top side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4 + 16;
+    p->indexList[ 1 ] = 1 + 16;
+    p->indexList[ 2 ] = 0 + 16;
+    p->indexList[ 3 ] = 4 + 16;
+    p->indexList[ 4 ] = 5 + 16;
+    p->indexList[ 5 ] = 1 + 16;
+    data->addPolygon( p );
+    // left side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0 + 8;
+    p->indexList[ 1 ] = 2 + 8;
+    p->indexList[ 2 ] = 6 + 8;
+    p->indexList[ 3 ] = 0 + 8;
+    p->indexList[ 4 ] = 6 + 8;
+    p->indexList[ 5 ] = 4 + 8;
+    data->addPolygon( p );
+    // back side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 4;
+    p->indexList[ 1 ] = 6;
+    p->indexList[ 2 ] = 7;
+    p->indexList[ 3 ] = 4;
+    p->indexList[ 4 ] = 7;
+    p->indexList[ 5 ] = 5;
+    data->addPolygon( p );
+    // front side
+    p = new Polygon3D();
+    p->indexAnz = 6;
+    p->indexList = new int[ p->indexAnz ];
+    p->indexList[ 0 ] = 0;
+    p->indexList[ 1 ] = 3;
+    p->indexList[ 2 ] = 2;
+    p->indexList[ 3 ] = 0;
+    p->indexList[ 4 ] = 1;
+    p->indexList[ 5 ] = 3;
+    data->addPolygon( p );
+    data->calculateNormals();
+    data->release();
+}
+
+void createModels( Bildschirm* zScreen )
+{
+    createDefaultCube( zScreen );
+    createCubeItem( zScreen );
+    createPlayer( zScreen );
+}
+
 
 LoadMenu::LoadMenu( Bildschirm* zScreen )
     : Menu( zScreen )
@@ -54,6 +496,7 @@ LoadMenu::LoadMenu( Bildschirm* zScreen )
             }
             files->release();
         }
+        createModels( zScreen );
         all->aktionPlus();
         zScreen->lock();
         hide();

+ 0 - 2
FactoryCraft/PlaceBlockUpdate.h

@@ -7,8 +7,6 @@ class PlaceBlockUpdateType : WorldUpdateType
 
 protected:
     PlaceBlockUpdateType();
-
-public:
     void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 

+ 70 - 0
FactoryCraft/Player.cpp

@@ -1,19 +1,89 @@
 #include "Player.h"
 #include "Area.h"
+#include "Globals.h"
+#include "Menu.h"
+#include "Game.h"
+#include <Bild.h>
+
 
 Player::Player()
     : Entity( PlayerEntityType::INSTANCE, 1 )
 {
+    setModelDaten( window->zBildschirm()->zGraphicsApi()->getModel( "player" ) );
+    Bild* b = new Bild();
+    b->neuBild( 10, 10, 0xFFFFFFFF );
+    Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "player", 0 );
+    if( !tex->zBild() )
+        tex->setBildZ( b );
+    else
+        b->release();
+    Model3DTextur* textur = new Model3DTextur();
+    textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
+    textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
+    textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );
+    textur->setPolygonTextur( 3, dynamic_cast<Textur*>(tex->getThis()) );
+    textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
+    textur->setPolygonTextur( 5, tex );
+    setModelTextur( textur );
     for( int i = 0; i < 9; i++ )
     {
         ItemSlot* slot = new ItemSlot( 50, 0, i, 0, ANY_DIRECTION, 0 );
         addSlot( slot );
     }
+    currentGame->setVisibility( this, 1 );
 }
 
 Player::~Player()
 {}
 
+bool Player::tick( double time )
+{
+    if( currentGame->getCurrentPlayerId() == id )
+    {
+        currentGame->zKamera()->setPosition( pos + Vec3<float>( 0.f, 0.f, 1.5f ) );
+        //currentGame->zKamera()->setDirection( faceDir );
+        /*
+        char b = 0;
+        serverMessageReader->lese( &b, 1 );
+        if( hasTarget && dimensions->hat( 0 ) )
+        {
+            if( entityTarget == -1 )
+            {
+                Block* block = zBlockAt( target, dimensions->z( 0 )->getDimensionId() );
+                if( block )
+                    block->setAmbientFactor( block->getAmbientFactor() - 0.2f );
+            }
+        }
+        if( b == 1 )
+        {
+            serverMessageReader->lese( (char*)&entityTarget, 4 );
+            hasTarget = 1;
+        }
+        else if( b == 2 )
+        {
+            serverMessageReader->lese( (char*)&target.x, 4 );
+            serverMessageReader->lese( (char*)&target.y, 4 );
+            serverMessageReader->lese( (char*)&target.z, 4 );
+            int side = 0;
+            serverMessageReader->lese( (char*)&side, 4 );
+            hasTarget = 1;
+        }
+        else
+            hasTarget = 0;
+        if( hasTarget && dimensions->hat( 0 ) )
+        {
+            if( entityTarget == -1 )
+            {
+                Block* block = zBlockAt( target, dimensions->z( 0 )->getDimensionId() );
+                if( block )
+                    block->setAmbientFactor( block->getAmbientFactor() + 0.2f );
+            }
+        }*/
+        ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, false, { 0, 0, 0 } );
+    }
+    return Entity::tick( time );
+}
+
 
 PlayerEntityType::PlayerEntityType()
     : EntityType( ID )

+ 2 - 0
FactoryCraft/Player.h

@@ -12,6 +12,8 @@ private:
 public:
     Player();
     ~Player();
+
+    virtual bool tick( double time ) override;
 };
 
 class PlayerEntityType : public EntityType

+ 30 - 54
FactoryCraft/World.cpp

@@ -29,6 +29,7 @@ World::World( Bildschirm3D* zScreen )
     firstMessage = 1;
     hasTarget = 0;
     entityTarget = -1;
+    ownEntityId = -1;
     start();
 }
 
@@ -50,7 +51,7 @@ void World::update( bool background )
         {
             int id = 0;
             serverMessageReader->lese( (char*)&id, 4 );
-            STATIC_REGISTRY( WorldUpdateType ).zElement( id )->applyUpdate( serverMessageReader );
+            STATIC_REGISTRY( WorldUpdateType ).zElement( id )->applyUpdateAndCheck( serverMessageReader );
         }
         if( type == 3 ) // API MESSAGE
         {
@@ -58,63 +59,17 @@ void World::update( bool background )
         }
         if( type == 4 ) // POSITION UPDATE
         {
-            Vec3<float> pos;
-            Vec3<float> dir;
-            serverMessageReader->lese( (char*)&pos.x, 4 );
-            serverMessageReader->lese( (char*)&pos.y, 4 );
-            serverMessageReader->lese( (char*)&pos.z, 4 );
-            kam->setPosition( pos + Vec3<float>( 0.f, 0.f, 1.5f ) );
-            if( firstMessage )
-            {
-                firstMessage = 0;
-                serverMessageReader->lese( (char*)&dir.x, 4 );
-                serverMessageReader->lese( (char*)&dir.y, 4 );
-                serverMessageReader->lese( (char*)&dir.z, 4 );
-                kam->setDirection( dir );
-            }
-            for( Dimension* dim : *dimensions )
-                dim->removeDistantChunks( { (int)pos.x, (int)pos.y }, this );
-            char b = 0;
-            serverMessageReader->lese( &b, 1 );
-            if( hasTarget && dimensions->hat( 0 ) )
-            {
-                if( entityTarget == -1 )
-                {
-                    Block* block = zBlockAt( target, dimensions->z( 0 )->getDimensionId() );
-                    if( block )
-                        block->setAmbientFactor( block->getAmbientFactor() - 0.2f );
-                }
-            }
-            if( b == 1 )
-            {
-                serverMessageReader->lese( (char*)&entityTarget, 4 );
-                hasTarget = 1;
-            }
-            else if( b == 2 )
-            {
-                serverMessageReader->lese( (char*)&target.x, 4 );
-                serverMessageReader->lese( (char*)&target.y, 4 );
-                serverMessageReader->lese( (char*)&target.z, 4 );
-                int side = 0;
-                serverMessageReader->lese( (char*)&side, 4 );
-                hasTarget = 1;
-            }
-            else
-                hasTarget = 0;
-            if( hasTarget && dimensions->hat( 0 ) )
-            {
-                if( entityTarget == -1 )
-                {
-                    Block* block = zBlockAt( target, dimensions->z( 0 )->getDimensionId() );
-                    if( block )
-                        block->setAmbientFactor( block->getAmbientFactor() + 0.2f );
-                }
-            }
-            ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, hasTarget, target );
+            serverMessageReader->lese( (char*)&ownEntityId, 4 );
         }
         network->zFactoryClient()->endMessageReading( background );
     }
     network->zFactoryClient()->endMessageReading( background );
+    Entity* player = getCurrentPlayerEntity();
+    if( player )
+    {
+        for( Dimension* dim : *dimensions )
+            dim->removeDistantChunks( { (int)player->getPos().x, (int)player->getPos().y }, this );
+    }
 }
 
 void World::setChunk( Chunk* chunk, int dimensionId )
@@ -236,4 +191,25 @@ void World::removeEntity( int id )
 {
     for( Dimension* d : *dimensions )
         d->removeEntity( id );
+}
+
+PlayerKam* World::zKamera() const
+{
+    return kam;
+}
+
+int World::getCurrentPlayerId() const
+{
+    return ownEntityId;
+}
+
+Entity* World::getCurrentPlayerEntity() const
+{
+    for( Dimension* d : *dimensions )
+    {
+        Entity* e = d->zEntity( ownEntityId );
+        if( e )
+            return e;
+    }
+    return 0;
 }

+ 4 - 0
FactoryCraft/World.h

@@ -21,6 +21,7 @@ private:
     int entityTarget;
     bool hasTarget;
     bool firstMessage;
+    int ownEntityId;
 
 public:
     World( Framework::Bildschirm3D* zScreen );
@@ -38,4 +39,7 @@ public:
     Framework::Punkt getChunkCenter( int x, int y ) const;
     Entity* zEntity( int id ) const;
     void removeEntity( int id );
+    PlayerKam* zKamera() const;
+    int getCurrentPlayerId() const;
+    Entity* getCurrentPlayerEntity() const;
 };

+ 18 - 1
FactoryCraft/WorldUpdate.cpp

@@ -1,9 +1,26 @@
 #include "WorldUpdate.h"
 
 #include "Registries.h"
+#include <Text.h>
 
 WorldUpdateType::WorldUpdateType( int id )
-    : ReferenceCounter()
+    : ReferenceCounter(),
+    id( id )
 {
     STATIC_REGISTRY( WorldUpdateType ).registerT( this, id );
+}
+
+void WorldUpdateType::applyUpdateAndCheck( Framework::StreamReader* zReader )
+{
+    this->applyUpdate( zReader );
+    int id;
+    zReader->lese( (char*)&id, 4 );
+    if( id != this->id )
+    {
+        Framework::Text* t = new Framework::Text( "asynchony after world update of type " );
+        t->append( this->id );
+        t->append( ". ID received from server was: " );
+        t->append( id );
+        throw t->getText();
+    }
 }

+ 5 - 1
FactoryCraft/WorldUpdate.h

@@ -7,9 +7,13 @@
 
 class WorldUpdateType : public Framework::ReferenceCounter
 {
+private:
+    int id;
+
 protected:
     WorldUpdateType( int id );
+    virtual void applyUpdate( Framework::StreamReader* zReader ) = 0;
 
 public:
-    virtual void applyUpdate( Framework::StreamReader* zReader ) = 0;
+    void applyUpdateAndCheck( Framework::StreamReader* zReader );
 };