-
Notifications
You must be signed in to change notification settings - Fork 459
feat!: interest system #1394
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
feat!: interest system #1394
Changes from all commits
cc36ca1
aaa0c91
6d89ca5
79567da
2484a7e
961339d
bb6bc00
67106a1
bb4a6ff
6a3dd26
3a7f24b
63683cd
86a44f0
143c067
dcb68a0
d29cc19
19aecd4
0c221ba
65b58f3
d7bb5fa
70af4cc
cf02c95
b9bb5ba
27f02bd
2cdbe0f
86adb19
ca0aba1
c1976d6
1050c29
da48bab
422d73d
c517d2c
311ca34
e797a38
ed6a847
0c0a53e
ae6030a
a6b7a5c
3e4cc99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using Unity.Netcode.Interest; | ||
|
|
||
| namespace Unity.Netcode | ||
| { | ||
| public class AddAllInterestKernel : IInterestKernel<NetworkObject> | ||
| { | ||
|
|
||
| public bool QueryFor(NetworkObject clientNetworkObject, NetworkObject obj) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| using System.Collections.Generic; | ||
| namespace Unity.Netcode.Interest | ||
| { | ||
| internal interface IInterestObject<TObject> | ||
| { | ||
| public void AddInterestNode(IInterestNode<TObject> obj); | ||
| public void RemoveInterestNode(IInterestNode<TObject> obj); | ||
| public List<IInterestNode<TObject>> GetInterestNodes(); | ||
| } | ||
|
|
||
| // interest *system* instead of interest node ? | ||
| internal class InterestManager<TObject> where TObject : IInterestObject<TObject> | ||
| { | ||
| private readonly InterestNodeStatic<TObject> m_DefaultInterestNode = new InterestNodeStatic<TObject>(); | ||
|
|
||
| // Trigger the Interest system to do an update sweep on any Interest nodes | ||
| // I am associated with | ||
| public void UpdateObject(ref TObject obj) | ||
| { | ||
| List<IInterestNode<TObject>> nodes = obj.GetInterestNodes(); | ||
| foreach (var node in nodes) | ||
| { | ||
| node.UpdateObject(obj); | ||
| } | ||
| } | ||
|
|
||
| public InterestManager() | ||
| { | ||
| // This is the node objects will be added to if no replication group is | ||
| // specified, which means they always get replicated | ||
| m_ChildNodes = new HashSet<IInterestNode<TObject>> { m_DefaultInterestNode }; | ||
| } | ||
|
|
||
| public void AddObject(ref TObject obj) | ||
| { | ||
| // If this new object has no associated Interest Nodes, then we put it in the | ||
| // default node, which all clients will then get. | ||
| // | ||
| // That is, if you don't opt into the system behavior is the same as before | ||
| // the Interest system was added | ||
|
|
||
| List<IInterestNode<TObject>> nodes = obj.GetInterestNodes(); | ||
|
|
||
| if (nodes.Count > 0) | ||
| { | ||
| // I am walking through each of the interest nodes that this object has | ||
| foreach (var node in nodes) | ||
| { | ||
| // the Interest Manager lazily adds nodes to itself when it sees | ||
| // new nodes that associate with the objects being added | ||
| m_ChildNodes.Add(node); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // if the object doesn't have any nodes, we assign it to the default node | ||
| AddDefaultInterestNode(obj); | ||
| } | ||
| } | ||
|
|
||
| public void AddDefaultInterestNode(TObject obj) | ||
| { | ||
| obj.AddInterestNode(m_DefaultInterestNode); | ||
| } | ||
|
|
||
| public void RemoveObject(ref TObject obj) | ||
| { | ||
| List<IInterestNode<TObject>> nodes = obj.GetInterestNodes(); | ||
| foreach (var node in nodes) | ||
| { | ||
| if (node == null) | ||
| { | ||
| continue; | ||
| } | ||
| node.RemoveObject(obj); | ||
| } | ||
| } | ||
|
|
||
| public void QueryFor(ref TObject client, ref HashSet<TObject> results) | ||
| { | ||
| foreach (var c in m_ChildNodes) | ||
| { | ||
| c.QueryFor(client, results); | ||
| } | ||
| } | ||
|
|
||
| private HashSet<IInterestNode<TObject>> m_ChildNodes; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Unity.Netcode.Interest | ||
| { | ||
| public interface IInterestNode<TObject> | ||
| { | ||
| public void QueryFor(TObject client, HashSet<TObject> results); | ||
| public void AddObject(TObject obj); | ||
| public void RemoveObject(TObject obj); | ||
| public void UpdateObject(TObject obj); | ||
| public void AddAdditiveKernel(IInterestKernel<TObject> kernel); | ||
| public void AddSubtractiveKernel(IInterestKernel<TObject> kernel); | ||
| }; | ||
|
|
||
| public interface IInterestKernel<TObject> | ||
| { | ||
| public bool QueryFor(TObject client, TObject obj); | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Is this needed ?
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.
As in, do we need the getter? I ran into problems with testing and this lazy initialization scheme was my solution. I actually am not a fan on how all the other services above (e.g. NetworkBehaviourUpdater) don't initialize until
NetworkManager::Initialize()is called and am interested in porting them to this way, because that means to exercise them I must callStartServer/StartHost, and maybe I don't want to require a stood-up, connected NM to test / exercise it.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 mean the extra space :P