Parcourir la source

fixed some errors

Kolja Strohm il y a 3 ans
Parent
commit
5cb4c24f10

+ 1 - 1
FactoryCraft/AddChunkUpdate.cpp

@@ -18,5 +18,5 @@ void AddChunkUpdateType::applyUpdate( Framework::StreamReader *zReader )
     zReader->lese( (char *)&center.y, 4 );
     Chunk *chunk = new Chunk( center, dimensionID );
     chunk->load( zReader );
-    currentGame->setChunk( chunk );
+    currentGame->setChunk( chunk, dimensionID );
 }

+ 163 - 1
FactoryCraft/BasicBlocks.cpp

@@ -1,9 +1,171 @@
 #include "BasicBlocks.h"
+#include <Model3D.h>
+#include <Globals.h>
+#include <GraphicsApi.h>
+#include <Bild.h>
+#include <Model3DList.h>
+#include "Globals.h"
 
 
 BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Textur *t )
     : Block( zTool, pos )
-{}
+{
+    Model3DData *data = 0;
+    if( Framework::zM3DRegister()->hatModel( "cube" ) )
+        data = Framework::zM3DRegister()->getModel( "cube" );
+    else
+    {
+        data = new Model3DData();
+        Framework::zM3DRegister()->addModel( dynamic_cast<Model3DData *>( data->getThis() ), "cube" );
+        float size = 1;
+        float left, right, top, bottom;
+        // Calculate the screen coordinates of the left side of the bitmap.
+        left = (float)( ( size / 2.0 ) * -1 );
+        // Calculate the screen coordinates of the right side of the bitmap.
+        right = left + (float)size;
+        // Calculate the screen coordinates of the top of the bitmap.
+        top = (float)( size / 2.0 );
+        // Calculate the screen coordinates of the bottom of the bitmap.
+        bottom = top - (float)size;
+        float front = -size / 2;
+        float back = front + size;
+
+        Vertex3D *vertecies = new Vertex3D[ 24 ];
+        for( int i = 0; i < 24; i++ )
+            vertecies[ i ].knochenId = 0;
+        vertecies[ 0 ].pos = Vec3<float >( left, top, front );
+        vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
+        vertecies[ 1 ].pos = Vec3<float >( right, top, front );
+        vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
+        vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
+        vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
+        vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
+        vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
+        vertecies[ 4 ].pos = Vec3<float >( left, top, back );
+        vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
+        vertecies[ 5 ].pos = Vec3<float >( right, top, back );
+        vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
+        vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
+        vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
+        vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
+        vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+        vertecies[ 8 ].pos = Vec3<float >( left, top, front );
+        vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
+        vertecies[ 9 ].pos = Vec3<float >( right, top, front );
+        vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
+        vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
+        vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
+        vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
+        vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
+        vertecies[ 12 ].pos = Vec3<float >( left, top, back );
+        vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
+        vertecies[ 13 ].pos = Vec3<float >( right, top, back );
+        vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
+        vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
+        vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
+        vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
+        vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+        vertecies[ 16 ].pos = Vec3<float >( left, top, front );
+        vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
+        vertecies[ 17 ].pos = Vec3<float >( right, top, front );
+        vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
+        vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
+        vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
+        vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
+        vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
+        vertecies[ 20 ].pos = Vec3<float >( left, top, back );
+        vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
+        vertecies[ 21 ].pos = Vec3<float >( right, top, back );
+        vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
+        vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
+        vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
+        vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
+        vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
+
+        model->setVertecies( vertecies, 24 );
+
+        // front 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;
+        model->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;
+        model->addPolygon( p );
+        // right side
+        p = new Polygon3D();
+        p->indexAnz = 6;
+        p->indexList = new int[ p->indexAnz ];
+        p->indexList[ 0 ] = 1 + 8;
+        p->indexList[ 1 ] = 7 + 8;
+        p->indexList[ 2 ] = 3 + 8;
+        p->indexList[ 3 ] = 1 + 8;
+        p->indexList[ 4 ] = 5 + 8;
+        p->indexList[ 5 ] = 7 + 8;
+        model->addPolygon( p );
+        // left side
+        p = new Polygon3D();
+        p->indexAnz = 6;
+        p->indexList = new int[ p->indexAnz ];
+        p->indexList[ 0 ] = 0 + 8;
+        p->indexList[ 1 ] = 2 + 8;
+        p->indexList[ 2 ] = 6 + 8;
+        p->indexList[ 3 ] = 0 + 8;
+        p->indexList[ 4 ] = 6 + 8;
+        p->indexList[ 5 ] = 4 + 8;
+        model->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;
+        model->addPolygon( p );
+        // down 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;
+        model->addPolygon( p );
+    }
+    setModelDaten( data );
+    Bild *b = new Bild();
+    b->neuBild( 10, 10, 0xFF2B240B );
+    Textur *tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "dirt", b );
+    Model3DTextur *textur = new Model3DTextur();
+    textur->setPolygonTextur( 0, dynamic_cast<Textur *>( tex->getThis() ) );
+    textur->setPolygonTextur( 1, dynamic_cast<Textur *>( tex->getThis() ) );
+    textur->setPolygonTextur( 2, dynamic_cast<Textur *>( tex->getThis() ) );
+    textur->setPolygonTextur( 3, dynamic_cast<Textur *>( tex->getThis() ) );
+    textur->setPolygonTextur( 4, dynamic_cast<Textur *>( tex->getThis() ) );
+    textur->setPolygonTextur( 5, tex );
+    setModelTextur( textur );
+}
 
 
 DirtBlockType::DirtBlockType()

+ 2 - 2
FactoryCraft/DirectConnect.cpp

@@ -13,7 +13,7 @@ DirectConnect::DirectConnect( Bildschirm *zScreen )
     elements.add( address );
     elements.add( port );
     Knopf *login = initKnopf( 200, 60, 100, 20, Knopf::Style::Normal, "Beitreten" );
-    login->setMausEreignis( [this, login]( void *p, void *o, MausEreignis me )
+    login->setMausEreignis( [this, login, zScreen]( void *p, void *o, MausEreignis me )
     {
         if( me.id == ME_RLinks )
         {
@@ -22,7 +22,7 @@ DirectConnect::DirectConnect( Bildschirm *zScreen )
             port->removeStyle( TextFeld::Style::Erlaubt );
             if( network->connect( address->zText()->getText(), (short)(int)*port->zText() ) )
             {
-                currentGame = new World();
+                currentGame = new World( dynamic_cast<Bildschirm3D *>( zScreen ) );
                 hide();
                 menuRegister->get( "game" )->show();
             }

+ 1 - 3
FactoryCraft/FactoryClient.cpp

@@ -18,10 +18,8 @@ FactoryClient::~FactoryClient()
 bool FactoryClient::connect( Text ip, short port, int accountId, Text secret )
 {
     if( client )
-    {
         disconnect();
-        client = new SSLKlient();
-    }
+    client = new SSLKlient();
     if( !client->verbinde( port, ip ) )
         return false;
     connected = 1;

+ 1 - 1
FactoryCraft/FactoryCraft.vcxproj

@@ -189,6 +189,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Debug\Network.dll" "network.dll"</Com
     <ClCompile Include="Main.cpp" />
     <ClCompile Include="Menu.cpp" />
     <ClCompile Include="NetworkHandler.cpp" />
+    <ClCompile Include="StaticInitializerOrder.cpp" />
     <ClCompile Include="World.cpp" />
     <ClCompile Include="WorldUpdate.cpp" />
   </ItemGroup>
@@ -216,7 +217,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Debug\Network.dll" "network.dll"</Com
     <ClInclude Include="Login.h" />
     <ClInclude Include="Menu.h" />
     <ClInclude Include="NetworkHandler.h" />
-    <ClInclude Include="StaticInitializerOrder.h" />
     <ClInclude Include="StaticRegistry.h" />
     <ClInclude Include="WorldUpdate.h" />
     <ClInclude Include="World.h" />

+ 3 - 3
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -99,6 +99,9 @@
     <ClCompile Include="Dimension.cpp">
       <Filter>world</Filter>
     </ClCompile>
+    <ClCompile Include="StaticInitializerOrder.cpp">
+      <Filter>static</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Menu.h">
@@ -155,9 +158,6 @@
     <ClInclude Include="StaticRegistry.h">
       <Filter>static</Filter>
     </ClInclude>
-    <ClInclude Include="StaticInitializerOrder.h">
-      <Filter>static</Filter>
-    </ClInclude>
     <ClInclude Include="BlockType.h">
       <Filter>world</Filter>
     </ClInclude>

+ 17 - 2
FactoryCraft/NetworkHandler.cpp

@@ -52,7 +52,9 @@ NetworkHandler::~NetworkHandler()
     }
     if( lsc )
     {
+        lsc->verbinde();
         lsc->logout();
+        lsc->trenne( 1 );
         lsc->release();
     }
     if( msc )
@@ -75,7 +77,16 @@ bool NetworkHandler::login( Framework::Text name, Framework::Text password )
         }
         lsc->logout();
     }
-    return lsc->login( name, password );
+    lsc->verbinde();
+    bool ok = lsc->login( name, password );
+    lsc->trenne( ok );
+    if( ok )
+    {
+        accountId = lsc->getAccountId();
+        lsc->release();
+        lsc = 0;
+    }
+    return ok;
 }
 
 bool NetworkHandler::connect( Text ip, short port )
@@ -83,7 +94,11 @@ bool NetworkHandler::connect( Text ip, short port )
     if( !gsc )
         gsc = msc->createMinigameServerClient();
     Text *secret = gsc->getSecret();
-    bool ok = fc->connect( ip, port, lsc->getAccountId(), *secret );
+    if( !secret )
+        return 0;
+    if( !fc )
+        fc = new FactoryClient();
+    bool ok = fc->connect( ip, port, accountId, *secret );
     secret->release();
     return ok;
 }

+ 1 - 0
FactoryCraft/NetworkHandler.h

@@ -12,6 +12,7 @@ private:
     KSGClient::MinigameServerClient *gsc;
     KSGClient::ErhaltungServerClient *esc;
     FactoryClient *fc;
+    int accountId;
 
 public:
     NetworkHandler();

+ 19 - 0
FactoryCraft/StaticInitializerOrder.cpp

@@ -0,0 +1,19 @@
+#include "StaticRegistry.h"
+#include "BlockType.h"
+#include "ItemType.h"
+
+int count_DimensionGenerator = 0;
+int count_ItemType = 0;
+int count_BlockType = 0;
+int count_WorldUpdateType = 0;
+int count_EntityType = 0;
+
+#undef REGISTER
+#define REGISTER(c, typ)               \
+const int c::ID = count_##typ++;       \
+const c *c::INSTANCE = new c(); 
+
+#include "BasicBlocks.h"
+//#include "OverworldDimension.h"
+#include "AddChunkUpdate.h"
+//#include "Player.h"

+ 3 - 3
FactoryCraft/StaticInitializerOrder.h

@@ -1,7 +1,7 @@
 #pragma once
 #include "StaticRegistry.h"
-//#include "BlockType.h"
-//#include "ItemType.h"
+#include "BlockType.h"
+#include "ItemType.h"
 
 int count_DimensionGenerator = 0;
 int count_ItemType = 0;
@@ -14,7 +14,7 @@ int count_EntityType = 0;
 const int c::ID = count_##typ++;       \
 const c *c::INSTANCE = new c(); 
 
-//#include "BasicBlocks.h"
+#include "BasicBlocks.h"
 //#include "OverworldDimension.h"
 #include "AddChunkUpdate.h"
 //#include "Player.h"

+ 46 - 3
FactoryCraft/World.cpp

@@ -7,18 +7,23 @@
 using namespace Network;
 using namespace Framework;
 
-World::World()
+World::World( Bildschirm3D *zScreen )
 {
     renderedWorld = new Welt3D();
     dimensions = new RCArray<Dimension>();
     currentPlayer = new CurrentPlayer();
+    zScreenPtr = zScreen;
+    kam = new Kam3D();
+    kam->setWelt( renderedWorld );
+    zScreen->addKamera( kam );
 }
 
 World::~World()
 {
+    zScreenPtr->removeKamera( kam );
     dimensions->release();
     currentPlayer->release();
-    renderedWorld->release();
+    kam->release();
 }
 
 void World::update()
@@ -37,7 +42,45 @@ void World::update()
     }
 }
 
-void World::setChunk( Chunk *chunk )
+void World::setChunk( Chunk *chunk, int dimensionId )
 {
+    Dimension *zDim = zDimension( dimensionId );
+    if( !zDim )
+    {
+        zDim = new Dimension( dimensionId );
+        dimensions->add( zDim );
+    }
+    zDim->addChunk( chunk );
+    zDim->updateVisibility();
+}
+
+Block *World::zBlockAt( Framework::Vec3<int> location, int dimension ) const
+{
+    Dimension *dim = zDimension( dimension );
+    if( dim )
+        return dim->zBlock( location );
+    return 0;
+}
 
+Dimension *World::zDimension( int id ) const
+{
+    for( auto dim = dimensions->getIterator(); dim; dim++ )
+    {
+        if( dim->getDimensionId() == id )
+            return dim;
+    }
+    return 0;
+}
+
+void World::setVisibility( Framework::Model3D *zModel, bool visible )
+{
+    if( visible )
+        renderedWorld->addZeichnung( dynamic_cast<Framework::Model3D *>( zModel->getThis() ) );
+    else
+        renderedWorld->removeZeichnung( zModel );
+}
+
+Framework::Bildschirm3D *World::zScreen() const
+{
+    return zScreenPtr;
 }

+ 7 - 2
FactoryCraft/World.h

@@ -1,6 +1,8 @@
 #pragma once
 
 #include <Welt3D.h>
+#include <Bildschirm.h>
+#include <Kam3D.h>
 
 #include "Dimension.h"
 #include "CurrentPlayer.h"
@@ -11,14 +13,17 @@ private:
     Framework::RCArray<Dimension> *dimensions;
     CurrentPlayer *currentPlayer;
     Framework::Welt3D *renderedWorld;
+    Framework::Bildschirm3D *zScreenPtr;
+    Framework::Kam3D *kam;
 
 public:
-    World();
+    World( Framework::Bildschirm3D *zScreen );
     ~World();
     void update();
-    void setChunk( Chunk *chunk );
+    void setChunk( Chunk *chunk, int dimensionId );
 
     Block *zBlockAt( Framework::Vec3<int> location, int dimension ) const;
     Dimension *zDimension( int id ) const;
     void setVisibility( Framework::Model3D *zModel, bool visible );
+    Framework::Bildschirm3D *zScreen() const;
 };