Kaynağa Gözat

fix some issues with the map

Kolja Strohm 1 yıl önce
ebeveyn
işleme
13831b8a79

+ 2 - 1
FactoryCraft/BlockType.h

@@ -56,10 +56,11 @@ private:
     bool lightSource;
     const char* name;
     const bool needModelSubscription;
-    int initialMapColor;
 
 protected:
+    int initialMapColor;
     Block* defaultBlock;
+
     BlockType(int id,
         Block* defaultBlock,
         ModelInfo model,

+ 18 - 6
FactoryCraft/ChunkMap.cpp

@@ -3,6 +3,14 @@
 #include "Chunk.h"
 #include "Constants.h"
 
+ChunkMap::ChunkMap(Framework::Punkt chunkCenter)
+    : ReferenceCounter(),
+      chunkCenter(chunkCenter)
+{
+    pixels = new MapPixel[CHUNK_SIZE * CHUNK_SIZE];
+    memset(pixels, 0, sizeof(MapPixel) * CHUNK_SIZE * CHUNK_SIZE);
+}
+
 ChunkMap::ChunkMap(Chunk* zChunk)
     : ReferenceCounter(),
       chunkCenter(zChunk->location)
@@ -28,13 +36,16 @@ ChunkMap::ChunkMap(Chunk* zChunk)
                 int color1 = 0;
                 int color2 = 0;
                 if (visible) color2 = block2->getMapColor();
-                visible = block2->isVisible();
+                visible = block2->isPassable() || block2->isTransparent();
                 if (visible) color1 = block1->getMapColor();
-                visible = block1->isVisible();
+                visible = block1->isPassable() || block1->isTransparent();
                 if (color1 || color2)
                 {
-                    blocksBuffer[256 - ++count] = {(unsigned char)height,
-                        (color1 >> 24) > (color2 >> 24) ? color1 : color2};
+                    MapBlock tmp = {(unsigned char)height,
+                        ((color1 >> 24) & 0xFF) > ((color2 >> 24) & 0xFF)
+                            ? color1
+                                                                 : color2};
+                    blocksBuffer[256 - ++count] = tmp;
                 }
             }
             int i = x * CHUNK_SIZE + y;
@@ -81,8 +92,9 @@ void ChunkMap::update(
     cs.lock();
     int index = x * CHUNK_SIZE + y;
     bool found = 0;
-    int resultColor = (color1 >> 24) > (color2 >> 24) ? color1 : color2;
-    bool removed = !(resultColor >> 24);
+    int resultColor
+        = ((color1 >> 24) & 0xFF) > ((color2 >> 24) & 0xFF) ? color1 : color2;
+    bool removed = !((resultColor >> 24) & 0xFF);
     for (int i = 0; i < pixels[index].len; i++)
     {
         if (pixels[index].blocks[i].height == height)

+ 4 - 3
FactoryCraft/ChunkMap.h

@@ -6,7 +6,7 @@
 #include <ReferenceCounter.h>
 #include <Critical.h>
 
-#pragma pack(1)
+#pragma pack(push, 1)
 
 // stores the color aof the map at a specific height
 struct MapBlock
@@ -23,7 +23,7 @@ struct MapPixel
     MapBlock* blocks;
 };
 
-#pragma pack(0)
+#pragma pack(pop)
 
 class Chunk;
 
@@ -36,7 +36,8 @@ private:
     Framework::Critical cs;
 
 public:
-    ChunkMap(Chunk *zChunk);
+    ChunkMap(Framework::Punkt chunkCenter);
+    ChunkMap(Chunk* zChunk);
     ChunkMap(Framework::StreamReader* zReader);
     ~ChunkMap();
 

+ 6 - 2
FactoryCraft/Dimension.cpp

@@ -94,6 +94,8 @@ void Dimension::api(Framework::InMemoryBuffer* zRequest,
             char addr[8];
             getAddrOfWorld(location, addr);
             ChunkMap* res = map->getMap(addr, 8, location);
+            // create an empty map for a chunk that does not yet exist
+            if (!res) res = new ChunkMap(location);
             zResponse->sendMap(res);
             zResponse->setUseBackground();
             res->release();
@@ -874,9 +876,11 @@ void Dimension::updateMap(int x, int y, int height)
     bool visible = 1;
     if (h2 != WORLD_HEIGHT - 1)
     {
-        visible = zBlockOrDefault({x, y, h2 + 1})->isVisible();
+        const Block* b3 = zBlockOrDefault({x, y, h2 + 1});
+        visible = b3->isPassable() || b3->isTransparent();
     }
-    int color1 = b2->isVisible() ? b1->getMapColor() : 0;
+    int color1
+        = (b2->isPassable() || b2->isTransparent()) ? b1->getMapColor() : 0;
     int color2 = visible ? b2->getMapColor() : 0;
     char addr[8];
     Punkt center = Game::INSTANCE->getChunkCenter(x, y);

+ 4 - 3
FactoryCraft/Dimension.h

@@ -5,9 +5,9 @@
 #include <Thread.h>
 
 #include "Chunk.h"
+#include "DimensionMap.h"
 #include "MultiblockStructure.h"
 #include "NetworkMessage.h"
-#include "DimensionMap.h"
 
 struct RequestQueue
 {
@@ -28,8 +28,6 @@ private:
     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;
     Framework::Array<Framework::Vec3<int>> lightUpdateQueue;
     Framework::Array<Framework::Vec3<int>> priorizedLightUpdateQueue;
     Framework::Critical lightCs;
@@ -41,6 +39,9 @@ private:
     DimensionMap* map;
     bool stop;
 
+    void getAddrOf(Framework::Punkt cPos, char* addr) const;
+    void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
+
 public:
     Dimension(int id);
     ~Dimension();

+ 1 - 0
FactoryCraft/LightSources.cpp

@@ -141,5 +141,6 @@ BasicLightSourceBlockType* BasicLightSourceBlockType::setHardness(
 BasicLightSourceBlockType* BasicLightSourceBlockType::setColor(int color)
 {
     this->color = color;
+    this->initialMapColor = color;
     return this;
 }