فهرست منبع

add grass to ground models to improve rendering performance

Kolja Strohm 2 سال پیش
والد
کامیت
a67c878d63
10فایلهای تغییر یافته به همراه352 افزوده شده و 140 حذف شده
  1. 38 2
      FactoryCraft/Block.cpp
  2. 4 0
      FactoryCraft/Block.h
  3. 228 98
      FactoryCraft/Chunk.cpp
  4. 7 3
      FactoryCraft/Chunk.h
  5. 27 8
      FactoryCraft/Dimension.cpp
  6. 5 1
      FactoryCraft/Dimension.h
  7. 14 0
      FactoryCraft/Game.cpp
  8. 7 0
      FactoryCraft/Game.h
  9. 22 27
      FactoryCraft/World.cpp
  10. 0 1
      FactoryCraft/World.h

+ 38 - 2
FactoryCraft/Block.cpp

@@ -54,8 +54,7 @@ void Block::api(char* message)
             Model3D* mdl = World::INSTANCE->getCurrentTarget();
             if (mdl == this)
             {
-                if (zBlockType()->getModelInfo().getModelName().istGleich(
-                        "cube"))
+                if (partOfGround)
                 {
                     World::INSTANCE->zSelectedEffectModel()->setDestroyedState(
                         1 - hp / maxHP);
@@ -66,10 +65,22 @@ void Block::api(char* message)
         }
     case 1: // model change
         {
+            bool affectsGround = partOfGround;
             ByteArrayReader reader(message + 1, 10000, 0);
             ModelInfo info(&reader);
             setModelDaten(info.getModel());
             setModelTextur(info.getTexture());
+            affectsGround |= info.getModelName().istGleich("cube")
+                          || info.getModelName().istGleich("grass");
+            if (affectsGround)
+            {
+                Chunk* zChunk = World::INSTANCE->zChunk(
+                    World::INSTANCE->getChunkCenter(location.x, location.y));
+                if (zChunk)
+                {
+                    zChunk->setGroundChanged();
+                }
+            }
             break;
         }
     case 2: // update fluid fill state
@@ -109,11 +120,31 @@ void Block::setLightData(Direction dir, unsigned char* data)
     if (zC) zC->setLightChanged();
 }
 
+void Block::setPartOfGround(bool partOfGround)
+{
+    this->partOfGround = partOfGround;
+}
+
 const unsigned char* Block::getLightData(Direction dir) const
 {
     return lightData + getDirectionIndex(dir) * 6;
 }
 
+__int64 Block::getMaxLight() const {
+    unsigned char max[6];
+    max[0] = max[1] = max[2] = max[3] = max[4] = max[5] = 0;
+    for (int i = 0; i < 6; i++)
+    {
+        for (int j = 0; j < 6; j++)
+        {
+			if (lightData[i * 6 + j] > max[j]) max[j] = lightData[i * 6 + j];
+		}
+	}
+    return ((__int64)max[0] << 24) | ((__int64)max[1] << 16)
+         | ((__int64)max[2] << 8) | ((__int64)max[3] << 56)
+         | ((__int64)max[4] << 48) | ((__int64)max[5] << 40);
+}
+
 bool Block::isVisible() const
 {
     return true;
@@ -217,4 +248,9 @@ Text Block::printLightInfo()
     result += (int)lightData[35];
     result += ")\n";
     return result;
+}
+
+bool Block::isPartOfGround() const
+{
+    return partOfGround;
 }

+ 4 - 0
FactoryCraft/Block.h

@@ -22,6 +22,7 @@ protected:
     Vec3<int> location;
     unsigned char lightData[6 * 6];
     char needRequestModelInfo;
+    bool partOfGround;
 
     void beforeRender(
         GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader) override;
@@ -39,6 +40,8 @@ public:
     void api(char* message);
     void copyLightTo(Block* zB);
     void setLightData(Direction dir, unsigned char* data);
+    void setPartOfGround(bool partOfGround);
+    __int64 getMaxLight() const;
     const unsigned char* getLightData(Direction dir) const;
     bool isVisible() const;
 
@@ -47,4 +50,5 @@ public:
     Skeleton* zSkeleton() const;
     friend Chunk;
     Text printLightInfo();
+    bool isPartOfGround() const;
 };

+ 228 - 98
FactoryCraft/Chunk.cpp

@@ -121,7 +121,9 @@ void Chunk::load(Framework::StreamReader* zReader)
             if (b->isVisible())
             {
                 if (!blockTypes[id]->getModelInfo().getModelName().istGleich(
-                        "cube"))
+                        "cube")
+                    && !blockTypes[id]->getModelInfo().getModelName().istGleich(
+                        "grass"))
                 {
                     b->tick(0);
                     visibleBlocks.add(b);
@@ -255,6 +257,7 @@ void Chunk::load(Framework::StreamReader* zReader)
 void Chunk::buildGroundModel()
 {
     vcs.lock();
+    visibleBlocks.leeren();
     lightChanged = 0;
     Model3DData* chunkModel = groundModel->zModelData();
     // remove old model
@@ -271,18 +274,103 @@ void Chunk::buildGroundModel()
     int groundVertexArraySize = 10000;
     for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
     {
-        if (blocks[i]
-            && blocks[i]->zBlockType()->getModelInfo().getModelName().istGleich(
-                "cube"))
+        if (blocks[i])
         {
-            int index = 0;
-            for (Text* textureName :
-                *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
+            if (blocks[i]
+                    ->zBlockType()
+                    ->getModelInfo()
+                    .getModelName()
+                    .istGleich("cube"))
+            {
+                blocks[i]->setPartOfGround(1);
+                int index = 0;
+                for (Text* textureName :
+                    *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
+                {
+                    Framework::Vec3<int> location(
+                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
+                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
+                        i % WORLD_HEIGHT);
+                    if (isPartOfGroundModel(location, index))
+                    {
+                        if (!groundModelBuidler.get(
+                                *textureName, textureName->getLength()))
+                        {
+                            GroundModelPart* part = new GroundModelPart();
+                            part->indexList = new int[10000];
+                            part->indexCount = 0;
+                            part->indexArraySize = 10000;
+                            part->name = *textureName;
+                            groundModelBuidler.set(
+                                *textureName, textureName->getLength(), part);
+                            groundPartArray.add(part);
+                        }
+                        GroundModelPart* part = groundModelBuidler.get(
+                            *textureName, textureName->getLength());
+                        const Vertex3D* vBuffer
+                            = blocks[i]->zModelData()->zVertexBuffer();
+                        Polygon3D* polygon
+                            = blocks[i]->zModelData()->getPolygon(index);
+                        if (part->indexCount + polygon->indexAnz
+                            > part->indexArraySize)
+                        {
+                            int* tmp = new int[part->indexArraySize + 10000];
+                            memcpy(tmp, part->indexList, part->indexCount * 4);
+                            delete[] part->indexList;
+                            part->indexList = tmp;
+                            part->indexArraySize += 10000;
+                        }
+                        if (groundVertexCount + polygon->indexAnz
+                            > groundVertexArraySize)
+                        {
+                            Vertex3D* tmp
+                                = new Vertex3D[groundVertexArraySize + 10000];
+                            memcpy(tmp,
+                                groundVerticies,
+                                groundVertexCount * sizeof(Vertex3D));
+                            delete[] groundVerticies;
+                            groundVerticies = tmp;
+                            groundVertexArraySize += 10000;
+                            __int64* lTmp = new __int64[groundVertexArraySize];
+                            memcpy(lTmp,
+                                lightBuffer,
+                                groundVertexCount * sizeof(__int64));
+                            delete[] lightBuffer;
+                            lightBuffer = lTmp;
+                        }
+                        for (int vi = 0; vi < polygon->indexAnz; vi++)
+                        {
+                            lightBuffer[groundVertexCount] = calculateLight(
+                                vBuffer[polygon->indexList[vi]].pos,
+                                location,
+                                getDirectionFromIndex(index));
+                            part->indexList[part->indexCount++]
+                                = groundVertexCount;
+                            groundVerticies[groundVertexCount++]
+                                = vBuffer[polygon->indexList[vi]];
+                            groundVerticies[groundVertexCount - 1].pos
+                                += blocks[i]->getPos()
+                                 - Vec3<float>((float)this->location.x,
+                                     (float)this->location.y,
+                                     (float)WORLD_HEIGHT / 2.f);
+                            groundVerticies[groundVertexCount - 1].id
+                                = groundVertexCount - 1;
+                        }
+                    }
+                    index++;
+                }
+            }
+            else if (blocks[i]
+                         ->zBlockType()
+                         ->getModelInfo()
+                         .getModelName()
+                         .istGleich("grass"))
             {
-                Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
-                    (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                    i % WORLD_HEIGHT);
-                if (isPartOfGroundModel(location, index))
+                blocks[i]->setPartOfGround(1);
+                __int64 light = blocks[i]->getMaxLight();
+                int index = 0;
+                for (Text* textureName :
+                    *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
                 {
                     if (!groundModelBuidler.get(
                             *textureName, textureName->getLength()))
@@ -331,10 +419,7 @@ void Chunk::buildGroundModel()
                     }
                     for (int vi = 0; vi < polygon->indexAnz; vi++)
                     {
-                        lightBuffer[groundVertexCount] = calculateLight(
-                            vBuffer[polygon->indexList[vi]].pos,
-                            location,
-                            getDirectionFromIndex(index));
+                        lightBuffer[groundVertexCount] = light;
                         part->indexList[part->indexCount++] = groundVertexCount;
                         groundVerticies[groundVertexCount++]
                             = vBuffer[polygon->indexList[vi]];
@@ -346,8 +431,13 @@ void Chunk::buildGroundModel()
                         groundVerticies[groundVertexCount - 1].id
                             = groundVertexCount - 1;
                     }
+                    index++;
                 }
-                index++;
+            }
+            else
+            {
+                blocks[i]->setPartOfGround(0);
+                visibleBlocks.add(blocks[i]);
             }
         }
     }
@@ -378,18 +468,49 @@ void Chunk::updateGroundLight()
     int groundVertexCount = 0;
     for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
     {
-        if (blocks[i]
-            && blocks[i]->zBlockType()->getModelInfo().getModelName().istGleich(
-                "cube"))
+        if (blocks[i])
         {
-            int index = 0;
-            for (Text* textureName :
-                *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
+            if (blocks[i]
+                    ->zBlockType()
+                    ->getModelInfo()
+                    .getModelName()
+                    .istGleich("cube"))
+            {
+                int index = 0;
+                for (Text* textureName :
+                    *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
+                {
+                    Framework::Vec3<int> location(
+                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
+                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
+                        i % WORLD_HEIGHT);
+                    if (isPartOfGroundModel(location, index))
+                    {
+                        const Vertex3D* vBuffer
+                            = blocks[i]->zModelData()->zVertexBuffer();
+                        Polygon3D* polygon
+                            = blocks[i]->zModelData()->getPolygon(index);
+                        for (int vi = 0; vi < polygon->indexAnz; vi++)
+                        {
+                            lightBuffer[groundVertexCount++] = calculateLight(
+                                vBuffer[polygon->indexList[vi]].pos,
+                                location,
+                                getDirectionFromIndex(index));
+                        }
+                    }
+                    index++;
+                }
+            }
+            else if (blocks[i]
+                         ->zBlockType()
+                         ->getModelInfo()
+                         .getModelName()
+                         .istGleich("grass"))
             {
-                Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
-                    (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                    i % WORLD_HEIGHT);
-                if (isPartOfGroundModel(location, index))
+                __int64 light = blocks[i]->getMaxLight();
+                int index = 0;
+                for (Text* textureName :
+                    *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
                 {
                     const Vertex3D* vBuffer
                         = blocks[i]->zModelData()->zVertexBuffer();
@@ -397,13 +518,9 @@ void Chunk::updateGroundLight()
                         = blocks[i]->zModelData()->getPolygon(index);
                     for (int vi = 0; vi < polygon->indexAnz; vi++)
                     {
-                        lightBuffer[groundVertexCount++] = calculateLight(
-                            vBuffer[polygon->indexList[vi]].pos,
-                            location,
-                            getDirectionFromIndex(index));
+                        lightBuffer[groundVertexCount++] = light;
                     }
                 }
-                index++;
             }
         }
     }
@@ -509,6 +626,68 @@ bool Chunk::isPartOfGroundModel(
     return needed;
 }
 
+void Chunk::renderSolid(std::function<void(Model3D*)> f)
+{
+    vcs.lock();
+    CustomDX11API* api
+        = (CustomDX11API*)uiFactory.initParam.bildschirm->zGraphicsApi();
+    api->setCullBack(false);
+    f(groundModel);
+    api->setCullBack(true);
+    float dist = 0.f;
+    if (api->isInFrustrum(groundModel->getPos(),
+            (CHUNK_SIZE / 2.f, CHUNK_SIZE / 2.f, WORLD_HEIGHT / 2.f),
+            &dist))
+    {
+        for (Block* b : visibleBlocks)
+        {
+            f(b);
+        }
+    }
+    vcs.unlock();
+}
+
+void Chunk::renderTransparent(std::function<void(Model3D*)> f) {}
+
+bool Chunk::tick(std::function<void(Model3D*)> f, double time)
+{
+    acs.lock();
+    vcs.lock(); // TODO: enshure no dead lock occures
+    if (modelChanged)
+    {
+        modelChanged = 0;
+        buildGroundModel();
+    }
+    if (lightChanged)
+    {
+        lightChanged = 0;
+        updateGroundLight();
+    }
+    bool res = groundModel->tick(time);
+    auto iterator = animations.begin();
+    while (iterator)
+    {
+        if (iterator->tick(time))
+        {
+            res |= iterator->zBlock()->tick(time);
+            if (iterator->isFinished())
+            {
+                iterator.remove();
+                continue;
+            }
+        }
+        else
+        {
+            iterator.remove();
+            continue;
+        }
+        ++iterator;
+    }
+    vcs.unlock();
+    acs.unlock();
+    return 1;
+}
+
 void Chunk::destroy()
 {
     Model3DData* chunkModel = groundModel->zModelData();
@@ -592,11 +771,18 @@ void Chunk::setBlock(Block* block)
     int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
     bool newAffectsGround
         = block
-       && block->zBlockType()->getModelInfo().getModelName().istGleich("cube");
+       && (block->zBlockType()->getModelInfo().getModelName().istGleich("cube")
+           || block->zBlockType()->getModelInfo().getModelName().istGleich(
+               "grass"));
     bool affectsGround
         = blocks[index]
-       && blocks[index]->zBlockType()->getModelInfo().getModelName().istGleich(
-           "cube");
+       && (blocks[index]->zBlockType()->getModelInfo().getModelName().istGleich(
+               "cube")
+           || blocks[index]
+                  ->zBlockType()
+                  ->getModelInfo()
+                  .getModelName()
+                  .istGleich("grass"));
     if (blocks[index])
     {
         vcs.lock();
@@ -667,7 +853,12 @@ void Chunk::removeBlock(Block* zBlock)
                                  ->zBlockType()
                                  ->getModelInfo()
                                  .getModelName()
-                                 .istGleich("cube");
+                                 .istGleich("cube")
+                          || blocks[index]
+                                 ->zBlockType()
+                                 ->getModelInfo()
+                                 .getModelName()
+                                 .istGleich("grass");
         blocks[index]->release();
         blocks[index] = 0;
         if (affectsGround) modelChanged = 1;
@@ -715,70 +906,9 @@ Framework::Vec3<int> Chunk::getMax() const
         location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
 }
 
-void Chunk::forAll(std::function<void(Model3D*)> f)
-{
-    vcs.lock();
-    f(groundModel);
-    float dist = 0.f;
-    CustomDX11API* api
-        = (CustomDX11API*)uiFactory.initParam.bildschirm->zGraphicsApi();
-    if (api->isInFrustrum(groundModel->getPos(),
-            (CHUNK_SIZE / 2.f, CHUNK_SIZE / 2.f, WORLD_HEIGHT / 2.f),
-            &dist))
-    {
-        api->setCullBack(false);
-        //int index = 0;
-        //int filter = 1 + (int)(dist / 100.f);
-        for (Block* b : visibleBlocks)
-        {
-         //   if (index % filter == 0)
-          //  {
-                f(b);
-           // }
-           // index++;
-        }
-        api->setCullBack(true);
-    }
-    vcs.unlock();
-}
-
-bool Chunk::tick(std::function<void(Model3D*)> f, double time)
+void Chunk::setGroundChanged()
 {
-    acs.lock();
-    vcs.lock(); // TODO: enshure no dead lock occures
-    if (modelChanged)
-    {
-        modelChanged = 0;
-        buildGroundModel();
-    }
-    if (lightChanged)
-    {
-        lightChanged = 0;
-        updateGroundLight();
-    }
-    bool res = groundModel->tick(time);
-    auto iterator = animations.begin();
-    while (iterator)
-    {
-        if (iterator->tick(time))
-        {
-            res |= iterator->zBlock()->tick(time);
-            if (iterator->isFinished())
-            {
-                iterator.remove();
-                continue;
-            }
-        }
-        else
-        {
-            iterator.remove();
-            continue;
-        }
-        ++iterator;
-    }
-    vcs.unlock();
-    acs.unlock();
-    return 1;
+    modelChanged = 1;
 }
 
 void Chunk::setLightChanged()

+ 7 - 3
FactoryCraft/Chunk.h

@@ -21,7 +21,7 @@ struct GroundModelPart
     Text name;
 };
 
-class Chunk : public Framework::Model3DCollection
+class Chunk : public Framework::ReferenceCounter
 {
 private:
     Framework::Punkt location;
@@ -50,6 +50,11 @@ public:
     Chunk(Framework::Punkt location);
     Chunk(Framework::Punkt location, Framework::StreamReader* zReader);
     ~Chunk();
+
+    void renderSolid(std::function<void(Model3D*)> f);
+    void renderTransparent(std::function<void(Model3D*)> f);
+    bool tick(std::function<void(Model3D*)> f, double time);
+
     void destroy();
     void api(char* message);
     Block* zBlockAt(Framework::Vec3<int> cLocation);
@@ -59,8 +64,7 @@ public:
     Framework::Punkt getCenter() const;
     Framework::Vec3<int> getMin() const;
     Framework::Vec3<int> getMax() const;
-    void forAll(std::function<void(Model3D*)> f) override;
-    bool tick(std::function<void(Model3D*)> f, double time) override;
+    void setGroundChanged();
     void setLightChanged();
 
     inline static int index(Framework::Vec3<int> localLocation)

+ 27 - 8
FactoryCraft/Dimension.cpp

@@ -20,6 +20,33 @@ Dimension::~Dimension()
     chunks->release();
 }
 
+void Dimension::forAll(std::function<void(Model3D*)> f)
+{
+    // handled by render and tick function
+}
+
+void Dimension::render(std::function<void(Model3D*)> f)
+{
+    for (Chunk* chunk : chunkList)
+    {
+        chunk->renderSolid(f);
+    }
+    for (Chunk* chunk : chunkList)
+    {
+        chunk->renderTransparent(f);
+    }
+}
+
+bool Dimension::tick(std::function<void(Model3D*)> f, double time)
+{
+    bool res = 0;
+    for (Chunk* chunk : chunkList)
+    {
+        res |= chunk->tick(f, time);
+    }
+    return res;
+}
+
 void Dimension::setId(int id)
 {
     this->id = id;
@@ -176,7 +203,6 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
     cs.lock();
     if (old)
     {
-        World::INSTANCE->setVisibility(old, 0);
         int index = 0;
         for (auto iterator = chunkList.begin(); iterator; ++iterator, ++index)
         {
@@ -193,13 +219,7 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
     else if (chunk)
         chunkList.add(chunk);
     chunks->set(addr, 8, chunk);
-    if (chunk) chunk->getThis();
     cs.unlock();
-    if (chunk)
-    {
-        World::INSTANCE->setVisibility(chunk, 1);
-        chunk->release();
-    }
 }
 
 bool Dimension::hasChunck(int x, int y) const
@@ -223,7 +243,6 @@ void Dimension::removeDistantChunks(Punkt wPos)
     {
         cs.lock();
         Chunk* chunk = chunkList.get(i);
-        World::INSTANCE->setVisibility(chunk, 0);
         chunk->destroy();
         setChunk(0, chunk->getCenter());
         cs.unlock();

+ 5 - 1
FactoryCraft/Dimension.h

@@ -9,7 +9,7 @@
 
 class World;
 
-class Dimension : public virtual Framework::ReferenceCounter
+class Dimension : public virtual Framework::Model3DCollection
 {
 private:
     int id;
@@ -24,6 +24,10 @@ public:
     Dimension();
     ~Dimension();
 
+    void forAll(std::function<void(Model3D*)> f) override;
+    void render(std::function<void(Model3D*)> f) override;
+    bool tick(std::function<void(Model3D*)> f, double time) override;
+
     void setId(int id);
     void api(char* message);
     Block* zBlock(Framework::Vec3<int> location);

+ 14 - 0
FactoryCraft/Game.cpp

@@ -14,6 +14,7 @@ Game::Game(Bildschirm* zScreen)
       recipieVisible(0),
       itemListContainer(0)
 {
+    elements.add(new ScreenCenter());
     inventoryDragController = new DragController<InventoryDragSource, int>();
     logout = initKnopf(10, 10, 200, 20, Knopf::Style::Normal, "Verlassen");
     logout->setMausEreignis([this, zScreen](void* p, void* o, MausEreignis me) {
@@ -310,4 +311,17 @@ void Game::hide()
             itemListContainer = 0;
         }
     });
+}
+
+ScreenCenter::ScreenCenter()
+    : Zeichnung()
+{
+    setPosition(0, 0);
+    setSize(uiFactory.initParam.bildschirm->getBackBufferSize());
+}
+
+void ScreenCenter::render(Bild& zRObj) 
+{
+    zRObj.drawLinieH(gr.x / 2 - 5, gr.y / 2, 10, 0xFFFFFFFF);
+    zRObj.drawLinieV(gr.x / 2, gr.y / 2 - 5, 10, 0xFFFFFFFF);
 }

+ 7 - 0
FactoryCraft/Game.h

@@ -48,4 +48,11 @@ public:
     Chat* zChat() const;
     MapWindow* zMap() const;
     void hide() override;
+};
+
+class ScreenCenter : public Framework::Zeichnung
+{
+public:
+    ScreenCenter();
+    virtual void render(Bild& zRObj) override;
 };

+ 22 - 27
FactoryCraft/World.cpp

@@ -1,6 +1,7 @@
 #include "World.h"
 
 #include <AsynchronCall.h>
+#include <DX12Buffer.h>
 #include <GraphicsApi.h>
 #include <iostream>
 #include <Network.h>
@@ -11,8 +12,6 @@
 #include "Globals.h"
 #include "Registries.h"
 #include "WorldUpdate.h"
-#include <DX12Buffer.h>
-#include <Welt3D.h>
 
 using namespace Network;
 using namespace Framework;
@@ -27,6 +26,8 @@ World::World(Bildschirm3D* zScreen, FactoryClient* client)
     renderedWorld->addDiffuseLight(DiffuseLight{
         Vec3<float>(0.5f, 0.5f, -1.f), Vec3<float>(1.f, 1.f, 1.f)});
     currentDimension = new Dimension();
+    renderedWorld->addCollection(
+        dynamic_cast<Model3DCollection*>(currentDimension->getThis()));
     zScreenPtr = zScreen;
     kam = new PlayerKam(zScreen);
     kam->setWelt(renderedWorld);
@@ -39,7 +40,8 @@ World::World(Bildschirm3D* zScreen, FactoryClient* client)
     dayLength = 1000;
     transitionLength = 0;
     nightLength = 0;
-    fallbackVertexLightBuffer = zScreen->zGraphicsApi()->createStructuredBuffer(16);
+    fallbackVertexLightBuffer
+        = zScreen->zGraphicsApi()->createStructuredBuffer(16);
     char data[16];
     memset(data, 0, 16);
     *(int*)data = 0xFFFFFF00;
@@ -261,7 +263,9 @@ void World::onTick(double time)
     }
     if (this->time > dayLength && this->time < dayLength + transitionLength)
     {
-        dayLightFactor = 1.f - (float)((this->time - dayLength) / transitionLength) * 0.95f;
+        dayLightFactor
+            = 1.f
+            - (float)((this->time - dayLength) / transitionLength) * 0.95f;
     }
     else if (this->time > dayLength + transitionLength
              && this->time < dayLength + transitionLength + nightLength)
@@ -276,7 +280,8 @@ void World::onTick(double time)
     else if (this->time > dayLength + transitionLength + nightLength)
     {
         dayLightFactor
-            = (float)((this->time - dayLength) / transitionLength) * 0.95f + 0.05f;
+            = (float)((this->time - dayLength) / transitionLength) * 0.95f
+            + 0.05f;
     }
     else
     {
@@ -285,11 +290,14 @@ void World::onTick(double time)
     if (this->time < dayLength + transitionLength
         || this->time > dayLength + transitionLength + nightLength)
     {
-        float currentDayTime = (float)(this->time < dayLength + transitionLength
-                                           ? this->time + transitionLength
-                          : this->time - dayLength + transitionLength + nightLength);
+        float currentDayTime
+            = (float)(this->time < dayLength + transitionLength
+                          ? this->time + transitionLength
+                          : this->time - dayLength + transitionLength
+                                + nightLength);
         Vec3<float> sunPos = Vec3<float>(-200.f, 50.f, 0.f);
-        sunPos.rotateY((float)((currentDayTime / (dayLength + transitionLength * 2)) * PI));
+        sunPos.rotateY((
+            float)((currentDayTime / (dayLength + transitionLength * 2)) * PI));
         sunPos.normalize();
         if (!renderedWorld->getDiffuseLightCount())
         {
@@ -371,17 +379,6 @@ Dimension* World::zDimension() const
     return currentDimension;
 }
 
-void World::setVisibility(Chunk* zChunk, bool visible)
-{
-    renderedWorld->lock();
-    if (visible)
-        renderedWorld->addCollection(
-            dynamic_cast<Framework::Model3DCollection*>(zChunk->getThis()));
-    else
-        renderedWorld->removeCollection(zChunk);
-    renderedWorld->unlock();
-}
-
 void World::setVisibility(Entity* zEntity, bool visible)
 {
     renderedWorld->lock();
@@ -449,16 +446,13 @@ void World::setTarget(Framework::Model3D* zTarget)
             selectionModel->setPosition(
                 zTarget->getPos().x, zTarget->getPos().y, zTarget->getPos().z);
             Block* b = dynamic_cast<Block*>(zTarget);
-            if (b
-                && b->zBlockType()->getModelInfo().getModelName().istGleich(
-                    "cube")
-                && b->getEffectPercentage() > 0)
+            if (b && b->isPartOfGround())
             {
-                 selectionModel->setDestroyedState(b->getEffectPercentage());
+                selectionModel->setDestroyedState(b->getEffectPercentage());
             }
             else
             {
-                 selectionModel->setDestroyedState(0);
+                selectionModel->setDestroyedState(0);
             }
             selectionModel->setVisible(1);
         }
@@ -531,7 +525,8 @@ FactoryClient* World::zClient() const
     return client;
 }
 
-float World::getDayLightFactor() const {
+float World::getDayLightFactor() const
+{
     return dayLightFactor;
 }
 

+ 0 - 1
FactoryCraft/World.h

@@ -45,7 +45,6 @@ public:
     Block* zBlockAt(Framework::Vec3<int> location) const;
     Block* getBlockAt(Framework::Vec3<int> location) const;
     Dimension* zDimension() const;
-    void setVisibility(Chunk* zChunk, bool visible);
     void setVisibility(Entity* zEntity, bool visible);
     Framework::Punkt getChunkCenter(int x, int y) const;
     Entity* zEntity(int id) const;