Interface generation fixes

This commit is contained in:
Garry Newman 2020-02-12 15:27:30 +00:00
parent 9a36dd58ff
commit 599ca7cbe1
7 changed files with 35 additions and 30 deletions

View File

@ -7,23 +7,6 @@ namespace Steamworks.Data
{
delegate void FSteamNetworkingSocketsDebugOutput (DebugOutputType nType, string pszMsg );
public struct SteamNetworkingPOPID
{
public uint Value;
public static implicit operator SteamNetworkingPOPID( uint value )
{
return new SteamNetworkingPOPID { Value = value };
}
public static implicit operator uint( SteamNetworkingPOPID value )
{
return value.Value;
}
public override string ToString() => Value.ToString();
}
[StructLayout( LayoutKind.Sequential )]
public struct SteamNetworkingQuickConnectionStatus
{

View File

@ -13,6 +13,8 @@ public static class Cleanup
type = type.Replace( "class ", "" );
type = type.Replace( "struct ", "" );
type = type.Replace( "unsigned long long", "uint64" );
type = type.Replace( "CSteamID", "SteamId" );
type = type.Replace( "CGameID", "GameId" );
type = type.Replace( "PersonaState", "FriendState" );
@ -47,6 +49,7 @@ public static class Cleanup
type = type.Replace( "InputAnalogActionData_t", "AnalogState" );
type = type.Replace( "InputMotionData_t", "MotionState" );
type = type.Replace( "MatchMakingKeyValuePair_t", "MatchMakingKeyValuePair" );
type = type.Replace( "ISteamNetworkingMessage", "SteamNetworkingMessage_t" );
return type;
}
@ -61,6 +64,13 @@ public static class Cleanup
if ( type == "DigitalState" ) return false;
if ( type == "MotionState" ) return false;
if ( type == "MatchMakingKeyValuePair" ) return false;
if ( type == "Connection" ) return false;
if ( type == "Socket" ) return false;
if ( type == "SteamNetworkingErrMsg" ) return false;
if ( type == "SteamNetworkingMicroseconds" ) return false;
if ( type == "FSteamNetworkingSocketsDebugOutput" ) return false;
if ( type == "SteamNetworkingMessage_t" ) return false;
if ( type == "SteamDatagramErrMsg" ) return false;
return true;
}

View File

@ -53,7 +53,7 @@ namespace Generator
}
private void WriteFunction( SteamApiDefinition.Interface iface, SteamApiDefinition.Interface.Method func )
{
var returnType = BaseType.Parse( func.ReturnType, null );
var returnType = BaseType.Parse( func.ReturnType, null, func.CallResult );
returnType.Func = func.Name;
if ( func.Params == null )
@ -70,7 +70,7 @@ namespace Generator
{
if ( args[i] is StringType )
{
if ( args[i + 1] is IntType || args[i + 1] is UIntType )
if ( args[i + 1] is IntType || args[i + 1] is UIntType || args[i + 1] is UIntPtrType )
{
if ( args[i + 1].Ref == string.Empty )
{
@ -87,12 +87,11 @@ namespace Generator
var argstr = string.Join( ", ", args.Where( x => !x.ShouldSkipAsArgument ).Select( x => x.AsArgument() ) ); ;
var delegateargstr = string.Join( ", ", args.Select( x => x.AsNativeArgument() ) );
//if ( returnType is SteamApiCallType sap )
// {
// sap.CallResult = func.CallResult;
// argstr = string.Join( ", ", args.Select( x => x.AsArgument().Replace( "ref ", " /* ref */ " ) ) );
// }
if ( returnType is SteamApiCallType sap )
{
sap.CallResult = func.CallResult;
argstr = string.Join( ", ", args.Select( x => x.AsArgument().Replace( "ref ", " /* ref */ " ) ) );
}
WriteLine( $"#region FunctionMeta" );

View File

@ -30,7 +30,7 @@ namespace Generator
if ( !Cleanup.ShouldCreate( name ) )
continue;
StartBlock( $"{Cleanup.Expose( name )} enum {name} : int" );
StartBlock( $"{Cleanup.Expose( name )} enum {name} : uint" );
{
//
// If all the enum values start with the same

View File

@ -37,7 +37,10 @@ namespace Generator
{
foreach ( var o in def.typedefs.Where( x => !x.Name.Contains( "::" ) ) )
{
var typeName = Cleanup.ConvertType( o.Name );
if ( !Cleanup.ShouldCreate( o.Name ) )
continue;
var typeName = Cleanup.ConvertType( o.Name );
if ( !Cleanup.ShouldCreate( typeName ) )
continue;
@ -50,7 +53,8 @@ namespace Generator
StartBlock( $"{Cleanup.Expose( typeName )} struct {typeName} : IEquatable<{typeName}>, IComparable<{typeName}>" );
{
WriteLine( $"public {ToManagedType( o.Type )} Value;" );
WriteLine( $"// Name: {o.Name}, Type: {o.Type}" );
WriteLine( $"public {ToManagedType( o.Type )} Value;" );
WriteLine();
WriteLine( $"public static implicit operator {typeName}( {ToManagedType( o.Type )} value ) => new {typeName}(){{ Value = value }};" );
WriteLine( $"public static implicit operator {ToManagedType( o.Type )}( {typeName} value ) => value.Value;" );

View File

@ -41,8 +41,11 @@ internal class BaseType
if ( basicType == "unsigned short" ) return new UInt16Type { NativeType = type, VarName = varname };
if ( basicType == "SteamId" ) return new CSteamIdType { NativeType = type, VarName = varname };
if ( basicType == "size_t" ) return new UIntPtrType{ NativeType = type, VarName = varname };
// DANGER DANGER Danger
if ( basicType == "size_t" ) return new ULongType { NativeType = type, VarName = varname };
if ( basicType == "intptr_t" ) return new LongType { NativeType = type, VarName = varname };
if ( basicType == "ptrdiff_t" ) return new LongType { NativeType = type, VarName = varname };
@ -68,7 +71,7 @@ internal class BaseType
public virtual bool ShouldSkipAsArgument => false;
public virtual string AsNativeArgument() => AsArgument();
public virtual string AsArgument() => IsVector ? $"[In,Out] {Ref}{TypeName.Trim( '*', ' ' )}[] {VarName}" : $"{Ref}{TypeName.Trim( '*', ' ' )} {VarName}";
public virtual string AsArgument() => IsVector ? $"[In,Out] {Ref}{TypeName.Trim( '*', ' ', '&' )}[] {VarName}" : $"{Ref}{TypeName.Trim( '*', ' ', '&' )} {VarName}";
public virtual string AsCallArgument() => $"{Ref}{VarName}";
public virtual string Return( string varname ) => $"return {varname};";
@ -217,6 +220,11 @@ internal class UInt16Type : BaseType
public override string TypeName => $"ushort";
}
internal class UIntPtrType : BaseType
{
public override string TypeName => $"UIntPtr";
}
internal class PointerType : BaseType
{
public override string TypeName => $"IntPtr";

View File

@ -20,6 +20,7 @@ namespace Generator
public class Method
{
public string ReturnType { get; set; }
public string CallResult { get; set; }
public class Param
{