speedup delta stating with disks with simple track tracking, should be within acceptable performance bounds (more or less)
This commit is contained in:
parent
3ffb6c3b52
commit
df71de64c8
|
@ -9,7 +9,7 @@ namespace BizHawk.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DeltaSerializer
|
public static class DeltaSerializer
|
||||||
{
|
{
|
||||||
public static byte[] GetDelta<T>(ReadOnlySpan<T> original, ReadOnlySpan<T> data)
|
public static ReadOnlySpan<byte> GetDelta<T>(ReadOnlySpan<T> original, ReadOnlySpan<T> data)
|
||||||
where T : unmanaged
|
where T : unmanaged
|
||||||
{
|
{
|
||||||
var orignalAsBytes = MemoryMarshal.AsBytes(original);
|
var orignalAsBytes = MemoryMarshal.AsBytes(original);
|
||||||
|
@ -94,7 +94,7 @@ namespace BizHawk.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret.Slice(0, retSize).ToArray();
|
return ret.Slice(0, retSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ApplyDelta<T>(ReadOnlySpan<T> original, Span<T> data, ReadOnlySpan<byte> delta)
|
public static void ApplyDelta<T>(ReadOnlySpan<T> original, Span<T> data, ReadOnlySpan<byte> delta)
|
||||||
|
|
|
@ -759,7 +759,7 @@ namespace BizHawk.Common
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var delta = DeltaSerializer.GetDelta<T>(original, data);
|
var delta = DeltaSerializer.GetDelta<T>(original, data).ToArray(); // TODO: don't create array here (need .net update to write span to binary writer)
|
||||||
Sync(name, ref delta, useNull: false);
|
Sync(name, ref delta, useNull: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
||||||
public const int FluxEntriesPerTrack = FluxBitsPerTrack / FluxBitsPerEntry;
|
public const int FluxEntriesPerTrack = FluxBitsPerTrack / FluxBitsPerEntry;
|
||||||
private readonly int[][] _tracks;
|
private readonly int[][] _tracks;
|
||||||
private readonly int[][] _originalMedia;
|
private readonly int[][] _originalMedia;
|
||||||
|
private bool[] _usedTracks;
|
||||||
public bool Valid;
|
public bool Valid;
|
||||||
public bool WriteProtected;
|
public bool WriteProtected;
|
||||||
|
|
||||||
|
@ -24,6 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
||||||
_tracks = new int[trackCapacity][];
|
_tracks = new int[trackCapacity][];
|
||||||
FillMissingTracks();
|
FillMissingTracks();
|
||||||
_originalMedia = _tracks.Select(t => (int[])t.Clone()).ToArray();
|
_originalMedia = _tracks.Select(t => (int[])t.Clone()).ToArray();
|
||||||
|
_usedTracks = new bool[trackCapacity];
|
||||||
Valid = true;
|
Valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +49,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
||||||
FillMissingTracks();
|
FillMissingTracks();
|
||||||
Valid = true;
|
Valid = true;
|
||||||
_originalMedia = _tracks.Select(t => (int[])t.Clone()).ToArray();
|
_originalMedia = _tracks.Select(t => (int[])t.Clone()).ToArray();
|
||||||
|
_usedTracks = new bool[trackCapacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] ConvertToFluxTransitions(int density, byte[] bytes, int fluxBitOffset)
|
private int[] ConvertToFluxTransitions(int density, byte[] bytes, int fluxBitOffset)
|
||||||
|
@ -133,17 +137,27 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
||||||
|
|
||||||
public int[] GetDataForTrack(int halftrack)
|
public int[] GetDataForTrack(int halftrack)
|
||||||
{
|
{
|
||||||
|
_usedTracks[halftrack] = true; // TODO: probably can be smarter about this with the WriteProtected flag
|
||||||
return _tracks[halftrack];
|
return _tracks[halftrack];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SyncState(Serializer ser)
|
public void SyncState(Serializer ser)
|
||||||
{
|
{
|
||||||
ser.Sync(nameof(WriteProtected), ref WriteProtected);
|
ser.Sync(nameof(WriteProtected), ref WriteProtected);
|
||||||
|
var oldUsedTracks = _usedTracks; // Sync changes reference if loading state (we don't care in the saving state case)
|
||||||
|
ser.Sync(nameof(_usedTracks), ref _usedTracks, useNull: false);
|
||||||
|
|
||||||
for (var i = 0; i < _tracks.Length; i++)
|
for (var i = 0; i < _tracks.Length; i++)
|
||||||
|
{
|
||||||
|
if (_usedTracks[i])
|
||||||
{
|
{
|
||||||
ser.SyncDelta($"MediaState{i}", _originalMedia[i], _tracks[i]);
|
ser.SyncDelta($"MediaState{i}", _originalMedia[i], _tracks[i]);
|
||||||
}
|
}
|
||||||
|
else if (ser.IsReader && oldUsedTracks[i]) // _tracks[i] might be different, but in the state it wasn't, so just copy _originalMedia[i]
|
||||||
|
{
|
||||||
|
_originalMedia[i].AsSpan().CopyTo(_tracks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue