-
Notifications
You must be signed in to change notification settings - Fork 11
Only run the routing algorithm when RA updates #70
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
Open
periodically-makes-puns
wants to merge
7
commits into
mockingbirdnest:master
Choose a base branch
from
periodically-makes-puns:route_on_ra
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
57a6ea4
vgv optimisations, run once every RA update
periodically-makes-puns ab03650
only update on RA hook
periodically-makes-puns bc3166f
indentation
periodically-makes-puns b26c4ca
i'm too tired to notice whitespace issues
periodically-makes-puns baa60ca
style oopsie, postincrement
periodically-makes-puns 7d25d39
fix memory leak, cleanup last update time
periodically-makes-puns 9b6fc19
properly consume power
periodically-makes-puns 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 hidden or 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,9 +1,9 @@ | ||
| namespace σκοπός { | ||
| internal class RuntimeMetrics { | ||
| public RuntimeMetrics() { } | ||
| public int num_fixed_update_iterations_ = 0; | ||
| public double fixed_update_runtime_ = 0; | ||
| public int num_iterations_ = 0; | ||
| public double total_runtime_ = 0; | ||
|
|
||
| public double AverageFixedUpdateRuntime => fixed_update_runtime_ / num_fixed_update_iterations_; | ||
| public double AverageRefreshRuntime => total_runtime_ / num_iterations_; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -48,13 +48,15 @@ public void Start() { | |
| Log("Starting"); | ||
| enabled = false; | ||
| GameEvents.CommNet.OnNetworkInitialized.Add(NetworkInitializedNotify); | ||
| GameEvents.CommNet.OnNetworkInitialized.Add(AddPostUpdateHandler); | ||
| GameEvents.Contract.onContractsLoaded.Add(NotifyContractsLoaded); | ||
| StartCoroutine(CreateNetwork()); | ||
| } | ||
|
|
||
| public void OnDestroy() { | ||
| Log("Destroying"); | ||
| GameEvents.CommNet.OnNetworkInitialized.Remove(NetworkInitializedNotify); | ||
| GameEvents.CommNet.OnNetworkInitialized.Remove(AddPostUpdateHandler); | ||
| GameEvents.Contract.onAccepted.Remove(ReloadContractConnections); | ||
| GameEvents.Contract.onFinished.Remove(ReloadContractConnections); | ||
| GameEvents.Contract.onContractsLoaded.Remove(NotifyContractsLoaded); | ||
|
|
@@ -68,6 +70,18 @@ private void NetworkInitializedNotify() { | |
| Log("CommNet Network Initialization fired."); | ||
| } | ||
|
|
||
| private void AddPostUpdateHandler() { | ||
| ((RACommNetwork) RACommNetNetwork.Instance.CommNet).NetworkUpdateComplete.Add(PostUpdateHandler); | ||
| } | ||
|
|
||
| private void PostUpdateHandler() { | ||
| double network_last_ut = ((RACommNetwork) RACommNetNetwork.Instance.CommNet).LastUpdateUT; | ||
| if (network_last_ut > last_update_ut_) { | ||
| do_refresh_ = true; | ||
| last_update_ut_ = network_last_ut; | ||
| } | ||
| } | ||
|
Contributor
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. I would like to assume the duplicate cast and derefrences get JIT-compiled out. But maybe they don't, and it probably makes readability better to do: |
||
|
|
||
| private IEnumerator CreateNetwork() { | ||
| while (RACommNetScenario.RACN == null || !CommNet.CommNetNetwork.Initialized) { | ||
| yield return new UnityEngine.WaitForFixedUpdate(); | ||
|
|
@@ -180,7 +194,12 @@ private void FixedUpdate() { | |
| // Time does not advance in the VAB, but after a revert, it is incorrectly stuck in the past. | ||
| ut_ = Planetarium.GetUniversalTime(); | ||
| } | ||
| network?.Refresh(); | ||
|
|
||
| if (do_refresh_) { | ||
| do_refresh_ = false; // Unset now so that it can reset if RA updates while we're working. | ||
| network?.Refresh(); | ||
| } | ||
| network?.ConsumeElectricCharge(); | ||
| } | ||
|
|
||
| private void LateUpdate() { | ||
|
|
@@ -231,5 +250,7 @@ link.b is RACommNode node_b && | |
| private KSP.UI.Screens.ApplicationLauncherButton toolbar_button_; | ||
|
|
||
| internal RuntimeMetrics runtimeMetrics_ = new RuntimeMetrics(); | ||
| internal bool do_refresh_ = false; | ||
| private double last_update_ut_; | ||
| } | ||
| } | ||
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.
If you add, you typically need to Remove in
OnDestroyThere 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.
Oh, that explains the memory leak I saw. Fixed.