StructPlatformPackSize instead of runtime Pack8 shit

This commit is contained in:
Garry Newman 2019-06-25 11:20:39 +01:00
parent 02e9063db8
commit 6dbed6a91d
3 changed files with 553 additions and 2845 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace Steamworks
{
internal static class Platform
{
#if PLATFORM_WIN64
public const int StructPlatformPackSize = 8;
#else
public const int StructPlatformPackSize = 4;
#endif
public const int StructPackSize = 4;
}
}

View File

@ -60,7 +60,7 @@ namespace Generator
//
// Main struct
//
WriteLine( "[StructLayout( LayoutKind.Sequential, Pack = 4 )]" );
WriteLine( $"[StructLayout( LayoutKind.Sequential, Pack = Platform.{(c.IsPack4OnWindows?"StructPackSize": "StructPlatformPackSize")} )]" );
StartBlock( $"{Cleanup.Expose( name )} struct {name}" );
{
//
@ -73,16 +73,9 @@ namespace Generator
{
WriteLine( "#region SteamCallback" );
{
if ( defaultPack == 4 )
{
WriteLine( $"internal static readonly int StructSize = System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" );
WriteLine( $"internal static {name} Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" );
}
else
{
WriteLine( $"internal static readonly int StructSize = System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" );
WriteLine( $"internal static {name} Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" );
}
WriteLine();
WriteLine( $"static Action<{name}> actionClient;" );
WriteLine( $"[MonoPInvokeCallback] static void OnClient( IntPtr thisptr, IntPtr pvParam ) => actionClient?.Invoke( Fill( pvParam ) );" );
@ -142,64 +135,8 @@ namespace Generator
{
WriteLine( "#region Marshalling" );
{
if ( defaultPack == 4 )
{
//WriteLine( $"internal static int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( typeof({name}) );" );
WriteLine( $"internal static {name} Fill( IntPtr p ) => (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) ) );" );
}
else
{
//WriteLine( $"internal static int GetStructSize() => System.Runtime.InteropServices.Marshal.SizeOf( Config.PackSmall ? typeof({name}) : typeof(Pack8) );" );
WriteLine( $"internal static {name} Fill( IntPtr p ) => Config.PackSmall ? (({name})({name}) Marshal.PtrToStructure( p, typeof({name}) )) : (({name})(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) ));" );
}
}
WriteLine( "#endregion" );
}
if ( defaultPack != 4 )
{
WriteLine( "#region Packed Versions" );
{
//
// Windows Packed version
//
WriteLine();
WriteLine( $"[StructLayout( LayoutKind.Sequential, Pack = {defaultPack} )]" );
StartBlock( $"public struct Pack8" );
{
StructFields( c.Fields );
//
// Implicit convert from PackSmall to regular
//
WriteLine();
Write( $"public static implicit operator {name} ( {name}.Pack8 d ) => " );
{
Write( $"new {name}{{ " );
{
foreach ( var f in c.Fields )
{
Write( $"{CleanMemberName( f.Name )} = d.{CleanMemberName( f.Name )}," );
}
}
WriteLine( " };" );
}
Write( $"public static implicit operator {name}.Pack8 ( {name} d ) => " );
{
Write( $"new {name}.Pack8{{ " );
{
foreach ( var f in c.Fields )
{
Write( $"{CleanMemberName( f.Name )} = d.{CleanMemberName( f.Name )}," );
}
}
WriteLine( " };" );
}
}
EndBlock();
}
WriteLine( "#endregion" );
}