Skip to content

Commit

Permalink
Add Push Button light sources
Browse files Browse the repository at this point in the history
- Added light sources to Push Button, Push Button (Shielded), Push Button (Mushroom), E-Stop Button, E-Stop Button (Shielded), and E-Stop Button (Circle Placard).
- Fixed bug that could allow flashing lights to fall out of sync with each other globally (Can still technically happen if individual script slow-down were to occur. Need to find a way to have the `blinkState` be static and only have one `onNextUpdate()` update it vs. all instances).
- Fixed indentation in certain NLVM files.
- Minor refactoring.
  • Loading branch information
lilkingjr1 committed Mar 9, 2024
1 parent a040f77 commit 498b404
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 67 deletions.
Binary file modified Reds-Panels-and-Operators.nl2park
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="1" g="0" b="0"/>
</usercolor>
<script>
Expand Down Expand Up @@ -52,6 +53,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -64,5 +72,12 @@
<materialpath name="estop_side_on_color">materials/estop_side_user2.nl2mat</materialpath>
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard_circle_estop">[ Placards ]/placard_circle_estop.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>estop_button</parent>
<position x="0.025" y="0.0215" z="0.0351"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
15 changes: 15 additions & 0 deletions scenery/reds_panels_and_operators/E-Stop Button (Shielded).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="1" g="0" b="0"/>
</usercolor>
<usertexture>
Expand Down Expand Up @@ -58,6 +59,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -70,5 +78,12 @@
<materialpath name="estop_side_on_color">materials/estop_side_user2.nl2mat</materialpath>
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard">[ Placards ]/placard.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>estop_button</parent>
<position x="0.025" y="0.0215" z="0.0351"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0.025" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
15 changes: 15 additions & 0 deletions scenery/reds_panels_and_operators/E-Stop Button.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="1" g="0" b="0"/>
</usercolor>
<usertexture>
Expand Down Expand Up @@ -57,6 +58,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -69,5 +77,12 @@
<materialpath name="estop_side_on_color">materials/estop_side_user2.nl2mat</materialpath>
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard">[ Placards ]/placard.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>estop_button</parent>
<position x="0.025" y="0.0215" z="0.0351"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
15 changes: 15 additions & 0 deletions scenery/reds_panels_and_operators/Push Button (Mushroom).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="0" g="1" b="0"/>
</usercolor>
<usertexture>
Expand Down Expand Up @@ -63,6 +64,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -76,5 +84,12 @@
<materialpath name="button_side_on_color">materials/estop_side_user2.nl2mat</materialpath>
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard">[ Placards ]/placard.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>button</parent>
<position x="0.025" y="0.0215" z="0.0355"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
15 changes: 15 additions & 0 deletions scenery/reds_panels_and_operators/Push Button (Shielded).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="0" g="1" b="0"/>
</usercolor>
<usertexture>
Expand Down Expand Up @@ -63,6 +64,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -77,5 +85,12 @@
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard">[ Placards ]/placard.nl2mat</materialpath>
<materialpath name="ribbed_height">materials/metal_ribbed.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>button</parent>
<position x="0.025" y="0.0195" z="0.0332"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0.025" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
15 changes: 15 additions & 0 deletions scenery/reds_panels_and_operators/Push Button.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<usercolor>
<label>Button</label>
<index>2</index>
<lightsources>light</lightsources>
<defaultcolor r="0" g="1" b="0"/>
</usercolor>
<usertexture>
Expand Down Expand Up @@ -63,6 +64,13 @@
<description>Select the special track of a ride you want this operator to move with during simulation. Set to &lt;None&gt; to disable.</description>
<label>Special Track to Attach To (Optional):</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
<id>disable_light</id>
<description>Disables the &quot;real&quot; light during simulation, possibly leading to better performance. Pilot light will still have a basic &quot;glow&quot;.</description>
<label>Disable Volumetric Light</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
<defaultvalue>false</defaultvalue>
Expand All @@ -75,5 +83,12 @@
<materialpath name="button_side_color">materials/button_side_user2.nl2mat</materialpath>
<materialpath name="metal">materials/metal.nl2mat</materialpath>
<materialpath name="placard">[ Placards ]/placard.nl2mat</materialpath>
<lightsource range="0.5" intensity="1" type="point">
<name>light</name>
<parent>button</parent>
<position x="0.025" y="0.0195" z="0.033"/>
<color r="1" g="1" b="1"/>
<halo zoffset="0" intensity="0.4" size="0.075"/>
</lightsource>
</sceneobject>
</root>
3 changes: 2 additions & 1 deletion scenery/reds_panels_and_operators/scripts/PilotLight.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PilotLight extends Script{
protected String LIGHT_ELEMENT_NAME = "pilot"; // Name of the pilot light element in the SCO/model
protected String LIGHT_OBJECT_NAME = "light"; // Name of the Scene Object Light
protected String PLACARD_ELEMENT_NAME = "placard"; // Name of the placard element in the SCO/model
protected float BLINK_INTERVAL = 0.5f; // Interval, in seconds, of the pilot light changing states when blinking

// All Pilot Light Functions:
private static final int F_STATIC_OFF = 0;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class PilotLight extends Script{
light = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT_OBJECT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);

Expand Down
6 changes: 3 additions & 3 deletions scenery/reds_panels_and_operators/scripts/PilotLight4Way.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public class PilotLight4Way extends PilotLight{
light2 = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT2_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT2_ELEMENT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);
light3 = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT3_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT3_ELEMENT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);
light4 = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT4_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT4_ELEMENT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public class PilotLightStack extends PilotLight{
light2 = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT2_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT2_ELEMENT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);
light3 = new IndicatorLight(
SceneObjectTools.getElementForName(sco, LIGHT3_ELEMENT_NAME, SCRIPT_NAME),
SceneObjectTools.getLightForName(sco, LIGHT3_ELEMENT_NAME, SCRIPT_NAME),
0.5f,
BLINK_INTERVAL,
!sco.getBooleanParameter("disable_light").boolValue()
);

Expand Down
17 changes: 14 additions & 3 deletions scenery/reds_panels_and_operators/scripts/PushButton.nlvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
Push Button NL2 Script
David Wolfe (Red-Thirten)
03/03/2024
03/08/2024
Animates the pilot light and button during run time, based on user settings.
Licensed under GNU GPLv3 - See LICENSE for more details.
*/
Expand All @@ -27,12 +27,14 @@ public class PushButton extends Script implements InteractionActionListener{
protected String SCRIPT_NAME = "PushButton"; // Script name for debugging
protected String BUTTON_ELEMENT_NAME = "button"; // Name of the button element in the SCO/model
protected String PLACARD_ELEMENT_NAME = "placard"; // Name of the placard element in the SCO/model
protected String LIGHT_OBJECT_NAME = "light"; // Name of the Scene Object Light
protected String PLC_NAME = "PLC Controller"; // Name of the PLC Controller instance expected in the sim
private static final String PLC_IND_PREFIX = "indicator"; // Prefix of the E-Stop Indicator elements & lights in the PLC SCO/model
private static final String PLC_RESET_LIGHT_NAME = "reset_ready"; // Name of the E-Stop Reset light in the PLC SCO/model
protected float BUTTON_TRAVEL_DIST = 0.008f; // Distance, in meters, the button will travel to be fully "pressed"
protected float BUTTON_TRAVEL_TIME = 1.f; // Time, in seconds, for the button to travel in and out ("speed")
protected float BUTTON_INTERACTION_RADIUS = 0.04f; // Radius, in meters, of the InteractionObject detection sphere
protected float BLINK_INTERVAL = 0.5f; // Interval, in seconds, of the pilot light changing states when blinking
protected bool BUTTON_HAS_LIGHT = true; // True if the button has a pilot light

// All Button Functions:
Expand Down Expand Up @@ -126,11 +128,18 @@ public class PushButton extends Script implements InteractionActionListener{
}

// Create OperatorButton object
Boolean booleanDisableLight = sco.getBooleanParameter("disable_light");
bool disableLight = true;
if (booleanDisableLight != null)
disableLight = booleanDisableLight.boolValue();
button = new OperatorButton(
SceneObjectTools.getElementForName(sco, BUTTON_ELEMENT_NAME, SCRIPT_NAME),
BUTTON_HAS_LIGHT,
BLINK_INTERVAL,
BUTTON_TRAVEL_DIST,
BUTTON_TRAVEL_TIME
BUTTON_TRAVEL_TIME,
sco.getLightForName(LIGHT_OBJECT_NAME),
!disableLight
);

// Function-specific checks and setup
Expand All @@ -139,9 +148,11 @@ public class PushButton extends Script implements InteractionActionListener{
// Static functions
case F_STATIC_OFF:
case F_STATIC_ON:
case F_STATIC_BLINK:
handleStaticFunc(sco);
return false;
case F_STATIC_BLINK:
handleStaticFunc(sco);
break;
// Functions that require station section
case F_DISPATCH:
case F_RESTRAINTS_OPEN:
Expand Down
Loading

0 comments on commit 498b404

Please sign in to comment.