Multiplayer icon indicating copy to clipboard operation
Multiplayer copied to clipboard

Removed some code repetition, simplified forced pause/slowdown check

Open SokyranTheDragon opened this issue 2 years ago • 1 comments

Currently, to check if map/world is force paused down, you need to call ITickable.TickRateMultiplier(TimeSpeed) (with speed other than paused). The situation is similar with force slowed down, but you need to call the method twice with 2 different speeds and compare if they're equal. This is not the most intuitive way to do it, and is a bit wasteful as well.

The replacement I've introduced introduced 2 properties to ITickable - bool IsForcePaused and bool IsForceSlowdown. The checks for force pause/slowdown have been moved from ITickable.TickRateMultiplier to those properties instead, and they can now be accessed from other places.

A new method was added to the TickPatch class - GetForcedTickRate. The idea was to make a method method that can check if the tick rate is forcibly paused or slowed down. It does so by using the new properties instead of ITickable.TickRateMultiplier.

On top of the previously mentioned change to force pause/slowdown checking, this also includes following changes:

  • ColonistBarTimeControl.DrawButtons now uses the new property instead of checking the TickRateMultiplier, which skips force slowdown checks. Additionally, the check is now only done once instead of (potentially) twice.
  • TickPatch.TimePerTick now only calls ActualRateMultiplier once instead of twice.

SokyranTheDragon avatar Feb 04 '23 19:02 SokyranTheDragon

As a side note - this should, in theory, have better performance. I say in theory, as the performance gain from those changes is gonna be so small that it won't be noticeable.

The changes I've made here were mostly to simplify code (forced pause/slowdown), and reduce repeated calls.

SokyranTheDragon avatar Feb 04 '23 19:02 SokyranTheDragon