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;
api = new SteamNative.SteamApi( steamworks, (IntPtr) 1 );
api = new SteamNative.SteamApi();
if ( !api.SteamAPI_Init() )
return false;
@ -63,7 +63,7 @@ internal bool InitServer( BaseSteamworks steamworks, uint IpAddress /*uint32*/,
{
isServer = true;
api = new SteamNative.SteamApi( steamworks, ( IntPtr)1 );
api = new SteamNative.SteamApi();
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
//
internal Platform.Interface platform;
internal Facepunch.Steamworks.BaseSteamworks steamworks;
//
// 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 );
else if ( Platform.IsWindows32 ) platform = new Platform.Win32( pointer );
else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( pointer );
else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( pointer );
else if ( Platform.IsOsx ) platform = new Platform.Mac( pointer );
if ( Platform.IsWindows64 ) platform = new Platform.Win64( ((IntPtr)1) );
else if ( Platform.IsWindows32 ) platform = new Platform.Win32( ((IntPtr)1) );
else if ( Platform.IsLinux32 ) platform = new Platform.Linux32( ((IntPtr)1) );
else if ( Platform.IsLinux64 ) platform = new Platform.Linux64( ((IntPtr)1) );
else if ( Platform.IsOsx ) platform = new Platform.Mac( ((IntPtr)1) );
}
//

View File

@ -41,12 +41,32 @@ private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
WriteLine( "// Holds a platform specific implentation" );
WriteLine( "//" );
WriteLine( "internal Platform.Interface platform;" );
if ( classname != "SteamApi" )
WriteLine( "internal Facepunch.Steamworks.BaseSteamworks steamworks;" );
WriteLine();
WriteLine( "//" );
WriteLine( "// Constructor decides which implementation to use based on current platform" );
WriteLine( "//" );
if ( classname == "SteamApi" )
{
StartBlock( $"internal {InterfaceNameToClass( classname )}()" );
{
WriteLine( "" );
WriteLine( "if ( Platform.IsWindows64 ) platform = new Platform.Win64( ((IntPtr)1) );" );
WriteLine( "else if ( Platform.IsWindows32 ) platform = new Platform.Win32( ((IntPtr)1) );" );
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();
}
else
{
StartBlock( $"internal {InterfaceNameToClass( classname )}( Facepunch.Steamworks.BaseSteamworks steamworks, IntPtr pointer )" );
{
WriteLine( "this.steamworks = steamworks;" );
@ -58,6 +78,8 @@ private void Class( string classname, SteamApiDefinition.MethodDef[] methodDef )
WriteLine( "else if ( Platform.IsOsx ) platform = new Platform.Mac( pointer );" );
}
EndBlock();
}
WriteLine();
WriteLine( "//" );