Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more extensions for Stride #76

Merged
merged 5 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sandbox/R3.Stride.Sandbox/R3.Stride.Sandbox.sln
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34408.163
Expand Down
12 changes: 12 additions & 0 deletions sandbox/R3.Stride.Sandbox/R3.Stride.Sandbox/Assets/Cube.sdpromodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!ProceduralModelAsset
Id: b6a6bd83-1c1f-4d73-8cd8-bd8a66cbe3c5
SerializedVersion: {Stride: 2.0.0.0}
Tags: []
Type: !CubeProceduralModel
Size: {X: 1.0, Y: 1.0, Z: 1.0}
Scale: {X: 1.0, Y: 1.0, Z: 1.0}
UvScale: {X: 1.0, Y: 1.0}
LocalOffset: {X: 0.0, Y: 0.0, Z: 0.0}
NumberOfTextureCoordinates: 10
MaterialInstance:
Material: 5b5781be-8137-4898-925e-5969eb8476a0:Sphere Material
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Hierarchy:
- ref!! 56cd9852-d94c-4646-a513-85195ea3fe9b
- ref!! b7806d41-f54f-4e99-9ec7-f9906f10b006
- ref!! 787562e5-0943-4493-85ce-6b0bd2abf47f
- ref!! 9c0e2928-6cdc-4033-b5cc-06d2dfdb291d
Parts:
- Entity:
Id: 016064cc-d022-441a-9402-adc01926f5c6
Expand Down Expand Up @@ -53,13 +54,27 @@ Hierarchy:
Id: 1a9d3c62-9ef5-4bde-b8e2-71ed721c0d9b
Model: aff8da36-c1ef-43b3-8fc4-4212a0730901:Ground
Materials: {}
9cd507465eca3af487d41bf2b217d26d: !StaticColliderComponent
Id: 076e6b55-b3c6-4922-ae2d-298b28a31cf0
CanSleep: false
Restitution: 0.0
Friction: 0.5
RollingFriction: 0.0
CcdMotionThreshold: 0.0
CcdSweptSphereRadius: 0.0
IsTrigger: false
AlwaysUpdateNaviMeshCache: false
ColliderShapes:
153eee591f3997346bb2929e45ea6830: !StaticPlaneColliderShapeDesc
Normal: {X: 0.0, Y: 1.0, Z: 0.0}
Offset: 0.0
- Entity:
Id: 2b300ec9-5416-4771-ab62-636a1ce25643
Name: Camera
Components:
b8b773f875648c0554f1d1f77a3e6982: !TransformComponent
Id: 6b2cd6ec-5617-4c0a-99f9-731f7a874820
Position: {X: 2.6, Y: 0.6, Z: -1.0}
Position: {X: 5.0, Y: 0.6, Z: -2.0}
Rotation: {X: 0.0, Y: 0.82903755, Z: 0.0, W: 0.5591929}
Scale: {X: 1.0, Y: 1.0, Z: 1.0}
Children: {}
Expand All @@ -82,6 +97,26 @@ Hierarchy:
Id: 0b8a72b5-76a3-447c-92fb-93e5302f01b9
Model: c4063b2b-caff-4757-9bcd-47c34e9452cc:Sphere
Materials: {}
9ecd94ecc0e9386fbd0c327a059558bc: !RigidbodyComponent
Id: fbf3f6ba-4737-4788-b5e9-f1b7506c5e79
CanSleep: false
Restitution: 0.0
Friction: 0.5
RollingFriction: 0.0
CcdMotionThreshold: 0.0
CcdSweptSphereRadius: 0.0
IsTrigger: false
IsKinematic: false
Mass: 1.0
LinearDamping: 0.0
AngularDamping: 0.0
OverrideGravity: false
Gravity: {X: 0.0, Y: 0.0, Z: 0.0}
NodeName: null
ColliderShapes:
f07e140ad4c31956db525f8c23bc5f92: !SphereColliderShapeDesc
Is2D: false
LocalOffset: {X: 0.0, Y: 0.0, Z: 0.0}
- Entity:
Id: 5fe200ea-5597-4507-b15e-2a13ec790a29
Name: Skybox
Expand Down Expand Up @@ -116,6 +151,44 @@ Hierarchy:
Size: {X: 1.28, Y: 0.72, Z: 1.0}
87d8cfc0f2480a8c80ec5245c6710d2f: !R3.Stride.Sandbox.UIExtensionTest,R3.Stride.Sandbox
Id: 65687212-b652-4f3f-a61a-f3320cc3e1e6
- Entity:
Id: 9c0e2928-6cdc-4033-b5cc-06d2dfdb291d
Name: Cube
Components:
f3a9306cfab07ec9687f289ac04ebe44: !TransformComponent
Id: 6524d4a2-830b-4be5-96a4-e07c28761768
Position: {X: 0.0, Y: 0.5, Z: 2.0}
Rotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
Scale: {X: 0.5, Y: 0.5, Z: 0.5}
Children: {}
905fc01ae7567f30e72873cd6f9269ec: !ModelComponent
Id: b931a3a8-253e-4ad9-b4d9-1ef12891519d
Model: b6a6bd83-1c1f-4d73-8cd8-bd8a66cbe3c5:Cube
Materials: {}
7e202eb6e07ed1ff4366b2c6eff48b73: !RigidbodyComponent
Id: 76143390-3505-458b-8165-a00cb34abfa7
CanSleep: false
Restitution: 0.0
Friction: 0.5
RollingFriction: 0.0
CcdMotionThreshold: 0.0
CcdSweptSphereRadius: 0.0
IsTrigger: true
IsKinematic: false
Mass: 0.0
LinearDamping: 0.0
AngularDamping: 0.0
OverrideGravity: false
Gravity: {X: 0.0, Y: 0.0, Z: 0.0}
NodeName: null
ColliderShapes:
59522ecd008781a40fe910ce5729b87f: !BoxColliderShapeDesc
Is2D: false
Size: {X: 0.5, Y: 0.5, Z: 0.5}
LocalOffset: {X: 0.0, Y: 0.0, Z: 0.0}
LocalRotation: {X: 0.0, Y: 0.0, Z: 0.0, W: 1.0}
f0e5f00a9db5203f5ec7e550b0e88491: !R3.Stride.Sandbox.CubeCollisionTest,R3.Stride.Sandbox
Id: 7ba17cb9-5eab-4c77-abd2-59f412561715
- Entity:
Id: b7806d41-f54f-4e99-9ec7-f9906f10b006
Name: Entity
Expand All @@ -130,3 +203,5 @@ Hierarchy:
Id: ad787971-6f5a-440e-91f5-f247ce01d6b4
6f4023fe5b305442911adadcff8c385d: !R3.Stride.Sandbox.ObservableTestScript,R3.Stride.Sandbox
Id: 1d8eed70-d32b-4820-a015-98f6b0634f8e
d6c08302e8bc4cff4f75a1bef919f3ea: !R3.Stride.Sandbox.EventKeyReceiverTest,R3.Stride.Sandbox
Id: 340c3d80-da0d-4b6f-b7b7-4071e161d717
50 changes: 50 additions & 0 deletions sandbox/R3.Stride.Sandbox/R3.Stride.Sandbox/CubeCollisionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stride.Core.Mathematics;
using Stride.Input;
using Stride.Engine;
using Stride.Physics;
using Silk.NET.OpenGL;

namespace R3.Stride.Sandbox
{
public class CubeCollisionTest : StartupScript
{
// Declared public member fields and properties will show in the game studio

public override void Start()
{
// Initialization of the script.
var component = Entity.Get<RigidbodyComponent>();
component.AngularVelocity = Vector3.UnitZ;
component.Collisions.CollectionChangedAsObservable()
.Subscribe(x =>
{
var (sender, arg) = x;
if(arg.Item is Collision collision)
{
Log.Info($"{sender}: {collision.ColliderA.Entity.Name}, {collision.ColliderB.Entity.Name}, {arg.Action}");
}
else
{
Log.Info($"{sender}: {arg.Item}, {arg.Key} {arg.Index}, {arg.OldItem}, {arg.Action}");
}
component.AngularVelocity = -component.AngularVelocity;
//component.UpdatePhysicsTransformation();
});
Observable.EveryUpdate()
.Subscribe(Entity, (_, ent) =>
{
var velocity = component.LinearVelocity;
velocity.Z = MathF.Cos((float)Game.UpdateTime.Total.TotalSeconds / 2);
component.LinearVelocity = velocity;
//component.UpdatePhysicsTransformation();
DebugText.Print($"{ent.Transform.Position}", new Int2(10, 300));
});

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stride.Engine;
using Stride.Engine.Events;

namespace R3.Stride.Sandbox;
public class EventKeyReceiverTest : StartupScript
{
EventKey<int> EventKey1 = new EventKey<int>("EventKeyTest", "Event1");
EventKey EventKey2 = new EventKey("EventKeyTest", "Event2");
public override void Start()
{
EventKey1.AsObservable()
.Subscribe(x =>
{
Log.Info($"event1 published: {x}");
});
EventKey2.AsObservable()
.Subscribe(_ =>
{
Log.Info("event2 published");
});
Observable.EveryUpdate()
.ThrottleLastFrame(60)
.Select((_, i) => i)
.Subscribe(x =>
{
EventKey1.Broadcast(x);
EventKey2.Broadcast();
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ObservableTestScript : SyncScript
// Declared public member fields and properties will show in the game studio
public override void Start()
{
Observable.Interval(TimeSpan.FromSeconds(1))
Observable.Interval(TimeSpan.FromSeconds(5))
.Subscribe(_ =>
{
Log.Info($"interval: {Game.UpdateTime.Total}");
Expand All @@ -29,7 +29,7 @@ public override void Start()
.ThrottleLastFrame(60)
.Subscribe(x =>
{
throw new Exception("test exception");
//throw new Exception("test exception");
});
}

Expand Down
31 changes: 31 additions & 0 deletions src/R3.Stride/R3StrideCollectionExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stride.Core.Collections;
using System.Threading;

namespace R3;
public static class R3StrideCollectionExtension
{
public static Observable<(object? sender, TrackingCollectionChangedEventArgs arg)> CollectionChangedAsObservable(this ITrackingCollectionChanged hashset, CancellationToken token = default)
{
return Observable.FromEventHandler<TrackingCollectionChangedEventArgs>(h => hashset.CollectionChanged += h, h => hashset.CollectionChanged -= h, token);
}
public static Observable<(object? sender, FastTrackingCollectionChangedEventArgs arg)> CollectionChangedAsObservable<T>(this FastTrackingCollection<T> collection, CancellationToken token = default)
{
return Observable.FromEvent<FastTrackingCollection<T>.FastEventHandler<FastTrackingCollectionChangedEventArgs>, (object?, FastTrackingCollectionChangedEventArgs)>(
h =>
{
void Handler(object? sender, ref FastTrackingCollectionChangedEventArgs arg)
{
h((sender, arg));
}
return new FastTrackingCollection<T>.FastEventHandler<FastTrackingCollectionChangedEventArgs>(Handler);
},
h => collection.CollectionChanged += h,
h => collection.CollectionChanged -= h,
token);
}
}
Loading