Made SteamNative.SteamApi less hacky to initialize

This commit is contained in:
Garry Newman 2017-07-06 10:33:13 +01:00
parent 5890fea9e6
commit 67fb987288
3 changed files with 40 additions and 20 deletions

View File

@ -36,7 +36,7 @@ internal bool InitClient( BaseSteamworks steamworks )
{ {
isServer = false; isServer = false;
api = new SteamNative.SteamApi( steamworks, (IntPtr) 1 ); api = new SteamNative.SteamApi();
if ( !api.SteamAPI_Init() ) if ( !api.SteamAPI_Init() )
return false; return false;
@ -63,7 +63,7 @@ internal bool InitServer( BaseSteamworks steamworks, uint IpAddress /*uint32*/,
{ {
isServer = true; isServer = true;
api = new SteamNative.SteamApi( steamworks, ( IntPtr)1 ); api = new SteamNative.SteamApi();
if ( !api.SteamInternal_GameServer_Init( IpAddress, usPort, GamePort, QueryPort, eServerMode, pchVersionString ) ) if ( !api.SteamInternal_GameServer_Init( IpAddress, usPort, GamePort, QueryPort, eServerMode, pchVersionString ) )
{ {

View File

@ -10,20 +10,18 @@ internal unsafe class SteamApi : IDisposable
// Holds a platform specific implentation // Holds a platform specific implentation
// //
internal Platform.Interface platform; internal Platform.Interface platform;
internal Facepunch.Steamworks.BaseSteamworks steamworks;
// //
// Constructor decides which implementation to use based on current platform // Constructor decides which implementation to use based on current platform
// //
internal SteamApi( Facepunch.Steamworks.BaseSteamworks steamworks, IntPtr pointer ) internal SteamApi()
{ {
this.steamworks = steamworks;
if ( Platform.IsWindows64 ) platform = new Platform.Win64( pointer ); if ( Platform.IsWindows64 ) platform = new Platform.Win64( ((IntPtr)1) );
else if ( Platform.IsWindows32 ) platform = new Platform.Win32( pointer ); else if ( Platform.IsWindows32 ) platform = new Platform.Win32( ((IntPtr)1) );
else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( pointer ); else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( ((IntPtr)1) );
else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( pointer ); else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( ((IntPtr)1) );
else if ( Platform.IsOsx ) platform = new Platform.Mac( pointer ); else if ( Platform.IsOsx ) platform = new Platform.Mac( ((IntPtr)1) );
} }
// //

View File

@ -41,23 +41,45 @@ private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
WriteLine( "// Holds a platform specific implentation" ); WriteLine( "// Holds a platform specific implentation" );
WriteLine( "//" ); WriteLine( "//" );
WriteLine( "internal Platform.Interface platform;" ); WriteLine( "internal Platform.Interface platform;" );
WriteLine( "internal Facepunch.Steamworks.BaseSteamworks steamworks;" );
if ( classname != "SteamApi" )
WriteLine( "internal Facepunch.Steamworks.BaseSteamworks steamworks;" );
WriteLine(); WriteLine();
WriteLine( "//" ); WriteLine( "//" );
WriteLine( "// Constructor decides which implementation to use based on current platform" ); WriteLine( "// Constructor decides which implementation to use based on current platform" );
WriteLine( "//" ); WriteLine( "//" );
StartBlock( $"internal {InterfaceNameToClass( classname )}( Facepunch.Steamworks.BaseSteamworks steamworks, IntPtr pointer )" );
if ( classname == "SteamApi" )
{ {
WriteLine( "this.steamworks = steamworks;" );
WriteLine( "" ); StartBlock( $"internal {InterfaceNameToClass( classname )}()" );
WriteLine( "if ( Platform.IsWindows64 ) platform = new Platform.Win64( pointer );" ); {
WriteLine( "else if ( Platform.IsWindows32 ) platform = new Platform.Win32( pointer );" ); WriteLine( "" );
WriteLine( "else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( pointer );" ); WriteLine( "if ( Platform.IsWindows64 ) platform = new Platform.Win64( ((IntPtr)1) );" );
WriteLine( "else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( pointer );" ); WriteLine( "else if ( Platform.IsWindows32 ) platform = new Platform.Win32( ((IntPtr)1) );" );
WriteLine( "else if ( Platform.IsOsx ) platform = new Platform.Mac( pointer );" ); WriteLine( "else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( ((IntPtr)1) );" );
WriteLine( "else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( ((IntPtr)1) );" );
WriteLine( "else if ( Platform.IsOsx ) platform = new Platform.Mac( ((IntPtr)1) );" );
}
EndBlock();
} }
EndBlock(); else
{
StartBlock( $"internal {InterfaceNameToClass( classname )}( Facepunch.Steamworks.BaseSteamworks steamworks, IntPtr pointer )" );
{
WriteLine( "this.steamworks = steamworks;" );
WriteLine( "" );
WriteLine( "if ( Platform.IsWindows64 ) platform = new Platform.Win64( pointer );" );
WriteLine( "else if ( Platform.IsWindows32 ) platform = new Platform.Win32( pointer );" );
WriteLine( "else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( pointer );" );
WriteLine( "else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( pointer );" );
WriteLine( "else if ( Platform.IsOsx ) platform = new Platform.Mac( pointer );" );
}
EndBlock();
}
WriteLine(); WriteLine();
WriteLine( "//" ); WriteLine( "//" );