Эх сурвалжийг харах

player movement is now client sided

Kolja Strohm 2 жил өмнө
parent
commit
ac10f9b8d6

+ 0 - 18
FactoryCraft/BlockRemovedUpdate.cpp

@@ -1,18 +0,0 @@
-#include "BlockRemovedUpdate.h"
-#include "Globals.h"
-#include "Game.h"
-
-BlockRemovedUpdateType::BlockRemovedUpdateType()
-	: WorldUpdateType(ID)
-{}
-
-void BlockRemovedUpdateType::applyUpdate(Framework::StreamReader* zReader)
-{
-	Framework::Vec3<int> pos;
-	zReader->lese((char*)&pos.x, 4);
-	zReader->lese((char*)&pos.y, 4);
-	zReader->lese((char*)&pos.z, 4);
-	Block* b = currentGame->zBlockAt(pos);
-	if (b)
-		currentGame->zDimension()->removeBlock(b);
-}

+ 0 - 14
FactoryCraft/BlockRemovedUpdate.h

@@ -1,14 +0,0 @@
-#pragma once
-
-#include "WorldUpdate.h"
-
-class BlockRemovedUpdateType : WorldUpdateType
-{
-	REGISTRABLE(BlockRemovedUpdateType)
-
-protected:
-	BlockRemovedUpdateType();
-	void applyUpdate(Framework::StreamReader* zReader) override;
-};
-
-REGISTER(BlockRemovedUpdateType, WorldUpdateType)

+ 2 - 0
FactoryCraft/Chunk.cpp

@@ -32,6 +32,8 @@ void Chunk::api(char* message)
 		int index = *(int*)(message + 1);
 		int id = *(int*)(message + 5);
 		Framework::Vec3<int> location((index / WORLD_HEIGHT) / CHUNK_SIZE, (index / WORLD_HEIGHT) % CHUNK_SIZE, index % WORLD_HEIGHT);
+		location.x += this->location.x - CHUNK_SIZE / 2;
+		location.y += this->location.y - CHUNK_SIZE / 2;
 		if (blockTypes[id]->doesNeedInstance())
 		{
 			Block* zB = blockTypes[id]->createBlock(location);

+ 3 - 1
FactoryCraft/Constants.h

@@ -1,4 +1,6 @@
 #pragma once
 
 #define CHUNK_SIZE 16
-#define WORLD_HEIGHT 500
+#define WORLD_HEIGHT 500
+#define CHUNK_VISIBILITY_RANGE 4
+#define MAX_VIEW_DISTANCE CHUNK_SIZE * CHUNK_VISIBILITY_RANGE

+ 191 - 8
FactoryCraft/Entity.cpp

@@ -1,12 +1,24 @@
+#include <Globals.h>
+
 #include "Entity.h"
 #include "Globals.h"
+#include "Game.h"
 
 
-Entity::Entity(const EntityType* zType, Framework::Model3DData* model, Framework::Model3DTextur* texture, int id)
-	: Model3D(), id(id), zType(zType)
+Entity::Entity(const EntityType* zType, Framework::Model3DData* model, Framework::Model3DTextur* texture, int id, Framework::Vec3<float> position, float maxMovementSpeed)
+	: Model3D(), id(id), zType(zType),
+	playerControlled(0),
+	maxMovementSpeed(maxMovementSpeed),
+	lastFlags(0),
+	timeSinceSync(0),
+	speed(0, 0, 0)
 {
+	pos = position;
 	setModelDaten(model);
 	setModelTextur(texture);
+	lastDirection = currentGame->zKamera()->getDirection();
+	currentFrame.duration = 0;
+	rend = 1;
 }
 
 Entity::~Entity()
@@ -17,15 +29,35 @@ void Entity::api(char* message)
 	switch (message[0])
 	{
 	case 0:
-	{ // update position
-		pos.x = *(float*)(message + 1);
-		pos.y = *(float*)(message + 5);
-		pos.z = *(float*)(message + 9);
+	{ // add movement frame
+		if (!playerControlled)
+		{
+			MovementFrame frame;
+			frame.direction.x = *(float*)(message += 1);
+			frame.direction.y = *(float*)(message += 4);
+			frame.direction.z = *(float*)(message += 4);
+			frame.targetPosition.x = *(float*)(message += 4);
+			frame.targetPosition.y = *(float*)(message += 4);
+			frame.targetPosition.z = *(float*)(message += 4);
+			frame.movementFlags = *(int*)(message += 4);
+			frame.duration = *(double*)(message += 4);
+			cs.lock();
+			movements.add(frame);
+			cs.unlock();
+		}
 		break;
 	}
 	case 1:
-	{ // update rotation
-		// TODO
+	{ // position correction
+		if (playerControlled)
+		{
+			timeSinceSync = 0;
+			pos.x = *(float*)(message += 1);
+			pos.y = *(float*)(message += 4);
+			pos.z = *(float*)(message += 4);
+			lastDirection = currentGame->zKamera()->getDirection();
+			lastFlags = 0;
+		}
 		break;
 	}
 	}
@@ -33,6 +65,151 @@ void Entity::api(char* message)
 
 bool Entity::tick(double time)
 {
+	if (playerControlled && GetForegroundWindow() == window->getFensterHandle())
+	{
+		Vec3<float> direction = currentGame->zKamera()->getDirection();
+		Vec3<float> lastPos = pos;
+		int flags = 0;
+		speed = { 0, 0, speed.z };
+		if (GetKeyState('w') & 0x8000 || GetKeyState('W') & 0x8000)
+		{
+			flags |= 1;
+			speed += {direction.x, direction.y, 0};
+		}
+		if (GetKeyState('a') & 0x8000 || GetKeyState('A') & 0x8000)
+		{
+			flags |= 2;
+			Vec2<float> norm = { direction.x, direction.y };
+			norm.CCW90().normalize();
+			speed += {norm.x, norm.y, 0};
+		}
+		if (GetKeyState('s') & 0x8000 || GetKeyState('S') & 0x8000)
+		{
+			flags |= 4;
+			speed += {-direction.x, -direction.y, 0};
+		}
+		if (GetKeyState('d') & 0x8000 || GetKeyState('D') & 0x8000)
+		{
+			flags |= 8;
+			Vec2<float> norm = { direction.x, direction.y };
+			norm.CW90().normalize();
+			speed += {norm.x, norm.y, 0};
+		}
+		if (GetKeyState(T_Shift) & 0x8000)
+		{
+			flags |= 16;
+			speed.z = -maxMovementSpeed;
+		}
+		else if (GetKeyState(T_Space) & 0x8000)
+		{
+			flags |= 32;
+			speed.z = maxMovementSpeed;
+		}
+		else
+		{
+			speed.z = 0.f;
+		}
+		Vec2<float> norm = { speed.x, speed.y };
+		if (norm.getLengthSq() != 0)
+		{
+			norm.normalize();
+			speed.x = norm.x * maxMovementSpeed;
+			speed.y = norm.y * maxMovementSpeed;
+		}
+		// TODO: collision check
+		pos += speed * (float)time;
+		currentGame->zKamera()->setPosition(pos + Vec3<float>(0.f, 0.f, 1.5f));
+		((Game*)(Menu*)menuRegister->get("game"))->updatePosition(pos, 0, { 0, 0, 0 });
+		if (flags != lastFlags || direction != lastDirection || timeSinceSync >= 1)
+		{
+			if (timeSinceSync > 0)
+			{
+				MovementFrame frame;
+				frame.direction = lastDirection;
+				frame.targetPosition = lastPos;
+				frame.movementFlags = lastFlags;
+				frame.duration = timeSinceSync;
+				network->zFactoryClient()->sendPlayerMovement(frame);
+			}
+			lastFlags = flags;
+			lastDirection = direction;
+			timeSinceSync = 0;
+		}
+		timeSinceSync += time;
+		rend = 1;
+	}
+	else
+	{
+		double totalTime = time;
+		while (totalTime > 0)
+		{
+			if (currentFrame.duration <= 0)
+			{
+				if (movements.getEintragAnzahl() > 0)
+				{
+					currentFrame = movements.get(0);
+					cs.lock();
+					movements.remove(0);
+					cs.unlock();
+				}
+				else
+				{
+					break;
+				}
+			}
+			double t = MIN(totalTime, currentFrame.duration);
+			speed = { 0, 0, speed.z };
+			if ((currentFrame.movementFlags | 1) == currentFrame.movementFlags)
+			{
+				speed += {currentFrame.direction.x, currentFrame.direction.y, 0};
+			}
+			if ((currentFrame.movementFlags | 2) == currentFrame.movementFlags)
+			{
+				Vec2<float> norm = { currentFrame.direction.x, currentFrame.direction.y };
+				norm.CCW90().normalize();
+				speed += {norm.x, norm.y, 0};
+			}
+			if ((currentFrame.movementFlags | 4) == currentFrame.movementFlags)
+			{
+				speed += {-currentFrame.direction.x, -currentFrame.direction.y, 0};
+			}
+			if ((currentFrame.movementFlags | 8) == currentFrame.movementFlags)
+			{
+				Vec2<float> norm = { currentFrame.direction.x, currentFrame.direction.y };
+				norm.CW90().normalize();
+				speed += {norm.x, norm.y, 0};
+			}
+			if ((currentFrame.movementFlags | 16) == currentFrame.movementFlags)
+			{
+				speed.z = -maxMovementSpeed;
+			}
+			else if ((currentFrame.movementFlags | 32) == currentFrame.movementFlags)
+			{
+				speed.z = maxMovementSpeed;
+			}
+			else
+			{
+				speed.z = 0.f;
+			}
+			Vec2<float> norm = { speed.x, speed.y };
+			if (norm.getLengthSq() != 0)
+			{
+				norm.normalize();
+				speed.x = norm.x * maxMovementSpeed;
+				speed.y = norm.y * maxMovementSpeed;
+			}
+			// TODO: collision check
+			pos += speed * (float)t;
+			currentFrame.duration -= t;
+			totalTime -= t;
+			if (currentFrame.duration <= 0)
+			{
+				pos = currentFrame.targetPosition;
+			}
+			rend = 1;
+		}
+
+	}
 	return Model3D::tick(time);
 }
 
@@ -54,4 +231,10 @@ void Entity::lock()
 void Entity::unlock()
 {
 	cs.unlock();
+}
+
+void Entity::setPlayerControlled()
+{
+	playerControlled = 1;
+	currentGame->zKamera()->setPosition(pos + Vec3<float>(0.f, 0.f, 1.5f));
 }

+ 18 - 1
FactoryCraft/Entity.h

@@ -9,15 +9,31 @@
 
 class Block;
 
+struct MovementFrame
+{
+	Framework::Vec3<float> direction;
+	Framework::Vec3<float> targetPosition;
+	int movementFlags;
+	double duration;
+};
+
 class Entity : public Framework::Model3D
 {
 private:
 	int id;
 	const EntityType* zType;
 	Framework::Critical cs;
+	bool playerControlled;
+	float maxMovementSpeed;
+	int lastFlags;
+	double timeSinceSync;
+	Framework::Vec3<float> lastDirection;
+	Framework::Array< MovementFrame > movements;
+	Framework::Vec3<float> speed;
+	MovementFrame currentFrame;
 
 public:
-	Entity(const EntityType* zType, Framework::Model3DData* model, Framework::Model3DTextur* texture, int id);
+	Entity(const EntityType* zType, Framework::Model3DData* model, Framework::Model3DTextur* texture, int id, Framework::Vec3<float> position, float maxMovementSpeed);
 	~Entity();
 
 	void api(char* message);
@@ -27,4 +43,5 @@ public:
 	const EntityType* zEntityType() const;
 	void lock();
 	void unlock();
+	void setPlayerControlled();
 };

+ 14 - 2
FactoryCraft/EntityType.cpp

@@ -1,6 +1,7 @@
 #include "EntityType.h"
 #include "Entity.h"
 #include "Registries.h"
+#include "Globals.h"
 
 
 EntityType::EntityType(int id, ModelInfo model)
@@ -16,14 +17,25 @@ Entity* EntityType::loadEntity(Framework::StreamReader* zReader) const
 	zReader->lese((char*)&position.x, 4);
 	zReader->lese((char*)&position.y, 4);
 	zReader->lese((char*)&position.z, 4);
+	float maxSpeed;
+	zReader->lese((char*)&maxSpeed, 4);
 	bool specialModel = 0;
 	zReader->lese((char*)&specialModel, 1);
+	Entity* e;
 	if (specialModel)
 	{
 		ModelInfo model(zReader);
-		return new Entity(this, model.getModel(), model.getTexture(), id);;
+		e = new Entity(this, model.getModel(), model.getTexture(), id, position, maxSpeed);
 	}
-	return new Entity(this, model.getModel(), model.getTexture(), id);
+	else
+	{
+		e = new Entity(this, model.getModel(), model.getTexture(), id, position, maxSpeed);
+	}
+	if (currentGame->zKamera()->getEntityId() == id)
+	{
+		e->setPlayerControlled();
+	}
+	return e;
 }
 
 int EntityType::getId() const

+ 21 - 0
FactoryCraft/FactoryClient.cpp

@@ -217,6 +217,27 @@ void FactoryClient::sendPlayerAction(char* data, unsigned short length)
 	cs.unlock();
 }
 
+void FactoryClient::sendPlayerMovement(MovementFrame& frame)
+{
+	if (!foreground)
+		return;
+	cs.lock();
+	short length = 38;
+	foreground->sende((char*)&length, 2);
+	char msgId = 2; // player message
+	foreground->sende(&msgId, 1);
+	foreground->sende(&msgId, 1); // set movement
+	foreground->sende((char*)&frame.direction.x, 4);
+	foreground->sende((char*)&frame.direction.y, 4);
+	foreground->sende((char*)&frame.direction.z, 4);
+	foreground->sende((char*)&frame.targetPosition.x, 4);
+	foreground->sende((char*)&frame.targetPosition.y, 4);
+	foreground->sende((char*)&frame.targetPosition.z, 4);
+	foreground->sende((char*)&frame.movementFlags, 4);
+	foreground->sende((char*)&frame.duration, 8);
+	cs.unlock();
+}
+
 void FactoryClient::entityAPIRequest(int entityId, char* message, unsigned short length)
 {
 	if (!foreground)

+ 3 - 0
FactoryCraft/FactoryClient.h

@@ -9,6 +9,8 @@
 #include <Either.h>
 #include <Punkt.h>
 
+#include "Entity.h"
+
 class FactoryClient : public Framework::ReferenceCounter
 {
 private:
@@ -32,6 +34,7 @@ public:
 	Network::NetworkReader* getNextBackgroundMessage();
 	void endMessageReading(bool bg);
 	void sendPlayerAction(char* data, unsigned short length);
+	void sendPlayerMovement(MovementFrame& frame);
 	void entityAPIRequest(int entityId, char* message, unsigned short length);
 	void chunkAPIRequest(Framework::Punkt center, char* message, unsigned short length);
 	void inventoryAPIRequest(Framework::Either<int, Framework::VecN<int, 4>> target, char* message, unsigned short length);

+ 0 - 4
FactoryCraft/FactoryCraft.vcxproj

@@ -173,7 +173,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="AddEntityUpdate.cpp" />
     <ClCompile Include="Area.cpp" />
     <ClCompile Include="Block.cpp" />
-    <ClCompile Include="BlockRemovedUpdate.cpp" />
     <ClCompile Include="BlockType.cpp" />
     <ClCompile Include="Chunk.cpp" />
     <ClCompile Include="CraftingGrid.cpp" />
@@ -198,7 +197,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="Menu.cpp" />
     <ClCompile Include="ModelInfo.cpp" />
     <ClCompile Include="NetworkHandler.cpp" />
-    <ClCompile Include="PlaceBlockUpdate.cpp" />
     <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="StaticInitializerOrder.cpp" />
     <ClCompile Include="World.cpp" />
@@ -208,7 +206,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="AddEntityUpdate.h" />
     <ClInclude Include="Area.h" />
     <ClInclude Include="Block.h" />
-    <ClInclude Include="BlockRemovedUpdate.h" />
     <ClInclude Include="BlockType.h" />
     <ClInclude Include="Chunk.h" />
     <ClInclude Include="Constants.h" />
@@ -234,7 +231,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="Menu.h" />
     <ClInclude Include="ModelInfo.h" />
     <ClInclude Include="NetworkHandler.h" />
-    <ClInclude Include="PlaceBlockUpdate.h" />
     <ClInclude Include="PlayerKam.h" />
     <ClInclude Include="Registries.h" />
     <ClInclude Include="StaticRegistry.h" />

+ 0 - 12
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -103,12 +103,6 @@
     <ClCompile Include="Load.cpp">
       <Filter>Menu</Filter>
     </ClCompile>
-    <ClCompile Include="PlaceBlockUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
-    <ClCompile Include="BlockRemovedUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
     <ClCompile Include="EntityType.cpp">
       <Filter>Entity</Filter>
     </ClCompile>
@@ -204,12 +198,6 @@
     <ClInclude Include="FactoryClient.h">
       <Filter>Network</Filter>
     </ClInclude>
-    <ClInclude Include="PlaceBlockUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
-    <ClInclude Include="BlockRemovedUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
     <ClInclude Include="Entity.h">
       <Filter>Entity</Filter>
     </ClInclude>

+ 1 - 1
FactoryCraft/ModelInfo.cpp

@@ -39,7 +39,7 @@ Framework::Model3DTextur* ModelInfo::getTexture() const
 	for (Text* texturPath : texturPaths)
 	{
 		Textur* tex = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur(texturPath->getText(), 0);
-		textur->setPolygonTextur(index++, dynamic_cast<Textur*>(tex));
+		textur->setPolygonTextur(index++, tex);
 	}
 	return textur;
 }

+ 2 - 2
FactoryCraft/NetworkHandler.cpp

@@ -27,8 +27,8 @@ NetworkHandler::NetworkHandler()
 	esc = 0;
 	if (msc->registerSSL(ipT->getText(), port))
 	{
-		esc = msc->createErhaltungServerClient();
-		esc->verbinde();
+		//esc = msc->createErhaltungServerClient();
+		//esc->verbinde();
 	}
 	iDat->release();
 	fc = 0;

+ 0 - 22
FactoryCraft/PlaceBlockUpdate.cpp

@@ -1,22 +0,0 @@
-#include "PlaceBlockUpdate.h"
-#include <Vec3.h>
-#include "BlockType.h"
-#include "StaticRegistry.h"
-#include "Registries.h"
-#include "Globals.h"
-
-PlaceBlockUpdateType::PlaceBlockUpdateType()
-	: WorldUpdateType(ID)
-{}
-
-void PlaceBlockUpdateType::applyUpdate(Framework::StreamReader* zReader)
-{
-	Framework::Vec3<int> pos;
-	zReader->lese((char*)&pos.x, 4);
-	zReader->lese((char*)&pos.y, 4);
-	zReader->lese((char*)&pos.z, 4);
-	unsigned short id;
-	zReader->lese((char*)&id, 2);
-	if (blockTypes[id]->doesNeedInstance())
-		currentGame->zDimension()->setBlock(blockTypes[id]->createBlock(pos));
-}

+ 0 - 13
FactoryCraft/PlaceBlockUpdate.h

@@ -1,13 +0,0 @@
-#pragma once
-#include "WorldUpdate.h"
-
-class PlaceBlockUpdateType : WorldUpdateType
-{
-	REGISTRABLE(PlaceBlockUpdateType)
-
-protected:
-	PlaceBlockUpdateType();
-	void applyUpdate(Framework::StreamReader* zReader) override;
-};
-
-REGISTER(PlaceBlockUpdateType, WorldUpdateType)

+ 12 - 110
FactoryCraft/PlayerKam.cpp

@@ -13,8 +13,6 @@ PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
 	setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
 	setRotation({ (float)PI / 2.f, 0, 0 });
 	entityId = -1;
-	transmittedDirection = getWorldDirection(getScreenPos() + getScreenSize() / 2);
-	timeSiceTransmision = 0;
 }
 
 void PlayerKam::setDirection(Framework::Vec3<float> direction)
@@ -28,50 +26,8 @@ void PlayerKam::setDirection(Framework::Vec3<float> direction)
 
 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];
@@ -84,47 +40,6 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
 	}
 	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)
 		{
 			bool oldControl = kameraControll;
@@ -135,8 +50,8 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
 		}
 		if (te.taste == T_Tab)
 		{
-			action[0] = 4;
-			network->zFactoryClient()->sendPlayerAction(action, 1);
+			char action = 4;
+			network->zFactoryClient()->sendPlayerAction(&action, 1);
 		}
 	}
 }
@@ -163,7 +78,6 @@ void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
 				{
 					char action[2] = { 1, 8 };
 					network->zFactoryClient()->sendPlayerAction(action, 2);
-
 				}
 				if (me.id == ME_RLinks)
 				{
@@ -199,16 +113,6 @@ bool PlayerKam::tick(double time)
 	removeStyle(Style::Movable | Style::Rotatable | Style::Zoomable);
 	bool result = Kam3D::tick(time);
 	addStyle(style);
-	if (entityId >= 0)
-	{
-		Entity* entity = currentGame->zEntity(entityId);
-		if (entity)
-		{
-			// update camera position
-			setPosition(entity->getPos() + Vec3<float>(0.f, 0.f, 1.5f));
-			((Game*)(Menu*)menuRegister->get("game"))->updatePosition(entity->getPos(), 0, { 0, 0, 0 });
-		}
-	}
 	if (kameraControll)
 	{
 		Punkt dir = window->getGröße() / 2 - (getMausPos() - window->getPosition());
@@ -221,18 +125,6 @@ bool PlayerKam::tick(double time)
 		setShowCursor(false);
 		setMausPos(window->getPosition() + window->getGröße() / 2);
 	}
-	timeSiceTransmision += time;
-	if (timeSiceTransmision > 0.5 && transmittedDirection != getWorldDirection(getScreenPos() + getScreenSize() / 2))
-	{
-		transmittedDirection = getWorldDirection(getScreenPos() + getScreenSize() / 2);
-		char action[13];
-		action[0] = 2;
-		*(float*)(action + 1) = transmittedDirection.x;
-		*(float*)(action + 5) = transmittedDirection.y;
-		*(float*)(action + 9) = transmittedDirection.z;
-		network->zFactoryClient()->sendPlayerAction(action, 13);
-		timeSiceTransmision = 0;
-	}
 	return result;
 }
 
@@ -249,4 +141,14 @@ void PlayerKam::setControlEnabled(bool enabled)
 	{
 		SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2);
 	}
+}
+
+int PlayerKam::getEntityId() const
+{
+	return entityId;
+}
+
+Framework::Vec3<float> PlayerKam::getDirection() const
+{
+	return getWorldDirection(getScreenPos() + getScreenSize() / 2);
 }

+ 2 - 2
FactoryCraft/PlayerKam.h

@@ -9,8 +9,6 @@ class PlayerKam : public Framework::Kam3D
 private:
 	bool kameraControll;
 	int entityId;
-	Framework::Vec3<float> transmittedDirection;
-	double timeSiceTransmision;
 
 public:
 	PlayerKam(Framework::Bildschirm3D* zScreen);
@@ -20,4 +18,6 @@ public:
 	bool tick(double time) override;
 	void setEntityId(int id);
 	void setControlEnabled(bool enabled);
+	int getEntityId() const;
+	Framework::Vec3<float> getDirection() const;
 };

+ 0 - 2
FactoryCraft/StaticInitializerOrder.cpp

@@ -12,7 +12,5 @@ const c *c::INSTANCE = new c();
 // order of includes determines the ids
 
 // world updates
-#include "PlaceBlockUpdate.h"
-#include "BlockRemovedUpdate.h"
 #include "AddEntityUpdate.h"
 #include "EntityRemovedUpdate.h"

+ 36 - 19
FactoryCraft/World.cpp

@@ -93,6 +93,11 @@ void World::update(bool background)
 		{
 			serverMessageReader->lese((char*)&ownEntityId, 4);
 			kam->setEntityId(ownEntityId);
+			Entity* p = zEntity(ownEntityId);
+			if (p)
+			{
+				p->setPlayerControlled();
+			}
 		}
 		network->zFactoryClient()->endMessageReading(background);
 	}
@@ -103,32 +108,44 @@ void World::update(bool background)
 		renderedWorld->lock();
 		currentDimension->removeDistantChunks({ (int)player->getPos().x, (int)player->getPos().y });
 		Punkt currentChunk = getChunkCenter((int)player->getX(), (int)player->getY());
-		for (int x = -CHUNK_VISIBILITY_RANGE; x <= CHUNK_VISIBILITY_RANGE; x++)
+		for (int x = 0; x <= CHUNK_VISIBILITY_RANGE; x++)
 		{
-			for (int y = -CHUNK_VISIBILITY_RANGE; y <= CHUNK_VISIBILITY_RANGE; y++)
+			for (int y = 0; y <= CHUNK_VISIBILITY_RANGE; y++)
 			{
-				Chunk* zC = currentDimension->zChunk(currentChunk + Punkt(x * CHUNK_SIZE, y * CHUNK_SIZE));
-				if (!zC)
+				std::function<void(Punkt)> requestChunk = [this](Punkt center)
 				{
-					char msg[1];
-					msg[0] = 0; // add observer and request chaunk data
-					Punkt pos = currentChunk + Punkt(x * CHUNK_SIZE, y * CHUNK_SIZE);
-					subLock.lock();
-					bool found = 0;
-					for (Punkt p : subscriptions)
+					Chunk* zC = currentDimension->zChunk(center);
+					if (!zC)
 					{
-						if (p == pos)
+						char msg[1];
+						msg[0] = 0; // add observer and request chaunk data
+						Punkt pos = center;
+						subLock.lock();
+						bool found = 0;
+						for (Punkt p : subscriptions)
 						{
-							found = 1;
-							break;
+							if (p == pos)
+							{
+								found = 1;
+								break;
+							}
 						}
+						if (!found)
+						{
+							network->zFactoryClient()->chunkAPIRequest(pos, msg, 1);
+							subscriptions.add(pos);
+						}
+						subLock.unlock();
 					}
-					if (!found)
-					{
-						network->zFactoryClient()->chunkAPIRequest(pos, msg, 1);
-						subscriptions.add(pos);
-					}
-					subLock.unlock();
+				};
+				requestChunk(currentChunk + Punkt(x * CHUNK_SIZE, y * CHUNK_SIZE));
+				if (y > 0)
+					requestChunk(currentChunk + Punkt(x * CHUNK_SIZE, -y * CHUNK_SIZE));
+				if (x > 0)
+				{
+					requestChunk(currentChunk + Punkt(-x * CHUNK_SIZE, y * CHUNK_SIZE));
+					if (y > 0)
+						requestChunk(currentChunk + Punkt(-x * CHUNK_SIZE, -y * CHUNK_SIZE));
 				}
 			}
 		}

+ 0 - 3
FactoryCraft/World.h

@@ -8,9 +8,6 @@
 #include "Dimension.h"
 #include "PlayerKam.h"
 
-#define CHUNK_VISIBILITY_RANGE 6
-#define MAX_VIEW_DISTANCE CHUNK_SIZE * CHUNK_VISIBILITY_RANGE
-
 class World : public Framework::Thread
 {
 private: