-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
C#: Optimize GetProcessDeltaTime() and GetPhysicsProcessDeltaTime() #74078
Closed
neikeq
wants to merge
1
commit into
godotengine:master
from
neikeq:csharp-optimize-get-delta-time-methods
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Godot | ||
{ | ||
|
@@ -195,5 +197,30 @@ public T GetParentOrNull<T>() where T : class | |
{ | ||
return GetParent() as T; | ||
} | ||
|
||
internal static double CachedPhysicsProcessDeltaTime; | ||
internal static double CachedProcessDeltaTime; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
[SuppressMessage("Performance", "CA1822:Mark members as static")] | ||
public partial double GetPhysicsProcessDeltaTime() => CachedPhysicsProcessDeltaTime; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
[SuppressMessage("Performance", "CA1822:Mark members as static")] | ||
public partial double GetProcessDeltaTime() => CachedProcessDeltaTime; | ||
Comment on lines
+204
to
+210
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we hide/deprecate these methods in favor of the properties? |
||
|
||
/// <inheritdoc cref="GetPhysicsProcessDeltaTime()"/> | ||
public static double PhysicsDeltaTime | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => CachedPhysicsProcessDeltaTime; | ||
} | ||
|
||
/// <inheritdoc cref="GetProcessDeltaTime()"/> | ||
public static double DeltaTime | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => CachedProcessDeltaTime; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -79,6 +79,7 @@ struct ManagedCallbacks { | |
using FuncDelegateUtils_TrySerializeDelegateWithGCHandle = bool(GD_CLR_STDCALL *)(GCHandleIntPtr, const Array *); | ||
using FuncDelegateUtils_TryDeserializeDelegateWithGCHandle = bool(GD_CLR_STDCALL *)(const Array *, GCHandleIntPtr *); | ||
using FuncScriptManagerBridge_FrameCallback = void(GD_CLR_STDCALL *)(); | ||
using FuncScriptManagerBridge_SetProcessDeltaTime = void(GD_CLR_STDCALL *)(double, bool); | ||
using FuncScriptManagerBridge_CreateManagedForGodotObjectBinding = GCHandleIntPtr(GD_CLR_STDCALL *)(const StringName *, Object *); | ||
using FuncScriptManagerBridge_CreateManagedForGodotObjectScriptInstance = bool(GD_CLR_STDCALL *)(const CSharpScript *, Object *, const Variant **, int32_t); | ||
using FuncScriptManagerBridge_GetScriptNativeName = void(GD_CLR_STDCALL *)(const CSharpScript *, StringName *); | ||
|
@@ -112,6 +113,7 @@ struct ManagedCallbacks { | |
FuncDelegateUtils_TrySerializeDelegateWithGCHandle DelegateUtils_TrySerializeDelegateWithGCHandle; | ||
FuncDelegateUtils_TryDeserializeDelegateWithGCHandle DelegateUtils_TryDeserializeDelegateWithGCHandle; | ||
FuncScriptManagerBridge_FrameCallback ScriptManagerBridge_FrameCallback; | ||
FuncScriptManagerBridge_SetProcessDeltaTime ScriptManagerBridge_SetProcessDeltaTime; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot to add |
||
FuncScriptManagerBridge_CreateManagedForGodotObjectBinding ScriptManagerBridge_CreateManagedForGodotObjectBinding; | ||
FuncScriptManagerBridge_CreateManagedForGodotObjectScriptInstance ScriptManagerBridge_CreateManagedForGodotObjectScriptInstance; | ||
FuncScriptManagerBridge_GetScriptNativeName ScriptManagerBridge_GetScriptNativeName; | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of using the
process_frame
andphysics_frame
signals, but our callback needs to have priority, as we want the delta time to be updated before the other callbacks are called.