Removed caching properties from video readers

Those seem redundant since the frame number is guaranteed to match the loaded data inside CurrentFrameData.
This commit is contained in:
penev92
2021-08-01 20:50:03 +03:00
committed by Matthias Mailänder
parent 0df3b34c52
commit 1b5f2f1b39
2 changed files with 14 additions and 35 deletions

View File

@@ -23,17 +23,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
public ushort Width { get; }
public ushort Height { get; }
public uint[,] CurrentFrameData { get; }
public int CurrentFrameNumber { get; private set; }
public uint[,] CurrentFrameData
{
get
{
if (cachedFrameNumber != CurrentFrameNumber)
DecodeFrameData();
return cachedCurrentFrameData;
}
}
public bool HasAudio { get; set; }
public byte[] AudioData { get; private set; } // audio for this frame: 22050Hz 16bit mono pcm, uncompressed.
@@ -69,9 +60,6 @@ namespace OpenRA.Mods.Cnc.FileFormats
// Top half contains block info, bottom half contains references to cbf array
byte[] origData;
int cachedFrameNumber = -1;
uint[,] cachedCurrentFrameData;
public VqaReader(Stream stream)
{
this.stream = stream;
@@ -113,8 +101,6 @@ namespace OpenRA.Mods.Cnc.FileFormats
/*var unknown5 =*/stream.ReadUInt32();
var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));
if (IsHqVqa)
{
cbfBuffer = new byte[maxCbfzSize];
@@ -130,7 +116,6 @@ namespace OpenRA.Mods.Cnc.FileFormats
}
palette = new uint[numColors];
cachedCurrentFrameData = new uint[frameSize, frameSize];
var type = stream.ReadASCII(4);
while (type != "FINF")
{
@@ -160,6 +145,9 @@ namespace OpenRA.Mods.Cnc.FileFormats
CollectAudioData();
var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));
CurrentFrameData = new uint[frameSize, frameSize];
Reset();
}
@@ -317,6 +305,9 @@ namespace OpenRA.Mods.Cnc.FileFormats
// Chunks are aligned on even bytes; advance by a byte if the next one is null
if (stream.Peek() == 0) stream.ReadByte();
}
// Now that the frame data has been loaded (in the relevant private fields), decode it into CurrentFrameData.
DecodeFrameData();
}
// VQA Frame
@@ -427,7 +418,6 @@ namespace OpenRA.Mods.Cnc.FileFormats
void DecodeFrameData()
{
cachedFrameNumber = CurrentFrameNumber;
if (IsHqVqa)
{
/* The VP?? chunks of the video file contains an array of instructions for
@@ -492,7 +482,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
{
var cbfi = (mod * 256 + px) * 8 + j * blockWidth + i;
var color = (mod == 0x0f) ? px : cbf[cbfi];
cachedCurrentFrameData[y * blockHeight + j, x * blockWidth + i] = palette[color];
CurrentFrameData[y * blockHeight + j, x * blockWidth + i] = palette[color];
}
}
}
@@ -514,7 +504,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
{
var p = (bx + by * blockWidth) * 3;
cachedCurrentFrameData[frameY + by, frameX + bx] = (uint)(0xFF << 24 | cbf[offset + p] << 16 | cbf[offset + p + 1] << 8 | cbf[offset + p + 2]);
CurrentFrameData[frameY + by, frameX + bx] = (uint)(0xFF << 24 | cbf[offset + p] << 16 | cbf[offset + p + 1] << 8 | cbf[offset + p + 2]);
}
x++;

View File

@@ -22,17 +22,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
public ushort Width { get; }
public ushort Height { get; }
public uint[,] CurrentFrameData { get; }
public int CurrentFrameNumber { get; private set; }
public uint[,] CurrentFrameData
{
get
{
if (cachedFrameNumber != CurrentFrameNumber)
LoadFrame();
return cachedCurrentFrameData;
}
}
public bool HasAudio => false;
public byte[] AudioData => null;
@@ -47,9 +38,6 @@ namespace OpenRA.Mods.Cnc.FileFormats
byte[] previousFramePaletteIndexData;
byte[] currentFramePaletteIndexData;
int cachedFrameNumber = -1;
uint[,] cachedCurrentFrameData;
public WsaReader(Stream stream)
{
this.stream = stream;
@@ -90,6 +78,9 @@ namespace OpenRA.Mods.Cnc.FileFormats
frameOffsets[i] += 768;
}
var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));
CurrentFrameData = new uint[frameSize, frameSize];
Reset();
}
@@ -132,11 +123,9 @@ namespace OpenRA.Mods.Cnc.FileFormats
XORDeltaCompression.DecodeInto(intermediateData, currentFramePaletteIndexData, 0);
var c = 0;
var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));
cachedCurrentFrameData = new uint[frameSize, frameSize];
for (var y = 0; y < Height; y++)
for (var x = 0; x < Width; x++)
cachedCurrentFrameData[y, x] = palette[currentFramePaletteIndexData[c++]];
CurrentFrameData[y, x] = palette[currentFramePaletteIndexData[c++]];
}
}
}