Skip to content

Commit

Permalink
C#: Array, Dictionary and marshaling refactoring
Browse files Browse the repository at this point in the history
- Array and Dictionary now store `Variant` instead of `System.Object`.
- Removed generic Array and Dictionary.
  They cause too much issues, heavily relying on reflection and
  very limited by the lack of a generic specialization.
- Removed support for non-Godot collections.
  Support for them also relied heavily on reflection for marshaling.
  Support for them will likely be re-introduced in the future, but
  it will have to rely on source generators instead of reflection.
- Reduced our use of reflection.
  The remaining usages will be moved to source generators soon.
  The only usage that I'm not sure yet how to replace is dynamic
  invocation of delegates.
  • Loading branch information
neikeq committed Aug 22, 2022
1 parent 344f502 commit 3123be2
Show file tree
Hide file tree
Showing 30 changed files with 766 additions and 1,723 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,9 @@ enum MyFlagsEnum
[Export] private Vector3[] field_Vector3Array = { Vector3.Up, Vector3.Down, Vector3.Left, Vector3.Right };
[Export] private Color[] field_ColorArray = { Colors.Aqua, Colors.Aquamarine, Colors.Azure, Colors.Beige };
[Export] private Godot.Object[] field_GodotObjectOrDerivedArray = { null };

// Generics
[Export] private Godot.Collections.Dictionary<string, string> field_GodotGenericDictionary =
new Godot.Collections.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private Godot.Collections.Array<string> field_GodotGenericArray =
new Godot.Collections.Array<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.Dictionary<string, string> field_SystemGenericDictionary =
new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private System.Collections.Generic.List<string> field_SystemGenericList =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.IDictionary<string, string> field_GenericIDictionary =
new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private System.Collections.Generic.ICollection<string> field_GenericICollection =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.IEnumerable<string> field_GenericIEnumerable =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
[Export] private StringName[] field_StringNameArray = { "foo", "bar" };
[Export] private NodePath[] field_NodePathArray = { "foo", "bar" };
[Export] private RID[] field_RIDArray = { default, default, default };

// Variant
[Export] private Variant field_Variant = "foo";
Expand All @@ -118,15 +99,5 @@ enum MyFlagsEnum

[Export] private Godot.Collections.Array field_GodotArray =
new() { "foo", 10, Vector2.Up, Colors.Chocolate };

[Export] private System.Collections.IDictionary field_IDictionary =
new System.Collections.Generic.Dictionary<object, object>
{ { "foo", 10 }, { Vector2.Up, Colors.Chocolate } };

[Export] private System.Collections.ICollection field_ICollection =
new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };

[Export] private System.Collections.IEnumerable field_IEnumerable =
new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,9 @@ enum MyFlagsEnum
[Export] private Vector3[] property_Vector3Array { get; set; } = { Vector3.Up, Vector3.Down, Vector3.Left, Vector3.Right };
[Export] private Color[] property_ColorArray { get; set; } = { Colors.Aqua, Colors.Aquamarine, Colors.Azure, Colors.Beige };
[Export] private Godot.Object[] property_GodotObjectOrDerivedArray { get; set; } = { null };

// Generics
[Export] private Godot.Collections.Dictionary<string, string> property_GodotGenericDictionary { get; set; } =
new Godot.Collections.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private Godot.Collections.Array<string> property_GodotGenericArray { get; set; } =
new Godot.Collections.Array<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.Dictionary<string, string> property_SystemGenericDictionary { get; set; } =
new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private System.Collections.Generic.List<string> property_SystemGenericList { get; set; } =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.IDictionary<string, string> property_GenericIDictionary { get; set; } =
new System.Collections.Generic.Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };

[Export] private System.Collections.Generic.ICollection<string> property_GenericICollection { get; set; } =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };

[Export] private System.Collections.Generic.IEnumerable<string> property_GenericIEnumerable { get; set; } =
new System.Collections.Generic.List<string> { "elem1", "elem2", "elem3" };
[Export] private StringName[] field_StringNameArray { get; set; } = { "foo", "bar" };
[Export] private NodePath[] field_NodePathArray { get; set; } = { "foo", "bar" };
[Export] private RID[] field_RIDArray { get; set; } = { default, default, default };

// Variant
[Export] private Variant property_Variant { get; set; } = "foo";
Expand All @@ -118,15 +99,5 @@ enum MyFlagsEnum

[Export] private Godot.Collections.Array property_GodotArray { get; set; } =
new() { "foo", 10, Vector2.Up, Colors.Chocolate };

[Export] private System.Collections.IDictionary property_IDictionary { get; set; } =
new System.Collections.Generic.Dictionary<object, object>
{ { "foo", 10 }, { Vector2.Up, Colors.Chocolate } };

[Export] private System.Collections.ICollection property_ICollection { get; set; } =
new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };

[Export] private System.Collections.IEnumerable property_IEnumerable { get; set; } =
new System.Collections.Generic.List<object> { "foo", 10, Vector2.Up, Colors.Chocolate };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,9 @@ public enum MarshalType
Vector3Array,
ColorArray,
GodotObjectOrDerivedArray,
SystemArrayOfSupportedType,

// Generics
GodotGenericDictionary,
GodotGenericArray,
SystemGenericDictionary,
SystemGenericList,
GenericIDictionary,
GenericICollection,
GenericIEnumerable,
SystemArrayOfStringName,
SystemArrayOfNodePath,
SystemArrayOfRID,

// Variant
Variant,
Expand All @@ -74,8 +67,5 @@ public enum MarshalType
RID,
GodotDictionary,
GodotArray,
IDictionary,
ICollection,
IEnumerable,
}
}
Loading

0 comments on commit 3123be2

Please sign in to comment.