فهرست منبع

render only blocksides where the direct neighbor block is transparent

Kolja Strohm 3 سال پیش
والد
کامیت
934b4c7f06

+ 39 - 34
FactoryCraft/BasicBlocks.cpp

@@ -88,28 +88,17 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
         vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
 
         data->setVertecies( vertecies, 24 );
-
-        // front side
+        // the order of the polygons has to be NORTH, EAST, SOUTH, WEST, TOP, BOTTOM according to the Area definition
+        // down side
         Polygon3D* p = new Polygon3D();
         p->indexAnz = 6;
         p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 0;
-        p->indexList[ 1 ] = 3;
-        p->indexList[ 2 ] = 2;
-        p->indexList[ 3 ] = 0;
-        p->indexList[ 4 ] = 1;
-        p->indexList[ 5 ] = 3;
-        data->addPolygon( p );
-        // back side
-        p = new Polygon3D();
-        p->indexAnz = 6;
-        p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4;
-        p->indexList[ 1 ] = 6;
-        p->indexList[ 2 ] = 7;
-        p->indexList[ 3 ] = 4;
-        p->indexList[ 4 ] = 7;
-        p->indexList[ 5 ] = 5;
+        p->indexList[ 0 ] = 6 + 16;
+        p->indexList[ 1 ] = 2 + 16;
+        p->indexList[ 2 ] = 3 + 16;
+        p->indexList[ 3 ] = 6 + 16;
+        p->indexList[ 4 ] = 3 + 16;
+        p->indexList[ 5 ] = 7 + 16;
         data->addPolygon( p );
         // right side
         p = new Polygon3D();
@@ -122,6 +111,17 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
         p->indexList[ 4 ] = 5 + 8;
         p->indexList[ 5 ] = 7 + 8;
         data->addPolygon( p );
+        // top side
+        p = new Polygon3D();
+        p->indexAnz = 6;
+        p->indexList = new int[ p->indexAnz ];
+        p->indexList[ 0 ] = 4 + 16;
+        p->indexList[ 1 ] = 1 + 16;
+        p->indexList[ 2 ] = 0 + 16;
+        p->indexList[ 3 ] = 4 + 16;
+        p->indexList[ 4 ] = 5 + 16;
+        p->indexList[ 5 ] = 1 + 16;
+        data->addPolygon( p );
         // left side
         p = new Polygon3D();
         p->indexAnz = 6;
@@ -133,29 +133,29 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
         p->indexList[ 4 ] = 6 + 8;
         p->indexList[ 5 ] = 4 + 8;
         data->addPolygon( p );
-        // top side
+        // back side
         p = new Polygon3D();
         p->indexAnz = 6;
         p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 4 + 16;
-        p->indexList[ 1 ] = 1 + 16;
-        p->indexList[ 2 ] = 0 + 16;
-        p->indexList[ 3 ] = 4 + 16;
-        p->indexList[ 4 ] = 5 + 16;
-        p->indexList[ 5 ] = 1 + 16;
+        p->indexList[ 0 ] = 4;
+        p->indexList[ 1 ] = 6;
+        p->indexList[ 2 ] = 7;
+        p->indexList[ 3 ] = 4;
+        p->indexList[ 4 ] = 7;
+        p->indexList[ 5 ] = 5;
         data->addPolygon( p );
-        // down side
+        data->calculateNormals();
+        // front side
         p = new Polygon3D();
         p->indexAnz = 6;
         p->indexList = new int[ p->indexAnz ];
-        p->indexList[ 0 ] = 6 + 16;
-        p->indexList[ 1 ] = 2 + 16;
-        p->indexList[ 2 ] = 3 + 16;
-        p->indexList[ 3 ] = 6 + 16;
-        p->indexList[ 4 ] = 3 + 16;
-        p->indexList[ 5 ] = 7 + 16;
+        p->indexList[ 0 ] = 0;
+        p->indexList[ 1 ] = 3;
+        p->indexList[ 2 ] = 2;
+        p->indexList[ 3 ] = 0;
+        p->indexList[ 4 ] = 1;
+        p->indexList[ 5 ] = 3;
         data->addPolygon( p );
-        data->calculateNormals();
     }
     setModelDaten( data );
     Bild* b = new Bild();
@@ -175,6 +175,11 @@ BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* z
     setModelTextur( textur );
 }
 
+bool BasicBlock::needRenderPolygon( int index )
+{
+    return CONST_BLOCK( zNeighbours[ index ], neighbourTypes[ index ] )->isTransparent();
+}
+
 
 DirtBlockType::DirtBlockType()
     : BlockType( ID )

+ 1 - 0
FactoryCraft/BasicBlocks.h

@@ -15,6 +15,7 @@ class BasicBlock : public Block
 {
 public:
     BasicBlock( const BlockType* zType, const char* texture, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t );
+    bool needRenderPolygon( int index ) override;
 
     friend DirtBlockType;
 };

+ 5 - 0
FactoryCraft/Block.cpp

@@ -61,6 +61,11 @@ void Block::setNeighbourType( Direction dir, int type )
     neighbourTypes[ getDirectionIndex( dir ) ] = type;
 }
 
+bool Block::isTransparent() const
+{
+    return transparent;
+}
+
 void Block::remove()
 {
     if( visible )

+ 1 - 0
FactoryCraft/Block.h

@@ -37,6 +37,7 @@ public:
     virtual void setNeighbour( Direction dir, Framework::Either<Block*, int> neighbour );
     virtual void setNeighbourBlock( Direction dir, Block* zN );
     virtual void setNeighbourType( Direction dir, int type );
+    bool isTransparent() const;
 
     void remove();
     bool isVisible() const;

+ 1 - 0
FactoryCraft/Main.cpp

@@ -53,6 +53,7 @@ int KSGStart Framework::Start( Framework::Startparam p )
     initMenus();
 
     RenderTh rTh;
+    rTh.setMaxFps( 120 );
     rTh.setBildschirm( dynamic_cast<Bildschirm*>(screen.getThis()) );
 
     rTh.beginn();

+ 2 - 2
FactoryCraft/NoBlock.cpp

@@ -3,8 +3,8 @@
 NoBlock::NoBlock()
     : Block( NoBlockBlockType::INSTANCE, 0, { 0,0,0 }, false )
 {
-    transparent = 1;
-    passable = 1;
+    transparent = 0;
+    passable = 0;
     hp = 0;
     maxHP = 0;
     hardness = 0;

+ 4 - 0
FactoryCraft/PlayerKam.cpp

@@ -142,6 +142,10 @@ void PlayerKam::doMausEreignis( Framework::MausEreignis& me )
                 int yDir = lastMousePos.y - me.originalY;
                 int xDir = lastMousePos.x - me.originalX;
                 setRotation( { min( max( getRotation().x - yDir * 0.005f, 0.1f ), 2.5f ), getRotation().y, getRotation().z - xDir * 0.005f } );
+                if( getRotation().z > 2 * PI )
+                    setRotation( { getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI } );
+                if( getRotation().z < -2 * PI )
+                    setRotation( { getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI } );
                 Vec3<float> direction = getWorldDirection( getScreenPos() + getScreenSize() / 2 );
                 char action[ 13 ];
                 action[ 0 ] = 2;

+ 2 - 0
FactoryCraft/World.cpp

@@ -96,6 +96,8 @@ void World::update( bool background )
                 serverMessageReader->lese( (char*)&target.x, 4 );
                 serverMessageReader->lese( (char*)&target.y, 4 );
                 serverMessageReader->lese( (char*)&target.z, 4 );
+                int side = 0;
+                serverMessageReader->lese( (char*)&side, 4 );
                 hasTarget = 1;
             }
             else