[MIRROR] Adds instant integrated circuit execution for event handling circuits. (#8015)

* Adds instant integrated circuit execution for event handling circuits. (#61205)

* Adds instant integrated circuit execution for event handling circuits.

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-09-06 08:07:51 -04:00
committed by GitHub
co-authored by Watermelon914
parent cfdf8bfc47
commit dc1b0d01a2
10 changed files with 183 additions and 59 deletions
+14 -4
View File
@@ -16,6 +16,9 @@
/// The name of the component shown on the UI
var/display_name = "Generic"
/// The colour this circuit component appears in the UI
var/ui_color = "blue"
/// The integrated_circuit that this component is attached to.
var/obj/item/integrated_circuit/parent
@@ -70,6 +73,8 @@
trigger_input = add_input_port("Trigger", PORT_TYPE_SIGNAL, order = 2)
if(circuit_flags & CIRCUIT_FLAG_OUTPUT_SIGNAL)
trigger_output = add_output_port("Triggered", PORT_TYPE_SIGNAL, order = 2)
if(circuit_flags & CIRCUIT_FLAG_INSTANT)
ui_color = "orange"
/obj/item/circuit_component/Destroy()
@@ -184,8 +189,9 @@
* Return value indicates whether the trigger was successful or not.
* Arguments:
* * port - Can be null. The port that sent the input
* * return_values - Only defined if the component is receiving an input due to instant execution. Contains the values to be returned once execution has stopped.
*/
/obj/item/circuit_component/proc/trigger_component(datum/port/input/port)
/obj/item/circuit_component/proc/trigger_component(datum/port/input/port, list/return_values)
SHOULD_NOT_SLEEP(TRUE)
pre_input_received(port)
if(!should_receive_input(port))
@@ -196,9 +202,9 @@
var/proc_to_call = port.trigger
if(!proc_to_call)
return FALSE
result = call(src, proc_to_call)(port)
result = call(src, proc_to_call)(port, return_values)
else
result = input_received()
result = input_received(null, return_values)
if(result)
return FALSE
@@ -248,8 +254,9 @@
* Return value indicates that the circuit should not send an output signal.
* Arguments:
* * port - Can be null. The port that sent the input
* * return_values - Only defined if the component is receiving an input due to instant execution. Contains the values to be returned once execution has stopped.
*/
/obj/item/circuit_component/proc/input_received(datum/port/input/port)
/obj/item/circuit_component/proc/input_received(datum/port/input/port, list/return_values)
SHOULD_NOT_SLEEP(TRUE)
return
@@ -274,6 +281,9 @@
/obj/item/circuit_component/proc/get_ui_notices()
. = list()
if(circuit_flags & CIRCUIT_FLAG_INSTANT)
. += create_ui_notice("Instant Execution", "red", "tachometer-alt")
if(!removable)
. += create_ui_notice("Unremovable", "red", "lock")
@@ -278,7 +278,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
"connected_to" = connected_to,
"color" = port.color,
"current_data" = current_data,
"datatype_data" = port.datatype_ui_data(user),
"datatype_data" = port.datatype_ui_data(user)
))
component_data["output_ports"] = list()
for(var/datum/port/output/port as anything in component.output_ports)
@@ -293,6 +293,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
component_data["x"] = component.rel_x
component_data["y"] = component.rel_y
component_data["removable"] = component.removable
component_data["color"] = component.ui_color
.["components"] += list(component_data)
.["variables"] = list()
+3 -3
View File
@@ -57,12 +57,12 @@
/**
* Updates the value of the input and calls input_received on the connected component
*/
/datum/port/input/proc/set_input(value)
/datum/port/input/proc/set_input(value, list/return_values)
if(QDELETED(src)) //Pain
return
set_value(value)
if(trigger)
connected_component.trigger_component(src)
connected_component.trigger_component(src, return_values)
/datum/port/output/proc/set_output(value)
set_value(value)
@@ -204,7 +204,7 @@
*/
/datum/port/input/proc/receive_value(datum/port/output/output, value)
SIGNAL_HANDLER
SScircuit_component.add_callback(CALLBACK(src, .proc/set_input, value))
SScircuit_component.add_callback(src, CALLBACK(src, .proc/set_input, value))
/// Signal handler proc to null the input if an atom is deleted. An update is not sent because this was not set by anything.
/datum/port/proc/null_value(datum/source)