-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New `RunTime` structure ## Changed Changes in `RunTimeInitialization`.
- Loading branch information
Showing
8 changed files
with
174 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
namespace Cobilas.GodotEngine.Utility.Runtime; | ||
|
||
public enum Priority { | ||
StartBefore, | ||
StartLater | ||
/// <summary>Indicates the boot priority.</summary> | ||
public enum Priority : byte { | ||
/// <summary>Starts before everyone else.</summary> | ||
StartBefore = 0, | ||
/// <summary>Starts after everyone else.</summary> | ||
StartLater = 1 | ||
} |
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,58 @@ | ||
using Godot; | ||
using System; | ||
using Cobilas.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Cobilas.GodotEngine.Utility.Runtime; | ||
/// <summary>Represents a list of <seealso cref="RunTimeInitialization"/> priorities.</summary> | ||
public struct PriorityList : IDisposable { | ||
private KeyValuePair<int, Node>[] nodes; | ||
|
||
/// <summary>Adds items to the priority list.</summary> | ||
/// <param name="priority">Object execution priority.</param> | ||
/// <param name="node">The object to be added to the list.</param> | ||
/// <returns>The method will return a <seealso cref="PriorityList"/> object with its modified priority list.</returns> | ||
public PriorityList Add(int priority, Node node) { | ||
nodes ??= Array.Empty<KeyValuePair<int, Node>>(); | ||
ArrayManipulation.Add(new KeyValuePair<int, Node>(priority, node), ref nodes); | ||
return this; | ||
} | ||
|
||
/// <summary>Execute your priority list.</summary> | ||
/// <param name="root">The parent node where nodes will be added to start their priority execution.</param> | ||
public readonly void Run(Node root) { | ||
if (!ArrayManipulation.EmpytArray(nodes)) | ||
foreach (KeyValuePair<int, Node> item in nodes) | ||
if (item.Value != null) | ||
root.AddChild(item.Value); | ||
} | ||
|
||
/// <summary>Sort the priority list according to the priority of the list items.</summary> | ||
public void ReorderList() { | ||
KeyValuePair<int, Node>[] temp = ReorderList(nodes); | ||
ArrayManipulation.ClearArray(ref nodes); | ||
nodes = temp; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() => ArrayManipulation.ClearArraySafe(ref nodes); | ||
|
||
private static KeyValuePair<int, Node>[] ReorderList(KeyValuePair<int, Node>[] list) { | ||
KeyValuePair<int, Node>[] result = Array.Empty<KeyValuePair<int, Node>>(); | ||
for (long A = 0; A < list.Length; A++) { | ||
if (result.LongLength == 0) { | ||
ArrayManipulation.Add(list[A], ref result); | ||
continue; | ||
} | ||
bool addInResult = true; | ||
for (long B = 0; B < result.LongLength; B++) | ||
if (list[A].Key < result[B].Key) { | ||
ArrayManipulation.Insert(list[A], B, ref result); | ||
addInResult = false; | ||
break; | ||
} | ||
if (addInResult) ArrayManipulation.Add(list[A], ref result); | ||
} | ||
return result; | ||
} | ||
} |
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,12 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Cobilas.GodotEngine.Utility.Runtime; | ||
|
||
/// <summary>Provides RunTime values and functions.</summary> | ||
[StructLayout(LayoutKind.Sequential, Size = 1)] | ||
public readonly struct RunTime { | ||
/// <summary>The interval in seconds from the last frame to the current one (Read Only).</summary> | ||
public const float DeltaTime = .33333333f; | ||
/// <summary>The interval in seconds of in-game time at which physics and other fixed frame rate updates are performed.</summary> | ||
public const float FixedDeltaTime = .02f; | ||
} |
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