Browse Source

fix direction mistakes

Kolja Strohm 3 years ago
parent
commit
1ad8af39ba

+ 36 - 0
FactoryCraft/Area.cpp

@@ -19,4 +19,40 @@ Direction opposite( Direction dir )
     default:
         return NO_DIRECTION;
     }
+}
+
+Directions getDirections( Framework::Vec3<float> currentPos, Framework::Vec3<float> otherPos )
+{
+    Directions result = NO_DIRECTION;
+    if( currentPos.x < otherPos.x )
+        result |= EAST;
+    if( currentPos.x > otherPos.x )
+        result |= WEST;
+    if( currentPos.y < otherPos.y )
+        result |= SOUTH;
+    if( currentPos.y > otherPos.y )
+        result |= NORTH;
+    if( currentPos.z < otherPos.z )
+        result |= TOP;
+    if( currentPos.z > otherPos.z )
+        result |= BOTTOM;
+    return result;
+}
+
+Framework::Vec3<int> getDirection( Directions dir )
+{
+    Framework::Vec3<int> result( 0, 0, 0 );
+    if( ( dir | NORTH ) == dir )
+        --result.y;
+    if( ( dir | EAST ) == dir )
+        ++result.x;
+    if( ( dir | SOUTH ) == dir )
+        ++result.y;
+    if( ( dir | WEST ) == dir )
+        --result.x;
+    if( ( dir | TOP ) == dir )
+        ++result.z;
+    if( ( dir | BOTTOM ) == dir )
+        --result.z;
+    return result;
 }

+ 6 - 1
FactoryCraft/Area.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#include <Vec3.h>
+
 struct Area
 {
     int startX;
@@ -19,5 +21,8 @@ enum Direction
     TOP = 16,
     BOTTOM = 32
 };
+typedef int Directions;
 
-Direction opposite( Direction dir );
+Direction opposite( Direction dir );
+Directions getDirections( Framework::Vec3<float> currentPos, Framework::Vec3<float> otherPos );
+Framework::Vec3<int> getDirection( Directions dir );

+ 28 - 10
FactoryCraft/Chunk.cpp

@@ -55,24 +55,42 @@ void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
     int index = ( location.x * CHUNK_SIZE + location.y ) * CHUNK_SIZE + location.z;
     Block *old = blocks[ index ];
     blocks[ index ] = block;
-    Block *neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x - 1, location.y, location.z ), dimensionId );
+    Block *neighbor = zGame->zBlockAt( location + getDirection( NORTH ), dimensionId );
     if( neighbor )
-        neighbor->neighbours[ WEST ] = block;
-    neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x + 1, location.y, location.z ), dimensionId );
-    if( neighbor )
-        neighbor->neighbours[ EAST ] = block;
-    neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x, location.y - 1, location.z ), dimensionId );
+    {
+        neighbor->neighbours[ SOUTH ] = block;
+        block->neighbours[ NORTH ] = neighbor;
+    }
+    neighbor = zGame->zBlockAt( location + getDirection( EAST ), dimensionId );
     if( neighbor )
+    {
+        neighbor->neighbours[ WEST ] = block;
+        block->neighbours[ EAST ] = neighbor;
+    }
+    neighbor = zGame->zBlockAt( location + getDirection( SOUTH ), dimensionId );
+    if( neighbor ) {}
+    {
         neighbor->neighbours[ NORTH ] = block;
-    neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x, location.y + 1, location.z ), dimensionId );
+        block->neighbours[ SOUTH ] = neighbor;
+    }
+    neighbor = zGame->zBlockAt( location + getDirection( WEST ), dimensionId );
     if( neighbor )
-        neighbor->neighbours[ SOUTH ] = block;
-    neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x, location.y, location.z - 1 ), dimensionId );
+    {
+        neighbor->neighbours[ EAST ] = block;
+        block->neighbours[ WEST ] = neighbor;
+    }
+    neighbor = zGame->zBlockAt( location + getDirection( TOP ), dimensionId );
     if( neighbor )
+    {
         neighbor->neighbours[ BOTTOM ] = block;
-    neighbor = zGame->zBlockAt( Framework::Vec3<int>( location.x, location.y, location.z + 1 ), dimensionId );
+        block->neighbours[ TOP ] = neighbor;
+    }
+    neighbor = zGame->zBlockAt( location + getDirection( BOTTOM ), dimensionId );
     if( neighbor )
+    {
         neighbor->neighbours[ TOP ] = block;
+        block->neighbours[ BOTTOM ] = neighbor;
+    }
     if( old )
         old->release();
 }

+ 8 - 8
FactoryCraft/Dimension.cpp

@@ -49,28 +49,28 @@ void Dimension::addChunk( Chunk *chunk )
     if( !chunks->z( addr ) )
     {
         chunks->set( addr, chunk );
-        getAddrOf( chunk->getCenter() + Punkt( 1, 0 ), addr );
+        getAddrOf( chunk->getCenter() + Punkt( CHUNK_SIZE, 0 ), addr );
         Chunk *zChunk = chunks->z( addr );
         if( zChunk )
         {
-            zChunk->setNeighbor( EAST, chunk );
-            chunk->setNeighbor( WEST, chunk );
+            zChunk->setNeighbor( WEST, chunk );
+            chunk->setNeighbor( EAST, chunk );
         }
-        getAddrOf( chunk->getCenter() + Punkt( -1, 0 ), addr );
+        getAddrOf( chunk->getCenter() + Punkt( -CHUNK_SIZE, 0 ), addr );
         zChunk = chunks->z( addr );
         if( zChunk )
         {
-            zChunk->setNeighbor( WEST, chunk );
-            chunk->setNeighbor( EAST, chunk );
+            zChunk->setNeighbor( EAST, chunk );
+            chunk->setNeighbor( WEST, chunk );
         }
-        getAddrOf( chunk->getCenter() + Punkt( 0, 1 ), addr );
+        getAddrOf( chunk->getCenter() + Punkt( 0, CHUNK_SIZE ), addr );
         zChunk = chunks->z( addr );
         if( zChunk )
         {
             zChunk->setNeighbor( NORTH, chunk );
             chunk->setNeighbor( SOUTH, chunk );
         }
-        getAddrOf( chunk->getCenter() + Punkt( 0, -1 ), addr );
+        getAddrOf( chunk->getCenter() + Punkt( 0, -CHUNK_SIZE ), addr );
         zChunk = chunks->z( addr );
         if( zChunk )
         {

+ 17 - 17
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -13,9 +13,6 @@
     <Filter Include="game">
       <UniqueIdentifier>{26d8996d-452d-4c1f-b52b-82310b4ee42f}</UniqueIdentifier>
     </Filter>
-    <Filter Include="items">
-      <UniqueIdentifier>{4d2e1a89-01ec-4f99-8aed-62d2e9707db9}</UniqueIdentifier>
-    </Filter>
     <Filter Include="effects">
       <UniqueIdentifier>{d758dbfd-2172-4c68-bc59-b39c289c28df}</UniqueIdentifier>
     </Filter>
@@ -55,6 +52,9 @@
     <Filter Include="server">
       <UniqueIdentifier>{479ff7ea-4fb5-4721-88d5-6f98e4e2ea07}</UniqueIdentifier>
     </Filter>
+    <Filter Include="inventory">
+      <UniqueIdentifier>{4d2e1a89-01ec-4f99-8aed-62d2e9707db9}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Event.h">
@@ -97,19 +97,19 @@
       <Filter>entities</Filter>
     </ClInclude>
     <ClInclude Include="Item.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="ItemStack.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="Inventory.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="ItemType.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="ItemSlot.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="EventThrower.h">
       <Filter>events</Filter>
@@ -121,7 +121,7 @@
       <Filter>effects</Filter>
     </ClInclude>
     <ClInclude Include="ItemSkill.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="Entity.h">
       <Filter>entities</Filter>
@@ -187,7 +187,7 @@
       <Filter>world</Filter>
     </ClInclude>
     <ClInclude Include="ItemFilter.h">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClInclude>
     <ClInclude Include="Server.h">
       <Filter>server</Filter>
@@ -219,7 +219,7 @@
       <Filter>static</Filter>
     </ClCompile>
     <ClCompile Include="ItemType.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="PerlinNoise.cpp">
       <Filter>world\generator\noise</Filter>
@@ -255,7 +255,7 @@
       <Filter>world\ticking</Filter>
     </ClCompile>
     <ClCompile Include="Item.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="Chunk.cpp">
       <Filter>world</Filter>
@@ -273,19 +273,19 @@
       <Filter>world\update</Filter>
     </ClCompile>
     <ClCompile Include="ItemStack.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="ItemSlot.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="ItemSkill.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="ItemFilter.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="Inventory.cpp">
-      <Filter>items</Filter>
+      <Filter>inventory</Filter>
     </ClCompile>
     <ClCompile Include="Area.cpp">
       <Filter>world</Filter>