Kaynağa Gözat

add uiml based gui system

Kolja Strohm 2 yıl önce
ebeveyn
işleme
78fd0fd567

+ 2 - 1
FactoryCraft/Area.h

@@ -19,7 +19,8 @@ enum Direction
     SOUTH = 4,
     WEST = 8,
     TOP = 16,
-    BOTTOM = 32
+    BOTTOM = 32,
+    INSIDE = 64
 };
 typedef int Directions;
 

+ 62 - 57
FactoryCraft/Block.cpp

@@ -3,102 +3,107 @@
 #include "Globals.h"
 
 
-Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
-    : Inventory( pos, hasInventory ),
-    Model3D(),
-    zType( zType )
+Block::Block(const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory)
+	: Inventory(pos, hasInventory),
+	Model3D(),
+	zType(zType)
 {
-    transparent = false;
-    passable = false;
-    hp = 1;
-    maxHP = 1;
-    hardness = 1;
-    this->zTool = zTool;
-    speedModifier = 1;
-    memset( sideVisible, 1, 6 );
-    Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
+	transparent = false;
+	passable = false;
+	hp = 1;
+	maxHP = 1;
+	hardness = 1;
+	this->zTool = zTool;
+	speedModifier = 1;
+	memset(sideVisible, 1, 6);
+	Model3D::setPosition((Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f});
 }
 
 Block::~Block()
 {}
 
+void Block::api(char* message)
+{
+	// TODO: implement api
+}
+
 bool Block::isTransparent() const
 {
-    return transparent;
+	return transparent;
 }
 
 bool Block::isPassable() const
 {
-    return passable;
+	return passable;
 }
 
-void Block::setSideVisible( Direction dir, bool visible )
+void Block::setSideVisible(Direction dir, bool visible)
 {
-    sideVisible[ getDirectionIndex( dir ) ] = visible;
+	sideVisible[getDirectionIndex(dir)] = visible;
 }
 
 const BlockType* Block::zBlockType() const
 {
-    return zType;
+	return zType;
 }
 
 
-BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
-    : Item( zType, name )
+BasicBlockItem::BasicBlockItem(const ItemType* zType, const char* name)
+	: Item(zType, name)
 {
-    placeable = 1;
-    transparent = 0;
-    passable = 0;
-    hp = 0;
-    maxHP = 0;
-    hardness = 0;
-    toolId = 0;
-    speedModifier = 0;
-    interactable = 0;
+	placeable = 1;
+	transparent = 0;
+	passable = 0;
+	hp = 0;
+	maxHP = 0;
+	hardness = 0;
+	toolId = 0;
+	speedModifier = 0;
+	interactable = 0;
 }
 
 
-BasicBlockItemType::BasicBlockItemType( int id, const char* name, const char* texturPath )
-    : ItemType( id, name ),
-    name( name ),
-    texturPath( texturPath )
+BasicBlockItemType::BasicBlockItemType(int id, const char* name, const char* texturPath)
+	: ItemType(id, name),
+	name(name),
+	texturPath(texturPath)
 {}
 
-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);
-    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->interactable, 1 );
+	ItemType::loadSuperItem(zItem, zReader);
+	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->interactable, 1);
 }
 
 Framework::Model3DData* BasicBlockItemType::getItemModel() const
 {
-    return uiFactory.initParam.bildschirm->zGraphicsApi()->getModel( "itemCube" );
+	return uiFactory.initParam.bildschirm->zGraphicsApi()->getModel("itemCube");
 }
 
 Item* BasicBlockItemType::createItem() const
 {
-    return new BasicBlockItem( this, name );
+	return new BasicBlockItem(this, name);
 }
 
 Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
 {
-    Model3DTextur* textur = new Model3DTextur();
-    Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur( texturPath, 0 );
-    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 );
-    return textur;
+	Model3DTextur* textur = new Model3DTextur();
+	Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur(texturPath, 0);
+	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);
+	return textur;
 }

+ 36 - 35
FactoryCraft/Block.h

@@ -16,60 +16,61 @@ class Chunk;
 class Block : public Model3D, public Inventory
 {
 protected:
-    bool transparent;
-    bool passable;
-    float hp;
-    float maxHP;
-    float hardness;
-    float speedModifier;
-    const BlockType* zType;
-    ItemType* zTool;
-    bool sideVisible[ 6 ];
+	bool transparent;
+	bool passable;
+	float hp;
+	float maxHP;
+	float hardness;
+	float speedModifier;
+	const BlockType* zType;
+	ItemType* zTool;
+	bool sideVisible[6];
 
 public:
-    Block( const BlockType* zType, ItemType* zTool, Vec3<int> position, bool hasInventory );
-    virtual ~Block();
+	Block(const BlockType* zType, ItemType* zTool, Vec3<int> position, bool hasInventory);
+	virtual ~Block();
 
-    bool isTransparent() const;
-    bool isPassable() const;
-    void setSideVisible( Direction dir, bool visible );
+	void api(char* message);
+	bool isTransparent() const;
+	bool isPassable() const;
+	void setSideVisible(Direction dir, bool visible);
 
-    const BlockType* zBlockType() const;
-    friend Chunk;
-    friend BlockType;
+	const BlockType* zBlockType() const;
+	friend Chunk;
+	friend BlockType;
 };
 
 class BasicBlockItem : public Item
 {
 protected:
-    bool transparent;
-    bool passable;
-    float hp;
-    float maxHP;
-    float hardness;
-    int toolId;
-    float speedModifier;
-    bool interactable;
+	bool transparent;
+	bool passable;
+	float hp;
+	float maxHP;
+	float hardness;
+	int toolId;
+	float speedModifier;
+	bool interactable;
 
 public:
-    BasicBlockItem( const ItemType* zType, const char* name );
+	BasicBlockItem(const ItemType* zType, const char* name);
 
-    friend BasicBlockItemType;
-    friend BlockType;
+	friend BasicBlockItemType;
+	friend BlockType;
 };
 
 class BasicBlockItemType : public ItemType
 {
 private:
-    const char* name;
-    const char* texturPath;
+	const char* name;
+	const char* texturPath;
 
 protected:
-    BasicBlockItemType( int id, const char* name, const char* texturPath );
-    virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const override;
+	BasicBlockItemType(int id, const char* name, const char* texturPath);
+	virtual void loadSuperItem(Item* zItem, Framework::StreamReader* zReader) const override;
 
 public:
-    virtual Framework::Model3DData* getItemModel() const override;
-    virtual Framework::Model3DTextur* getItemTextur() const override;
-    virtual Item* createItem() const override;
+	virtual Framework::Model3DData* getItemModel() const override;
+	virtual Framework::Model3DTextur* getItemTextur() const override;
+	virtual Item* createItem() const override;
 };

+ 101 - 96
FactoryCraft/Chunk.cpp

@@ -5,141 +5,146 @@
 #include "Registries.h"
 
 
-Chunk::Chunk( Framework::Punkt location, int dimensionId )
-    : ReferenceCounter(),
-    dimensionId( dimensionId ),
-    location( location ),
-    isLoading( 0 )
+Chunk::Chunk(Framework::Punkt location, int dimensionId)
+	: ReferenceCounter(),
+	dimensionId(dimensionId),
+	location(location),
+	isLoading(0)
 {}
 
-Chunk::Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader )
-    : Chunk( location, dimensionId )
+Chunk::Chunk(Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader)
+	: Chunk(location, dimensionId)
 {
-    load( zReader );
+	load(zReader);
 }
 
 Chunk::~Chunk()
 {}
 
-Block* Chunk::zBlockAt( Framework::Vec3<int> location )
+void Chunk::api(char* message)
 {
-    cs.lock();
-    for( Block* b : blocks )
-    {
-        if( Framework::Vec3<int>( (int)floor( b->getPos().x ), (int)floor( b->getPos().y ), (int)floor( b->getPos().z ) ) == location )
-        {
-            cs.unlock();
-            return b;
-        }
-    }
-    cs.unlock();
-    return 0;
+	// TODO: implement api
 }
 
-void Chunk::setBlock( Block* block )
+Block* Chunk::zBlockAt(Framework::Vec3<int> location)
 {
-    cs.lock();
-    Framework::Vec3<int> pos = (Framework::Vec3<int>)block->getPos();
-    for( Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++ )
-    {
-        if( pos == (Framework::Vec3<int>)iterator->getPos() )
-        {
-            iterator->release();
-            iterator.set( block );
-            cs.unlock();
-            return;
-        }
-    }
-    blocks.add( block );
-    cs.unlock();
-    if( !isLoading )
-        updateVisibility();
+	cs.lock();
+	for (Block* b : blocks)
+	{
+		if (Framework::Vec3<int>((int)floor(b->getPos().x), (int)floor(b->getPos().y), (int)floor(b->getPos().z)) == location)
+		{
+			cs.unlock();
+			return b;
+		}
+	}
+	cs.unlock();
+	return 0;
 }
 
-void Chunk::removeBlock( Block* zBlock )
+void Chunk::setBlock(Block* block)
 {
-    cs.lock();
-    int index = 0;
-    for( Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++, index++ )
-    {
-        if( zBlock == (Block*)iterator )
-        {
-            blocks.remove( index );
-            cs.unlock();
-            if( !isLoading )
-                updateVisibility();
-            return;
-        }
-    }
-    cs.unlock();
+	cs.lock();
+	Framework::Vec3<int> pos = (Framework::Vec3<int>)block->getPos();
+	for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++)
+	{
+		if (pos == (Framework::Vec3<int>)iterator->getPos())
+		{
+			iterator->release();
+			iterator.set(block);
+			cs.unlock();
+			return;
+		}
+	}
+	blocks.add(block);
+	cs.unlock();
+	if (!isLoading)
+		updateVisibility();
 }
 
-void Chunk::load( Framework::StreamReader* zReader )
+void Chunk::removeBlock(Block* zBlock)
 {
-    isLoading = 1;
-    Framework::Vec3<int> pos = { 0, 0, 0 };
-    unsigned short id;
-    zReader->lese( (char*)&id, 2 );
-    while( id )
-    {
-        zReader->lese( (char*)&pos.x, 4 );
-        zReader->lese( (char*)&pos.y, 4 );
-        zReader->lese( (char*)&pos.z, 4 );
-        bool d;
-        zReader->lese( (char*)&d, 1 );
-        if( d )
-        {
-            Block* block = STATIC_REGISTRY( BlockType ).zElement( id )->loadBlock( { pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z }, zReader );
-            if( block )
-                setBlock( block );
-        }
-        else if( STATIC_REGISTRY( BlockType ).zElement( id )->needsInstance() )
-            setBlock( STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( { pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z } ) );
-        zReader->lese( (char*)&id, 2 );
-    }
-    isLoading = 0;
-    updateVisibility();
+	cs.lock();
+	int index = 0;
+	for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++, index++)
+	{
+		if (zBlock == (Block*)iterator)
+		{
+			blocks.remove(index);
+			cs.unlock();
+			if (!isLoading)
+				updateVisibility();
+			return;
+		}
+	}
+	cs.unlock();
+}
+
+void Chunk::load(Framework::StreamReader* zReader)
+{
+	isLoading = 1;
+	Framework::Vec3<int> pos = { 0, 0, 0 };
+	unsigned short id;
+	zReader->lese((char*)&id, 2);
+	while (id)
+	{
+		zReader->lese((char*)&pos.x, 4);
+		zReader->lese((char*)&pos.y, 4);
+		zReader->lese((char*)&pos.z, 4);
+		bool d;
+		zReader->lese((char*)&d, 1);
+		if (d)
+		{
+			Block* block = STATIC_REGISTRY(BlockType).zElement(id)->loadBlock({ pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z }, zReader);
+			if (block)
+				setBlock(block);
+		}
+		else if (STATIC_REGISTRY(BlockType).zElement(id)->needsInstance())
+			setBlock(STATIC_REGISTRY(BlockType).zElement(id)->createBlock({ pos.x + location.x - CHUNK_SIZE / 2, pos.y + location.y - CHUNK_SIZE / 2, pos.z }));
+		zReader->lese((char*)&id, 2);
+	}
+	isLoading = 0;
+	updateVisibility();
 }
 
 int Chunk::getDimensionId() const
 {
-    return dimensionId;
+	return dimensionId;
 }
 
 Framework::Punkt Chunk::getCenter() const
 {
-    return location;
+	return location;
 }
 
 Framework::Vec3<int> Chunk::getMin() const
 {
-    return { location.x - CHUNK_SIZE / 2, location.y - CHUNK_SIZE / 2, 0 };
+	return { location.x - CHUNK_SIZE / 2, location.y - CHUNK_SIZE / 2, 0 };
 }
 
 Framework::Vec3<int> Chunk::getMax() const
 {
-    return { location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT };
+	return { location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT };
 }
 
-void Chunk::forAll( std::function<void( Model3D* )> f )
+void Chunk::forAll(std::function<void(Model3D*)> f)
 {
-    cs.lock();
-    for( Block* b : blocks )
-        f( b );
-    cs.unlock();
+	cs.lock();
+	for (Block* b : blocks)
+		f(b);
+	cs.unlock();
 }
 
 void Chunk::updateVisibility()
 {
-    cs.lock();
-    for( Block* b : blocks )
-    {
-        Framework::Vec3<int> pos = Framework::Vec3<int>( (int)floor( b->getPos().x ), (int)floor( b->getPos().y ), (int)floor( b->getPos().z ) );
-        for( int i = 0; i < 6; i++ )
-        {
-            Block* c = zBlockAt( pos + getDirection( getDirectionFromIndex( i ) ) );
-            b->setSideVisible( getDirectionFromIndex( i ), !c || c->isTransparent() || c->isPassable() );
-        }
-    }
-    cs.unlock();
+	cs.lock();
+	for (Block* b : blocks)
+	{
+		Framework::Vec3<int> pos = Framework::Vec3<int>((int)floor(b->getPos().x), (int)floor(b->getPos().y), (int)floor(b->getPos().z));
+		for (int i = 0; i < 6; i++)
+		{
+			Block* c = zBlockAt(pos + getDirection(getDirectionFromIndex(i)));
+			b->setSideVisible(getDirectionFromIndex(i), !c || c->isTransparent() || c->isPassable());
+		}
+	}
+	cs.unlock();
 }

+ 19 - 18
FactoryCraft/Chunk.h

@@ -13,24 +13,25 @@
 class Chunk : public Framework::Model3DCollection
 {
 private:
-    int dimensionId;
-    Framework::Punkt location;
-    Framework::RCArray<Block> blocks;
-    bool isLoading;
-    Framework::Critical cs;
+	int dimensionId;
+	Framework::Punkt location;
+	Framework::RCArray<Block> blocks;
+	bool isLoading;
+	Framework::Critical cs;
 
 public:
-    Chunk( Framework::Punkt location, int dimensionId );
-    Chunk( Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader );
-    ~Chunk();
-    Block* zBlockAt( Framework::Vec3<int> cLocation );
-    void setBlock( Block* block );
-    void removeBlock( Block* zBlock );
-    void load( Framework::StreamReader* zReader );
-    int getDimensionId() const;
-    Framework::Punkt getCenter() const;
-    Framework::Vec3<int> getMin() const;
-    Framework::Vec3<int> getMax() const;
-    void forAll( std::function<void( Model3D* )> f ) override;
-    void updateVisibility();
+	Chunk(Framework::Punkt location, int dimensionId);
+	Chunk(Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader);
+	~Chunk();
+	void api(char* message);
+	Block* zBlockAt(Framework::Vec3<int> cLocation);
+	void setBlock(Block* block);
+	void removeBlock(Block* zBlock);
+	void load(Framework::StreamReader* zReader);
+	int getDimensionId() const;
+	Framework::Punkt getCenter() const;
+	Framework::Vec3<int> getMin() const;
+	Framework::Vec3<int> getMax() const;
+	void forAll(std::function<void(Model3D*)> f) override;
+	void updateVisibility();
 };

+ 69 - 0
FactoryCraft/CraftingGrid.cpp

@@ -0,0 +1,69 @@
+#include <XML.h>
+
+#include "CraftingGrid.h"
+
+using namespace Framework;
+
+CraftingGridElement::CraftingGridElement()
+	: UIMLElement()
+{}
+
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+bool CraftingGridElement::isApplicableFor(Framework::XML::Element& element)
+{
+	return element.getName().istGleich("inventory");
+}
+
+//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+Framework::Zeichnung* CraftingGridElement::parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
+{
+	Text targetValue = element.getAttributeValue("target");
+	Vec3<int> blockPos(0, 0, 0);
+	Framework::Either<int, Vec3<int>> target((int)targetValue);
+	if (targetValue.hat(','))
+	{
+		Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
+		Text* second = targetValue.getTeilText(targetValue.positionVon(",", 0) + 1, targetValue.positionVon(",", 1));
+		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1);
+		target = Framework::Either<int, Vec3<int>>(Vec3<int>((int)*first, (int)*second, (int)*third));
+		first->release();
+		second->release();
+		third->release();
+	}
+	return new CraftingGridView((int)element.getAttributeValue("rowSize"), (int)element.getAttributeValue("colSize"), (int)element.getAttributeValue("numOutputSlots"), target);
+}
+
+//! wendet die layout parameter zu einer Zeichnung an
+void CraftingGridElement::layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter)
+{
+	UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
+}
+
+
+CraftingGridView::CraftingGridView(int rowSize, int colSize, int numOutputSlots, Either<int, Vec3<int>> target)
+	: ZeichnungHintergrund(),
+	rowSize(rowSize),
+	colSize(colSize),
+	numOutputSlots(numOutputSlots),
+	target(target)
+{}
+
+void CraftingGridView::api(char* message)
+{
+
+}
+
+bool CraftingGridView::tick(double tickVal)
+{
+	return ZeichnungHintergrund::tick(tickVal);
+}
+
+void CraftingGridView::render(Bild& rObj)
+{
+	ZeichnungHintergrund::render(rObj);
+}
+
+void CraftingGridView::doMausEreignis(MausEreignis& me, bool userRet)
+{
+	ZeichnungHintergrund::doMausEreignis(me, userRet);
+}

+ 35 - 0
FactoryCraft/CraftingGrid.h

@@ -0,0 +1,35 @@
+#pragma once
+
+#include "NetworkAPIProcessor.h"
+
+#include <UIMLView.h>
+#include <Either.h>
+
+class CraftingGridElement : public Framework::UIMLElement
+{
+public:
+	CraftingGridElement();
+	//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+	bool isApplicableFor(Framework::XML::Element& element) override;
+	//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+	Framework::Zeichnung* parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory) override;
+	//! wendet die layout parameter zu einer Zeichnung an
+	void layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter) override;
+};
+
+class CraftingGridView : public Framework::ZeichnungHintergrund, public NetworkAPIProcessor
+{
+private:
+	int rowSize;
+	int colSize;
+	int numOutputSlots;
+	// entity id or block position
+	Framework::Either<int, Framework::Vec3<int>> target;
+
+public:
+	CraftingGridView(int rowSize, int colSize, int numOutputSlots, Framework::Either<int, Framework::Vec3<int>> target);
+	void api(char* message) override;
+	bool tick(double tickVal) override;
+	void render(Framework::Bild& rObj) override;
+	void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+};

+ 0 - 10
FactoryCraft/CurrentPlayer.h

@@ -1,10 +0,0 @@
-#pragma once
-#include "Player.h"
-#include <Kam3D.h>
-
-class CurrentPlayer : public Framework::ReferenceCounter
-{
-private:
-    Player* player;
-    Framework::Kam3D* kam3D;
-};

+ 66 - 0
FactoryCraft/Dialog.cpp

@@ -0,0 +1,66 @@
+#include <XML.h>
+#include <TextFeld.h>
+#include <TastaturEreignis.h>
+
+#include "Dialog.h"
+#include "InventoryView.h"
+#include "Equipment.h"
+#include "CraftingGrid.h"
+#include "Globals.h"
+
+using namespace Framework;
+
+UIMLDialog::UIMLDialog(Framework::Text uiml, std::function<void(UIMLDialog* self)> onClose)
+	: Fenster()
+{
+	XML::Element* xml = new XML::Element(uiml);
+	view = new UIMLView("<v/>", uiFactory);
+	view->addKnownElement(new InventoryElement());
+	view->addKnownElement(new EquipmentElement());
+	view->addKnownElement(new CraftingGridElement());
+	view->setUIML(xml);
+	view->setSize(xml->getAttributeValue("width"), xml->getAttributeValue("height"));
+	name = xml->getAttributeValue("id");
+	view->layout();
+	addMember(view);
+
+	setStyle(Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::BodyHAlpha | Fenster::Style::Beweglich | Fenster::Style::Titel | Fenster::Style::TitelHAlpha | Fenster::Style::Closable | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund | Fenster::Style::ClosingHintergrund);
+	setKBgFarbe(0xA0000000);
+	setTBgFarbe(0xA0000000);
+	setSBgFarbe(0xA0000000);
+	setSize(view->getBreite() + 4, view->getHeight() + 24);
+	setPosition(window->zBildschirm()->getBackBufferSize() / 2 - getSize() / 2);
+	setRBreite(2);
+	setClosingMe([onClose, this](void* p, void* o, MausEreignis me)
+		{
+			if (me.id == ME_RLinks)
+				onClose(this);
+			return 1;
+		});
+	setRFarbe(0xFF52525E);
+	setTitel(xml->getAttributeValue("title"));
+	setTSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
+	zTTextFeld()->setSize(0, 20);
+	zTTextFeld()->addStyle(TextFeld::Style::Center);
+	setTastaturEreignis(_ret1TE);
+}
+
+UIMLDialog::~UIMLDialog()
+{}
+
+void UIMLDialog::api(char* message)
+{
+	short idLen = *(short*)message;
+	char* id = new char[idLen + 1];
+	memcpy(id, message + 2, idLen);
+	id[idLen] = 0;
+	NetworkAPIProcessor* processor = dynamic_cast<NetworkAPIProcessor*>(view->zZeichnungById(id));
+	if (processor)
+		processor->api(message + 2 + idLen);
+	delete[] id;
+}
+
+const Framework::Text& UIMLDialog::getName() const
+{
+	return name;
+}

+ 20 - 0
FactoryCraft/Dialog.h

@@ -0,0 +1,20 @@
+#pragma once
+
+#include "NetworkAPIProcessor.h"
+
+#include <Fenster.h>
+#include <UIMLView.h>
+
+class UIMLDialog : public Framework::Fenster, public NetworkAPIProcessor
+{
+private:
+	Framework::UIMLView* view;
+	Framework::Text name;
+	std::function<void(UIMLDialog* self)> onClose;
+
+public:
+	UIMLDialog(Framework::Text uiml, std::function<void(UIMLDialog *self)> onClose);
+	~UIMLDialog();
+	void api(char* message) override;
+	const Framework::Text& getName() const;
+};

+ 199 - 165
FactoryCraft/Dimension.cpp

@@ -9,197 +9,231 @@ using namespace Framework;
 
 #define MAX_VIEW_DISTANCE CHUNK_SIZE * 8
 
-Dimension::Dimension( int id )
-    : dimensionId( id ),
-    chunks( new Trie<Chunk>() ),
-    entities( new RCArray<Entity>() )
+Dimension::Dimension(int id)
+	: dimensionId(id),
+	chunks(new Trie<Chunk>()),
+	entities(new RCArray<Entity>())
 {}
 
 Dimension::~Dimension()
 {
-    entities->release();
-    chunks->release();
+	entities->release();
+	chunks->release();
 }
 
-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;
 }
 
-void Dimension::getAddrOfWorld( Punkt wPos, char* addr ) const
+void Dimension::getAddrOfWorld(Punkt wPos, char* addr) const
 {
-    if( wPos.x < 0 )
-        wPos.x -= CHUNK_SIZE;
-    if( wPos.y < 0 ) // needed because otherwise would (-8, -8) have the same adress as (8, 8)
-        wPos.y -= CHUNK_SIZE;
-    wPos /= CHUNK_SIZE;
-    getAddrOf( wPos, addr );
+	if (wPos.x < 0)
+		wPos.x -= CHUNK_SIZE;
+	if (wPos.y < 0) // needed because otherwise would (-8, -8) have the same adress as (8, 8)
+		wPos.y -= CHUNK_SIZE;
+	wPos /= CHUNK_SIZE;
+	getAddrOf(wPos, addr);
 }
 
-Chunk* Dimension::zChunk( Punkt wPos ) const
+void Dimension::api(char* message)
+{
+	switch (message[0])
+	{
+	case 1: // chunck
+	{
+		int cX = *(int*)(message + 1);
+		int cY = *(int*)(message + 5);
+		Chunk* ch = zChunk(Punkt(cX, cY));
+		if (ch)
+			ch->api(message + 9);
+		break;
+	}
+	case 2: // entity
+	{
+		int eId = *(int*)(message + 1);
+		Entity* e = zEntity(eId);
+		if (e)
+			e->api(message + 5);
+		break;
+	}
+	case 3: // block
+	{
+		int px = *(int*)(message + 1);
+		int py = *(int*)(message + 5);
+		int pz = *(int*)(message + 9);
+		Block* b = zBlock(Framework::Vec3<int>(px, py, pz));
+		if (b)
+			b->api(message + 13);
+		break;
+	}
+	}
+}
+
+Chunk* Dimension::zChunk(Punkt wPos) const
 {
-    char addr[ 8 ];
-    getAddrOfWorld( wPos, addr );
-    return chunks->z( addr, 8 );
+	char addr[8];
+	getAddrOfWorld(wPos, addr);
+	return chunks->z(addr, 8);
 }
 
-Block* Dimension::zBlock( Vec3<int> location )
+Block* Dimension::zBlock(Vec3<int> location)
 {
-    Chunk* c = zChunk( currentGame->getChunkCenter( location.x, location.y ) );
-    if( c )
-        return c->zBlockAt( location );
-    return 0;
+	Chunk* c = zChunk(currentGame->getChunkCenter(location.x, location.y));
+	if (c)
+		return c->zBlockAt(location);
+	return 0;
 }
 
-Block* Dimension::getBlock( Vec3<int> location )
+Block* Dimension::getBlock(Vec3<int> location)
+{
+	cs.lock();
+	Chunk* c = zChunk(currentGame->getChunkCenter(location.x, location.y));
+	if (c)
+	{
+		Block* b = c->zBlockAt(location);
+		b = b ? dynamic_cast<Block*>(b->getThis()) : 0;
+		cs.unlock();
+		return b;
+	}
+	cs.unlock();
+	return 0;
+}
+
+void Dimension::addEntity(Entity* entity)
 {
-    cs.lock();
-    Chunk* c = zChunk( currentGame->getChunkCenter( location.x, location.y ) );
-    if( c )
-    {
-        Block* b = c->zBlockAt( location );
-        b = b ? dynamic_cast<Block*>(b->getThis()) : 0;
-        cs.unlock();
-        return b;
-    }
-    cs.unlock();
-    return 0;
+	entities->add(entity);
+}
+
+void Dimension::setChunk(Chunk* chunk, Punkt center, World* zWorld)
+{
+	char addr[8];
+	getAddrOfWorld(center, addr);
+	Chunk* old = chunks->z(addr, 8);
+	cs.lock();
+	if (old)
+	{
+		zWorld->setVisibility(old, 0);
+		int index = 0;
+		for (auto iterator = chunkList.begin(); iterator; ++iterator, ++index)
+		{
+			if ((Chunk*)iterator == old)
+			{
+				if (chunk)
+					iterator.set(chunk);
+				else
+					chunkList.remove(index);
+				break;
+			}
+		}
+	}
+	else if (chunk)
+		chunkList.add(chunk);
+	chunks->set(addr, 8, chunk);
+	if (chunk)
+	{
+		zWorld->setVisibility(chunk, 1);
+	}
+	cs.unlock();
 }
 
-void Dimension::addEntity( Entity* entity )
+int Dimension::getDimensionId() const
 {
-    entities->add( entity );
+	return dimensionId;
 }
 
-void Dimension::setChunk( Chunk* chunk, Punkt center, World* zWorld )
+bool Dimension::hasChunck(int x, int y) const
 {
-    char addr[ 8 ];
-    getAddrOfWorld( center, addr );
-    Chunk* old = chunks->z( addr, 8 );
-    cs.lock();
-    if( old )
-    {
-        zWorld->setVisibility( old, 0 );
-        int index = 0;
-        for( auto iterator = chunkList.begin(); iterator; ++iterator, ++index )
-        {
-            if( (Chunk*)iterator == old )
-            {
-                if( chunk )
-                    iterator.set( chunk );
-                else
-                    chunkList.remove( index );
-                break;
-            }
-        }
-    }
-    else if( chunk )
-        chunkList.add( chunk );
-    chunks->set( addr, 8, chunk );
-    if( chunk )
-    {
-        zWorld->setVisibility( chunk, 1 );
-    }
-    cs.unlock();
+	return zChunk(Punkt(x, y));
 }
 
-int Dimension::getDimensionId() const
+void Dimension::removeDistantChunks(Punkt wPos, World* zWorld)
+{
+	Array<int> removed;
+	int index = 0;
+	for (Chunk* chunk : chunkList)
+	{
+		if ((chunk->getCenter() - wPos).getLength() > MAX_VIEW_DISTANCE)
+			removed.add(index, 0);
+		index++;
+	}
+	for (int i : removed)
+	{
+		Chunk* chunk = chunkList.get(i);
+		zWorld->setVisibility(chunk, 0);
+		setChunk(0, chunk->getCenter(), zWorld);
+	}
+}
+
+void Dimension::setBlock(Block* block)
 {
-    return dimensionId;
-}
-
-bool Dimension::hasChunck( int x, int y ) const
-{
-    return zChunk( Punkt( x, y ) );
-}
-
-void Dimension::removeDistantChunks( Punkt wPos, World* zWorld )
-{
-    Array<int> removed;
-    int index = 0;
-    for( Chunk* chunk : chunkList )
-    {
-        if( (chunk->getCenter() - wPos).getLength() > MAX_VIEW_DISTANCE )
-            removed.add( index, 0 );
-        index++;
-    }
-    for( int i : removed )
-    {
-        Chunk* chunk = chunkList.get( i );
-        zWorld->setVisibility( chunk, 0 );
-        setChunk( 0, chunk->getCenter(), zWorld );
-    }
-}
-
-void Dimension::setBlock( Block* block )
-{
-    cs.lock();
-    Chunk* c = zChunk( currentGame->getChunkCenter( (int)floor( block->getPos().x ), (int)floor( block->getPos().y ) ) );
-    if( c )
-        c->setBlock( block );
-    else
-        block->release();
-    cs.unlock();
-}
-
-void Dimension::removeBlock( Block* zBlock )
-{
-    cs.lock();
-    Chunk* c = zChunk( currentGame->getChunkCenter( (int)floor( zBlock->getPos().x ), (int)floor( zBlock->getPos().y ) ) );
-    if( c )
-        c->removeBlock( zBlock );
-    cs.unlock();
-}
-
-Entity* Dimension::zEntity( int id )
-{
-    cs.lock();
-    for( Entity* e : *entities )
-    {
-        if( e->getId() == id )
-        {
-            cs.unlock();
-            return e;
-        }
-    }
-    cs.unlock();
-    return 0;
-}
-
-Entity* Dimension::getEntity( int id )
-{
-    cs.lock();
-    for( Entity* e : *entities )
-    {
-        if( e->getId() == id )
-        {
-            Entity* result = dynamic_cast<Entity*>(e->getThis());
-            cs.unlock();
-            return result;
-        }
-    }
-    cs.unlock();
-    return 0;
-}
-
-void Dimension::removeEntity( int id )
-{
-    currentGame->lockWorld();
-    cs.lock();
-    int index = 0;
-    for( Entity* e : *entities )
-    {
-        if( e->getId() == id )
-        {
-            currentGame->setVisibility( e, 0 );
-            entities->remove( index );
-            cs.unlock();
-            currentGame->unlockWorld();
-            return;
-        }
-        index++;
-    }
-    cs.unlock();
-    currentGame->unlockWorld();
+	cs.lock();
+	Chunk* c = zChunk(currentGame->getChunkCenter((int)floor(block->getPos().x), (int)floor(block->getPos().y)));
+	if (c)
+		c->setBlock(block);
+	else
+		block->release();
+	cs.unlock();
+}
+
+void Dimension::removeBlock(Block* zBlock)
+{
+	cs.lock();
+	Chunk* c = zChunk(currentGame->getChunkCenter((int)floor(zBlock->getPos().x), (int)floor(zBlock->getPos().y)));
+	if (c)
+		c->removeBlock(zBlock);
+	cs.unlock();
+}
+
+Entity* Dimension::zEntity(int id)
+{
+	cs.lock();
+	for (Entity* e : *entities)
+	{
+		if (e->getId() == id)
+		{
+			cs.unlock();
+			return e;
+		}
+	}
+	cs.unlock();
+	return 0;
+}
+
+Entity* Dimension::getEntity(int id)
+{
+	cs.lock();
+	for (Entity* e : *entities)
+	{
+		if (e->getId() == id)
+		{
+			Entity* result = dynamic_cast<Entity*>(e->getThis());
+			cs.unlock();
+			return result;
+		}
+	}
+	cs.unlock();
+	return 0;
+}
+
+void Dimension::removeEntity(int id)
+{
+	currentGame->lockWorld();
+	cs.lock();
+	int index = 0;
+	for (Entity* e : *entities)
+	{
+		if (e->getId() == id)
+		{
+			currentGame->setVisibility(e, 0);
+			entities->remove(index);
+			cs.unlock();
+			currentGame->unlockWorld();
+			return;
+		}
+		index++;
+	}
+	cs.unlock();
+	currentGame->unlockWorld();
 }

+ 23 - 22
FactoryCraft/Dimension.h

@@ -12,29 +12,30 @@ class World;
 class Dimension : public virtual Framework::ReferenceCounter
 {
 private:
-    int dimensionId;
-    Framework::Trie<Chunk>* chunks;
-    Framework::Array<Chunk*> chunkList;
-    Framework::RCArray<Entity>* entities;
-    Framework::Critical cs;
-    void getAddrOf( Framework::Punkt cPos, char* addr ) const;
-    void getAddrOfWorld( Framework::Punkt wPos, char* addr ) const;
+	int dimensionId;
+	Framework::Trie<Chunk>* chunks;
+	Framework::Array<Chunk*> chunkList;
+	Framework::RCArray<Entity>* entities;
+	Framework::Critical cs;
+	void getAddrOf(Framework::Punkt cPos, char* addr) const;
+	void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
 
 public:
-    Dimension( int id );
-    ~Dimension();
+	Dimension(int id);
+	~Dimension();
 
-    Block* zBlock( Framework::Vec3<int> location );
-    Block* getBlock( Framework::Vec3<int> location );
-    void addEntity( Entity* entity );
-    void setChunk( Chunk* chunk, Framework::Punkt center, World* zWorld );
-    int getDimensionId() const;
-    bool hasChunck( int x, int y ) const;
-    Chunk* zChunk( Framework::Punkt wPos ) const;
-    void removeDistantChunks( Framework::Punkt wPos, World* zWorld );
-    void setBlock( Block* block );
-    void removeBlock( Block* zBlock );
-    Entity* zEntity( int id );
-    Entity* getEntity( int id );
-    void removeEntity( int id );
+	void api(char* message);
+	Block* zBlock(Framework::Vec3<int> location);
+	Block* getBlock(Framework::Vec3<int> location);
+	void addEntity(Entity* entity);
+	void setChunk(Chunk* chunk, Framework::Punkt center, World* zWorld);
+	int getDimensionId() const;
+	bool hasChunck(int x, int y) const;
+	Chunk* zChunk(Framework::Punkt wPos) const;
+	void removeDistantChunks(Framework::Punkt wPos, World* zWorld);
+	void setBlock(Block* block);
+	void removeBlock(Block* zBlock);
+	Entity* zEntity(int id);
+	Entity* getEntity(int id);
+	void removeEntity(int id);
 };

+ 60 - 55
FactoryCraft/Entity.cpp

@@ -1,119 +1,124 @@
 #include "Entity.h"
 #include "Globals.h"
 
-ActionTarget::ActionTarget( Framework::Vec3<int> blockPos, Direction blockSide )
-    : blockPos( blockPos ),
-    targetBlockSide( blockSide ),
-    entityId( -1 )
+ActionTarget::ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide)
+	: blockPos(blockPos),
+	targetBlockSide(blockSide),
+	entityId(-1)
 {}
 
-ActionTarget::ActionTarget( int entityId )
-    : entityId( entityId )
+ActionTarget::ActionTarget(int entityId)
+	: entityId(entityId)
 {}
 
-ActionTarget* ActionTarget::load( Framework::StreamReader* zReader )
-{
-    char b;
-    zReader->lese( &b, 1 );
-    if( b == 1 )
-    {
-        int id;
-        zReader->lese( (char*)&id, 4 );
-        return new ActionTarget( id );
-    }
-    else if( b == 2 )
-    {
-        Framework::Vec3<int> pos;
-        Direction side;
-        zReader->lese( (char*)&pos.x, 4 );
-        zReader->lese( (char*)&pos.y, 4 );
-        zReader->lese( (char*)&pos.z, 4 );
-        zReader->lese( (char*)&side, 4 );
-        return new ActionTarget( pos, side );
-    }
-    return 0;
+ActionTarget* ActionTarget::load(Framework::StreamReader* zReader)
+{
+	char b;
+	zReader->lese(&b, 1);
+	if (b == 1)
+	{
+		int id;
+		zReader->lese((char*)&id, 4);
+		return new ActionTarget(id);
+	}
+	else if (b == 2)
+	{
+		Framework::Vec3<int> pos;
+		Direction side;
+		zReader->lese((char*)&pos.x, 4);
+		zReader->lese((char*)&pos.y, 4);
+		zReader->lese((char*)&pos.z, 4);
+		zReader->lese((char*)&side, 4);
+		return new ActionTarget(pos, side);
+	}
+	return 0;
 }
 
 bool ActionTarget::isBlock() const
 {
-    return entityId == -1;
+	return entityId == -1;
 }
 
 bool ActionTarget::isEntity() const
 {
-    return entityId >= 0;
+	return entityId >= 0;
 }
 
 int ActionTarget::getEntityId() const
 {
-    return entityId;
+	return entityId;
 }
 
 Framework::Vec3<int> ActionTarget::getBlockPos() const
 {
-    return blockPos;
+	return blockPos;
 }
 
 Direction ActionTarget::getBlockSide() const
 {
-    return targetBlockSide;
+	return targetBlockSide;
 }
 
-Framework::Either<Block*, Entity*> ActionTarget::zTarget( int dimension ) const
+Framework::Either<Block*, Entity*> ActionTarget::zTarget(int dimension) const
 {
-    if( entityId >= 0 )
-        return currentGame->zEntity( entityId );
-    else
-        return currentGame->zBlockAt( blockPos, dimension );
+	if (entityId >= 0)
+		return currentGame->zEntity(entityId);
+	else
+		return currentGame->zBlockAt(blockPos, dimension);
 }
 
-Framework::Either<Block*, Entity*> ActionTarget::getTarget( int dimension ) const
+Framework::Either<Block*, Entity*> ActionTarget::getTarget(int dimension) const
 {
-    if( entityId >= 0 )
-        return currentGame->getEntity( entityId );
-    else
-        return currentGame->getBlockAt( blockPos, dimension );
+	if (entityId >= 0)
+		return currentGame->getEntity(entityId);
+	else
+		return currentGame->getBlockAt(blockPos, dimension);
 }
 
 
-Entity::Entity( const EntityType* zType, bool hasInventory )
-    : Model3D(), Inventory( { 0.f, 0.f, 0.f }, hasInventory ), zEntityType( zType ), target( 0 )
+Entity::Entity(const EntityType* zType, bool hasInventory)
+	: Model3D(), Inventory({ 0.f, 0.f, 0.f }, hasInventory), zEntityType(zType), target(0)
 {}
 
 Entity::~Entity()
 {
-    if( target )
-        delete target;
+	if (target)
+		delete target;
+}
+
+void Entity::api(char* message)
+{
+	// TODO: implement api
 }
 
-bool Entity::tick( double time )
+bool Entity::tick(double time)
 {
-    setPosition( location );
-    // TODO: calculate rotation based on faceDir
-    return Model3D::tick( time );
+	setPosition(location);
+	// TODO: calculate rotation based on faceDir
+	return Model3D::tick(time);
 }
 
 int Entity::getId() const
 {
-    return id;
+	return id;
 }
 
 const EntityType* Entity::zType() const
 {
-    return zEntityType;
+	return zEntityType;
 }
 
 int Entity::getCurrentDimension() const
 {
-    return currentDimensionId;
+	return currentDimensionId;
 }
 
 void Entity::lock()
 {
-    cs.lock();
+	cs.lock();
 }
 
 void Entity::unlock()
 {
-    cs.unlock();
+	cs.unlock();
 }

+ 40 - 39
FactoryCraft/Entity.h

@@ -11,57 +11,58 @@ class Block;
 class ActionTarget
 {
 private:
-    Framework::Vec3<int> blockPos;
-    Direction targetBlockSide;
-    int entityId;
+	Framework::Vec3<int> blockPos;
+	Direction targetBlockSide;
+	int entityId;
 
 public:
-    ActionTarget( Framework::Vec3<int> blockPos, Direction blockSide );
-    ActionTarget( int entityId );
+	ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
+	ActionTarget(int entityId);
 
-    static ActionTarget* load( Framework::StreamReader* zReader );
+	static ActionTarget* load(Framework::StreamReader* zReader);
 
-    bool isBlock() const;
-    bool isEntity() const;
-    int getEntityId() const;
-    Framework::Vec3<int> getBlockPos() const;
-    Direction getBlockSide() const;
-    Framework::Either<Block*, Entity*> zTarget( int dimensionId ) const;
-    Framework::Either<Block*, Entity*> getTarget( int dimensionId ) const;
+	bool isBlock() const;
+	bool isEntity() const;
+	int getEntityId() const;
+	Framework::Vec3<int> getBlockPos() const;
+	Direction getBlockSide() const;
+	Framework::Either<Block*, Entity*> zTarget(int dimensionId) const;
+	Framework::Either<Block*, Entity*> getTarget(int dimensionId) const;
 };
 
 class Entity : public Framework::Model3D, public Inventory
 {
 protected:
-    float maxHP;
-    float currentHP;
-    float stamina;
-    float maxStamina;
-    float hunger;
-    float maxHunger;
-    float thirst;
-    float maxThirst;
-    float targetDistanceLimit;
-    Framework::Vec3<float> speed;
-    Framework::Vec3<float> faceDir;
-    const EntityType* zEntityType;
-    int currentDimensionId;
-    float gravityMultiplier;
-    int id;
-    ActionTarget* target;
-    Framework::Critical cs;
+	float maxHP;
+	float currentHP;
+	float stamina;
+	float maxStamina;
+	float hunger;
+	float maxHunger;
+	float thirst;
+	float maxThirst;
+	float targetDistanceLimit;
+	Framework::Vec3<float> speed;
+	Framework::Vec3<float> faceDir;
+	const EntityType* zEntityType;
+	int currentDimensionId;
+	float gravityMultiplier;
+	int id;
+	ActionTarget* target;
+	Framework::Critical cs;
 
 public:
-    Entity( const EntityType* zType, bool hasInventory );
-    ~Entity();
+	Entity(const EntityType* zType, bool hasInventory);
+	~Entity();
 
-    virtual bool tick( double time ) override;
+	void api(char* message);
+	virtual bool tick(double time) override;
 
-    int getId() const;
-    const EntityType* zType() const;
-    int getCurrentDimension() const;
-    void lock();
-    void unlock();
+	int getId() const;
+	const EntityType* zType() const;
+	int getCurrentDimension() const;
+	void lock();
+	void unlock();
 
-    friend EntityType;
+	friend EntityType;
 };

+ 53 - 0
FactoryCraft/Equipment.cpp

@@ -0,0 +1,53 @@
+#include <XML.h>
+
+#include "Equipment.h"
+
+using namespace Framework;
+
+EquipmentElement::EquipmentElement()
+	: UIMLElement()
+{}
+
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+bool EquipmentElement::isApplicableFor(Framework::XML::Element& element)
+{
+	return element.getName().istGleich("equipment");
+}
+
+//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+Framework::Zeichnung* EquipmentElement::parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
+{
+	return new EquipmentView((int)element.getAttributeValue("entity"));
+}
+
+//! wendet die layout parameter zu einer Zeichnung an
+void EquipmentElement::layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter)
+{
+	UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
+}
+
+
+EquipmentView::EquipmentView(int entityId)
+	: ZeichnungHintergrund(),
+	entityId(entityId)
+{}
+
+void EquipmentView::api(char* message)
+{
+
+}
+
+bool EquipmentView::tick(double tickVal)
+{
+	return ZeichnungHintergrund::tick(tickVal);
+}
+
+void EquipmentView::render(Bild& rObj)
+{
+	ZeichnungHintergrund::render(rObj);
+}
+
+void EquipmentView::doMausEreignis(MausEreignis& me, bool userRet)
+{
+	ZeichnungHintergrund::doMausEreignis(me, userRet);
+}

+ 30 - 0
FactoryCraft/Equipment.h

@@ -0,0 +1,30 @@
+#pragma once
+
+#include "NetworkAPIProcessor.h"
+
+#include <UIMLView.h>
+
+class EquipmentElement : public Framework::UIMLElement
+{
+public:
+	EquipmentElement();
+	//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+	bool isApplicableFor(Framework::XML::Element& element) override;
+	//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+	Framework::Zeichnung* parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory) override;
+	//! wendet die layout parameter zu einer Zeichnung an
+	void layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter) override;
+};
+
+class EquipmentView : public Framework::ZeichnungHintergrund, public NetworkAPIProcessor
+{
+private:
+	int entityId;
+
+public:
+	EquipmentView(int entityId);
+	void api(char* message) override;
+	bool tick(double tickVal) override;
+	void render(Framework::Bild& rObj) override;
+	void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+};

+ 125 - 111
FactoryCraft/FactoryClient.cpp

@@ -4,140 +4,154 @@ using namespace Network;
 
 FactoryClient::FactoryClient()
 {
-    client = 0;
-    background = 0;
-    foreground = 0;
-    backgroundReader = 0;
-    foregroundReader = 0;
-    bgReaderUsage = 0;
-    fgReaderUsage = 0;
+	client = 0;
+	background = 0;
+	foreground = 0;
+	backgroundReader = 0;
+	foregroundReader = 0;
+	bgReaderUsage = 0;
+	fgReaderUsage = 0;
 }
 
 FactoryClient::~FactoryClient()
 {
-    if( client )
-        disconnect();
+	if (client)
+		disconnect();
 }
 
-bool FactoryClient::connect( Text ip, short port, int accountId, Text secret )
+bool FactoryClient::connect(Text ip, short port, int accountId, Text secret)
 {
-    if( client )
-        disconnect();
-    client = new SSLKlient();
-    if( !client->verbinde( port, ip ) )
-        return false;
-    if( !client->sende( "\1", 1 ) )
-        return false;
-    if( !client->sende( (char*)&accountId, 4 ) )
-        return false;
-    unsigned char len = (unsigned char)secret.getLength();
-    if( !client->sende( (char*)&len, 1 ) )
-        return false;
-    if( !client->sende( secret, len ) )
-        return false;
-    char result = 0;
-    if( !client->getNachricht( &result, 1 ) || result != 1 )
-        return false;
-    int keyLen;
-    if( !client->getNachricht( (char*)&keyLen, 4 ) )
-        return false;
-    char* key = new char[ keyLen ];
-    if( !client->getNachricht( key, keyLen ) )
-        return false;
-    int p;
-    if( !client->getNachricht( (char*)&p, 4 ) )
-        return false;
-    foreground = new Klient();
-    if( !foreground->verbinde( p, ip ) )
-        return false;
-    unsigned short l = (unsigned short)keyLen;
-    if( !foreground->sende( (char*)&l, 2 ) )
-        return false;
-    if( !foreground->sende( key, keyLen ) )
-        return false;
-    bool bg = 0;
-    if( !foreground->sende( (char*)&bg, 1 ) )
-        return false;
-    foregroundReader = new NetworkReader( foreground );
-    background = new Klient();
-    if( !background->verbinde( p, ip ) )
-        return false;
-    if( !background->sende( (char*)&l, 2 ) )
-        return false;
-    if( !background->sende( key, keyLen ) )
-        return false;
-    bg = 1;
-    if( !background->sende( (char*)&bg, 1 ) )
-        return false;
-    backgroundReader = new NetworkReader( background );
-    client->trenne();
-    return true;
+	if (client)
+		disconnect();
+	client = new SSLKlient();
+	if (!client->verbinde(port, ip))
+		return false;
+	if (!client->sende("\1", 1))
+		return false;
+	if (!client->sende((char*)&accountId, 4))
+		return false;
+	unsigned char len = (unsigned char)secret.getLength();
+	if (!client->sende((char*)&len, 1))
+		return false;
+	if (!client->sende(secret, len))
+		return false;
+	char result = 0;
+	if (!client->getNachricht(&result, 1) || result != 1)
+		return false;
+	int keyLen;
+	if (!client->getNachricht((char*)&keyLen, 4))
+		return false;
+	char* key = new char[keyLen];
+	if (!client->getNachricht(key, keyLen))
+		return false;
+	int p;
+	if (!client->getNachricht((char*)&p, 4))
+		return false;
+	foreground = new Klient();
+	if (!foreground->verbinde(p, ip))
+		return false;
+	unsigned short l = (unsigned short)keyLen;
+	if (!foreground->sende((char*)&l, 2))
+		return false;
+	if (!foreground->sende(key, keyLen))
+		return false;
+	bool bg = 0;
+	if (!foreground->sende((char*)&bg, 1))
+		return false;
+	foregroundReader = new NetworkReader(foreground);
+	background = new Klient();
+	if (!background->verbinde(p, ip))
+		return false;
+	if (!background->sende((char*)&l, 2))
+		return false;
+	if (!background->sende(key, keyLen))
+		return false;
+	bg = 1;
+	if (!background->sende((char*)&bg, 1))
+		return false;
+	backgroundReader = new NetworkReader(background);
+	client->trenne();
+	return true;
 }
 
 void FactoryClient::disconnect()
 {
-    if( client )
-    {
-        NetworkReader* fgReader = foregroundReader;
-        NetworkReader* bgReader = backgroundReader;
-        backgroundReader = 0;
-        foregroundReader = 0;
-        if( foreground )
-            foreground->trenne();
-        if( background )
-            background->trenne();
-        while( fgReaderUsage > 0 || bgReaderUsage > 0 )
-            Sleep( 100 );
-        delete fgReader;
-        delete bgReader;
-        client->release();
-        client = 0;
-        if( foreground )
-            foreground->release();
-        foreground = 0;
-        if( background )
-            background->release();
-        background = 0;
-    }
+	if (client)
+	{
+		NetworkReader* fgReader = foregroundReader;
+		NetworkReader* bgReader = backgroundReader;
+		backgroundReader = 0;
+		foregroundReader = 0;
+		if (foreground)
+			foreground->trenne();
+		if (background)
+			background->trenne();
+		while (fgReaderUsage > 0 || bgReaderUsage > 0)
+			Sleep(100);
+		delete fgReader;
+		delete bgReader;
+		client->release();
+		client = 0;
+		if (foreground)
+			foreground->release();
+		foreground = 0;
+		if (background)
+			background->release();
+		background = 0;
+	}
 }
 
 NetworkReader* FactoryClient::getNextForegroundMessage()
 {
-    fgReaderUsage++;
-    if( !foreground )
-        return 0;
-    if( !foreground->hatNachricht( 0 ) )
-        return 0;
-    return foregroundReader;
+	fgReaderUsage++;
+	if (!foreground)
+		return 0;
+	if (!foreground->hatNachricht(0))
+		return 0;
+	return foregroundReader;
 }
 
 NetworkReader* FactoryClient::getNextBackgroundMessage()
 {
-    bgReaderUsage++;
-    if( !background )
-        return 0;
-    if( !background->hatNachricht( 0 ) )
-        return 0;
-    return backgroundReader;
+	bgReaderUsage++;
+	if (!background)
+		return 0;
+	if (!background->hatNachricht(0))
+		return 0;
+	return backgroundReader;
 }
 
-void FactoryClient::endMessageReading( bool bg )
+void FactoryClient::endMessageReading(bool bg)
 {
-    if( bg )
-        bgReaderUsage--;
-    else
-        fgReaderUsage--;
+	if (bg)
+		bgReaderUsage--;
+	else
+		fgReaderUsage--;
 }
 
-void FactoryClient::sendPlayerAction( void* data, unsigned short length )
+void FactoryClient::sendPlayerAction(char* data, unsigned short length)
 {
-    if( !foreground )
-        return;
-    cs.lock();
-    length += 1;
-    foreground->sende( (char*)&length, 2 );
-    char msgId = 2;
-    foreground->sende( &msgId, 1 );
-    foreground->sende( (char*)data, length - 1 );
-    cs.unlock();
+	if (!foreground)
+		return;
+	cs.lock();
+	length += 1;
+	foreground->sende((char*)&length, 2);
+	char msgId = 2;
+	foreground->sende(&msgId, 1);
+	foreground->sende((char*)data, length - 1);
+	cs.unlock();
+}
+
+void FactoryClient::entityAPIRequest(int entityId, char* message, unsigned short length)
+{
+	if (!foreground)
+		return;
+	cs.lock();
+	length += 5;
+	foreground->sende((char*)&length, 2);
+	char msgId = 3;
+	foreground->sende(&msgId, 1);
+	foreground->sende((char*)&entityId, 4);
+	foreground->sende(message, length - 5);
+	cs.unlock();
 }

+ 17 - 16
FactoryCraft/FactoryClient.h

@@ -9,24 +9,25 @@
 class FactoryClient : public Framework::ReferenceCounter
 {
 private:
-    Network::SSLKlient* client;
-    Network::Klient* foreground;
-    Network::Klient* background;
-    Network::NetworkReader* foregroundReader;
-    Network::NetworkReader* backgroundReader;
-    Framework::Critical cs;
-    int bgReaderUsage;
-    int fgReaderUsage;
+	Network::SSLKlient* client;
+	Network::Klient* foreground;
+	Network::Klient* background;
+	Network::NetworkReader* foregroundReader;
+	Network::NetworkReader* backgroundReader;
+	Framework::Critical cs;
+	int bgReaderUsage;
+	int fgReaderUsage;
 
-    void disconnect();
+	void disconnect();
 
 public:
-    FactoryClient();
-    ~FactoryClient();
+	FactoryClient();
+	~FactoryClient();
 
-    bool connect( Text ip, short port, int accountId, Text secret );
-    Network::NetworkReader* getNextForegroundMessage();
-    Network::NetworkReader* getNextBackgroundMessage();
-    void endMessageReading( bool bg );
-    void sendPlayerAction( void* data, unsigned short length );
+	bool connect(Text ip, short port, int accountId, Text secret);
+	Network::NetworkReader* getNextForegroundMessage();
+	Network::NetworkReader* getNextBackgroundMessage();
+	void endMessageReading(bool bg);
+	void sendPlayerAction(char* data, unsigned short length);
+	void entityAPIRequest(int entityId, char* message, unsigned short length);
 };

+ 8 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -179,16 +179,20 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="BlockRemovedUpdate.cpp" />
     <ClCompile Include="BlockType.cpp" />
     <ClCompile Include="Chunk.cpp" />
+    <ClCompile Include="CraftingGrid.cpp" />
+    <ClCompile Include="Dialog.cpp" />
     <ClCompile Include="Dimension.cpp" />
     <ClCompile Include="DirectConnect.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="EntityChangedUpdate.cpp" />
     <ClCompile Include="EntityRemovedUpdate.cpp" />
     <ClCompile Include="EntityType.cpp" />
+    <ClCompile Include="Equipment.cpp" />
     <ClCompile Include="FactoryClient.cpp" />
     <ClCompile Include="Game.cpp" />
     <ClCompile Include="Globals.cpp" />
     <ClCompile Include="Initialisierung.cpp" />
+    <ClCompile Include="InventoryView.cpp" />
     <ClCompile Include="Inventoty.cpp" />
     <ClCompile Include="Item.cpp" />
     <ClCompile Include="ItemEntity.cpp" />
@@ -218,18 +222,22 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="BlockType.h" />
     <ClInclude Include="Chunk.h" />
     <ClInclude Include="Constants.h" />
+    <ClInclude Include="CraftingGrid.h" />
+    <ClInclude Include="Dialog.h" />
     <ClInclude Include="Dimension.h" />
     <ClInclude Include="DirectConnect.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="EntityChangedUpdate.h" />
     <ClInclude Include="EntityRemovedUpdate.h" />
     <ClInclude Include="EntityType.h" />
+    <ClInclude Include="Equipment.h" />
     <ClInclude Include="FactoryClient.h" />
     <ClInclude Include="Game.h" />
     <ClInclude Include="Globals.h" />
     <ClInclude Include="AddChunkUpdate.h" />
     <ClInclude Include="Initialisierung.h" />
     <ClInclude Include="Inventory.h" />
+    <ClInclude Include="InventoryView.h" />
     <ClInclude Include="Item.h" />
     <ClInclude Include="ItemEntity.h" />
     <ClInclude Include="ItemSlot.h" />

+ 39 - 17
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -1,14 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <Filter Include="Headerdateien">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Ressourcendateien">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
-    </Filter>
     <Filter Include="static">
       <UniqueIdentifier>{4a54dd56-42bb-4f6c-839d-8ed5709a9373}</UniqueIdentifier>
     </Filter>
@@ -37,7 +29,13 @@
       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
       <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     </Filter>
-    <Filter Include="Headerdateien\Entity">
+    <Filter Include="Menu\uiml">
+      <UniqueIdentifier>{6bf492a1-4d32-4c47-94b3-ccda46632c44}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Menu\uiml\inventory">
+      <UniqueIdentifier>{41ade392-45b4-4224-907c-de5926f15261}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Entity">
       <UniqueIdentifier>{2a45d30e-df5b-4886-8ae7-d42ff2b3a13e}</UniqueIdentifier>
     </Filter>
   </ItemGroup>
@@ -133,19 +131,19 @@
       <Filter>world\update</Filter>
     </ClCompile>
     <ClCompile Include="EntityType.cpp">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClCompile>
     <ClCompile Include="Entity.cpp">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClCompile>
     <ClCompile Include="Player.cpp">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClCompile>
     <ClCompile Include="AddEntityUpdate.cpp">
       <Filter>world\update</Filter>
     </ClCompile>
     <ClCompile Include="ItemEntity.cpp">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClCompile>
     <ClCompile Include="EntityChangedUpdate.cpp">
       <Filter>world\update</Filter>
@@ -153,6 +151,18 @@
     <ClCompile Include="EntityRemovedUpdate.cpp">
       <Filter>world\update</Filter>
     </ClCompile>
+    <ClCompile Include="Dialog.cpp">
+      <Filter>Menu\uiml</Filter>
+    </ClCompile>
+    <ClCompile Include="InventoryView.cpp">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClCompile>
+    <ClCompile Include="Equipment.cpp">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClCompile>
+    <ClCompile Include="CraftingGrid.cpp">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -249,19 +259,19 @@
       <Filter>world\update</Filter>
     </ClInclude>
     <ClInclude Include="Entity.h">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClInclude>
     <ClInclude Include="EntityType.h">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClInclude>
     <ClInclude Include="Player.h">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClInclude>
     <ClInclude Include="AddEntityUpdate.h">
       <Filter>world\update</Filter>
     </ClInclude>
     <ClInclude Include="ItemEntity.h">
-      <Filter>Headerdateien\Entity</Filter>
+      <Filter>Entity</Filter>
     </ClInclude>
     <ClInclude Include="EntityChangedUpdate.h">
       <Filter>world\update</Filter>
@@ -269,5 +279,17 @@
     <ClInclude Include="EntityRemovedUpdate.h">
       <Filter>world\update</Filter>
     </ClInclude>
+    <ClInclude Include="Dialog.h">
+      <Filter>Menu\uiml</Filter>
+    </ClInclude>
+    <ClInclude Include="CraftingGrid.h">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClInclude>
+    <ClInclude Include="Equipment.h">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClInclude>
+    <ClInclude Include="InventoryView.h">
+      <Filter>Menu\uiml\inventory</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 144 - 79
FactoryCraft/Game.cpp

@@ -5,90 +5,155 @@
 #include <AsynchronCall.h>
 #include <Bildschirm.h>
 
-Game::Game( Bildschirm* zScreen )
-    : Menu( zScreen )
+Game::Game(Bildschirm* zScreen)
+	: Menu(zScreen)
 {
-    logout = initKnopf( 10, 10, 200, 20, Knopf::Style::Normal, "Verlassen" );
-    logout->setMausEreignis( [this, zScreen]( void* p, void* o, MausEreignis me ) {
-        if( me.id == ME_RLinks )
-        {
-            logout->removeStyle( Knopf::Style::Erlaubt );
-            new AsynchronCall( [this, zScreen]() {
-                if( network->leaveGame() )
-                {
-                    currentGame->release();
-                    currentGame = 0;
-                    zScreen->lock();
-                    hide();
-                    menuRegister->get( "directConnect" )->show();
-                    zScreen->unlock();
-                }
-                logout->addStyle( Knopf::Style::Erlaubt );
-            } );
-        }
-        return 1;
-    } );
-    elements.add( logout );
-    debug = initTextFeld( 10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "" );
-    elements.add( debug );
-    invB = new Bild();
-    invB->neuBild( zScreen->getBackBufferSize().x - 20, 50, 0 );
-    invB->setAlpha3D( 1 );
-    inventory = initBildZ( 10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB );
-    elements.add( inventory );
+	logout = initKnopf(10, 10, 200, 20, Knopf::Style::Normal, "Verlassen");
+	logout->setMausEreignis([this, zScreen](void* p, void* o, MausEreignis me)
+		{
+			if (me.id == ME_RLinks)
+			{
+				logout->removeStyle(Knopf::Style::Erlaubt);
+				new AsynchronCall([this, zScreen]()
+					{
+						if (network->leaveGame())
+						{
+							currentGame->release();
+							currentGame = 0;
+							zScreen->lock();
+							hide();
+							menuRegister->get("directConnect")->show();
+							zScreen->unlock();
+						}
+						logout->addStyle(Knopf::Style::Erlaubt);
+					});
+			}
+			return 1;
+		});
+	elements.add(logout);
+	debug = initTextFeld(10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "");
+	elements.add(debug);
+	invB = new Bild();
+	invB->neuBild(zScreen->getBackBufferSize().x - 20, 50, 0);
+	invB->setAlpha3D(1);
+	inventory = initBildZ(10, zScreen->getBackBufferSize().y - 60, zScreen->getBackBufferSize().x - 20, 50, BildZ::Style::Sichtbar | BildZ::Style::Alpha, invB);
+	elements.add(inventory);
 }
 
-void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos )
+Game::~Game()
+{}
+
+void Game::updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos)
+{
+	Text txt = "Position: (";
+	txt.setPrecision(2);
+	txt += position.x;
+	txt += ", ";
+	txt += position.y;
+	txt += ", ";
+	txt += position.z;
+	txt += ")";
+	if (target)
+	{
+		txt += "\nTarget: (";
+		txt += targetPos.x;
+		txt += ", ";
+		txt += targetPos.y;
+		txt += ", ";
+		txt += targetPos.z;
+		txt += ")";
+	}
+	debug->setText(txt);
+}
+
+void Game::updateInventory(Framework::Array<ItemSlot*>& itemBar, int pos)
 {
-    Text txt = "Position: (";
-    txt.setPrecision( 2 );
-    txt += position.x;
-    txt += ", ";
-    txt += position.y;
-    txt += ", ";
-    txt += position.z;
-    txt += ")";
-    if( target )
-    {
-        txt += "\nTarget: (";
-        txt += targetPos.x;
-        txt += ", ";
-        txt += targetPos.y;
-        txt += ", ";
-        txt += targetPos.z;
-        txt += ")";
-    }
-    debug->setText( txt );
+	invB->fillRegion(0, 0, invB->getBreite(), invB->getHeight(), 0);
+	TextRenderer tr;
+	tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
+	tr.setSchriftSize(12);
+	int index = 0;
+	for (auto slot : itemBar)
+	{
+		if (pos == index)
+		{
+			invB->fillRegion(50 * index, 0, 50, 50, 0x7F202020);
+		}
+		if (slot && slot->zStack() && slot->zStack()->zItem())
+		{
+			Bild* icon = itemIcons->z(slot->zStack()->zItem()->zItemType()->getId());
+			invB->alphaBild(50 * index, 0, 50, 50, *icon);
+			tr.renderText(5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF);
+			int size = slot->zStack()->getSize();
+			const char* units[] = { "", "K", "M", "G", "T", "P" };
+			int i = 0;
+			for (; i < 6 && size > 1024; i++)
+				size = size / 1024;
+			Text count = size;
+			count += units[i];
+			tr.renderText(45 - tr.getTextBreite(count) + index * 50, 45 - tr.getTextHeight(count), count, *invB, 0xFFFFFFFF);
+		}
+		index++;
+	}
+	inventory->setRender();
 }
 
-void Game::updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos )
+void Game::api(char* data)
 {
-    invB->fillRegion( 0, 0, invB->getBreite(), invB->getHeight(), 0 );
-    TextRenderer tr;
-    tr.setSchriftZ( dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()) );
-    tr.setSchriftSize( 12 );
-    int index = 0;
-    for( auto slot : itemBar )
-    {
-        if( pos == index )
-        {
-            invB->fillRegion( 50 * index, 0, 50, 50, 0x7F202020 );
-        }
-        if( slot && slot->zStack() && slot->zStack()->zItem() )
-        {
-            Bild* icon = itemIcons->z( slot->zStack()->zItem()->zItemType()->getId() );
-            invB->alphaBild( 50 * index, 0, 50, 50, *icon );
-            tr.renderText( 5 + index * 50, 5, slot->zStack()->zItem()->getName(), *invB, 0xFFFFFFFF );
-            int size = slot->zStack()->getSize();
-            const char* units[] = { "", "K", "M", "G", "T", "P" };
-            int i = 0;
-            for( ; i < 6 && size > 1024; i++ )
-                size = size / 1024;
-            Text count = size;
-            count += units[ i ];
-            tr.renderText( 45 - tr.getTextBreite( count ) + index * 50, 45 - tr.getTextHeight( count ), count, *invB, 0xFFFFFFFF );
-        }
-        index++;
-    }
-    inventory->setRender();
+	switch (data[0])
+	{
+	case 0: // open dialog
+	{
+		bool exists = 0;
+		short len = *(short*)(data + 1);
+		char* dialogName = new char[len + 1];
+		memcpy(dialogName, data + 3, len);
+		dialogName[len] = 0;
+		for (UIMLDialog* dialog : dialogs)
+		{
+			if (dialog->getName().istGleich(dialogName))
+			{
+				exists = 1;
+				break;
+			}
+		}
+		delete[] dialogName;
+		if (!exists)
+		{
+			int uimlLen = *(int*)(data + 4 + len);
+			char* uiml = new char[uimlLen + 1];
+			memcpy(uiml, data + 8 + len, uimlLen);
+			uiml[uimlLen] = 0;
+			UIMLDialog* dialog = new UIMLDialog(uiml, [this](UIMLDialog* dialog)
+				{
+					logout->postAction([this, dialog]()
+						{
+							int index = 0;
+							for (UIMLDialog* d : dialogs)
+							{
+								if (d == dialog)
+								{
+									dialogs.remove(index);
+									window->zBildschirm()->removeMember(d);
+									break;
+								}
+								index++;
+							}
+						});
+				});
+			dialogs.add(dialog);
+			window->zBildschirm()->addMember(dialog);
+			delete[]uiml;
+		}
+		break;
+	}
+	case 1:
+	{ // element message
+		for (UIMLDialog* dialog : dialogs)
+		{
+			dialog->api(data + 1);
+		}
+		break;
+	}
+	}
 }

+ 12 - 8
FactoryCraft/Game.h

@@ -4,6 +4,7 @@
 #include <Bild.h>
 
 #include "Menu.h"
+#include "Dialog.h"
 
 class Player;
 class ItemSlot;
@@ -11,15 +12,18 @@ class ItemSlot;
 class Game : public Menu
 {
 private:
-    Framework::Knopf* logout;
-    Framework::TextFeld* debug;
-    Framework::Bild* invB;
-    Framework::BildZ* inventory;
+	Framework::Knopf* logout;
+	Framework::TextFeld* debug;
+	Framework::Bild* invB;
+	Framework::BildZ* inventory;
+	Framework::Array<UIMLDialog*> dialogs;
 
 public:
-    // Konstruktor
-    Game( Bildschirm* zScreen );
+	// Konstruktor
+	Game(Bildschirm* zScreen);
+	~Game();
 
-    void updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos );
-    void updateInventory( Framework::Array<ItemSlot*>& itemBar, int pos );
+	void updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos);
+	void updateInventory(Framework::Array<ItemSlot*>& itemBar, int pos);
+	void api(char* data);
 };

+ 9 - 7
FactoryCraft/Inventory.h

@@ -13,16 +13,18 @@ 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 );
-    void addSlot( ItemSlot* slot );
+	Framework::Vec3<float> location;
+	virtual void loadInventory(Framework::StreamReader* zReader);
+	void addSlot(ItemSlot* slot);
 
 
 public:
-    Inventory( const Framework::Vec3<float> location, bool hasInventory );
-    virtual ~Inventory();
+	Inventory(const Framework::Vec3<float> location, bool hasInventory);
+	virtual ~Inventory();
+	Framework::Iterator<ItemSlot*> begin();
+	Framework::Iterator<ItemSlot*> end();
 };

+ 171 - 0
FactoryCraft/InventoryView.cpp

@@ -0,0 +1,171 @@
+#include <XML.h>
+#include <Bild.h>
+
+#include "InventoryView.h"
+#include "Globals.h"
+
+using namespace Framework;
+
+InventoryElement::InventoryElement()
+	: UIMLElement()
+{}
+
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+bool InventoryElement::isApplicableFor(Framework::XML::Element& element)
+{
+	return element.getName().istGleich("inventory");
+}
+
+//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+Framework::Zeichnung* InventoryElement::parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
+{
+	Text targetValue = element.getAttributeValue("target");
+	Vec3<int> blockPos(0, 0, 0);
+	Framework::Either<int, Vec3<int>> target((int)targetValue);
+	if (targetValue.hat(','))
+	{
+		Text* first = targetValue.getTeilText(0, targetValue.positionVon(",", 0) + 1);
+		Text* second = targetValue.getTeilText(targetValue.positionVon(",", 0) + 1, targetValue.positionVon(",", 1));
+		Text* third = targetValue.getTeilText(targetValue.positionVon(",", 1) + 1);
+		target = Framework::Either<int, Vec3<int>>(Vec3<int>((int)*first, (int)*second, (int)*third));
+		first->release();
+		second->release();
+		third->release();
+	}
+	return new InventoryView(element.getAttributeValue("id"), target, (int)element.getAttributeValue("rowSize"), element.getAttributeValue("slotNameFilter"));
+}
+
+//! wendet die layout parameter zu einer Zeichnung an
+void InventoryElement::layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter)
+{
+	UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
+}
+
+
+void SlotInfo::render(int x, int y, Framework::Bild& rObj)
+{
+	TextRenderer tr;
+	tr.setSchriftZ(dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
+	tr.setSchriftSize(12);
+	rObj.fillRegion(x, y, 52, 52, 0xFF52525E);
+	rObj.fillRegion(x + 1, y + 1, 50, 50, 0xFF222222);
+	if (itemCount > 0)
+	{
+		rObj.alphaBild(x + 1, y + 1, 50, 50, *zItem);
+		if (damage < maxDamage)
+		{
+			rObj.fillRegion(x + 1, y + 47, 50, 2, 0xFF000000);
+			rObj.fillRegion(x + 1, y + 47, (int)((damage / maxDamage) * 50), 2, 0xFFFF0000);
+		}
+		if (durability < maxDurability)
+		{
+			rObj.fillRegion(x + 1, y + 49, 50, 2, 0xFF000000);
+			rObj.fillRegion(x + 1, y + 49, (int)((durability / maxDurability) * 50), 2, 0xFF00FF00);
+		}
+		const char* units[] = { "", "K", "M", "G", "T", "P" };
+		int i = 0;
+		for (; i < 6 && itemCount > 1024; i++)
+			itemCount = itemCount / 1024;
+		Text count = itemCount;
+		count += units[i];
+		tr.renderText(x + 45 - tr.getTextBreite(count), y + 45 - tr.getTextHeight(count), count, rObj, 0xFFFFFFFF);
+	}
+}
+
+
+InventoryView::InventoryView(Text id, Either<int, Vec3<int>> target, int rowSize, Text slotNameFilter)
+	: ZeichnungHintergrund(),
+	rowSize(rowSize),
+	target(target),
+	slotNameFilter(slotNameFilter),
+	id(id),
+	slots(0)
+{
+	if (target.isA())
+	{
+		char* msg = new char[id.getLength() + slotNameFilter.getLength() + 3];
+		msg[0] = 100;
+		msg[1] = (char)id.getLength();
+		memcpy(msg + 2, id.getText(), id.getLength());
+		msg[2 + id.getLength()] = (char)slotNameFilter.getLength();
+		memcpy(msg + 3 + id.getLength(), slotNameFilter.getText(), slotNameFilter.getLength());
+		network->zFactoryClient()->entityAPIRequest(target, msg, id.getLength() + slotNameFilter.getLength() + 3);
+		delete[] msg;
+	}
+	setStyle(ZeichnungHintergrund::Style::Sichtbar | ZeichnungHintergrund::Style::Erlaubt);
+}
+
+InventoryView::~InventoryView()
+{
+	if (slots)
+		slots->release();
+}
+
+void InventoryView::api(char* message)
+{
+	switch (message[0])
+	{
+	case 0:
+		// send inventory content
+	{
+		Array<SlotInfo>* slots = new Array<SlotInfo>();
+		int count = *(int*)(++message);
+		for (int i = 0; i < count; i++)
+		{
+			SlotInfo info;
+			info.id = *(int*)(message += 4);
+			info.itemCount = *(int*)(message += 4);
+			if (info.itemCount > 0)
+			{
+				info.damage = *(float*)(message += 4);
+				info.maxDamage = *(float*)(message += 4);
+				info.durability = *(float*)(message += 4);
+				info.maxDurability = *(float*)(message += 4);
+				info.zItem = itemIcons->z(*(int*)(message += 4));
+			}
+			slots->add(info);
+		}
+		postAction([this, slots]()
+			{
+				if (this->slots)
+					this->slots->release();
+				this->slots = slots;
+			});
+	}
+	}
+}
+
+bool InventoryView::tick(double tickVal)
+{
+	return ZeichnungHintergrund::tick(tickVal);
+}
+
+void InventoryView::render(Bild& rObj)
+{
+	ZeichnungHintergrund::render(rObj);
+	if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y))
+		return;
+	if (slots)
+	{
+		int x = 0;
+		int y = 0;
+		int rowCount = 0;
+		for (SlotInfo info : *slots)
+		{
+			info.render(x, y, rObj);
+			x += 60;
+			if (++rowCount >= rowSize)
+			{
+				y += 60;
+				x = 0;
+				rowCount = 0;
+			}
+		}
+	}
+	rObj.releaseDrawOptions();
+}
+
+void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
+{
+	ZeichnungHintergrund::doMausEreignis(me, userRet);
+}

+ 50 - 0
FactoryCraft/InventoryView.h

@@ -0,0 +1,50 @@
+#pragma once
+
+#include <UIMLView.h>
+#include <Either.h>
+
+#include "NetworkAPIProcessor.h"
+
+class InventoryElement : public Framework::UIMLElement
+{
+public:
+	InventoryElement();
+	//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+	bool isApplicableFor(Framework::XML::Element& element) override;
+	//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+	Framework::Zeichnung* parseElement(Framework::XML::Element& element, Framework::UIMLContainer& generalFactory) override;
+	//! wendet die layout parameter zu einer Zeichnung an
+	void layout(Framework::XML::Element& element, Framework::Zeichnung& z, int pWidth, int pHeight, Framework::UIMLContainer& generalLayouter) override;
+};
+
+struct SlotInfo
+{
+	int id;
+	int itemCount;
+	float damage;
+	float maxDamage;
+	float durability;
+	float maxDurability;
+	Framework::Bild* zItem;
+
+	void render(int x, int y, Framework::Bild& rObj);
+};
+
+class InventoryView : public Framework::ZeichnungHintergrund, public NetworkAPIProcessor
+{
+private:
+	int rowSize;
+	// entity id or block position
+	Framework::Either<int, Framework::Vec3<int>> target;
+	Framework::Text slotNameFilter;
+	Framework::Text id;
+	Framework::Array<SlotInfo>* slots;
+
+public:
+	InventoryView(Framework::Text id, Framework::Either<int, Framework::Vec3<int>> target, int rowSize, Framework::Text slotNameFilter);
+	~InventoryView();
+	void api(char* message) override;
+	bool tick(double tickVal) override;
+	void render(Framework::Bild& rObj) override;
+	void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+};

+ 64 - 54
FactoryCraft/Inventoty.cpp

@@ -6,69 +6,79 @@
 using namespace Framework;
 
 
-Inventory::Inventory( const Framework::Vec3<float> location, bool hasInventory )
-    : ReferenceCounter(),
-    location( location )
+Inventory::Inventory(const Framework::Vec3<float> location, bool hasInventory)
+	: ReferenceCounter(),
+	location(location)
 {
-    if( hasInventory )
-    {
-        pullSlotsOrder = new Framework::RCArray<ItemSlot>();
-        pushSlotsOrder = new Framework::RCArray<ItemSlot>();
-    }
-    else
-    {
-        pullSlotsOrder = 0;
-        pushSlotsOrder = 0;
-    }
+	if (hasInventory)
+	{
+		pullSlotsOrder = new Framework::RCArray<ItemSlot>();
+		pushSlotsOrder = new Framework::RCArray<ItemSlot>();
+	}
+	else
+	{
+		pullSlotsOrder = 0;
+		pushSlotsOrder = 0;
+	}
 }
 
 Inventory::~Inventory()
 {
-    if( pullSlotsOrder )
-        pullSlotsOrder->release();
-    if( pushSlotsOrder )
-        pushSlotsOrder->release();
+	if (pullSlotsOrder)
+		pullSlotsOrder->release();
+	if (pushSlotsOrder)
+		pushSlotsOrder->release();
 }
 
-void Inventory::loadInventory( Framework::StreamReader* zReader )
+void Inventory::loadInventory(Framework::StreamReader* zReader)
 {
-    if( pushSlotsOrder )
-    {
-        for( auto slot : *pushSlotsOrder )
-        {
-            int size = 0;
-            zReader->lese( (char*)&size, 4 );
-            if( size != 0 )
-            {
-                int id = 0;
-                zReader->lese( (char*)&id, 4 );
-                Item* item = STATIC_REGISTRY( ItemType ).zElement( id )->loadItem( zReader );
-                slot->setItems( new ItemStack( item, size ) );
-            }
-            else
-                slot->setItems( 0 );
-        }
-    }
+	if (pushSlotsOrder)
+	{
+		for (auto slot : *pushSlotsOrder)
+		{
+			int size = 0;
+			zReader->lese((char*)&size, 4);
+			if (size != 0)
+			{
+				int id = 0;
+				zReader->lese((char*)&id, 4);
+				Item* item = STATIC_REGISTRY(ItemType).zElement(id)->loadItem(zReader);
+				slot->setItems(new ItemStack(item, size));
+			}
+			else
+				slot->setItems(0);
+		}
+	}
 }
 
-void Inventory::addSlot( ItemSlot* slot )
+void Inventory::addSlot(ItemSlot* slot)
 {
-    int pullPrio = slot->getPullPriority();
-    int pushPrio = slot->getPushPriority();
-    int index = 0;
-    for( auto stack : *pullSlotsOrder )
-    {
-        if( stack->getPullPriority() > pullPrio )
-            break;
-        index++;
-    }
-    pullSlotsOrder->add( dynamic_cast<ItemSlot*>(slot->getThis()), index );
-    index = 0;
-    for( auto stack : *pushSlotsOrder )
-    {
-        if( stack->getPushPriority() > pushPrio )
-            break;
-        index++;
-    }
-    pushSlotsOrder->add( slot, index );
+	int pullPrio = slot->getPullPriority();
+	int pushPrio = slot->getPushPriority();
+	int index = 0;
+	for (auto stack : *pullSlotsOrder)
+	{
+		if (stack->getPullPriority() > pullPrio)
+			break;
+		index++;
+	}
+	pullSlotsOrder->add(dynamic_cast<ItemSlot*>(slot->getThis()), index);
+	index = 0;
+	for (auto stack : *pushSlotsOrder)
+	{
+		if (stack->getPushPriority() > pushPrio)
+			break;
+		index++;
+	}
+	pushSlotsOrder->add(slot, index);
+}
+
+Framework::Iterator<ItemSlot*> Inventory::begin()
+{
+	return pullSlotsOrder->begin();
+}
+
+Framework::Iterator<ItemSlot*> Inventory::end()
+{
+	return pullSlotsOrder->end();
 }

+ 16 - 16
FactoryCraft/ItemEntity.cpp

@@ -4,32 +4,32 @@
 
 
 ItemEntity::ItemEntity()
-    : Entity( ItemEntityType::INSTANCE, 1 )
+	: Entity(ItemEntityType::INSTANCE, 1)
 {
-    slot = new ItemSlot( INT_MAX, 0, 0, 0, ANY_DIRECTION, 0 );
-    addSlot( slot );
-    currentGame->setVisibility( this, 1 );
-    // TODO: initialize model3d
+	slot = new ItemSlot("", INT_MAX, 0, 0, 0, ANY_DIRECTION, 0);
+	addSlot(slot);
+	currentGame->setVisibility(this, 1);
+	// TODO: initialize model3d
 }
 
-bool ItemEntity::tick( double time )
+bool ItemEntity::tick(double time)
 {
-    lock();
-    if( !model && slot->zStack() )
-    {
-        setModelDaten( slot->zStack()->zItem()->zItemType()->getItemModel() );
-        textur = slot->zStack()->zItem()->zItemType()->getItemTextur();
-    }
-    unlock();
-    return Entity::tick( time );
+	lock();
+	if (!model && slot->zStack())
+	{
+		setModelDaten(slot->zStack()->zItem()->zItemType()->getItemModel());
+		textur = slot->zStack()->zItem()->zItemType()->getItemTextur();
+	}
+	unlock();
+	return Entity::tick(time);
 }
 
 
 ItemEntityType::ItemEntityType()
-    : EntityType( ID )
+	: EntityType(ID)
 {}
 
 Entity* ItemEntityType::createEntity() const
 {
-    return new ItemEntity();
+	return new ItemEntity();
 }

+ 8 - 2
FactoryCraft/ItemSlot.cpp

@@ -1,7 +1,7 @@
 #include "ItemSlot.h"
 
 
-ItemSlot::ItemSlot( int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize )
+ItemSlot::ItemSlot(Framework::Text name, int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize )
     : ReferenceCounter(),
     items( 0 ),
     maxSize( maxSize ),
@@ -9,7 +9,8 @@ ItemSlot::ItemSlot( int maxSize, int pullPriority, int pushPriority, int allowed
     allowedPushSides( allowedPushSides ),
     pullPriority( pullPriority ),
     pushPriority( pushPriority ),
-    allowHigherStackSize( allowHigherStackSize )
+    allowHigherStackSize( allowHigherStackSize ),
+    name(name)
 {}
 
 ItemSlot::~ItemSlot()
@@ -38,4 +39,9 @@ int ItemSlot::getPushPriority() const
 ItemStack* ItemSlot::zStack() const
 {
     return items;
+}
+
+const Framework::Text& ItemSlot::getName() const
+{
+    return name;
 }

+ 15 - 13
FactoryCraft/ItemSlot.h

@@ -6,20 +6,22 @@
 class ItemSlot : public virtual Framework::ReferenceCounter
 {
 private:
-    ItemStack* items;
-    int maxSize;
-    Directions allowedPullSide;
-    Directions allowedPushSides;
-    int pullPriority;
-    int pushPriority;
-    bool allowHigherStackSize;
+	ItemStack* items;
+	int maxSize;
+	Directions allowedPullSide;
+	Directions allowedPushSides;
+	int pullPriority;
+	int pushPriority;
+	bool allowHigherStackSize;
+	Framework::Text name;
 
 public:
-    ItemSlot( int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize );
-    ~ItemSlot();
+	ItemSlot(Framework::Text name, int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize);
+	~ItemSlot();
 
-    void setItems( ItemStack* item );
-    int getPullPriority() const;
-    int getPushPriority() const;
-    ItemStack* zStack() const;
+	void setItems(ItemStack* item);
+	int getPullPriority() const;
+	int getPushPriority() const;
+	ItemStack* zStack() const;
+	const Framework::Text& getName() const;
 };

+ 7 - 0
FactoryCraft/NetworkAPIProcessor.h

@@ -0,0 +1,7 @@
+#pragma once
+
+class NetworkAPIProcessor
+{
+public:
+	virtual void api(char* message) = 0;
+};

+ 75 - 64
FactoryCraft/Player.cpp

@@ -1,91 +1,102 @@
+#include <Bild.h>
+
 #include "Player.h"
 #include "Area.h"
 #include "Globals.h"
 #include "Menu.h"
 #include "Game.h"
-#include <Bild.h>
 
 
 Player::Player()
-    : Entity( PlayerEntityType::INSTANCE, 1 ),
-    leftHandPosition( 0 )
+	: Entity(PlayerEntityType::INSTANCE, 1),
+	leftHandPosition(0)
 {
-    setModelDaten( uiFactory.initParam.bildschirm->zGraphicsApi()->getModel( "player" ) );
-    Bild* b = new Bild();
-    b->neuBild( 10, 10, 0xFFFFFFFF );
-    Textur* tex = uiFactory.initParam.bildschirm->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 );
-        itemBar.add( slot );
-        addSlot( slot );
-    }
-    currentGame->setVisibility( this, 1 );
+	setModelDaten(uiFactory.initParam.bildschirm->zGraphicsApi()->getModel("player"));
+	Bild* b = new Bild();
+	b->neuBild(10, 10, 0xFFFFFFFF);
+	Textur* tex = uiFactory.initParam.bildschirm->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("Crafting", 1, INT_MAX, INT_MAX, INSIDE, INSIDE, 0);
+		addSlot(slot);
+	}
+	for (int i = 0; i < 10; i++)
+	{
+		ItemSlot* slot = new ItemSlot("ItemBar", 50, 0, i, 0, ANY_DIRECTION, 0);
+		itemBar.add(slot);
+		addSlot(slot);
+	}
+	for (int i = 0; i < 30; i++)
+	{
+		ItemSlot* slot = new ItemSlot("Inventory", 50, 0, i + 10, 0, ANY_DIRECTION, 0);
+		addSlot(slot);
+	}
+	currentGame->setVisibility(this, 1);
 }
 
 Player::~Player()
 {}
 
-bool Player::tick( double time )
+bool Player::tick(double time)
 {
-    cs.lock();
-    if( currentGame->getCurrentPlayerId() == id )
-    {
-        currentGame->zKamera()->setPosition( pos + Vec3<float>( 0.f, 0.f, 1.5f ) );
-        if( target )
-        {
-            auto t = target->getTarget( currentDimensionId );
-            if( t.isA() && t.getA() )
-                currentGame->setTarget( t.getA() );
-            if( t.isB() && t.getB() )
-                currentGame->setTarget( t.getB() );
-            if( (t.isA() && t.getA()) || (t.isB() && t.getB()) )
-                ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, 1, t.isA() ? t.getA()->getPos() : t.getB()->getPos() );
-            else
-                ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, 0, { 0, 0, 0 } );
-            if( t.isA() && t.getA() )
-                t.getA()->release();
-            if( t.isB() && t.getB() )
-                t.getB()->release();
-        }
-        else
-        {
-            currentGame->setTarget( 0 );
-            ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, 0, { 0, 0, 0 } );
-        }
-        ((Game*)(Menu*)menuRegister->get( "game" ))->updateInventory( itemBar, leftHandPosition );
-    }
-    cs.unlock();
-    return Entity::tick( time );
+	cs.lock();
+	if (currentGame->getCurrentPlayerId() == id)
+	{
+		currentGame->zKamera()->setPosition(pos + Vec3<float>(0.f, 0.f, 1.5f));
+		if (target)
+		{
+			auto t = target->getTarget(currentDimensionId);
+			if (t.isA() && t.getA())
+				currentGame->setTarget(t.getA());
+			if (t.isB() && t.getB())
+				currentGame->setTarget(t.getB());
+			if ((t.isA() && t.getA()) || (t.isB() && t.getB()))
+				((Game*)(Menu*)menuRegister->get("game"))->updatePosition(pos, 1, t.isA() ? t.getA()->getPos() : t.getB()->getPos());
+			else
+				((Game*)(Menu*)menuRegister->get("game"))->updatePosition(pos, 0, { 0, 0, 0 });
+			if (t.isA() && t.getA())
+				t.getA()->release();
+			if (t.isB() && t.getB())
+				t.getB()->release();
+		}
+		else
+		{
+			currentGame->setTarget(0);
+			((Game*)(Menu*)menuRegister->get("game"))->updatePosition(pos, 0, { 0, 0, 0 });
+		}
+		((Game*)(Menu*)menuRegister->get("game"))->updateInventory(itemBar, leftHandPosition);
+	}
+	cs.unlock();
+	return Entity::tick(time);
 }
 
 
 PlayerEntityType::PlayerEntityType()
-    : EntityType( ID )
+	: EntityType(ID)
 {}
 
-void PlayerEntityType::loadSuperEntity( Entity* zEntity, Framework::StreamReader* zReader ) const
+void PlayerEntityType::loadSuperEntity(Entity* zEntity, Framework::StreamReader* zReader) const
 {
-    Player* zPlayer = dynamic_cast<Player*>(zEntity);
-    if( !zPlayer )
-        throw "PlayerEntityType::loadSuperEntity was called with an entity witch is not an instance of Player";
-    zReader->lese( (char*)&zPlayer->leftHandPosition, 4 );
-    EntityType::loadSuperEntity( zEntity, zReader );
+	Player* zPlayer = dynamic_cast<Player*>(zEntity);
+	if (!zPlayer)
+		throw "PlayerEntityType::loadSuperEntity was called with an entity witch is not an instance of Player";
+	zReader->lese((char*)&zPlayer->leftHandPosition, 4);
+	EntityType::loadSuperEntity(zEntity, zReader);
 }
 
 Entity* PlayerEntityType::createEntity() const
 {
-    return new Player();
+	return new Player();
 }

+ 198 - 192
FactoryCraft/PlayerKam.cpp

@@ -1,211 +1,217 @@
 #include "PlayerKam.h"
 #include "Globals.h"
+#include "Game.h"
 
-PlayerKam::PlayerKam( Framework::Bildschirm3D* zScreen )
-    : Kam3D()
+PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
+	: Kam3D()
 {
-    kameraControll = 0;
-    setBildschirmPosition( 0, 0 );
-    setBildschirmSize( zScreen->getBackBufferSize() );
-    setStyle( Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable );
-    setRotation( { (float)PI / 2.f, 0, 0 } );
+	kameraControll = 0;
+	setBildschirmPosition(0, 0);
+	setBildschirmSize(zScreen->getBackBufferSize());
+	setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
+	setRotation({ (float)PI / 2.f, 0, 0 });
 }
 
-void PlayerKam::setDirection( Framework::Vec3<float> direction )
+void PlayerKam::setDirection(Framework::Vec3<float> direction)
 {
-    if( direction.getLengthSq() > 0 )
-    {
-        float rotZ = std::atan2( direction.y, direction.x ) + (float)PI / 2;
-        setRotation( { getRotation().x, getRotation().y, rotZ } );
-    }
+	if (direction.getLengthSq() > 0)
+	{
+		float rotZ = std::atan2(direction.y, direction.x) + (float)PI / 2;
+		setRotation({ getRotation().x, getRotation().y, rotZ });
+	}
 }
 
-void PlayerKam::doTastaturEreignis( Framework::TastaturEreignis& te )
+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.taste >= '0' && te.taste <= '9' )
-        {
-            char action[ 5 ];
-            action[ 0 ] = 3;
-            *(int*)(action + 1) = te.taste - '1';
-            if( *(int*)(action + 1) < 0 )
-                *(int*)(action + 1) = 9;
-            network->zFactoryClient()->sendPlayerAction( &action, 5 );
-        }
-    }
-    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 );
-        }
-        if( te.taste == T_Esc )
-        {
-            kameraControll = 0;
-            ShowCursor( true );
-        }
-    }
+	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.taste >= '0' && te.taste <= '9')
+		{
+			char action[5];
+			action[0] = 3;
+			*(int*)(action + 1) = te.taste - '1';
+			if (*(int*)(action + 1) < 0)
+				*(int*)(action + 1) = 9;
+			network->zFactoryClient()->sendPlayerAction(action, 5);
+		}
+	}
+	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);
+		}
+		if (te.taste == T_Esc)
+		{
+			kameraControll = 0;
+			ShowCursor(true);
+		}
+		if (te.taste == T_Tab)
+		{
+			action[0] = 4;
+			network->zFactoryClient()->sendPlayerAction(action, 1);
+		}
+	}
 }
 
-void PlayerKam::doMausEreignis( Framework::MausEreignis& me )
+void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
 {
-    if( me.verarbeitet )
-    {
-        kameraControll = 0;
-        ShowCursor( true );
-    }
-    else
-    {
-        if( !kameraControll )
-        {
-            if( me.id == ME_PLinks )
-            {
-                lastMousePos = { me.originalX, me.originalY };
-                kameraControll = 1;
-            }
-        }
-        else
-        {
-            if( kameraControll )
-            {
-                if( me.id == ME_Bewegung )
-                {
-                    int yDir = lastMousePos.y - me.originalY;
-                    int xDir = lastMousePos.x - me.originalX;
-                    setRotation( { min( max( getRotation().x - yDir * 0.005f, 0.1f ), 2.5f ), getRotation().y, getRotation().z - xDir * 0.005f } );
-                    if( getRotation().z > 2 * PI )
-                        setRotation( { getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI } );
-                    if( getRotation().z < -2 * PI )
-                        setRotation( { getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI } );
-                    Vec3<float> direction = getWorldDirection( getScreenPos() + getScreenSize() / 2 );
-                    char action[ 13 ];
-                    action[ 0 ] = 2;
-                    *(float*)(action + 1) = direction.x;
-                    *(float*)(action + 5) = direction.y;
-                    *(float*)(action + 9) = direction.z;
-                    network->zFactoryClient()->sendPlayerAction( action, 13 );
-                    SetCursorPos( lastMousePos.x + window->getPosition().x, lastMousePos.y + window->getPosition().y );
-                    ShowCursor( false );
-                }
-                if( me.id == ME_PLinks )
-                {
-                    char action[ 2 ] = { 1, 8 };
-                    network->zFactoryClient()->sendPlayerAction( action, 2 );
+	if (me.verarbeitet)
+	{
+		kameraControll = 0;
+		ShowCursor(true);
+	}
+	else
+	{
+		if (!kameraControll)
+		{
+			if (me.id == ME_PLinks)
+			{
+				lastMousePos = { me.originalX, me.originalY };
+				kameraControll = 1;
+			}
+		}
+		else
+		{
+			if (kameraControll)
+			{
+				if (me.id == ME_Bewegung)
+				{
+					int yDir = lastMousePos.y - me.originalY;
+					int xDir = lastMousePos.x - me.originalX;
+					setRotation({ min(max(getRotation().x - yDir * 0.005f, 0.1f), 2.5f), getRotation().y, getRotation().z - xDir * 0.005f });
+					if (getRotation().z > 2 * PI)
+						setRotation({ getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI });
+					if (getRotation().z < -2 * PI)
+						setRotation({ getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI });
+					Vec3<float> direction = getWorldDirection(getScreenPos() + getScreenSize() / 2);
+					char action[13];
+					action[0] = 2;
+					*(float*)(action + 1) = direction.x;
+					*(float*)(action + 5) = direction.y;
+					*(float*)(action + 9) = direction.z;
+					network->zFactoryClient()->sendPlayerAction(action, 13);
+					SetCursorPos(lastMousePos.x + window->getPosition().x, lastMousePos.y + window->getPosition().y);
+					ShowCursor(false);
+				}
+				if (me.id == ME_PLinks)
+				{
+					char action[2] = { 1, 8 };
+					network->zFactoryClient()->sendPlayerAction(action, 2);
 
-                }
-                if( me.id == ME_RLinks )
-                {
-                    char action[ 2 ] = { 0, 8 };
-                    network->zFactoryClient()->sendPlayerAction( action, 2 );
-                }
-                if( me.id == ME_PRechts )
-                {
-                    char action[ 2 ] = { 1, 9 };
-                    network->zFactoryClient()->sendPlayerAction( action, 2 );
-                }
-                if( me.id == ME_RRechts )
-                {
-                    char action[ 2 ] = { 0, 9 };
-                    network->zFactoryClient()->sendPlayerAction( action, 2 );
-                }
-            }
+				}
+				if (me.id == ME_RLinks)
+				{
+					char action[2] = { 0, 8 };
+					network->zFactoryClient()->sendPlayerAction(action, 2);
+				}
+				if (me.id == ME_PRechts)
+				{
+					char action[2] = { 1, 9 };
+					network->zFactoryClient()->sendPlayerAction(action, 2);
+				}
+				if (me.id == ME_RRechts)
+				{
+					char action[2] = { 0, 9 };
+					network->zFactoryClient()->sendPlayerAction(action, 2);
+				}
+			}
 
-        }
-        me.verarbeitet = 1;
-    }
+		}
+		me.verarbeitet = 1;
+	}
 }
 
-bool PlayerKam::tick( double time )
+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;
+	__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;
 }

+ 197 - 177
FactoryCraft/World.cpp

@@ -15,249 +15,269 @@ using namespace Network;
 using namespace Framework;
 
 
-World::World( Bildschirm3D* zScreen )
-    : Thread()
+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 PlayerKam( zScreen );
-    kam->setWelt( renderedWorld );
-    zScreen->addKamera( kam );
-    firstMessage = 1;
-    hasTarget = 0;
-    entityTarget = -1;
-    ownEntityId = -1;
-    currentTarget = 0;
-    start();
+	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>();
+	zScreenPtr = zScreen;
+	kam = new PlayerKam(zScreen);
+	kam->setWelt(renderedWorld);
+	zScreen->addKamera(kam);
+	firstMessage = 1;
+	hasTarget = 0;
+	entityTarget = -1;
+	ownEntityId = -1;
+	currentTarget = 0;
+	start();
 }
 
 World::~World()
 {
-    zScreenPtr->removeKamera( kam );
-    dimensions->release();
-    currentPlayer->release();
-    if( currentTarget )
-        currentTarget->release();
+	zScreenPtr->removeKamera(kam);
+	dimensions->release();
+	if (currentTarget)
+		currentTarget->release();
 }
 
-void World::update( bool background )
+void World::update(bool background)
 {
-    NetworkReader* serverMessageReader = 0;
-    unsigned char type = 0;
-    while( background ? serverMessageReader = network->zFactoryClient()->getNextBackgroundMessage() : serverMessageReader = network->zFactoryClient()->getNextForegroundMessage() )
-    {
-        serverMessageReader->lese( (char*)&type, 1 );
-        if( type == 2 ) // WORLD UPDATE
-        {
-            int id = 0;
-            serverMessageReader->lese( (char*)&id, 4 );
-            STATIC_REGISTRY( WorldUpdateType ).zElement( id )->applyUpdateAndCheck( serverMessageReader );
-        }
-        if( type == 3 ) // API MESSAGE
-        {
-            // TODO: process messages
-        }
-        if( type == 4 ) // POSITION UPDATE
-        {
-            serverMessageReader->lese( (char*)&ownEntityId, 4 );
-        }
-        network->zFactoryClient()->endMessageReading( background );
-    }
-    network->zFactoryClient()->endMessageReading( background );
-    Entity* player = getCurrentPlayerEntity();
-    if( player )
-    {
-        renderedWorld->lock();
-        for( Dimension* dim : *dimensions )
-            dim->removeDistantChunks( { (int)player->getPos().x, (int)player->getPos().y }, this );
-        renderedWorld->unlock();
-    }
+	NetworkReader* serverMessageReader = 0;
+	unsigned char type = 0;
+	while (background ? serverMessageReader = network->zFactoryClient()->getNextBackgroundMessage() : serverMessageReader = network->zFactoryClient()->getNextForegroundMessage())
+	{
+		serverMessageReader->lese((char*)&type, 1);
+		if (type == 2) // WORLD UPDATE
+		{
+			int id = 0;
+			serverMessageReader->lese((char*)&id, 4);
+			STATIC_REGISTRY(WorldUpdateType).zElement(id)->applyUpdateAndCheck(serverMessageReader);
+		}
+		if (type == 3) // API MESSAGE
+		{
+			int length;
+			serverMessageReader->lese((char*)&length, 4);
+			char* data = new char[length];
+			serverMessageReader->lese(data, length);
+			switch (data[0])
+			{
+			case 1: // dimension message
+			{
+				int dimId = *(int*)(data + 1);
+				Dimension* dim = zDimension(dimId);
+				if (dim)
+					dim->api(data + 5);
+				break;
+			}
+			case 2: // gui message
+				((Game*)(Menu*)menuRegister->get("game"))->api(data + 1);
+				break;
+			}
+			delete[] data;
+			// TODO: process messages
+		}
+		if (type == 4) // POSITION UPDATE
+		{
+			serverMessageReader->lese((char*)&ownEntityId, 4);
+		}
+		network->zFactoryClient()->endMessageReading(background);
+	}
+	network->zFactoryClient()->endMessageReading(background);
+	Entity* player = getCurrentPlayerEntity();
+	if (player)
+	{
+		renderedWorld->lock();
+		for (Dimension* dim : *dimensions)
+			dim->removeDistantChunks({ (int)player->getPos().x, (int)player->getPos().y }, this);
+		renderedWorld->unlock();
+	}
 }
 
-void World::setChunk( Chunk* chunk, int dimensionId )
+void World::setChunk(Chunk* chunk, int dimensionId)
 {
-    zScreenPtr->lock();
-    Dimension* zDim = zDimension( dimensionId );
-    if( !zDim )
-    {
-        zDim = new Dimension( dimensionId );
-        dimensions->add( zDim );
-    }
-    zDim->setChunk( chunk, chunk->getCenter(), this );
-    zScreenPtr->unlock();
+	zScreenPtr->lock();
+	renderedWorld->lock();
+	Dimension* zDim = zDimension(dimensionId);
+	if (!zDim)
+	{
+		zDim = new Dimension(dimensionId);
+		dimensions->add(zDim);
+	}
+	zDim->setChunk(chunk, chunk->getCenter(), this);
+	renderedWorld->unlock();
+	zScreenPtr->unlock();
 }
 
 void World::thread()
 {
-    new AsynchronCall( "World Update", [this]() {
-        while( true )
-        {
-            zScreenPtr->lock();
-            if( currentGame != this )
-            {
-                zScreenPtr->unlock();
-                return;
-            }
-            zScreenPtr->unlock();
-            update( 0 );
-            Sleep( 10 );
-        }
-    } );
-    while( true )
-    {
-        zScreenPtr->lock();
-        if( currentGame != this )
-        {
-            zScreenPtr->unlock();
-            return;
-        }
-        zScreenPtr->unlock();
-        update( 1 );
-        Sleep( 10 );
-    }
+	new AsynchronCall("World Update", [this]()
+		{
+			while (true)
+			{
+				zScreenPtr->lock();
+				if (currentGame != this)
+				{
+					zScreenPtr->unlock();
+					return;
+				}
+				zScreenPtr->unlock();
+				update(0);
+				Sleep(10);
+			}
+		});
+	while (true)
+	{
+		zScreenPtr->lock();
+		if (currentGame != this)
+		{
+			zScreenPtr->unlock();
+			return;
+		}
+		zScreenPtr->unlock();
+		update(1);
+		Sleep(10);
+	}
 }
 
-Block* World::zBlockAt( Framework::Vec3<int> location, int dimension ) const
+Block* World::zBlockAt(Framework::Vec3<int> location, int dimension) const
 {
-    Dimension* dim = zDimension( dimension );
-    if( dim )
-        return dim->zBlock( location );
-    return 0;
+	Dimension* dim = zDimension(dimension);
+	if (dim)
+		return dim->zBlock(location);
+	return 0;
 }
 
-Block* World::getBlockAt( Framework::Vec3<int> location, int dimension ) const
+Block* World::getBlockAt(Framework::Vec3<int> location, int dimension) const
 {
-    Dimension* dim = zDimension( dimension );
-    if( dim )
-        return dim->getBlock( location );
-    return 0;
+	Dimension* dim = zDimension(dimension);
+	if (dim)
+		return dim->getBlock(location);
+	return 0;
 }
 
-Dimension* World::zDimension( int id ) const
+Dimension* World::zDimension(int id) const
 {
-    for( auto dim : *dimensions )
-    {
-        if( dim->getDimensionId() == id )
-            return dim;
-    }
-    return 0;
+	for (auto dim : *dimensions)
+	{
+		if (dim->getDimensionId() == id)
+			return dim;
+	}
+	return 0;
 }
 
-Dimension* World::zDimensionOrCreate( int id )
+Dimension* World::zDimensionOrCreate(int id)
 {
-    zScreenPtr->lock();
-    Dimension* d = zDimension( id );
-    if( !d )
-    {
-        d = new Dimension( id );
-        dimensions->add( d );
-    }
-    zScreenPtr->unlock();
-    return d;
+	zScreenPtr->lock();
+	Dimension* d = zDimension(id);
+	if (!d)
+	{
+		d = new Dimension(id);
+		dimensions->add(d);
+	}
+	zScreenPtr->unlock();
+	return d;
 }
 
-void World::setVisibility( Chunk* zChunk, bool visible )
+void World::setVisibility(Chunk* zChunk, bool visible)
 {
-    renderedWorld->lock();
-    if( visible )
-        renderedWorld->addCollection( dynamic_cast<Framework::Model3DCollection*>(zChunk->getThis()) );
-    else
-        renderedWorld->removeCollection( zChunk );
-    renderedWorld->unlock();
+	renderedWorld->lock();
+	if (visible)
+		renderedWorld->addCollection(dynamic_cast<Framework::Model3DCollection*>(zChunk->getThis()));
+	else
+		renderedWorld->removeCollection(zChunk);
+	renderedWorld->unlock();
 }
 
-void World::setVisibility( Entity* zEntity, bool visible )
+void World::setVisibility(Entity* zEntity, bool visible)
 {
-    renderedWorld->lock();
-    if( visible )
-        renderedWorld->addZeichnung( dynamic_cast<Framework::Model3D*>(zEntity->getThis()) );
-    else
-        renderedWorld->removeZeichnung( zEntity );
-    renderedWorld->unlock();
+	renderedWorld->lock();
+	if (visible)
+		renderedWorld->addZeichnung(dynamic_cast<Framework::Model3D*>(zEntity->getThis()));
+	else
+		renderedWorld->removeZeichnung(zEntity);
+	renderedWorld->unlock();
 }
 
-Framework::Punkt World::getChunkCenter( int x, int y ) const
+Framework::Punkt World::getChunkCenter(int x, int y) const
 {
-    return Punkt( ((x < 0 ? x + 1 : x) / CHUNK_SIZE) * CHUNK_SIZE + (x < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2, ((y < 0 ? y + 1 : y) / CHUNK_SIZE) * CHUNK_SIZE + (y < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2 );
+	return Punkt(((x < 0 ? x + 1 : x) / CHUNK_SIZE) * CHUNK_SIZE + (x < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2, ((y < 0 ? y + 1 : y) / CHUNK_SIZE) * CHUNK_SIZE + (y < 0 ? -CHUNK_SIZE : CHUNK_SIZE) / 2);
 }
 
-Entity* World::zEntity( int id ) const
+Entity* World::zEntity(int id) const
 {
-    for( Dimension* d : *dimensions )
-    {
-        Entity* e = d->zEntity( id );
-        if( e )
-            return e;
-    }
-    return 0;
+	for (Dimension* d : *dimensions)
+	{
+		Entity* e = d->zEntity(id);
+		if (e)
+			return e;
+	}
+	return 0;
 }
 
-Entity* World::getEntity( int id ) const
+Entity* World::getEntity(int id) const
 {
-    for( Dimension* d : *dimensions )
-    {
-        Entity* e = d->getEntity( id );
-        if( e )
-            return e;
-    }
-    return 0;
+	for (Dimension* d : *dimensions)
+	{
+		Entity* e = d->getEntity(id);
+		if (e)
+			return e;
+	}
+	return 0;
 }
 
-void World::removeEntity( int id )
+void World::removeEntity(int id)
 {
-    for( Dimension* d : *dimensions )
-        d->removeEntity( id );
+	for (Dimension* d : *dimensions)
+		d->removeEntity(id);
 }
 
 PlayerKam* World::zKamera() const
 {
-    return kam;
+	return kam;
 }
 
 int World::getCurrentPlayerId() const
 {
-    return ownEntityId;
+	return ownEntityId;
 }
 
 Entity* World::getCurrentPlayerEntity() const
 {
-    for( Dimension* d : *dimensions )
-    {
-        Entity* e = d->zEntity( ownEntityId );
-        if( e )
-            return e;
-    }
-    return 0;
+	for (Dimension* d : *dimensions)
+	{
+		Entity* e = d->zEntity(ownEntityId);
+		if (e)
+			return e;
+	}
+	return 0;
 }
 
-void World::setTarget( Framework::Model3D* zTarget )
+void World::setTarget(Framework::Model3D* zTarget)
 {
-    if( zTarget != currentTarget )
-    {
-        if( currentTarget )
-        {
-            currentTarget->setAmbientFactor( currentTarget->getAmbientFactor() - 0.2f );
-            currentTarget->release();
-            currentTarget = 0;
-        }
-        if( zTarget )
-        {
-            currentTarget = dynamic_cast<Framework::Model3D*>(zTarget->getThis());
-            if( currentTarget )
-                currentTarget->setAmbientFactor( currentTarget->getAmbientFactor() + 0.2f );
-        }
-    }
+	if (zTarget != currentTarget)
+	{
+		if (currentTarget)
+		{
+			currentTarget->setAmbientFactor(currentTarget->getAmbientFactor() - 0.2f);
+			currentTarget->release();
+			currentTarget = 0;
+		}
+		if (zTarget)
+		{
+			currentTarget = dynamic_cast<Framework::Model3D*>(zTarget->getThis());
+			if (currentTarget)
+				currentTarget->setAmbientFactor(currentTarget->getAmbientFactor() + 0.2f);
+		}
+	}
 }
 
 void World::lockWorld()
 {
-    renderedWorld->lock();
+	renderedWorld->lock();
 }
 
 void World::unlockWorld()
 {
-    renderedWorld->unlock();
+	renderedWorld->unlock();
 }

+ 31 - 33
FactoryCraft/World.h

@@ -6,45 +6,43 @@
 #include <Thread.h>
 
 #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;
-    PlayerKam* kam;
-    Framework::Vec3<int> target;
-    int entityTarget;
-    bool hasTarget;
-    bool firstMessage;
-    int ownEntityId;
-    Framework::Model3D* currentTarget;
+	Framework::RCArray<Dimension>* dimensions;
+	Framework::Welt3D* renderedWorld;
+	Framework::Bildschirm3D* zScreenPtr;
+	PlayerKam* kam;
+	Framework::Vec3<int> target;
+	int entityTarget;
+	bool hasTarget;
+	bool firstMessage;
+	int ownEntityId;
+	Framework::Model3D* currentTarget;
 
 public:
-    World( Framework::Bildschirm3D* zScreen );
-    ~World();
-    void update( bool background );
-    void setChunk( Chunk* chunk, int dimensionId );
-    void thread() override;
+	World(Framework::Bildschirm3D* zScreen);
+	~World();
+	void update(bool background);
+	void setChunk(Chunk* chunk, int dimensionId);
+	void thread() override;
 
-    Block* zBlockAt( Framework::Vec3<int> location, int dimension ) const;
-    Block* getBlockAt( Framework::Vec3<int> location, int dimension ) const;
-    Dimension* zDimension( int id ) const;
-    Dimension* zDimensionOrCreate( int id );
-    void setVisibility( Chunk* zChunk, bool visible );
-    void setVisibility( Entity* zEntity, bool visible );
-    Framework::Punkt getChunkCenter( int x, int y ) const;
-    Entity* zEntity( int id ) const;
-    Entity* getEntity( int id ) const;
-    void removeEntity( int id );
-    PlayerKam* zKamera() const;
-    int getCurrentPlayerId() const;
-    Entity* getCurrentPlayerEntity() const;
-    void setTarget( Framework::Model3D* zTarget );
-    void lockWorld();
-    void unlockWorld();
+	Block* zBlockAt(Framework::Vec3<int> location, int dimension) const;
+	Block* getBlockAt(Framework::Vec3<int> location, int dimension) const;
+	Dimension* zDimension(int id) const;
+	Dimension* zDimensionOrCreate(int id);
+	void setVisibility(Chunk* zChunk, bool visible);
+	void setVisibility(Entity* zEntity, bool visible);
+	Framework::Punkt getChunkCenter(int x, int y) const;
+	Entity* zEntity(int id) const;
+	Entity* getEntity(int id) const;
+	void removeEntity(int id);
+	PlayerKam* zKamera() const;
+	int getCurrentPlayerId() const;
+	Entity* getCurrentPlayerEntity() const;
+	void setTarget(Framework::Model3D* zTarget);
+	void lockWorld();
+	void unlockWorld();
 };