1818using System . Collections . Generic ;
1919using System . Linq ;
2020using NLog ;
21- using PinMame ;
2221using UnityEngine ;
2322using VisualPinball . Engine . Game . Engines ;
2423using VisualPinball . Unity ;
@@ -40,7 +39,6 @@ public PinMameGame Game {
4039
4140 [ HideInInspector ]
4241 public string romId = string . Empty ;
43- public GameObject dmd ;
4442
4543 public GamelogicEngineSwitch [ ] AvailableSwitches {
4644 get {
@@ -65,6 +63,8 @@ public GamelogicEngineLamp[] AvailableLamps {
6563 public event EventHandler < LampEventArgs > OnLampChanged ;
6664 public event EventHandler < LampsEventArgs > OnLampsChanged ;
6765 public event EventHandler < LampColorEventArgs > OnLampColorChanged ;
66+ public event EventHandler < AvailableDisplays > OnDisplaysAvailable ;
67+ public event EventHandler < DisplayFrameData > OnDisplayFrame ;
6868
6969 [ NonSerialized ] private Player _player ;
7070 [ NonSerialized ] private PinMame . PinMame _pinMame ;
@@ -74,20 +74,13 @@ public GamelogicEngineLamp[] AvailableLamps {
7474 private Dictionary < int , GamelogicEngineCoil > _coils = new Dictionary < int , GamelogicEngineCoil > ( ) ;
7575 private Dictionary < int , GamelogicEngineLamp > _lamps = new Dictionary < int , GamelogicEngineLamp > ( ) ;
7676
77- private Texture2D _texture ;
78- private DmdDimensions _dmdDimensions ;
77+ private const string DisplayDmd = "dmd" ;
78+
79+ private bool _sizeAnnounced ;
7980
8081 private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
8182 private static readonly Color Tint = new Color ( 1 , 0.18f , 0 ) ;
8283
83- private readonly Dictionary < byte , Color > _map = new Dictionary < byte , Color > {
84- { 0x0 , Color . Lerp ( Color . black , Tint , 0 ) } ,
85- { 0x14 , Color . Lerp ( Color . black , Tint , 0.33f ) } ,
86- { 0x21 , Color . Lerp ( Color . black , Tint , 0.66f ) } ,
87- { 0x43 , Color . Lerp ( Color . black , Tint , 1f ) } ,
88- { 0x64 , Color . Lerp ( Color . black , Tint , 1f ) }
89- } ;
90-
9184 private void Start ( )
9285 {
9386 UpdateCaches ( ) ;
@@ -156,23 +149,14 @@ private void Update()
156149 }
157150
158151 // dmd
159- if ( dmd != null && _pinMame . NeedsDmdUpdate ( ) ) {
160- if ( _texture == null ) {
161- _dmdDimensions = _pinMame . GetDmdDimensions ( ) ;
162- _texture = new Texture2D ( _dmdDimensions . Width , _dmdDimensions . Height ) ;
163- dmd . GetComponent < Renderer > ( ) . sharedMaterial . mainTexture = _texture ;
152+ if ( _pinMame . NeedsDmdUpdate ( ) ) {
153+ if ( ! _sizeAnnounced ) {
154+ var dim = _pinMame . GetDmdDimensions ( ) ;
155+ OnDisplaysAvailable ? . Invoke ( this , new AvailableDisplays (
156+ new DisplayConfig ( DisplayDmd , DisplayType . Dmd2PinMame , dim . Width , dim . Height ) ) ) ;
157+ _sizeAnnounced = true ;
164158 }
165-
166- var frame = _pinMame . GetDmdPixels ( ) ;
167- if ( frame . Length == _dmdDimensions . Width * _dmdDimensions . Height ) {
168- for ( var y = 0 ; y < _dmdDimensions . Height ; y ++ ) {
169- for ( var x = 0 ; x < _dmdDimensions . Width ; x ++ ) {
170- var pixel = frame [ y * _dmdDimensions . Width + x ] ;
171- _texture . SetPixel ( _dmdDimensions . Width - x , _dmdDimensions . Height - y , _map . ContainsKey ( pixel ) ? _map [ pixel ] : Color . magenta ) ;
172- }
173- }
174- }
175- _texture . Apply ( ) ;
159+ OnDisplayFrame ? . Invoke ( this , new DisplayFrameData ( DisplayDmd , _pinMame . GetDmdPixels ( ) ) ) ;
176160 }
177161 }
178162
@@ -211,4 +195,27 @@ public void Switch(string id, bool isClosed)
211195 }
212196 }
213197 }
198+
199+ // internal readonly struct DisplayKey : IEquatable<DisplayKey>
200+ // {
201+ // private readonly int _width;
202+ // private readonly int _height;
203+ // private readonly int _bitLength;
204+ //
205+ // public DisplayKey(int width, int height, int bitLength)
206+ // {
207+ // _width = width;
208+ // _height = height;
209+ // _bitLength = bitLength;
210+ // }
211+ //
212+ // public override bool Equals(object obj) => obj is DisplayKey other && Equals(other);
213+ //
214+ // public bool Equals(DisplayKey other)
215+ // {
216+ // return _width == other._width && _height == other._height && _bitLength == other._bitLength;
217+ // }
218+ //
219+ // public override int GetHashCode() => (_width, _height, _bitLength).GetHashCode();
220+ // }
214221}
0 commit comments