Преглед на файлове

clients can now subscribe to chunc changes

Kolja Strohm преди 2 години
родител
ревизия
fe130366e6

+ 0 - 38
FactoryCraft/AddChunkUpdate.cpp

@@ -1,38 +0,0 @@
-#include "AddChunkUpdate.h"
-#include "Chunk.h"
-#include "Constants.h"
-#include "Dimension.h"
-
-
-AddChunkUpdate::AddChunkUpdate(Chunk* chunk)
-	: WorldUpdate(AddChunkUpdateType::ID, chunk->getDimensionId(), Framework::Vec3<int>(chunk->getCenter().x - CHUNK_SIZE / 2, chunk->getCenter().y - CHUNK_SIZE / 2, 0), Framework::Vec3<int>(chunk->getCenter().x + CHUNK_SIZE / 2 - 1, chunk->getCenter().y + CHUNK_SIZE / 2 - 1, WORLD_HEIGHT - 1)),
-	chunk(chunk)
-{}
-
-AddChunkUpdate::~AddChunkUpdate()
-{
-	chunk->release();
-}
-
-void AddChunkUpdate::onUpdate(Dimension* zDimension)
-{
-	zDimension->setChunk(dynamic_cast<Chunk*>(chunk->getThis()), chunk->getCenter());
-}
-
-void AddChunkUpdate::write(Framework::StreamWriter* zWriter)
-{
-	Framework::Punkt center = chunk->getCenter();
-	zWriter->schreibe((char*)&center.x, 4);
-	zWriter->schreibe((char*)&center.y, 4);
-	chunk->sendToClient(zWriter);
-}
-
-Chunk* AddChunkUpdate::zChunk() const
-{
-	return chunk;
-}
-
-
-AddChunkUpdateType::AddChunkUpdateType()
-	: WorldUpdateType(ID)
-{}

+ 0 - 31
FactoryCraft/AddChunkUpdate.h

@@ -1,31 +0,0 @@
-#pragma once
-
-#include "WorldUpdate.h"
-
-class Chunk;
-
-class AddChunkUpdate : public WorldUpdate
-{
-private:
-	Chunk* chunk;
-
-protected:
-	void write(Framework::StreamWriter* zWriter) override;
-
-public:
-	AddChunkUpdate(Chunk* chunk);
-	~AddChunkUpdate();
-
-	void onUpdate(Dimension* zDimension) override;
-	Chunk* zChunk() const;
-};
-
-class AddChunkUpdateType : WorldUpdateType
-{
-	REGISTRABLE(AddChunkUpdateType)
-
-protected:
-	AddChunkUpdateType();
-};
-
-REGISTER(AddChunkUpdateType, WorldUpdateType)

+ 1 - 1
FactoryCraft/Block.cpp

@@ -217,7 +217,7 @@ void Block::setHP(float hp)
 	else
 	{
 		NetworkMessage changeMsg;
-		changeMsg.adressBlock(this);
+		changeMsg.addressBlock(this);
 		char msg[5];
 		msg[0] = 0; // hp changed
 		*(float*)(msg + 1) = this->hp;

+ 87 - 51
FactoryCraft/Chunk.cpp

@@ -1,3 +1,5 @@
+#include <InMemoryBuffer.h>
+
 #include "Chunk.h"
 #include "Constants.h"
 #include "Game.h"
@@ -52,9 +54,75 @@ Framework::Either<Block*, int> Chunk::zBlockNeighbor(Framework::Vec3<int> locati
 	return 0;
 }
 
-void Chunk::api(Framework::StreamReader* zRequest, NetworkMessage* zResponse)
+void Chunk::notifyObservers(NetworkMessage& msg)
+{
+	Array<int> remove;
+	int index = 0;
+	for (int id : observers)
+	{
+		Entity* zE = Game::INSTANCE->zEntity(id);
+		if (!zE)
+			remove.add(index, 0);
+		else
+			Game::INSTANCE->sendMessage(&msg, zE);
+		index++;
+	}
+	for (int i : remove)
+		observers.remove(i);
+}
+
+void Chunk::addObserver(Entity* zEntity)
+{
+	for (int id : observers)
+	{
+		if (id == zEntity->getId())
+			return;
+	}
+	observers.add(zEntity->getId());
+	InMemoryBuffer buffer;
+	buffer.schreibe("\4", 1);
+	buffer.schreibe((char*)&location.x, 4);
+	buffer.schreibe((char*)&location.y, 4);
+	sendToClient(&buffer);
+	NetworkMessage msg;
+	msg.addressDimension();
+	char* message = new char[buffer.getSize()];
+	buffer.lese(message, (int)buffer.getSize());
+	msg.setMessage(message, (int)buffer.getSize(), 1);
+	msg.setUseBackground();
+	Game::INSTANCE->sendMessage(&msg, zEntity);
+}
+
+void Chunk::removeObserver(Entity* zEntity)
+{
+	int index = 0;
+	for (int id : observers)
+	{
+		if (id == zEntity->getId())
+		{
+			observers.remove(index);
+			return;
+		}
+		index++;
+	}
+}
+
+void Chunk::api(Framework::StreamReader* zRequest, Entity* zSource)
 {
 	// TODO: answer api messages
+	char type;
+	zRequest->lese(&type, 1);
+	switch (type)
+	{
+	case 0:
+		// register observer
+		addObserver(zSource);
+		break;
+	case 1:
+		// unsubscribe
+		removeObserver(zSource);
+		break;
+	}
 }
 
 Framework::Either<Block*, int> Chunk::zBlockAt(Framework::Vec3<int> location) const
@@ -141,6 +209,14 @@ void Chunk::putBlockAt(Framework::Vec3<int> location, Block* block)
 		block->setNeighbour(BOTTOM, neighbor);
 	if (old)
 		old->release();
+	char msg[9];
+	msg[0] = 0; // set block
+	*(int*)(msg + 1) = index;
+	*(int*)(msg + 5) = block ? block->zBlockType()->getId() : NoBlockBlockType::ID;
+	NetworkMessage message;
+	message.addressChunck(this);
+	message.setMessage(msg, 9, 0);
+	notifyObservers(message);
 }
 
 void Chunk::putBlockTypeAt(Framework::Vec3<int> location, int type)
@@ -166,6 +242,14 @@ void Chunk::putBlockTypeAt(Framework::Vec3<int> location, int type)
 	neighbor = zBlockNeighbor(location + getDirection(BOTTOM));
 	if (neighbor.isA())
 		((Block*)neighbor)->setNeighbourType(TOP, type);
+	char msg[9];
+	msg[0] = 0; // set block
+	*(int*)(msg + 1) = index;
+	*(int*)(msg + 5) = type;
+	NetworkMessage message;
+	message.addressChunck(this);
+	message.setMessage(msg, 9, 0);
+	notifyObservers(message);
 }
 
 void Chunk::setNeighbor(Direction dir, Chunk* zChunk)
@@ -432,55 +516,7 @@ void Chunk::setAdded()
 	added = 1;
 }
 
-void Chunk::addView(Entity* zEntity)
-{
-	cs.lock();
-	bool found = 0;
-	for (Entity* e : views)
-	{
-		if (e == zEntity)
-		{
-			found = 1;
-			break;
-		}
-	}
-	if (!found)
-		views.add(zEntity);
-	cs.unlock();
-}
-
-void Chunk::removeView(Entity* zEntity)
-{
-	cs.lock();
-	int i = 0;
-	for (Entity* e : views)
-	{
-		if (e == zEntity)
-		{
-			views.remove(i);
-			break;
-		}
-		i++;
-	}
-	cs.unlock();
-}
-
-bool Chunk::hasView(Entity* zEntity)
-{
-	cs.lock();
-	for (Entity* e : views)
-	{
-		if (e == zEntity)
-		{
-			cs.unlock();
-			return 1;
-		}
-	}
-	cs.unlock();
-	return 0;
-}
-
-bool Chunk::hasViews() const
+bool Chunk::hasObservers() const
 {
-	return views.getEintragAnzahl() > 0;
+	return observers.getEintragAnzahl() > 0;
 }

+ 6 - 6
FactoryCraft/Chunk.h

@@ -20,14 +20,17 @@ private:
 	Framework::Either<Block*, int> zBlockNeighbor(Framework::Vec3<int> location);
 	bool added;
 	Framework::Critical cs;
-	Framework::Array<Entity*> views;
+	Framework::Array<int> observers;
 
 public:
 	Chunk(Framework::Punkt location, int dimensionId);
 	Chunk(Framework::Punkt location, int dimensionId, Framework::StreamReader* zReader);
 	~Chunk();
 
-	void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse);
+	void notifyObservers(NetworkMessage& msg);
+	void addObserver(Entity* zEntity);
+	void removeObserver(Entity* zEntity);
+	void api(Framework::StreamReader* zRequest, Entity* zSource);
 
 	Framework::Either<Block*, int> zBlockAt(Framework::Vec3<int> cLocation) const;
 	const Block* zBlockConst(Framework::Vec3<int> location) const;
@@ -46,8 +49,5 @@ public:
 	Framework::Vec3<int> getMax() const;
 	void prepareRemove();
 	void setAdded();
-	void addView(Entity* zEntity);
-	void removeView(Entity* zEntity);
-	bool hasView(Entity* zEntity);
-	bool hasViews() const;
+	bool hasObservers() const;
 };

+ 1 - 1
FactoryCraft/CraftingStorage.cpp

@@ -35,7 +35,7 @@ BasicShapedCrafter::BasicShapedCrafter(int width, int height, Inventory* zInvent
 			{
 				NetworkMessage message;
 				getOutputPreview(message);
-				message.adressGui(id);
+				message.addressGui(id);
 				Game::INSTANCE->sendMessage(&message, zSource);
 			}
 		});

+ 55 - 3
FactoryCraft/Dimension.cpp

@@ -19,9 +19,33 @@ Dimension::~Dimension()
 	chunks->release();
 }
 
-void Dimension::api(Framework::StreamReader* zRequest, NetworkMessage* zResponse)
+void Dimension::api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource)
 {
-	// TODO: switch type chunck, block
+	char type;
+	zRequest->lese(&type, 1);
+	switch (type)
+	{
+	case 0: // chunk message
+	{
+		Punkt center;
+		zRequest->lese((char*)&center.x, 4);
+		zRequest->lese((char*)&center.y, 4);
+		cs.lock();
+		Chunk* cC = zChunk(center);
+		if (!cC)
+		{
+			// TODO: have a max amount of waiting requests per player
+			waitingRequests.add({ dynamic_cast<InMemoryBuffer*>(zRequest->getThis()), center, zSource->getId() });
+			Game::INSTANCE->requestArea({ center.x - CHUNK_SIZE / 2, center.y - CHUNK_SIZE / 2, center.x + CHUNK_SIZE / 2 - 1, center.y + CHUNK_SIZE / 2 - 1, dimensionId });
+		}
+		else
+		{
+			cC->api(zRequest, zSource);
+		}
+		cs.unlock();
+		break;
+	}
+	}
 }
 
 void Dimension::tickEntities()
@@ -178,6 +202,34 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
 		if (chunk)
 			chunk->setNeighbor(NORTH, zChunk);
 	}
+	if (chunk)
+	{
+		cs.lock();
+		int index = 0;
+		for (Iterator<RequestQueue> iterator = waitingRequests.begin(); iterator; )
+		{
+			Entity* zE = Game::INSTANCE->zEntity(iterator.val().sourceId);
+			if (zE)
+			{
+				if (iterator.val().chunkCenter == chunk->getCenter())
+				{
+					chunk->api(iterator.val().request, zE);
+					iterator.val().request->release();
+					iterator.remove();
+					continue;
+				}
+			}
+			else
+			{
+				iterator.val().request->release();
+				iterator.remove();
+				continue;
+			}
+			iterator++;
+			index++;
+		}
+		cs.unlock();
+	}
 }
 
 void Dimension::save(Text worldDir) const
@@ -247,7 +299,7 @@ void Dimension::removeOldChunks()
 	int index = 0;
 	for (Chunk* chunk : chunkList)
 	{
-		if (!chunk->hasViews())
+		if (!chunk->hasObservers())
 			removed.add(index, 0);
 		index++;
 	}

+ 11 - 2
FactoryCraft/Dimension.h

@@ -1,11 +1,18 @@
 #pragma once
 
 #include <Punkt.h>
-#include <Reader.h>
+#include <InMemoryBuffer.h>
 
 #include "Chunk.h"
 #include "NetworkMessage.h"
 
+struct RequestQueue
+{
+	Framework::InMemoryBuffer* request;
+	Framework::Punkt chunkCenter;
+	int sourceId;
+};
+
 class Dimension : public virtual Framework::ReferenceCounter
 {
 private:
@@ -14,6 +21,8 @@ private:
 	Framework::Trie<Chunk>* chunks;
 	Framework::Array<Chunk*> chunkList;
 	Framework::RCArray<Entity>* entities;
+	Framework::Array<RequestQueue> waitingRequests;
+	Framework::Critical cs;
 	void getAddrOf(Framework::Punkt cPos, char* addr) const;
 	void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
 
@@ -21,7 +30,7 @@ public:
 	Dimension(int id);
 	~Dimension();
 
-	void api(Framework::StreamReader* zRequest, NetworkMessage* zResponse);
+	void api(Framework::InMemoryBuffer* zRequest, NetworkMessage* zResponse, Entity* zSource);
 	void tickEntities();
 
 	Framework::Either<Block*, int> zBlock(Framework::Vec3<int> location);

+ 1 - 1
FactoryCraft/Entity.cpp

@@ -416,7 +416,7 @@ void Entity::tick(const Dimension* zDimension)
 	if (oldPos != location)
 	{
 		NetworkMessage changeMsg;
-		changeMsg.adressEntity(this);
+		changeMsg.addressEntity(this);
 		char msg[13];
 		msg[0] = 0; // position changed
 		*(float*)(msg + 1) = this->location.x;

+ 0 - 2
FactoryCraft/FactoryCraft.vcxproj

@@ -92,7 +92,6 @@
     <RemoteTargetPath>$(RemoteProjectDir)/$(TargetName)$(TargetExt)</RemoteTargetPath>
   </PropertyGroup>
   <ItemGroup>
-    <ClInclude Include="AddChunkUpdate.h" />
     <ClInclude Include="AddEntityUpdate.h" />
     <ClInclude Include="Area.h" />
     <ClInclude Include="BasicBlocks.h" />
@@ -149,7 +148,6 @@
     <ClInclude Include="WorldUpdate.h" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="AddChunkUpdate.cpp" />
     <ClCompile Include="AddEntityUpdate.cpp" />
     <ClCompile Include="Area.cpp" />
     <ClCompile Include="BasicBlock.cpp" />

+ 0 - 6
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -150,9 +150,6 @@
     <ClInclude Include="EntityType.h">
       <Filter>entities</Filter>
     </ClInclude>
-    <ClInclude Include="AddChunkUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
     <ClInclude Include="WorldLoader.h">
       <Filter>world\loader</Filter>
     </ClInclude>
@@ -293,9 +290,6 @@
     <ClCompile Include="Dimension.cpp">
       <Filter>world</Filter>
     </ClCompile>
-    <ClCompile Include="AddChunkUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
     <ClCompile Include="ItemStack.cpp">
       <Filter>inventory</Filter>
     </ClCompile>

+ 15 - 81
FactoryCraft/Game.cpp

@@ -2,12 +2,12 @@
 #include "Zeit.h"
 #include "Player.h"
 #include "OverworldDimension.h"
-#include "AddChunkUpdate.h"
 #include "NoBlock.h"
 #include "AsynchronCall.h"
 #include "Entity.h"
 #include "AddEntityUpdate.h"
 #include "EntityRemovedUpdate.h"
+#include "NetworkMessage.h"
 
 using namespace Framework;
 
@@ -73,8 +73,6 @@ void GameClient::sendWorldUpdate(WorldUpdate* update)
 					break;
 				index++;
 			}
-			if (update->getType() == AddChunkUpdateType::ID)
-				((AddChunkUpdate*)update)->zChunk()->addView(zPlayer);
 			updateQueue.add(update, index);
 			other.unlock();
 			updateSync.notify();
@@ -104,59 +102,8 @@ void GameClient::reply()
 		client->zForegroundWriter()->schreibe((char*)&id, 4);
 		foreground.unlock();
 		first = 0;
-		Dimension* dim = Game::INSTANCE->zDimension(d);
-		if (dim)
-		{
-			for (int xP = x - CHUNK_SIZE * viewDistance; xP <= x + CHUNK_SIZE * viewDistance; xP += CHUNK_SIZE)
-			{
-				for (int yP = y - CHUNK_SIZE * viewDistance; yP <= y + CHUNK_SIZE * viewDistance; yP += CHUNK_SIZE)
-				{
-					Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
-					if (chunk)
-						sendWorldUpdate(new AddChunkUpdate(dynamic_cast<Chunk*>(chunk->getThis())));
-				}
-			}
-		}
 		Game::INSTANCE->requestArea({ x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance, x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance, d });
 	}
-	else
-	{
-		Punkt lastMin = Game::INSTANCE->getChunkCenter((int)floor(lastPos.x) - CHUNK_SIZE * viewDistance, (int)floor(lastPos.y) - CHUNK_SIZE * viewDistance);
-		Punkt curMin = Game::INSTANCE->getChunkCenter(x - CHUNK_SIZE * viewDistance, y - CHUNK_SIZE * viewDistance);
-		Punkt lastMax = Game::INSTANCE->getChunkCenter((int)floor(lastPos.x) + CHUNK_SIZE * viewDistance, (int)floor(lastPos.y) + CHUNK_SIZE * viewDistance);
-		Punkt curMax = Game::INSTANCE->getChunkCenter(x + CHUNK_SIZE * viewDistance, y + CHUNK_SIZE * viewDistance);
-		Dimension* dim = Game::INSTANCE->zDimension(d);
-		if (dim)
-		{
-			for (int xP = curMin.x; xP <= curMax.x; xP += CHUNK_SIZE)
-			{
-				for (int yP = curMin.y; yP <= curMax.y; yP += CHUNK_SIZE)
-				{
-					if (xP < lastMin.x || xP > lastMax.x || yP < lastMin.y || yP > lastMax.y)
-					{
-						Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
-						if (chunk)
-							sendWorldUpdate(new AddChunkUpdate(dynamic_cast<Chunk*>(chunk->getThis())));
-						else
-							Game::INSTANCE->requestArea(Game::INSTANCE->getChunckArea(Game::INSTANCE->getChunkCenter(xP, yP)));
-					}
-				}
-			}
-			for (int xP = lastMin.x; xP <= lastMax.x; xP += CHUNK_SIZE)
-			{
-				for (int yP = lastMin.y; yP <= lastMax.y; yP += CHUNK_SIZE)
-				{
-					if (xP < curMin.x || xP > curMax.x || yP < curMin.y || yP > curMax.y)
-					{
-						Chunk* chunk = dim->zChunk(Game::INSTANCE->getChunkCenter(xP, yP));
-						if (chunk)
-							chunk->removeView(zPlayer);
-					}
-				}
-			}
-		}
-	}
-	lastPos = zPlayer->getPosition();
 }
 
 void GameClient::logout()
@@ -185,20 +132,17 @@ bool GameClient::isOnline() const
 
 void GameClient::sendResponse(NetworkMessage* zResponse)
 {
-	if (zResponse->isAreaAffected({ lastPos.x - (float)CHUNK_SIZE * (float)viewDistance, lastPos.y - (float)CHUNK_SIZE * (float)viewDistance, 0.f }, { lastPos.x + (float)CHUNK_SIZE * (float)viewDistance, lastPos.y + (float)CHUNK_SIZE * (float)viewDistance, (float)WORLD_HEIGHT }, zPlayer->getCurrentDimensionId()))
+	if (zResponse->isUseBackground())
 	{
-		if (zResponse->isUseBackground())
-		{
-			background.lock();
-			zResponse->writeTo(client->zBackgroundWriter());
-			background.unlock();
-		}
-		else
-		{
-			foreground.lock();
-			zResponse->writeTo(client->zForegroundWriter());
-			foreground.unlock();
-		}
+		background.lock();
+		zResponse->writeTo(client->zBackgroundWriter());
+		background.unlock();
+	}
+	else
+	{
+		foreground.lock();
+		zResponse->writeTo(client->zForegroundWriter());
+		foreground.unlock();
 	}
 }
 
@@ -371,7 +315,7 @@ void Game::thread()
 	save();
 }
 
-void Game::api(Framework::StreamReader* zRequest, GameClient* zOrigin)
+void Game::api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin)
 {
 	char type;
 	zRequest->lese(&type, 1);
@@ -380,15 +324,13 @@ void Game::api(Framework::StreamReader* zRequest, GameClient* zOrigin)
 	{
 	case 1: // world
 	{
-		int dimensionId;
-		zRequest->lese((char*)&dimensionId, 4);
-		Dimension* dim = zDimension(dimensionId);
+		Dimension* dim = zDimension(zOrigin->zEntity()->getCurrentDimensionId());
 		if (!dim)
 		{
-			dim = new Dimension(dimensionId);
+			dim = new Dimension(zOrigin->zEntity()->getCurrentDimensionId());
 			addDimension(dim);
 		}
-		dim->api(zRequest, &response);
+		dim->api(zRequest, &response, zOrigin->zEntity());
 		break;
 	}
 	case 2: // player
@@ -535,14 +477,6 @@ bool Game::doesChunkExist(int x, int y, int dimension)
 {
 	cs.lock();
 	bool result = isChunkLoaded(x, y, dimension) || loader->existsChunk(x, y, dimension);
-	if (!result)
-	{
-		for (WorldUpdate* update : *updates)
-		{
-			if (update->getType() == AddChunkUpdateType::ID)
-				result |= ((AddChunkUpdate*)update)->zChunk()->getCenter() == Framework::Punkt(x, y);
-		}
-	}
 	cs.unlock();
 	return result;
 }

+ 1 - 2
FactoryCraft/Game.h

@@ -29,7 +29,6 @@ private:
 	Critical other;
 	Framework::Synchronizer updateSync;
 	RCArray<InMemoryBuffer> requests;
-	Vec3<float> lastPos;
 	RCArray<WorldUpdate> updateQueue;
 	int viewDistance;
 	bool first;
@@ -84,7 +83,7 @@ private:
 public:
 	~Game();
 	void initialize();
-	void api(Framework::StreamReader* zRequest, GameClient* zOrigin);
+	void api(Framework::InMemoryBuffer* zRequest, GameClient* zOrigin);
 	void broadcastMessage(NetworkMessage* zResponse);
 	void sendMessage(NetworkMessage* zResponse, Entity* zTargetPlayer);
 	bool requestWorldUpdate(WorldUpdate* update);

+ 2 - 2
FactoryCraft/Inventory.cpp

@@ -399,7 +399,7 @@ void Inventory::notyObservers(NetworkMessage& msg)
 		Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
 		if (e)
 		{
-			msg.adressGui(observer.getSecond());
+			msg.addressGui(observer.getSecond());
 			Game::INSTANCE->sendMessage(&msg, e);
 		}
 		else
@@ -698,7 +698,7 @@ void Inventory::inventoryApi(Framework::StreamReader* zRequest, NetworkMessage*
 		char* id = new char[idLen + 1];
 		zRequest->lese(id, idLen);
 		id[(int)idLen] = 0;
-		zResponse->adressGui(id);
+		zResponse->addressGui(id);
 		addObserver(zSource, id);
 		delete[] id;
 		char filterLen;

+ 53 - 68
FactoryCraft/NetworkMessage.cpp

@@ -5,93 +5,85 @@
 
 NetworkMessage::NetworkMessage()
 {
-	adress = 0;
-	adressLength = 0;
+	address = 0;
+	addressLength = 0;
 	broadcast = 0;
 	message = 0;
 	msgDelete = 0;
 	msgLength = 0;
 	useBackground = 0;
-	minPosition.x = std::numeric_limits<float>::min();
-	minPosition.y = std::numeric_limits<float>::min();
-	minPosition.z = std::numeric_limits<float>::min();
-	maxPosition.x = std::numeric_limits<float>::max();
-	maxPosition.y = std::numeric_limits<float>::max();
-	maxPosition.z = std::numeric_limits<float>::max();
-	affectedDimension = -1;
 }
 
 NetworkMessage::~NetworkMessage()
 {
 	if (msgDelete)
 		delete[] message;
-	delete[] adress;
+	delete[] address;
 }
 
-void NetworkMessage::adressChunck(Chunk* zChunk)
+void NetworkMessage::addressChunck(Chunk* zChunk)
 {
-	delete[] adress;
-	adressLength = 10;
-	adress = new char[adressLength];
-	adress[0] = 1; // dimension response
-	adress[1] = 1; // chunck
+	delete[] address;
+	addressLength = 10;
+	address = new char[addressLength];
+	address[0] = 1; // dimension response
+	address[1] = 1; // chunck
 	Framework::Punkt center = zChunk->getCenter();
-	*(int*)(adress + 2) = center.x;
-	*(int*)(adress + 6) = center.y;
-	minPosition = zChunk->getMin();
-	maxPosition = zChunk->getMax();
-	affectedDimension = zChunk->getDimensionId();
+	*(int*)(address + 2) = center.x;
+	*(int*)(address + 6) = center.y;
 }
 
-void NetworkMessage::adressEntity(Entity* zEntity)
+void NetworkMessage::addressEntity(Entity* zEntity)
 {
-	delete[] adress;
-	adressLength = 6;
-	adress = new char[adressLength];
-	adress[0] = 1; // dimension response
-	adress[1] = 2; // entity
-	*(int*)(adress + 2) = zEntity->getId();
-	minPosition = zEntity->getPosition();
-	maxPosition = zEntity->getPosition();
-	affectedDimension = zEntity->getCurrentDimensionId();
+	delete[] address;
+	addressLength = 6;
+	address = new char[addressLength];
+	address[0] = 1; // dimension response
+	address[1] = 2; // entity
+	*(int*)(address + 2) = zEntity->getId();
 }
 
-void NetworkMessage::adressBlock(Block* zBlock)
+void NetworkMessage::addressDimension()
 {
-	delete[] adress;
-	adressLength = 14;
-	adress = new char[adressLength];
-	adress[0] = 1; // dimension response
-	adress[1] = 3; // block
+	delete[] address;
+	addressLength = 1;
+	address = new char[1];
+	address[0] = 1; // dimension response
+}
+
+void NetworkMessage::addressBlock(Block* zBlock)
+{
+	delete[] address;
+	addressLength = 14;
+	address = new char[addressLength];
+	address[0] = 1; // dimension response
+	address[1] = 3; // block
 	Framework::Vec3<int> pos = zBlock->getPos();
-	*(int*)(adress + 2) = pos.x;
-	*(int*)(adress + 6) = pos.y;
-	*(int*)(adress + 10) = pos.z;
-	minPosition = pos;
-	maxPosition = pos;
-	affectedDimension = zBlock->getDimensionId();
+	*(int*)(address + 2) = pos.x;
+	*(int*)(address + 6) = pos.y;
+	*(int*)(address + 10) = pos.z;
 }
 
 void NetworkMessage::openDialog(Framework::Text dialogName)
 {
-	delete[] adress;
-	adressLength = (char)(4 + dialogName.getLength());
-	adress = new char[adressLength];
-	adress[0] = 2; // gui message
-	adress[1] = 0; // open dialog
-	*(short*)(adress + 2) = (short)dialogName.getLength(); // block
-	memcpy(adress + 4, dialogName.getText(), dialogName.getLength());
+	delete[] address;
+	addressLength = (char)(4 + dialogName.getLength());
+	address = new char[addressLength];
+	address[0] = 2; // gui message
+	address[1] = 0; // open dialog
+	*(short*)(address + 2) = (short)dialogName.getLength(); // block
+	memcpy(address + 4, dialogName.getText(), dialogName.getLength());
 }
 
-void NetworkMessage::adressGui(Framework::Text elementId)
+void NetworkMessage::addressGui(Framework::Text elementId)
 {
-	delete[] adress;
-	adressLength = (char)(4 + elementId.getLength());
-	adress = new char[adressLength];
-	adress[0] = 2; // gui message
-	adress[1] = 1; // element message
-	*(short*)(adress + 2) = (short)elementId.getLength(); // block
-	memcpy(adress + 4, elementId.getText(), elementId.getLength());
+	delete[] address;
+	addressLength = (char)(4 + elementId.getLength());
+	address = new char[addressLength];
+	address[0] = 2; // gui message
+	address[1] = 1; // element message
+	*(short*)(address + 2) = (short)elementId.getLength(); // block
+	memcpy(address + 4, elementId.getText(), elementId.getLength());
 }
 
 void NetworkMessage::setMessage(char* msg, int length, bool deleteMsg)
@@ -113,21 +105,14 @@ void NetworkMessage::sendToAll()
 	broadcast = true;
 }
 
-bool NetworkMessage::isAreaAffected(Framework::Vec3<float> min, Framework::Vec3<float> max, int affectedDimension) const
-{
-	return minPosition.x <= max.x && maxPosition.x >= min.x &&
-		minPosition.y <= max.y && maxPosition.y >= min.y &&
-		minPosition.z <= max.z && maxPosition.z >= min.z && (this->affectedDimension < 0 || this->affectedDimension == affectedDimension);
-}
-
 void NetworkMessage::writeTo(Framework::StreamWriter* zWriter) const
 {
-	int total = msgLength + adressLength;
+	int total = msgLength + addressLength;
 	if (total)
 	{
 		zWriter->schreibe((char*)&GameClient::Message::API_MESSAGE, 1);
 		zWriter->schreibe((char*)&total, 4);
-		zWriter->schreibe(adress, adressLength);
+		zWriter->schreibe(address, addressLength);
 		zWriter->schreibe(message, msgLength);
 	}
 }
@@ -139,7 +124,7 @@ bool NetworkMessage::isBroadcast() const
 
 bool NetworkMessage::isEmpty() const
 {
-	return msgLength + adressLength <= 0;
+	return msgLength + addressLength <= 0;
 }
 
 bool NetworkMessage::isUseBackground() const

+ 7 - 10
FactoryCraft/NetworkMessage.h

@@ -10,31 +10,28 @@ class Entity;
 class NetworkMessage
 {
 private:
-	char* adress;
-	char adressLength;
-	Framework::Vec3<float> minPosition;
-	Framework::Vec3<float> maxPosition;
+	char* address;
+	char addressLength;
 	bool broadcast;
 	char* message;
 	bool msgDelete;
 	int msgLength;
 	bool useBackground;
-	int affectedDimension;
 
 public:
 	NetworkMessage();
 	~NetworkMessage();
 
-	void adressChunck(Chunk* zChunk);
-	void adressEntity(Entity* zEntity);
-	void adressBlock(Block* zBlock);
+	void addressChunck(Chunk* zChunk);
+	void addressEntity(Entity* zEntity);
+	void addressBlock(Block* zBlock);;
+	void addressDimension();
 	void openDialog(Framework::Text dialogName);
-	void adressGui(Framework::Text elementId);
+	void addressGui(Framework::Text elementId);
 	void setMessage(char* msg, int length, bool deleteMsg);
 	void setUseBackground();
 	void sendToAll();
 
-	bool isAreaAffected(Framework::Vec3<float> min, Framework::Vec3<float> max, int dimensionId) const;
 	void writeTo(Framework::StreamWriter* zWriter) const;
 	bool isBroadcast() const;
 	bool isEmpty() const;

+ 1 - 1
FactoryCraft/Player.cpp

@@ -296,7 +296,7 @@ void Player::playerApi(Framework::StreamReader* zRequest, NetworkMessage* zRespo
 		zRequest->lese((char*)&leftHandPosition, 4);
 		leftHandPosition = leftHandPosition % itemBar.getEintragAnzahl();
 		NetworkMessage msg;
-		msg.adressGui("gui_item_bar");
+		msg.addressGui("gui_item_bar");
 		char message[5];
 		message[0] = 3; // set selected slot
 		*(int*)(message + 1) = leftHandPosition;

+ 0 - 1
FactoryCraft/StaticInitializerOrder.cpp

@@ -28,7 +28,6 @@ bool initialized_##c##_##typ = StaticRegistry<typ>::INSTANCE.info(c::ID);
 #include "PlayerHand.h"
 #include "StoneTool.h"
 // world updates
-#include "AddChunkUpdate.h"
 #include "PlaceBlockUpdate.h"
 #include "BlockRemovedUpdate.h"
 #include "AddEntityUpdate.h"

+ 7 - 2
FactoryCraft/WorldGenerator.cpp

@@ -1,7 +1,6 @@
 #include "WorldGenerator.h"
 #include "StaticRegistry.h"
 #include "Game.h"
-#include "AddChunkUpdate.h"
 #include "NoiseInterpolator.h"
 
 using namespace Framework;
@@ -49,7 +48,13 @@ void WorldGenerator::thread()
 				{
 					Chunk* generatedChunk = StaticRegistry<DimensionGenerator>::INSTANCE.zElement(next.dimensionId)->generateChunk(seed, x, y);
 					generatedChunk->removeUnusedBlocks();
-					Game::INSTANCE->requestWorldUpdate(new AddChunkUpdate(generatedChunk));
+					Dimension* dim = Game::INSTANCE->zDimension(next.dimensionId);
+					if (!dim)
+					{
+						dim = new Dimension(next.dimensionId);
+						Game::INSTANCE->addDimension(dim);
+					}
+					dim->setChunk(generatedChunk, Punkt(x, y));
 				}
 			}
 		}

+ 7 - 2
FactoryCraft/WorldLoader.cpp

@@ -3,7 +3,6 @@
 
 #include "WorldLoader.h"
 #include "Game.h"
-#include "AddChunkUpdate.h"
 
 using namespace Framework;
 
@@ -80,7 +79,13 @@ void WorldLoader::thread()
 					if (file->open(Datei::Style::lesen))
 					{
 						Chunk* chunk = new Chunk(Framework::Punkt(x, y), next.dimensionId, file);
-						Game::INSTANCE->requestWorldUpdate(new AddChunkUpdate(chunk));
+						Dimension* dim = Game::INSTANCE->zDimension(next.dimensionId);
+						if (!dim)
+						{
+							dim = new Dimension(next.dimensionId);
+							Game::INSTANCE->addDimension(dim);
+						}
+						dim->setChunk(chunk, Punkt(x, y));
 					}
 					file->close();
 					file->release();