Răsfoiți Sursa

improve fluid system

Kolja Strohm 1 an în urmă
părinte
comite
93b14b8be6

+ 20 - 15
FactoryCraft/Block.cpp

@@ -18,7 +18,9 @@ Block::Block(const BlockType* zType,
       location(pos),
       maxHP((float)maxHP),
       needRequestModelInfo(needRequestModelInfo),
-      partOfModel(0)
+      partOfModel(0),
+    flowOptions(0),
+    distanceToSource(0)
 {
     hp = (float)maxHP;
     memset(sideVisible, 0, 6);
@@ -43,8 +45,9 @@ void Block::beforeRender(
     FactoryCraftModel::beforeRender(api, zVertexShader, zPixelShader);
 }
 
-void Block::setFill(short fill) {
-    this->fill = fill;
+void Block::setFlow(char flowOptions, char distanceToSource) {
+    this->flowOptions = flowOptions;
+    this->distanceToSource = distanceToSource;
 }
 
 void Block::api(char* message)
@@ -81,18 +84,15 @@ void Block::api(char* message)
             }
             break;
         }
-    case 2: // update fluid fill state
+    case 2: // update fluid state
         {
-            short tmp = *(short*)(message + 1);
-            if (tmp != fill)
+        	flowOptions = message[1];
+            distanceToSource = message[2];
+            Chunk* zChunk = World::INSTANCE->zChunk(
+                World::INSTANCE->getChunkCenter(location.x, location.y));
+            if (zChunk)
             {
-                fill = tmp;
-                Chunk* zChunk = World::INSTANCE->zChunk(
-                    World::INSTANCE->getChunkCenter(location.x, location.y));
-                if (zChunk)
-                {
-                    zChunk->setModelChanged(partOfModel);
-                }
+                zChunk->setModelChanged(partOfModel);
             }
         }
     }
@@ -256,7 +256,12 @@ int Block::getPartOfModels() const
     return partOfModel;
 }
 
-short Block::getFill() const
+char Block::getFlowOptions() const
+{
+    return flowOptions;
+}
+
+char Block::getDistanceToSource() const
 {
-    return fill;
+    return distanceToSource;
 }

+ 5 - 3
FactoryCraft/Block.h

@@ -23,7 +23,8 @@ protected:
     unsigned char lightData[6 * 6];
     char needRequestModelInfo;
     int partOfModel;
-    short fill;
+    char flowOptions;
+    char distanceToSource;
 
     void beforeRender(
         GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader) override;
@@ -38,7 +39,7 @@ public:
         bool needRequestModelInfo);
     virtual ~Block();
 
-    void setFill(short fill);
+    void setFlow(char flowOptions, char distanceToSource);
     void api(char* message);
     void copyLightTo(Block* zB);
     void setLightData(Direction dir, unsigned char* data);
@@ -52,7 +53,8 @@ public:
     Skeleton* zSkeleton() const;
     Text printLightInfo();
     int getPartOfModels() const;
-    short getFill() const;
+    char getFlowOptions() const;
+    char getDistanceToSource() const;
     
     friend Chunk;
 };

+ 10 - 2
FactoryCraft/BlockType.cpp

@@ -9,14 +9,17 @@ BlockType::BlockType(int id,
     bool needsInstance,
     ModelInfo model,
     int initialMaxHP,
-    bool needModelSubscription, bool fluid)
+    bool needModelSubscription,
+    bool fluid,
+    char maxFlowDistance)
     : ReferenceCounter(),
       id(id),
       needsInstance(needsInstance),
       model(model),
       initialMaxHP(initialMaxHP),
       needModelSubscription(needModelSubscription),
-      fluid(fluid)
+      fluid(fluid),
+      maxFlowDistance(maxFlowDistance)
 {}
 
 BlockType::~BlockType() {}
@@ -52,6 +55,11 @@ bool BlockType::isFluid() const
 	return fluid;
 }
 
+char BlockType::getMaxFlowDistance() const
+{
+    return maxFlowDistance;
+}
+
 const ModelInfo& BlockType::getModelInfo() const
 {
     return model;

+ 4 - 1
FactoryCraft/BlockType.h

@@ -17,6 +17,7 @@ private:
     int initialMaxHP;
     bool needModelSubscription;
     bool fluid;
+    char maxFlowDistance;
     ModelInfo model;
 
 public:
@@ -25,12 +26,14 @@ public:
         ModelInfo model,
         int initialMaxHP,
         bool needModelSubscription,
-        bool fluid);
+        bool fluid,
+        char maxFlowDistance);
     ~BlockType();
     Block* createBlock(Framework::Vec3<int> position);
     bool doesNeedInstance() const;
     bool doesNeedModelSubscription() const;
     bool isFluid() const;
+    char getMaxFlowDistance() const;
 
     const ModelInfo& getModelInfo() const;
 

+ 5 - 3
FactoryCraft/Chunk.cpp

@@ -151,10 +151,12 @@ void Chunk::load(Framework::StreamReader* zReader)
     {
         int index;
         zReader->lese((char*)&index, 4);
-        short fill = 0;
+        char flowOptions = 0;
+        char distanceToSource = 0;
         if (blockTypes[id]->isFluid())
         {
-            zReader->lese((char*)&fill, 2);
+            zReader->lese(&flowOptions, 1);
+            zReader->lese(&distanceToSource, 1);
         }
         pos = Vec3<int>((index / WORLD_HEIGHT) / CHUNK_SIZE,
             (index / WORLD_HEIGHT) % CHUNK_SIZE,
@@ -166,7 +168,7 @@ void Chunk::load(Framework::StreamReader* zReader)
                 {pos.x + location.x - CHUNK_SIZE / 2,
                     pos.y + location.y - CHUNK_SIZE / 2,
                     pos.z});
-            b->setFill(fill);
+            b->setFlow(flowOptions, distanceToSource);
             blocks[index] = b;
             cs.unlock();
             vcs.lock();

+ 7 - 2
FactoryCraft/ChunkFluidModel.cpp

@@ -197,10 +197,15 @@ void ChunkFluidModel::buildModel()
                                 = groundVertexCount;
                             groundVerticies[groundVertexCount++]
                                 = vBuffer[polygon->indexList[vi]];
-                            if (getDirectionFromIndex(index) == TOP)
+                            if (getDirectionFromIndex(index) & TOP)
                             {
+                                char maxFlowDist = blocks()[i]
+                                                       ->zBlockType()
+                                                       ->getMaxFlowDistance();
+                                float dist = (float)(maxFlowDist + 1 - blocks()[i]
+                                                    ->getDistanceToSource()) / (float)(maxFlowDist + 1);
                                 groundVerticies[groundVertexCount - 1].pos.z
-                                    -= (1 - blocks()[i]->getFill() / 1000.f);
+                                    -= (1 - dist);
                             }
                             groundVerticies[groundVertexCount - 1].pos
                                 += blocks()[i]->getPos()

+ 22 - 22
FactoryCraft/CustomUIDX11PixelShader.h

@@ -355,10 +355,10 @@ ret
 
 const BYTE CustomUIDX11PixelShader[] =
 {
-     68,  88,  66,  67, 171, 201, 
-    199,  85, 115, 128, 158, 198, 
-    123, 194,  73,  66,  69, 176, 
-     71, 132,   1,   0,   0,   0, 
+     68,  88,  66,  67, 140, 231, 
+     96, 132, 125, 195, 116, 122, 
+      8, 235,   0, 210,   0, 223, 
+    250,  99,   1,   0,   0,   0, 
     192, 137,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     252,   4,   0,   0, 188,   5, 
@@ -1625,10 +1625,10 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    192, 168, 216, 100,   1,   0, 
-      0,   0,  45, 148,  49,  15, 
-     55,  88,  40,  79, 151,  58, 
-     76, 100, 250, 142, 212, 168, 
+    244, 137, 224, 100,   1,   0, 
+      0,   0,  47,  36, 186,  99, 
+    217, 121,  67,  68, 145,  13, 
+    228,  43, 248, 106, 111, 255, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1801,10 +1801,10 @@ const BYTE CustomUIDX11PixelShader[] =
       3,   0,  28,  19,   2,   0, 
      65,  36,   1,   0, 236, 179, 
       1,   0, 125, 226,   0,   0, 
-     21, 230,   0,   0, 133, 128, 
-      0,   0,  73,  20,   1,   0, 
-    153, 189,   3,   0,  19, 140, 
-      1,   0, 209,  10,   2,   0, 
+     21, 230,   0,   0, 216, 174, 
+      3,   0,  73,  20,   1,   0, 
+    153, 189,   3,   0, 166, 158, 
+      2,   0, 209,  10,   2,   0, 
      53, 174,   3,   0, 146, 230, 
       3,   0,  98, 163,   2,   0, 
     118,  19,   1,   0, 140, 144, 
@@ -3076,8 +3076,8 @@ const BYTE CustomUIDX11PixelShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  32,  32, 
      27, 226,  48,   1, 128,   0, 
-      0,   0,  73, 125, 221, 102, 
-    204, 205, 217,   1,   1,   0, 
+      0,   0, 188, 157, 156, 191, 
+    126, 210, 217,   1,   1,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4330,13 +4330,13 @@ const BYTE CustomUIDX11PixelShader[] =
       8,  16,   0,   0,   1,   0, 
       0,   2,  14,   0,  23,  21, 
       0,  16,   0,   0,   3,   2, 
-     16,  47,   0,   0, 242, 241, 
+      0,  23,   0,   0, 242, 241, 
      10,   0,  24,  21,  10,  16, 
       0,   0,   1,   0,   1,   0, 
      10,   0,  24,  21,  11,  16, 
       0,   0,   1,   0,   0,   2, 
      14,   0,  23,  21,   0,   0, 
-      0,   0,  10,   2,  16,  47, 
+      0,   0,  10,   2,   0,  23, 
       0,   0, 242, 241,  10,   0, 
      24,  21,  13,  16,   0,   0, 
       1,   0,   1,   0,  10,   0, 
@@ -5806,11 +5806,11 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 192, 168, 216, 100, 
-      1,   0,   0,   0,  45, 148, 
-     49,  15,  55,  88,  40,  79, 
-    151,  58,  76, 100, 250, 142, 
-    212, 168, 174,   0,   0,   0, 
+     49,   1, 244, 137, 224, 100, 
+      1,   0,   0,   0,  47,  36, 
+    186,  99, 217, 121,  67,  68, 
+    145,  13, 228,  43, 248, 106, 
+    111, 255, 174,   0,   0,   0, 
      47,  76, 105, 110, 107,  73, 
     110, 102, 111,   0,  47, 110, 
      97, 109, 101, 115,   0,  47, 
@@ -5910,7 +5910,7 @@ const BYTE CustomUIDX11PixelShader[] =
       2,   0,   9,   0,  88,   9, 
       0,   0,   0,   0,   0,   0, 
     156,  13,   0,   0,   1,   0, 
-    163, 143,   0,   0,   0,   0, 
+     25, 249,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,  84, 101, 120, 116, 
     117, 114, 101,  80, 105, 120, 

+ 17 - 17
FactoryCraft/CustomUIDX11VertexShader.h

@@ -281,10 +281,10 @@ ret
 
 const BYTE CustomUIDX11VertexShader[] =
 {
-     68,  88,  66,  67,  93,  90, 
-     93,  57, 122, 213,  63, 168, 
-     91,  28, 153, 244,  90,  82, 
-    139, 247,   1,   0,   0,   0, 
+     68,  88,  66,  67,   2, 139, 
+     37,  95, 152, 158, 208, 223, 
+     95, 199, 107,  74, 222, 240, 
+    140,  66,   1,   0,   0,   0, 
     124, 103,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      76,   4,   0,   0,   4,   5, 
@@ -1454,11 +1454,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 192, 168, 216, 100, 
-      1,   0,   0,   0, 234, 162, 
-     64, 102, 133,  53, 194,  70, 
-    177, 194,  88, 215, 116, 147, 
-     79, 245,   0,   0,   0,   0, 
+     49,   1, 244, 137, 224, 100, 
+      1,   0,   0,   0,   9, 119, 
+    197, 160, 200,   4, 151,  73, 
+    177, 115, 197,  37, 237,  38, 
+    203, 248,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2393,8 +2393,8 @@ const BYTE CustomUIDX11VertexShader[] =
     106, 101,  99, 116, 105, 111, 
     110,  59,  13,  10, 125,  13, 
      10,  13,  27, 226,  48,   1, 
-    128,   0,   0,   0, 218,  25, 
-    250, 102, 204, 205, 217,   1, 
+    128,   0,   0,   0, 105,  31, 
+    184, 191, 126, 210, 217,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4355,11 +4355,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 192, 168, 
-    216, 100,   1,   0,   0,   0, 
-    234, 162,  64, 102, 133,  53, 
-    194,  70, 177, 194,  88, 215, 
-    116, 147,  79, 245, 175,   0, 
+    148,  46,  49,   1, 244, 137, 
+    224, 100,   1,   0,   0,   0, 
+      9, 119, 197, 160, 200,   4, 
+    151,  73, 177, 115, 197,  37, 
+    237,  38, 203, 248, 175,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -4459,7 +4459,7 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   2,   0,   9,   0, 
     148,   7,   0,   0,   0,   0, 
       0,   0, 220,   9,   0,   0, 
-      1,   0,  21,  44,   0,   0, 
+      1,   0, 193, 132,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  86, 

+ 5 - 1
FactoryCraft/FactoryClient.cpp

@@ -49,6 +49,9 @@ void FactoryClient::loadServerInfo()
         foregroundReader->lese((char*)&needsSubscription, 1);
         bool fluid;
         foregroundReader->lese((char*)&fluid, 1);
+        char maxFlowDistance = 0;
+        if (fluid)
+			foregroundReader->lese((char*)&maxFlowDistance, 1);
         int maxHp;
         foregroundReader->lese((char*)&maxHp, 4);
         blockTypes[i] = new BlockType(id,
@@ -56,7 +59,8 @@ void FactoryClient::loadServerInfo()
             ModelInfo(foregroundReader),
             maxHp,
             needsSubscription,
-            fluid);
+            fluid,
+            maxFlowDistance);
     }
     foregroundReader->lese((char*)&itemTypeCount, 4);
     itemTypes = new ItemType*[itemTypeCount];