Browse Source

receive entity updates only for entities in the subscribed world area and remove old world update and registry architecture

Kolja Strohm 7 months ago
parent
commit
16b5e467c5

+ 0 - 18
FactoryCraft/AddEntityUpdate.cpp

@@ -1,18 +0,0 @@
-#include "AddEntityUpdate.h"
-
-#include "Entity.h"
-#include "Globals.h"
-#include "Registries.h"
-#include "StaticRegistry.h"
-
-AddEntityUpdateType::AddEntityUpdateType()
-    : WorldUpdateType(ID)
-{}
-
-void AddEntityUpdateType::applyUpdate(Framework::StreamReader* zReader)
-{
-    int type;
-    zReader->lese((char*)&type, 4);
-    Entity* entity = entityTypes[type]->loadEntity(zReader);
-    World::INSTANCE->zDimension()->addEntity(entity);
-}

+ 0 - 14
FactoryCraft/AddEntityUpdate.h

@@ -1,14 +0,0 @@
-#pragma once
-
-#include "WorldUpdate.h"
-
-class AddEntityUpdateType : public WorldUpdateType
-{
-    REGISTRABLE(AddEntityUpdateType)
-
-protected:
-    AddEntityUpdateType();
-    void applyUpdate(Framework::StreamReader* zReader) override;
-};
-
-REGISTER(AddEntityUpdateType, WorldUpdateType)

+ 0 - 1
FactoryCraft/Block.h

@@ -5,7 +5,6 @@
 #include "Area.h"
 #include "Area.h"
 #include "BlockType.h"
 #include "BlockType.h"
 #include "FactoryCraftModel.h"
 #include "FactoryCraftModel.h"
-#include "Registries.h"
 
 
 using namespace Framework;
 using namespace Framework;
 
 

+ 5 - 3
FactoryCraft/BlockType.cpp

@@ -1,7 +1,6 @@
 #include "BlockType.h"
 #include "BlockType.h"
 
 
 #include "Block.h"
 #include "Block.h"
-#include "Registries.h"
 
 
 using namespace Framework;
 using namespace Framework;
 
 
@@ -24,7 +23,8 @@ BlockType::BlockType(int id,
 
 
 BlockType::~BlockType() {}
 BlockType::~BlockType() {}
 
 
-Block* BlockType::createBlock(Framework::Vec3<int> position, bool passable, float speedModifier)
+Block* BlockType::createBlock(
+    Framework::Vec3<int> position, bool passable, float speedModifier)
 {
 {
     return new Block(this,
     return new Block(this,
         position,
         position,
@@ -33,7 +33,9 @@ Block* BlockType::createBlock(Framework::Vec3<int> position, bool passable, floa
         initialMaxHP,
         initialMaxHP,
         model.isTransparent(),
         model.isTransparent(),
         needModelSubscription,
         needModelSubscription,
-        model.getSize(), passable, speedModifier);
+        model.getSize(),
+        passable,
+        speedModifier);
 }
 }
 
 
 int BlockType::getId() const
 int BlockType::getId() const

+ 2 - 2
FactoryCraft/BlockType.h

@@ -5,7 +5,6 @@
 #include <Vec3.h>
 #include <Vec3.h>
 
 
 #include "ModelInfo.h"
 #include "ModelInfo.h"
-#include "StaticRegistry.h"
 
 
 class Block;
 class Block;
 
 
@@ -29,7 +28,8 @@ public:
         bool fluid,
         bool fluid,
         char maxFlowDistance);
         char maxFlowDistance);
     ~BlockType();
     ~BlockType();
-    Block* createBlock(Framework::Vec3<int> position, bool passable, float speedModifier);
+    Block* createBlock(
+        Framework::Vec3<int> position, bool passable, float speedModifier);
     bool doesNeedInstance() const;
     bool doesNeedInstance() const;
     bool doesNeedModelSubscription() const;
     bool doesNeedModelSubscription() const;
     bool isFluid() const;
     bool isFluid() const;

+ 0 - 1
FactoryCraft/Chunk.cpp

@@ -8,7 +8,6 @@
 #include "CustomDX11API.h"
 #include "CustomDX11API.h"
 #include "FactoryCraftModel.h"
 #include "FactoryCraftModel.h"
 #include "Globals.h"
 #include "Globals.h"
-#include "Registries.h"
 #include "TransparentChunkGroundModel.h"
 #include "TransparentChunkGroundModel.h"
 
 
 Chunk::Chunk(Framework::Punkt location)
 Chunk::Chunk(Framework::Punkt location)

+ 1 - 1
FactoryCraft/Constants.h

@@ -5,6 +5,6 @@
 #ifdef _DEBUG
 #ifdef _DEBUG
 #    define CHUNK_VISIBILITY_RANGE 2
 #    define CHUNK_VISIBILITY_RANGE 2
 #else
 #else
-#    define CHUNK_VISIBILITY_RANGE 64
+#    define CHUNK_VISIBILITY_RANGE 32
 #endif
 #endif
 #define MAX_VIEW_DISTANCE CHUNK_SIZE* CHUNK_VISIBILITY_RANGE
 #define MAX_VIEW_DISTANCE CHUNK_SIZE* CHUNK_VISIBILITY_RANGE

+ 14 - 0
FactoryCraft/Dimension.cpp

@@ -164,6 +164,20 @@ void Dimension::api(char* message)
     case 6: // set gravity
     case 6: // set gravity
         gravity = *(float*)(message + 1);
         gravity = *(float*)(message + 1);
         break;
         break;
+    case 7: // add entity
+        {
+            int type = *(int*)(message + 1);
+            ByteArrayReader reader(message + 5, INT_MAX, 0);
+            Entity* entity = entityTypes[type]->loadEntity(&reader);
+            addEntity(entity);
+            break;
+        }
+    case 8: // remove entity
+        {
+            int id = *(int*)(message + 1);
+            removeEntity(id);
+            break;
+        }
     }
     }
 }
 }
 
 

+ 0 - 14
FactoryCraft/EntityRemovedUpdate.cpp

@@ -1,14 +0,0 @@
-#include "EntityRemovedUpdate.h"
-
-#include "Globals.h"
-
-EntityRemovedUpdateType::EntityRemovedUpdateType()
-    : WorldUpdateType(ID)
-{}
-
-void EntityRemovedUpdateType::applyUpdate(Framework::StreamReader* zReader)
-{
-    int id;
-    zReader->lese((char*)&id, 4);
-    World::INSTANCE->removeEntity(id);
-}

+ 0 - 14
FactoryCraft/EntityRemovedUpdate.h

@@ -1,14 +0,0 @@
-#pragma once
-
-#include "WorldUpdate.h"
-
-class EntityRemovedUpdateType : WorldUpdateType
-{
-    REGISTRABLE(EntityRemovedUpdateType)
-
-protected:
-    EntityRemovedUpdateType();
-    void applyUpdate(Framework::StreamReader* zReader) override;
-};
-
-REGISTER(EntityRemovedUpdateType, WorldUpdateType)

+ 0 - 1
FactoryCraft/EntityType.cpp

@@ -2,7 +2,6 @@
 
 
 #include "Entity.h"
 #include "Entity.h"
 #include "Globals.h"
 #include "Globals.h"
-#include "Registries.h"
 
 
 EntityType::EntityType(int id, ModelInfo model)
 EntityType::EntityType(int id, ModelInfo model)
     : id(id),
     : id(id),

+ 0 - 9
FactoryCraft/FactoryCraft.vcxproj

@@ -173,7 +173,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     </CustomBuildStep>
     </CustomBuildStep>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
-    <ClCompile Include="AddEntityUpdate.cpp" />
     <ClCompile Include="Area.cpp" />
     <ClCompile Include="Area.cpp" />
     <ClCompile Include="Block.cpp" />
     <ClCompile Include="Block.cpp" />
     <ClCompile Include="BlockAnimation.cpp" />
     <ClCompile Include="BlockAnimation.cpp" />
@@ -196,7 +195,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="DimensionMap.cpp" />
     <ClCompile Include="DimensionMap.cpp" />
     <ClCompile Include="DragElement.cpp" />
     <ClCompile Include="DragElement.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="Entity.cpp" />
-    <ClCompile Include="EntityRemovedUpdate.cpp" />
     <ClCompile Include="EntityType.cpp" />
     <ClCompile Include="EntityType.cpp" />
     <ClCompile Include="Equipment.cpp" />
     <ClCompile Include="Equipment.cpp" />
     <ClCompile Include="FactoryClient.cpp" />
     <ClCompile Include="FactoryClient.cpp" />
@@ -224,16 +222,13 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="ModelInfo.cpp" />
     <ClCompile Include="ModelInfo.cpp" />
     <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="ShapedRecipie.cpp" />
     <ClCompile Include="ShapedRecipie.cpp" />
-    <ClCompile Include="StaticInitializerOrder.cpp" />
     <ClCompile Include="StatusBars.cpp" />
     <ClCompile Include="StatusBars.cpp" />
     <ClCompile Include="TransparentChunkGroundModel.cpp" />
     <ClCompile Include="TransparentChunkGroundModel.cpp" />
     <ClCompile Include="UIMLToolTip.cpp" />
     <ClCompile Include="UIMLToolTip.cpp" />
     <ClCompile Include="UnshapedRecipie.cpp" />
     <ClCompile Include="UnshapedRecipie.cpp" />
     <ClCompile Include="World.cpp" />
     <ClCompile Include="World.cpp" />
-    <ClCompile Include="WorldUpdate.cpp" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <ClInclude Include="AddEntityUpdate.h" />
     <ClInclude Include="Area.h" />
     <ClInclude Include="Area.h" />
     <ClInclude Include="Block.h" />
     <ClInclude Include="Block.h" />
     <ClInclude Include="BlockType.h" />
     <ClInclude Include="BlockType.h" />
@@ -257,7 +252,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="DragController.h" />
     <ClInclude Include="DragController.h" />
     <ClInclude Include="DragElement.h" />
     <ClInclude Include="DragElement.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="Entity.h" />
-    <ClInclude Include="EntityRemovedUpdate.h" />
     <ClInclude Include="EntityType.h" />
     <ClInclude Include="EntityType.h" />
     <ClInclude Include="Equipment.h" />
     <ClInclude Include="Equipment.h" />
     <ClInclude Include="FactoryClient.h" />
     <ClInclude Include="FactoryClient.h" />
@@ -284,14 +278,11 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="Menu.h" />
     <ClInclude Include="Menu.h" />
     <ClInclude Include="ModelInfo.h" />
     <ClInclude Include="ModelInfo.h" />
     <ClInclude Include="PlayerKam.h" />
     <ClInclude Include="PlayerKam.h" />
-    <ClInclude Include="Registries.h" />
     <ClInclude Include="ShapedRecipie.h" />
     <ClInclude Include="ShapedRecipie.h" />
-    <ClInclude Include="StaticRegistry.h" />
     <ClInclude Include="StatusBars.h" />
     <ClInclude Include="StatusBars.h" />
     <ClInclude Include="TransparentChunkGroundModel.h" />
     <ClInclude Include="TransparentChunkGroundModel.h" />
     <ClInclude Include="UIMLToolTip.h" />
     <ClInclude Include="UIMLToolTip.h" />
     <ClInclude Include="UnshapedRecipie.h" />
     <ClInclude Include="UnshapedRecipie.h" />
-    <ClInclude Include="WorldUpdate.h" />
     <ClInclude Include="World.h" />
     <ClInclude Include="World.h" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>

+ 0 - 30
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -7,9 +7,6 @@
     <Filter Include="world">
     <Filter Include="world">
       <UniqueIdentifier>{0a3d8693-54b5-4227-ba18-b964b512430b}</UniqueIdentifier>
       <UniqueIdentifier>{0a3d8693-54b5-4227-ba18-b964b512430b}</UniqueIdentifier>
     </Filter>
     </Filter>
-    <Filter Include="world\update">
-      <UniqueIdentifier>{b7be90aa-b378-46eb-90ed-b31d984ff5ce}</UniqueIdentifier>
-    </Filter>
     <Filter Include="inventory">
     <Filter Include="inventory">
       <UniqueIdentifier>{dcbc509e-a646-43ea-9b60-9c5e96e3ea34}</UniqueIdentifier>
       <UniqueIdentifier>{dcbc509e-a646-43ea-9b60-9c5e96e3ea34}</UniqueIdentifier>
     </Filter>
     </Filter>
@@ -91,9 +88,6 @@
     <ClCompile Include="Initialisierung.cpp">
     <ClCompile Include="Initialisierung.cpp">
       <Filter>static</Filter>
       <Filter>static</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="WorldUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
     <ClCompile Include="BlockType.cpp">
     <ClCompile Include="BlockType.cpp">
       <Filter>world</Filter>
       <Filter>world</Filter>
     </ClCompile>
     </ClCompile>
@@ -109,9 +103,6 @@
     <ClCompile Include="Dimension.cpp">
     <ClCompile Include="Dimension.cpp">
       <Filter>world</Filter>
       <Filter>world</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="StaticInitializerOrder.cpp">
-      <Filter>static</Filter>
-    </ClCompile>
     <ClCompile Include="PlayerKam.cpp">
     <ClCompile Include="PlayerKam.cpp">
       <Filter>world\view</Filter>
       <Filter>world\view</Filter>
     </ClCompile>
     </ClCompile>
@@ -139,12 +130,6 @@
     <ClCompile Include="Entity.cpp">
     <ClCompile Include="Entity.cpp">
       <Filter>Entity</Filter>
       <Filter>Entity</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="AddEntityUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
-    <ClCompile Include="EntityRemovedUpdate.cpp">
-      <Filter>world\update</Filter>
-    </ClCompile>
     <ClCompile Include="Dialog.cpp">
     <ClCompile Include="Dialog.cpp">
       <Filter>Menu\uiml</Filter>
       <Filter>Menu\uiml</Filter>
     </ClCompile>
     </ClCompile>
@@ -267,9 +252,6 @@
     <ClInclude Include="World.h">
     <ClInclude Include="World.h">
       <Filter>world</Filter>
       <Filter>world</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="WorldUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
     <ClInclude Include="Globals.h">
     <ClInclude Include="Globals.h">
       <Filter>static</Filter>
       <Filter>static</Filter>
     </ClInclude>
     </ClInclude>
@@ -285,9 +267,6 @@
     <ClInclude Include="Constants.h">
     <ClInclude Include="Constants.h">
       <Filter>static</Filter>
       <Filter>static</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Registries.h">
-      <Filter>static</Filter>
-    </ClInclude>
     <ClInclude Include="PlayerKam.h">
     <ClInclude Include="PlayerKam.h">
       <Filter>world\view</Filter>
       <Filter>world\view</Filter>
     </ClInclude>
     </ClInclude>
@@ -315,12 +294,6 @@
     <ClInclude Include="EntityType.h">
     <ClInclude Include="EntityType.h">
       <Filter>Entity</Filter>
       <Filter>Entity</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="AddEntityUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
-    <ClInclude Include="EntityRemovedUpdate.h">
-      <Filter>world\update</Filter>
-    </ClInclude>
     <ClInclude Include="Dialog.h">
     <ClInclude Include="Dialog.h">
       <Filter>Menu\uiml</Filter>
       <Filter>Menu\uiml</Filter>
     </ClInclude>
     </ClInclude>
@@ -336,9 +309,6 @@
     <ClInclude Include="ModelInfo.h">
     <ClInclude Include="ModelInfo.h">
       <Filter>static</Filter>
       <Filter>static</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="StaticRegistry.h">
-      <Filter>static</Filter>
-    </ClInclude>
     <ClInclude Include="ItemBar.h">
     <ClInclude Include="ItemBar.h">
       <Filter>Menu\uiml\playerGUI</Filter>
       <Filter>Menu\uiml\playerGUI</Filter>
     </ClInclude>
     </ClInclude>

+ 1 - 0
FactoryCraft/Globals.h

@@ -8,6 +8,7 @@
 #include <Schrift.h>
 #include <Schrift.h>
 #include <UIInitialization.h>
 #include <UIInitialization.h>
 
 
+#include "ItemType.h"
 #include "Menu.h"
 #include "Menu.h"
 #include "World.h"
 #include "World.h"
 
 

+ 0 - 2
FactoryCraft/ItemType.cpp

@@ -3,8 +3,6 @@
 
 
 #include <InMemoryBuffer.h>
 #include <InMemoryBuffer.h>
 
 
-#include "Registries.h"
-
 ItemType::ItemType(
 ItemType::ItemType(
     int id, ModelInfo model, Framework::Text name, Framework::Text tooltipUIML)
     int id, ModelInfo model, Framework::Text name, Framework::Text tooltipUIML)
     : ReferenceCounter(),
     : ReferenceCounter(),

+ 0 - 18
FactoryCraft/Registries.h

@@ -1,18 +0,0 @@
-#pragma once
-
-#include "BlockType.h"
-#include "EntityType.h"
-#include "ItemType.h"
-#include "StaticRegistry.h"
-#include "WorldUpdate.h"
-
-#ifndef _REGISTRY
-#    define _REGISTRY extern
-#endif
-
-#define STATIC_REGISTRY(Type) Type##Registry
-
-_REGISTRY StaticRegistry<WorldUpdateType> WorldUpdateTypeRegistry;
-_REGISTRY StaticRegistry<BlockType> BlockTypeRegistry;
-_REGISTRY StaticRegistry<ItemType> ItemTypeRegistry;
-_REGISTRY StaticRegistry<EntityType> EntityTypeRegistry;

+ 0 - 16
FactoryCraft/StaticInitializerOrder.cpp

@@ -1,16 +0,0 @@
-#define _REGISTRY
-
-#include "Registries.h"
-
-int count_WorldUpdateType = 0;
-
-#undef REGISTER
-#define REGISTER(c, typ)             \
-    const int c::ID = count_##typ++; \
-    const c* c::INSTANCE = new c();
-
-// order of includes determines the ids
-
-// world updates
-#include "AddEntityUpdate.h"
-#include "EntityRemovedUpdate.h"

+ 0 - 66
FactoryCraft/StaticRegistry.h

@@ -1,66 +0,0 @@
-#pragma once
-
-#define REGISTRABLE(c)        \
-                              \
-public:                       \
-    static const c* INSTANCE; \
-    static const int ID;      \
-                              \
-private:
-
-#define REGISTER(c, typ)
-
-template<typename T> class StaticRegistry
-{
-private:
-    T** registry;
-    int count;
-
-public:
-    StaticRegistry()
-    {
-        count = 1;
-        registry = new T*[count];
-        memset(registry, 0, sizeof(T*) * count);
-    }
-
-    ~StaticRegistry()
-    {
-        for (int index = 0; index < count; index++)
-        {
-            if (registry[index])
-            {
-                registry[index]->release();
-                registry[index] = 0;
-            }
-        }
-        delete[] registry;
-    }
-
-    void registerT(T* type, int id)
-    {
-        if (id >= count)
-        {
-            T** temp = new T*[id + 1];
-            memcpy(temp, registry, sizeof(T*) * count);
-            memset(temp + count, 0, sizeof(T*) * (id + 1 - count));
-            delete[] registry;
-            registry = temp;
-            count = id + 1;
-        }
-        registry[id] = type;
-    }
-
-    T* zElement(int id)
-    {
-        if (id < 0 || id >= count) return 0;
-        return registry[id];
-    }
-
-    int getCount() const
-    {
-        return count;
-    }
-
-    friend T;
-};

+ 0 - 10
FactoryCraft/World.cpp

@@ -10,8 +10,6 @@
 #include "Constants.h"
 #include "Constants.h"
 #include "Game.h"
 #include "Game.h"
 #include "Globals.h"
 #include "Globals.h"
-#include "Registries.h"
-#include "WorldUpdate.h"
 
 
 using namespace Network;
 using namespace Network;
 using namespace Framework;
 using namespace Framework;
@@ -84,14 +82,6 @@ void World::update(bool background)
                : serverMessageReader = client->getNextForegroundMessage())
                : serverMessageReader = client->getNextForegroundMessage())
     {
     {
         serverMessageReader->lese((char*)&type, 1);
         serverMessageReader->lese((char*)&type, 1);
-        if (type == 2) // WORLD UPDATE
-        {
-            int id = 0;
-            serverMessageReader->lese((char*)&id, 4);
-            STATIC_REGISTRY(WorldUpdateType)
-                .zElement(id)
-                ->applyUpdateAndCheck(serverMessageReader);
-        }
         if (type == 3) // API MESSAGE
         if (type == 3) // API MESSAGE
         {
         {
             int length;
             int length;

+ 0 - 28
FactoryCraft/WorldUpdate.cpp

@@ -1,28 +0,0 @@
-#include "WorldUpdate.h"
-
-#include <Text.h>
-
-#include "Registries.h"
-
-WorldUpdateType::WorldUpdateType(int id)
-    : ReferenceCounter(),
-      id(id)
-{
-    STATIC_REGISTRY(WorldUpdateType).registerT(this, id);
-}
-
-void WorldUpdateType::applyUpdateAndCheck(Framework::StreamReader* zReader)
-{
-    this->applyUpdate(zReader);
-    int id;
-    zReader->lese((char*)&id, 4);
-    if (id != this->id)
-    {
-        Framework::Text* t
-            = new Framework::Text("asynchony after world update of type ");
-        t->append(this->id);
-        t->append(". ID received from server was: ");
-        t->append(id);
-        throw t->getText();
-    }
-}

+ 0 - 19
FactoryCraft/WorldUpdate.h

@@ -1,19 +0,0 @@
-#pragma once
-
-#include <Reader.h>
-#include <ReferenceCounter.h>
-
-#include "StaticRegistry.h"
-
-class WorldUpdateType : public Framework::ReferenceCounter
-{
-private:
-    int id;
-
-protected:
-    WorldUpdateType(int id);
-    virtual void applyUpdate(Framework::StreamReader* zReader) = 0;
-
-public:
-    void applyUpdateAndCheck(Framework::StreamReader* zReader);
-};

BIN
FactoryCraft/error_core_memory_dump.dmp