Browse Source

adjust system for lazy block instantiation

Kolja Strohm 3 years ago
parent
commit
2c7f34cca6
58 changed files with 843 additions and 374 deletions
  1. 5 5
      FactoryCraft/AddChunkUpdate.cpp
  2. 1 1
      FactoryCraft/AddChunkUpdate.h
  3. 54 29
      FactoryCraft/BasicBlocks.cpp
  4. 9 4
      FactoryCraft/BasicBlocks.h
  5. 43 21
      FactoryCraft/Block.cpp
  6. 16 10
      FactoryCraft/Block.h
  7. 32 13
      FactoryCraft/BlockType.cpp
  8. 8 3
      FactoryCraft/BlockType.h
  9. 106 49
      FactoryCraft/Chunk.cpp
  10. 12 9
      FactoryCraft/Chunk.h
  11. 2 2
      FactoryCraft/CurrentPlayer.h
  12. 16 12
      FactoryCraft/Dimension.cpp
  13. 9 8
      FactoryCraft/Dimension.h
  14. 6 7
      FactoryCraft/DirectConnect.cpp
  15. 3 3
      FactoryCraft/DirectConnect.h
  16. 18 5
      FactoryCraft/FactoryClient.cpp
  17. 6 3
      FactoryCraft/FactoryClient.h
  18. BIN
      FactoryCraft/FactoryCraft.exe
  19. 10 3
      FactoryCraft/FactoryCraft.vcxproj
  20. 18 0
      FactoryCraft/FactoryCraft.vcxproj.filters
  21. 2 3
      FactoryCraft/Game.cpp
  22. 2 2
      FactoryCraft/Game.h
  23. 2 4
      FactoryCraft/Globals.cpp
  24. 5 5
      FactoryCraft/Globals.h
  25. 25 25
      FactoryCraft/Initialisierung.cpp
  26. 7 7
      FactoryCraft/Initialisierung.h
  27. 3 3
      FactoryCraft/Inventory.h
  28. 8 6
      FactoryCraft/Inventoty.cpp
  29. 2 2
      FactoryCraft/Item.cpp
  30. 3 3
      FactoryCraft/Item.h
  31. 1 1
      FactoryCraft/ItemSlot.cpp
  32. 2 2
      FactoryCraft/ItemSlot.h
  33. 2 2
      FactoryCraft/ItemStack.cpp
  34. 3 3
      FactoryCraft/ItemStack.h
  35. 19 18
      FactoryCraft/ItemType.cpp
  36. 4 6
      FactoryCraft/ItemType.h
  37. 5 6
      FactoryCraft/Login.cpp
  38. 3 3
      FactoryCraft/Login.h
  39. 8 9
      FactoryCraft/Main.cpp
  40. 5 7
      FactoryCraft/Menu.cpp
  41. 2 2
      FactoryCraft/Menu.h
  42. 7 5
      FactoryCraft/NetworkHandler.cpp
  43. 6 6
      FactoryCraft/NetworkHandler.h
  44. 68 0
      FactoryCraft/NoBlock.cpp
  45. 51 0
      FactoryCraft/NoBlock.h
  46. 133 0
      FactoryCraft/PlayerKam.cpp
  47. 14 0
      FactoryCraft/PlayerKam.h
  48. 16 0
      FactoryCraft/Registries.h
  49. 4 4
      FactoryCraft/StaticInitializerOrder.cpp
  50. 9 15
      FactoryCraft/StaticRegistry.h
  51. 30 25
      FactoryCraft/World.cpp
  52. 12 11
      FactoryCraft/World.h
  53. 3 1
      FactoryCraft/WorldUpdate.cpp
  54. 1 1
      FactoryCraft/WorldUpdate.h
  55. 2 0
      FactoryCraft/data_release/optionen.ini
  56. BIN
      FactoryCraft/data_release/schriften/ksgs.ltds
  57. BIN
      FactoryCraft/data_release/schriften/normal.ltds
  58. BIN
      FactoryCraft/error_core_memory_dump.dmp

+ 5 - 5
FactoryCraft/AddChunkUpdate.cpp

@@ -9,14 +9,14 @@ AddChunkUpdateType::AddChunkUpdateType()
 {}
 
 
-void AddChunkUpdateType::applyUpdate( Framework::StreamReader *zReader )
+void AddChunkUpdateType::applyUpdate( Framework::StreamReader* zReader )
 {
     int dimensionID;
-    zReader->lese( (char *)&dimensionID, 4 );
+    zReader->lese( (char*)&dimensionID, 4 );
     Framework::Punkt center;
-    zReader->lese( (char *)&center.x, 4 );
-    zReader->lese( (char *)&center.y, 4 );
-    Chunk *chunk = new Chunk( center, dimensionID );
+    zReader->lese( (char*)&center.x, 4 );
+    zReader->lese( (char*)&center.y, 4 );
+    Chunk* chunk = new Chunk( center, dimensionID );
     chunk->load( zReader );
     currentGame->setChunk( chunk, dimensionID );
 }

+ 1 - 1
FactoryCraft/AddChunkUpdate.h

@@ -10,7 +10,7 @@ protected:
     AddChunkUpdateType();
 
 public:
-    void applyUpdate( Framework::StreamReader *zReader ) override;
+    void applyUpdate( Framework::StreamReader* zReader ) override;
 };
 
 REGISTER( AddChunkUpdateType, WorldUpdateType )

+ 54 - 29
FactoryCraft/BasicBlocks.cpp

@@ -7,30 +7,33 @@
 #include "Globals.h"
 
 
-BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Textur *t )
-    : Block( zTool, pos, false )
+BasicBlock::BasicBlock( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t )
+    : Block( zType, zTool, pos, false )
 {
-    Model3DData *data = 0;
+    Model3DData* data = 0;
     if( Framework::zM3DRegister()->hatModel( "cube" ) )
         data = Framework::zM3DRegister()->getModel( "cube" );
     else
     {
         data = new Model3DData();
-        Framework::zM3DRegister()->addModel( dynamic_cast<Model3DData *>( data->getThis() ), "cube" );
+        data->setAmbientFactor( 0.2f );
+        data->setDiffusFactor( 0.4f );
+        data->setSpecularFactor( 0.4f );
+        Framework::zM3DRegister()->addModel( dynamic_cast<Model3DData*>(data->getThis()), "cube" );
         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 );
+        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 );
+        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 ];
+        Vertex3D* vertecies = new Vertex3D[ 24 ];
         for( int i = 0; i < 24; i++ )
             vertecies[ i ].knochenId = 0;
         vertecies[ 0 ].pos = Vec3<float >( left, top, front );
@@ -84,10 +87,10 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
         vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
 
-        model->setVertecies( vertecies, 24 );
+        data->setVertecies( vertecies, 24 );
 
         // front side
-        Polygon3D *p = new Polygon3D();
+        Polygon3D* p = new Polygon3D();
         p->indexAnz = 6;
         p->indexList = new int[ p->indexAnz ];
         p->indexList[ 0 ] = 0;
@@ -96,7 +99,7 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 0;
         p->indexList[ 4 ] = 1;
         p->indexList[ 5 ] = 3;
-        model->addPolygon( p );
+        data->addPolygon( p );
         // back side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -107,7 +110,7 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 4;
         p->indexList[ 4 ] = 7;
         p->indexList[ 5 ] = 5;
-        model->addPolygon( p );
+        data->addPolygon( p );
         // right side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -118,7 +121,7 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 1 + 8;
         p->indexList[ 4 ] = 5 + 8;
         p->indexList[ 5 ] = 7 + 8;
-        model->addPolygon( p );
+        data->addPolygon( p );
         // left side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -129,7 +132,7 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 0 + 8;
         p->indexList[ 4 ] = 6 + 8;
         p->indexList[ 5 ] = 4 + 8;
-        model->addPolygon( p );
+        data->addPolygon( p );
         // top side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -140,7 +143,7 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 4 + 16;
         p->indexList[ 4 ] = 5 + 16;
         p->indexList[ 5 ] = 1 + 16;
-        model->addPolygon( p );
+        data->addPolygon( p );
         // down side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -151,18 +154,19 @@ BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Te
         p->indexList[ 3 ] = 6 + 16;
         p->indexList[ 4 ] = 3 + 16;
         p->indexList[ 5 ] = 7 + 16;
-        model->addPolygon( p );
+        data->addPolygon( p );
+        data->calculateNormals();
     }
     setModelDaten( data );
-    Bild *b = new Bild();
-    b->neuBild( 10, 10, 0xFF2B240B );
-    Textur *tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "dirt", b );
-    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() ) );
+    Bild* b = new Bild();
+    b->neuBild( 10, 10, 0xFFFFFFFF );
+    Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "dirt", b );
+    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 );
 }
@@ -172,15 +176,36 @@ DirtBlockType::DirtBlockType()
     : BlockType( ID )
 {}
 
-void DirtBlockType::loadSuperBlock( Block *zBlock, Framework::StreamReader *zReader )
+void DirtBlockType::loadSuperBlock( Block* zBlock, Framework::StreamReader* zReader )
 {
     BlockType::loadSuperBlock( zBlock, zReader );
 }
 
-Block *DirtBlockType::createBlock( Framework::Vec3<int> position )
+Block* DirtBlockType::createBlock( Framework::Vec3<int> position )
 {
     // TODO: load texture
-    return new BasicBlock( 0, position, 0 ); // TODO: add efective tool
+    Block* b = new BasicBlock( DirtBlockType::INSTANCE, 0, position, 0 ); // TODO: add efective tool
+    initializeSuperBlock( b );
+    return b;
+}
+
+void DirtBlockType::initializeSuperBlock( Block* zBlock )
+{
+    BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
+    if( !block )
+        throw "DirtBlockType::createSuperBlock was called with a block witch is not an instance of BasicBlock";
+    block->transparent = 0;
+    block->passable = 0;
+    block->hp = 100;
+    block->maxHP = 100;
+    block->hardness = 1;
+    block->zTool = 0;
+    block->speedModifier = 1;
+}
+
+bool DirtBlockType::needsInstance() const
+{
+    return 1;
 }
 
 
@@ -188,8 +213,8 @@ DirtBlockItemType::DirtBlockItemType()
     : BasicBlockItemType( ID )
 {}
 
-Item *DirtBlockItemType::createItem() const
+Item* DirtBlockItemType::createItem() const
 {
-    BasicBlockItem *item = new BasicBlockItem( (ItemType *)this, "Dirt" );
+    BasicBlockItem* item = new BasicBlockItem( (ItemType*)this, "Dirt" );
     return item;
 }

+ 9 - 4
FactoryCraft/BasicBlocks.h

@@ -14,7 +14,7 @@ class DirtBlockItemType;
 class BasicBlock : public Block
 {
 public:
-    BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Textur *t );
+    BasicBlock( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t );
 
     friend DirtBlockType;
 };
@@ -24,9 +24,14 @@ class DirtBlockType : public BlockType
     REGISTRABLE( DirtBlockType )
 
 protected:
-    virtual void loadSuperBlock( Block *zBlock, Framework::StreamReader *zReader ) override;
-    virtual Block *createBlock( Framework::Vec3<int> position ) override;
     DirtBlockType();
+    virtual void loadSuperBlock( Block* zBlock, Framework::StreamReader* zReader ) override;
+
+public:
+    virtual Block* createBlock( Framework::Vec3<int> position ) override;
+    virtual void initializeSuperBlock( Block* zBlock )  override;
+    virtual bool needsInstance() const override;
+
 };
 REGISTER( DirtBlockType, BlockType )
 
@@ -38,6 +43,6 @@ protected:
     DirtBlockItemType();
 
 public:
-    virtual Item *createItem() const override;
+    virtual Item* createItem() const override;
 };
 REGISTER( DirtBlockItemType, ItemType )

+ 43 - 21
FactoryCraft/Block.cpp

@@ -3,8 +3,10 @@
 #include "Globals.h"
 
 
-Block::Block( ItemType *zTool, Framework::Vec3<int> pos, bool hasInventory )
-    : Inventory( pos, hasInventory )
+Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
+    : Inventory( pos, hasInventory ),
+    Model3D(),
+    zType( zType )
 {
     visible = false;
     transparent = false;
@@ -14,7 +16,9 @@ Block::Block( ItemType *zTool, Framework::Vec3<int> pos, bool hasInventory )
     hardness = 1;
     this->zTool = zTool;
     speedModifier = 1;
-    memset( zNeighbours, 0, sizeof( Block * ) * 6 );
+    memset( zNeighbours, 0, sizeof( Block* ) * 6 );
+    memset( neighbourTypes, 0, sizeof( int ) * 6 );
+    Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
 }
 
 Block::~Block()
@@ -22,14 +26,9 @@ Block::~Block()
 
 bool Block::updateVisibility()
 {
-    bool v = 0;
+    bool v = 1;
     for( int d = 0; d < 6; d++ )
-    {
-        if( IS_BLOCK( zNeighbours[ d ] ) )
-            v |= zNeighbours[ d ]->isVisible() && (zNeighbours[ d ]->transparent || zNeighbours[ d ]->passable);
-        else if( zNeighbours[ d ] )
-            v = 1;
-    }
+        v |= CONST_BLOCK( zNeighbours[ d ], neighbourTypes[ d ] )->isVisible() && (CONST_BLOCK( zNeighbours[ d ], neighbourTypes[ d ] )->transparent || CONST_BLOCK( zNeighbours[ d ], neighbourTypes[ d ] )->passable);
     if( v != visible )
     {
         visible = v;
@@ -39,18 +38,41 @@ bool Block::updateVisibility()
     return false;
 }
 
-void Block::setNeighbour( Direction dir, Block *zN )
+void Block::setNeighbour( Direction dir, Framework::Either<Block*, int> neighbour )
+{
+    if( neighbour.isA() )
+        setNeighbourBlock( dir, neighbour );
+    else
+    {
+        setNeighbourBlock( dir, 0 );
+        setNeighbourType( dir, neighbour );
+    }
+}
+
+void Block::setNeighbourBlock( Direction dir, Block* zN )
 {
+    if( zN )
+        setNeighbourType( dir, zN->zBlockType()->getId() );
     zNeighbours[ getDirectionIndex( dir ) ] = zN;
 }
 
+void Block::setNeighbourType( Direction dir, int type )
+{
+    neighbourTypes[ getDirectionIndex( dir ) ] = type;
+}
+
 bool Block::isVisible() const
 {
     return visible;
 }
 
+const BlockType* Block::zBlockType() const
+{
+    return zType;
+}
+
 
-BasicBlockItem::BasicBlockItem( const ItemType *zType, const char *name )
+BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
     : Item( zType, name )
 {
     placeable = 1;
@@ -68,17 +90,17 @@ BasicBlockItemType::BasicBlockItemType( int id )
     : ItemType( id )
 {}
 
-void BasicBlockItemType::loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const
+void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
 {
     ItemType::loadSuperItem( zItem, zReader );
-    BasicBlockItem *item = dynamic_cast<BasicBlockItem *>(zItem);
+    BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
     if( !item )
         throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
-    zReader->lese( (char *)&item->transparent, 1 );
-    zReader->lese( (char *)&item->passable, 1 );
-    zReader->lese( (char *)&item->hp, 4 );
-    zReader->lese( (char *)&item->maxHP, 4 );
-    zReader->lese( (char *)&item->hardness, 4 );
-    zReader->lese( (char *)&item->toolId, 4 );
-    zReader->lese( (char *)&item->speedModifier, 4 );
+    zReader->lese( (char*)&item->transparent, 1 );
+    zReader->lese( (char*)&item->passable, 1 );
+    zReader->lese( (char*)&item->hp, 4 );
+    zReader->lese( (char*)&item->maxHP, 4 );
+    zReader->lese( (char*)&item->hardness, 4 );
+    zReader->lese( (char*)&item->toolId, 4 );
+    zReader->lese( (char*)&item->speedModifier, 4 );
 }

+ 16 - 10
FactoryCraft/Block.h

@@ -1,21 +1,22 @@
 #pragma once
 
 #include <Model3D.h>
+#include <Either.h>
 
 #include "Inventory.h"
 #include "Chunk.h"
 #include "BlockType.h"
+#include "Registries.h"
 
 using namespace Framework;
 
-class BasicBlockItemType;
+#define CONST_BLOCK(maybeBlock, type) (maybeBlock ? maybeBlock : STATIC_REGISTRY( BlockType ).zElement((int)type)->zDefault())
 
-#define AIR_BLOCK -1
-#define IS_BLOCK(b) (((__int64)b) > 0)
+class BasicBlockItemType;
 
 class Block : public Model3D, public Inventory
 {
-private:
+protected:
     bool visible;
     bool transparent;
     bool passable;
@@ -23,17 +24,22 @@ private:
     float maxHP;
     float hardness;
     float speedModifier;
-    ItemType *zTool;
-    Block *zNeighbours[ 6 ];
+    const BlockType* zType;
+    ItemType* zTool;
+    Block* zNeighbours[ 6 ];
+    int neighbourTypes[ 6 ];
 
 public:
-    Block( ItemType *zTool, Vec3<int> position, bool hasInventory );
+    Block( const BlockType* zType, ItemType* zTool, Vec3<int> position, bool hasInventory );
     virtual ~Block();
 
     bool updateVisibility();
-    virtual void setNeighbour( Direction dir, Block *zN );
+    virtual void setNeighbour( Direction dir, Framework::Either<Block*, int> neighbour );
+    virtual void setNeighbourBlock( Direction dir, Block* zN );
+    virtual void setNeighbourType( Direction dir, int type );
 
     bool isVisible() const;
+    const BlockType* zBlockType() const;
     friend Chunk;
     friend BlockType;
 };
@@ -50,7 +56,7 @@ protected:
     float speedModifier;
 
 public:
-    BasicBlockItem( const ItemType *zType, const char *name );
+    BasicBlockItem( const ItemType* zType, const char* name );
 
     friend BasicBlockItemType;
     friend BlockType;
@@ -60,5 +66,5 @@ class BasicBlockItemType : public ItemType
 {
 protected:
     BasicBlockItemType( int id );
-    virtual void loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const override;
+    virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const override;
 };

+ 32 - 13
FactoryCraft/BlockType.cpp

@@ -1,32 +1,44 @@
 #include "BlockType.h"
 #include "Block.h"
 
+#include "Registries.h"
+
 using namespace Framework;
 
 BlockType::BlockType( int id )
     : ReferenceCounter(),
-    id( id )
+    id( id ),
+    defaultBlock( 0 )
+{
+    STATIC_REGISTRY( BlockType ).registerT( this, id );
+}
+
+BlockType::~BlockType()
 {
-    StaticRegistry<BlockType>::INSTANCE.registerT( this, id );
+    if( defaultBlock )
+        defaultBlock->release();
 }
 
-void BlockType::loadSuperBlock( Block *zBlock, Framework::StreamReader *zReader )
+void BlockType::loadSuperBlock( Block* zBlock, Framework::StreamReader* zReader )
 {
     zBlock->loadInventory( zReader );
-    zReader->lese( (char *)&zBlock->transparent, 1 );
-    zReader->lese( (char *)&zBlock->passable, 1 );
-    zReader->lese( (char *)&zBlock->hp, 4 );
-    zReader->lese( (char *)&zBlock->maxHP, 4 );
-    zReader->lese( (char *)&zBlock->hardness, 4 );
-    zReader->lese( (char *)&zBlock->speedModifier, 4 );
+    zReader->lese( (char*)&zBlock->transparent, 1 );
+    zReader->lese( (char*)&zBlock->passable, 1 );
+    zReader->lese( (char*)&zBlock->hp, 4 );
+    zReader->lese( (char*)&zBlock->maxHP, 4 );
+    zReader->lese( (char*)&zBlock->hardness, 4 );
+    zReader->lese( (char*)&zBlock->speedModifier, 4 );
     int effectiveToolId;
-    zReader->lese( (char *)&effectiveToolId, 4 );
-    zBlock->zTool = StaticRegistry<ItemType>::INSTANCE.zElement( effectiveToolId );
+    zReader->lese( (char*)&effectiveToolId, 4 );
+    if( effectiveToolId >= 0 )
+        zBlock->zTool = STATIC_REGISTRY( ItemType ).zElement( effectiveToolId );
+    else
+        zBlock->zTool = 0;
 }
 
-Block *BlockType::loadBlock( Framework::Vec3<int> position, Framework::StreamReader *zReader )
+Block* BlockType::loadBlock( Framework::Vec3<int> position, Framework::StreamReader* zReader )
 {
-    Block *result = createBlock( position );
+    Block* result = createBlock( position );
     loadSuperBlock( result, zReader );
     return result;
 }
@@ -34,4 +46,11 @@ Block *BlockType::loadBlock( Framework::Vec3<int> position, Framework::StreamRea
 int BlockType::getId() const
 {
     return id;
+}
+
+const Block* BlockType::zDefault()
+{
+    if( !defaultBlock )
+        defaultBlock = createBlock( { 0, 0, 0 } );
+    return defaultBlock;
 }

+ 8 - 3
FactoryCraft/BlockType.h

@@ -12,15 +12,20 @@ class BlockType : public virtual Framework::ReferenceCounter
 {
 private:
     const int id;
+    Block* defaultBlock;
 
 protected:
     BlockType( int id );
+    virtual ~BlockType();
 
-    virtual void loadSuperBlock( Block *zBlock, Framework::StreamReader *zReader );
-    virtual Block *createBlock( Framework::Vec3<int> position ) = 0;
+    virtual void loadSuperBlock( Block* zBlock, Framework::StreamReader* zReader );
+    virtual void initializeSuperBlock( Block* zBlock ) = 0;
 
 public:
-    virtual Block *loadBlock( Framework::Vec3<int> position, Framework::StreamReader *zReader );
+    virtual Block* createBlock( Framework::Vec3<int> position ) = 0;
+    virtual Block* loadBlock( Framework::Vec3<int> position, Framework::StreamReader* zReader );
+    virtual const Block* zDefault();
+    virtual bool needsInstance() const = 0;
 
     int getId() const;
 };

+ 106 - 49
FactoryCraft/Chunk.cpp

@@ -3,6 +3,8 @@
 #include "Block.h"
 #include "Globals.h"
 
+#include "Registries.h"
+
 
 Chunk::Chunk( Framework::Punkt location, int dimensionId )
     : ReferenceCounter(),
@@ -10,15 +12,16 @@ Chunk::Chunk( Framework::Punkt location, int dimensionId )
     location( location )
 {
     blocks = new Block * [ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
-    Block *val = (Block *)AIR_BLOCK;
-    std::uninitialized_fill_n( blocks, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT, val );
+    blockIds = new unsigned short[ CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT ];
+    memset( blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof( Block* ) );
+    memset( blockIds, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof( unsigned short ) );
     zNeighbours[ 0 ] = 0;
     zNeighbours[ 1 ] = 0;
     zNeighbours[ 2 ] = 0;
     zNeighbours[ 3 ] = 0;
 }
 
-Chunk::Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader *zReader )
+Chunk::Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader )
     : Chunk( location, dimensionId )
 {
     load( zReader );
@@ -28,16 +31,23 @@ Chunk::~Chunk()
 {
     for( int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++ )
     {
-        if( IS_BLOCK( blocks[ i ] ) )
+        if( blocks[ i ] )
             blocks[ i ]->release();
     }
     delete[] blocks;
+    delete[] blockIds;
 }
 
-Block *Chunk::zBlockNeighbor( Framework::Vec3<int> location )
+Framework::Either<Block*, int> 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 ];
+    {
+        int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
+        if( blocks[ index ] )
+            return blocks[ index ];
+        else
+            return (int)blockIds[ index ];
+    }
     if( location.z >= 0 && location.z < WORLD_HEIGHT )
         return currentGame->zBlockAt( { location.x + this->location.x - CHUNK_SIZE / 2, location.y + this->location.y - CHUNK_SIZE / 2, location.z }, dimensionId );
     return 0;
@@ -48,66 +58,101 @@ bool Chunk::updateVisibility()
     bool update = false;
     for( int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++ )
     {
-        if( IS_BLOCK( blocks[ i ] ) )
+        if( blocks[ i ] )
             update |= blocks[ i ]->updateVisibility();
     }
     return update;
 }
 
-Block *Chunk::getBlockAt( Framework::Vec3<int> location ) const
+Framework::Either<Block*, int> Chunk::zBlockAt( Framework::Vec3<int> location ) const
 {
-    Block *result = zBlockAt( location );
-    if( result )
-        return dynamic_cast<Block *>(result->getThis());
-    return 0;
+    int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
+    assert( index < CHUNK_SIZE* CHUNK_SIZE* WORLD_HEIGHT );
+    if( blocks[ index ] )
+        return blocks[ index ];
+    else
+        return (int)blockIds[ index ];
 }
 
-Block *Chunk::zBlockAt( Framework::Vec3<int> location ) const
+const Block* Chunk::zBlockConst( Framework::Vec3<int> location ) const
 {
-    return blocks[ (location.x * CHUNK_SIZE + location.y) * CHUNK_SIZE + location.z ];
+    Block* b = zBlockAt( location );
+    if( b )
+        return b;
+    int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
+    if( blockIds[ index ] )
+        return STATIC_REGISTRY( BlockType ).zElement( blockIds[ index ] )->zDefault();
+    return 0;
 }
 
-void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
+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 ];
+    assert( index < CHUNK_SIZE* CHUNK_SIZE* WORLD_HEIGHT );
+    Block* old = blocks[ index ];
+    if( block )
+        blockIds[ index ] = (unsigned short)block->zBlockType()->getId();
     blocks[ index ] = block;
-    Block *neighbor = zBlockNeighbor( location + getDirection( NORTH ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( SOUTH, block );
-    if( IS_BLOCK( block ) )
+    Either<Block*, int> neighbor = zBlockNeighbor( location + getDirection( NORTH ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( SOUTH, block );
+    if( block )
         block->setNeighbour( NORTH, neighbor );
     neighbor = zBlockNeighbor( location + getDirection( EAST ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( WEST, block );
-    if( IS_BLOCK( block ) )
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( WEST, block );
+    if( block )
         block->setNeighbour( EAST, neighbor );
     neighbor = zBlockNeighbor( location + getDirection( SOUTH ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( NORTH, block );
-    if( IS_BLOCK( block ) )
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( NORTH, block );
+    if( block )
         block->setNeighbour( SOUTH, neighbor );
     neighbor = zBlockNeighbor( location + getDirection( WEST ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( EAST, block );
-    if( IS_BLOCK( block ) )
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( EAST, block );
+    if( block )
         block->setNeighbour( WEST, neighbor );
     neighbor = zBlockNeighbor( location + getDirection( TOP ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( BOTTOM, block );
-    if( IS_BLOCK( block ) )
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( BOTTOM, block );
+    if( block )
         block->setNeighbour( TOP, neighbor );
     neighbor = zBlockNeighbor( location + getDirection( BOTTOM ) );
-    if( IS_BLOCK( neighbor ) )
-        neighbor->setNeighbour( TOP, block );
-    if( IS_BLOCK( block ) )
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbour( TOP, block );
+    if( block )
         block->setNeighbour( BOTTOM, neighbor );
-    if( IS_BLOCK( old ) )
+    if( old )
         old->release();
 }
 
-void Chunk::setNeighbor( Direction dir, Chunk *zChunk )
+void Chunk::putBlockTypeAt( Framework::Vec3<int> location, int type )
+{
+    int index = (location.x * CHUNK_SIZE + location.y) * WORLD_HEIGHT + location.z;
+    assert( index < CHUNK_SIZE* CHUNK_SIZE* WORLD_HEIGHT );
+    blockIds[ index ] = (unsigned short)type;
+    Either<Block*, int> neighbor = zBlockNeighbor( location + getDirection( NORTH ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( SOUTH, type );
+    neighbor = zBlockNeighbor( location + getDirection( EAST ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( WEST, type );
+    neighbor = zBlockNeighbor( location + getDirection( SOUTH ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( NORTH, type );
+    neighbor = zBlockNeighbor( location + getDirection( WEST ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( EAST, type );
+    neighbor = zBlockNeighbor( location + getDirection( TOP ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( BOTTOM, type );
+    neighbor = zBlockNeighbor( location + getDirection( BOTTOM ) );
+    if( neighbor.isA() )
+        ((Block*)neighbor)->setNeighbourType( TOP, type );
+}
+
+void Chunk::setNeighbor( Direction dir, Chunk* zChunk )
 {
     zNeighbours[ getDirectionIndex( dir ) ] = zChunk;
     for( int i = 0; i < CHUNK_SIZE; i++ )
@@ -117,45 +162,57 @@ void Chunk::setNeighbor( Direction dir, Chunk *zChunk )
             if( dir == NORTH )
             {
                 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 ] );
+                if( blocks[ index ] )
+                {
+                    int j = (i * CHUNK_SIZE + CHUNK_SIZE - 1) * WORLD_HEIGHT + z;
+                    if( zChunk->blocks[ j ] )
+                        blocks[ index ]->setNeighbour( NORTH, zChunk->blocks[ j ] );
+                    else
+                        blocks[ index ]->setNeighbourType( NORTH, zChunk->blockIds[ j ] );
+                }
             }
             else if( dir == EAST )
             {
                 int index = ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z;
-                if( IS_BLOCK( blocks[ index ] ) )
+                if( 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( 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( blocks[ index ] )
                     blocks[ index ]->setNeighbour( WEST, zChunk->blocks[ ((CHUNK_SIZE - 1) * CHUNK_SIZE + i) * WORLD_HEIGHT + z ] );
             }
         }
     }
 }
 
-void Chunk::load( Framework::StreamReader *zReader )
+void Chunk::load( Framework::StreamReader* zReader )
 {
+    zReader->lese( (char*)blockIds, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof( unsigned short ) );
     for( int x = 0; x < CHUNK_SIZE; x++ )
     {
         for( int y = 0; y < CHUNK_SIZE; y++ )
         {
             for( int z = 0; z < WORLD_HEIGHT; z++ )
             {
-                int blockType;
-                zReader->lese( (char *)&blockType, 4 );
-                if( blockType >= 0 )
-                {
-                    Block *block = StaticRegistry<BlockType>::INSTANCE.zElement( blockType )->loadBlock( Framework::Vec3<int>( x, y, z ), zReader );
+                unsigned short blockType;
+                zReader->lese( (char*)&blockType, 2 );
+                Block* block = STATIC_REGISTRY( BlockType ).zElement( blockType )->loadBlock( Framework::Vec3<int>( x + location.x - CHUNK_SIZE / 2, y + location.y - CHUNK_SIZE / 2, z ), zReader );
+                if( block )
                     putBlockAt( { x, y, z }, block );
+                else
+                {
+                    if( STATIC_REGISTRY( BlockType ).zElement( blockIds[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ] )->needsInstance() )
+                        putBlockAt( { x, y, z }, STATIC_REGISTRY( BlockType ).zElement( blockIds[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ] )->createBlock( { x + location.x - CHUNK_SIZE / 2, y + location.y - CHUNK_SIZE / 2, z } ) );
+                    else
+                        putBlockTypeAt( { x, y, z }, blockIds[ (x * CHUNK_SIZE + y) * WORLD_HEIGHT + z ] );
                 }
             }
         }

+ 12 - 9
FactoryCraft/Chunk.h

@@ -3,6 +3,7 @@
 #include <Punkt.h>
 #include <ReferenceCounter.h>
 #include <Reader.h>
+#include <Either.h>
 
 #include "Area.h"
 
@@ -13,20 +14,22 @@ class Chunk : public virtual Framework::ReferenceCounter
 private:
     int dimensionId;
     Framework::Punkt location;
-    Block **blocks;
-    Chunk *zNeighbours[ 4 ];
-    Block *zBlockNeighbor( Framework::Vec3<int> location );
+    Block** blocks;
+    unsigned short* blockIds;
+    Chunk* zNeighbours[ 4 ];
+    Framework::Either<Block*, int> zBlockNeighbor( Framework::Vec3<int> location );
 
 public:
     Chunk( Framework::Punkt location, int dimensionId );
-    Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader *zReader );
+    Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader );
     ~Chunk();
     bool updateVisibility();
-    Block *getBlockAt( Framework::Vec3<int> cLocation ) const;
-    Block *zBlockAt( Framework::Vec3<int> cLocation ) const;
-    void putBlockAt( Framework::Vec3<int> location, Block *block );
-    void setNeighbor( Direction dir, Chunk *zChunk );
-    void load( Framework::StreamReader *zReader );
+    Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> cLocation ) const;
+    const Block* zBlockConst( Framework::Vec3<int> location ) const;
+    void putBlockAt( Framework::Vec3<int> location, Block* block );
+    void putBlockTypeAt( Framework::Vec3<int> location, int type );
+    void setNeighbor( Direction dir, Chunk* zChunk );
+    void load( Framework::StreamReader* zReader );
     int getDimensionId() const;
     Framework::Punkt getCenter() const;
     Framework::Vec3<int> getMin() const;

+ 2 - 2
FactoryCraft/CurrentPlayer.h

@@ -5,6 +5,6 @@
 class CurrentPlayer : public Framework::ReferenceCounter
 {
 private:
-    Entity *entity;
-    Framework::Kam3D *kam3D;
+    Entity* entity;
+    Framework::Kam3D* kam3D;
 };

+ 16 - 12
FactoryCraft/Dimension.cpp

@@ -25,19 +25,22 @@ void Dimension::updateVisibility()
     while( changed )
     {
         changed = false;
-        for( auto chunk = chunks->getIterator(); chunk; chunk++ )
-            changed |= chunk->updateVisibility();
+        for( auto chunk : chunkList )
+        {
+            if( chunk )
+                changed |= chunk->updateVisibility();
+        }
     }
 }
 
-void Dimension::getAddrOf( Punkt cPos, char *addr ) const
+void Dimension::getAddrOf( Punkt cPos, char* addr ) const
 {
-    *(int *)addr = cPos.x;
-    *( (int *)addr + 1 ) = cPos.y;
+    *(int*)addr = cPos.x;
+    *((int*)addr + 1) = cPos.y;
     addr[ 8 ] = 0;
 }
 
-void Dimension::getAddrOfWorld( Punkt wPos, char *addr ) const
+void Dimension::getAddrOfWorld( Punkt wPos, char* addr ) const
 {
     if( wPos.x < 0 )
         wPos.x -= CHUNK_SIZE;
@@ -47,16 +50,16 @@ void Dimension::getAddrOfWorld( Punkt wPos, char *addr ) const
     getAddrOf( wPos, addr );
 }
 
-Chunk *Dimension::zChunk( Punkt wPos ) const
+Chunk* Dimension::zChunk( Punkt wPos ) const
 {
     char addr[ 9 ];
     getAddrOfWorld( wPos, addr );
     return chunks->z( addr, 9 );
 }
 
-Block *Dimension::zBlock( Vec3<int> location )
+Framework::Either<Block*, int> Dimension::zBlock( Vec3<int> location )
 {
-    Chunk *c = zChunk( currentGame->getChunkCenter( location.x, location.y ) );
+    Chunk* c = zChunk( currentGame->getChunkCenter( location.x, location.y ) );
     if( c )
     {
         int x = location.x % CHUNK_SIZE;
@@ -70,20 +73,21 @@ Block *Dimension::zBlock( Vec3<int> location )
     return 0;
 }
 
-void Dimension::addEntity( Entity *entity )
+void Dimension::addEntity( Entity* entity )
 {
     entities->add( entity );
 }
 
-void Dimension::addChunk( Chunk *chunk )
+void Dimension::addChunk( Chunk* chunk )
 {
     char addr[ 9 ];
     getAddrOfWorld( chunk->getCenter(), addr );
     if( !chunks->z( addr, 9 ) )
     {
         chunks->set( addr, 9, chunk );
+        chunkList.add( chunk );
         getAddrOfWorld( chunk->getCenter() + Punkt( CHUNK_SIZE, 0 ), addr );
-        Chunk *zChunk = chunks->z( addr, 9 );
+        Chunk* zChunk = chunks->z( addr, 9 );
         if( zChunk )
         {
             zChunk->setNeighbor( WEST, chunk );

+ 9 - 8
FactoryCraft/Dimension.h

@@ -10,20 +10,21 @@ class Dimension : public virtual Framework::ReferenceCounter
 {
 private:
     int dimensionId;
-    Framework::Trie<Chunk> *chunks;
-    Framework::RCArray<Entity> *entities;
-    void getAddrOf( Framework::Punkt cPos, char *addr ) const;
-    void getAddrOfWorld( Framework::Punkt wPos, char *addr ) const;
+    Framework::Trie<Chunk>* chunks;
+    Framework::Array<Chunk*> chunkList;
+    Framework::RCArray<Entity>* entities;
+    void getAddrOf( Framework::Punkt cPos, char* addr ) const;
+    void getAddrOfWorld( Framework::Punkt wPos, char* addr ) const;
 
 public:
     Dimension( int id );
     ~Dimension();
 
     void updateVisibility();
-    Block *zBlock( Framework::Vec3<int> location );
-    void addEntity( Entity *entity );
-    void addChunk( Chunk *chunk );
+    Framework::Either<Block*, int> zBlock( Framework::Vec3<int> location );
+    void addEntity( Entity* entity );
+    void addChunk( Chunk* chunk );
     int getDimensionId() const;
     bool hasChunck( int x, int y ) const;
-    Chunk *zChunk( Framework::Punkt wPos ) const;
+    Chunk* zChunk( Framework::Punkt wPos ) const;
 };

+ 6 - 7
FactoryCraft/DirectConnect.cpp

@@ -2,19 +2,18 @@
 #include "Initialisierung.h"
 #include "Globals.h"
 
-DirectConnect::DirectConnect( Bildschirm *zScreen )
+DirectConnect::DirectConnect( Bildschirm* zScreen )
     : Menu( zScreen )
 {
     elements.add( initTextFeld( 10, 10, 90, 20, TextFeld::Style::Text, "Adresse: " ) );
     elements.add( initTextFeld( 10, 35, 90, 20, TextFeld::Style::Text, "Port: " ) );
-    address = initTextFeld( 100, 10, 200, 20, TextFeld::Style::TextFeld, "" );
-    port = initTextFeld( 100, 35, 200, 20, TextFeld::Style::TextFeld, "" );
+    address = initTextFeld( 100, 10, 200, 20, TextFeld::Style::TextFeld, "koljastrohm-games.com" );
+    port = initTextFeld( 100, 35, 200, 20, TextFeld::Style::TextFeld, "5425" );
     port->setTastaturEreignis( _nurNummernTE );
     elements.add( address );
     elements.add( port );
-    Knopf *login = initKnopf( 200, 60, 100, 20, Knopf::Style::Normal, "Beitreten" );
-    login->setMausEreignis( [this, login, zScreen]( void *p, void *o, MausEreignis me )
-    {
+    Knopf* login = initKnopf( 200, 60, 100, 20, Knopf::Style::Normal, "Beitreten" );
+    login->setMausEreignis( [this, login, zScreen]( void* p, void* o, MausEreignis me ) {
         if( me.id == ME_RLinks )
         {
             login->removeStyle( Knopf::Style::Erlaubt );
@@ -22,7 +21,7 @@ DirectConnect::DirectConnect( Bildschirm *zScreen )
             port->removeStyle( TextFeld::Style::Erlaubt );
             if( network->connect( address->zText()->getText(), (short)(int)*port->zText() ) )
             {
-                currentGame = new World( dynamic_cast<Bildschirm3D *>( zScreen ) );
+                currentGame = new World( dynamic_cast<Bildschirm3D*>(zScreen) );
                 hide();
                 menuRegister->get( "game" )->show();
             }

+ 3 - 3
FactoryCraft/DirectConnect.h

@@ -6,9 +6,9 @@
 class DirectConnect : public Menu
 {
 private:
-    TextFeld *address;
-    TextFeld *port;
+    TextFeld* address;
+    TextFeld* port;
 
 public:
-    DirectConnect( Bildschirm *zScreen );
+    DirectConnect( Bildschirm* zScreen );
 };

+ 18 - 5
FactoryCraft/FactoryClient.cpp

@@ -25,10 +25,10 @@ bool FactoryClient::connect( Text ip, short port, int accountId, Text secret )
     connected = 1;
     if( !client->sende( "\1", 1 ) )
         return false;
-    if( !client->sende( (char *)&accountId, 4 ) )
+    if( !client->sende( (char*)&accountId, 4 ) )
         return false;
     unsigned char len = (unsigned char)secret.getLength();
-    if( !client->sende( (char *)&len, 1 ) )
+    if( !client->sende( (char*)&len, 1 ) )
         return false;
     if( !client->sende( secret, len ) )
         return false;
@@ -52,7 +52,7 @@ void FactoryClient::disconnect()
     }
 }
 
-NetworkReader *FactoryClient::getNextMessage()
+NetworkReader* FactoryClient::getNextMessage()
 {
     if( !client )
         return 0;
@@ -68,7 +68,20 @@ NetworkReader *FactoryClient::getNextMessage()
         client = 0;
         return 0;
     }
-    if( !client->hatNachricht( 0 ) )
-        return 0;
     return reader;
+}
+
+void FactoryClient::sendPlayerAction( void* data, unsigned short length )
+{
+    if( !client )
+        return;
+    cs.lock();
+    char msgId = 3;
+    client->sende( &msgId, 1 );
+    length += 1;
+    client->sende( (char*)&length, 2 );
+    msgId = 2;
+    client->sende( &msgId, 1 );
+    client->sende( (char*)data, length - 1 );
+    cs.unlock();
 }

+ 6 - 3
FactoryCraft/FactoryClient.h

@@ -4,19 +4,22 @@
 #include <Klient.h>
 #include <Text.h>
 #include <Thread.h>
+#include <Critical.h>
 
 class FactoryClient : public Framework::ReferenceCounter
 {
 private:
-    Network::SSLKlient *client;
+    Network::SSLKlient* client;
     bool connected;
     void disconnect();
-    Network::NetworkReader *reader;
+    Network::NetworkReader* reader;
+    Framework::Critical cs;
 
 public:
     FactoryClient();
     ~FactoryClient();
 
     bool connect( Text ip, short port, int accountId, Text secret );
-    Network::NetworkReader *getNextMessage();
+    Network::NetworkReader* getNextMessage();
+    void sendPlayerAction( void* data, unsigned short length );
 };

BIN
FactoryCraft/FactoryCraft.exe


+ 10 - 3
FactoryCraft/FactoryCraft.vcxproj

@@ -34,7 +34,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v142</PlatformToolset>
+    <PlatformToolset>v143</PlatformToolset>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -85,7 +85,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <LinkIncremental>false</LinkIncremental>
-    <IncludePath>..\..\..\KSGNetwork\Include;..\..\..\..\..\Allgemein\Framework;..\..\..\Include;..\..\..\..\..\Allgemein\Network\Network;$(IncludePath)</IncludePath>
+    <IncludePath>..\..\..\..\Klient\KSGNetwork\Include;..\..\..\..\..\Allgemein\Framework;..\..\..\Include;..\..\..\..\..\Allgemein\Network\Network;$(IncludePath)</IncludePath>
     <LibraryPath>..\..\..\..\..\Allgemein\Framework\x64\Release;..\..\..\..\..\Allgemein\Network\x64\Release;$(LibraryPath)</LibraryPath>
     <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>
   </PropertyGroup>
@@ -109,6 +109,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FANGEN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <LanguageStandard>stdcpp17</LanguageStandard>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -164,7 +165,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Debug\Network.dll" "network.dll"</Com
     </Link>
     <CustomBuildStep>
       <Outputs>kopieren...;%(Outputs)</Outputs>
-      <Command>copy "..\x64\Release\FactoryCraft.exe" "..\..\Fertig\FactoryCraft\Client"</Command>
+      <Command>copy "..\..\..\..\..\Allgemein\Framework\x64\Release\Framework.dll" "framework.dll"
+copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</Command>
     </CustomBuildStep>
   </ItemDefinitionGroup>
   <ItemGroup>
@@ -189,6 +191,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Debug\Network.dll" "network.dll"</Com
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Menu.cpp" />
     <ClCompile Include="NetworkHandler.cpp" />
+    <ClCompile Include="NoBlock.cpp" />
+    <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="StaticInitializerOrder.cpp" />
     <ClCompile Include="World.cpp" />
     <ClCompile Include="WorldUpdate.cpp" />
@@ -217,6 +221,9 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Debug\Network.dll" "network.dll"</Com
     <ClInclude Include="Login.h" />
     <ClInclude Include="Menu.h" />
     <ClInclude Include="NetworkHandler.h" />
+    <ClInclude Include="NoBlock.h" />
+    <ClInclude Include="PlayerKam.h" />
+    <ClInclude Include="Registries.h" />
     <ClInclude Include="StaticRegistry.h" />
     <ClInclude Include="WorldUpdate.h" />
     <ClInclude Include="World.h" />

+ 18 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -28,6 +28,9 @@
     <Filter Include="world\blocks">
       <UniqueIdentifier>{3a74980a-cc13-4580-9921-d32b06389e35}</UniqueIdentifier>
     </Filter>
+    <Filter Include="world\view">
+      <UniqueIdentifier>{494659c8-0209-497f-9200-86215d7680bf}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Main.cpp">
@@ -102,6 +105,12 @@
     <ClCompile Include="StaticInitializerOrder.cpp">
       <Filter>static</Filter>
     </ClCompile>
+    <ClCompile Include="PlayerKam.cpp">
+      <Filter>world\view</Filter>
+    </ClCompile>
+    <ClCompile Include="NoBlock.cpp">
+      <Filter>world\blocks</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Menu.h">
@@ -182,5 +191,14 @@
     <ClInclude Include="Constants.h">
       <Filter>static</Filter>
     </ClInclude>
+    <ClInclude Include="Registries.h">
+      <Filter>static</Filter>
+    </ClInclude>
+    <ClInclude Include="PlayerKam.h">
+      <Filter>world\view</Filter>
+    </ClInclude>
+    <ClInclude Include="NoBlock.h">
+      <Filter>world\blocks</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 2 - 3
FactoryCraft/Game.cpp

@@ -2,12 +2,11 @@
 #include "Initialisierung.h"
 #include "Globals.h"
 
-Game::Game( Bildschirm *zScreen )
+Game::Game( Bildschirm* zScreen )
     : Menu( zScreen )
 {
     logout = initKnopf( 10, 10, 200, 20, Knopf::Style::Normal, "Verlassen" );
-    logout->setMausEreignis( [this]( void *p, void *o, MausEreignis me )
-    {
+    logout->setMausEreignis( [this]( void* p, void* o, MausEreignis me ) {
         if( me.id == ME_RLinks )
         {
             logout->removeStyle( Knopf::Style::Erlaubt );

+ 2 - 2
FactoryCraft/Game.h

@@ -7,9 +7,9 @@
 class Game : public Menu
 {
 private:
-    Knopf *logout;
+    Knopf* logout;
 
 public:
     // Konstruktor
-    Game( Bildschirm *zScreen );
+    Game( Bildschirm* zScreen );
 };

+ 2 - 4
FactoryCraft/Globals.cpp

@@ -9,12 +9,10 @@
 void initVariables()
 {
     dlls = new DLLRegister();
-    menuRegister = new HashMap<Framework::Text, Framework::RCPointer<Menu>>( 10, []( Text txt )
-    {
+    menuRegister = new HashMap<Framework::Text, Framework::RCPointer<Menu>>( 10, []( Text txt ) {
         return txt.hashCode();
     } );
-    fontRegister = new HashMap<Framework::Text, Framework::RCPointer<Schrift>>( 10, []( Text txt )
-    {
+    fontRegister = new HashMap<Framework::Text, Framework::RCPointer<Schrift>>( 10, []( Text txt ) {
         return txt.hashCode();
     } );
     network = new NetworkHandler();

+ 5 - 5
FactoryCraft/Globals.h

@@ -14,12 +14,12 @@
 #define variable extern
 #endif
 
-variable Framework::HashMap<Framework::Text, Framework::RCPointer<Menu>> *menuRegister;
+variable Framework::HashMap<Framework::Text, Framework::RCPointer<Menu>>* menuRegister;
 variable UIInit uiFactory;
-variable Framework::HashMap<Framework::Text, Framework::RCPointer<Schrift>> *fontRegister;
-variable NetworkHandler *network;
-variable DLLRegister *dlls;
-variable World *currentGame;
+variable Framework::HashMap<Framework::Text, Framework::RCPointer<Schrift>>* fontRegister;
+variable NetworkHandler* network;
+variable DLLRegister* dlls;
+variable World* currentGame;
 
 
 void initVariables();

+ 25 - 25
FactoryCraft/Initialisierung.cpp

@@ -8,9 +8,9 @@
 #include <Liste.h>
 #include "Globals.h"
 
-Knopf *initKnopf( int x, int y, int br, int hö, __int64 style, char *titel )
+Knopf* initKnopf( int x, int y, int br, int hö, __int64 style, char* titel )
 {
-    Knopf *ret = uiFactory.createKnopf( uiFactory.initParam );
+    Knopf* ret = uiFactory.createKnopf( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -18,9 +18,9 @@ Knopf *initKnopf( int x, int y, int br, int h
     return ret;
 }
 
-KontrollKnopf *initKontrollKnopf( int x, int y, int br, int hö, __int64 style, char *txt )
+KontrollKnopf* initKontrollKnopf( int x, int y, int br, int hö, __int64 style, char* txt )
 {
-    KontrollKnopf *ret = uiFactory.createKontrollKnopf( uiFactory.initParam );
+    KontrollKnopf* ret = uiFactory.createKontrollKnopf( uiFactory.initParam );
     ret->addStyle( style );
     ret->setText( txt );
     ret->setSText( txt );
@@ -29,9 +29,9 @@ KontrollKnopf *initKontrollKnopf( int x, int y, int br, int h
     return ret;
 }
 
-Fenster *initFenster( int x, int y, int br, int hö, __int64 style, char *titel )
+Fenster* initFenster( int x, int y, int br, int hö, __int64 style, char* titel )
 {
-    Fenster *ret = uiFactory.createFenster( uiFactory.initParam );
+    Fenster* ret = uiFactory.createFenster( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -42,9 +42,9 @@ Fenster *initFenster( int x, int y, int br, int h
     return ret;
 }
 
-TextFeld *initTextFeld( int x, int y, int br, int hö, __int64 style, char *txt )
+TextFeld* initTextFeld( int x, int y, int br, int hö, __int64 style, char* txt )
 {
-    TextFeld *ret = uiFactory.createTextFeld( uiFactory.initParam );
+    TextFeld* ret = uiFactory.createTextFeld( uiFactory.initParam );
     ret->addStyle( style );
     ret->setText( txt );
     ret->setPosition( x, y );
@@ -52,9 +52,9 @@ TextFeld *initTextFeld( int x, int y, int br, int h
     return ret;
 }
 
-BildZ *initBildZ( int x, int y, int br, int hö, __int64 style, Bild *b )
+BildZ* initBildZ( int x, int y, int br, int hö, __int64 style, Bild* b )
 {
-    BildZ *ret = uiFactory.createBildZ( uiFactory.initParam );
+    BildZ* ret = uiFactory.createBildZ( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -63,9 +63,9 @@ BildZ *initBildZ( int x, int y, int br, int h
     return ret;
 }
 
-AuswahlBox *initAuswahlBox( int x, int y, int br, int hö, __int64 style, std::initializer_list< char * > values )
+AuswahlBox* initAuswahlBox( int x, int y, int br, int hö, __int64 style, std::initializer_list< char* > values )
 {
-    AuswahlBox *ret = uiFactory.createAuswahlBox( uiFactory.initParam );
+    AuswahlBox* ret = uiFactory.createAuswahlBox( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -74,9 +74,9 @@ AuswahlBox *initAuswahlBox( int x, int y, int br, int h
     return ret;
 }
 
-ObjTabelle *initObjTabelle( int x, int y, int br, int hö, __int64 style, std::initializer_list< OBJTabelleSpalteIni > spalten, int überschriftHöhe )
+ObjTabelle* initObjTabelle( int x, int y, int br, int hö, __int64 style, std::initializer_list< OBJTabelleSpalteIni > spalten, int überschriftHöhe )
 {
-    ObjTabelle *ret = uiFactory.createObjTabelle( uiFactory.initParam );
+    ObjTabelle* ret = uiFactory.createObjTabelle( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -84,9 +84,9 @@ ObjTabelle *initObjTabelle( int x, int y, int br, int h
     {
         ret->addSpalte( i->name );
         ret->setSpaltenBreite( i->name, i->breite );
-        if( ( style | ObjTabelle::Style::SpaltenBreiteMin ) == style )
+        if( (style | ObjTabelle::Style::SpaltenBreiteMin) == style )
             ret->setMinSpaltenBreite( i->name, i->minBreite );
-        if( ( style | ObjTabelle::Style::SpaltenBreiteMax ) == style )
+        if( (style | ObjTabelle::Style::SpaltenBreiteMax) == style )
             ret->setMaxSpaltenBreite( i->name, i->maxBreite );
         if( überschriftHöhe )
         {
@@ -101,9 +101,9 @@ ObjTabelle *initObjTabelle( int x, int y, int br, int h
     return ret;
 }
 
-LDiag *initLinienDiagramm( int x, int y, int br, int hö, __int64 style, DiagDaten *data )
+LDiag* initLinienDiagramm( int x, int y, int br, int hö, __int64 style, DiagDaten* data )
 {
-    LDiag *ret = uiFactory.createLDiag( uiFactory.initParam );
+    LDiag* ret = uiFactory.createLDiag( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
@@ -112,18 +112,18 @@ LDiag *initLinienDiagramm( int x, int y, int br, int h
     return ret;
 }
 
-FBalken *initFBalken( int x, int y, int br, int hö, __int64 style )
+FBalken* initFBalken( int x, int y, int br, int hö, __int64 style )
 {
-    FBalken *ret = uiFactory.createFBalken( uiFactory.initParam );
+    FBalken* ret = uiFactory.createFBalken( uiFactory.initParam );
     ret->addStyle( style );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
     return ret;
 }
 
-AuswahlListe *initAuswahlListe( int x, int y, int br, int hö, __int64 style, std::initializer_list< char * > values )
+AuswahlListe* initAuswahlListe( int x, int y, int br, int hö, __int64 style, std::initializer_list< char* > values )
 {
-    AuswahlListe *ret = uiFactory.createAuswahlListe( uiFactory.initParam );
+    AuswahlListe* ret = uiFactory.createAuswahlListe( uiFactory.initParam );
     ret->setPosition( x, y );
     ret->setSize( br, hö );
     ret->addStyle( style );
@@ -133,9 +133,9 @@ AuswahlListe *initAuswahlListe( int x, int y, int br, int h
     return ret;
 }
 
-ZeichnungHintergrund *initZeichnungHintergrund( int x, int y, int br, int hö, __int64 style, int farbe )
+ZeichnungHintergrund* initZeichnungHintergrund( int x, int y, int br, int hö, __int64 style, int farbe )
 {
-    ZeichnungHintergrund *ret = new ZeichnungHintergrund();
+    ZeichnungHintergrund* ret = new ZeichnungHintergrund();
     ret->setStyle( style );
     ret->setHintergrundFarbe( farbe );
     if( ret->hatStyle( ZeichnungHintergrund::Style::Rahmen ) )
@@ -148,7 +148,7 @@ ZeichnungHintergrund *initZeichnungHintergrund( int x, int y, int br, int h
     return ret;
 }
 
-void initToolTip( Zeichnung *obj, const char *txt )
+void initToolTip( Zeichnung* obj, const char* txt )
 {
     obj->setToolTipText( txt, uiFactory.initParam.bildschirm, uiFactory.initParam.schrift );
     obj->zToolTip()->addStyle( TextFeld::Style::Mehrzeilig );

+ 7 - 7
FactoryCraft/Initialisierung.h

@@ -12,17 +12,17 @@ using namespace Framework;
 
 struct OBJTabelleSpalteIni
 {
-    char *name;
+    char* name;
     int breite;
     int minBreite;
     int maxBreite;
 };
 
-Knopf *initKnopf( int x, int y, int br, int hö, __int64 style, char *titel );
-KontrollKnopf *initKontrollKnopf( int x, int y, int br, int hö, __int64 style, char *txt );
-TextFeld *initTextFeld( int x, int y, int br, int hö, __int64 style, char *txt );
-AuswahlBox *initAuswahlBox( int x, int y, int br, int hö, __int64 style, std::initializer_list< char * > values );
-ObjTabelle *initObjTabelle( int x, int y, int br, int hö, __int64 style, std::initializer_list< OBJTabelleSpalteIni > spalten, int überschriftHöhe );
-LDiag *initLinienDiagramm( int x, int y, int br, int hö, __int64 style, DiagDaten *data );
+Knopf* initKnopf( int x, int y, int br, int hö, __int64 style, char* titel );
+KontrollKnopf* initKontrollKnopf( int x, int y, int br, int hö, __int64 style, char* txt );
+TextFeld* initTextFeld( int x, int y, int br, int hö, __int64 style, char* txt );
+AuswahlBox* initAuswahlBox( int x, int y, int br, int hö, __int64 style, std::initializer_list< char* > values );
+ObjTabelle* initObjTabelle( int x, int y, int br, int hö, __int64 style, std::initializer_list< OBJTabelleSpalteIni > spalten, int überschriftHöhe );
+LDiag* initLinienDiagramm( int x, int y, int br, int hö, __int64 style, DiagDaten* data );
 
 #endif

+ 3 - 3
FactoryCraft/Inventory.h

@@ -13,12 +13,12 @@ class Inventory;
 class Inventory : public virtual Framework::ReferenceCounter
 {
 private:
-    Framework::RCArray<ItemSlot> *pullSlotsOrder;
-    Framework::RCArray<ItemSlot> *pushSlotsOrder;
+    Framework::RCArray<ItemSlot>* pullSlotsOrder;
+    Framework::RCArray<ItemSlot>* pushSlotsOrder;
 
 protected:
     Framework::Vec3<float> location;
-    virtual void loadInventory( Framework::StreamReader *zReader );
+    virtual void loadInventory( Framework::StreamReader* zReader );
 
 public:
     Inventory( const Framework::Vec3<float> location, bool hasInventory );

+ 8 - 6
FactoryCraft/Inventoty.cpp

@@ -1,6 +1,8 @@
 #include "Inventory.h"
 #include "Area.h"
 
+#include "Registries.h"
+
 using namespace Framework;
 
 
@@ -28,20 +30,20 @@ Inventory::~Inventory()
         pushSlotsOrder->release();
 }
 
-void Inventory::loadInventory( Framework::StreamReader *zReader )
+void Inventory::loadInventory( Framework::StreamReader* zReader )
 {
     if( pushSlotsOrder )
     {
-        for( auto iterator = pushSlotsOrder->getIterator(); iterator; iterator++ )
+        for( auto slot : *pushSlotsOrder )
         {
             int size = 0;
-            zReader->lese( (char *)&size, 4 );
+            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->setItems( new ItemStack( item, size ) );
+                zReader->lese( (char*)&id, 4 );
+                Item* item = STATIC_REGISTRY( ItemType ).zElement( id )->loadItem( zReader );
+                slot->setItems( new ItemStack( item, size ) );
             }
         }
     }

+ 2 - 2
FactoryCraft/Item.cpp

@@ -1,7 +1,7 @@
 #include "Item.h"
 
 
-Item::Item( const ItemType *zType, const char *name )
+Item::Item( const ItemType* zType, const char* name )
     : ReferenceCounter(),
     zType( zType ),
     damage( 0 ),
@@ -17,7 +17,7 @@ Item::Item( const ItemType *zType, const char *name )
     name( name )
 {}
 
-const ItemType *Item::zItemType() const
+const ItemType* Item::zItemType() const
 {
     return zType;
 }

+ 3 - 3
FactoryCraft/Item.h

@@ -8,7 +8,7 @@ class ItemType;
 class Item : public virtual Framework::ReferenceCounter
 {
 protected:
-    const ItemType *zType;
+    const ItemType* zType;
     float damage;
     float maxDamage;
     float durability;
@@ -20,11 +20,11 @@ protected:
     bool usable;
     int maxStackSize;
     Framework::Text name;
-    Item( const ItemType *zType, const char *name );
+    Item( const ItemType* zType, const char* name );
 
 public:
 
-    const ItemType *zItemType() const;
+    const ItemType* zItemType() const;
     float getDamage() const;
     float getDurability() const;
     bool isUsable() const;

+ 1 - 1
FactoryCraft/ItemSlot.cpp

@@ -18,7 +18,7 @@ ItemSlot::~ItemSlot()
         items->release();
 }
 
-void ItemSlot::setItems( ItemStack *item )
+void ItemSlot::setItems( ItemStack* item )
 {
     this->items = items;
 }

+ 2 - 2
FactoryCraft/ItemSlot.h

@@ -6,7 +6,7 @@
 class ItemSlot : public virtual Framework::ReferenceCounter
 {
 private:
-    ItemStack *items;
+    ItemStack* items;
     int maxSize;
     Directions allowedPullSide;
     Directions allowedPushSides;
@@ -18,5 +18,5 @@ public:
     ItemSlot( int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize );
     ~ItemSlot();
 
-    void setItems( ItemStack *item );
+    void setItems( ItemStack* item );
 };

+ 2 - 2
FactoryCraft/ItemStack.cpp

@@ -2,14 +2,14 @@
 #include "Item.h"
 
 
-ItemStack::ItemStack( Item *item, int currentSize, int maxSize )
+ItemStack::ItemStack( Item* item, int currentSize, int maxSize )
     : ReferenceCounter(),
     item( item ),
     size( currentSize ),
     maxSize( maxSize )
 {}
 
-ItemStack::ItemStack( Item *item, int currentSize )
+ItemStack::ItemStack( Item* item, int currentSize )
     : ItemStack( item, currentSize, item->getMaxStackSize() )
 {}
 

+ 3 - 3
FactoryCraft/ItemStack.h

@@ -5,13 +5,13 @@
 class ItemStack : public virtual Framework::ReferenceCounter
 {
 private:
-    Item *item;
+    Item* item;
     int size;
     int maxSize;
 
 public:
-    ItemStack( Item *item, int currentSize, int maxSize );
-    ItemStack( Item *item, int currentSize );
+    ItemStack( Item* item, int currentSize, int maxSize );
+    ItemStack( Item* item, int currentSize );
     ~ItemStack();
 
     int getSize() const;

+ 19 - 18
FactoryCraft/ItemType.cpp

@@ -3,33 +3,34 @@
 
 #include "ItemType.h"
 #include "ItemStack.h"
+#include "Registries.h"
 
 ItemType::ItemType( int id )
     : ReferenceCounter(),
     id( id )
 {
-    StaticRegistry<ItemType>::INSTANCE.registerT( this, id );
+    STATIC_REGISTRY( ItemType ).registerT( this, id );
 }
 
 ItemType::~ItemType()
 {}
 
-void ItemType::loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const
+void ItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
 {
-    zReader->lese( (char *)&zItem->damage, 4 );
-    zReader->lese( (char *)&zItem->maxDamage, 4 );
-    zReader->lese( (char *)&zItem->durability, 4 );
-    zReader->lese( (char *)&zItem->maxDurability, 4 );
+    zReader->lese( (char*)&zItem->damage, 4 );
+    zReader->lese( (char*)&zItem->maxDamage, 4 );
+    zReader->lese( (char*)&zItem->durability, 4 );
+    zReader->lese( (char*)&zItem->maxDurability, 4 );
     unsigned char flags = 0;
-    zReader->lese( (char *)&flags, 1 );
-    zItem->eatable = ( flags | 1 ) == flags;
-    zItem->placeable = ( flags | 2 ) == flags;
-    zItem->equippable = ( flags | 4 ) == flags;
-    zItem->solid = ( flags | 8 ) == flags;
-    zItem->usable = ( flags | 16 ) == flags;
-    zReader->lese( (char *)&zItem->maxStackSize, 1 );
+    zReader->lese( (char*)&flags, 1 );
+    zItem->eatable = (flags | 1) == flags;
+    zItem->placeable = (flags | 2) == flags;
+    zItem->equippable = (flags | 4) == flags;
+    zItem->solid = (flags | 8) == flags;
+    zItem->usable = (flags | 16) == flags;
+    zReader->lese( (char*)&zItem->maxStackSize, 1 );
     unsigned char len = 0;
-    zReader->lese( (char *)&len, 1 );
+    zReader->lese( (char*)&len, 1 );
     zItem->name.fillText( ' ', len );
     zReader->lese( zItem->name, len );
 }
@@ -39,17 +40,17 @@ int ItemType::getId() const
     return id;
 }
 
-ItemStack *ItemType::createItemStack( int size ) const
+ItemStack* ItemType::createItemStack( int size ) const
 {
-    Item *item = createItem();
+    Item* item = createItem();
     if( !item )
         return 0;
     return new ItemStack( item, MIN( size, item->getMaxStackSize() ) );
 }
 
-Item *ItemType::loadItem( Framework::StreamReader *zReader ) const
+Item* ItemType::loadItem( Framework::StreamReader* zReader ) const
 {
-    Item *item = createItem();
+    Item* item = createItem();
     loadSuperItem( item, zReader );
     return item;
 }

+ 4 - 6
FactoryCraft/ItemType.h

@@ -5,8 +5,6 @@
 #include <Trie.h>
 #include <Writer.h>
 
-#include "StaticRegistry.h"
-
 class Item;
 class ItemStack;
 class ItemSkill;
@@ -19,13 +17,13 @@ protected:
 
     ItemType( int id );
 
-    virtual void loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const;
+    virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const;
 
 public:
     ~ItemType();
 
     int getId() const;
-    virtual Item *createItem() const = 0;
-    virtual ItemStack *createItemStack( int size ) const;
-    virtual Item *loadItem( Framework::StreamReader *zReader ) const;
+    virtual Item* createItem() const = 0;
+    virtual ItemStack* createItemStack( int size ) const;
+    virtual Item* loadItem( Framework::StreamReader* zReader ) const;
 };

+ 5 - 6
FactoryCraft/Login.cpp

@@ -2,19 +2,18 @@
 #include "Initialisierung.h"
 #include "Globals.h"
 
-LoginMenu::LoginMenu( Bildschirm *zScreen )
+LoginMenu::LoginMenu( Bildschirm* zScreen )
     : Menu( zScreen )
 {
     elements.add( initTextFeld( 10, 10, 90, 20, TextFeld::Style::Text, "Name: " ) );
     elements.add( initTextFeld( 10, 35, 90, 20, TextFeld::Style::Text, "Passwort: " ) );
-    name = initTextFeld( 100, 10, 200, 20, TextFeld::Style::TextFeld, "" );
-    password = initTextFeld( 100, 35, 200, 20, TextFeld::Style::TextFeld, "" );
+    name = initTextFeld( 100, 10, 200, 20, TextFeld::Style::TextFeld, "Kolja" );
+    password = initTextFeld( 100, 35, 200, 20, TextFeld::Style::TextFeld, "1rg3ndw13" );
     password->setSchowChar( '*' );
     elements.add( name );
     elements.add( password );
-    Knopf *login = initKnopf( 200, 60, 100, 20, Knopf::Style::Normal, "Login" );
-    login->setMausEreignis( [this, login]( void *p, void *o, MausEreignis me )
-    {
+    Knopf* login = initKnopf( 200, 60, 100, 20, Knopf::Style::Normal, "Login" );
+    login->setMausEreignis( [this, login]( void* p, void* o, MausEreignis me ) {
         if( me.id == ME_RLinks )
         {
             login->removeStyle( Knopf::Style::Erlaubt );

+ 3 - 3
FactoryCraft/Login.h

@@ -7,9 +7,9 @@
 class LoginMenu : public Menu
 {
 private:
-    TextFeld *name;
-    TextFeld *password;
+    TextFeld* name;
+    TextFeld* password;
 
 public:
-    LoginMenu( Bildschirm *zScreen );
+    LoginMenu( Bildschirm* zScreen );
 };

+ 8 - 9
FactoryCraft/Main.cpp

@@ -20,12 +20,12 @@ int KSGStart Framework::Start( Framework::Startparam p )
     Datei d;
     d.setDatei( "data/schriften" );
     auto list = d.getDateiListe();
-    for( auto fontFile = list->getIterator(); fontFile; fontFile++ )
+    for( Text* fontFile : *list )
     {
         LTDSDatei dat;
         dat.setPfad( new Text( Text( "data/schriften/" ).operator+( fontFile->getText() ) ) );
         dat.leseDaten();
-        Text *name = fontFile->getTeilText( 0, fontFile->getLength() - 5 );
+        Text* name = fontFile->getTeilText( 0, fontFile->getLength() - 5 );
         fontRegister->put( *name, RCPointer<Schrift>::of( dat.ladeSchrift() ) );
         name->release();
     }
@@ -35,25 +35,24 @@ int KSGStart Framework::Start( Framework::Startparam p )
     WNDCLASS wc = Framework::F_Normal( p.hinst );
     wc.lpszClassName = "Factory Craft";
     window.erstellen( WS_POPUPWINDOW, wc );
-    Monitor m = Framework::getMonitor( 0 );
+    Monitor m = Framework::getMonitor( 2 );
     window.setBounds( Punkt( m.x, m.y ), Punkt( m.breite, m.height ) );
     window.setAnzeigeModus( SW_SHOWNORMAL );
-    window.setVSchließAktion( [&window]( void *p, void *f )
-    {
+    window.setVSchließAktion( [&window]( void* p, void* f ) {
         StopNachrichtenSchleife( window.getFensterHandle() );
     } );
     window.setMausAktion( _ret1ME );
     window.setTastaturAktion( _ret1TE );
-    Bildschirm3D screen( dynamic_cast<WFenster *>( window.getThis() ), GraphicApiType::DIRECTX12 );
-    window.setBildschirm( dynamic_cast<Bildschirm *>( screen.getThis() ) );
+    Bildschirm3D screen( dynamic_cast<WFenster*>(window.getThis()), GraphicApiType::DIRECTX11 );
+    window.setBildschirm( dynamic_cast<Bildschirm*>(screen.getThis()) );
+    screen.setFillFarbe( 0 );
     screen.update();
-    screen.setdeckFarbe( 0 );
 
     uiFactory = Framework::defaultUI( fontRegister->get( "normal" ), &screen );
     initMenus();
 
     RenderTh rTh;
-    rTh.setBildschirm( dynamic_cast<Bildschirm *>( screen.getThis() ) );
+    rTh.setBildschirm( dynamic_cast<Bildschirm*>(screen.getThis()) );
 
     rTh.beginn();
     StartNachrichtenSchleife();

+ 5 - 7
FactoryCraft/Menu.cpp

@@ -1,23 +1,21 @@
 #include "Menu.h"
 #include <AsynchronCall.h>
 
-Menu::Menu( Bildschirm *zScreen )
+Menu::Menu( Bildschirm* zScreen )
     : ReferenceCounter(),
     zScreen( zScreen )
 {}
 
 void Menu::show()
 {
-    for( auto i = elements.getIterator(); i; i++ )
-    {
-        zScreen->addMember( dynamic_cast<Zeichnung *>(i->getThis()) );
-    }
+    for( auto member : elements )
+        zScreen->addMember( dynamic_cast<Zeichnung*>(member->getThis()) );
 }
 
 void Menu::hide()
 {
     new AsynchronCall( [this]() {
-        for( auto i = elements.getIterator(); i; i++ )
-            zScreen->removeMember( dynamic_cast<Zeichnung *>(i->getThis()) );
+        for( auto member : elements )
+            zScreen->removeMember( dynamic_cast<Zeichnung*>(member->getThis()) );
     } );
 }

+ 2 - 2
FactoryCraft/Menu.h

@@ -9,10 +9,10 @@ class Menu : public ReferenceCounter
 {
 protected:
     RCArray<Zeichnung> elements;
-    Bildschirm *zScreen;
+    Bildschirm* zScreen;
 
 public:
-    Menu( Bildschirm *zScreen );
+    Menu( Bildschirm* zScreen );
 
     void show();
     void hide();

+ 7 - 5
FactoryCraft/NetworkHandler.cpp

@@ -15,14 +15,14 @@ NetworkHandler::NetworkHandler()
     msc = getMainClient();
     if( !msc )
         throw "Could not create Main Server Client from DLL 'data/bin/KSGNetwork.dll'";
-    InitDatei *iDat = new InitDatei( "data/optionen.ini" );
+    InitDatei* iDat = new InitDatei( "data/optionen.ini" );
     iDat->laden();
     if( !iDat->zWert( "ServerIP" ) )
         iDat->addWert( "ServerIP", "127.0.0.1" );
     if( !iDat->zWert( "ServerPort" ) )
         iDat->addWert( "ServerPort", "4225" );
     iDat->speichern();
-    Text *ipT = iDat->zWert( "ServerIP" );
+    Text* ipT = iDat->zWert( "ServerIP" );
     unsigned short port = (unsigned short)TextZuInt( iDat->zWert( "ServerPort" )->getText(), 10 );
     esc = 0;
     if( msc->registerSSL( ipT->getText(), port ) )
@@ -77,6 +77,8 @@ bool NetworkHandler::login( Framework::Text name, Framework::Text password )
         }
         lsc->logout();
     }
+    if( !lsc )
+        return 0;
     lsc->verbinde();
     bool ok = lsc->login( name, password );
     lsc->trenne( ok );
@@ -93,9 +95,9 @@ bool NetworkHandler::connect( Text ip, short port )
 {
     if( !gsc )
         gsc = msc->createMinigameServerClient();
-    if (!gsc)
+    if( !gsc )
         return 0;
-    Text *secret = gsc->getSecret();
+    Text* secret = gsc->getSecret();
     if( !secret )
         return 0;
     if( !fc )
@@ -105,7 +107,7 @@ bool NetworkHandler::connect( Text ip, short port )
     return ok;
 }
 
-FactoryClient *NetworkHandler::zFactoryClient() const
+FactoryClient* NetworkHandler::zFactoryClient() const
 {
     return fc;
 }

+ 6 - 6
FactoryCraft/NetworkHandler.h

@@ -7,11 +7,11 @@
 class NetworkHandler : public virtual Framework::ReferenceCounter
 {
 private:
-    KSGClient::MainServerClient *msc;
-    KSGClient::LoginServerClient *lsc;
-    KSGClient::MinigameServerClient *gsc;
-    KSGClient::ErhaltungServerClient *esc;
-    FactoryClient *fc;
+    KSGClient::MainServerClient* msc;
+    KSGClient::LoginServerClient* lsc;
+    KSGClient::MinigameServerClient* gsc;
+    KSGClient::ErhaltungServerClient* esc;
+    FactoryClient* fc;
     int accountId;
 
 public:
@@ -20,6 +20,6 @@ public:
 
     bool login( Framework::Text name, Framework::Text password );
     bool connect( Text ip, short port );
-    FactoryClient *zFactoryClient() const;
+    FactoryClient* zFactoryClient() const;
     bool leaveGame();
 };

+ 68 - 0
FactoryCraft/NoBlock.cpp

@@ -0,0 +1,68 @@
+#include "NoBlock.h"
+
+NoBlock::NoBlock()
+    : Block( NoBlockBlockType::INSTANCE, 0, { 0,0,0 }, false )
+{
+    transparent = 1;
+    passable = 1;
+    hp = 0;
+    maxHP = 0;
+    hardness = 0;
+}
+
+const NoBlock NoBlock::INSTANCE;
+
+
+NoBlockBlockType::NoBlockBlockType()
+    : BlockType( ID )
+{}
+
+NoBlockBlockType::NoBlockBlockType( int id )
+    : BlockType( id )
+{}
+
+Block* NoBlockBlockType::createBlock( Framework::Vec3<int> position )
+{
+    return 0;
+}
+
+Block* NoBlockBlockType::loadBlock( Framework::Vec3<int> position, Framework::StreamReader* zReader )
+{
+    return 0;
+}
+
+void NoBlockBlockType::initializeSuperBlock( Block* zBlock )
+{}
+
+const Block* NoBlockBlockType::zDefault()
+{
+    return &NoBlock::INSTANCE;
+}
+
+bool NoBlockBlockType::needsInstance() const
+{
+    return 0;
+}
+
+
+AirBlock::AirBlock()
+    : Block( AirBlockBlockType::INSTANCE, 0, { 0,0,0 }, false )
+{
+    transparent = 1;
+    passable = 1;
+    hp = 0;
+    maxHP = 0;
+    hardness = 0;
+}
+
+const AirBlock AirBlock::INSTANCE;
+
+
+AirBlockBlockType::AirBlockBlockType()
+    : NoBlockBlockType( ID )
+{}
+
+const Block* AirBlockBlockType::zDefault()
+{
+    return &AirBlock::INSTANCE;
+}

+ 51 - 0
FactoryCraft/NoBlock.h

@@ -0,0 +1,51 @@
+#pragma once
+
+#include "BlockType.h"
+#include "Block.h"
+
+class NoBlockBlockType;
+
+class NoBlock : public Block
+{
+public:
+    static const NoBlock INSTANCE;
+
+protected:
+    NoBlock();
+
+    friend NoBlockBlockType;
+};
+
+class NoBlockBlockType : public BlockType
+{
+    REGISTRABLE( NoBlockBlockType )
+
+protected:
+    NoBlockBlockType();
+    NoBlockBlockType( int id );
+    virtual Block* createBlock( Framework::Vec3<int> position ) override;
+    virtual Block* loadBlock( Framework::Vec3<int> position, Framework::StreamReader* zReader ) override;
+    virtual void initializeSuperBlock( Block* zBlock ) override;
+    virtual const Block* zDefault() override;
+    virtual bool needsInstance() const override;
+};
+REGISTER( NoBlockBlockType, BlockType )
+
+class AirBlock : public Block
+{
+public:
+    static const AirBlock INSTANCE;
+
+protected:
+    AirBlock();
+};
+
+class AirBlockBlockType : public NoBlockBlockType
+{
+    REGISTRABLE( AirBlockBlockType )
+
+protected:
+    AirBlockBlockType();
+    virtual const Block* zDefault() override;
+};
+REGISTER( AirBlockBlockType, BlockType )

+ 133 - 0
FactoryCraft/PlayerKam.cpp

@@ -0,0 +1,133 @@
+#include "PlayerKam.h"
+#include "Globals.h"
+
+PlayerKam::PlayerKam( Framework::Bildschirm3D* zScreen )
+    : Kam3D()
+{
+    setBildschirmPosition( 0, 0 );
+    setBildschirmSize( zScreen->getBackBufferSize() );
+    setStyle( Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable );
+    setRotation( { 0, 0, 0 } );
+}
+
+void PlayerKam::setDirection( Framework::Vec2<float> direction )
+{
+    if( direction.getLengthSq() > 0 )
+    {
+        float rotZ = lowPrecisionASin( abs( direction.x ) / Vec3< float >( direction.x, direction.y, 0.f ).getLength() );
+        setRotation( { (float)PI / 2.f, getRotation().y, rotZ } );
+    }
+}
+
+void PlayerKam::doTastaturEreignis( Framework::TastaturEreignis& te )
+{
+    char action[ 2 ];
+    if( te.id == TE_Press )
+    {
+        action[ 0 ] = 1;
+        if( te.taste == 'w' || te.taste == 'W' )
+        {
+            action[ 1 ] = 0;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'a' || te.taste == 'A' )
+        {
+            action[ 1 ] = 1;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 's' || te.taste == 'S' )
+        {
+            action[ 1 ] = 2;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'd' || te.taste == 'D' )
+        {
+            action[ 1 ] = 3;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == T_Shift )
+        {
+            action[ 1 ] = 4;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'q' || te.taste == 'Q' )
+        {
+            action[ 1 ] = 5;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'e' || te.taste == 'E' )
+        {
+            action[ 1 ] = 6;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == T_Space )
+        {
+            action[ 1 ] = 7;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+    }
+    if( te.id == TE_Release )
+    {
+        action[ 0 ] = 0;
+        if( te.taste == 'w' || te.taste == 'W' )
+        {
+            action[ 1 ] = 0;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'a' || te.taste == 'A' )
+        {
+            action[ 1 ] = 1;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 's' || te.taste == 'S' )
+        {
+            action[ 1 ] = 2;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'd' || te.taste == 'D' )
+        {
+            action[ 1 ] = 3;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == T_Shift )
+        {
+            action[ 1 ] = 4;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'q' || te.taste == 'Q' )
+        {
+            action[ 1 ] = 5;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == 'e' || te.taste == 'E' )
+        {
+            action[ 1 ] = 6;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+        if( te.taste == T_Space )
+        {
+            action[ 1 ] = 7;
+            network->zFactoryClient()->sendPlayerAction( action, 2 );
+        }
+    }
+}
+
+void PlayerKam::doMausEreignis( Framework::MausEreignis& me )
+{
+
+}
+
+bool PlayerKam::tick( double time )
+{
+    __int64 style = 0;
+    if( hatStyle( Style::Movable ) )
+        style |= Style::Movable;
+    if( hatStyle( Style::Rotatable ) )
+        style |= Style::Rotatable;
+    if( hatStyle( Style::Zoomable ) )
+        style |= Style::Zoomable;
+    removeStyle( Style::Movable | Style::Rotatable | Style::Zoomable );
+    bool result = Kam3D::tick( time );
+    addStyle( style );
+    return result;
+}

+ 14 - 0
FactoryCraft/PlayerKam.h

@@ -0,0 +1,14 @@
+#pragma once
+#include <Kam3D.h>
+#include <TastaturEreignis.h>
+#include <Bildschirm.h>
+
+class PlayerKam : public Framework::Kam3D
+{
+public:
+    PlayerKam( Framework::Bildschirm3D* zScreen );
+    void setDirection( Framework::Vec2<float> direction );
+    void doTastaturEreignis( Framework::TastaturEreignis& te ) override;
+    void doMausEreignis( Framework::MausEreignis& me ) override;
+    bool tick( double time ) override;
+};

+ 16 - 0
FactoryCraft/Registries.h

@@ -0,0 +1,16 @@
+#pragma once
+
+#include "StaticRegistry.h"
+#include "WorldUpdate.h"
+#include "BlockType.h"
+#include "ItemType.h"
+
+#ifndef _REGISTRY
+#define _REGISTRY extern
+#endif
+
+#define STATIC_REGISTRY(Type) Type##Registry
+
+_REGISTRY StaticRegistry<WorldUpdateType> WorldUpdateTypeRegistry;
+_REGISTRY StaticRegistry<BlockType> BlockTypeRegistry;
+_REGISTRY StaticRegistry<ItemType> ItemTypeRegistry;

+ 4 - 4
FactoryCraft/StaticInitializerOrder.cpp

@@ -1,8 +1,7 @@
-#include "StaticRegistry.h"
-#include "BlockType.h"
-#include "ItemType.h"
+#define _REGISTRY
+
+#include "Registries.h"
 
-int count_DimensionGenerator = 0;
 int count_ItemType = 0;
 int count_BlockType = 0;
 int count_WorldUpdateType = 0;
@@ -13,6 +12,7 @@ int count_EntityType = 0;
 const int c::ID = count_##typ++;       \
 const c *c::INSTANCE = new c(); 
 
+#include "NoBlock.h" // must be first
 #include "BasicBlocks.h"
 //#include "OverworldDimension.h"
 #include "AddChunkUpdate.h"

+ 9 - 15
FactoryCraft/StaticRegistry.h

@@ -13,18 +13,16 @@ private:
 template<typename T>
 class StaticRegistry
 {
-public:
-    static StaticRegistry<T> INSTANCE;
-
 private:
-    T **registry;
+    T** registry;
     int count;
 
+public:
     StaticRegistry()
     {
         count = 100;
         registry = new T * [ count ];
-        memset( registry, 0, sizeof( T * ) * count );
+        memset( registry, 0, sizeof( T* ) * count );
     }
 
     ~StaticRegistry()
@@ -40,13 +38,13 @@ private:
         delete[]registry;
     }
 
-    void registerT( T *type, int id )
+    void registerT( T* type, int id )
     {
         if( id >= count )
         {
-            T **temp = new T * [ id + 1 ];
-            memcpy( temp, registry, sizeof( T * ) * count );
-            memset( temp + count, 0, sizeof( T * ) * ( id + 1 - count ) );
+            T** temp = new T * [ id + 1 ];
+            memcpy( temp, registry, sizeof( T* ) * count );
+            memset( temp + count, 0, sizeof( T* ) * (id + 1 - count) );
             delete[]registry;
             registry = temp;
             count = id + 1;
@@ -54,8 +52,7 @@ private:
         registry[ id ] = type;
     }
 
-public:
-    T *zElement( int id )
+    T* zElement( int id )
     {
         if( id < 0 || id >= count )
             return 0;
@@ -68,7 +65,4 @@ public:
     }
 
     friend T;
-};
-
-template <typename T>
-StaticRegistry<T> StaticRegistry<T>::INSTANCE;
+};

+ 30 - 25
FactoryCraft/World.cpp

@@ -1,21 +1,26 @@
 #include <Network.h>
 #include <Welt3D.h>
+#include <GraphicsApi.h>
+#include <iostream>
 #include "World.h"
 #include "Globals.h"
 #include "WorldUpdate.h"
 #include "Constants.h"
+#include "Registries.h"
+#include "BasicBlocks.h"
 
 using namespace Network;
 using namespace Framework;
 
-World::World( Bildschirm3D *zScreen )
+World::World( Bildschirm3D* zScreen )
     : Thread()
 {
     renderedWorld = new Welt3D();
+    renderedWorld->addDiffuseLight( DiffuseLight{ Vec3<float>( 0.5f, 0.5f, -1.f ), Vec3<float>( 1.f, 1.f, 1.f ) } );
     dimensions = new RCArray<Dimension>();
     currentPlayer = new CurrentPlayer();
     zScreenPtr = zScreen;
-    kam = new Kam3D();
+    kam = new PlayerKam( zScreen );
     kam->setWelt( renderedWorld );
     zScreen->addKamera( kam );
     start();
@@ -30,16 +35,16 @@ World::~World()
 
 void World::update()
 {
-    NetworkReader *serverMessageReader = 0;
-    const char type = 0;
+    NetworkReader* serverMessageReader = 0;
+    unsigned char type = 0;
     while( serverMessageReader = network->zFactoryClient()->getNextMessage() )
     {
-        serverMessageReader->lese( (char *)&type, 1 );
+        serverMessageReader->lese( (char*)&type, 1 );
         if( type == 2 ) // WORLD UPDATE
         {
             int id = 0;
-            serverMessageReader->lese( (char *)&id, 4 );
-            StaticRegistry<WorldUpdateType>::INSTANCE.zElement( id )->applyUpdate( serverMessageReader );
+            serverMessageReader->lese( (char*)&id, 4 );
+            STATIC_REGISTRY( WorldUpdateType ).zElement( id )->applyUpdate( serverMessageReader );
         }
         if( type == 3 ) // API MESSAGE
         {
@@ -48,22 +53,22 @@ void World::update()
         if( type == 4 ) // POSITION UPDATE
         {
             Vec3<float> pos, dir;
-            serverMessageReader->lese( (char *)&pos.x, 4 );
-            serverMessageReader->lese( (char *)&pos.y, 4 );
-            serverMessageReader->lese( (char *)&pos.z, 4 );
-            kam->setPosition( pos );
-            serverMessageReader->lese( (char *)&dir.x, 4 );
-            serverMessageReader->lese( (char *)&dir.y, 4 );
-            dir.z = 0;
-            if( dir.getLengthSq() > 0 )
-                kam->setAusrichtung( pos + dir * 10 );
+            serverMessageReader->lese( (char*)&pos.x, 4 );
+            serverMessageReader->lese( (char*)&pos.y, 4 );
+            serverMessageReader->lese( (char*)&pos.z, 4 );
+            std::cout << "position: " << pos.x << ", " << pos.y << ", " << pos.z << " face: ";
+            kam->setPosition( pos + Vec3<float>( 0.f, 0.f, 2.f ) );
+            serverMessageReader->lese( (char*)&dir.x, 4 );
+            serverMessageReader->lese( (char*)&dir.y, 4 );
+            std::cout << pos.x << ", " << pos.y << "\n";
+            kam->setDirection( { dir.x, dir.y } );
         }
     }
 }
 
-void World::setChunk( Chunk *chunk, int dimensionId )
+void World::setChunk( Chunk* chunk, int dimensionId )
 {
-    Dimension *zDim = zDimension( dimensionId );
+    Dimension* zDim = zDimension( dimensionId );
     if( !zDim )
     {
         zDim = new Dimension( dimensionId );
@@ -89,17 +94,17 @@ void World::thread()
     }
 }
 
-Block *World::zBlockAt( Framework::Vec3<int> location, int dimension ) const
+Framework::Either<Block*, int> World::zBlockAt( Framework::Vec3<int> location, int dimension ) const
 {
-    Dimension *dim = zDimension( dimension );
+    Dimension* dim = zDimension( dimension );
     if( dim )
         return dim->zBlock( location );
     return 0;
 }
 
-Dimension *World::zDimension( int id ) const
+Dimension* World::zDimension( int id ) const
 {
-    for( auto dim = dimensions->getIterator(); dim; dim++ )
+    for( auto dim : *dimensions )
     {
         if( dim->getDimensionId() == id )
             return dim;
@@ -107,15 +112,15 @@ Dimension *World::zDimension( int id ) const
     return 0;
 }
 
-void World::setVisibility( Framework::Model3D *zModel, bool visible )
+void World::setVisibility( Framework::Model3D* zModel, bool visible )
 {
     if( visible )
-        renderedWorld->addZeichnung( dynamic_cast<Framework::Model3D *>(zModel->getThis()) );
+        renderedWorld->addZeichnung( dynamic_cast<Framework::Model3D*>(zModel->getThis()) );
     else
         renderedWorld->removeZeichnung( zModel );
 }
 
-Framework::Bildschirm3D *World::zScreen() const
+Framework::Bildschirm3D* World::zScreen() const
 {
     return zScreenPtr;
 }

+ 12 - 11
FactoryCraft/World.h

@@ -7,26 +7,27 @@
 
 #include "Dimension.h"
 #include "CurrentPlayer.h"
+#include "PlayerKam.h"
 
 class World : public Framework::Thread
 {
 private:
-    Framework::RCArray<Dimension> *dimensions;
-    CurrentPlayer *currentPlayer;
-    Framework::Welt3D *renderedWorld;
-    Framework::Bildschirm3D *zScreenPtr;
-    Framework::Kam3D *kam;
+    Framework::RCArray<Dimension>* dimensions;
+    CurrentPlayer* currentPlayer;
+    Framework::Welt3D* renderedWorld;
+    Framework::Bildschirm3D* zScreenPtr;
+    PlayerKam* kam;
 
 public:
-    World( Framework::Bildschirm3D *zScreen );
+    World( Framework::Bildschirm3D* zScreen );
     ~World();
     void update();
-    void setChunk( Chunk *chunk, int dimensionId );
+    void setChunk( Chunk* chunk, int dimensionId );
     void thread() override;
 
-    Block *zBlockAt( Framework::Vec3<int> location, int dimension ) const;
-    Dimension *zDimension( int id ) const;
-    void setVisibility( Framework::Model3D *zModel, bool visible );
-    Framework::Bildschirm3D *zScreen() const;
+    Framework::Either<Block*, int> zBlockAt( Framework::Vec3<int> location, int dimension ) const;
+    Dimension* zDimension( int id ) const;
+    void setVisibility( Framework::Model3D* zModel, bool visible );
+    Framework::Bildschirm3D* zScreen() const;
     Framework::Punkt getChunkCenter( int x, int y ) const;
 };

+ 3 - 1
FactoryCraft/WorldUpdate.cpp

@@ -1,7 +1,9 @@
 #include "WorldUpdate.h"
 
+#include "Registries.h"
+
 WorldUpdateType::WorldUpdateType( int id )
     : ReferenceCounter()
 {
-    StaticRegistry<WorldUpdateType>::INSTANCE.registerT( this, id );
+    STATIC_REGISTRY( WorldUpdateType ).registerT( this, id );
 }

+ 1 - 1
FactoryCraft/WorldUpdate.h

@@ -11,5 +11,5 @@ protected:
     WorldUpdateType( int id );
 
 public:
-    virtual void applyUpdate( Framework::StreamReader *zReader ) = 0;
+    virtual void applyUpdate( Framework::StreamReader* zReader ) = 0;
 };

+ 2 - 0
FactoryCraft/data_release/optionen.ini

@@ -0,0 +1,2 @@
+ServerIP=78.47.96.161
+ServerPort=5225

BIN
FactoryCraft/data_release/schriften/ksgs.ltds


BIN
FactoryCraft/data_release/schriften/normal.ltds


BIN
FactoryCraft/error_core_memory_dump.dmp