Skip to content

Commit 49b020e

Browse files
[spritekit] Update for Xcode 9 beta 1, 2 & 3 (#2331)
- Added Quaternion support to XI runtime (simd_quatf).
1 parent b59a82e commit 49b020e

File tree

8 files changed

+248
-1
lines changed

8 files changed

+248
-1
lines changed

runtime/bindings-generator.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,26 @@ static IEnumerable<FunctionData> GetFunctionData ()
14441444
}
14451445
);
14461446

1447+
data.Add (
1448+
new FunctionData {
1449+
Comment = " // Quaternion func ()",
1450+
Prefix = "simd__",
1451+
Variants = Variants.All,
1452+
ReturnType = Types.QuatF,
1453+
}
1454+
);
1455+
1456+
data.Add (
1457+
new FunctionData {
1458+
Comment = " // void func (Quaternion)",
1459+
Prefix = "simd__",
1460+
Variants = Variants.NonStret,
1461+
Parameters = new ParameterData [] {
1462+
new ParameterData { TypeData = Types.QuatF },
1463+
},
1464+
}
1465+
);
1466+
14471467
// Required for ModelIO
14481468
data.Add (
14491469
new FunctionData {
@@ -1994,6 +2014,12 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
19942014
writer.WriteLine ("\t\t{0}.points [i].c = {1}.points [i] [2];", managedVariable, nativeVariable);
19952015
writer.WriteLine ("\t}");
19962016
break;
2017+
case "Quaternion":
2018+
writer.WriteLine ("\t{0}.vector.a = {1}.vector [0];", managedVariable, nativeVariable);
2019+
writer.WriteLine ("\t{0}.vector.b = {1}.vector [1];", managedVariable, nativeVariable);
2020+
writer.WriteLine ("\t{0}.vector.c = {1}.vector [2];", managedVariable, nativeVariable);
2021+
writer.WriteLine ("\t{0}.vector.d = {1}.vector [3];", managedVariable, nativeVariable);
2022+
break;
19972023
default:
19982024
throw new NotImplementedException (string.Format ("MarshalToManaged for: NativeType: {0} ManagedType: {1}", type.NativeType, type.ManagedType));
19992025
}
@@ -2081,6 +2107,12 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
20812107
writer.WriteLine ("\t\t{0}.points [i][2] = {1}.points [i].c;", nativeVariable, managedVariable);
20822108
writer.WriteLine ("\t}");
20832109
break;
2110+
case "Quaternion":
2111+
writer.WriteLine ("\t{0}.vector [0] = {1}.vector.a;", nativeVariable, managedVariable);
2112+
writer.WriteLine ("\t{0}.vector [1] = {1}.vector.b;", nativeVariable, managedVariable);
2113+
writer.WriteLine ("\t{0}.vector [2] = {1}.vector.c;", nativeVariable, managedVariable);
2114+
writer.WriteLine ("\t{0}.vector [3] = {1}.vector.d;", nativeVariable, managedVariable);
2115+
break;
20842116
default:
20852117
throw new NotImplementedException (string.Format ("MarshalToNative for: NativeType: {0} ManagedType: {1}", type.NativeType, type.ManagedType));
20862118
}
@@ -2658,6 +2690,13 @@ public static class Types {
26582690
NativeWrapperType = "CGSize",
26592691
RequireMarshal = false,
26602692
};
2693+
2694+
public static TypeData QuatF = new TypeData {
2695+
ManagedType = "Quaternion",
2696+
NativeType = "simd_quatf",
2697+
NativeWrapperType = "struct QuatF",
2698+
RequireMarshal = true,
2699+
};
26612700
}
26622701
}
26632702

runtime/bindings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ typedef struct { vector_float2 columns[2]; } matrix_float2x2;
8484
typedef struct { vector_float3 columns[3]; } matrix_float3x3;
8585
typedef struct { vector_float4 columns[4]; } matrix_float4x4;
8686

87+
typedef struct { vector_float4 vector; } simd_quatf;
88+
8789
typedef struct {
8890
vector_float3 maxBounds;
8991
vector_float3 minBounds;
@@ -150,6 +152,10 @@ struct Matrix4f {
150152
Vector4f columns [4];
151153
};
152154

155+
struct QuatF {
156+
Vector4f vector;
157+
};
158+
153159
struct MDLAxisAlignedBoundingBoxWrapper {
154160
Vector3f maxBounds;
155161
Vector3f minBounds;

src/SpriteKit/Enums.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,14 @@ public enum SKTileAdjacencyMask : nuint
183183
LowerLeftCorner = Up | Right | LowerRight | Down | LowerLeft | Left | UpperLeft,
184184
UpperLeftCorner = Up | UpperRight | Right | Down | LowerLeft | Left | UpperLeft,
185185
}
186+
187+
[NoWatch]
188+
[NoMac]
189+
[TV (11,0), iOS (11,0)]
190+
[Native]
191+
public enum SKNodeFocusBehavior : nint {
192+
None = 0,
193+
Occluding,
194+
Focusable,
195+
}
186196
}

src/spritekit.cs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
using XamCore.CoreGraphics;
2222
using XamCore.CoreVideo;
2323
using XamCore.SceneKit;
24+
#if !WATCH
25+
using XamCore.Metal;
26+
#endif
2427

2528
using Vector2 = global::OpenTK.Vector2;
2629
using Vector3 = global::OpenTK.Vector3;
2730
using Matrix2 = global::OpenTK.Matrix2;
2831
using Matrix3 = global::OpenTK.Matrix3;
2932
using Matrix4 = global::OpenTK.Matrix4;
3033
using Vector4 = global::OpenTK.Vector4;
34+
using Quaternion = global::OpenTK.Quaternion;
3135

3236
#if MONOMAC
3337
using XamCore.AppKit;
@@ -37,6 +41,7 @@
3741
using pfloat = System.nfloat;
3842
#else
3943
using XamCore.UIKit;
44+
using NSLineBreakMode = global::XamCore.UIKit.UILineBreakMode;
4045
using pfloat = System.Single;
4146
#if !WATCH
4247
using UIView = global::XamCore.UIKit.UIView;
@@ -51,6 +56,11 @@ interface AVPlayer {}
5156
interface CIFilter {}
5257
interface GKPolygonObstacle {}
5358
interface UIView {}
59+
interface IMTLCommandBuffer {}
60+
interface IMTLCommandQueue {}
61+
interface IMTLDevice {}
62+
interface IMTLRenderCommandEncoder {}
63+
interface MTLRenderPassDescriptor {}
5464
#endif
5565

5666
delegate void SKNodeChildEnumeratorHandler (SKNode node, out bool stop);
@@ -166,6 +176,12 @@ partial interface SKNode : NSCoding, NSCopying {
166176
[Export ("userInteractionEnabled")]
167177
bool UserInteractionEnabled { [Bind ("isUserInteractionEnabled")] get; set; }
168178

179+
[NoWatch]
180+
[NoMac]
181+
[TV (11,0), iOS (11,0)]
182+
[Export ("focusBehavior", ArgumentSemantic.Assign)]
183+
SKNodeFocusBehavior FocusBehavior { get; set; }
184+
169185
[Export ("parent")]
170186
SKNode Parent { get; }
171187

@@ -1182,19 +1198,40 @@ partial interface SKLabelNode {
11821198
[Static, Export ("labelNodeWithText:")]
11831199
SKLabelNode FromText ([NullAllowed] string text);
11841200

1201+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
1202+
[Static]
1203+
[Export ("labelNodeWithAttributedText:")]
1204+
SKLabelNode FromText ([NullAllowed] NSAttributedString attributedText);
1205+
11851206
[Export ("verticalAlignmentMode")]
11861207
SKLabelVerticalAlignmentMode VerticalAlignmentMode { get; set; }
11871208

11881209
[Export ("horizontalAlignmentMode")]
11891210
SKLabelHorizontalAlignmentMode HorizontalAlignmentMode { get; set; }
11901211

1212+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
1213+
[Export ("numberOfLines")]
1214+
nint NumberOfLines { get; set; }
1215+
1216+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
1217+
[Export ("lineBreakMode", ArgumentSemantic.Assign)]
1218+
NSLineBreakMode LineBreakMode { get; set; }
1219+
1220+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
1221+
[Export ("preferredMaxLayoutWidth")]
1222+
nfloat PreferredMaxLayoutWidth { get; set; }
1223+
11911224
[Export ("fontName", ArgumentSemantic.Copy)]
11921225
string FontName { get; set; }
11931226

11941227
[Export ("text", ArgumentSemantic.Copy)]
11951228
[NullAllowed] // nullable in Xcode7 headers and caught by introspection tests
11961229
string Text { get; set; }
11971230

1231+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
1232+
[NullAllowed, Export ("attributedText", ArgumentSemantic.Copy)]
1233+
NSAttributedString AttributedText { get; set; }
1234+
11981235
[Export ("fontSize")]
11991236
nfloat FontSize { get; set; }
12001237

@@ -3223,5 +3260,78 @@ interface SKWarpGeometryGrid : NSCoding
32233260
[Export ("gridByReplacingDestPositions:")]
32243261
SKWarpGeometryGrid _GridByReplacingDestPositions (IntPtr destPositions);
32253262
}
3263+
3264+
// SKRenderer is not available for WatchKit apps and the iOS simulator
3265+
[NoWatch]
3266+
[TV (11,0), Mac (10,13), iOS (11,0)]
3267+
[BaseType (typeof(NSObject))]
3268+
[DisableDefaultCtor]
3269+
interface SKRenderer {
3270+
[Static]
3271+
[Export ("rendererWithDevice:")]
3272+
[return: NullAllowed]
3273+
SKRenderer FromDevice ([NullAllowed] IMTLDevice device);
3274+
3275+
[Export ("renderWithViewport:commandBuffer:renderPassDescriptor:")]
3276+
void Render (CGRect viewport, IMTLCommandBuffer commandBuffer, MTLRenderPassDescriptor renderPassDescriptor);
3277+
3278+
[Export ("renderWithViewport:renderCommandEncoder:renderPassDescriptor:commandQueue:")]
3279+
void Render (CGRect viewport, IMTLRenderCommandEncoder renderCommandEncoder, MTLRenderPassDescriptor renderPassDescriptor, IMTLCommandQueue commandQueue);
3280+
3281+
[Export ("updateAtTime:")]
3282+
void Update (double currentTime);
3283+
3284+
[NullAllowed, Export ("scene", ArgumentSemantic.Assign)]
3285+
SKScene Scene { get; set; }
3286+
3287+
[Export ("ignoresSiblingOrder")]
3288+
bool IgnoresSiblingOrder { get; set; }
3289+
3290+
[Export ("shouldCullNonVisibleNodes")]
3291+
bool ShouldCullNonVisibleNodes { get; set; }
3292+
3293+
[Export ("showsDrawCount")]
3294+
bool ShowsDrawCount { get; set; }
3295+
3296+
[Export ("showsNodeCount")]
3297+
bool ShowsNodeCount { get; set; }
3298+
3299+
[Export ("showsQuadCount")]
3300+
bool ShowsQuadCount { get; set; }
3301+
3302+
[Export ("showsPhysics")]
3303+
bool ShowsPhysics { get; set; }
3304+
3305+
[Export ("showsFields")]
3306+
bool ShowsFields { get; set; }
3307+
}
3308+
3309+
[TV (11,0), Watch (4,0), Mac (13,0), iOS (11,0)]
3310+
[BaseType (typeof(SKNode))]
3311+
interface SKTransformNode {
3312+
[Export ("xRotation")]
3313+
nfloat XRotation { get; set; }
3314+
3315+
[Export ("yRotation")]
3316+
nfloat YRotation { get; set; }
3317+
3318+
[Export ("eulerAngles")]
3319+
Vector3 EulerAngles {
3320+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get;
3321+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] set;
3322+
}
3323+
3324+
[Export ("rotationMatrix")]
3325+
Matrix3 RotationMatrix {
3326+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get;
3327+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] set;
3328+
}
3329+
3330+
[Export ("quaternion")]
3331+
Quaternion Quaternion {
3332+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] get;
3333+
[MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] set;
3334+
}
3335+
}
32263336
}
32273337
#endif

tests/introspection/iOS/iOSApiSelectorTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ protected override bool Skip (Type type)
9292
case "UILocalNotification":
9393
return true;
9494

95-
// Metal is not available on the (iOS8) simulator
95+
// Metal is not available on the simulator
9696
case "CAMetalLayer":
97+
case "SKRenderer":
9798
return (Runtime.Arch == Arch.SIMULATOR);
9899

99100
// iOS 10 - this type can only be instantiated on devices, but the selectors are forwarded

tests/monotouch-test/Asserts.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public static void AreEqual (MDLAxisAlignedBoundingBox expected, MDLAxisAlignedB
8383
AreEqual (expected.MaxBounds, actual.MaxBounds, message + " (MaxBounds)");
8484
AreEqual (expected.MinBounds, actual.MinBounds, message + " (MinBounds)");
8585
}
86+
87+
public static void AreEqual (Quaternion expected, Quaternion actual, string message)
88+
{
89+
Assert.AreEqual (expected.X, actual.X, message + " (X)");
90+
Assert.AreEqual (expected.Y, actual.Y, message + " (Y)");
91+
Assert.AreEqual (expected.Z, actual.Z, message + " (Z)");
92+
Assert.AreEqual (expected.W, actual.W, message + " (W)");
93+
}
8694
#endif // !__WATCHOS__
8795
}
8896

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#if !__WATCHOS__
2+
3+
using System;
4+
#if XAMCORE_2_0
5+
using Foundation;
6+
#if !MONOMAC
7+
using UIKit;
8+
#endif
9+
using SpriteKit;
10+
using ObjCRuntime;
11+
#else
12+
using MonoTouch.Foundation;
13+
using MonoTouch.SpriteKit;
14+
using MonoTouch.UIKit;
15+
using MonoTouch.ObjCRuntime;
16+
#endif
17+
using OpenTK;
18+
using NUnit.Framework;
19+
20+
namespace MonoTouchFixtures.SpriteKit {
21+
22+
[TestFixture]
23+
[Preserve (AllMembers = true)]
24+
public class SKTransformNodeTest {
25+
[SetUp]
26+
public void VersionCheck ()
27+
{
28+
TestRuntime.AssertXcodeVersion (9, 0);
29+
}
30+
31+
[Test]
32+
public void EulerAngles ()
33+
{
34+
Vector3 V3;
35+
36+
using (var obj = new SKTransformNode ()) {
37+
Asserts.AreEqual (Vector3.Zero, obj.EulerAngles, "1 EulerAngles");
38+
V3 = new Vector3 (1, 2, 3);
39+
obj.EulerAngles = V3;
40+
// The values bellow match what the same code in Swift returns.
41+
Assert.AreEqual (-2.14159298f, obj.EulerAngles.X, "#x1");
42+
Assert.AreEqual (1.14159274f, obj.EulerAngles.Y, "#y1");
43+
Assert.AreEqual (-0.141592711f, obj.EulerAngles.Z, "#z1");
44+
}
45+
}
46+
47+
[Test]
48+
public void RotationMatrix ()
49+
{
50+
using (var obj = new SKTransformNode ()) {
51+
obj.RotationMatrix = Matrix3.Zero;
52+
// In Swift, a rotated zero matrice also becomes the identity matrice.
53+
Asserts.AreEqual (Matrix3.Identity, obj.RotationMatrix, "RotationMatrix");
54+
}
55+
}
56+
57+
[Test]
58+
public void QuaternionTest ()
59+
{
60+
Quaternion Q;
61+
62+
using (var obj = new SKTransformNode ()) {
63+
Asserts.AreEqual (Quaternion.Identity, obj.Quaternion, "1 Quaternion");
64+
Q = new Quaternion (new Vector3 (1, 2, 3), 4);
65+
obj.Quaternion = Q;
66+
Asserts.AreEqual (Q, obj.Quaternion, "2 Quaternion");
67+
}
68+
}
69+
}
70+
}
71+
72+
#endif // !__WATCHOS__

tests/monotouch-test/monotouch-test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@
657657
<Compile Include="HomeKit\HMPresenceEventTest.cs" />
658658
<Compile Include="HomeKit\HMSignificantTimeEventTest.cs" />
659659
<Compile Include="UIKit\UIDragDropSessionExtensionsTest.cs" />
660+
<Compile Include="SpriteKit\SKTransformNodeTest.cs" />
660661
</ItemGroup>
661662
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
662663
<ItemGroup>

0 commit comments

Comments
 (0)