From 21e5cfe8d2c2ef55d16406918d2fe02bb76e011b Mon Sep 17 00:00:00 2001 From: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Date: Sun, 19 Sep 2021 08:21:52 +0100 Subject: [PATCH] Adds the interrupt signal to the delay component, reorganises BCI files and circuit code improvements (#61393) Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> --- code/game/machinery/computer/crew.dm | 8 +++--- .../machinery/computer/launchpad_control.dm | 8 +++--- code/game/machinery/computer/security.dm | 16 +++++------ code/game/machinery/computer/teleporter.dm | 8 +++--- code/game/machinery/computer/tram_controls.dm | 8 +++--- code/game/machinery/quantum_pad.dm | 8 +++--- .../atmospherics/machinery/airalarm.dm | 8 +++--- code/modules/recycling/conveyor2.dm | 8 +++--- .../components/{ => bci}/hud/bar_overlay.dm | 0 .../{ => bci}/hud/counter_overlay.dm | 0 .../{ => bci}/hud/object_overlay.dm | 0 .../{ => bci}/hud/target_intercept.dm | 0 .../wiremod/components/utility/delay.dm | 27 +++++++++++++------ code/modules/wiremod/core/component.dm | 16 +++++++++-- code/modules/wiremod/shell/scanner_gate.dm | 8 ++---- tgstation.dme | 8 +++--- 16 files changed, 75 insertions(+), 56 deletions(-) rename code/modules/wiremod/components/{ => bci}/hud/bar_overlay.dm (100%) rename code/modules/wiremod/components/{ => bci}/hud/counter_overlay.dm (100%) rename code/modules/wiremod/components/{ => bci}/hud/object_overlay.dm (100%) rename code/modules/wiremod/components/{ => bci}/hud/target_intercept.dm (100%) diff --git a/code/game/machinery/computer/crew.dm b/code/game/machinery/computer/crew.dm index 35b73f74fa1..6c3fab9fef2 100644 --- a/code/game/machinery/computer/crew.dm +++ b/code/game/machinery/computer/crew.dm @@ -33,12 +33,12 @@ /obj/item/circuit_component/medical_console_data/populate_ports() records = add_output_port("Crew Monitoring Data", PORT_TYPE_TABLE) -/obj/item/circuit_component/medical_console_data/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/medical_console_data/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/computer/crew)) - attached_console = parent + if(istype(shell, /obj/machinery/computer/crew)) + attached_console = shell -/obj/item/circuit_component/medical_console_data/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/medical_console_data/unregister_usb_parent(atom/movable/shell) attached_console = null return ..() diff --git a/code/game/machinery/computer/launchpad_control.dm b/code/game/machinery/computer/launchpad_control.dm index c3f1fe9a53d..060112d55ed 100644 --- a/code/game/machinery/computer/launchpad_control.dm +++ b/code/game/machinery/computer/launchpad_control.dm @@ -58,12 +58,12 @@ why_fail = add_output_port("Fail reason", PORT_TYPE_STRING) on_fail = add_output_port("Failed", PORT_TYPE_SIGNAL) -/obj/item/circuit_component/bluespace_launchpad/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/bluespace_launchpad/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/computer/launchpad)) - attached_console = parent + if(istype(shell, /obj/machinery/computer/launchpad)) + attached_console = shell -/obj/item/circuit_component/bluespace_launchpad/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/bluespace_launchpad/unregister_usb_parent(atom/movable/shell) attached_console = null return ..() diff --git a/code/game/machinery/computer/security.dm b/code/game/machinery/computer/security.dm index 49d3df78c76..b846128d8cc 100644 --- a/code/game/machinery/computer/security.dm +++ b/code/game/machinery/computer/security.dm @@ -50,12 +50,12 @@ records = add_output_port("Security Records", PORT_TYPE_TABLE) on_fail = add_output_port("Failed", PORT_TYPE_SIGNAL) -/obj/item/circuit_component/arrest_console_data/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/arrest_console_data/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/computer/secure_data)) - attached_console = parent + if(istype(shell, /obj/machinery/computer/secure_data)) + attached_console = shell -/obj/item/circuit_component/arrest_console_data/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/arrest_console_data/unregister_usb_parent(atom/movable/shell) attached_console = null return ..() @@ -121,12 +121,12 @@ var/obj/machinery/computer/secure_data/attached_console -/obj/item/circuit_component/arrest_console_arrest/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/arrest_console_arrest/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/computer/secure_data)) - attached_console = parent + if(istype(shell, /obj/machinery/computer/secure_data)) + attached_console = shell -/obj/item/circuit_component/arrest_console_arrest/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/arrest_console_arrest/unregister_usb_parent(atom/movable/shell) attached_console = null return ..() diff --git a/code/game/machinery/computer/teleporter.dm b/code/game/machinery/computer/teleporter.dm index 2331f4a0b13..5f70dc2dcd5 100644 --- a/code/game/machinery/computer/teleporter.dm +++ b/code/game/machinery/computer/teleporter.dm @@ -237,16 +237,16 @@ possible_targets = add_output_port("Possible Targets", PORT_TYPE_LIST) on_fail = add_output_port("Failed", PORT_TYPE_SIGNAL) -/obj/item/circuit_component/teleporter_control_console/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/teleporter_control_console/register_usb_parent(atom/movable/shell) . = ..() - if (istype(parent, /obj/machinery/computer/teleporter)) - attached_console = parent + if (istype(shell, /obj/machinery/computer/teleporter)) + attached_console = shell RegisterSignal(attached_console, COMSIG_TELEPORTER_NEW_TARGET, .proc/on_teleporter_new_target) update_targets() -/obj/item/circuit_component/teleporter_control_console/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/teleporter_control_console/unregister_usb_parent(atom/movable/shell) UnregisterSignal(attached_console, COMSIG_TELEPORTER_NEW_TARGET) attached_console = null return attached_console diff --git a/code/game/machinery/computer/tram_controls.dm b/code/game/machinery/computer/tram_controls.dm index 01cc0f7d552..74fa7ee4289 100644 --- a/code/game/machinery/computer/tram_controls.dm +++ b/code/game/machinery/computer/tram_controls.dm @@ -134,15 +134,15 @@ location = add_output_port("Location", PORT_TYPE_STRING) travelling_output = add_output_port("Travelling", PORT_TYPE_NUMBER) -/obj/item/circuit_component/tram_controls/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/tram_controls/register_usb_parent(atom/movable/shell) . = ..() - if (istype(parent, /obj/machinery/computer/tram_controls)) - computer = parent + if (istype(shell, /obj/machinery/computer/tram_controls)) + computer = shell var/obj/structure/industrial_lift/tram/central/tram_part = computer.tram_ref?.resolve() RegisterSignal(tram_part, COMSIG_TRAM_SET_TRAVELLING, .proc/on_tram_set_travelling) RegisterSignal(tram_part, COMSIG_TRAM_TRAVEL, .proc/on_tram_travel) -/obj/item/circuit_component/tram_controls/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/tram_controls/unregister_usb_parent(atom/movable/shell) var/obj/structure/industrial_lift/tram/central/tram_part = computer.tram_ref?.resolve() computer = null UnregisterSignal(tram_part, list(COMSIG_TRAM_SET_TRAVELLING, COMSIG_TRAM_TRAVEL)) diff --git a/code/game/machinery/quantum_pad.dm b/code/game/machinery/quantum_pad.dm index e169a1d4f1d..e943e061bdb 100644 --- a/code/game/machinery/quantum_pad.dm +++ b/code/game/machinery/quantum_pad.dm @@ -211,12 +211,12 @@ target_pad = add_input_port("Target Pad", PORT_TYPE_ATOM) failed = add_output_port("On Fail", PORT_TYPE_SIGNAL) -/obj/item/circuit_component/quantumpad/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/quantumpad/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/quantumpad)) - attached_pad = parent + if(istype(shell, /obj/machinery/quantumpad)) + attached_pad = shell -/obj/item/circuit_component/quantumpad/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/quantumpad/unregister_usb_parent(atom/movable/shell) attached_pad = null return ..() diff --git a/code/modules/atmospherics/machinery/airalarm.dm b/code/modules/atmospherics/machinery/airalarm.dm index 2582ad87e5c..8320f12ab12 100644 --- a/code/modules/atmospherics/machinery/airalarm.dm +++ b/code/modules/atmospherics/machinery/airalarm.dm @@ -950,12 +950,12 @@ air_alarm_options = add_option_port("Air Alarm Options", component_options) options_map = component_options -/obj/item/circuit_component/air_alarm/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/air_alarm/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/airalarm)) - connected_alarm = parent + if(istype(shell, /obj/machinery/airalarm)) + connected_alarm = shell -/obj/item/circuit_component/air_alarm/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/air_alarm/unregister_usb_parent(atom/movable/shell) connected_alarm = null return ..() diff --git a/code/modules/recycling/conveyor2.dm b/code/modules/recycling/conveyor2.dm index 0ced1d45e89..cc92f5c404c 100644 --- a/code/modules/recycling/conveyor2.dm +++ b/code/modules/recycling/conveyor2.dm @@ -474,12 +474,12 @@ GLOBAL_LIST_EMPTY(conveyors_by_id) . = ..() . += create_ui_notice("Conveyor direction 0 means that it is stopped, 1 means that it is active and -1 means that it is working in reverse mode", "orange", "info") -/obj/item/circuit_component/conveyor_switch/register_usb_parent(atom/movable/parent) +/obj/item/circuit_component/conveyor_switch/register_usb_parent(atom/movable/shell) . = ..() - if(istype(parent, /obj/machinery/conveyor_switch)) - attached_switch = parent + if(istype(shell, /obj/machinery/conveyor_switch)) + attached_switch = shell -/obj/item/circuit_component/conveyor_switch/unregister_usb_parent(atom/movable/parent) +/obj/item/circuit_component/conveyor_switch/unregister_usb_parent(atom/movable/shell) attached_switch = null return ..() diff --git a/code/modules/wiremod/components/hud/bar_overlay.dm b/code/modules/wiremod/components/bci/hud/bar_overlay.dm similarity index 100% rename from code/modules/wiremod/components/hud/bar_overlay.dm rename to code/modules/wiremod/components/bci/hud/bar_overlay.dm diff --git a/code/modules/wiremod/components/hud/counter_overlay.dm b/code/modules/wiremod/components/bci/hud/counter_overlay.dm similarity index 100% rename from code/modules/wiremod/components/hud/counter_overlay.dm rename to code/modules/wiremod/components/bci/hud/counter_overlay.dm diff --git a/code/modules/wiremod/components/hud/object_overlay.dm b/code/modules/wiremod/components/bci/hud/object_overlay.dm similarity index 100% rename from code/modules/wiremod/components/hud/object_overlay.dm rename to code/modules/wiremod/components/bci/hud/object_overlay.dm diff --git a/code/modules/wiremod/components/hud/target_intercept.dm b/code/modules/wiremod/components/bci/hud/target_intercept.dm similarity index 100% rename from code/modules/wiremod/components/hud/target_intercept.dm rename to code/modules/wiremod/components/bci/hud/target_intercept.dm diff --git a/code/modules/wiremod/components/utility/delay.dm b/code/modules/wiremod/components/utility/delay.dm index 3319cdf148b..05e0c75ca0b 100644 --- a/code/modules/wiremod/components/utility/delay.dm +++ b/code/modules/wiremod/components/utility/delay.dm @@ -8,32 +8,43 @@ */ /obj/item/circuit_component/delay display_name = "Delay" - desc = "A component that delays a signal by a specified duration." + desc = "A component that delays a signal by a specified duration. Timer gets reset when triggered again." /// Amount to delay by var/datum/port/input/delay_amount /// Input signal to fire the delay var/datum/port/input/trigger + /// Interrupts the delay before it fires + var/datum/port/input/interrupt + + var/timer_id = TIMER_ID_NULL /// The output of the signal var/datum/port/output/output /obj/item/circuit_component/delay/populate_ports() delay_amount = add_input_port("Delay", PORT_TYPE_NUMBER, trigger = null) - trigger = add_input_port("Trigger", PORT_TYPE_SIGNAL) + trigger = add_input_port("Trigger", PORT_TYPE_SIGNAL, trigger = .proc/trigger_delay) + interrupt = add_input_port("Interrupt", PORT_TYPE_SIGNAL, trigger = .proc/interrupt_timer) output = add_output_port("Result", PORT_TYPE_SIGNAL) -/obj/item/circuit_component/delay/input_received(datum/port/input/port) - - if(!COMPONENT_TRIGGERED_BY(trigger, port)) - return - +/obj/item/circuit_component/delay/proc/trigger_delay(datum/port/input/port) + CIRCUIT_TRIGGER var/delay = delay_amount.value if(delay > COMP_DELAY_MIN_VALUE) // Convert delay into deciseconds - addtimer(CALLBACK(output, /datum/port/output.proc/set_output, trigger.value), delay*10) + timer_id = addtimer(CALLBACK(output, /datum/port/output.proc/set_output, trigger.value), delay*10, TIMER_UNIQUE|TIMER_STOPPABLE|TIMER_OVERRIDE) else + if(timer_id != TIMER_ID_NULL) + deltimer(timer_id) + timer_id = TIMER_ID_NULL output.set_output(trigger.value) +/obj/item/circuit_component/delay/proc/interrupt_timer(datum/port/input/port) + CIRCUIT_TRIGGER + if(timer_id != TIMER_ID_NULL) + deltimer(timer_id) + timer_id = TIMER_ID_NULL + #undef COMP_DELAY_MIN_VALUE diff --git a/code/modules/wiremod/core/component.dm b/code/modules/wiremod/core/component.dm index 983a26c4224..e6921e8314e 100644 --- a/code/modules/wiremod/core/component.dm +++ b/code/modules/wiremod/core/component.dm @@ -325,8 +325,20 @@ for(var/entry in entries) . += create_ui_notice("Column Name: '[entry]'", "grey", "columns") -/obj/item/circuit_component/proc/register_usb_parent(atom/movable/parent) +/** + * Called when a circuit component is added to an object with a USB port. + * + * Arguments: + * * shell - The object that USB cables can connect to + */ +/obj/item/circuit_component/proc/register_usb_parent(atom/movable/shell) return -/obj/item/circuit_component/proc/unregister_usb_parent(atom/movable/parent) +/** + * Called when a circuit component is removed from an object with a USB port. + * + * Arguments: + * * shell - The object that USB cables can connect to + */ +/obj/item/circuit_component/proc/unregister_usb_parent(atom/movable/shell) return diff --git a/code/modules/wiremod/shell/scanner_gate.dm b/code/modules/wiremod/shell/scanner_gate.dm index c925975d267..45560b76851 100644 --- a/code/modules/wiremod/shell/scanner_gate.dm +++ b/code/modules/wiremod/shell/scanner_gate.dm @@ -3,8 +3,6 @@ desc = "A gate able to perform mid-depth scans on any organisms who pass under it." icon = 'icons/obj/machines/scangate.dmi' icon_state = "scangate_black" - var/scanline_timer - var/locked = FALSE /obj/structure/scanner_gate_shell/Initialize() @@ -34,23 +32,21 @@ /obj/structure/scanner_gate_shell/proc/set_scanline(type, duration) cut_overlays() - deltimer(scanline_timer) add_overlay(type) if(duration) - scanline_timer = addtimer(CALLBACK(src, .proc/set_scanline, "passive"), duration, TIMER_STOPPABLE) + addtimer(CALLBACK(src, .proc/set_scanline, "passive"), duration, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE) /obj/item/circuit_component/scanner_gate display_name = "Scanner Gate" desc = "A gate able to perform mid-depth scans on any object that pass through it." - circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL - var/datum/port/output/scanned var/obj/structure/scanner_gate_shell/attached_gate /obj/item/circuit_component/scanner_gate/populate_ports() scanned = add_output_port("Scanned Object", PORT_TYPE_ATOM) + trigger_output = add_output_port("Triggered", PORT_TYPE_SIGNAL, order = 2) /obj/item/circuit_component/scanner_gate/register_shell(atom/movable/shell) . = ..() diff --git a/tgstation.dme b/tgstation.dme index 37330511dc0..9d01c3c77c8 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -3845,10 +3845,10 @@ #include "code\modules\wiremod\components\atom\hear.dm" #include "code\modules\wiremod\components\atom\self.dm" #include "code\modules\wiremod\components\atom\species.dm" -#include "code\modules\wiremod\components\hud\bar_overlay.dm" -#include "code\modules\wiremod\components\hud\counter_overlay.dm" -#include "code\modules\wiremod\components\hud\object_overlay.dm" -#include "code\modules\wiremod\components\hud\target_intercept.dm" +#include "code\modules\wiremod\components\bci\hud\bar_overlay.dm" +#include "code\modules\wiremod\components\bci\hud\counter_overlay.dm" +#include "code\modules\wiremod\components\bci\hud\object_overlay.dm" +#include "code\modules\wiremod\components\bci\hud\target_intercept.dm" #include "code\modules\wiremod\components\list\concat.dm" #include "code\modules\wiremod\components\list\get_column.dm" #include "code\modules\wiremod\components\list\index.dm"