Ver Fonte

fix naighbor indizes

Kolja Strohm há 3 anos atrás
pai
commit
0660d863a4
4 ficheiros alterados com 30 adições e 11 exclusões
  1. 24 6
      FactoryCraft/Area.cpp
  2. 2 1
      FactoryCraft/Area.h
  3. 3 3
      FactoryCraft/Block.cpp
  4. 1 1
      FactoryCraft/Chunk.cpp

+ 24 - 6
FactoryCraft/Area.cpp

@@ -4,17 +4,35 @@
 Framework::Vec3<int> getDirection( Directions dir )
 {
     Framework::Vec3<int> result( 0, 0, 0 );
-    if( ( dir | NORTH ) == dir )
+    if( (dir | NORTH) == dir )
         --result.y;
-    if( ( dir | EAST ) == dir )
+    if( (dir | EAST) == dir )
         ++result.x;
-    if( ( dir | SOUTH ) == dir )
+    if( (dir | SOUTH) == dir )
         ++result.y;
-    if( ( dir | WEST ) == dir )
+    if( (dir | WEST) == dir )
         --result.x;
-    if( ( dir | TOP ) == dir )
+    if( (dir | TOP) == dir )
         ++result.z;
-    if( ( dir | BOTTOM ) == dir )
+    if( (dir | BOTTOM) == dir )
         --result.z;
     return result;
+}
+
+int getDirectionIndex( Direction dir )
+{
+    if( dir == NORTH )
+        return 0;
+    if( dir == EAST )
+        return 1;
+    if( dir == SOUTH )
+        return 2;
+    if( dir == WEST )
+        return 3;
+    if( dir == TOP )
+        return 4;
+    if( dir == BOTTOM )
+        return 5;
+    assert( false );
+    return -1;
 }

+ 2 - 1
FactoryCraft/Area.h

@@ -23,4 +23,5 @@ enum Direction
 };
 typedef int Directions;
 
-Framework::Vec3<int> getDirection( Directions dir );
+Framework::Vec3<int> getDirection( Directions dir );
+int getDirectionIndex( Direction dir );

+ 3 - 3
FactoryCraft/Block.cpp

@@ -26,7 +26,7 @@ bool Block::updateVisibility()
     for( int d = 0; d < 6; d++ )
     {
         if( IS_BLOCK( zNeighbours[ d ] ) )
-            v |= zNeighbours[ d ]->isVisible() && ( zNeighbours[ d ]->transparent || zNeighbours[ d ]->passable );
+            v |= zNeighbours[ d ]->isVisible() && (zNeighbours[ d ]->transparent || zNeighbours[ d ]->passable);
         else if( zNeighbours[ d ] )
             v = 1;
     }
@@ -41,7 +41,7 @@ bool Block::updateVisibility()
 
 void Block::setNeighbour( Direction dir, Block *zN )
 {
-    zNeighbours[ dir ] = zN;
+    zNeighbours[ getDirectionIndex( dir ) ] = zN;
 }
 
 bool Block::isVisible() const
@@ -71,7 +71,7 @@ BasicBlockItemType::BasicBlockItemType( int id )
 void BasicBlockItemType::loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const
 {
     ItemType::loadSuperItem( zItem, zReader );
-    BasicBlockItem *item = dynamic_cast<BasicBlockItem *>( zItem );
+    BasicBlockItem *item = dynamic_cast<BasicBlockItem *>(zItem);
     if( !item )
         throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
     zReader->lese( (char *)&item->transparent, 1 );

+ 1 - 1
FactoryCraft/Chunk.cpp

@@ -109,7 +109,7 @@ void Chunk::putBlockAt( Framework::Vec3<int> location, Block *block )
 
 void Chunk::setNeighbor( Direction dir, Chunk *zChunk )
 {
-    zNeighbours[ dir ] = zChunk;
+    zNeighbours[ getDirectionIndex( dir ) ] = zChunk;
     for( int i = 0; i < CHUNK_SIZE; i++ )
     {
         for( int z = 0; z < WORLD_HEIGHT; z++ )