2014-11-02 00:22:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-11-15 14:31:18 +00:00
|
|
|
|
using System.IO;
|
2014-11-02 00:22:04 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2014-12-05 00:59:00 +00:00
|
|
|
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
2014-11-30 20:29:30 +00:00
|
|
|
|
|
2014-11-02 00:22:04 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
public class TasLagLog
|
2014-11-02 00:22:04 +00:00
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
private readonly SortedList<int, bool> LagLog = new SortedList<int, bool>();
|
|
|
|
|
|
|
|
|
|
public bool? this[int frame]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (LagLog.ContainsKey(frame))
|
|
|
|
|
{
|
|
|
|
|
return LagLog[frame];
|
|
|
|
|
}
|
2014-11-15 14:55:44 +00:00
|
|
|
|
else if (frame == Global.Emulator.Frame)
|
|
|
|
|
{
|
|
|
|
|
if (frame == LagLog.Count)
|
|
|
|
|
{
|
2014-12-05 00:59:00 +00:00
|
|
|
|
LagLog[frame] = Global.Emulator.AsInputPollable().IsLagFrame; // Note: Side effects!
|
2014-11-15 14:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-05 00:59:00 +00:00
|
|
|
|
return Global.Emulator.AsInputPollable().IsLagFrame;
|
2014-11-15 14:55:44 +00:00
|
|
|
|
}
|
2014-11-15 14:31:18 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
LagLog.Remove(frame);
|
|
|
|
|
}
|
|
|
|
|
else if (frame < 0)
|
|
|
|
|
{
|
|
|
|
|
return; // Nothing to do
|
|
|
|
|
}
|
|
|
|
|
else if (LagLog.ContainsKey(frame))
|
|
|
|
|
{
|
|
|
|
|
LagLog[frame] = value.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LagLog.Add(frame, value.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
LagLog.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 00:22:04 +00:00
|
|
|
|
public void RemoveFrom(int frame)
|
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
if (frame > 0 && frame <= LagLog.Count)
|
2014-11-02 00:22:04 +00:00
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
for (int i = LagLog.Count - 1; i > frame; i--) // Reverse order because removing from a sorted list re-indexes the items after the removed item
|
|
|
|
|
{
|
|
|
|
|
LagLog.RemoveAt(i);
|
|
|
|
|
}
|
2014-11-02 00:22:04 +00:00
|
|
|
|
}
|
2014-11-02 14:25:06 +00:00
|
|
|
|
else if (frame == 0)
|
2014-11-02 13:52:45 +00:00
|
|
|
|
{
|
|
|
|
|
this.Clear();
|
|
|
|
|
}
|
2014-11-15 14:31:18 +00:00
|
|
|
|
|
2014-11-02 00:22:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 14:31:18 +00:00
|
|
|
|
public void Save(BinaryWriter bw)
|
2014-11-02 00:22:04 +00:00
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
bw.Write(LagLog.Count);
|
|
|
|
|
foreach (var kvp in LagLog)
|
2014-11-02 00:39:53 +00:00
|
|
|
|
{
|
2014-11-15 14:31:18 +00:00
|
|
|
|
bw.Write(kvp.Key);
|
|
|
|
|
bw.Write(kvp.Value);
|
2014-11-02 00:39:53 +00:00
|
|
|
|
}
|
2014-11-15 14:31:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load(BinaryReader br)
|
|
|
|
|
{
|
|
|
|
|
LagLog.Clear();
|
2014-11-20 00:14:33 +00:00
|
|
|
|
if (br.BaseStream.Length > 0)
|
2014-11-02 00:22:04 +00:00
|
|
|
|
{
|
2014-11-20 00:14:33 +00:00
|
|
|
|
int length = br.ReadInt32();
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
LagLog.Add(br.ReadInt32(), br.ReadBoolean());
|
|
|
|
|
}
|
2014-11-02 00:22:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|