BizHawk/ExternalCoreProjects/Virtu/MachineEvents.cs

115 lines
2.4 KiB
C#
Raw Normal View History

2015-02-17 22:58:25 +00:00
using System;
using System.Collections.Generic;
using System.Globalization;
namespace Jellyfish.Virtu
{
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
internal sealed class MachineEvent
{
public MachineEvent(int delta, Action action)
{
Delta = delta;
Action = action;
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "Delta = {0} Action = {{{1}.{2}}}", Delta, Action.Method.DeclaringType?.Name, Action.Method.Name);
}
public int Delta { get; set; }
public Action Action { get; set; }
}
public sealed class MachineEvents
{
public void AddEvent(int delta, Action action)
{
var node = _used.First;
for (; node != null; node = node.Next)
{
if (delta < node.Value.Delta)
{
node.Value.Delta -= delta;
break;
}
if (node.Value.Delta > 0)
{
delta -= node.Value.Delta;
}
}
var newNode = _free.First;
if (newNode != null)
{
_free.RemoveFirst();
newNode.Value.Delta = delta;
newNode.Value.Action = action;
}
else
{
newNode = new LinkedListNode<MachineEvent>(new MachineEvent(delta, action));
}
if (node != null)
{
_used.AddBefore(node, newNode);
}
else
{
_used.AddLast(newNode);
}
}
public int FindEvent(Action action)
{
int delta = 0;
for (var node = _used.First; node != null; node = node.Next)
{
delta += node.Value.Delta;
2015-05-18 00:14:00 +00:00
var other = node.Value.Action;
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
if (other.Method == action.Method && other.Target == action.Target)
2015-05-18 00:14:00 +00:00
{
return delta;
}
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
}
2015-05-18 00:14:00 +00:00
return 0;
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
}
2015-05-18 00:14:00 +00:00
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
// ReSharper disable once UnusedMember.Global
public void HandleEvents(int delta)
{
var node = _used.First;
node.Value.Delta -= delta;
2015-02-17 22:58:25 +00:00
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
while (node.Value.Delta <= 0)
{
2015-05-18 00:14:00 +00:00
node.Value.Action();
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
RemoveEvent(node);
node = _used.First;
}
}
private void RemoveEvent(LinkedListNode<MachineEvent> node)
{
if (node.Next != null)
{
node.Next.Value.Delta += node.Value.Delta;
}
_used.Remove(node);
_free.AddFirst(node); // cache node; avoids garbage
}
// ReSharper disable once FieldCanBeMadeReadOnly.Local
private LinkedList<MachineEvent> _used = new LinkedList<MachineEvent>();
// ReSharper disable once FieldCanBeMadeReadOnly.Local
private LinkedList<MachineEvent> _free = new LinkedList<MachineEvent>();
}
2015-02-17 22:58:25 +00:00
}