Skip to content
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

refactor: simplified interest management #990

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

dragonslaya84
Copy link
Member

@dragonslaya84 dragonslaya84 commented Nov 7, 2021

Only implements the interest manager that will auto check if any systems are added if not just use all current players on server to send data. Much faster and there is no need to do checks.

Next step will be to implement different systems people may need or use.

Please test and comment. All users using mirage what type of systems do you think you will need.? I only want to implement what end users are using or implement as end users need them.

Implementing there own system is very easy as creating a new class and overriding the NetworkVisibility system. That creates a pure C# system that interest manager finds. If you require showing the information in inspector you need to create a 2nd file that inherits from BaseVisibilityInspector.

I found it better this way for full control. You would implement both there is a single override that you only need to do and its the Start method of unity and implement anything inside there. The system will auto register itself using the base class.

  • Implement basic global system that just runs when no visibility system set,
  • Write tests
  • Proximity Checker
  • Scene Checker

@dragonslaya84 dragonslaya84 changed the title Simplified interest management refactor: simplified interest management Nov 7, 2021
…i. Proximity checker currently only one that is finished and tested atm.
…null references issues due to adding aoi systems at runtime.
implemented scene visibility
fixed docs ref.
added new unregister so if gameobjects get destroyed they unregister from visibility system.
Implemented a new multi visibility system performance benchmark. Runs Scene + proximity systems.
@James-Frowen
Copy link
Member

James-Frowen commented Nov 12, 2021

I'm getting this error when opening a prefab, Assets/Tests/Performance/Runtime/InterestManagement/InterestManagement/Prefabs/Player.prefab:

NullReferenceException: Object reference not set to an instance of an object
Mirage.NetworkInformationPreview.DrawObservers (Mirage.NetworkIdentity identity, System.Single initialX, System.Single Y) (at Assets/Mirage/Editor/NetworkInformationPreview.cs:176)
Mirage.NetworkInformationPreview.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at Assets/Mirage/Editor/NetworkInformationPreview.cs:114)

@James-Frowen
Copy link
Member

This is still creating 1 system per spawned, you can check using

adding this to Update to test it
Debug.Log($"IM.Count:{_visibilitySystems.Count}");
image

@dragonslaya84
Copy link
Member Author

Debug.Log($"IM.Count:{_visibilitySystems.Count}");

Kk good catch. Its the code I am using for comparing. Maybe its faulty checking now.

@dragonslaya84
Copy link
Member Author

I'm getting this error when opening a prefab, Assets/Tests/Performance/Runtime/InterestManagement/InterestManagement/Prefabs/Player.prefab:

NullReferenceException: Object reference not set to an instance of an object
Mirage.NetworkInformationPreview.DrawObservers (Mirage.NetworkIdentity identity, System.Single initialX, System.Single Y) (at Assets/Mirage/Editor/NetworkInformationPreview.cs:176)
Mirage.NetworkInformationPreview.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at Assets/Mirage/Editor/NetworkInformationPreview.cs:114)

Fixed

registering in onenable is sometimes too early.
It will also cause unspawned objects to be included in AOI, and maybe sent to clients

Also adding todo
- NetworkVisibility to VisibilitySystem
- NetworkProximityCheckerVisibility to DistanceVisibilitySystem
- SceneVisibilityChecker to SceneVisibilitySystem
- _visibilitySystemData to _data
- VisibilitySystemData Observers
moving Comparer so it is not hidden inside IM. Makes it more obvious what is going on when using the sturct in a hashset
we can just use the system itself since it'll have the reference to the dictionary
@sonarcloud
Copy link

sonarcloud bot commented Nov 15, 2021

Please retry analysis of this Pull-Request directly on SonarCloud.

- BaseVisibilityInspector to VisibilitySystemFactory
- NetworkSceneChecker to SceneVisibilityFactory
- NetworkProximityChecker to DistanceVisibilityFactory
we dont need this layer of abstraction
- removing base settings
- making register take identity and settings
- making unregister just take identity

RegisterObject makes more sense if it is given the object, rather than settings that has the object.

This will also reduce extra code if a system does not need any settings (if could just pass in null)
- renamed OnAuthenticated  to RebuildForPlayer

OnAuthenticated seems like a bad name because we will need to call it more than just OnAuthenticated, Like when we spawna  new character for the player
making sure we still call IM functions are same time as before
- need to rebuild observers for player after setting character
- moving show to player to IM
- adding OnSpawn and OnDestroy instead of using world events (we need to control the order, our event might be called before/after user added events)
can just use scene instead
changing how it is created.
pass variables around rather than using fields
- InterestManager lazy intialize
- VisibilitySystemFactory adds to IM on awake, and removes in destroy

Key points:
- IM always exists on SOM
- Systems can and should be added before Server Starts
- Systems will add them selves to IM when they are constructed
@sonarcloud
Copy link

sonarcloud bot commented Nov 16, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 2 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 22 Code Smells

29.6% 29.6% Coverage
0.0% 0.0% Duplication

@github-actions github-actions bot added the has conflicts Pull Request has merge conflicts label Nov 29, 2021
@dragonslaya84 dragonslaya84 added the keep-open Stops issue being closed because it is stale label Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts Pull Request has merge conflicts keep-open Stops issue being closed because it is stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants