Skip to content

Lamp Manager#282

Merged
freezy merged 23 commits into
masterfrom
feature/lamp-manager
Jan 19, 2021
Merged

Lamp Manager#282
freezy merged 23 commits into
masterfrom
feature/lamp-manager

Conversation

@freezy
Copy link
Copy Markdown
Owner

@freezy freezy commented Jan 18, 2021

This PR adds a lamp manager to the editor and handles lamps during game play. Please check out the documentation for a more detailed high-level description.

It was a bit tested with the PinMAME branch, so it somewhat works. Thanks to @ecurtz who did the ground work.

Lamp changes can be sent in batches or individually. Gamelogic that knows about RGB lamps can also just send color changes (e.g. PinMAME doesn't, it just exposes three wires per lamp and we need to figure out ourselves which wires go together). If a batch of lamps contains RGB values for the same lamp, they are grouped and sent together. In short, the gamelogic engine has these events at its disposal to trigger lamp changes:

  • OnLampChanged - takes in an ID and an int value
  • OnLampsChanged - takes in a list of IDs and int values
  • OnLampColorChanged - takes in an ID and a color

Note we always emit ints, although most lamps are typically binary. How the value is interpreted is set by the mapping config (0-1 vs 0-255). This makes it easy to re-use the same struct.

We've also implemented fading over multiple frames using Coroutines. Fading time should be calculated correctly, for example if a lamp has only faded out halfway when it's triggered again, fading in will only take half the time. Also, blinking was implemented. All this is part of LightAuthoring.

Player Changes

The Player class got too big, so I've split it up:

  • Player - lifecycle code and registrations, and a few APIs forwarded to the other classes
  • LampPlayer - Lamp assignment and gameplay handling
  • CoilPlayer - Coil assignment and gameplay handing - has a reference to LampPlayer so it can forward coil lamps
  • SwitchPlayer - Switch assignment and gamplay handling - has a reference to the input manager
  • WirePlayer - Idem, references the input manager and the switches so it can hook into the sources.

Those four are pretty much autonomous anyway, so having them in separate classes is much cleaner.

Other Changes

  • Monitoring - Lamps, coils and switches now have their statuses during gameplay in a map that can be easily consumed. This was necessary for switches because we need to have the initial switch states ready when starting a game, so I've added it for coils and lights as well. Each editor window now shows them in real-time.
  • Gamelogic engines are now directly MonoBehaviours, which makes it less complicated to fetch them and customize the inspector.
  • The switch assignment code should be more stable now and log more relevant stuff

TODO

  • Update coil manager documentation
  • Clean up gamelogic engine inspector

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 18, 2021

Codecov Report

Merging #282 (83309c2) into master (e4d8dd3) will increase coverage by 0.49%.
The diff coverage is 72.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #282      +/-   ##
==========================================
+ Coverage   56.89%   57.39%   +0.49%     
==========================================
  Files         160      162       +2     
  Lines        9474     9599     +125     
  Branches      941      960      +19     
==========================================
+ Hits         5390     5509     +119     
- Misses       3855     3860       +5     
- Partials      229      230       +1     
Impacted Files Coverage Δ
VisualPinball.Engine/Math/Color.cs 63.63% <ø> (ø)
VisualPinball.Engine/VPT/Flasher/Flasher.cs 75.00% <ø> (ø)
VisualPinball.Engine/VPT/Light/Light.cs 20.00% <ø> (ø)
VisualPinball.Engine/VPT/MaterialLoader.cs 78.94% <ø> (ø)
...ualPinball.Engine/VPT/Mappings/MappingsLampData.cs 28.00% <28.00%> (ø)
...sualPinball.Engine/IO/BiffMappingsLampAttribute.cs 30.76% <30.76%> (ø)
VisualPinball.Engine/VPT/Mappings/MappingsData.cs 52.54% <40.00%> (-2.56%) ⬇️
VisualPinball.Engine/VPT/Mappings/Mappings.cs 82.72% <97.22%> (+4.99%) ⬆️
VisualPinball.Engine/VPT/Table/Table.cs 49.73% <100.00%> (+0.39%) ⬆️
VisualPinball.Engine/VPT/Table/TableBuilder.cs 85.71% <100.00%> (+1.26%) ⬆️
... and 3 more

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 e4d8dd3...83309c2. Read the comment docs.

@freezy freezy self-assigned this Jan 18, 2021
@freezy freezy added editor Editor-related changes for Unity player Related to the player refactoring Ugly code that needs to go labels Jan 18, 2021
@freezy freezy merged commit 107e8f6 into master Jan 19, 2021
@freezy freezy deleted the feature/lamp-manager branch January 19, 2021 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

editor Editor-related changes for Unity player Related to the player refactoring Ugly code that needs to go

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants