-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
365 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<!-- Currently no packable --> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="GodotSharp" Version="4.2.1" /> | ||
<!--<PackageReference Include="Godot.SourceGenerators" Version="4.2.1" />--> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\R3\R3.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#nullable enable | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace R3; | ||
|
||
public partial class FrameProviderDispatcher : global::Godot.Node | ||
{ | ||
StrongBox<double> processDelta = new StrongBox<double>(); | ||
StrongBox<double> physicsProcessDelta = new StrongBox<double>(); | ||
|
||
public override void _Ready() | ||
{ | ||
GodotProviderInitializer.SetDefaultObservableSystem(); | ||
|
||
((GodotFrameProvider)GodotFrameProvider.Process).Delta = processDelta; | ||
((GodotFrameProvider)GodotFrameProvider.PhysicsProcess).Delta = physicsProcessDelta; | ||
} | ||
|
||
public override void _Process(double delta) | ||
{ | ||
processDelta.Value = delta; | ||
((GodotFrameProvider)GodotFrameProvider.Process).Run(delta); | ||
} | ||
|
||
public override void _PhysicsProcess(double delta) | ||
{ | ||
physicsProcessDelta.Value = delta; | ||
((GodotFrameProvider)GodotFrameProvider.PhysicsProcess).Run(delta); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#nullable enable | ||
|
||
using Godot; | ||
using R3.Collections; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace R3; | ||
|
||
internal enum PlayerLoopTiming | ||
{ | ||
Process, | ||
PhysicsProcess | ||
} | ||
|
||
public class GodotFrameProvider : FrameProvider | ||
{ | ||
public static readonly FrameProvider Process = new GodotFrameProvider(PlayerLoopTiming.Process); | ||
public static readonly FrameProvider PhysicsProcess = new GodotFrameProvider(PlayerLoopTiming.PhysicsProcess); | ||
|
||
FreeListCore<IFrameRunnerWorkItem> list; | ||
readonly object gate = new object(); | ||
|
||
PlayerLoopTiming PlayerLoopTiming { get; } | ||
|
||
internal StrongBox<double> Delta = default!; // set from Node before running process. | ||
|
||
internal GodotFrameProvider(PlayerLoopTiming playerLoopTiming) | ||
{ | ||
this.PlayerLoopTiming = playerLoopTiming; | ||
this.list = new FreeListCore<IFrameRunnerWorkItem>(gate); | ||
} | ||
|
||
public override long GetFrameCount() | ||
{ | ||
if (PlayerLoopTiming == PlayerLoopTiming.Process) | ||
{ | ||
return (long)Engine.GetProcessFrames(); | ||
} | ||
else | ||
{ | ||
return (long)Engine.GetPhysicsFrames(); | ||
} | ||
} | ||
|
||
public override void Register(IFrameRunnerWorkItem callback) | ||
{ | ||
list.Add(callback, out _); | ||
} | ||
|
||
internal void Run(double _) | ||
{ | ||
long frameCount = GetFrameCount(); | ||
|
||
var span = list.AsSpan(); | ||
for (int i = 0; i < span.Length; i++) | ||
{ | ||
ref readonly var item = ref span[i]; | ||
if (item != null) | ||
{ | ||
try | ||
{ | ||
if (!item.MoveNext(frameCount)) | ||
{ | ||
list.Remove(i); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
list.Remove(i); | ||
try | ||
{ | ||
ObservableSystem.GetUnhandledExceptionHandler().Invoke(ex); | ||
} | ||
catch { } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#nullable enable | ||
|
||
using Godot; | ||
using System; | ||
|
||
namespace R3; | ||
|
||
public static class GodotProviderInitializer | ||
{ | ||
public static void SetDefaultObservableSystem() | ||
{ | ||
SetDefaultObservableSystem(ex => GD.PrintErr(ex)); | ||
} | ||
|
||
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler) | ||
{ | ||
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler); | ||
ObservableSystem.DefaultTimeProvider = GodotTimeProvider.Process; | ||
ObservableSystem.DefaultFrameProvider = GodotFrameProvider.PhysicsProcess; | ||
} | ||
} |
Oops, something went wrong.