Browse Source

process EntityRemovedUpdate world updates

Kolja Strohm 3 years ago
parent
commit
6d9671f97f

+ 23 - 0
FactoryCraft/Dimension.cpp

@@ -139,10 +139,33 @@ void Dimension::removeBlock( Block* zBlock )
 
 Entity* Dimension::zEntity( int id )
 {
+    cs.lock();
     for( Entity* e : *entities )
     {
         if( e->getId() == id )
+        {
+            cs.unlock();
             return e;
+        }
     }
+    cs.unlock();
     return 0;
+}
+
+void Dimension::removeEntity( int id )
+{
+    cs.lock();
+    int index = 0;
+    for( Entity* e : *entities )
+    {
+        if( e->getId() == id )
+        {
+            currentGame->setVisibility( e, 0 );
+            entities->remove( index );
+            cs.unlock();
+            return;
+        }
+        index++;
+    }
+    cs.unlock();
 }

+ 1 - 0
FactoryCraft/Dimension.h

@@ -34,4 +34,5 @@ public:
     void setBlock( Block* block );
     void removeBlock( Block* zBlock );
     Entity* zEntity( int id );
+    void removeEntity( int id );
 };

+ 14 - 0
FactoryCraft/EntityRemovedUpdate.cpp

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

+ 16 - 0
FactoryCraft/EntityRemovedUpdate.h

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

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -183,6 +183,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="DirectConnect.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="EntityChangedUpdate.cpp" />
+    <ClCompile Include="EntityRemovedUpdate.cpp" />
     <ClCompile Include="EntityType.cpp" />
     <ClCompile Include="FactoryClient.cpp" />
     <ClCompile Include="Game.cpp" />
@@ -221,6 +222,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="DirectConnect.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="EntityChangedUpdate.h" />
+    <ClInclude Include="EntityRemovedUpdate.h" />
     <ClInclude Include="EntityType.h" />
     <ClInclude Include="FactoryClient.h" />
     <ClInclude Include="Game.h" />

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -150,6 +150,9 @@
     <ClCompile Include="EntityChangedUpdate.cpp">
       <Filter>world\update</Filter>
     </ClCompile>
+    <ClCompile Include="EntityRemovedUpdate.cpp">
+      <Filter>world\update</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -263,5 +266,8 @@
     <ClInclude Include="EntityChangedUpdate.h">
       <Filter>world\update</Filter>
     </ClInclude>
+    <ClInclude Include="EntityRemovedUpdate.h">
+      <Filter>world\update</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 2 - 1
FactoryCraft/StaticInitializerOrder.cpp

@@ -26,4 +26,5 @@ const c *c::INSTANCE = new c();
 #include "BlockChangedUpdate.h"
 #include "BlockRemovedUpdate.h"
 #include "AddEntityUpdate.h"
-#include "EntityChangedUpdate.h"
+#include "EntityChangedUpdate.h"
+#include "EntityRemovedUpdate.h"

+ 6 - 0
FactoryCraft/World.cpp

@@ -230,4 +230,10 @@ Entity* World::zEntity( int id ) const
             return e;
     }
     return 0;
+}
+
+void World::removeEntity( int id )
+{
+    for( Dimension* d : *dimensions )
+        d->removeEntity( id );
 }

+ 1 - 0
FactoryCraft/World.h

@@ -37,4 +37,5 @@ public:
     Framework::Bildschirm3D* zScreen() const;
     Framework::Punkt getChunkCenter( int x, int y ) const;
     Entity* zEntity( int id ) const;
+    void removeEntity( int id );
 };