Răsfoiți Sursa

blocks can now be destroyed by the player

Kolja Strohm 3 ani în urmă
părinte
comite
e361f6ce8a

+ 21 - 0
FactoryCraft/BlockRemovedUpdate.cpp

@@ -0,0 +1,21 @@
+#include "BlockRemovedUpdate.h"
+#include "Globals.h"
+#include "Game.h"
+
+BlockRemovedUpdateType::BlockRemovedUpdateType()
+    : WorldUpdateType( ID )
+{}
+
+void BlockRemovedUpdateType::applyUpdate( Framework::StreamReader* zReader )
+{
+    int dimension = 0;
+    zReader->lese( (char*)&dimension, 4 );
+    Framework::Vec3<int> pos;
+    zReader->lese( (char*)&pos.x, 4 );
+    zReader->lese( (char*)&pos.y, 4 );
+    zReader->lese( (char*)&pos.z, 4 );
+    Dimension* d = currentGame->zDimension( dimension );
+    Block* b = d->zBlock( pos );
+    if( b )
+        d->removeBlock( b );
+}

+ 16 - 0
FactoryCraft/BlockRemovedUpdate.h

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

+ 1 - 1
FactoryCraft/Dimension.cpp

@@ -44,7 +44,7 @@ Chunk* Dimension::zChunk( Punkt wPos ) const
     return chunks->z( addr, 8 );
 }
 
-Framework::Either<Block*, int> Dimension::zBlock( Vec3<int> location )
+Block* Dimension::zBlock( Vec3<int> location )
 {
     Chunk* c = zChunk( currentGame->getChunkCenter( location.x, location.y ) );
     if( c )

+ 1 - 1
FactoryCraft/Dimension.h

@@ -24,7 +24,7 @@ public:
     Dimension( int id );
     ~Dimension();
 
-    Framework::Either<Block*, int> zBlock( Framework::Vec3<int> location );
+    Block* zBlock( Framework::Vec3<int> location );
     void addEntity( Entity* entity );
     void setChunk( Chunk* chunk, Framework::Punkt center, World* zWorld );
     int getDimensionId() const;

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -175,6 +175,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="BasicBlocks.cpp" />
     <ClCompile Include="Block.cpp" />
     <ClCompile Include="BlockChangedUpdate.cpp" />
+    <ClCompile Include="BlockRemovedUpdate.cpp" />
     <ClCompile Include="BlockType.cpp" />
     <ClCompile Include="Chunk.cpp" />
     <ClCompile Include="Dimension.cpp" />
@@ -205,6 +206,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="BasicBlocks.h" />
     <ClInclude Include="Block.h" />
     <ClInclude Include="BlockChangedUpdate.h" />
+    <ClInclude Include="BlockRemovedUpdate.h" />
     <ClInclude Include="BlockType.h" />
     <ClInclude Include="Chunk.h" />
     <ClInclude Include="Constants.h" />

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -126,6 +126,9 @@
     <ClCompile Include="PlaceBlockUpdate.cpp">
       <Filter>world\update</Filter>
     </ClCompile>
+    <ClCompile Include="BlockRemovedUpdate.cpp">
+      <Filter>world\update</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Entity.h">
@@ -224,5 +227,8 @@
     <ClInclude Include="PlaceBlockUpdate.h">
       <Filter>world\update</Filter>
     </ClInclude>
+    <ClInclude Include="BlockRemovedUpdate.h">
+      <Filter>world\update</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 1 - 1
FactoryCraft/Main.cpp

@@ -36,7 +36,7 @@ int KSGStart Framework::Start( Framework::Startparam p )
     WNDCLASS wc = Framework::F_Normal( p.hinst );
     wc.lpszClassName = "Factory Craft";
     window.erstellen( WS_POPUPWINDOW, wc );
-    Monitor m = Framework::getMonitor( 0 );
+    Monitor m = Framework::getMonitor( 1 );
     window.setBounds( Punkt( m.x, m.y ), Punkt( m.breite, m.height ) );
     window.setAnzeigeModus( SW_SHOWNORMAL );
     window.setVSchließAktion( [&window]( void* p, void* f ) {

+ 9 - 1
FactoryCraft/PlaceBlockUpdate.cpp

@@ -19,5 +19,13 @@ void PlaceBlockUpdateType::applyUpdate( Framework::StreamReader* zReader )
     zReader->lese( (char*)&pos.z, 4 );
     unsigned short id;
     zReader->lese( (char*)&id, 2 );
-    currentGame->zDimension( dimension )->setBlock( STATIC_REGISTRY( BlockType ).zElement( id )->loadBlock( pos, zReader ) );
+    bool d = 1;
+    zReader->lese( (char*)&d, 1 );
+    if( !d )
+    {
+        if( STATIC_REGISTRY( BlockType ).zElement( id )->needsInstance() )
+            currentGame->zDimension( dimension )->setBlock( STATIC_REGISTRY( BlockType ).zElement( id )->createBlock( pos ) );
+    }
+    else
+        currentGame->zDimension( dimension )->setBlock( STATIC_REGISTRY( BlockType ).zElement( id )->loadBlock( pos, zReader ) );
 }

+ 6 - 3
FactoryCraft/StaticInitializerOrder.cpp

@@ -14,10 +14,13 @@ const c *c::INSTANCE = new c();
 
 // order of includes determines the ids
 
+// block types
 #include "NoBlock.h" // must be first
 #include "BasicBlocks.h"
-//#include "OverworldDimension.h"
-#include "AddChunkUpdate.h"
+// entities
 //#include "Player.h"
+// world updates
+#include "AddChunkUpdate.h"
 #include "PlaceBlockUpdate.h"
-#include "BlockChangedUpdate.h"
+#include "BlockChangedUpdate.h"
+#include "BlockRemovedUpdate.h"