Refactor GameSpeed setting

*Remove internal GameSpeed defaults
 Enforce setting values explicitly all the time
 Require definition of a DefaultSpeed

*Remove Global.Timestep default

*Remove the hacky Timestep/OrderLatency setting via LobbyInfo

*Fix shellmaps ignoring mod-defined gamespeeds

*Make DateTimeGlobal use the MapOptions gamespeed
This commit is contained in:
reaperrr
2021-04-02 14:11:45 +02:00
committed by Paul Chote
parent fe129956bb
commit 1a9dfc0893
22 changed files with 214 additions and 205 deletions

View File

@@ -26,27 +26,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tlm = world.WorldActor.TraitOrDefault<TimeLimitManager>();
var startTick = Ui.LastTickTime;
Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != world.LobbyInfo.GlobalSettings.Timestep)
Func<bool> shouldShowStatus = () => (world.Paused || world.ReplayTimestep != world.Timestep)
&& (Ui.LastTickTime - startTick) / 1000 % 2 == 0;
Func<string> statusText = () =>
{
if (world.Paused || world.Timestep == 0)
if (world.Paused || world.ReplayTimestep == 0)
return "Paused";
if (world.Timestep == 1)
if (world.ReplayTimestep == 1)
return "Max Speed";
return "{0}% Speed".F(world.LobbyInfo.GlobalSettings.Timestep * 100 / world.Timestep);
return "{0}% Speed".F(world.Timestep * 100 / world.ReplayTimestep);
};
if (timer != null)
{
// Timers in replays should be synced to the effective game time, not the playback time.
var timestep = world.Timestep;
if (world.IsReplay)
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
timer.GetText = () =>
{
if (status == null && shouldShowStatus())
@@ -54,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var timeLimit = tlm?.TimeLimit ?? 0;
var displayTick = timeLimit > 0 ? timeLimit - world.WorldTick : world.WorldTick;
return WidgetUtils.FormatTime(Math.Max(0, displayTick), timestep);
return WidgetUtils.FormatTime(Math.Max(0, displayTick), world.Timestep);
};
}

View File

@@ -46,12 +46,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var originalTimestep = world.Timestep;
var pauseButton = widget.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.IsVisible = () => world.Timestep != 0 && orderManager.NetFrameNumber < replayNetTicks;
pauseButton.OnClick = () => world.Timestep = 0;
pauseButton.IsVisible = () => world.ReplayTimestep != 0 && orderManager.NetFrameNumber < replayNetTicks;
pauseButton.OnClick = () => world.ReplayTimestep = 0;
var playButton = widget.Get<ButtonWidget>("BUTTON_PLAY");
playButton.IsVisible = () => world.Timestep == 0 || orderManager.NetFrameNumber >= replayNetTicks;
playButton.OnClick = () => world.Timestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
playButton.IsVisible = () => world.ReplayTimestep == 0 || orderManager.NetFrameNumber >= replayNetTicks;
playButton.OnClick = () => world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
playButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
var slowButton = widget.Get<ButtonWidget>("BUTTON_SLOW");
@@ -60,8 +60,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
slowButton.OnClick = () =>
{
speed = PlaybackSpeed.Slow;
if (world.Timestep != 0)
world.Timestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
if (world.ReplayTimestep != 0)
world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
};
var normalSpeedButton = widget.Get<ButtonWidget>("BUTTON_REGULAR");
@@ -70,8 +70,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
normalSpeedButton.OnClick = () =>
{
speed = PlaybackSpeed.Regular;
if (world.Timestep != 0)
world.Timestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
if (world.ReplayTimestep != 0)
world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
};
var fastButton = widget.Get<ButtonWidget>("BUTTON_FAST");
@@ -80,8 +80,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
fastButton.OnClick = () =>
{
speed = PlaybackSpeed.Fast;
if (world.Timestep != 0)
world.Timestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
if (world.ReplayTimestep != 0)
world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
};
var maximumButton = widget.Get<ButtonWidget>("BUTTON_MAXIMUM");
@@ -90,8 +90,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
maximumButton.OnClick = () =>
{
speed = PlaybackSpeed.Maximum;
if (world.Timestep != 0)
world.Timestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
if (world.ReplayTimestep != 0)
world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]);
};
}
}