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]);
};
}
}

View File

@@ -27,7 +27,6 @@ namespace OpenRA.Mods.Common.Widgets
public Func<Player> GetPlayer;
readonly World world;
readonly WorldRenderer worldRenderer;
readonly int timestep;
public int IconWidth = 32;
public int IconHeight = 24;
@@ -56,7 +55,6 @@ namespace OpenRA.Mods.Common.Widgets
this.world = world;
this.worldRenderer = worldRenderer;
clocks = new Dictionary<ProductionQueue, Animation>();
timestep = world.IsReplay ? world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep : world.Timestep;
GetTooltipIcon = () => TooltipIcon;
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
@@ -69,7 +67,6 @@ namespace OpenRA.Mods.Common.Widgets
GetPlayer = other.GetPlayer;
world = other.world;
worldRenderer = other.worldRenderer;
timestep = other.timestep;
clocks = other.clocks;
IconWidth = other.IconWidth;
@@ -198,7 +195,7 @@ namespace OpenRA.Mods.Common.Widgets
foreach (var icon in productionIcons)
{
var current = icon.Queued.First();
var text = GetOverlayForItem(current, timestep);
var text = GetOverlayForItem(current, world.Timestep);
tiny.DrawTextWithContrast(text,
icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);

View File

@@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Widgets
readonly World world;
readonly WorldRenderer worldRenderer;
readonly Dictionary<string, Animation> clocks;
readonly int timestep;
readonly Lazy<TooltipContainerWidget> tooltipContainer;
@@ -55,11 +54,6 @@ namespace OpenRA.Mods.Common.Widgets
this.worldRenderer = worldRenderer;
clocks = new Dictionary<string, Animation>();
// Timers in replays should be synced to the effective game time, not the playback time.
timestep = world.Timestep;
if (world.IsReplay)
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
@@ -72,7 +66,6 @@ namespace OpenRA.Mods.Common.Widgets
world = other.world;
worldRenderer = other.worldRenderer;
clocks = other.clocks;
timestep = other.timestep;
IconWidth = other.IconWidth;
IconHeight = other.IconHeight;
@@ -146,7 +139,7 @@ namespace OpenRA.Mods.Common.Widgets
var tiny = Game.Renderer.Fonts["Tiny"];
foreach (var icon in supportPowerIconsIcons)
{
var text = GetOverlayForItem(icon.Power, timestep);
var text = GetOverlayForItem(icon.Power, world.Timestep);
tiny.DrawTextWithContrast(text,
icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1);

View File

@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.Widgets
public readonly TextAlign Align = TextAlign.Left;
public readonly TimerOrder Order = TimerOrder.Descending;
readonly int timestep;
readonly IEnumerable<SupportPowerInstance> powers;
readonly Color bgDark, bgLight;
(string Text, Color Color)[] texts;
@@ -38,11 +37,6 @@ namespace OpenRA.Mods.Common.Widgets
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimerRelationships != PlayerRelationship.None && !p.Disabled);
// Timers in replays should be synced to the effective game time, not the playback time.
timestep = world.Timestep;
if (world.IsReplay)
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
bgDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
bgLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
}
@@ -58,9 +52,9 @@ namespace OpenRA.Mods.Common.Widgets
texts = displayedPowers.Select(p =>
{
var time = WidgetUtils.FormatTime(p.RemainingTicks, false, timestep);
var text = Format.F(p.Info.Description, time);
var self = p.Instances[0].Self;
var time = WidgetUtils.FormatTime(p.RemainingTicks, false, self.World.Timestep);
var text = Format.F(p.Info.Description, time);
var playerColor = self.Owner.Color;
if (Game.Settings.Game.UsePlayerStanceColors)