瀏覽代碼

Grafik Engine und maximale FPS einstellbar

Kolja Strohm 5 年之前
父節點
當前提交
13217c05f8

+ 6 - 1
KSGClient/Global/Render.cpp

@@ -2,6 +2,7 @@
 #include "Render.h"
 #include <Globals.h>
 #include <TastaturEreignis.h>
+#include <InitDatei.h>
 #include "..\Aktionen\AktionsThread.h"
 
 // Inhalt der Render Klasse aus Render.h
@@ -41,6 +42,7 @@ void Render::thread() // Render Schleife
     bool fpsAdd = 0;
     time->messungStart();
     double ausgleich = 0;
+    int maxFPS = 0;
     while( !exit )
     {
         if( bildschirm )
@@ -69,10 +71,13 @@ void Render::thread() // Render Schleife
             }
             else
                 Sleep( 100 );
+            bildschirm->lock();
+            maxFPS = userOptions->wertExistiert( "MaxFPS" ) ? *userOptions->zWert( "MaxFPS" ) : 30;
+            bildschirm->unlock();
         }
         else
             Sleep( 100 );
-        ausgleich += 1.0 / 30 - tickval;
+        ausgleich += 1.0 / maxFPS - tickval;
         if( ausgleich > 0 )
             Sleep( (int)( ausgleich * 1000 ) );
         time->messungEnde();

+ 4 - 0
KSGClient/Global/Variablen.cpp

@@ -3,6 +3,8 @@
 #include <Punkt.h>
 #include <DateiSystem.h>
 #include <Globals.h>
+#include <InitDatei.h>
+#include <Datei.h>
 #include "../Netzwerk/KSGServer.h"
 #include "../Leser/KartenLeser.h"
 
@@ -131,4 +133,6 @@ void releaseVariables()
     }
     if( updateH )
         updateH->release();
+    if( userOptions )
+        userOptions->release();
 }

+ 1 - 0
KSGClient/Global/Variablen.h

@@ -40,6 +40,7 @@ variable Bilder *bilder;
 variable UpdateHandler *updateH;
 variable bool _render;
 variable KeepAliveTh *keepAliveTh;
+variable InitDatei *userOptions;
 
 void initVariables( Schrift *zSchrift, Bildschirm *zBildschirm );
 void releaseVariables();

+ 55 - 4
KSGClient/NachLogin/Einstellungen/Einstellungen.cpp

@@ -1,5 +1,8 @@
 #include "Einstellungen.h"
 #include <MausEreignis.h>
+#include <GraphicsApi.h>
+#include <InitDatei.h>
+#include "../../Global/Variablen.h"
 #include "../../Global/Initialisierung.h"
 
 // Inhalt der Einstellungen Klasse aus Einstellungen.h
@@ -15,10 +18,50 @@ Einstellungen::Einstellungen( Schrift *zSchrift, Fenster *zF )
 	f->setSBgFarbe( 0xF0000000 );
 	f->setClosingMeParam( this );
 	f->setClosingMe( einstellungenSchließenME );
+    TextFeld *gat = initTextFeld( 5, 5, 300, 20, zSchrift, TextFeld::Style::Text, "Grafik Engine (Neustart erforderlich)" );
+    f->addMember( gat );
+    AuswahlBox *graphicAPI = initAuswahlBox( 5, 25, 100, 20, zSchrift, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, { "Aktuellste", "DirectX 9" } );
+    if( DirectX11::isAvailable() )
+        graphicAPI->addEintrag( "DirectX 11" );
+    if( DirectX12::isAvailable() )
+        graphicAPI->addEintrag( "DirectX 12" );
+    graphicAPI->setAuswahl( 0 );
+    if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX9" ) )
+        graphicAPI->setAuswahl( 1 );
+    if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX11" ) )
+        graphicAPI->setAuswahl( 2 );
+    if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX12" ) )
+        graphicAPI->setAuswahl( 3 );
+    graphicAPI->setEventAktion( [ this ]( void *p, AuswahlBox * b, int unused, int auswahl )
+    {
+        switch( auswahl )
+        {
+        case 1:
+            userOptions->setWert( "GraphicAPI", "DX9" );
+            break;
+        case 2:
+            userOptions->setWert( "GraphicAPI", "DX11" );
+            break;
+        case 3:
+            userOptions->setWert( "GraphicAPI", "DX12" );
+            break;
+        default:
+            userOptions->setWert( "GraphicAPI", "BEST" );
+            break;
+        }
+    } );
+    TextFeld *mft = initTextFeld( 5, 50, 200, 20, zSchrift, TextFeld::Style::Text, "Maximale FPS" );
+    f->addMember( mft );
+    maxFPS = initTextFeld( 5, 70, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "MaxFPS" ) ? userOptions->zWert( "MaxFPS" )->getText() : "30" );
+    maxFPS->setTastaturEreignis( _nurNummernTE );
+    f->addMember( maxFPS->getThis() );
 	ok = initKnopf( 390, 450, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Ok" );
 	ok->setMausEreignisParameter( this );
 	ok->setMausEreignis( einstellungenOkME );
 	f->addMember( ok->getThis() );
+    // add AuswahlBoxen
+    f->addMember( graphicAPI );
+
 	zF->addMember( f->getThis() );
 	ref = 1;
 }
@@ -26,6 +69,7 @@ Einstellungen::Einstellungen( Schrift *zSchrift, Fenster *zF )
 // Destruktor
 Einstellungen::~Einstellungen()
 {
+    maxFPS->release();
 	f->release();
 	ok->release();
 }
@@ -33,8 +77,6 @@ Einstellungen::~Einstellungen()
 // nicht constant
 void Einstellungen::setSichtbar()
 {
-    // TODO
-	//-------------------
 	f->setStyle( Fenster::Style::Sichtbar, f->hatStyleNicht( Fenster::Style::Sichtbar ) );
 }
 
@@ -50,8 +92,17 @@ bool Einstellungen::okME( MausEreignis &me )
 	if( me.id == ME_RLinks )
 	{
 		f->removeStyle( Fenster::Style::Sichtbar );
-        // TODO
-		//-----------------------------
+        int fps = *maxFPS->zText();
+        if( fps > 0 )
+        {
+            hauptScreen->lock();
+            if( !userOptions->wertExistiert( "MaxFPS" ) )
+                userOptions->addWert( "MaxFPS", maxFPS->zText()->getText() );
+            else
+                userOptions->setWert( "MaxFPS", maxFPS->zText()->getText() );
+            hauptScreen->unlock();
+        }
+        userOptions->speichern();
 	}
 	return 1;
 }

+ 1 - 0
KSGClient/NachLogin/Einstellungen/Einstellungen.h

@@ -11,6 +11,7 @@ class Einstellungen
 private:
 	Fenster *f;
 	Knopf *ok;
+    TextFeld *maxFPS;
 	int ref;
 
 public:

+ 23 - 2
KSGClient/Start/Start.cpp

@@ -16,6 +16,7 @@
 #include <sstream>
 #include <InitDatei.h>
 #include <TexturList.h>
+#include <GraphicsApi.h>
 
 void fensterVS( void *p, void *f )
 {
@@ -35,6 +36,19 @@ bool fensterTE( void *p, void *f, TastaturEreignis te )
 int KSGStart Framework::Start( Startparam p )
 {
     Network::Start( 50 );
+    
+    if( !DateiExistiert( "data/user_options.ini" ) )
+    {
+        userOptions = new InitDatei( "data/default_options.ini" );
+        userOptions->laden();
+        userOptions->setPfad( "data/user_options.ini" );
+        userOptions->speichern();
+    }
+    else
+    {
+        userOptions = new InitDatei( "data/user_options.ini" );
+        userOptions->laden();
+    }
 
     InitDatei init( "data/optionen.ini" );
     init.laden();
@@ -58,8 +72,15 @@ int KSGStart Framework::Start( Startparam p )
     fenster->setMausAktion( fensterME );
     fenster->setTastaturAktion( fensterTE );
     fenster->setVSchließAktion( fensterVS );
-
-    Bildschirm *bildschirm = new Bildschirm3D( fenster->getThis() );
+    Bildschirm *bildschirm = 0;
+    if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX9" ) )
+        bildschirm = new Bildschirm3D( fenster->getThis(), DIRECTX9 );
+    else if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX11" ) )
+        bildschirm = new Bildschirm3D( fenster->getThis(), DIRECTX11 );
+    else if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX12" ) )
+        bildschirm = new Bildschirm3D( fenster->getThis(), DIRECTX12 );
+    else
+        bildschirm = new Bildschirm3D( fenster->getThis() );
     fenster->setBildschirm( bildschirm->getThis() );
     fenster->setAnzeigeModus( 1 );
     fenster->setFokus();