Skip to content

Commit a080086

Browse files
authored
Refactor InputDisplayGenerator + LogEntryGenerator + ControllerDefinition (#3782)
* refactor InputDisplayGenerator and LogEntryGenerator handling * Fix NRE in Tastudio. I can already see this avalanching into 100 different bugs * cba, revert 48f4e13 and bring back bullshit dummy default MovieController * Refactor MnemonicCache + make Bk2LogEntryGenerator and Bk2InputDisplayGenerator static. This should simplify stuff and make the logic clearer
1 parent 08bd14e commit a080086

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+239
-401
lines changed

src/BizHawk.Client.Common/Api/Classes/MovieApi.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public string GetInputAsMnemonic(int frame)
5050
return string.Empty;
5151
}
5252

53-
var lg = _movieSession.Movie.LogGeneratorInstance(
54-
_movieSession.Movie.GetInputState(frame));
55-
return lg.GenerateLogEntry();
53+
return Bk2LogEntryGenerator.GenerateLogEntry(_movieSession.Movie.GetInputState(frame));
5654
}
5755

5856
public void Save(string filename)

src/BizHawk.Client.Common/Controller.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace BizHawk.Client.Common
99
{
1010
public class Controller : IController
1111
{
12-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
13-
1412
public Controller(ControllerDefinition definition)
1513
{
1614
Definition = definition;
@@ -186,4 +184,4 @@ public void BindAxis(string button, AnalogBind bind)
186184
.Select(kvp => kvp.Key)
187185
.ToList();
188186
}
189-
}
187+
}

src/BizHawk.Client.Common/DisplayManager/OSDManager.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private string MakeFrameCounter()
7575

7676
return sb.ToString();
7777
}
78-
78+
7979
return _emulator.Frame.ToString();
8080
}
8181

@@ -172,10 +172,10 @@ public void DrawMessages(IBlitter g)
172172
}
173173

174174
public string InputStrMovie()
175-
=> MakeStringFor(_movieSession.MovieController, cache: true);
175+
=> MakeStringFor(_movieSession.MovieController);
176176

177177
public string InputStrImmediate()
178-
=> MakeStringFor(_inputManager.AutofireStickyXorAdapter, cache: true);
178+
=> MakeStringFor(_inputManager.AutofireStickyXorAdapter);
179179

180180
public string InputPrevious()
181181
{
@@ -196,15 +196,9 @@ public string InputStrOrAll()
196196
? MakeStringFor(_inputManager.AutofireStickyXorAdapter.Or(_movieSession.Movie.GetInputState(_emulator.Frame - 1)))
197197
: InputStrImmediate();
198198

199-
private string MakeStringFor(IController controller, bool cache = false)
199+
private static string MakeStringFor(IController controller)
200200
{
201-
var idg = controller.InputDisplayGenerator;
202-
if (idg is null)
203-
{
204-
idg = new Bk2InputDisplayGenerator(_emulator.SystemId, controller);
205-
if (cache) controller.InputDisplayGenerator = idg;
206-
}
207-
return idg.Generate();
201+
return Bk2InputDisplayGenerator.Generate(controller);
208202
}
209203

210204
public string MakeIntersectImmediatePrevious()
@@ -292,7 +286,7 @@ public void DrawScreenInfo(IBlitter g)
292286
// in order to achieve this we want to avoid drawing anything pink that isn't actually held down right now
293287
// so we make an AND adapter and combine it using immediate & sticky
294288
// (adapter creation moved to InputManager)
295-
var autoString = MakeStringFor(_inputManager.WeirdStickyControllerForInputDisplay, cache: true);
289+
var autoString = MakeStringFor(_inputManager.WeirdStickyControllerForInputDisplay);
296290
g.DrawString(autoString, autoColor, point.X, point.Y);
297291

298292
//recolor everything that's changed from the previous input

src/BizHawk.Client.Common/controllers/AutofireController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace BizHawk.Client.Common
99
{
1010
public class AutofireController : IController
1111
{
12-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
13-
1412
public AutofireController(IEmulator emulator, int on, int off)
1513
{
1614
On = on < 1 ? 0 : on;

src/BizHawk.Client.Common/controllers/ClickyVirtualPadController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public class ClickyVirtualPadController : IController
1414

1515
public ControllerDefinition Definition { get; set; }
1616

17-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
18-
1917
public bool IsPressed(string button) => _pressed.Contains(button);
2018

2119
public int AxisValue(string name) => 0;

src/BizHawk.Client.Common/controllers/SimpleController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public class SimpleController : IController
1313
{
1414
public ControllerDefinition Definition { get; }
1515

16-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
17-
1816
protected Dictionary<string, int> Axes { get; private set; } = new();
1917

2018
protected Dictionary<string, bool> Buttons { get; private set; } = new();

src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Linq;
2+
using System.Text;
3+
using BizHawk.Emulation.Common;
4+
5+
namespace BizHawk.Client.Common
6+
{
7+
/// <summary>
8+
/// Generates a display friendly version of the input log entry
9+
/// using .bk2 mnemonics as the basis for display
10+
/// </summary>
11+
public static class Bk2InputDisplayGenerator
12+
{
13+
public static string Generate(IController source)
14+
{
15+
if (source.Definition.MnemonicsCache is null)
16+
throw new InvalidOperationException("Can't generate input display string with empty mnemonics cache");
17+
18+
var sb = new StringBuilder();
19+
20+
foreach ((string buttonName, AxisSpec? axisSpec) in source.Definition.ControlsOrdered.SelectMany(x => x))
21+
{
22+
if (axisSpec.HasValue)
23+
{
24+
int val = source.AxisValue(buttonName);
25+
26+
if (val == axisSpec.Value.Neutral)
27+
{
28+
sb.Append(" ");
29+
}
30+
else
31+
{
32+
sb.Append(val.ToString().PadLeft(5, ' ')).Append(',');
33+
}
34+
}
35+
else
36+
{
37+
sb.Append(source.IsPressed(buttonName)
38+
? source.Definition.MnemonicsCache[buttonName]
39+
: ' ');
40+
}
41+
}
42+
43+
return sb.ToString();
44+
}
45+
}
46+
}

src/BizHawk.Client.Common/inputAdapters/BitwiseAdapters.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ public class AndAdapter : IInputAdapter
88
{
99
public ControllerDefinition Definition => Source.Definition;
1010

11-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
12-
1311
public bool IsPressed(string button)
1412
{
1513
if (Source != null && SourceAnd != null)
@@ -36,8 +34,6 @@ public class XorAdapter : IInputAdapter
3634
{
3735
public ControllerDefinition Definition => Source.Definition;
3836

39-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
40-
4137
public bool IsPressed(string button)
4238
{
4339
if (Source != null && SourceXor != null)
@@ -64,8 +60,6 @@ public class ORAdapter : IInputAdapter
6460
{
6561
public ControllerDefinition Definition => Source.Definition;
6662

67-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
68-
6963
public bool IsPressed(string button)
7064
{
7165
return (Source?.IsPressed(button) ?? false)

src/BizHawk.Client.Common/inputAdapters/CopyController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public class CopyControllerAdapter : IInputAdapter
1111
{
1212
public ControllerDefinition Definition => Curr.Definition;
1313

14-
public IInputDisplayGenerator InputDisplayGenerator { get; set; } = null;
15-
1614
public bool IsPressed(string button) => Curr.IsPressed(button);
1715

1816
public int AxisValue(string name) => Curr.AxisValue(name);

0 commit comments

Comments
 (0)