Skip to content

Commit

Permalink
Lighting Controller (YARC-Official#718)
Browse files Browse the repository at this point in the history
* Lighting Controller

An implementation of a universal lighting controller other classes can listen to.

* Reimplementation of Stage Kit logic

* IRL Lighting Rewrite

This breaks the IRL lighting into 3 parts (Controller, Interpreter, Hardware) so that things can be expanded, extended, and added too much more easily for future support of more things.

* rewrite conclusion

* metas

* Changed how cues are created

they now are created on start and live in a list, enabled and disabled as needed.

* Changed list to dictionary which simplified the switch

* clean up

* In BeatEventHandler, moved removing items ahead of adding items
  • Loading branch information
TheFatBastid authored Apr 3, 2024
1 parent 45f1549 commit 95121a9
Show file tree
Hide file tree
Showing 23 changed files with 1,360 additions and 1,061 deletions.
2 changes: 1 addition & 1 deletion Assets/Scenes/Gameplay.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ MonoBehaviour:
m_GameObject: {fileID: 318454370}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ff8084e0e7e64cf4d965e697cc8deee6, type: 3}
m_Script: {fileID: 11500000, guid: e59b27f1aacb384409394db184ff559b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &396166999
Expand Down
13 changes: 0 additions & 13 deletions Assets/Scenes/MenuScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ GameObject:
m_Component:
- component: {fileID: 1937505654}
- component: {fileID: 1937505655}
- component: {fileID: 1937505656}
m_Layer: 0
m_Name: Menu Manager
m_TagString: Untagged
Expand Down Expand Up @@ -671,18 +670,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8e0335b9607e43008c11a3660f5cad96, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1937505656
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1937505653}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1f2d345ee0adf7e4492657083a9e67d2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1731608352421187187
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
48 changes: 35 additions & 13 deletions Assets/Scenes/PersistentScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1}
m_IndirectSpecularColor: {r: 0.12731713, g: 0.13414738, b: 0.121078536, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -982,9 +982,11 @@ GameObject:
m_Component:
- component: {fileID: 728815264}
- component: {fileID: 728815265}
- component: {fileID: 728815266}
- component: {fileID: 728815267}
- component: {fileID: 728815268}
- component: {fileID: 728815269}
- component: {fileID: 728815271}
- component: {fileID: 728815273}
- component: {fileID: 728815272}
m_Layer: 0
m_Name: Integrations
m_TagString: Untagged
Expand Down Expand Up @@ -1019,7 +1021,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 43233795acd9ae84690111f3010c5413, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &728815266
--- !u!114 &728815267
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -1028,15 +1030,10 @@ MonoBehaviour:
m_GameObject: {fileID: 728815263}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1d1faa5ee2902ba40bafec9aea861ebd, type: 3}
m_Script: {fileID: 11500000, guid: cb438f304d0d4064fb1de229c53becde, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentFogState: 0
PreviousFogState: 0
CurrentStrobeState: 0
PreviousStrobeState: 0
LargeVenue: 0
--- !u!114 &728815267
--- !u!114 &728815269
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -1045,10 +1042,35 @@ MonoBehaviour:
m_GameObject: {fileID: 728815263}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cb438f304d0d4064fb1de229c53becde, type: 3}
m_Script: {fileID: 11500000, guid: 525ce11d5f9f48a48adee4bc7515712a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &728815271
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 728815263}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e549df73151ee6b48a2700b69f0e6be2, type: 3}
m_Name:
m_EditorClassIdentifier:
<GameManager>k__BackingField: {fileID: 0}
--- !u!114 &728815272
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 728815263}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1d1faa5ee2902ba40bafec9aea861ebd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &728815268
--- !u!114 &728815273
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand Down
14 changes: 1 addition & 13 deletions Assets/Scenes/ScoreScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ Canvas:
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 25
m_SortingLayerID: 0
m_SortingOrder: 0
Expand Down Expand Up @@ -1687,7 +1688,6 @@ GameObject:
- component: {fileID: 1731608351534815122}
- component: {fileID: 1731608351534815121}
- component: {fileID: 1731608351534815136}
- component: {fileID: 1731608351534815137}
m_Layer: 5
m_Name: Score Screen
m_TagString: Untagged
Expand Down Expand Up @@ -1720,15 +1720,3 @@ MonoBehaviour:
type: 3}
_vocalsCardPrefab: {fileID: 8427776599031895052, guid: d037b5975b78e3a4481a5c9d3d7f8c35,
type: 3}
--- !u!114 &1731608351534815137
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1731608351534815135}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c544de295e7a331478e3f14f616f38c2, type: 3}
m_Name:
m_EditorClassIdentifier:
208 changes: 208 additions & 0 deletions Assets/Script/Integration/MasterLightingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
using System;
using PlasticBand.Haptics;
using UnityEngine;
using UnityEngine.SceneManagement;
using YARG.Core.Chart;
using YARG.Core.Logging;
using YARG.Gameplay;

namespace YARG.Integration
{
public class MasterLightingController : MonoBehaviour
{
/*
Real-life lighting integration works in 3 parts:
1) This class, the Master lighting controller, which maintains the state of the lighting and stage effects.
It listens for events from the venue track, sync (beat) track, etc, maintains a list of current lighting cues,
fog state, etc, and broadcasts those events on change.
2) Lighting Interpreters. These classes listen to the events from the Master Lighting Controller and translate them
into the actual timing and light patterns, for example, interpreting flare_fast as 8 blue leds turning on.
Currently there is only one lighting controller, the Stage Kit Interpreter (which uses its Cues and Primitives classes),
that attempts to make cues be as close to the Rock Band Stage Kit as possible but in the future there could others.
3) Hardware controllers. These classes listen to the Lighting Interpreters and translate the lighting cues into
the actual hardware commands. Currently there are two hardware controllers, one for DMX and one for the Stage Kits.
*/

public enum FogState
{
Off,
On,
}

public static LightingEvent CurrentLightingCue
{
get => _currentLightingCue;
set
{
PreviousLightingCue = _currentLightingCue;
_currentLightingCue = value;
OnLightingEvent?.Invoke(value);
}
}

public static LightingEvent PreviousLightingCue;

public static FogState CurrentFogState
{
get => _currentFogState;
set
{
PreviousFogState = _currentFogState;
_currentFogState = value;
OnFogState?.Invoke(value);
}
}

public static FogState PreviousFogState = FogState.Off;

public static StageKitStrobeSpeed CurrentStrobeState
{
get => _currentStrobeState;
set
{
PreviousStrobeState = _currentStrobeState;
_currentStrobeState = value;
OnStrobeEvent?.Invoke(value);
}
}

public static StageKitStrobeSpeed PreviousStrobeState = StageKitStrobeSpeed.Off;

public static DrumNote CurrentDrumNote
{
get => _currentDrumNote;
set
{
_currentDrumNote = value;
OnDrumEvent?.Invoke(value);
}
}

public static VocalNote CurrentVocalNote
{
get => _currentVocalNote;
set
{
_currentVocalNote = value;
OnVocalsEvent?.Invoke(value);
}
}

public static Beatline CurrentBeatline
{
get => _currentBeatline;
set
{
_currentBeatline = value;
OnBeatLineEvent?.Invoke(value);
}
}

public static bool Paused
{
get => _paused;
set
{
//On Pause, turn off the fog and strobe so people don't die, but leave the leds on, looks nice.
if (value)
{
CurrentFogState = FogState.Off;
CurrentStrobeState = StageKitStrobeSpeed.Off;
}
else
{
CurrentFogState = PreviousFogState;
CurrentStrobeState = PreviousStrobeState;
}

_paused = value;
OnPause?.Invoke(value);
}
}

public static bool LargeVenue
{
get => _largeVenue;
set
{
_largeVenue = value;
OnLargeVenue?.Invoke(value);
}
}

public static event Action<bool> OnPause;
public static event Action OnBonusFXEvent;
public static event Action<bool> OnLargeVenue;
public static event Action<FogState> OnFogState;
public static event Action<DrumNote> OnDrumEvent;
public static event Action<VocalNote> OnVocalsEvent;
public static event Action<Beatline> OnBeatLineEvent;
public static event Action<LightingEvent> OnLightingEvent;
public static event Action<StageKitStrobeSpeed> OnStrobeEvent;

private static bool _paused;
private static bool _largeVenue;
private static Beatline _currentBeatline;
private static DrumNote _currentDrumNote;
private static FogState _currentFogState;
private static VocalNote _currentVocalNote;
private static LightingEvent _currentLightingCue;
private static StageEffectEvent _currentStageEffect;
private static StageKitStrobeSpeed _currentStrobeState;

private GameplayBehaviour _gameplayMonitor;

private void Start()
{
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}

private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;
}

private void OnSceneUnloaded(Scene scene)
{
CurrentLightingCue = null;
CurrentFogState = FogState.Off;
CurrentStrobeState = StageKitStrobeSpeed.Off;
}

private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
switch ((SceneIndex) scene.buildIndex)
{
case SceneIndex.Gameplay:
break;

case SceneIndex.Score:
CurrentLightingCue = new LightingEvent(LightingType.Score, 0, 0);
break;

case SceneIndex.Menu:
CurrentLightingCue = new LightingEvent(LightingType.Menu, 0, 0);
break;

default:
YargLogger.LogWarning("Unknown Scene loaded!");
break;
}
}

public static void FireBonusFXEvent()
{
//This is a instantaneous event, so we don't need to keep track of it.
OnBonusFXEvent?.Invoke();
}
}
}
/*
"Dad always thought laughter was the best medicine, which I guess is why several of us died of tuberculosis."
-Jack Handey.
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 95121a9

Please sign in to comment.