Skip to content

Commit 3428f7b

Browse files
committed
dmd: Fix spinup mode (needs mc enabled).
1 parent 6d2e668 commit 3428f7b

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine
5757

5858
private bool _displaysAnnounced;
5959

60+
private readonly Queue<Action> _dispatchQueue = new Queue<Action>();
61+
6062
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
6163

6264
public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
@@ -79,7 +81,7 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
7981
_api.Launch(new MpfConsoleOptions {
8082
ShowLogInsteadOfConsole = false,
8183
VerboseLogging = true,
82-
UseMediaController = false,
84+
UseMediaController = true,
8385
});
8486

8587
_api.Client.OnEnableCoil += OnEnableCoil;
@@ -100,6 +102,16 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
100102
}
101103
}
102104
_api.StartGame(mappedSwitchStatuses);
105+
Logger.Info("Game started.");
106+
}
107+
108+
private void Update()
109+
{
110+
lock (_dispatchQueue) {
111+
while (_dispatchQueue.Count > 0) {
112+
_dispatchQueue.Dequeue().Invoke();
113+
}
114+
}
103115
}
104116

105117
public void Switch(string id, bool isClosed)
@@ -203,15 +215,25 @@ private void OnRemoveHardwareRule(object sender, RemoveHardwareRuleRequest e)
203215

204216
private void OnDmdFrame(object sender, SetDmdFrameRequest frame)
205217
{
218+
Logger.Info($"<-- dmd frame: {frame.Name}");
206219
if (!_displaysAnnounced) {
207220
_displaysAnnounced = true;
208221
var config = _api.GetMachineDescription();
222+
Logger.Info($"[MPF] Announcing {config.Dmds} display(s)");
209223
foreach (var dmd in config.Dmds) {
210-
OnDisplaysAvailable?.Invoke(this, new AvailableDisplays(
211-
new DisplayConfig(dmd.Name, dmd.Width, dmd.Height)));
224+
Logger.Info($"[MPF] Announcing display \"{dmd.Name}\" @ {dmd.Width}x{dmd.Height}");
225+
lock (_dispatchQueue) {
226+
_dispatchQueue.Enqueue(() => OnDisplaysAvailable?.Invoke(this,
227+
new AvailableDisplays(new DisplayConfig(dmd.Name, dmd.Width, dmd.Height))));
228+
}
212229
}
230+
Logger.Info("[MPF] Displays announced.");
231+
}
232+
233+
lock (_dispatchQueue) {
234+
_dispatchQueue.Enqueue(() => OnDisplayFrame?.Invoke(this,
235+
new DisplayFrameData(frame.Name, DisplayFrameFormat.Dmd24, frame.FrameData())));
213236
}
214-
OnDisplayFrame?.Invoke(this, new DisplayFrameData(frame.Name, DisplayFrameFormat.Dmd8, frame.FrameData()));
215237
}
216238

217239
private void OnDestroy()
@@ -223,6 +245,7 @@ private void OnDestroy()
223245
_api.Client.OnConfigureHardwareRule -= OnConfigureHardwareRule;
224246
_api.Client.OnRemoveHardwareRule -= OnRemoveHardwareRule;
225247
_api.Client.OnFadeLight -= OnFadeLight;
248+
_api.Client.OnDmdFrame -= OnDmdFrame;
226249
_api.Dispose();
227250
}
228251
}

VisualPinball.Engine.Mpf/MpfSpawner.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.IO;
1515
using System.Runtime.InteropServices;
1616
using System.Threading;
17+
using NLog;
1718

1819
namespace VisualPinball.Engine.Mpf
1920
{
@@ -24,6 +25,7 @@ internal class MpfSpawner
2425
private readonly string _machineFolder;
2526

2627
private readonly SemaphoreSlim _ready = new SemaphoreSlim(0, 1);
28+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2729

2830
public MpfSpawner(string machineFolder)
2931
{
@@ -51,9 +53,12 @@ public void Spawn(MpfConsoleOptions options)
5153
private void RunMpf(string mpfExePath, MpfConsoleOptions options)
5254
{
5355
var args = $"\"{_machineFolder}\"";
54-
if (!options.UseMediaController) {
56+
if (options.UseMediaController) {
57+
args = "both " + args;
58+
} else {
5559
args += " -b";
5660
}
61+
5762
if (options.ShowLogInsteadOfConsole) {
5863
args += " -t";
5964
}
@@ -68,6 +73,8 @@ private void RunMpf(string mpfExePath, MpfConsoleOptions options)
6873
RedirectStandardOutput = options.CatchStdOut,
6974
};
7075

76+
Logger.Info($"[MPF] Spawning: > {mpfExePath} {args}");
77+
7178
using (var process = Process.Start(info)) {
7279
_ready.Release();
7380
if (!options.CatchStdOut) {

VisualPinball.Engine.Mpf/VisualPinball.Engine.Mpf.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
<InputAssemblies Include="$(OutDir)Grpc.Core.dll" />
4747
</ItemGroup>
4848

49+
<ItemGroup>
50+
<Folder Include="machine\logs" />
51+
</ItemGroup>
52+
4953
<Target Name="ILRepack" AfterTargets="Build">
5054
<Exec Condition="$([MSBuild]::IsOSPlatform('Windows')) == 'true'" Command="tools\ILRepack.exe /target:library /internalize $(OutDir)$(AssemblyName).dll @(InputAssemblies, ' ') /out:$(OutDir)$(AssemblyName).dll" />
5155
<Exec Condition="$([MSBuild]::IsOSPlatform('Windows')) != 'true'" Command="mono tools/ILRepack.exe /target:library /internalize $(OutDir)$(AssemblyName).dll @(InputAssemblies, ' ') /out:$(OutDir)$(AssemblyName).dll" />

VisualPinball.Engine.Mpf/machine/config/config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
#config_version=5
22

3+
displays:
4+
dmd: # source display for the DMD
5+
width: 128
6+
height: 32
7+
default: true
8+
39
hardware:
410
platform: visual_pinball_engine
511

12+
rgb_dmds:
13+
default:
14+
fps: 30
15+
16+
mpf-mc:
17+
fps: 30
18+
19+
slides:
20+
dmd_slide_1: # slide we'll show on the physical DMD
21+
- type: text
22+
text: MISSION PINBALL
23+
font_size: 30
24+
color: red
25+
x: 0
26+
animations:
27+
add_to_slide:
28+
- property: x
29+
value: 250
30+
duration: 30
31+
relative: true
32+
33+
slide_player:
34+
init_done:
35+
dmd_slide_1:
36+
target: dmd
37+
638
vpe:
739
debug: True
840

0 commit comments

Comments
 (0)