فهرست منبع

fix: model changes were ignored if affected blocks were combined into chunk models

Kolja Strohm 1 ماه پیش
والد
کامیت
bcb889dddb

+ 23 - 6
FactoryCraft/Block.cpp

@@ -25,7 +25,8 @@ Block::Block(const BlockType* zType,
       flowOptions(0),
       distanceToSource(0),
       passable(passable),
-      speedModifier(speedModifier)
+      speedModifier(speedModifier),
+      currentModelInfo(0)
 {
     hp = (float)maxHP;
     memset(sideVisible, 0, 6);
@@ -38,7 +39,13 @@ Block::Block(const BlockType* zType,
     setSize(size);
 }
 
-Block::~Block() {}
+Block::~Block()
+{
+    if (currentModelInfo)
+    {
+        delete currentModelInfo;
+    }
+}
 
 void Block::beforeRender(
     GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader)
@@ -79,17 +86,22 @@ void Block::api(char* message)
         }
     case 1: // model change
         {
+            ModelInfo* old = currentModelInfo;
             ByteArrayReader reader(message + 1, 10000, 0);
-            ModelInfo info(&reader);
-            setModelDaten(info.getModel());
-            setSize(info.getSize());
-            setModelTextur(info.getTexture());
+            currentModelInfo = new ModelInfo(&reader);
+            setModelDaten(currentModelInfo->getModel());
+            setSize(currentModelInfo->getSize());
+            setModelTextur(currentModelInfo->getTexture());
             Chunk* zChunk = World::INSTANCE->zChunk(
                 World::INSTANCE->getChunkCenter(location.x, location.y));
             if (zChunk)
             {
                 zChunk->setModelChanged(partOfModel);
             }
+            if (old)
+            {
+                delete old;
+            }
             break;
         }
     case 2: // update fluid state
@@ -291,3 +303,8 @@ char Block::getDistanceToSource() const
 {
     return distanceToSource;
 }
+
+const ModelInfo& Block::getCurrentModelInfo() const
+{
+    return currentModelInfo ? *currentModelInfo : zType->getModelInfo();
+}

+ 3 - 0
FactoryCraft/Block.h

@@ -5,6 +5,7 @@
 #include "Area.h"
 #include "BlockType.h"
 #include "FactoryCraftModel.h"
+#include "ModelInfo.h"
 
 using namespace Framework;
 
@@ -26,6 +27,7 @@ protected:
     char distanceToSource;
     bool passable;
     float speedModifier;
+    ModelInfo* currentModelInfo;
 
     void beforeRender(
         GraphicsApi* api, Shader* zVertexShader, Shader* zPixelShader) override;
@@ -59,6 +61,7 @@ public:
     int getPartOfModels() const;
     char getFlowOptions() const;
     char getDistanceToSource() const;
+    const ModelInfo& getCurrentModelInfo() const;
 
     friend Chunk;
 };

+ 2 - 1
FactoryCraft/Chunk.cpp

@@ -14,7 +14,8 @@ Chunk::Chunk(Framework::Punkt location)
     : ReferenceCounter(),
       location(location),
       isLoading(0),
-      lightChanged(0)
+      lightChanged(0),
+      modelChanged(0)
 {
     blocks = new Block*[CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT];
     memset(blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof(Block*));

+ 20 - 18
FactoryCraft/ChunkFluidModel.cpp

@@ -135,20 +135,19 @@ void ChunkFluidModel::buildModel()
                 setBlockPartOfModel(blocks()[i], 1);
                 int index = 0;
                 for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
                 {
                     Framework::Vec3<int> location(
                         (i / WORLD_HEIGHT) / CHUNK_SIZE,
                         (i / WORLD_HEIGHT) % CHUNK_SIZE,
                         i % WORLD_HEIGHT);
                     Framework::Vec3<int> aboveLocation
-                        = location
-                        + getDirection(Direction::TOP);
+                        = location + getDirection(Direction::TOP);
                     int aboveIndex = Chunk::index(aboveLocation);
                     bool sameAbove = aboveLocation.z < WORLD_HEIGHT
-						&& blocks()[aboveIndex]
-						&& blocks()[aboveIndex]->zBlockType()
-							   == blocks()[i]->zBlockType();
+                                  && blocks()[aboveIndex]
+                                  && blocks()[aboveIndex]->zBlockType()
+                                         == blocks()[i]->zBlockType();
                     if (isPartOfGroundModel(location, index))
                     {
                         if (!groundModelBuidler.get(
@@ -212,16 +211,19 @@ void ChunkFluidModel::buildModel()
                                 char maxFlowDist = blocks()[i]
                                                        ->zBlockType()
                                                        ->getMaxFlowDistance();
-                                float dist = (float)(maxFlowDist + 1 - blocks()[i]
-                                                    ->getDistanceToSource()) / (float)(maxFlowDist + 1);
+                                float dist
+                                    = (float)(maxFlowDist + 1
+                                              - blocks()[i]
+                                                  ->getDistanceToSource())
+                                    / (float)(maxFlowDist + 1);
                                 groundVerticies[groundVertexCount - 1].pos.z
                                     -= (1 - dist);
                             }
                             groundVerticies[groundVertexCount - 1].pos
                                 += blocks()[i]->getPos()
-                                    - Vec3<float>((float)chunkCenter().x,
-                                        (float)chunkCenter().y,
-                                        (float)WORLD_HEIGHT / 2.f);
+                                 - Vec3<float>((float)chunkCenter().x,
+                                     (float)chunkCenter().y,
+                                     (float)WORLD_HEIGHT / 2.f);
                             groundVerticies[groundVertexCount - 1].id
                                 = groundVertexCount - 1;
                         }
@@ -261,15 +263,13 @@ bool ChunkFluidModel::updateLightning()
     int groundVertexCount = 0;
     for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
     {
-        if (blocks()[i]
-            && isPartOfModel(blocks()[i]))
+        if (blocks()[i] && isPartOfModel(blocks()[i]))
         {
             int index = 0;
             for (Text* textureName :
-                *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                *blocks()[i]->getCurrentModelInfo().getTexturNames())
             {
-                Framework::Vec3<int> location(
-                    (i / WORLD_HEIGHT) / CHUNK_SIZE,
+                Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
                     (i / WORLD_HEIGHT) % CHUNK_SIZE,
                     i % WORLD_HEIGHT);
                 if (isPartOfGroundModel(location, index))
@@ -282,9 +282,11 @@ bool ChunkFluidModel::updateLightning()
                     {
                         if (oldVertexCount <= groundVertexCount)
                         {
-                            std::cout << "ERROR: to many vertecies in chunk fluid model" << std::endl;
+                            std::cout << "ERROR: to many vertecies in chunk "
+                                         "fluid model"
+                                      << std::endl;
                             return 0;
-						}
+                        }
                         lightBuffer[groundVertexCount++] = calculateLight(
                             vBuffer[polygon->indexList[vi]].pos,
                             location,

+ 6 - 8
FactoryCraft/ChunkGroundModel.cpp

@@ -102,10 +102,9 @@ bool ChunkGroundModel::isPartOfGroundModel(
         int naighborIndex = Chunk::index(neighborLocation);
         if (!blocks()[naighborIndex]
             || !blocks()[naighborIndex]
-                    ->zBlockType()
-                    ->getModelInfo()
-                    .getModelName()
-                    .istGleich("cube"))
+                ->getCurrentModelInfo()
+                .getModelName()
+                .istGleich("cube"))
         {
             needed = 1;
         }
@@ -137,7 +136,7 @@ void ChunkGroundModel::buildModel()
                 setBlockPartOfModel(blocks()[i], 1);
                 int index = 0;
                 for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
                 {
                     Framework::Vec3<int> location(
                         (i / WORLD_HEIGHT) / CHUNK_SIZE,
@@ -249,7 +248,7 @@ bool ChunkGroundModel::updateLightning()
             {
                 int index = 0;
                 for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
                 {
                     Framework::Vec3<int> location(
                         (i / WORLD_HEIGHT) / CHUNK_SIZE,
@@ -285,6 +284,5 @@ bool ChunkGroundModel::isTransparent() const
 
 bool ChunkGroundModel::isPartOfModel(Block* zBlock) const
 {
-    return zBlock->zBlockType()->getModelInfo().getModelName().istGleich(
-        "cube");
+    return zBlock->getCurrentModelInfo().getModelName().istGleich("cube");
 }

+ 1 - 1
FactoryCraft/Entity.cpp

@@ -32,7 +32,7 @@ Entity::Entity(const EntityType* zType,
     lastDirection = World::INSTANCE->zKamera()->getDirection();
     currentFrame.duration = 0;
     rend = 1;
-    lastFlags = 0;
+    lastFlags = MOVEMENT_FLAG_FLY;
     setSize(size);
 }
 

+ 2 - 2
FactoryCraft/FactoryCraft.vcxproj

@@ -34,7 +34,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>true</UseDebugLibraries>
-    <PlatformToolset>v143</PlatformToolset>
+    <PlatformToolset>v145</PlatformToolset>
     <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -109,7 +109,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FANGEN_EXPORTS;annotate#//;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <LanguageStandard>stdcpp20</LanguageStandard>
+      <LanguageStandard>stdcpplatest</LanguageStandard>
       <PreprocessToFile>false</PreprocessToFile>
     </ClCompile>
     <Link>

+ 7 - 6
FactoryCraft/TransparentChunkGroundModel.cpp

@@ -1,8 +1,9 @@
+#include "TransparentChunkGroundModel.h"
+
 #include <Trie.h>
 
 #include "Area.h"
 #include "Block.h"
-#include "TransparentChunkGroundModel.h"
 #include "Constants.h"
 #include "FactoryCraftModel.h"
 #include "Globals.h"
@@ -11,7 +12,8 @@ using namespace Framework;
 
 TransparentChunkGroundModel::TransparentChunkGroundModel(
     FactoryCraftModel* target, Chunk* zChunk)
-    : ChunkModelBuilder(target, zChunk, Chunk::CombinedModels::TRANSPARENT_GROUND)
+    : ChunkModelBuilder(
+          target, zChunk, Chunk::CombinedModels::TRANSPARENT_GROUND)
 {}
 
 __int64 TransparentChunkGroundModel::calculateLight(
@@ -110,7 +112,7 @@ void TransparentChunkGroundModel::buildModel()
                 __int64 light = blocks()[i]->getMaxLight();
                 int index = 0;
                 for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
                 {
                     if (!groundModelBuidler.get(
                             *textureName, textureName->getLength()))
@@ -212,7 +214,7 @@ bool TransparentChunkGroundModel::updateLightning()
                 __int64 light = blocks()[i]->getMaxLight();
                 int index = 0;
                 for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
                 {
                     const Vertex3D* vBuffer
                         = blocks()[i]->zModelData()->zVertexBuffer();
@@ -237,6 +239,5 @@ bool TransparentChunkGroundModel::isTransparent() const
 
 bool TransparentChunkGroundModel::isPartOfModel(Block* zBlock) const
 {
-    return zBlock->zBlockType()->getModelInfo().getModelName().istGleich(
-        "grass");
+    return zBlock->getCurrentModelInfo().getModelName().istGleich("grass");
 }

BIN
FactoryCraft/data_release/models/items.m3


BIN
FactoryCraft/data_release/models/plants.m3


BIN
FactoryCraft/data_release/textures/items.ltdb


BIN
FactoryCraft/data_release/textures/plants.ltdb


BIN
FactoryCraft/error_core_memory_dump.dmp