diff --git a/OpenRA.Game/Graphics/Video.cs b/OpenRA.Game/Graphics/Video.cs index 60e60d19ad..0fc9855199 100644 --- a/OpenRA.Game/Graphics/Video.cs +++ b/OpenRA.Game/Graphics/Video.cs @@ -22,7 +22,7 @@ namespace OpenRA.Video /// Current frame color data in 32-bit BGRA. /// byte[] CurrentFrameData { get; } - int CurrentFrameNumber { get; } + int CurrentFrameIndex { get; } void AdvanceFrame(); bool HasAudio { get; } diff --git a/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs b/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs index cf61f94445..640155e42e 100644 --- a/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs +++ b/OpenRA.Mods.Cnc/FileFormats/VqaVideo.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public ushort Height { get; } public byte[] CurrentFrameData { get; } - public int CurrentFrameNumber { get; private set; } + public int CurrentFrameIndex { get; private set; } public bool HasAudio { get; set; } public byte[] AudioData { get; private set; } // audio for this frame: 22050Hz 16bit mono pcm, uncompressed. @@ -163,7 +163,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public void Reset() { - CurrentFrameNumber = chunkBufferOffset = currentChunkBuffer = 0; + CurrentFrameIndex = chunkBufferOffset = currentChunkBuffer = 0; LoadFrame(); } @@ -260,18 +260,18 @@ namespace OpenRA.Mods.Cnc.FileFormats public void AdvanceFrame() { - CurrentFrameNumber++; + CurrentFrameIndex++; LoadFrame(); } void LoadFrame() { - if (CurrentFrameNumber >= FrameCount) + if (CurrentFrameIndex >= FrameCount) return; // Seek to the start of the frame - stream.Seek(offsets[CurrentFrameNumber], SeekOrigin.Begin); - var end = (CurrentFrameNumber < FrameCount - 1) ? offsets[CurrentFrameNumber + 1] : stream.Length; + stream.Seek(offsets[CurrentFrameIndex], SeekOrigin.Begin); + var end = (CurrentFrameIndex < FrameCount - 1) ? offsets[CurrentFrameIndex + 1] : stream.Length; while (stream.Position < end) { diff --git a/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs b/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs index f9f9006305..495ea94950 100644 --- a/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs +++ b/OpenRA.Mods.Cnc/FileFormats/WsaVideo.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public ushort Height { get; } public byte[] CurrentFrameData { get; } - public int CurrentFrameNumber { get; private set; } + public int CurrentFrameIndex { get; private set; } public bool HasAudio => false; public byte[] AudioData => null; @@ -99,7 +99,7 @@ namespace OpenRA.Mods.Cnc.FileFormats public void Reset() { - CurrentFrameNumber = 0; + CurrentFrameIndex = 0; previousFramePaletteIndexData = null; LoadFrame(); } @@ -107,18 +107,18 @@ namespace OpenRA.Mods.Cnc.FileFormats public void AdvanceFrame() { previousFramePaletteIndexData = currentFramePaletteIndexData; - CurrentFrameNumber++; + CurrentFrameIndex++; LoadFrame(); } void LoadFrame() { - if (CurrentFrameNumber >= FrameCount) + if (CurrentFrameIndex >= FrameCount) return; - stream.Seek(frameOffsets[CurrentFrameNumber], SeekOrigin.Begin); + stream.Seek(frameOffsets[CurrentFrameIndex], SeekOrigin.Begin); - var dataLength = frameOffsets[CurrentFrameNumber + 1] - frameOffsets[CurrentFrameNumber]; + var dataLength = frameOffsets[CurrentFrameIndex + 1] - frameOffsets[CurrentFrameIndex]; var rawData = StreamExts.ReadBytes(stream, (int)dataLength); var intermediateData = new byte[Width * Height]; diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 5c77bfba0f..12fe4fcf6b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic frameSlider.GetValue = () => { if (isVideoLoaded) - return player.Video.CurrentFrameNumber; + return player.Video.CurrentFrameIndex; if (currentSound != null) return currentSound.SeekPosition * currentSoundFormat.SampleRate; @@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic frameText.GetText = () => { if (isVideoLoaded) - return $"{player.Video.CurrentFrameNumber + 1} / {player.Video.FrameCount}"; + return $"{player.Video.CurrentFrameIndex + 1} / {player.Video.FrameCount}"; if (currentSoundFormat != null) return $"{Math.Round(currentSoundFormat.LengthInSeconds, 3)} sec"; diff --git a/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs b/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs index f37aa0b5e9..3d9607c22f 100644 --- a/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Widgets Sprite videoSprite, overlaySprite; Sheet overlaySheet; IVideo video = null; - string cachedVideo; + string cachedVideoFileName; float invLength; float2 videoOrigin, videoSize; float2 overlayOrigin, overlaySize; @@ -43,13 +43,13 @@ namespace OpenRA.Mods.Common.Widgets public void Load(string filename) { - if (filename == cachedVideo) + if (filename == cachedVideoFileName) return; var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), true, Game.ModData.VideoLoaders); Open(video); - cachedVideo = filename; + cachedVideoFileName = filename; } public void Open(IVideo video) @@ -98,17 +98,17 @@ namespace OpenRA.Mods.Common.Widgets if (video.HasAudio && !Game.Sound.DummyEngine) nextFrame = (int)float2.Lerp(0, video.FrameCount, Game.Sound.VideoSeekPosition * invLength); else - nextFrame = video.CurrentFrameNumber + 1; + nextFrame = video.CurrentFrameIndex + 1; // Without the 2nd check the sound playback sometimes ends before the final frame is displayed which causes the player to be stuck on the first frame - if (nextFrame > video.FrameCount || nextFrame < video.CurrentFrameNumber) + if (nextFrame > video.FrameCount || nextFrame < video.CurrentFrameIndex) { Stop(); return; } var skippedFrames = 0; - while (nextFrame > video.CurrentFrameNumber) + while (nextFrame > video.CurrentFrameIndex) { video.AdvanceFrame(); videoSprite.Sheet.GetTexture().SetData(video.CurrentFrameData, textureSize, textureSize); @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Widgets } if (skippedFrames > 1) - Log.Write("perf", "VideoPlayer: {0} skipped {1} frames at position {2}", cachedVideo, skippedFrames, video.CurrentFrameNumber); + Log.Write("perf", $"{nameof(VideoPlayerWidget)}: {cachedVideoFileName} skipped {skippedFrames} frames at position {video.CurrentFrameIndex}"); } WidgetUtils.DrawSprite(videoSprite, videoOrigin, videoSize); diff --git a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs index 2fef38fd65..81a9325ecd 100644 --- a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs +++ b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs @@ -557,10 +557,10 @@ namespace OpenRA.Platforms.Default readonly Func getSize; readonly Action setEmpty; readonly Func getData; - readonly Action setData2; - readonly Func setData3; - readonly Action setData4; - readonly Func setData5; + readonly Action setData1; + readonly Func setData2; + readonly Action setData3; + readonly Func setData4; readonly Action dispose; public ThreadedTexture(ThreadedGraphicsContext device, ITextureInternal texture) @@ -572,10 +572,10 @@ namespace OpenRA.Platforms.Default getSize = () => texture.Size; setEmpty = tuple => { var t = (ValueTuple)tuple; texture.SetEmpty(t.Item1, t.Item2); }; getData = () => texture.GetData(); - setData2 = tuple => { var t = (ValueTuple)tuple; texture.SetData(t.Item1, t.Item2, t.Item3); }; - setData3 = tuple => { setData2(tuple); return null; }; - setData4 = tuple => { var t = (ValueTuple)tuple; texture.SetFloatData(t.Item1, t.Item2, t.Item3); }; - setData5 = tuple => { setData4(tuple); return null; }; + setData1 = tuple => { var t = (ValueTuple)tuple; texture.SetData(t.Item1, t.Item2, t.Item3); }; + setData2 = tuple => { setData1(tuple); return null; }; + setData3 = tuple => { var t = (ValueTuple)tuple; texture.SetFloatData(t.Item1, t.Item2, t.Item3); }; + setData4 = tuple => { setData3(tuple); return null; }; dispose = texture.Dispose; } @@ -609,13 +609,13 @@ namespace OpenRA.Platforms.Default // If we are able to create a small array the GC can collect easily, post a message to avoid blocking. var temp = new byte[colors.Length]; Array.Copy(colors, temp, temp.Length); - device.Post(setData2, (temp, width, height)); + device.Post(setData1, (temp, width, height)); } else { // If the length is large and would result in an array on the Large Object Heap (LOH), // send a message and block to avoid LOH allocation as this requires a Gen2 collection. - device.Send(setData3, (colors, width, height)); + device.Send(setData2, (colors, width, height)); } } @@ -628,13 +628,13 @@ namespace OpenRA.Platforms.Default // If we are able to create a small array the GC can collect easily, post a message to avoid blocking. var temp = new float[data.Length]; Array.Copy(data, temp, temp.Length); - device.Post(setData4, (temp, width, height)); + device.Post(setData3, (temp, width, height)); } else { // If the length is large and would result in an array on the Large Object Heap (LOH), // send a message and block to avoid LOH allocation as this requires a Gen2 collection. - device.Send(setData5, (data, width, height)); + device.Send(setData4, (data, width, height)); } }