We can treat mac and linux as the same os

This commit is contained in:
Garry Newman 2019-04-30 13:01:30 +01:00
parent 8da5ab2cd0
commit cbc154da66
6 changed files with 47 additions and 49 deletions

View File

@ -19,11 +19,11 @@ public static OsType Os
}
else if ( File.Exists( @"/System/Library/CoreServices/SystemVersion.plist" ) )
{
_os = OsType.MacOs;
_os = OsType.Posix;
}
else if ( File.Exists( @"/proc/sys/kernel/ostype" ) )
{
_os = OsType.Linux;
_os = OsType.Posix;
}
else
{
@ -55,7 +55,6 @@ public enum OsType
{
None,
Windows,
Linux,
MacOs,
Posix,
}
}

View File

@ -44,7 +44,7 @@ internal static class Win64
public static extern bool SteamAPI_RestartAppIfNecessary( uint unOwnAppID );
}
internal static class MacOs
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamAPI_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )]
@ -85,9 +85,9 @@ static internal bool Init()
{
return Win64.SteamAPI_Init();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamAPI_Init();
return Posix.SteamAPI_Init();
}
else
{
@ -101,9 +101,9 @@ static internal void RunCallbacks()
{
Win64.SteamAPI_RunCallbacks();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_RunCallbacks();
Posix.SteamAPI_RunCallbacks();
}
else
{
@ -117,9 +117,9 @@ static internal void RegisterCallback( IntPtr pCallback, int callback )
{
Win64.SteamAPI_RegisterCallback( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_RegisterCallback( pCallback, callback );
Posix.SteamAPI_RegisterCallback( pCallback, callback );
}
else
{
@ -133,9 +133,9 @@ static internal void UnregisterCallback( IntPtr pCallback )
{
Win64.SteamAPI_UnregisterCallback( pCallback );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_UnregisterCallback( pCallback );
Posix.SteamAPI_UnregisterCallback( pCallback );
}
else
{
@ -149,9 +149,9 @@ static internal void RegisterCallResult( IntPtr pCallback, SteamAPICall_t callba
{
Win64.SteamAPI_RegisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_RegisterCallResult( pCallback, callback );
Posix.SteamAPI_RegisterCallResult( pCallback, callback );
}
else
{
@ -165,9 +165,9 @@ static internal void UnregisterCallResult( IntPtr pCallback, SteamAPICall_t call
{
Win64.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_UnregisterCallResult( pCallback, callback );
Posix.SteamAPI_UnregisterCallResult( pCallback, callback );
}
else
{
@ -181,9 +181,9 @@ static internal void Shutdown()
{
Win64.SteamAPI_Shutdown();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamAPI_Shutdown();
Posix.SteamAPI_Shutdown();
}
else
{
@ -197,9 +197,9 @@ static internal HSteamUser GetHSteamUser()
{
return Win64.SteamAPI_GetHSteamUser();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamAPI_GetHSteamUser();
return Posix.SteamAPI_GetHSteamUser();
}
else
{
@ -213,9 +213,9 @@ static internal HSteamPipe GetHSteamPipe()
{
return Win64.SteamAPI_GetHSteamPipe();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamAPI_GetHSteamPipe();
return Posix.SteamAPI_GetHSteamPipe();
}
else
{
@ -229,9 +229,9 @@ static internal bool RestartAppIfNecessary( uint unOwnAppID )
{
return Win64.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamAPI_RestartAppIfNecessary( unOwnAppID );
return Posix.SteamAPI_RestartAppIfNecessary( unOwnAppID );
}
else
{

View File

@ -24,7 +24,7 @@ internal static class Win64
public static extern HSteamPipe SteamGameServer_GetHSteamPipe();
}
internal static class MacOs
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamGameServer_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern void SteamGameServer_RunCallbacks();
@ -45,9 +45,9 @@ static internal void RunCallbacks()
{
Win64.SteamGameServer_RunCallbacks();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamGameServer_RunCallbacks();
Posix.SteamGameServer_RunCallbacks();
}
else
{
@ -61,9 +61,9 @@ static internal void Shutdown()
{
Win64.SteamGameServer_Shutdown();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
MacOs.SteamGameServer_Shutdown();
Posix.SteamGameServer_Shutdown();
}
else
{
@ -77,9 +77,9 @@ static internal HSteamUser GetHSteamUser()
{
return Win64.SteamGameServer_GetHSteamUser();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamGameServer_GetHSteamUser();
return Posix.SteamGameServer_GetHSteamUser();
}
else
{
@ -93,9 +93,9 @@ static internal HSteamPipe GetHSteamPipe()
{
return Win64.SteamGameServer_GetHSteamPipe();
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamGameServer_GetHSteamPipe();
return Posix.SteamGameServer_GetHSteamPipe();
}
else
{

View File

@ -25,7 +25,7 @@ internal static class Win64
public static extern IntPtr SteamInternal_CreateInterface( string version );
}
internal static class MacOs
internal static class Posix
{
[DllImport( "libsteam_api", EntryPoint = "SteamInternal_GameServer_Init", CallingConvention = CallingConvention.Cdecl )]
[return: MarshalAs( UnmanagedType.I1 )]
@ -47,9 +47,9 @@ static internal bool GameServer_Init( uint unIP, ushort usPort, ushort usGamePor
{
return Win64.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
return Posix.SteamInternal_GameServer_Init( unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString );
}
else
{
@ -63,9 +63,9 @@ static internal IntPtr FindOrCreateUserInterface( int steamuser, string versionn
{
return Win64.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
return Posix.SteamInternal_FindOrCreateUserInterface( steamuser, versionname );
}
else
{
@ -79,9 +79,9 @@ static internal IntPtr FindOrCreateGameServerInterface( int steamuser, string ve
{
return Win64.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
return Posix.SteamInternal_FindOrCreateGameServerInterface( steamuser, versionname );
}
else
{
@ -95,9 +95,9 @@ static internal IntPtr CreateInterface( string version )
{
return Win64.SteamInternal_CreateInterface( version );
}
else if ( Config.Os == OsType.MacOs )
else if ( Config.Os == OsType.Posix )
{
return MacOs.SteamInternal_CreateInterface( version );
return Posix.SteamInternal_CreateInterface( version );
}
else
{

View File

@ -112,7 +112,6 @@ void WriteFunctionPointerReader( CodeParser.Class clss )
}
else
{
WriteLine( $"_{func.Name} = Marshal.GetDelegateForFunctionPointer<F{func.Name}>( Marshal.ReadIntPtr( VTable, {locations[i]}) );" );
if ( returnType.IsReturnedWeird )

View File

@ -36,7 +36,7 @@ public void GenerateGlobalFunctions( string startingWith, string filename )
}
EndBlock();
StartBlock( $"internal static class MacOs" );
StartBlock( $"internal static class Posix" );
{
foreach ( var func in functions )
{
@ -107,21 +107,21 @@ private void WriteGlobalFunction( string cname, SteamApiDefinition.MethodDef fun
WriteLine( returnType.Return( v ) );
}
}
Else( " if ( Config.Os == OsType.MacOs )" );
Else( " if ( Config.Os == OsType.Posix )" );
{
if ( returnType.IsReturnedWeird )
{
WriteLine( $"var retVal = default( {returnType.TypeName} );" );
WriteLine( $"MacOs.{func.Name}( ref retVal, {callargs} );" );
WriteLine( $"Posix.{func.Name}( ref retVal, {callargs} );" );
WriteLine( $"{returnType.Return( "retVal" )}" );
}
else if ( returnType.IsVoid )
{
WriteLine( $"MacOs.{func.Name}( {callargs} );" );
WriteLine( $"Posix.{func.Name}( {callargs} );" );
}
else
{
var v = $"MacOs.{func.Name}( {callargs} )";
var v = $"Posix.{func.Name}( {callargs} )";
WriteLine( returnType.Return( v ) );
}