Explorar o código

add a map of the landscape

Kolja Strohm %!s(int64=2) %!d(string=hai) anos
pai
achega
713146c71a

+ 74 - 0
FactoryCraft/ChunkMap.cpp

@@ -0,0 +1,74 @@
+#include "ChunkMap.h"
+
+#include "Constants.h"
+
+ChunkMap::ChunkMap(Framework::StreamReader* zReader)
+    : ReferenceCounter(),
+      maxHeight(0)
+{
+    pixels = new MapPixel[CHUNK_SIZE * CHUNK_SIZE];
+    memset(pixels, 0, sizeof(MapPixel) * CHUNK_SIZE * CHUNK_SIZE);
+    zReader->lese((char*)&chunkCenter.x, 4);
+    zReader->lese((char*)&chunkCenter.y, 4);
+    pixels = new MapPixel[CHUNK_SIZE * CHUNK_SIZE];
+    memset(pixels, 0, sizeof(MapPixel) * CHUNK_SIZE * CHUNK_SIZE);
+    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE; i++)
+    {
+        zReader->lese((char*)&pixels[i].len, 1);
+        if (pixels[i].len > 0)
+        {
+            pixels[i].blocks = new MapBlock[pixels[i].len];
+            zReader->lese(
+                (char*)pixels[i].blocks, (int)sizeof(MapBlock) * pixels[i].len);
+        }
+    }
+    rendered.neuBild(16, 16, 0xA0000000);
+    setMaxHeight(255);
+}
+
+ChunkMap::~ChunkMap()
+{
+    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE; i++)
+    {
+        delete[] pixels[i].blocks;
+    }
+    delete[] pixels;
+}
+
+void ChunkMap::setMaxHeight(unsigned char maxHeight)
+{
+    if (maxHeight != this->maxHeight)
+    {
+        rendered.fillRegion(0, 0, CHUNK_SIZE, CHUNK_SIZE, 0xA0000000);
+        this->maxHeight = maxHeight;
+        for (int x = 0; x < CHUNK_SIZE; x++)
+        {
+            for (int y = 0; y < CHUNK_SIZE; y++)
+            {
+                int i = x * CHUNK_SIZE + y;
+                bool first = 1;
+                for (int j = 0; j < pixels[i].len
+                                && pixels[i].blocks[j].height <= maxHeight;
+                     j++)
+                {
+                    if (first)
+                    {
+                        rendered.setPixelDP(x, y, 0xFF000000);
+                        first = 0;
+                    }
+                    rendered.alphaPixel2D(x, y, pixels[i].blocks[j].color);
+                }
+            }
+        }
+    }
+}
+
+const Framework::Bild& ChunkMap::getRenderedImage() const
+{
+    return rendered;
+}
+
+Framework::Punkt ChunkMap::getChunkCenter() const
+{
+    return chunkCenter;
+}

+ 40 - 0
FactoryCraft/ChunkMap.h

@@ -0,0 +1,40 @@
+#pragma once
+
+#include <Bild.h>
+
+#pragma pack(push, 1)
+
+// stores the color aof the map at a specific height
+struct MapBlock
+{
+    unsigned char height;
+    int color;
+};
+
+// stores the colors at all heights of a specific x and y position on the map.
+// there can by only 256 colors stored per position
+struct MapPixel
+{
+    unsigned char len;
+    MapBlock* blocks;
+};
+
+#pragma pack(pop)
+
+class ChunkMap : public Framework::ReferenceCounter
+{
+private:
+    MapPixel* pixels;
+    Framework::Punkt chunkCenter;
+    Framework::Bild rendered;
+    unsigned char maxHeight;
+    
+public:
+    ChunkMap(Framework::StreamReader* zReader);
+    ~ChunkMap();
+    
+    void setMaxHeight(unsigned char maxHeight);
+    
+    const Framework::Bild &getRenderedImage() const;
+    Framework::Punkt getChunkCenter() const;
+};

+ 22 - 22
FactoryCraft/CustomUIDX11PixelShader.h

@@ -257,10 +257,10 @@ ret
 
 const BYTE CustomUIDX11PixelShader[] =
 {
-     68,  88,  66,  67,  46, 150, 
-    195,  67, 173,  54, 189,  35, 
-     37,  33, 101,  50,  98, 127, 
-    243, 161,   1,   0,   0,   0, 
+     68,  88,  66,  67, 254, 231, 
+      2, 242,  19,  94,  75, 107, 
+    180, 252, 149, 150, 201,  81, 
+    132,  51,   1,   0,   0,   0, 
     164, 118,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     252,   4,   0,   0, 164,   5, 
@@ -1394,11 +1394,11 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 112,  48, 195,  99, 
-      1,   0,   0,   0,  24,  13, 
-    110,  22,  12, 161,  27,  70, 
-    128, 231,  85, 108, 215,  61, 
-    170,  44,   0,   0,   0,   0, 
+     49,   1,  60, 110, 214,  99, 
+      1,   0,   0,   0,  34, 204, 
+     48, 204,  54,  20, 178,  78, 
+    191, 173,   5, 221,  34,  94, 
+    241, 113,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -1569,10 +1569,10 @@ const BYTE CustomUIDX11PixelShader[] =
       3,   0, 194,  82,   1,   0, 
      43, 236,   3,   0,  28,  19, 
       2,   0,  65,  36,   1,   0, 
-    236, 179,   1,   0,  82, 162, 
+    236, 179,   1,   0,  32,  72, 
       1,   0, 125,  10,   2,   0, 
-    125, 181,   2,   0,  72, 145, 
-      0,   0, 193,  33,   3,   0, 
+    125, 181,   2,   0,  46,   6, 
+      1,   0, 193,  33,   3,   0, 
      65, 185,   2,   0, 146, 230, 
       3,   0,  53, 174,   3,   0, 
     118,  19,   1,   0,  98, 163, 
@@ -2589,8 +2589,8 @@ const BYTE CustomUIDX11PixelShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  32,  32, 
      32,  32,  27, 226,  48,   1, 
-    128,   0,   0,   0, 232,   1, 
-     45, 216, 105,  40, 217,   1, 
+    128,   0,   0,   0,  89,  37, 
+    244, 216, 225,  51, 217,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -3579,14 +3579,14 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,  23,   0,   1,   0, 
       5,  16,   0,   0,  14,   0, 
      23,  21,   0,  16,   0,   0, 
-      3,   2, 224,  96,   0,   0, 
+      3,   2, 240,  24,   0,   0, 
     242, 241,  10,   0,  24,  21, 
       8,  16,   0,   0,   1,   0, 
       1,   0,  10,   0,  24,  21, 
       9,  16,   0,   0,   1,   0, 
       0,   2,  14,   0,  23,  21, 
       0,   0,   0,   0,  10,   2, 
-    224,  96,   0,   0, 242, 241, 
+    240,  24,   0,   0, 242, 241, 
      10,   0,  24,  21,  11,  16, 
       0,   0,   1,   0,   1,   0, 
      10,   0,  24,  21,  12,  16, 
@@ -4807,11 +4807,11 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 112,  48, 
-    195,  99,   1,   0,   0,   0, 
-     24,  13, 110,  22,  12, 161, 
-     27,  70, 128, 231,  85, 108, 
-    215,  61, 170,  44, 174,   0, 
+    148,  46,  49,   1,  60, 110, 
+    214,  99,   1,   0,   0,   0, 
+     34, 204,  48, 204,  54,  20, 
+    178,  78, 191, 173,   5, 221, 
+     34,  94, 241, 113, 174,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -4911,7 +4911,7 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   2,   0,   9,   0, 
      76,   7,   0,   0,   0,   0, 
       0,   0, 100,   9,   0,   0, 
-      1,   0, 137,  59,   0,   0, 
+      1,   0, 152,  25,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  80, 

+ 16 - 16
FactoryCraft/CustomUIDX11VertexShader.h

@@ -237,10 +237,10 @@ ret
 
 const BYTE CustomUIDX11VertexShader[] =
 {
-     68,  88,  66,  67, 220,  11, 
-    186, 195, 246,  42, 226, 245, 
-    142, 170,  21, 102,  89,  42, 
-     84, 181,   1,   0,   0,   0, 
+     68,  88,  66,  67,  29, 180, 
+    253, 108, 175,  62,   9, 222, 
+    149, 197,   1,  67,  13, 153, 
+    136, 181,   1,   0,   0,   0, 
     216,  93,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      84,   3,   0,   0,  12,   4, 
@@ -1340,11 +1340,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 112,  48, 195,  99, 
-      1,   0,   0,   0, 217, 208, 
-    202, 191, 222, 174,  30,  73, 
-    175, 163, 237, 211, 252, 179, 
-     65, 165,   0,   0,   0,   0, 
+     49,   1,  60, 110, 214,  99, 
+      1,   0,   0,   0, 206, 106, 
+    240,   6,   3, 239, 245,  77, 
+    172,  46, 187,  47, 144,  34, 
+     36, 211,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2109,7 +2109,7 @@ const BYTE CustomUIDX11VertexShader[] =
     105, 111, 110,  59,  13,  10, 
     125,  13,  10,  13,  27, 226, 
      48,   1, 128,   0,   0,   0, 
-    152, 117,  73, 216, 105,  40, 
+    232,  32,  15, 217, 225,  51, 
     217,   1,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -3900,11 +3900,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 112,  48, 195,  99, 
-      1,   0,   0,   0, 217, 208, 
-    202, 191, 222, 174,  30,  73, 
-    175, 163, 237, 211, 252, 179, 
-     65, 165, 175,   0,   0,   0, 
+     49,   1,  60, 110, 214,  99, 
+      1,   0,   0,   0, 206, 106, 
+    240,   6,   3, 239, 245,  77, 
+    172,  46, 187,  47, 144,  34, 
+     36, 211, 175,   0,   0,   0, 
      47,  76, 105, 110, 107,  73, 
     110, 102, 111,   0,  47, 110, 
      97, 109, 101, 115,   0,  47, 
@@ -4004,7 +4004,7 @@ const BYTE CustomUIDX11VertexShader[] =
       2,   0,   9,   0,  64,   6, 
       0,   0,   0,   0,   0,   0, 
     236,   8,   0,   0,   1,   0, 
-     29,  22,   0,   0,   0,   0, 
+    205, 126,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,  84, 101, 120, 116, 
     117, 114, 101,  86, 101, 114, 

+ 266 - 0
FactoryCraft/DimensionMap.cpp

@@ -0,0 +1,266 @@
+#include "DimensionMap.h"
+
+#include "Constants.h"
+#include "World.h"
+
+DimensionMap::DimensionMap()
+    : ZeichnungHintergrund(),
+      originChunkCenter(0, 0),
+      scrollOffset(0, 0),
+      chunkCount(0),
+      pixelsPerBlock(16),
+      maxHeight(255),
+      waitingForChunk(0),
+      drag(0)
+{
+    setStyle(Style::Sichtbar | Style::Erlaubt);
+    chunks = new Framework::Trie<ChunkMap>();
+    setMausEreignis(_ret1ME);
+    requestNextChunk();
+}
+
+DimensionMap::~DimensionMap()
+{
+    chunks->release();
+}
+
+void DimensionMap::getAddrOf(Punkt cPos, char* addr) const
+{
+    *(int*)addr = cPos.x;
+    *((int*)addr + 1) = cPos.y;
+}
+
+void DimensionMap::getAddrOfWorld(Punkt wPos, char* addr) const
+{
+    // needed because otherwise would (-8, -8) have the same
+    // adress as (8, 8)
+    if (wPos.x < 0) wPos.x -= CHUNK_SIZE;
+    if (wPos.y < 0) wPos.y -= CHUNK_SIZE;
+
+    wPos /= CHUNK_SIZE;
+    getAddrOf(wPos, addr);
+}
+
+Framework::Punkt DimensionMap::getMinVisibleChunkCenter(
+    Framework::Punkt& screenPos) const
+{
+    screenPos = getSize() / 2 - scrollOffset;
+    Punkt currentChunkCenter = originChunkCenter;
+    while (screenPos.x + pixelsPerBlock * (CHUNK_SIZE / 2) >= 0)
+    {
+        screenPos.x -= pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.x -= CHUNK_SIZE;
+    }
+    while (screenPos.y + pixelsPerBlock * (CHUNK_SIZE / 2) >= 0)
+    {
+        screenPos.y -= pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.y -= CHUNK_SIZE;
+    }
+    while (screenPos.x + pixelsPerBlock * (CHUNK_SIZE / 2) < 0)
+    {
+        screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.x += CHUNK_SIZE;
+    }
+    while (screenPos.y + pixelsPerBlock * (CHUNK_SIZE / 2) < 0)
+    {
+        screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.y += CHUNK_SIZE;
+    }
+    return currentChunkCenter;
+}
+
+Framework::Punkt DimensionMap::getMaxVisibleChunkCenter(
+    Framework::Punkt& screenPos) const
+{
+    screenPos = getSize() / 2 - scrollOffset;
+    Punkt currentChunkCenter = originChunkCenter;
+    while (screenPos.x - pixelsPerBlock * (CHUNK_SIZE / 2) < getBreite())
+    {
+        screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.x += CHUNK_SIZE;
+    }
+    while (screenPos.y - pixelsPerBlock * (CHUNK_SIZE / 2) < getHeight())
+    {
+        screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.y += CHUNK_SIZE;
+    }
+    while (screenPos.x - pixelsPerBlock * (CHUNK_SIZE / 2) >= getBreite())
+    {
+        screenPos.x -= pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.x -= CHUNK_SIZE;
+    }
+    while (screenPos.y - pixelsPerBlock * (CHUNK_SIZE / 2) >= getHeight())
+    {
+        screenPos.y -= pixelsPerBlock * CHUNK_SIZE;
+        currentChunkCenter.y -= CHUNK_SIZE;
+    }
+    return currentChunkCenter;
+}
+
+bool DimensionMap::tick(double time)
+{
+    if (lastSize != getSize())
+    {
+        lastSize = getSize();
+        requestNextChunk();
+    }
+    return ZeichnungHintergrund::tick(time);
+}
+
+void DimensionMap::requestNextChunk()
+{
+    cs.lock();
+    if (waitingForChunk)
+    {
+        cs.unlock();
+        return;
+    }
+    if (chunkCount == 0)
+    {
+        waitingForChunk = 1;
+        Vec3<float> playerPos
+            = World::INSTANCE->getCurrentPlayerEntity()->getPos();
+        char msg[9];
+        msg[0] = 2;
+        *(int*)(msg + 1) = (int)playerPos.x;
+        *(int*)(msg + 5) = (int)playerPos.y;
+        World::INSTANCE->zClient()->dimensionAPIRequest(msg, 9);
+    }
+    else
+    {
+        Punkt minScreenPos;
+        Punkt minVisibleChunk = getMinVisibleChunkCenter(minScreenPos);
+        Punkt maxScreenPos;
+        Punkt maxVisibleChunk = getMaxVisibleChunkCenter(maxScreenPos);
+        Punkt screenPos = minScreenPos;
+        Punkt screenCenter = getSize() / 2;
+        double minDist = -1;
+        Punkt resultChunk(0, 0);
+        char addr[8];
+        for (int x = minVisibleChunk.x; x <= maxVisibleChunk.x; x += CHUNK_SIZE)
+        {
+            for (int y = minVisibleChunk.y; y <= maxVisibleChunk.y;
+                 y += CHUNK_SIZE)
+            {
+                getAddrOfWorld({x, y}, addr);
+                if (!chunks->z(addr, 8))
+                {
+                    if (minDist < 0
+                        || (screenCenter - screenPos).getLengthSq() < minDist)
+                    {
+                        minDist = (screenCenter - screenPos).getLengthSq();
+                        resultChunk = {x, y};
+                    }
+                }
+                screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+            }
+            screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+            screenPos.y = minScreenPos.y;
+        }
+        if (minDist >= 0)
+        {
+            waitingForChunk = 1;
+            char msg[9];
+            msg[0] = 2;
+            *(int*)(msg + 1) = (int)resultChunk.x;
+            *(int*)(msg + 5) = (int)resultChunk.y;
+            World::INSTANCE->zClient()->dimensionAPIRequest(msg, 9);
+        }
+    }
+    cs.unlock();
+}
+
+void DimensionMap::addChunk(ChunkMap* chunk)
+{
+    cs.lock();
+    if (chunkCount == 0) originChunkCenter = chunk->getChunkCenter();
+    char addr[8];
+    getAddrOfWorld(chunk->getChunkCenter(), addr);
+    chunks->set(addr, 8, chunk);
+    chunkCount++;
+    waitingForChunk = 0;
+    cs.unlock();
+    requestNextChunk();
+}
+
+void DimensionMap::render(Framework::Bild& rObj)
+{
+    ZeichnungHintergrund::render(rObj);
+    if (!rObj.setDrawOptions(innenPosition, innenSize)) return;
+    cs.lock();
+    Punkt minScreenPos;
+    Punkt minVisibleChunk = getMinVisibleChunkCenter(minScreenPos);
+    Punkt maxScreenPos;
+    Punkt maxVisibleChunk = getMaxVisibleChunkCenter(maxScreenPos);
+    char addr[8];
+    Punkt screenPos = minScreenPos;
+    for (int x = minVisibleChunk.x; x <= maxVisibleChunk.x; x += CHUNK_SIZE)
+    {
+        for (int y = minVisibleChunk.y; y <= maxVisibleChunk.y; y += CHUNK_SIZE)
+        {
+            getAddrOfWorld({x, y}, addr);
+            ChunkMap* map = chunks->z(addr, 8);
+            if (map)
+            {
+                map->setMaxHeight((unsigned char)maxHeight);
+                rObj.drawBildSkall(
+                    screenPos.x - (pixelsPerBlock * CHUNK_SIZE) / 2,
+                    screenPos.y - (pixelsPerBlock * CHUNK_SIZE) / 2,
+                    pixelsPerBlock * CHUNK_SIZE,
+                    pixelsPerBlock * CHUNK_SIZE,
+                    map->getRenderedImage());
+            }
+            screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+        }
+        screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+        screenPos.y = minScreenPos.y;
+    }
+    cs.unlock();
+    rObj.releaseDrawOptions();
+}
+
+void DimensionMap::doMausEreignis(Framework::MausEreignis& me, bool userRet)
+{
+    if (me.id == ME_PLinks)
+    {
+        drag = 1;
+        lastMouse = {me.mx, me.my};
+    }
+    if (me.id == ME_RLinks || me.id == ME_Leaves) drag = 0;
+    if (me.id == ME_Bewegung && drag)
+    {
+        scrollOffset -= Punkt(me.mx, me.my) - lastMouse;
+        lastMouse = Punkt(me.mx, me.my);
+        rend = 1;
+        requestNextChunk();
+    }
+    if (me.id == ME_DScroll && pixelsPerBlock > 1)
+    {
+        scrollOffset = (scrollOffset / pixelsPerBlock) * (pixelsPerBlock - 1);
+        pixelsPerBlock--;
+        rend = 1;
+        requestNextChunk();
+    }
+    if (me.id == ME_UScroll)
+    {
+        scrollOffset = (scrollOffset / pixelsPerBlock) * (pixelsPerBlock + 1);
+        pixelsPerBlock++;
+        rend = 1;
+        requestNextChunk();
+    }
+    if (me.id == ME_RRechts)
+    {
+        if (maxHeight != 255)
+        {
+            maxHeight = 255;
+        }
+        else
+        {
+            maxHeight
+                = (int)(World::INSTANCE->getCurrentPlayerEntity()->getPos().z
+                        / 2);
+        }
+        rend = 1;
+    }
+    ZeichnungHintergrund::doMausEreignis(me, userRet);
+}

+ 37 - 0
FactoryCraft/DimensionMap.h

@@ -0,0 +1,37 @@
+#pragma once
+
+#include <Zeichnung.h>
+#include <Trie.h>
+
+#include "ChunkMap.h"
+
+class DimensionMap : public Framework::ZeichnungHintergrund
+{
+private:
+    Framework::Trie<ChunkMap>* chunks;
+    Framework::Punkt originChunkCenter;
+    Framework::Punkt scrollOffset;
+    int chunkCount;
+    int pixelsPerBlock;
+    int maxHeight;
+    bool waitingForChunk;
+    bool drag;
+    Framework::Punkt lastMouse;
+    Framework::Punkt lastSize;
+
+    void getAddrOf(Framework::Punkt cPos, char* addr) const;
+    void getAddrOfWorld(Framework::Punkt wPos, char* addr) const;
+    Framework::Punkt getMinVisibleChunkCenter(Framework::Punkt &screenPos) const;
+    Framework::Punkt getMaxVisibleChunkCenter(
+        Framework::Punkt& screenPos) const;
+
+public:
+    DimensionMap();
+    ~DimensionMap();
+    
+    void requestNextChunk();
+    void addChunk(ChunkMap* chunk);
+    bool tick(double time) override;
+    void render(Framework::Bild& rObj) override;
+    void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
+};

+ 12 - 0
FactoryCraft/FactoryClient.cpp

@@ -396,6 +396,18 @@ void FactoryClient::chunkAPIRequest(
     cs.unlock();
 }
 
+void FactoryClient::dimensionAPIRequest(
+    char* message, unsigned short length)
+{
+    length += 1;
+    cs.lock();
+    foreground->sende((char*)&length, 2);
+    char type = 1;
+    foreground->sende(&type, 1);
+    foreground->sende(message, length - 1);
+    cs.unlock();
+}
+
 void FactoryClient::inventoryAPIRequest(
     Framework::Either<int, Framework::VecN<int, 4>> target,
     char* message,

+ 1 - 0
FactoryCraft/FactoryClient.h

@@ -45,6 +45,7 @@ public:
     void blockAPIRequest(Vec3<int> pos, char* message, unsigned short length);
     void chunkAPIRequest(
         Framework::Punkt center, char* message, unsigned short length);
+    void dimensionAPIRequest(char* message, unsigned short length);
     void inventoryAPIRequest(
         Framework::Either<int, Framework::VecN<int, 4>> target,
         char* message,

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -179,12 +179,14 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="ChatMessage.cpp" />
     <ClCompile Include="ChatOptions.cpp" />
     <ClCompile Include="Chunk.cpp" />
+    <ClCompile Include="ChunkMap.cpp" />
     <ClCompile Include="CraftingGrid.cpp" />
     <ClCompile Include="CraftingRecipies.cpp" />
     <ClCompile Include="CustomDX11API.cpp" />
     <ClCompile Include="Dialog.cpp" />
     <ClCompile Include="Dimension.cpp" />
     <ClCompile Include="AddServerMenu.cpp" />
+    <ClCompile Include="DimensionMap.cpp" />
     <ClCompile Include="DragElement.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="EntityRemovedUpdate.cpp" />
@@ -199,6 +201,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="ItemList.cpp" />
     <ClCompile Include="ItemType.cpp" />
     <ClCompile Include="Load.cpp" />
+    <ClCompile Include="MapWindow.cpp" />
     <ClCompile Include="RecipieGroup.cpp" />
     <ClCompile Include="RecipieIngredient.cpp" />
     <ClCompile Include="RecipieOutput.cpp" />
@@ -225,6 +228,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="ChatMessage.h" />
     <ClInclude Include="ChatOptions.h" />
     <ClInclude Include="Chunk.h" />
+    <ClInclude Include="ChunkMap.h" />
     <ClInclude Include="Constants.h" />
     <ClInclude Include="CraftingGrid.h" />
     <ClInclude Include="CraftingRecipies.h" />
@@ -232,6 +236,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="Dialog.h" />
     <ClInclude Include="Dimension.h" />
     <ClInclude Include="AddServerMenu.h" />
+    <ClInclude Include="DimensionMap.h" />
     <ClInclude Include="DragController.h" />
     <ClInclude Include="DragElement.h" />
     <ClInclude Include="Entity.h" />
@@ -247,6 +252,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="ItemList.h" />
     <ClInclude Include="ItemType.h" />
     <ClInclude Include="Load.h" />
+    <ClInclude Include="MapWindow.h" />
     <ClInclude Include="RecipieGroup.h" />
     <ClInclude Include="RecipieIngredient.h" />
     <ClInclude Include="RecipieOutput.h" />

+ 21 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -56,6 +56,9 @@
     <Filter Include="Menu\chat">
       <UniqueIdentifier>{aa163982-63f3-4fe2-b13d-366055b56a00}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Menu\map">
+      <UniqueIdentifier>{775b26b6-17cd-4eca-9360-a1a2965ea0eb}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Main.cpp">
@@ -190,6 +193,15 @@
     <ClCompile Include="ChatOptions.cpp">
       <Filter>Menu\chat</Filter>
     </ClCompile>
+    <ClCompile Include="ChunkMap.cpp">
+      <Filter>Menu\map</Filter>
+    </ClCompile>
+    <ClCompile Include="DimensionMap.cpp">
+      <Filter>Menu\map</Filter>
+    </ClCompile>
+    <ClCompile Include="MapWindow.cpp">
+      <Filter>Menu\map</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -330,6 +342,15 @@
     <ClInclude Include="ChatOptions.h">
       <Filter>Menu\chat</Filter>
     </ClInclude>
+    <ClInclude Include="ChunkMap.h">
+      <Filter>Menu\map</Filter>
+    </ClInclude>
+    <ClInclude Include="DimensionMap.h">
+      <Filter>Menu\map</Filter>
+    </ClInclude>
+    <ClInclude Include="MapWindow.h">
+      <Filter>Menu\map</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="DX11CustomVertexShader.hlsl">

+ 11 - 2
FactoryCraft/Game.cpp

@@ -77,8 +77,9 @@ Game::Game(Bildschirm* zScreen)
     chatButton->setAlphaFeldFarbe(0x5F337AB7);
     chatButton->setSize(40, 40);
     chatButton->setPosition(5, zScreen->getBackBufferSize().y - 45);
-    chatButton->addStyle(
-        Framework::Knopf::Style::HBild | Framework::Knopf::Style::HAlpha |Framework::Knopf::Style::Hintergrund);
+    chatButton->addStyle(Framework::Knopf::Style::HBild
+                         | Framework::Knopf::Style::HAlpha
+                         | Framework::Knopf::Style::Hintergrund);
     chatButton->setHintergrundBildZ(iconsDat.laden(0, new Text("chat.png")));
     chatButton->setMausEreignis(
         [this](void* p, void* o, Framework::MausEreignis me) {
@@ -90,6 +91,9 @@ Game::Game(Bildschirm* zScreen)
             return 1;
         });
     elements.add(chatButton);
+
+    mapWindow = new MapWindow();
+    elements.add(mapWindow);
 }
 
 Game::~Game()
@@ -295,4 +299,9 @@ void Game::makeChatButtonVisible()
 Chat* Game::zChat() const
 {
     return chat;
+}
+
+MapWindow* Game::zMap() const
+{
+    return mapWindow;
 }

+ 5 - 2
FactoryCraft/Game.h

@@ -3,11 +3,12 @@
 #include <Bild.h>
 #include <Knopf.h>
 
+#include "Chat.h"
 #include "Dialog.h"
 #include "DragController.h"
-#include "Menu.h"
 #include "ItemList.h"
-#include "Chat.h"
+#include "MapWindow.h"
+#include "Menu.h"
 
 class Player;
 class InventoryDragSource;
@@ -24,6 +25,7 @@ private:
     Framework::TextFeld* filter;
     ItemListContainer* itemListContainer;
     Framework::Knopf* chatButton;
+    MapWindow* mapWindow;
     Chat* chat;
     bool recipieVisible;
 
@@ -44,4 +46,5 @@ public:
     const Text* zFilterText();
     void makeChatButtonVisible();
     Chat* zChat() const;
+    MapWindow* zMap() const;
 };

+ 2 - 1
FactoryCraft/Globals.cpp

@@ -26,8 +26,9 @@ void initVariables()
 
 void initMenus()
 {
+    LoadMenu *load = new LoadMenu(uiFactory.initParam.bildschirm);
     menuRegister->put("load",
-        RCPointer<Menu>::of(new LoadMenu(uiFactory.initParam.bildschirm)));
+        RCPointer<Menu>::of(load));
     menuRegister->put("serverSelection",
         RCPointer<Menu>::of(
             new ServerSelectionMenu(uiFactory.initParam.bildschirm)));

+ 93 - 0
FactoryCraft/MapWindow.cpp

@@ -0,0 +1,93 @@
+#include "MapWindow.h"
+
+#include <TextFeld.h>
+
+#include "Globals.h"
+
+MapWindow::MapWindow()
+    : Fenster(),
+      map(0)
+{
+    setStyle(
+        Fenster::Style::Erlaubt | Fenster::Style::Rahmen
+        | Fenster::Style::BodyHAlpha | Fenster::Style::Titel
+        | Fenster::Style::TitelHAlpha | Fenster::Style::Closable
+        | Fenster::Style::ClosingHAlpha | Fenster::Style::ClosingKlickBuffer
+        | Fenster::Style::TitelHintergrund | Fenster::Style::BodyHintergrund
+        | Fenster::Style::ClosingHintergrund | Fenster::Style::MEIgnoreInside
+        | Fenster::Style::HeightChangeable | Fenster::Style::BreiteChangeable
+        | Fenster::Style::BodyMinBr | Fenster::Style::BodyMinHi
+        | Fenster::Style::Beweglich);
+    removeStyle(Fenster::Style::Sichtbar);
+    setTitel("Map");
+    setClosingMe([this](void* p, void* o, Framework::MausEreignis me) {
+        if (me.id == Framework::ME_RLinks)
+        {
+            setVisibility(0);
+        }
+        return 1;
+    });
+    setSize(500, 500);
+    setPosition(uiFactory.initParam.bildschirm->getBackBufferSize().x / 2
+                    - getBreite() / 2,
+        uiFactory.initParam.bildschirm->getBackBufferSize().y / 2
+            - getHeight() / 2);
+    setMausEreignis(Framework::_ret1ME);
+    setTastaturEreignis(Framework::_ret1TE);
+    setRBreite(1);
+    setRFarbe(0xFF52525E);
+    setKBgFarbe(0xA0000000);
+    setTBgFarbe(0xA0000000);
+    setSBgFarbe(0xA0000000);
+    setTSchriftZ(
+        dynamic_cast<Schrift*>(uiFactory.initParam.schrift->getThis()));
+    zTTextFeld()->setSize(0, 20);
+    zTTextFeld()->addStyle(TextFeld::Style::Center);
+    setKMin(200, 200);
+}
+
+void MapWindow::setVisibility(bool visible)
+{
+    if ((visible && !map) || (!visible && map))
+    {
+        uiFactory.initParam.bildschirm->postAction([this, visible]() {
+            if (visible && !map)
+            {
+                lockZeichnung();
+                map = new DimensionMap();
+                map->setSize(getInnenBreite(), getInnenHeight());
+                addMember(map);
+                unlockZeichnung();
+                addStyle(Fenster::Style::Sichtbar);
+            }
+            if (!visible && map)
+            {
+                removeStyle(Fenster::Style::Sichtbar);
+                lockZeichnung();
+                removeMember(map);
+                map = 0;
+                unlockZeichnung();
+            }
+        });
+    }
+}
+
+void MapWindow::addChunk(ChunkMap* chunk)
+{
+    lockZeichnung();
+    if (map)
+    {
+        map->addChunk(chunk);
+    }
+    else
+    {
+        chunk->release();
+    }
+    unlockZeichnung();
+}
+
+bool MapWindow::tick(double time)
+{
+    if (map) map->setSize(getInnenBreite(), getInnenHeight());
+    return Fenster::tick(time);
+}

+ 19 - 0
FactoryCraft/MapWindow.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include <Fenster.h>
+
+#include "DimensionMap.h"
+
+class MapWindow : public Framework::Fenster
+{
+private:
+    DimensionMap* map;
+
+public:
+    MapWindow();
+    
+    void setVisibility(bool visible);
+    void addChunk(ChunkMap* chunk);
+    
+    bool tick(double time) override;
+};

+ 4 - 0
FactoryCraft/PlayerKam.cpp

@@ -54,6 +54,10 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
             char action = 4;
             World::INSTANCE->zClient()->sendPlayerAction(&action, 1);
         }
+        if (te.taste[0] == 'm')
+        {
+            ((Game*)(Menu*)menuRegister->get("game"))->zMap()->setVisibility(1);
+        }
     }
 }
 

+ 9 - 0
FactoryCraft/World.cpp

@@ -124,6 +124,15 @@ void World::update(bool background)
                         ->initOptions(data + 1);
                     break;
                 }
+            case 6: // map data
+                {
+                    ByteArrayReader reader(data + 1, length - 1, 0);
+                    ChunkMap* map = new ChunkMap(&reader);
+                    ((Game*)(Menu*)menuRegister->get("game"))
+                        ->zMap()
+                        ->addChunk(map);
+                    break;
+                }
             }
             delete[] data;
             // TODO: process messages