init
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
internal static class CallableDelegateRegistry
|
||||
{
|
||||
private static readonly Dictionary<long, Func<Variant[], Variant>> Delegates = new Dictionary<long, Func<Variant[], Variant>>();
|
||||
private static long nextId = 1;
|
||||
|
||||
internal static long Register(Func<Variant[], Variant> function)
|
||||
{
|
||||
long id = nextId++;
|
||||
Delegates[id] = function;
|
||||
return id;
|
||||
}
|
||||
|
||||
internal static void Unregister(long delegateId)
|
||||
{
|
||||
Delegates.Remove(delegateId);
|
||||
}
|
||||
|
||||
public static Variant Invoke(long delegateId, Variant[] arguments)
|
||||
{
|
||||
Func<Variant[], Variant> function;
|
||||
if (!Delegates.TryGetValue(delegateId, out function))
|
||||
{
|
||||
return new Variant();
|
||||
}
|
||||
return function(arguments ?? new Variant[0]);
|
||||
}
|
||||
|
||||
internal static T ConvertArgument<T>(Variant[] arguments, int index)
|
||||
{
|
||||
Variant value = arguments[index];
|
||||
Type type = typeof(T);
|
||||
if (type == typeof(Variant))
|
||||
{
|
||||
return (T)(object)value;
|
||||
}
|
||||
if (type == typeof(string))
|
||||
{
|
||||
return (T)(object)value.ToString();
|
||||
}
|
||||
if (type == typeof(int))
|
||||
{
|
||||
return (T)(object)(int)value.AsInt64();
|
||||
}
|
||||
if (type == typeof(long))
|
||||
{
|
||||
return (T)(object)value.AsInt64();
|
||||
}
|
||||
if (type == typeof(float))
|
||||
{
|
||||
return (T)(object)(float)value.AsDouble();
|
||||
}
|
||||
if (type == typeof(double))
|
||||
{
|
||||
return (T)(object)value.AsDouble();
|
||||
}
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
return (T)(object)value.AsBool();
|
||||
}
|
||||
if (type == typeof(Vector2))
|
||||
{
|
||||
return (T)(object)value.AsVector2();
|
||||
}
|
||||
if (type == typeof(Vector3))
|
||||
{
|
||||
return (T)(object)value.AsVector3();
|
||||
}
|
||||
if (type == typeof(StringName))
|
||||
{
|
||||
return (T)(object)value.AsStringName();
|
||||
}
|
||||
if (type == typeof(NodePath))
|
||||
{
|
||||
return (T)(object)value.AsNodePath();
|
||||
}
|
||||
if (type == typeof(RID))
|
||||
{
|
||||
return (T)(object)value.AsRID();
|
||||
}
|
||||
if (type == typeof(Color))
|
||||
{
|
||||
return (T)(object)value.AsColor();
|
||||
}
|
||||
if (type == typeof(Quaternion))
|
||||
{
|
||||
return (T)(object)value.AsQuaternion();
|
||||
}
|
||||
if (type == typeof(Basis))
|
||||
{
|
||||
return (T)(object)value.AsBasis();
|
||||
}
|
||||
if (type == typeof(Transform3D))
|
||||
{
|
||||
return (T)(object)value.AsTransform3D();
|
||||
}
|
||||
if (type == typeof(Node))
|
||||
{
|
||||
return (T)(object)value.AsObject<Node>();
|
||||
}
|
||||
if (type == typeof(Node2D))
|
||||
{
|
||||
return (T)(object)value.AsObject<Node2D>();
|
||||
}
|
||||
if (type == typeof(GodotObject))
|
||||
{
|
||||
return (T)(object)value.AsObject<GodotObject>();
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class ExportAttribute : Attribute
|
||||
{
|
||||
public readonly PropertyHint Hint;
|
||||
public readonly string HintString;
|
||||
public readonly PropertyUsageFlags Usage;
|
||||
|
||||
public ExportAttribute()
|
||||
: this(PropertyHint.None, string.Empty, PropertyUsageFlags.PropertyUsageDefault)
|
||||
{
|
||||
}
|
||||
|
||||
public ExportAttribute(PropertyHint hint)
|
||||
: this(hint, string.Empty, PropertyUsageFlags.PropertyUsageDefault)
|
||||
{
|
||||
}
|
||||
|
||||
public ExportAttribute(PropertyHint hint, string hintString)
|
||||
: this(hint, hintString, PropertyUsageFlags.PropertyUsageDefault)
|
||||
{
|
||||
}
|
||||
|
||||
public ExportAttribute(PropertyHint hint, string hintString, PropertyUsageFlags usage)
|
||||
{
|
||||
Hint = hint;
|
||||
HintString = hintString ?? string.Empty;
|
||||
Usage = usage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
public static class GD
|
||||
{
|
||||
public static void Print(string message)
|
||||
{
|
||||
PrintInternal(message);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern void PrintInternal(string message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
public partial class GodotObject : System.IDisposable
|
||||
{
|
||||
private static readonly Dictionary<IntPtr, WeakReference> NativeInstanceCache = new Dictionary<IntPtr, WeakReference>();
|
||||
|
||||
internal System.IntPtr NativePtr;
|
||||
private int ownedNativeRefCount;
|
||||
|
||||
internal static T CreateFromNative<T>(System.IntPtr nativePtr) where T : GodotObject, new()
|
||||
{
|
||||
return CreateFromNative<T>(nativePtr, false);
|
||||
}
|
||||
|
||||
internal static T CreateFromNative<T>(System.IntPtr nativePtr, bool ownsNativeRef) where T : GodotObject, new()
|
||||
{
|
||||
if (nativePtr == System.IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
WeakReference weakReference;
|
||||
if (NativeInstanceCache.TryGetValue(nativePtr, out weakReference))
|
||||
{
|
||||
T cached = weakReference.Target as T;
|
||||
if (cached != null && cached.NativePtr == nativePtr)
|
||||
{
|
||||
if (ownsNativeRef)
|
||||
{
|
||||
cached.ownedNativeRefCount++;
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
T instance = new T();
|
||||
instance.NativePtr = nativePtr;
|
||||
instance.ownedNativeRefCount = ownsNativeRef ? 1 : 0;
|
||||
NativeInstanceCache[nativePtr] = new WeakReference(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
~GodotObject()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
System.GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (NativePtr == System.IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NativeInstanceCache.Remove(NativePtr);
|
||||
while (ownedNativeRefCount > 0)
|
||||
{
|
||||
NativeCalls.GodotObjectReleaseRefCounted(NativePtr);
|
||||
ownedNativeRefCount--;
|
||||
}
|
||||
NativePtr = System.IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<AssemblyName>GodotSharpCompat</AssemblyName>
|
||||
<RootNamespace>Godot</RootNamespace>
|
||||
<NoStandardLib>true</NoStandardLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<DebugType>none</DebugType>
|
||||
<OutputPath>..\..\project\leanclr\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>../../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System">
|
||||
<HintPath>../../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/System.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Godot
|
||||
{
|
||||
internal static partial class NativeCalls
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Godot
|
||||
{
|
||||
public partial class Node : GodotObject
|
||||
{
|
||||
public virtual void _Ready()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user