freezy / VisualPinball.Engine

:video_game: Visual Pinball Engine for Unity
https://docs.visualpinball.org
GNU General Public License v3.0
415 stars 62 forks source link

Fix editor performance #353

Closed jsm174 closed 2 years ago

jsm174 commented 2 years ago

Currently, the Lamp/Switch/Coil/Wire managers are refreshed during gameplay using:

#if UNITY_EDITOR
   UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
#endif

@Pandelii noticed a huge performance hit and after debugging, this was the culprit.

This PR adds a new Update During Gameplaysetting to the Player component that is defaulted true. When this is enabled and a switch, coil, or lamp is updated, we will look for any open corresponding managers, and call the repaint method. (note, there can be multiple of the same manager windows open)

We also do the same for the TroughInspector and CoilDevice.

This PR also does the following:

freezy commented 2 years ago

image

Niiice! Thanks for that!

freezy commented 2 years ago

Would it be easy to make this toggleable during gameplay? Right now it seems you need to stop, toggle, and start, to get the effect.

codecov[bot] commented 2 years ago

Codecov Report

Merging #353 (1cea646) into master (ca3b34c) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #353   +/-   ##
=======================================
  Coverage   83.91%   83.91%           
=======================================
  Files         125      125           
  Lines        6741     6741           
=======================================
  Hits         5657     5657           
  Misses       1084     1084           
Impacted Files Coverage Δ
...Pinball.Engine/Game/Engines/GamelogicEngineLamp.cs 73.68% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9a855fb...1cea646. Read the comment docs.

jsm174 commented 2 years ago

Would it be easy to make this toggleable during gameplay? Right now it seems you need to stop, toggle, and start, to get the effect.

Cool. I renamed all the Repaint* methods to RefreshUI and put a check inside for _player.UpdateDuringGameplay. This allow the flag to be toggled during gameplay.