소스 검색

fixed block positioning bug

Kolja Strohm 3 년 전
부모
커밋
ecc195d13d
4개의 변경된 파일16개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 2
      FactoryCraft/Chunk.cpp
  2. 12 2
      FactoryCraft/Game.cpp
  3. 1 1
      FactoryCraft/Game.h
  4. 1 1
      FactoryCraft/World.cpp

+ 2 - 2
FactoryCraft/Chunk.cpp

@@ -26,7 +26,7 @@ Block* Chunk::zBlockAt( Framework::Vec3<int> location )
     cs.lock();
     for( Block* b : blocks )
     {
-        if( (Framework::Vec3<int>)b->getPos() == location )
+        if( Framework::Vec3<int>( (int)floor( b->getPos().x ), (int)floor( b->getPos().y ), (int)floor( b->getPos().z ) ) == location )
         {
             cs.unlock();
             return b;
@@ -134,7 +134,7 @@ void Chunk::updateVisibility()
     cs.lock();
     for( Block* b : blocks )
     {
-        Framework::Vec3<int> pos = (Framework::Vec3<int>)b->getPos();
+        Framework::Vec3<int> pos = Framework::Vec3<int>( (int)floor( b->getPos().x ), (int)floor( b->getPos().y ), (int)floor( b->getPos().z ) );
         for( int i = 0; i < 6; i++ )
         {
             Block* c = zBlockAt( pos + getDirection( getDirectionFromIndex( i ) ) );

+ 12 - 2
FactoryCraft/Game.cpp

@@ -29,11 +29,11 @@ Game::Game( Bildschirm* zScreen )
         return 1;
     } );
     elements.add( logout );
-    debug = initTextFeld( 10, 40, 500, 20, TextFeld::Style::Text, "" );
+    debug = initTextFeld( 10, 40, 500, 40, TextFeld::Style::Text | TextFeld::Style::Mehrzeilig, "" );
     elements.add( debug );
 }
 
-void Game::updatePosition( Vec3<float> position )
+void Game::updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos )
 {
     Text txt = "Position: (";
     txt.setPrecision( 2 );
@@ -43,5 +43,15 @@ void Game::updatePosition( Vec3<float> position )
     txt += ", ";
     txt += position.z;
     txt += ")";
+    if( target )
+    {
+        txt += "\nTarget: (";
+        txt += targetPos.x;
+        txt += ", ";
+        txt += targetPos.y;
+        txt += ", ";
+        txt += targetPos.z;
+        txt += ")";
+    }
     debug->setText( txt );
 }

+ 1 - 1
FactoryCraft/Game.h

@@ -14,5 +14,5 @@ public:
     // Konstruktor
     Game( Bildschirm* zScreen );
 
-    void updatePosition( Vec3<float> position );
+    void updatePosition( Vec3<float> position, bool target, Vec3<int> targetPos );
 };

+ 1 - 1
FactoryCraft/World.cpp

@@ -72,7 +72,6 @@ void World::update( bool background )
                 serverMessageReader->lese( (char*)&dir.z, 4 );
                 kam->setDirection( dir );
             }
-            ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos );
             for( Dimension* dim : *dimensions )
                 dim->removeDistantChunks( { (int)pos.x, (int)pos.y }, this );
             char b = 0;
@@ -111,6 +110,7 @@ void World::update( bool background )
                         block.getA()->setAmbientFactor( block.getA()->getAmbientFactor() + 0.2f );
                 }
             }
+            ((Game*)(Menu*)menuRegister->get( "game" ))->updatePosition( pos, hasTarget, target );
         }
         network->zFactoryClient()->endMessageReading( background );
     }