Browse Source

improve map loading speed and added options window

Kolja Strohm 2 years ago
parent
commit
4f63f51ede

+ 15 - 3
FactoryCraft/ChunkMap.cpp

@@ -12,8 +12,6 @@ ChunkMap::ChunkMap(Framework::StreamReader* zReader)
     memset(heightMap, 0, 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);
@@ -28,6 +26,19 @@ ChunkMap::ChunkMap(Framework::StreamReader* zReader)
     setMaxHeight(255);
 }
 
+ChunkMap::ChunkMap(Framework::Punkt center)
+    : ReferenceCounter(),
+      chunkCenter(center),
+      maxHeight(0)
+{
+    pixels = new MapPixel[CHUNK_SIZE * CHUNK_SIZE];
+    memset(pixels, 0, sizeof(MapPixel) * CHUNK_SIZE * CHUNK_SIZE);
+    heightMap = new unsigned char[CHUNK_SIZE * CHUNK_SIZE];
+    memset(heightMap, 0, CHUNK_SIZE * CHUNK_SIZE);
+    rendered.neuBild(16, 16, 0xA0000000);
+    setMaxHeight(255);
+}
+
 ChunkMap::~ChunkMap()
 {
     for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE; i++)
@@ -73,7 +84,8 @@ const Framework::Bild& ChunkMap::getRenderedImage() const
     return rendered;
 }
 
-unsigned char* ChunkMap::getHeightMap() const {
+unsigned char* ChunkMap::getHeightMap() const
+{
     return heightMap;
 }
 

+ 1 - 0
FactoryCraft/ChunkMap.h

@@ -32,6 +32,7 @@ private:
     
 public:
     ChunkMap(Framework::StreamReader* zReader);
+    ChunkMap(Framework::Punkt center);
     ~ChunkMap();
     
     void setMaxHeight(unsigned char maxHeight);

+ 2 - 0
FactoryCraft/Dimension.cpp

@@ -108,6 +108,7 @@ void Dimension::api(char* message)
                     = location + getDirection(getDirectionFromIndex(i));
                 if (pos.z >= 0 && pos.z < WORLD_HEIGHT)
                 {
+                    cs.lock();
                     Block* zB = zBlock(pos);
                     if (zB)
                     {
@@ -121,6 +122,7 @@ void Dimension::api(char* message)
                                 ->blockVisibilityChanged(zB);
                         }
                     }
+                    cs.unlock();
                 }
             }
             break;

+ 240 - 78
FactoryCraft/DimensionMap.cpp

@@ -3,14 +3,14 @@
 #include "Constants.h"
 #include "World.h"
 
-DimensionMap::DimensionMap()
+DimensionMap::DimensionMap(MapOptions* zOptions)
     : ZeichnungHintergrund(),
+      zOptions(zOptions),
       originChunkCenter(0, 0),
       scrollOffset(0, 0),
       chunkCount(0),
       pixelsPerBlock(16),
-      maxHeight(255),
-      waitingForChunk(0),
+      requestCount(0),
       drag(0)
 {
     setStyle(Style::Sichtbar | Style::Erlaubt);
@@ -97,6 +97,28 @@ Framework::Punkt DimensionMap::getMaxVisibleChunkCenter(
     return currentChunkCenter;
 }
 
+void DimensionMap::removeUnused() const
+{
+    Punkt tmp;
+    Framework::Punkt min = getMinVisibleChunkCenter(tmp);
+    Framework::Punkt max = getMaxVisibleChunkCenter(tmp);
+    char addr[8];
+    for (auto i = chunkList.begin(); i;)
+    {
+        if (i->getChunkCenter().x < min.x || i->getChunkCenter().y < min.y
+            || i->getChunkCenter().x > max.x || i->getChunkCenter().y > max.y)
+        {
+            getAddrOfWorld(i->getChunkCenter(), addr);
+            chunks->remove(addr, 8);
+            i.remove();
+        }
+        else
+        {
+            ++i;
+        }
+    }
+}
+
 bool DimensionMap::tick(double time)
 {
     if (lastSize != getSize())
@@ -110,14 +132,14 @@ bool DimensionMap::tick(double time)
 void DimensionMap::requestNextChunk()
 {
     cs.lock();
-    if (waitingForChunk)
+    if (requestCount >= 20)
     {
         cs.unlock();
         return;
     }
     if (chunkCount == 0)
     {
-        waitingForChunk = 1;
+        requestCount++;
         Vec3<float> playerPos
             = World::INSTANCE->getCurrentPlayerEntity()->getPos();
         char msg[9];
@@ -128,43 +150,54 @@ void DimensionMap::requestNextChunk()
     }
     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)
+        while (requestCount < 20)
         {
-            for (int y = minVisibleChunk.y; y <= maxVisibleChunk.y;
-                 y += CHUNK_SIZE)
+            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)
             {
-                getAddrOfWorld({x, y}, addr);
-                if (!chunks->z(addr, 8))
+                for (int y = minVisibleChunk.y; y <= maxVisibleChunk.y;
+                     y += CHUNK_SIZE)
                 {
-                    if (minDist < 0
-                        || (screenCenter - screenPos).getLengthSq() < minDist)
+                    getAddrOfWorld({x, y}, addr);
+                    if (!chunks->z(addr, 8))
                     {
-                        minDist = (screenCenter - screenPos).getLengthSq();
-                        resultChunk = {x, y};
+                        if (minDist < 0
+                            || (screenCenter - screenPos).getLengthSq()
+                                   < minDist)
+                        {
+                            minDist = (screenCenter - screenPos).getLengthSq();
+                            resultChunk = {x, y};
+                        }
                     }
+                    screenPos.y += pixelsPerBlock * CHUNK_SIZE;
                 }
-                screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+                screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+                screenPos.y = minScreenPos.y;
+            }
+            if (minDist >= 0)
+            {
+                requestCount++;
+                char msg[9];
+                msg[0] = 2;
+                *(int*)(msg + 1) = (int)resultChunk.x;
+                *(int*)(msg + 5) = (int)resultChunk.y;
+                World::INSTANCE->zClient()->dimensionAPIRequest(msg, 9);
+                getAddrOfWorld({resultChunk.x, resultChunk.y}, addr);
+                chunks->set(addr, 8, new ChunkMap(resultChunk));
+            }
+            else
+            {
+                break;
             }
-            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();
@@ -177,8 +210,10 @@ void DimensionMap::addChunk(ChunkMap* chunk)
     char addr[8];
     getAddrOfWorld(chunk->getChunkCenter(), addr);
     chunks->set(addr, 8, chunk);
+    chunkList.add(chunk);
     chunkCount++;
-    waitingForChunk = 0;
+    requestCount--;
+    removeUnused();
     cs.unlock();
     requestNextChunk();
 }
@@ -188,11 +223,21 @@ void DimensionMap::render(Framework::Bild& rObj)
     ZeichnungHintergrund::render(rObj);
     if (!rObj.setDrawOptions(innenPosition, innenSize)) return;
     cs.lock();
+    if (zOptions->isFollowPlayer())
+    {
+        Vec3<float> playerPos
+            = World::INSTANCE->getCurrentPlayerEntity()->getPos();
+        scrollOffset
+            = (Punkt((int)playerPos.x, (int)playerPos.y) - originChunkCenter)
+            * pixelsPerBlock;
+        requestNextChunk();
+    }
     Punkt minScreenPos;
     Punkt minVisibleChunk = getMinVisibleChunkCenter(minScreenPos);
     Punkt maxScreenPos;
     Punkt maxVisibleChunk = getMaxVisibleChunkCenter(maxScreenPos);
     char addr[8];
+    // render chunks
     Punkt screenPos = minScreenPos;
     for (int x = minVisibleChunk.x; x <= maxVisibleChunk.x; x += CHUNK_SIZE)
     {
@@ -202,7 +247,18 @@ void DimensionMap::render(Framework::Bild& rObj)
             ChunkMap* map = chunks->z(addr, 8);
             if (map)
             {
-                map->setMaxHeight((unsigned char)maxHeight);
+                if (zOptions->isUnderground())
+                {
+                    map->setMaxHeight(
+                        (int)(World::INSTANCE->getCurrentPlayerEntity()
+                                  ->getPos()
+                                  .z
+                              / 2));
+                }
+                else
+                {
+                    map->setMaxHeight(255);
+                }
                 Punkt topLeft(screenPos.x - (pixelsPerBlock * CHUNK_SIZE) / 2,
                     screenPos.y - (pixelsPerBlock * CHUNK_SIZE) / 2);
                 rObj.drawBildSkall(topLeft.x,
@@ -210,42 +266,162 @@ void DimensionMap::render(Framework::Bild& rObj)
                     pixelsPerBlock * CHUNK_SIZE,
                     pixelsPerBlock * CHUNK_SIZE,
                     map->getRenderedImage());
+            }
+            screenPos.y += pixelsPerBlock * CHUNK_SIZE;
+        }
+        screenPos.x += pixelsPerBlock * CHUNK_SIZE;
+        screenPos.y = minScreenPos.y;
+    }
+    // render shadow and borders
+    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)
+            {
+                Punkt topLeft(screenPos.x - (pixelsPerBlock * CHUNK_SIZE) / 2,
+                    screenPos.y - (pixelsPerBlock * CHUNK_SIZE) / 2);
+                getAddrOfWorld({x, y - CHUNK_SIZE}, addr);
+                ChunkMap* tmp = chunks->z(addr, 8);
+                unsigned char* heightMapTop = tmp ? tmp->getHeightMap() : 0;
+                getAddrOfWorld({x + CHUNK_SIZE, y}, addr);
+                tmp = chunks->z(addr, 8);
+                unsigned char* heightMapRight = tmp ? tmp->getHeightMap() : 0;
+                getAddrOfWorld({x, y + CHUNK_SIZE}, addr);
+                tmp = chunks->z(addr, 8);
+                unsigned char* heightMapBottom = tmp ? tmp->getHeightMap() : 0;
+                getAddrOfWorld({x - CHUNK_SIZE, y}, addr);
+                tmp = chunks->z(addr, 8);
+                unsigned char* heightMapLeft = tmp ? tmp->getHeightMap() : 0;
                 unsigned char* heightMap = map->getHeightMap();
-                for (int xx = 0; xx < CHUNK_SIZE - 1; xx++)
+                for (int xx = 0; xx < CHUNK_SIZE; xx++)
                 {
-                    for (int yy = 0; yy < CHUNK_SIZE - 1; yy++)
+                    for (int yy = 0; yy < CHUNK_SIZE; yy++)
                     {
-                        if (heightMap[yy * CHUNK_SIZE + xx]
-                    > heightMap[yy * CHUNK_SIZE + xx + 1]
-                            )
+                        bool shadowR = 0;
+                        bool shadowB = 0;
+                        if (xx < CHUNK_SIZE - 1)
                         {
-                            rObj.drawLinieVAlpha((xx * pixelsPerBlock)
-                                                     + topLeft.x
-                                                     + pixelsPerBlock,
-                                (yy * pixelsPerBlock) + topLeft.y,
-                                pixelsPerBlock,
-                                0xFF000000);
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMap[yy * CHUNK_SIZE + xx + 1])
+                            {
+                                rObj.drawLinieVAlpha((xx * pixelsPerBlock)
+                                                         + topLeft.x
+                                                         + pixelsPerBlock,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock,
+                                    0x40000000);
+                                shadowR = 1;
+                            }
                         }
-                        if (heightMap[yy * CHUNK_SIZE + xx]
-                > heightMap[(yy + 1) * CHUNK_SIZE + xx])
+                        else if (heightMapRight)
                         {
-                            rObj.drawLinieHAlpha(
-                                (xx * pixelsPerBlock) + topLeft.x,
-                                (yy * pixelsPerBlock) + topLeft.y
-                                    + pixelsPerBlock,
-                                pixelsPerBlock,
-                                0x40000000);
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMapRight[yy * CHUNK_SIZE])
+                            {
+                                rObj.drawLinieVAlpha((xx * pixelsPerBlock)
+                                                         + topLeft.x
+                                                         + pixelsPerBlock,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock,
+                                    0x40000000);
+                                shadowR = 1;
+                            }
+                        }
+                        if (yy < CHUNK_SIZE - 1)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMap[(yy + 1) * CHUNK_SIZE + xx])
+                            {
+                                rObj.drawLinieHAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y
+                                        + pixelsPerBlock,
+                                    pixelsPerBlock,
+                                    0x30000000);
+                                shadowB = 1;
+                            }
+                        }
+                        else if (heightMapBottom)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMapBottom[xx])
+                            {
+                                rObj.drawLinieHAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y
+                                        + pixelsPerBlock,
+                                    pixelsPerBlock,
+                                    0x30000000);
+                                shadowB = 1;
+                            }
+                        }
+                        if (xx > 0)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMap[yy * CHUNK_SIZE + xx - 1])
+                            {
+                                rObj.drawLinieVAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock - shadowB,
+                                    0x20FFFFFF);
+                            }
+                        }
+                        else if (heightMapLeft)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMapLeft[yy * CHUNK_SIZE + CHUNK_SIZE
+                                                - 1])
+                            {
+                                rObj.drawLinieVAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock - shadowB,
+                                    0x20FFFFFF);
+                            }
+                        }
+                        if (yy > 0)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMap[(yy - 1) * CHUNK_SIZE + xx])
+                            {
+                                rObj.drawLinieHAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock - shadowR,
+                                    0x10FFFFFF);
+                            }
+                        }
+                        else if (heightMapTop)
+                        {
+                            if (heightMap[yy * CHUNK_SIZE + xx]
+                                > heightMapTop[(CHUNK_SIZE - 1) * CHUNK_SIZE
+                                               + xx])
+                            {
+                                rObj.drawLinieHAlpha(
+                                    (xx * pixelsPerBlock) + topLeft.x,
+                                    (yy * pixelsPerBlock) + topLeft.y,
+                                    pixelsPerBlock - shadowR,
+                                    0x10FFFFFF);
+                            }
                         }
                     }
                 }
-                rObj.drawLinieHAlpha(topLeft.x,
-                    topLeft.y,
-                    pixelsPerBlock * CHUNK_SIZE,
-                    0x50FFFFFF);
-                rObj.drawLinieVAlpha(topLeft.x,
-                    topLeft.y,
-                    pixelsPerBlock * CHUNK_SIZE,
-                    0x50FFFFFF);
+                if (zOptions->isShowChunkBorders())
+                {
+                    rObj.drawLinieHAlpha(topLeft.x,
+                        topLeft.y,
+                        pixelsPerBlock * CHUNK_SIZE,
+                        0x50FFFFFF);
+                    rObj.drawLinieVAlpha(topLeft.x,
+                        topLeft.y,
+                        pixelsPerBlock * CHUNK_SIZE,
+                        0x50FFFFFF);
+                }
             }
             screenPos.y += pixelsPerBlock * CHUNK_SIZE;
         }
@@ -285,19 +461,5 @@ void DimensionMap::doMausEreignis(Framework::MausEreignis& me, bool userRet)
         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);
 }

+ 10 - 6
FactoryCraft/DimensionMap.h

@@ -1,34 +1,38 @@
 #pragma once
 
-#include <Zeichnung.h>
 #include <Trie.h>
+#include <Zeichnung.h>
 
 #include "ChunkMap.h"
+#include "MapOptions.h"
 
 class DimensionMap : public Framework::ZeichnungHintergrund
 {
 private:
+    MapOptions* zOptions;
     Framework::Trie<ChunkMap>* chunks;
+    Framework::Array<ChunkMap*> chunkList;
     Framework::Punkt originChunkCenter;
     Framework::Punkt scrollOffset;
     int chunkCount;
     int pixelsPerBlock;
-    int maxHeight;
-    bool waitingForChunk;
+    int requestCount;
     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 getMinVisibleChunkCenter(
+        Framework::Punkt& screenPos) const;
     Framework::Punkt getMaxVisibleChunkCenter(
         Framework::Punkt& screenPos) const;
+    void removeUnused() const;
 
 public:
-    DimensionMap();
+    DimensionMap(MapOptions* zOptions);
     ~DimensionMap();
-    
+
     void requestNextChunk();
     void addChunk(ChunkMap* chunk);
     bool tick(double time) override;

+ 4 - 4
FactoryCraft/Entity.cpp

@@ -149,7 +149,7 @@ bool Entity::tick(double time)
         }
         Vec3<float> frameSpeed = speed * (float)time;
         bool hasCollided = 0;
-        while (true)
+        for(int m = 0; m < 20; m++)
         {
             float tf = 1.f;
             int collType = 0;
@@ -427,7 +427,7 @@ bool Entity::tick(double time)
             if (updateType == 1)
             {
                 if ((int)worldBoundingBoxFloor[updateI].x
-                    < (int)floor(worldBoundingBox[updateI].x + frameSpeed.x))
+                    <= (int)floor(worldBoundingBox[updateI].x + frameSpeed.x))
                     worldBoundingBoxFloor[updateI].x++;
                 if ((int)worldBoundingBoxFloor[updateI].x
                     > (int)floor(worldBoundingBox[updateI].x + frameSpeed.x))
@@ -436,7 +436,7 @@ bool Entity::tick(double time)
             if (updateType == 2)
             {
                 if ((int)worldBoundingBoxFloor[updateI].y
-                    < (int)floor(worldBoundingBox[updateI].y + frameSpeed.y))
+                    <= (int)floor(worldBoundingBox[updateI].y + frameSpeed.y))
                     worldBoundingBoxFloor[updateI].y++;
                 if ((int)worldBoundingBoxFloor[updateI].y
                     > (int)floor(worldBoundingBox[updateI].y + frameSpeed.y))
@@ -445,7 +445,7 @@ bool Entity::tick(double time)
             if (updateType == 3)
             {
                 if ((int)worldBoundingBoxFloor[updateI].z
-                    < (int)floor(worldBoundingBox[updateI].z + frameSpeed.z))
+                    <= (int)floor(worldBoundingBox[updateI].z + frameSpeed.z))
                     worldBoundingBoxFloor[updateI].z++;
                 if ((int)worldBoundingBoxFloor[updateI].z
                     > (int)floor(worldBoundingBox[updateI].z + frameSpeed.z))

+ 116 - 0
FactoryCraft/MapOptions.cpp

@@ -0,0 +1,116 @@
+#include "MapOptions.h"
+
+#include <DateiSystem.h>
+
+#include "Globals.h"
+#include "Initialisierung.h"
+
+MapOptions::MapOptions()
+    : Fenster()
+{
+    Framework::LTDBDatei iconsDat;
+    iconsDat.setDatei(new Framework::Text("data/bilder/gui_icons.ltdb"));
+    iconsDat.leseDaten(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::Beweglich | Style::ClosingHBild
+        | Style::ClosingBuffer);
+    removeStyle(Fenster::Style::Sichtbar);
+    setTitel("Map options");
+    setClosingMe([this](void* p, void* o, Framework::MausEreignis me) {
+        if (me.id == Framework::ME_RLinks)
+        {
+            removeStyle(Fenster::Style::Sichtbar);
+        }
+        return 1;
+    });
+    setSize(210, 125);
+    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);
+    setSAfStrength(10);
+    setSAfFarbe(0x5F9C0A0A);
+    setSBgBildZ(iconsDat.laden(0, new Text("close.png")));
+    setSKAfFarbe(0xFF9C0A0A);
+    setSKAfStrength(10);
+
+    underground = initKontrollKnopf(5,
+        5,
+        200,
+        20,
+        Framework::KontrollKnopf::Style::Normal
+            & ~Framework::KontrollKnopf::Style::Rahmen,
+        "Show underground map");
+    underground->setNMausEreignis(_ret1ME);
+    addMember(underground);
+
+    followPlayer = initKontrollKnopf(5,
+        30,
+        200,
+        20,
+        Framework::KontrollKnopf::Style::Normal
+            & ~Framework::KontrollKnopf::Style::Rahmen,
+        "Follow player");
+    followPlayer->setNMausEreignis(_ret1ME);
+    addMember(followPlayer);
+
+    showPlayers = initKontrollKnopf(5,
+        55,
+        200,
+        20,
+        (Framework::KontrollKnopf::Style::Normal
+            | Framework::KontrollKnopf::Style::Selected)
+            & ~Framework::KontrollKnopf::Style::Rahmen,
+        "Show Players");
+    showPlayers->setNMausEreignis(_ret1ME);
+    addMember(showPlayers);
+
+    showChunkBorders = initKontrollKnopf(5,
+        80,
+        200,
+        20,
+        (Framework::KontrollKnopf::Style::Normal
+            | Framework::KontrollKnopf::Style::Selected)
+            & ~Framework::KontrollKnopf::Style::Rahmen,
+        "Show Chunk Borders");
+    showChunkBorders->setNMausEreignis(_ret1ME);
+    addMember(showChunkBorders);
+}
+
+bool MapOptions::isUnderground()
+{
+    return underground->hatStyle(KontrollKnopf::Style::Selected);
+}
+
+bool MapOptions::isFollowPlayer()
+{
+    return followPlayer->hatStyle(KontrollKnopf::Style::Selected);
+}
+
+bool MapOptions::isShowPlayers()
+{
+    return showPlayers->hatStyle(KontrollKnopf::Style::Selected);
+}
+
+bool MapOptions::isShowChunkBorders()
+{
+    return showChunkBorders->hatStyle(KontrollKnopf::Style::Selected);
+}

+ 21 - 0
FactoryCraft/MapOptions.h

@@ -1 +1,22 @@
 #pragma once
+
+#include "OptionsWindow.h"
+
+#include <Knopf.h>
+
+class MapOptions : public Framework::Fenster
+{
+private:
+    Framework::KontrollKnopf* underground;
+    Framework::KontrollKnopf* followPlayer;
+    Framework::KontrollKnopf* showPlayers;
+    Framework::KontrollKnopf* showChunkBorders;
+    
+public:
+    MapOptions();
+
+    bool isUnderground();
+    bool isFollowPlayer();
+    bool isShowPlayers();
+    bool isShowChunkBorders();
+};

+ 9 - 4
FactoryCraft/MapWindow.cpp

@@ -5,9 +5,7 @@
 #include "Globals.h"
 
 MapWindow::MapWindow()
-    : OptionsWindow([this]() {
-          // TODO: open options
-      }),
+    : OptionsWindow([this]() { options->addStyle(Fenster::Style::Sichtbar); }),
       map(0)
 {
     setTitel("Map");
@@ -24,6 +22,13 @@ MapWindow::MapWindow()
         uiFactory.initParam.bildschirm->getBackBufferSize().y / 2
             - getHeight() / 2);
     setKMin(200, 200);
+    options = new MapOptions();
+    uiFactory.initParam.bildschirm->addMember(dynamic_cast<Zeichnung*>(options->getThis()));
+}
+
+MapWindow::~MapWindow()
+{
+    options->release();
 }
 
 void MapWindow::setVisibility(bool visible)
@@ -34,7 +39,7 @@ void MapWindow::setVisibility(bool visible)
             if (visible && !map)
             {
                 lockZeichnung();
-                map = new DimensionMap();
+                map = new DimensionMap(options);
                 map->setSize(getInnenBreite(), getInnenHeight());
                 addMember(map);
                 unlockZeichnung();

+ 3 - 0
FactoryCraft/MapWindow.h

@@ -3,14 +3,17 @@
 #include "OptionsWindow.h"
 
 #include "DimensionMap.h"
+#include "MapOptions.h"
 
 class MapWindow : public OptionsWindow
 {
 private:
     DimensionMap* map;
+    MapOptions* options;
 
 public:
     MapWindow();
+    ~MapWindow();
     
     void setVisibility(bool visible);
     void addChunk(ChunkMap* chunk);