Parcourir la source

Neue Critical Klasse des Frameworks wird nun verwendet

Kolja Strohm il y a 6 ans
Parent
commit
2e674218cf
9 fichiers modifiés avec 56 ajouts et 55 suppressions
  1. 4 3
      GSL/GSL.vcxproj
  2. 27 26
      GSL/GSLDatei.cpp
  3. 2 1
      GSL/GSLDatei.h
  4. 1 1
      GSL/Include/GSLSoundV.h
  5. 8 10
      GSL/Player.cpp
  6. 2 1
      GSL/Player.h
  7. 7 9
      GSL/Sound.cpp
  8. 2 1
      GSL/Sound.h
  9. 3 3
      build.bat

+ 4 - 3
GSL/GSL.vcxproj

@@ -126,7 +126,8 @@
       <AdditionalDependencies>Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <CustomBuildStep>
-      <Command>copy "..\x64\Debug\GSL.dll" "..\..\..\Spiele Platform\Klient\patcher\patcher\data\bin\GSL.dll"</Command>
+      <Command>copy "x64\Debug\GSL.dll" "..\..\..\Spiele Platform\Klient\patcher\patcher\data\bin\GSL.dll"
+copy "x64\Debug\GSL.dll" "..\..\..\Spiele Platform\Klient\Fertig\Debug\x64\data\bin\GSL.dll"</Command>
     </CustomBuildStep>
     <CustomBuildStep>
       <Outputs>kopieren...;%(Outputs)</Outputs>
@@ -151,7 +152,7 @@
       <AdditionalDependencies>Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <CustomBuildStep>
-      <Command>copy "..\Release\GSL.dll" "..\..\..\Spiele Platform\Klient\Fertig\x32\data\bin\GSL.dll"</Command>
+      <Command>copy "Release\GSL.dll" "..\..\..\Spiele Platform\Klient\Fertig\x32\data\bin\GSL.dll"</Command>
     </CustomBuildStep>
     <CustomBuildStep>
       <Outputs>kopieren...;%(Outputs)</Outputs>
@@ -176,7 +177,7 @@
       <AdditionalDependencies>Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <CustomBuildStep>
-      <Command>copy "..\x64\Release\GSL.dll" "..\..\..\Spiele Platform\Klient\Fertig\x64\data\bin\GSL.dll"</Command>
+      <Command>copy "x64\Release\GSL.dll" "..\..\..\Spiele Platform\Klient\Fertig\x64\data\bin\GSL.dll"</Command>
     </CustomBuildStep>
     <CustomBuildStep>
       <Outputs>kopieren...;%(Outputs)</Outputs>

+ 27 - 26
GSL/GSLDatei.cpp

@@ -13,7 +13,6 @@ GSLDatei::GSLDatei()
 {
 	sounds = new Array< SoundKopf >();
 	pfad = new Text();
-	InitializeCriticalSection( &cs );
 	ref = 1;
 }
 
@@ -22,35 +21,37 @@ GSLDatei::~GSLDatei()
 {
 	sounds->release();
 	pfad->release();
-	DeleteCriticalSection( &cs );
 }
 
 // Datei open
 void GSLDatei::setDatei( Framework::Text *txt )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	pfad->setText( txt );
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 }
 
 void GSLDatei::setDatei( char *txt )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	pfad->setText( txt );
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 }
 
 bool GSLDatei::leseDaten()
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	sounds->leeren();
 	Datei d;
 	d.setDatei( *pfad );
-	if( !d.getSize() )
-		return 1;
+    if( !d.getSize() )
+    {
+        cs.unlock();
+        return 1;
+    }
 	if( !d.open( Datei::Style::lesen ) )
 	{
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 0;
 	}
 	unsigned char sAnz = 0;
@@ -106,7 +107,7 @@ bool GSLDatei::leseDaten()
 		sounds->add( kpf );
 	}
 	d.close();
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 	return 1;
 }
 
@@ -132,17 +133,17 @@ GSLSoundV *GSLDatei::getSound( Framework::Text *name )
 
 GSLSoundV *GSLDatei::getSound( char *name )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	int anz = sounds->getEintragAnzahl();
 	for( int i = 0; i < anz; i++ )
 	{
 		if( sounds->get( i ).name.istGleich( name ) )
 		{
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			return new GSLSound( sounds->get( i ) );
 		}
 	}
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 	return 0;
 }
 
@@ -177,14 +178,14 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 			break;
 	}
 	name = kName;
-	EnterCriticalSection( &cs );
+    cs.lock();
 	// Prüfen ob bereits vorhanden
 	int anz = sounds->getEintragAnzahl();
 	for( int i = 0; i < anz; i++ )
 	{
 		if( sounds->get( i ).name.istGleich( name ) )
 		{
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			return 0;
 		}
 	}
@@ -196,7 +197,7 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 	tmp.erstellen();
 	if( !tmp.open( Datei::Style::schreiben ) )
 	{
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 0;
 	}
 	char *buffer = new char[ 0x4000 ];
@@ -241,7 +242,7 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 	{
 		sounds->remove( sAnz );
 		tmp.remove();
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 0;
 	}
 	sAnz = (unsigned char)sounds->getEintragAnzahl();
@@ -298,7 +299,7 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 			neu.close();
 			neu.remove();
 			sounds->remove( sAnz );
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			return 0;
 		}
 		alt.setLPosition( hLen, 0 );
@@ -320,7 +321,7 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 		neu.close();
 		neu.remove();
 		sounds->remove( sAnz );
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 0;
 	}
 	for( int i = 0; i < (int)tmp.getSize(); )
@@ -340,7 +341,7 @@ bool GSLDatei::speicherSound( GSLSoundV *zSound, char *name )
 	alt.remove();
 	neu.umbenennen( *pfad );
 	leseDaten();
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 	return 1;
 }
 
@@ -354,7 +355,7 @@ bool GSLDatei::removeSound( Framework::Text *name )
 
 bool GSLDatei::removeSound( char *name )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	// Prüfen ob vorhanden
 	int anz = sounds->getEintragAnzahl();
 	int num = -1;
@@ -368,7 +369,7 @@ bool GSLDatei::removeSound( char *name )
 	}
 	if( num < 0 )
 	{
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 1;
 	}
 	Text neuPf = pfad->getText();
@@ -379,7 +380,7 @@ bool GSLDatei::removeSound( char *name )
 	neu.erstellen();
 	if( !neu.open( Datei::Style::schreiben ) )
 	{
-		LeaveCriticalSection( &cs );
+        cs.unlock();
 		return 0;
 	}
 	SoundKopf kpf = sounds->get( num );
@@ -443,7 +444,7 @@ bool GSLDatei::removeSound( char *name )
 		{
 			neu.close();
 			neu.remove();
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			return 0;
 		}
 		alt.setLPosition( neu.getSPosition() + ( 140 + 5 * kpf.name.getLength() ) / 8, 0 );
@@ -475,7 +476,7 @@ bool GSLDatei::removeSound( char *name )
 	alt.remove();
 	neu.umbenennen( *pfad );
 	leseDaten();
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 	return 1;
 }
 

+ 2 - 1
GSL/GSLDatei.h

@@ -4,6 +4,7 @@
 #include <Text.h>
 #include <Array.h>
 #include <Datei.h>
+#include <Critical.h>
 #ifdef WIN32
 #include "Include/GSLDateiV.h"
 #else
@@ -29,7 +30,7 @@ namespace GSL
 	private:
 		Array< SoundKopf > *sounds;
 		Text *pfad;
-		CRITICAL_SECTION cs;
+		Critical cs;
 		int ref;
 
 	public:

+ 1 - 1
GSL/Include/GSLSoundV.h

@@ -5,7 +5,7 @@
 
 namespace GSL
 {
-    class GSLSoundV : protected Framework::Thread
+    class GSLSoundV : protected virtual Framework::Thread
     {
     public:
         virtual ~GSLSoundV()

+ 8 - 10
GSL/Player.cpp

@@ -15,55 +15,53 @@ void CALLBACK AudioOutProc( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DWOR
 // Konstruktor
 GSLPlayer::GSLPlayer()
 {
-	InitializeCriticalSection( &cs );
 }
 
 // Destruktor
 GSLPlayer::~GSLPlayer()
 {
 	sounds.leeren();
-	DeleteCriticalSection( &cs );
 }
 
 // nicht constant
 bool GSLPlayer::addSound( GSLSound *snd )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	int anz = sounds.getEintragAnzahl();
 	for( int i = 0; i < anz; i++ )
 	{
 		if( sounds.z( i ) == snd )
 		{
 			snd->release();
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			return 0;
 		}
 	}
 	sounds.add( snd );
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 	return 1;
 }
 
 void GSLPlayer::removeSound( GSLSound *zSnd )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	int anz = sounds.getEintragAnzahl();
 	for( int i = 0; i < anz; i++ )
 	{
 		if( sounds.z( i ) == zSnd )
 		{
-			LeaveCriticalSection( &cs );
+            cs.unlock();
 			sounds.remove( i );
 			return;
 		}
 	}
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 }
 
 #ifdef WIN32
 void GSLPlayer::sendSoundMSG( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
 {
-	EnterCriticalSection( &cs );
+    cs.lock();
 	int anz = sounds.getEintragAnzahl();
 	for( int i = 0; i < anz; i++ )
 	{
@@ -73,6 +71,6 @@ void GSLPlayer::sendSoundMSG( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DW
 			break;
 		}
 	}
-	LeaveCriticalSection( &cs );
+    cs.unlock();
 }
 #endif

+ 2 - 1
GSL/Player.h

@@ -9,6 +9,7 @@
 #include <mmsystem.h>
 #include <Array.h>
 #include "Sound.h"
+#include <Critical.h>
 
 #pragma comment( lib, "winmm.lib" )
 #else
@@ -24,7 +25,7 @@ namespace GSL
 	{
 	private:
 		RCArray< GSLSound > sounds;
-		CRITICAL_SECTION cs;
+		Critical cs;
 
 	public:
 		// Konstruktor

+ 7 - 9
GSL/Sound.cpp

@@ -15,6 +15,7 @@ void CALLBACK AudioOutProc( HWAVEOUT hOut, UINT uMsg, DWORD_PTR dwInstance, DWOR
 // Inhalt der Sound Klasse aus Sound.h
 // Konstruktor
 GSLSound::GSLSound( const SoundKopf &skpf )
+    : Thread()
 {
 	kpf = skpf;
 	dat = new Datei();
@@ -25,7 +26,6 @@ GSLSound::GSLSound( const SoundKopf &skpf )
 	uAudioDelay = 0;
 	uAudioCount = 0;
 	uAudioPlay = 16;
-	hAudioCs = { 0 };
 	hAudioEvent = 0;
 	uAudioWrite = 0;
 	uAudioStop = 0;
@@ -102,7 +102,6 @@ int GSLSound::audioOpen()
 	}
 	if( waveOutGetDevCaps( (UINT_PTR)hAudioId, (LPWAVEOUTCAPSA)&sAudioCaps, sizeof( WAVEOUTCAPS ) ) )
 		memset( &sAudioCaps, 0, sizeof( sAudioCaps ) );
-	InitializeCriticalSection( &hAudioCs );
 	waveOutReset( hAudioId );
 	waveOutSetVolume( hAudioId, 0xFFFFFFFF );
 #endif
@@ -120,7 +119,6 @@ int GSLSound::audioClose()
 	if( !hAudioId )
 		return 1;
 	audioStop();
-	DeleteCriticalSection( &hAudioCs );
 	while( uAudioCount > 0 )
 	{
 		uAudioCount--;
@@ -198,11 +196,11 @@ int GSLSound::audioSchreiben( unsigned int uCount )
 	{
 		aAudioSize[ uAudioDelay ] = uCount;
 		uAudioDelay++;
-		EnterCriticalSection( &hAudioCs );				// increase write pos 
+        hAudioCs.lock();				// increase write pos 
 		uAudioWrite++;
 		if( uAudioWrite >= uAudioCount )
 			uAudioWrite = 0;
-		LeaveCriticalSection( &hAudioCs );
+        hAudioCs.unlock();
 		return 0;
 	}
 	if( uAudioDelay == 8 )
@@ -222,7 +220,7 @@ int GSLSound::audioSchreiben( unsigned int uCount )
 	pHeader->dwBufferLength = uCount;
 	if( waveOutWrite( hAudioId, pHeader, sizeof( WAVEHDR ) ) )
 		return 3;
-	EnterCriticalSection( &hAudioCs );
+    hAudioCs.lock();
 	uAudioWrite++;
 	if( uAudioWrite >= uAudioCount )
 		uAudioWrite = 0;
@@ -231,7 +229,7 @@ int GSLSound::audioSchreiben( unsigned int uCount )
 		iDelta += uAudioCount;
 	if( iDelta < 2 )
 		ResetEvent( hAudioEvent );
-	LeaveCriticalSection( &hAudioCs );
+    hAudioCs.unlock();
 #endif
 	return 0;
 }
@@ -337,7 +335,7 @@ void GSLSound::msg( UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_P
 	{
 	case WOM_DONE:
 		pHeader = (WAVEHDR*)dwParam1;
-		EnterCriticalSection( &hAudioCs );
+        hAudioCs.lock();
 		InterlockedExchangeAdd( (unsigned __int64*)&lAudioDone, (__int64)pHeader->dwBufferLength );
 		iDelta = (int)( uAudioPlay - pHeader->dwUser );
 		if( iDelta < 0 )
@@ -353,7 +351,7 @@ void GSLSound::msg( UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_P
 			if( iDelta >= 2 )
 				SetEvent( hAudioEvent );
 		}
-		LeaveCriticalSection( &hAudioCs );
+        hAudioCs.unlock();
 		break;
 	}
 }

+ 2 - 1
GSL/Sound.h

@@ -9,6 +9,7 @@
 #include "GSLDatei.h"
 #include "GSLSoundV.h"
 #endif
+#include <Critical.h>
 
 using namespace Framework;
 
@@ -27,7 +28,7 @@ namespace GSL
 		WAVEHDR *aAudioHdr[ 16 ];
 		char *aAudioPtr[ 16 ];
 		unsigned int uAudioPlay;
-		CRITICAL_SECTION hAudioCs;
+		Critical hAudioCs;
 		HANDLE hAudioEvent;
 		WAVEOUTCAPS sAudioCaps;
 		unsigned int uAudioWrite;

+ 3 - 3
build.bat

@@ -1,6 +1,6 @@
-"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" GSL.sln /t:GSL:rebuild /p:configuration=debug /p:platform=x64
-"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" GSL.sln /t:GSL:rebuild /p:configuration=release /p:platform=x64
-"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" GSL.sln /t:GSL:rebuild /p:configuration=release /p:platform=win32
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "GSL/GSL.vcxproj" /p:configuration=debug /p:platform=x64
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "GSL/GSL.vcxproj" /p:configuration=release /p:platform=x64
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "GSL/GSL.vcxproj" /p:configuration=release /p:platform=win32
 
 "D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "GSL Linux/GSL Linux.vcxproj" /t:rebuild /p:configuration=debug /p:platform=x64
 "D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "GSL Linux/GSL Linux.vcxproj" /t:rebuild /p:configuration=release /p:platform=x64