Skip to content

Remove internal id from switches, lamps, and coils#408

Merged
freezy merged 3 commits into
masterfrom
misc/remove-internal-id
May 28, 2022
Merged

Remove internal id from switches, lamps, and coils#408
freezy merged 3 commits into
masterfrom
misc/remove-internal-id

Conversation

@jsm174
Copy link
Copy Markdown
Collaborator

@jsm174 jsm174 commented Apr 18, 2022

Switch, lamps, and coils in VisualPinball.Engine are identified with an Id variable that is a string.

PinMAME internally uses integers to identify switches, lamps, and coils.

Because of this, an InternalId variable was added to VisualPinball.Engine to help mapping.

When working on RGB lamps for TWD, we had issues and needed to pass InternalId to the lamp player.

We then noticed missing lamps when auto Populating lamps in the lamp manager. Lamps that don't have an internal id default as 0. Auto populating overwrites existing entries by internal ids.

Since InternalId is real only needed for PinMAME, (Visual Scripting and MPF only use Id), we could remove InternalId all together, and make the PinMAME GLE deal with the Id.

This PR does exactly that. There are additional PRs for PinMAME, Visual Scripting, and MPF.

@jsm174 jsm174 requested a review from freezy April 18, 2022 15:59
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2022

Codecov Report

Merging #408 (dff8097) into master (b663871) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #408      +/-   ##
==========================================
- Coverage   83.34%   83.30%   -0.05%     
==========================================
  Files         128      128              
  Lines        7081     7075       -6     
==========================================
- Hits         5902     5894       -8     
- Misses       1179     1181       +2     
Impacted Files Coverage Δ
...Pinball.Engine/Game/Engines/GamelogicEngineCoil.cs 71.42% <0.00%> (+2.67%) ⬆️
...Pinball.Engine/Game/Engines/GamelogicEngineLamp.cs 20.00% <0.00%> (-0.90%) ⬇️
...nball.Engine/Game/Engines/GamelogicEngineSwitch.cs 73.33% <0.00%> (-26.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48ddbe1...dff8097. Read the comment docs.

Copy link
Copy Markdown
Owner

@freezy freezy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Great to hear that this can be simplified. :)

Will test and look through PinMAME tomorrow.

Comment on lines -199 to +207
foreach (var sw in MainComponent.AvailableSwitches) {
if (sw.InternalId > 0) {
_stackSwitches[sw.InternalId - 1] = CreateSwitch(sw.Id, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
_switchLookup[sw.Id] = _stackSwitches[sw.InternalId - 1];
foreach (var @switch in MainComponent.AvailableSwitches) {
var match = new Regex(@"^ball_switch_(\d+)$").Match(@switch.Id);
if (match.Success) {
int.TryParse(match.Groups[1].Value, out int id);
if (id > 0) {
_stackSwitches[id - 1] = CreateSwitch(@switch.Id, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
_switchLookup[@switch.Id] = _stackSwitches[id - 1];
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit ugly, but since it's only done once I guess there isn't too much of an impact. I would at least move the regex compilation out of the loop though.

And one thing I would add is a comment when ball_switch_{i} is defined, so it's clear we cannot rename it without changing the regex.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Just curious, if there are multiple troughs on a playfield, would multiple ball_switch_1s cause any issues?

@jsm174 jsm174 force-pushed the misc/remove-internal-id branch 2 times, most recently from 942bd72 to 74930ad Compare April 18, 2022 23:33
@jsm174 jsm174 force-pushed the misc/remove-internal-id branch from 74930ad to 3a242c9 Compare April 18, 2022 23:35
@freezy
Copy link
Copy Markdown
Owner

freezy commented May 24, 2022

Merging this soon. @jsm174 Could you update the MPF repo with these changes as well please?

@jsm174
Copy link
Copy Markdown
Collaborator Author

jsm174 commented May 24, 2022

sure. Will do tonight!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants