소스 검색

request model states after block loading if block can have diferent states

Kolja Strohm 2 년 전
부모
커밋
226e8f6100
5개의 변경된 파일37개의 추가작업 그리고 6개의 파일을 삭제
  1. 9 2
      FactoryCraft/Block.cpp
  2. 3 1
      FactoryCraft/Block.h
  3. 2 1
      FactoryCraft/BlockType.cpp
  4. 22 2
      FactoryCraft/FactoryClient.cpp
  5. 1 0
      FactoryCraft/FactoryClient.h

+ 9 - 2
FactoryCraft/Block.cpp

@@ -11,11 +11,13 @@ Block::Block(const BlockType* zType,
     Model3DData* model,
     Model3DTextur* texture,
     int maxHP,
-    bool transparent)
+    bool transparent,
+    bool needRequestModelInfo)
     : Model3D(),
       zType(zType),
       location(pos),
-      maxHP((float)maxHP)
+      maxHP((float)maxHP),
+      needRequestModelInfo(needRequestModelInfo)
 {
     hp = (float)maxHP;
     memset(sideVisible, 0, 6);
@@ -38,6 +40,11 @@ Block::~Block()
 void Block::beforeRender(
     GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader)
 {
+    if (needRequestModelInfo)
+    {
+        needRequestModelInfo = 0;
+        World::INSTANCE->zClient()->blockAPIRequest(location, "\0", 1);
+    }
     CustomDX11API* cApi = dynamic_cast<CustomDX11API*>(api);
     if (cApi && model->getVertexAnzahl() == 24)
     {

+ 3 - 1
FactoryCraft/Block.h

@@ -22,6 +22,7 @@ protected:
     Framework::Textur* breakTextur;
     unsigned char lightData[6 * 6];
     char lightBuffer[24 * 4];
+    char needRequestModelInfo;
 
     void beforeRender(
         GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader) override;
@@ -34,7 +35,8 @@ public:
         Model3DData* model,
         Model3DTextur* texture,
         int maxHp,
-        bool transparent);
+        bool transparent,
+        bool needRequestModelInfo);
     virtual ~Block();
 
     void api(char* message);

+ 2 - 1
FactoryCraft/BlockType.cpp

@@ -27,7 +27,8 @@ Block* BlockType::createBlock(Framework::Vec3<int> position)
         model.getModel(),
         model.getTexture(),
         initialMaxHP,
-        model.isTransparent());
+        model.isTransparent(),
+        needModelSubscription);
 }
 
 int BlockType::getId() const

+ 22 - 2
FactoryCraft/FactoryClient.cpp

@@ -80,7 +80,8 @@ void FactoryClient::loadServerInfo()
     kam->setBildschirmPosition(0, 0);
     kam->setBildschirmSize(50, 50);
     kam->setPosition(Vec3<float>(0, 0, 0));
-    kam->setRotation({(float)PI / 2.f, 0.f, std::atan2(0.f, -1.f) + (float)PI / 2});
+    kam->setRotation(
+        {(float)PI / 2.f, 0.f, std::atan2(0.f, -1.f) + (float)PI / 2});
     Bild* b = new Bild();
     b->neuBild(50, 50, 0);
     for (int i = 0; i < itemTypeCount; i++)
@@ -91,7 +92,9 @@ void FactoryClient::loadServerInfo()
         {
             Vec3<float> min = data->getMinPos();
             Vec3<float> max = data->getMaxPos();
-            float maxX = MAX(MAX(MAX(abs(min.x), abs(max.x)), MAX(abs(min.y), abs(max.y))),  MAX(abs(min.z), abs(max.z)));
+            float maxX = MAX(
+                MAX(MAX(abs(min.x), abs(max.x)), MAX(abs(min.y), abs(max.y))),
+                MAX(abs(min.z), abs(max.z)));
             kam->setPosition(Vec3<float>(maxX * 5, 0.f, 0.f));
         }
         mdl->setModelDaten(data);
@@ -347,6 +350,23 @@ void FactoryClient::entityAPIRequest(
     cs.unlock();
 }
 
+void FactoryClient::blockAPIRequest(
+    Vec3<int> pos, char* message, unsigned short length)
+{
+    if (!foreground) return;
+    cs.lock();
+    length += 14;
+    foreground->sende((char*)&length, 2);
+    char msgId = 1;
+    foreground->sende(&msgId, 1);
+    foreground->sende(&msgId, 1);
+    foreground->sende((char*)&pos.x, 4);
+    foreground->sende((char*)&pos.y, 4);
+    foreground->sende((char*)&pos.z, 4);
+    foreground->sende(message, length - 14);
+    cs.unlock();
+}
+
 void FactoryClient::chunkAPIRequest(
     Punkt center, char* message, unsigned short length)
 {

+ 1 - 0
FactoryCraft/FactoryClient.h

@@ -42,6 +42,7 @@ public:
     void sendPlayerAction(char* data, unsigned short length);
     void sendPlayerMovement(MovementFrame& frame);
     void entityAPIRequest(int entityId, char* message, unsigned short length);
+    void blockAPIRequest(Vec3<int> pos, char* message, unsigned short length);
     void chunkAPIRequest(
         Framework::Punkt center, char* message, unsigned short length);
     void inventoryAPIRequest(