diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index be44b976a0..f0b61be1e6 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -73,7 +73,8 @@ namespace OpenRA public static int RenderFrame = 0; public static int NetFrameNumber { get { return orderManager.NetFrameNumber; } } public static int LocalTick { get { return orderManager.LocalFrameNumber; } } - public const int NetTickScale = 3; // 120ms net tick for 40ms local tick + public const int NetTickScale = 3; // 120ms net tick for 40ms local tick + public const int Timestep = 40; public static event Action ConnectionStateChanged = _ => { }; static ConnectionState lastConnectionState = ConnectionState.PreConnecting; @@ -224,6 +225,7 @@ namespace OpenRA var map = modData.PrepareMap(mapUID); orderManager.world = new World(modData.Manifest, map, orderManager, isShellmap); + orderManager.world.Timestep = Timestep; worldRenderer = new WorldRenderer(orderManager.world); orderManager.world.LoadComplete(worldRenderer); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index fc228d25dd..b0970f43d1 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -200,7 +200,6 @@ - diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index 161fbb705e..131c915d7c 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -37,8 +37,8 @@ namespace OpenRA if (filename.ToLowerInvariant().EndsWith("wav")) return LoadWave(new WavLoader(FileSystem.Open(filename))); - else - return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename))); + + return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename))); } static ISoundSource LoadWave(WavLoader wave) @@ -55,12 +55,12 @@ namespace OpenRA { engine = Game.Settings.Server.Dedicated ? "Null" : engine; switch (engine) - { /* TODO: if someone cares about pluggable crap here, ship this out */ + { case "AL": return new OpenAlSoundEngine(); case "Null": return new NullSoundEngine(); default: - throw new InvalidOperationException("Unsupported sound engine: {0}".F (engine)); + throw new InvalidOperationException("Unsupported sound engine: {0}".F(engine)); } } @@ -79,23 +79,26 @@ namespace OpenRA public static SoundDevice[] AvailableDevices() { - var defaultDevices = new [] + var defaultDevices = new[] { new SoundDevice("AL", null, "Default Output"), new SoundDevice("Null", null, "Output Disabled") }; - var alDevices = OpenAlSoundEngine.AvailableDevices() + var devices = OpenAlSoundEngine.AvailableDevices() .Select(d => new SoundDevice("AL", d, d)); - return defaultDevices.Concat(alDevices).ToArray(); + return defaultDevices.Concat(devices).ToArray(); } - public static void SetListenerPosition(WPos position) { soundEngine.SetListenerPosition(position); } + public static void SetListenerPosition(WPos position) + { + soundEngine.SetListenerPosition(position); + } static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier) { - if (String.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(name)) return null; if (player != null && player != player.World.LocalPlayer) return null; @@ -142,11 +145,11 @@ namespace OpenRA if (MusicPlaying && !music.Playing) { StopMusic(); - OnMusicComplete(); + onMusicComplete(); } } - static Action OnMusicComplete; + static Action onMusicComplete; public static bool MusicPlaying { get; private set; } public static MusicInfo CurrentMusic { get { return currentMusic; } } @@ -160,7 +163,7 @@ namespace OpenRA if (m == null || !m.Exists) return; - OnMusicComplete = then; + onMusicComplete = then; if (m == currentMusic && music != null) { @@ -168,6 +171,7 @@ namespace OpenRA MusicPlaying = true; return; } + StopMusic(); var sound = sounds[m.Filename]; @@ -183,6 +187,7 @@ namespace OpenRA { if (music == null) return; + MusicPlaying = true; soundEngine.PauseSound(music, false); } @@ -220,7 +225,11 @@ namespace OpenRA static float soundVolumeModifier = 1.0f; public static float SoundVolumeModifier { - get { return soundVolumeModifier; } + get + { + return soundVolumeModifier; + } + set { soundVolumeModifier = value; @@ -231,7 +240,11 @@ namespace OpenRA static float InternalSoundVolume { get { return SoundVolume * soundVolumeModifier; } } public static float SoundVolume { - get { return Game.Settings.Sound.SoundVolume; } + get + { + return Game.Settings.Sound.SoundVolume; + } + set { Game.Settings.Sound.SoundVolume = value; @@ -241,7 +254,11 @@ namespace OpenRA public static float MusicVolume { - get { return Game.Settings.Sound.MusicVolume; } + get + { + return Game.Settings.Sound.MusicVolume; + } + set { Game.Settings.Sound.MusicVolume = value; @@ -252,7 +269,11 @@ namespace OpenRA public static float VideoVolume { - get { return Game.Settings.Sound.VideoVolume; } + get + { + return Game.Settings.Sound.VideoVolume; + } + set { Game.Settings.Sound.VideoVolume = value; @@ -263,25 +284,28 @@ namespace OpenRA public static float MusicSeekPosition { - get { return (music != null) ? music.SeekPosition : 0; } + get { return music != null ? music.SeekPosition : 0; } } public static float VideoSeekPosition { - get { return (video != null) ? video.SeekPosition : 0; } + get { return video != null ? video.SeekPosition : 0; } } // Returns true if played successfully public static bool PlayPredefined(Player p, Actor voicedUnit, string type, string definition, string variant, bool attenuateVolume) { - if (definition == null) return false; + if (definition == null) + return false; + + if (Rules.Voices == null || Rules.Notifications == null) + return false; - if (Rules.Voices == null) return false; - if (Rules.Notifications == null) return false; var rules = (voicedUnit != null) ? Rules.Voices[type] : Rules.Notifications[type]; - if (rules == null) return false; + if (rules == null) + return false; - var ID = (voicedUnit != null) ? voicedUnit.ActorID : 0; + var id = voicedUnit != null ? voicedUnit.ActorID : 0; string clip; var suffix = rules.DefaultVariant; @@ -308,19 +332,20 @@ namespace OpenRA clip = rules.NotificationsPools.Value[definition].GetNext(); } - if (String.IsNullOrEmpty(clip)) return false; + if (string.IsNullOrEmpty(clip)) + return false; if (variant != null) { if (rules.Variants.ContainsKey(variant) && !rules.DisableVariants.Contains(definition)) - suffix = rules.Variants[variant][ID % rules.Variants[variant].Length]; + suffix = rules.Variants[variant][id % rules.Variants[variant].Length]; if (rules.Prefixes.ContainsKey(variant) && !rules.DisablePrefixes.Contains(definition)) - prefix = rules.Prefixes[variant][ID % rules.Prefixes[variant].Length]; + prefix = rules.Prefixes[variant][id % rules.Prefixes[variant].Length]; } var name = prefix + clip + suffix; - if (!String.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) + if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) soundEngine.Play2D(sounds[name], false, true, WPos.Zero, InternalSoundVolume, attenuateVolume); @@ -330,22 +355,21 @@ namespace OpenRA public static bool PlayVoice(string phrase, Actor voicedUnit, string variant) { - if (voicedUnit == null) return false; - if (phrase == null) return false; + if (voicedUnit == null || phrase == null) + return false; var mi = voicedUnit.Info.Traits.GetOrDefault(); - if (mi == null) return false; - if (mi.Voice == null) return false; + if (mi == null || mi.Voice == null) + return false; var type = mi.Voice.ToLowerInvariant(); - return PlayPredefined(null, voicedUnit, type, phrase, variant, true); } public static bool PlayNotification(Player player, string type, string notification, string variant) { - if (type == null) return false; - if (notification == null) return false; + if (type == null || notification == null) + return false; return PlayPredefined(player, null, type.ToLowerInvariant(), notification, variant, false); } @@ -395,16 +419,20 @@ namespace OpenRA { class PoolSlot { - public bool isActive; - public int frameStarted; - public WPos pos; - public bool isRelative; - public ISoundSource sound; + public bool IsActive; + public int FrameStarted; + public WPos Pos; + public bool IsRelative; + public ISoundSource Sound; } + const int MaxInstancesPerFrame = 3; + const int GroupDistance = 2730; + const int GroupDistanceSqr = GroupDistance * GroupDistance; + const int PoolSize = 32; + float volume = 1f; Dictionary sourcePool = new Dictionary(); - const int POOL_SIZE = 32; static string[] QueryDevices(string label, int type) { @@ -415,7 +443,7 @@ namespace OpenRA if (Al.alGetError() != Al.AL_NO_ERROR) { Log.Write("sound", "Failed to query OpenAL device list using {0}", label); - return new string[] {}; + return new string[] { }; } return devices; @@ -430,7 +458,7 @@ namespace OpenRA if (Alc.alcIsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT") == Alc.ALC_TRUE) return QueryDevices("ALC_ENUMERATION_EXT", Alc.ALC_DEVICE_SPECIFIER); - return new string[] {}; + return new string[] { }; } public OpenAlSoundEngine() @@ -456,7 +484,7 @@ namespace OpenRA throw new InvalidOperationException("Can't create OpenAL context"); Alc.alcMakeContextCurrent(ctx); - for (var i = 0; i < POOL_SIZE; i++) + for (var i = 0; i < PoolSize; i++) { var source = 0; Al.alGenSources(1, out source); @@ -466,7 +494,7 @@ namespace OpenRA return; } - sourcePool.Add(source, new PoolSlot() { isActive = false }); + sourcePool.Add(source, new PoolSlot() { IsActive = false }); } } @@ -474,9 +502,9 @@ namespace OpenRA { foreach (var kvp in sourcePool) { - if (!kvp.Value.isActive) + if (!kvp.Value.IsActive) { - sourcePool[kvp.Key].isActive = true; + sourcePool[kvp.Key].IsActive = true; return kvp.Key; } } @@ -494,9 +522,9 @@ namespace OpenRA return -1; foreach (int i in freeSources) - sourcePool[i].isActive = false; + sourcePool[i].IsActive = false; - sourcePool[freeSources[0]].isActive = true; + sourcePool[freeSources[0]].IsActive = true; return freeSources[0]; } @@ -506,10 +534,6 @@ namespace OpenRA return new OpenAlSoundSource(data, channels, sampleBits, sampleRate); } - const int maxInstancesPerFrame = 3; - const int groupDistance = 2730; - const int groupDistanceSqr = groupDistance * groupDistance; - public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { if (sound == null) @@ -518,9 +542,8 @@ namespace OpenRA return null; } - var world = Game.orderManager.world; - int currFrame = world != null ? world.FrameNumber : 0; - float atten = 1f; + var currFrame = Game.orderManager.LocalFrameNumber; + var atten = 1f; // Check if max # of instances-per-location reached: if (attenuateVolume) @@ -528,40 +551,41 @@ namespace OpenRA int instances = 0, activeCount = 0; foreach (var s in sourcePool.Values) { - if (!s.isActive) + if (!s.IsActive) continue; - if (s.isRelative != relative) + if (s.IsRelative != relative) continue; ++activeCount; - if (s.sound != sound) + if (s.Sound != sound) continue; - if (currFrame - s.frameStarted >= 5) + if (currFrame - s.FrameStarted >= 5) continue; // Too far away to count? - var lensqr = (s.pos - pos).LengthSquared; - if (lensqr >= groupDistanceSqr) + var lensqr = (s.Pos - pos).LengthSquared; + if (lensqr >= GroupDistanceSqr) continue; // If we are starting too many instances of the same sound within a short time then stop this one: - if (++instances == maxInstancesPerFrame) + if (++instances == MaxInstancesPerFrame) return null; } // Attenuate a little bit based on number of active sounds: - atten = 0.66f * ((POOL_SIZE - activeCount * 0.5f) / POOL_SIZE); + atten = 0.66f * ((PoolSize - activeCount * 0.5f) / PoolSize); } - int source = GetSourceFromPool(); - if (source == -1) return null; + var source = GetSourceFromPool(); + if (source == -1) + return null; var slot = sourcePool[source]; - slot.pos = pos; - slot.frameStarted = currFrame; - slot.sound = sound; - slot.isRelative = relative; - return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume * atten); + slot.Pos = pos; + slot.FrameStarted = currFrame; + slot.Sound = sound; + slot.IsRelative = relative; + return new OpenAlSound(source, (sound as OpenAlSoundSource).Buffer, loop, relative, pos, volume * atten); } public float Volume @@ -575,7 +599,7 @@ namespace OpenRA if (sound == null) return; - int key = ((OpenAlSound)sound).source; + var key = ((OpenAlSound)sound).Source; int state; Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state); if (state == Al.AL_PLAYING && paused) @@ -586,7 +610,7 @@ namespace OpenRA public void SetAllSoundsPaused(bool paused) { - foreach (int key in sourcePool.Keys) + foreach (var key in sourcePool.Keys) { int state; Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state); @@ -603,21 +627,21 @@ namespace OpenRA { int state; Al.alGetSourcei(b, Al.AL_SOURCE_STATE, out state); - return ((state == Al.AL_PLAYING || state == Al.AL_PAUSED) && - ((music == null) || b != ((OpenAlSound)music).source) && - ((video == null) || b != ((OpenAlSound)video).source)); - }).ToList(); + return (state == Al.AL_PLAYING || state == Al.AL_PAUSED) && + (music == null || b != ((OpenAlSound)music).Source) && + (video == null || b != ((OpenAlSound)video).Source); + }); + foreach (var s in sounds) - { Al.alSourcef(s, Al.AL_GAIN, volume); - } } public void StopSound(ISound sound) { - if (sound == null) return; + if (sound == null) + return; - int key = ((OpenAlSound)sound).source; + var key = ((OpenAlSound)sound).Source; int state; Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state); if (state == Al.AL_PLAYING || state == Al.AL_PAUSED) @@ -626,7 +650,7 @@ namespace OpenRA public void StopAllSounds() { - foreach (int key in sourcePool.Keys) + foreach (var key in sourcePool.Keys) { int state; Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state); @@ -648,7 +672,7 @@ namespace OpenRA class OpenAlSoundSource : ISoundSource { - public readonly int buffer; + public readonly int Buffer; static int MakeALFormat(int channels, int bits) { @@ -660,22 +684,25 @@ namespace OpenRA public OpenAlSoundSource(byte[] data, int channels, int sampleBits, int sampleRate) { - Al.alGenBuffers(1, out buffer); - Al.alBufferData(buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate); + Al.alGenBuffers(1, out Buffer); + Al.alBufferData(Buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate); } } class OpenAlSound : ISound { - public readonly int source = -1; + public readonly int Source = -1; float volume = 1f; public OpenAlSound(int source, int buffer, bool looping, bool relative, WPos pos, float volume) { - if (source == -1) return; - this.source = source; - Al.alSourcef(source, Al.AL_PITCH, 1f); + if (source == -1) + return; + + Source = source; Volume = volume; + + Al.alSourcef(source, Al.AL_PITCH, 1f); Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, pos.Z); Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f); Al.alSourcei(source, Al.AL_BUFFER, buffer); @@ -689,11 +716,15 @@ namespace OpenRA public float Volume { - get { return volume; } + get + { + return volume; + } + set { - if (source != -1) - Al.alSourcef(source, Al.AL_GAIN, volume = value); + if (Source != -1) + Al.alSourcef(Source, Al.AL_GAIN, volume = value); } } @@ -702,7 +733,7 @@ namespace OpenRA get { float pos; - Al.alGetSourcef(source, Al.AL_SAMPLE_OFFSET, out pos); + Al.alGetSourcef(Source, Al.AL_SAMPLE_OFFSET, out pos); return pos / 22050f; } } @@ -712,7 +743,7 @@ namespace OpenRA get { int state; - Al.alGetSourcei(source, Al.AL_SOURCE_STATE, out state); + Al.alGetSourcei(Source, Al.AL_SOURCE_STATE, out state); return state == Al.AL_PLAYING; } } @@ -735,17 +766,17 @@ namespace OpenRA return new NullSound(); } - public void PauseSound(ISound sound, bool paused) {} - public void StopSound(ISound sound) {} - public void SetAllSoundsPaused(bool paused) {} - public void StopAllSounds() {} - public void SetListenerPosition(WPos position) {} - public void SetSoundVolume(float volume, ISound music, ISound video) {} + public void PauseSound(ISound sound, bool paused) { } + public void StopSound(ISound sound) { } + public void SetAllSoundsPaused(bool paused) { } + public void StopAllSounds() { } + public void SetListenerPosition(WPos position) { } + public void SetSoundVolume(float volume, ISound music, ISound video) { } public float Volume { get; set; } } - class NullSoundSource : ISoundSource {} + class NullSoundSource : ISoundSource { } class NullSound : ISound { diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 30e71b7bfa..8c8665a15e 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -61,7 +61,7 @@ namespace OpenRA.Traits void Invalidate() { - Hash = Sync.hash_player(self.Owner) + self.World.FrameNumber * 3; + Hash = Sync.hash_player(self.Owner) + self.World.WorldTick * 3; } static IEnumerable FindVisibleTiles(World world, CPos position, WRange radius) diff --git a/OpenRA.Game/Widgets/TimerWidget.cs b/OpenRA.Game/Widgets/TimerWidget.cs deleted file mode 100644 index 9a63adf860..0000000000 --- a/OpenRA.Game/Widgets/TimerWidget.cs +++ /dev/null @@ -1,36 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Drawing; -using OpenRA.FileFormats; -using OpenRA.Graphics; - -namespace OpenRA.Widgets -{ - public class TimerWidget : LabelWidget - { - public override void Draw() - { - var font = Game.Renderer.Fonts[Font]; - var rb = RenderBounds; - var color = GetColor(); - var contrast = GetContrastColor(); - - var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":""); - var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top); - if (Contrast) - font.DrawTextWithContrast(s, pos, color, contrast, 1); - else - font.DrawText(s, pos, color); - } - } -} - diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 462fe8e82d..d9201f5aa9 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -30,7 +30,7 @@ namespace OpenRA List effects = new List(); Queue> frameEndActions = new Queue>(); - public int FrameNumber { get { return orderManager.LocalFrameNumber; } } + public int Timestep; internal readonly OrderManager orderManager; public Session LobbyInfo { get { return orderManager.LobbyInfo; } } @@ -190,6 +190,7 @@ namespace OpenRA public bool PredictedPaused { get; internal set; } public bool PauseStateLocked { get; set; } public bool IsShellmap = false; + public int WorldTick { get; private set; } public void SetPauseState(bool paused) { @@ -209,6 +210,8 @@ namespace OpenRA { if (!Paused && (!IsShellmap || Game.Settings.Game.ShowShellmap)) { + WorldTick++; + using (new PerfSample("tick_idle")) foreach (var ni in ActorsWithTrait()) if (ni.Actor.IsIdle) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs index a3876179fa..266515e2b6 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS"); shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap; - shellmapDecorations.Get("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0; + shellmapDecorations.Get("RECBLOCK").IsVisible = () => world.WorldTick / 25 % 2 == 0; var shellmapDisabledDecorations = widget.Get("SHELLMAP_DISABLED_DECORATIONS"); shellmapDisabledDecorations.IsVisible = () => !Game.Settings.Game.ShowShellmap; diff --git a/OpenRA.Mods.RA/Activities/DeliverResources.cs b/OpenRA.Mods.RA/Activities/DeliverResources.cs index 00fedd3efa..80faea03ff 100755 --- a/OpenRA.Mods.RA/Activities/DeliverResources.cs +++ b/OpenRA.Mods.RA/Activities/DeliverResources.cs @@ -34,10 +34,10 @@ namespace OpenRA.Mods.RA.Activities { // Maybe we lost the owner-linked refinery: harv.OwnerLinkedProc = null; - if (self.World.FrameNumber - chosenTicks > NextChooseTime) + if (self.World.WorldTick - chosenTicks > NextChooseTime) { harv.ChooseNewProc(self, null); - chosenTicks = self.World.FrameNumber; + chosenTicks = self.World.WorldTick; } } else diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index 3ea2d44632..24d37eef9d 100755 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -49,8 +49,8 @@ namespace OpenRA.Mods.RA.Move var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.actor == self); if (cached != null) { - Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick); - if (world.FrameNumber - cached.tick > MaxPathAge) + Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.WorldTick - cached.tick); + if (world.WorldTick - cached.tick > MaxPathAge) CachedPaths.Remove(cached); return new List(cached.result); } @@ -73,8 +73,8 @@ namespace OpenRA.Mods.RA.Move CheckSanePath2(pb, from, target); - CachedPaths.RemoveAll(p => world.FrameNumber - p.tick > MaxPathAge); - CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.FrameNumber }); + CachedPaths.RemoveAll(p => world.WorldTick - p.tick > MaxPathAge); + CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.WorldTick }); return new List(pb); } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 0d30d9f469..4e19ed923b 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -479,6 +479,8 @@ + + diff --git a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs index a905455cb7..8a9b02d40f 100644 --- a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0) return; - if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25) + if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25) { Sound.PlayNotification(self.Owner, "Speech", "BaseAttack", self.Owner.Country.Race); @@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA radarPings.Add(() => self.Owner == self.World.LocalPlayer, self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); } - lastAttackTime = self.World.FrameNumber; + lastAttackTime = self.World.WorldTick; } } } diff --git a/OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs b/OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs index 29e773592a..24d8190afc 100644 --- a/OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs +++ b/OpenRA.Mods.RA/Player/HarvesterAttackNotifier.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA if (e.Attacker != null && e.Attacker.Owner == self.Owner) return; - if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25) + if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25) { Sound.PlayNotification(self.Owner, "Speech", "HarvesterAttack", self.Owner.Country.Race); @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA radarPings.Add(() => self.Owner == self.World.LocalPlayer, self.CenterPosition, info.RadarPingColor, info.RadarPingDuration); } - lastAttackTime = self.World.FrameNumber; + lastAttackTime = self.World.WorldTick; } } } diff --git a/OpenRA.Mods.RA/Player/PlayerStatistics.cs b/OpenRA.Mods.RA/Player/PlayerStatistics.cs index 5779954e5f..23550375cd 100644 --- a/OpenRA.Mods.RA/Player/PlayerStatistics.cs +++ b/OpenRA.Mods.RA/Player/PlayerStatistics.cs @@ -73,9 +73,9 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - if (self.World.FrameNumber % 1500 == 1) + if (self.World.WorldTick % 1500 == 1) UpdateEarnedThisMinute(); - if (self.World.FrameNumber % 250 == 0) + if (self.World.WorldTick % 250 == 0) UpdateMapControl(); } diff --git a/OpenRA.Mods.RA/ScaredyCat.cs b/OpenRA.Mods.RA/ScaredyCat.cs index 33a536c1dc..aafaa535b7 100644 --- a/OpenRA.Mods.RA/ScaredyCat.cs +++ b/OpenRA.Mods.RA/ScaredyCat.cs @@ -40,14 +40,14 @@ namespace OpenRA.Mods.RA { if (!Panicking) Self.CancelActivity(); - PanicStartedTick = Self.World.FrameNumber; + PanicStartedTick = Self.World.WorldTick; } public void Tick(Actor self) { if (!Panicking) return; - if (self.World.FrameNumber >= PanicStartedTick + Info.PanicLength) + if (self.World.WorldTick >= PanicStartedTick + Info.PanicLength) { self.CancelActivity(); PanicStartedTick = 0; diff --git a/OpenRA.Mods.RA/Widgets/Logic/GameTimerLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/GameTimerLogic.cs new file mode 100644 index 0000000000..a2e6a87b1f --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/GameTimerLogic.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Network; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets.Logic +{ + public class GameTimerLogic + { + [ObjectCreator.UseCtor] + public GameTimerLogic(Widget widget, OrderManager orderManager, World world) + { + var timer = widget.GetOrNull("GAME_TIMER"); + if (timer != null) + timer.GetText = () => WidgetUtils.FormatTime(world.WorldTick); + + var status = widget.GetOrNull("GAME_TIMER_STATUS"); + if (status != null) + { + // Blink the status line + status.IsVisible = () => (world.Paused || world.Timestep != Game.Timestep) + && orderManager.LocalFrameNumber / 25 % 2 == 0; + + status.GetText = () => + { + if (world.Paused || world.Timestep == 0) + return "Paused"; + + if (world.Timestep == 1) + return "Max Speed"; + + return "{0:F1}x Speed".F(Game.Timestep * 1f / world.Timestep); + }; + } + } + } +} diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index bd39887338..ad24f1ccf2 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -291,7 +291,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { statusCheckbox.IsHighlighted = () => !statusCheckbox.IsChecked() && orderManager.LobbyInfo.FirstEmptySlot() == null && - world.FrameNumber / 25 % 2 == 0; + orderManager.LocalFrameNumber / 25 % 2 == 0; } // Options panel diff --git a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs index b70d656afe..c34ee8cf1b 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ObserverStatsLogic.cs @@ -285,12 +285,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic string AverageOrdersPerMinute(double orders) { - return (world.FrameNumber == 0 ? 0 : orders / (world.FrameNumber / 1500.0)).ToString("F1"); + return (world.WorldTick == 0 ? 0 : orders / (world.WorldTick / 1500.0)).ToString("F1"); } string AverageEarnedPerMinute(double earned) { - return "$" + (world.FrameNumber == 0 ? 0 : earned / (world.FrameNumber / 1500.0)).ToString("F2"); + return "$" + (world.WorldTick == 0 ? 0 : earned / (world.WorldTick / 1500.0)).ToString("F2"); } static Color GetPowerColor(PowerState state) diff --git a/OpenRA.Mods.RA/World/PathfinderDebugOverlay.cs b/OpenRA.Mods.RA/World/PathfinderDebugOverlay.cs index 7a4ba1f35b..ea7efa424b 100644 --- a/OpenRA.Mods.RA/World/PathfinderDebugOverlay.cs +++ b/OpenRA.Mods.RA/World/PathfinderDebugOverlay.cs @@ -56,8 +56,8 @@ namespace OpenRA.Mods.RA return; var qr = Game.Renderer.WorldQuadRenderer; - var doDim = refreshTick - world.FrameNumber <= 0; - if (doDim) refreshTick = world.FrameNumber + 20; + var doDim = refreshTick - world.WorldTick <= 0; + if (doDim) refreshTick = world.WorldTick + 20; var viewBounds = wr.Viewport.CellBounds; foreach (var pair in layers) diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 3e6182850b..719d7e8a8f 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -3,11 +3,25 @@ Container@INGAME_ROOT: Children: LogicTicker@DISCONNECT_WATCHER: Logic:DisconnectWatcherLogic - Timer@GAME_TIMER: - X: WINDOW_RIGHT/2 - Y: 0 - Font: Title - Contrast: true + Container@GAME_TIMER_BLOCK: + Logic:GameTimerLogic + X:WINDOW_RIGHT/2 - WIDTH + Width:100 + Height:55 + Children: + Label@GAME_TIMER: + Width:PARENT_RIGHT + Height:30 + Align:Center + Font:Title + Contrast:true + Label@GAME_TIMER_STATUS: + Y:35 + Width:PARENT_RIGHT + Height:15 + Align:Center + Font:Bold + Contrast:true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 diff --git a/mods/d2k/chrome/ingame.yaml b/mods/d2k/chrome/ingame.yaml index 177cce6a79..191fa3280c 100644 --- a/mods/d2k/chrome/ingame.yaml +++ b/mods/d2k/chrome/ingame.yaml @@ -19,11 +19,25 @@ Container@INGAME_ROOT: Y:0 Width:WINDOW_RIGHT Height:WINDOW_BOTTOM - Timer@GAME_TIMER: - X: WINDOW_RIGHT/2 - Y: 0 - Font: Title - Contrast: true + Container@GAME_TIMER_BLOCK: + Logic:GameTimerLogic + X:WINDOW_RIGHT/2 - WIDTH + Width:100 + Height:55 + Children: + Label@GAME_TIMER: + Width:PARENT_RIGHT + Height:30 + Align:Center + Font:Title + Contrast:true + Label@GAME_TIMER_STATUS: + Y:32 + Width:PARENT_RIGHT + Height:15 + Align:Center + Font:Bold + Contrast:true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 2700640889..c16e160d3e 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -19,11 +19,25 @@ Container@INGAME_ROOT: Y:0 Width:WINDOW_RIGHT Height:WINDOW_BOTTOM - Timer@GAME_TIMER: - X: WINDOW_RIGHT/2 - Y: 0-10 - Font: Title - Contrast: true + Container@GAME_TIMER_BLOCK: + Logic:GameTimerLogic + X:WINDOW_RIGHT/2 - WIDTH + Width:100 + Height:55 + Children: + Label@GAME_TIMER: + Width:PARENT_RIGHT + Height:15 + Align:Center + Font:Title + Contrast:true + Label@GAME_TIMER_STATUS: + Y:35 + Width:PARENT_RIGHT + Height:15 + Align:Center + Font:Bold + Contrast:true StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40