Skip to content

Commit

Permalink
adding the ability to add systems to the Initialization system group …
Browse files Browse the repository at this point in the history
…and addressed slow equality warnings fore graph data
  • Loading branch information
tbg10101 committed Oct 19, 2024
1 parent 99ecd94 commit 269276b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ desktop.ini
# JetBrains Rider generated #
# ========================= #
.idea
/Examples~/*/*.user
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 993198346}
m_IndirectSpecularColor: {r: 0.18028386, g: 0.22571427, b: 0.3069231, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -517,14 +516,19 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_flags: 5
_initializationGroup:
Nodes:
- SystemReference: {fileID: 0}
NodePosition: {x: 1126, y: 441}
Dependencies: []
_simResetGroup:
Nodes:
- SystemReference: {fileID: 0}
NodePosition: {x: 918, y: 271}
Dependencies:
- {fileID: 11400000, guid: e01661ff769361b4b937408c043acd78, type: 2}
- SystemReference: {fileID: 11400000, guid: e01661ff769361b4b937408c043acd78, type: 2}
NodePosition: {x: 584, y: 208}
NodePosition: {x: 604, y: 271}
Dependencies: []
_mainSimGroup:
Nodes:
Expand Down Expand Up @@ -556,7 +560,7 @@ MonoBehaviour:
Dependencies:
- {fileID: 11400000, guid: a2c5f951bc7bf904cb32976be936ea2d, type: 2}
- SystemReference: {fileID: 11400000, guid: a2c5f951bc7bf904cb32976be936ea2d, type: 2}
NodePosition: {x: 221, y: 230}
NodePosition: {x: 240, y: 220}
Dependencies: []
_presentationPostUpdateGroup:
Nodes:
Expand Down Expand Up @@ -778,12 +782,12 @@ MonoBehaviour:
m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings:
quality: 3
frameInfluence: 0.1
jitterScale: 1
mipBias: 0
varianceClampScale: 0.9
contrastAdaptiveSharpening: 0
m_Quality: 3
m_FrameInfluence: 0.1
m_JitterScale: 1
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
--- !u!20 &1317645714
Camera:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -883,6 +887,7 @@ MonoBehaviour:
m_DeselectOnBackgroundClick: 1
m_PointerBehavior: 0
m_CursorLockBehavior: 0
m_ScrollDeltaPerTick: 6
--- !u!114 &1325820873
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
29 changes: 28 additions & 1 deletion Runtime/Scripts/MonoBehaviours/SystemTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,37 @@
using UnityEngine;

namespace Software10101.DOTS.MonoBehaviours {
public abstract class SystemTypeReference : ScriptableObject {
public abstract class SystemTypeReference : ScriptableObject, IEquatable<SystemTypeReference> {
public abstract Type SystemType {
get;
}

public bool Equals(SystemTypeReference other) {
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return base.Equals(other) && SystemType == other.SystemType;
}

public override bool Equals(object obj) {
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((SystemTypeReference)obj);
}

public override int GetHashCode() {
unchecked {
return (base.GetHashCode() * 397) ^ (SystemType != null ? SystemType.GetHashCode() : 0);
}
}

public static bool operator ==(SystemTypeReference left, SystemTypeReference right) {
return Equals(left, right);
}

public static bool operator !=(SystemTypeReference left, SystemTypeReference right) {
return !Equals(left, right);
}
}

public abstract class SystemTypeReference<T> : SystemTypeReference where T : ReferenceCreatedSystemBase {
Expand Down
64 changes: 60 additions & 4 deletions Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public sealed class WorldBehaviour : MonoBehaviour {
[SerializeField]
private WorldFlags _flags = WorldFlags.Game;

[Tooltip("Also know as the Initialization group.")]
[SerializeField]
private GraphSystemGroupData _startOfFrameGroup = GraphSystemGroupData.CreateEmpty();

[SerializeField]
private GraphSystemGroupData _simResetGroup = GraphSystemGroupData.CreateEmpty();

Expand All @@ -48,9 +52,12 @@ private void Awake() {
_world = new World(name, _flags);

// set up initialization group
// ReSharper disable once UnusedVariable // not used by the bootstrapper but is one of Unity's root system groups
InitializationSystemGroup initGroup =
InitializationSystemGroup startOfFrameGroup =
AddSystemToCurrentPlayerLoop(new InitializationSystemGroup(), typeof(Initialization));
foreach (SystemTypeReference systemTypeReference in _startOfFrameGroup.GetExecutionOrder()) {
CreateSystemIntoGroup(systemTypeReference.SystemType, startOfFrameGroup).SetCreator(systemTypeReference);
}
AddSystemToGroup(new PostStartOfFrameEntityCommandBufferSystem(), startOfFrameGroup);

// set up simulation systems
SimulationSystemGroup simGroup = AddSystemToCurrentPlayerLoop(new SimulationSystemGroup(), typeof(FixedUpdate));
Expand Down Expand Up @@ -103,6 +110,7 @@ private void Awake() {
}

private void Reset() {
_startOfFrameGroup = GraphSystemGroupData.CreateEmpty();
_simResetGroup = GraphSystemGroupData.CreateEmpty();
_mainSimGroup = GraphSystemGroupData.CreateEmpty();
_presentationPreUpdateGroup = GraphSystemGroupData.CreateEmpty();
Expand Down Expand Up @@ -178,6 +186,7 @@ public IReadOnlyDictionary<SystemTypeReference, string> GetAllConfiguredSystemRe
Dictionary<SystemTypeReference, string> result = new();

Dictionary<GraphSystemGroupData, string> groups = new() {
{ _startOfFrameGroup, nameof(_startOfFrameGroup) },
{ _simResetGroup, nameof(_simResetGroup) },
{ _mainSimGroup, nameof(_mainSimGroup) },
{ _presentationPreUpdateGroup, nameof(_presentationPreUpdateGroup) },
Expand Down Expand Up @@ -219,7 +228,7 @@ internal CreationBufferToken() { }
}

[Serializable]
public struct GraphSystemGroupData {
public struct GraphSystemGroupData : IEquatable<GraphSystemGroupData> {
public SystemNodeData[] Nodes;

public static GraphSystemGroupData CreateEmpty() {
Expand Down Expand Up @@ -278,7 +287,7 @@ public IEnumerable<SystemTypeReference> GetExecutionOrder() {
}

[Serializable]
public struct SystemNodeData {
public struct SystemNodeData : IEquatable<SystemNodeData> {
public SystemTypeReference SystemReference;
public Vector2 NodePosition;
public SystemTypeReference[] Dependencies;
Expand All @@ -292,6 +301,53 @@ SystemTypeReference[] dependencies
NodePosition = nodePosition;
Dependencies = dependencies;
}

public bool Equals(SystemNodeData other) {
return Equals(SystemReference, other.SystemReference) &&
NodePosition.Equals(other.NodePosition) &&
Dependencies.SequenceEqual(other.Dependencies);
}

public override bool Equals(object obj) {
return obj is SystemNodeData other && Equals(other);
}

public override int GetHashCode() {
unchecked {
int hashCode = (SystemReference != null ? SystemReference.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ NodePosition.GetHashCode();
hashCode = (hashCode * 397) ^ (Dependencies != null ? Dependencies.GetHashCode() : 0);
return hashCode;
}
}

public static bool operator ==(SystemNodeData left, SystemNodeData right) {
return left.Equals(right);
}

public static bool operator !=(SystemNodeData left, SystemNodeData right) {
return !left.Equals(right);
}
}

public bool Equals(GraphSystemGroupData other) {
return Nodes.SequenceEqual(other.Nodes);
}

public override bool Equals(object obj) {
return obj is GraphSystemGroupData other && Equals(other);
}

public override int GetHashCode() {
return (Nodes != null ? Nodes.GetHashCode() : 0);
}

public static bool operator ==(GraphSystemGroupData left, GraphSystemGroupData right) {
return left.Equals(right);
}

public static bool operator !=(GraphSystemGroupData left, GraphSystemGroupData right) {
return !left.Equals(right);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Software10101.DOTS.Systems.Groups;
using Unity.Entities;

namespace Software10101.DOTS.Systems.EntityCommandBufferSystems {
[UpdateInGroup(typeof(SimulationSystemGroup))]
[UpdateAfter(typeof(SimulationMainSystemGroup))]
public sealed partial class PostStartOfFrameEntityCommandBufferSystem : EntityCommandBufferSystem { }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.10101software.dots.hybridsimulation",
"displayName": "DOTS Hybrid Simulation Worlds",
"description": "A framework for using FixedUpdate in a simulation world which is linked to a GameObject-based presentation layer.",
"version": "1.3.1",
"version": "1.3.2",
"unity": "2022.3",
"dependencies": {
"com.unity.entities": "1.3.5"
Expand Down

0 comments on commit 269276b

Please sign in to comment.