Enabled communication with Subspace transmitters and squashed bugs (#8723)

First, cycle speed of all NTSL2+ programs has been increased by a factor of, on average 10. Cycles are much faster than I gave them credit for in my original pull.

Secondly, a bug in which programs could bug out and appear on multiple computers should have been squashed.

Thirdly and most importantly, NTSL2+ can now talk to Integrated Electronics via the Subspace Transmitter Part.
when net.subscribe("channel"){print(message)} and net.message("channel", "contents") can be used for this.
This commit is contained in:
William Lemon
2020-04-25 16:43:24 +03:00
committed by GitHub
parent 5c08a085ec
commit aceffc62ed
5 changed files with 90 additions and 5 deletions
@@ -143,6 +143,7 @@
var/data = get_pin_data(IC_INPUT, 1)
if (data != null)
var/chan = "[WP_ELECTRONICS][get_pin_data(IC_INPUT, 2) || "default"]"
ntsl2.receive_subspace(chan, data)
for (var/thing in GET_LISTENERS(chan))
var/listener/L = thing
var/obj/item/integrated_circuit/transfer/wireless/W = L.target
@@ -14,7 +14,7 @@
/datum/computer_file/program/ntsl2_interpreter/process_tick()
if(istype(running))
running.cycle(5000)
running.cycle(30000)
..()
/datum/computer_file/program/ntsl2_interpreter/kill_program()
@@ -50,8 +50,8 @@
if(copytext(topc, 1, 2) == "?")
topc = copytext(topc, 2) + "?" + input("", "Enter Data")
running.topic(topc)
running.cycle(300)
. = TRUE
running.cycle(5000)
. = 1
if(href_list["PRG_refresh"])
. = TRUE
+41
View File
@@ -1,21 +1,50 @@
/datum/NTSL_interpreter
var/connected = 0
var/locked = 0 // Due to the psudo-threaded nature of Byond, two messages could be sent at the same time. This is a measure against that.
var/list/programs = list()
/datum/NTSL_interpreter/proc/attempt_connect()
locked = 0
var/res = send(list(action="clear"))
if(!res)
log_debug("NTSL2+ Daemon could not be connected to. Functionality will not be enabled.")
else
START_PROCESSING(SSfast_process, src)
connected = 1
log_debug("NTSL2+ Daemon connected successfully.")
/datum/NTSL_interpreter/proc/disconnect()
connected = 0
send(list(action="clear"))
STOP_PROCESSING(SSfast_process, src)
for(var/datum/ntsl_program/P in programs)
P.kill()
/datum/NTSL_interpreter/process()
if(connected)
var/received_message = send(list(action="subspace_transmit"))
if(received_message && received_message!="0")
var/messages = splittext(received_message, "\n")
for(var/individual_message in messages)
var/list/message_info = params2list(individual_message);
var/channel = "[WP_ELECTRONICS][message_info["channel"]]"
var/message_type = message_info["type"]
var/message_body = message_info["data"]
var/message = 0
if(message_type == "num")
message = text2num(message_body)
else if(message_type == "text")
message = html_encode(message_body)
else if(message_type == "ref")
message = locate(message_body)
for (var/thing in GET_LISTENERS(channel))
var/listener/L = thing
var/obj/item/integrated_circuit/transfer/wireless/W = L.target
if (W != src)
W.receive(message)
/datum/NTSL_interpreter/proc/new_program(var/code, var/computer, var/mob/user)
if(!connected)
return 0
@@ -28,12 +57,24 @@
return P
return 0
/datum/NTSL_interpreter/proc/receive_subspace(var/channel, var/data)
if(istext(data))
ntsl2.send(list(action="subspace_receive", channel=copytext(channel, length(WP_ELECTRONICS)+1), type="text", data=html_decode(data)))
else if(isnum(data))
ntsl2.send(list(action="subspace_receive", channel=copytext(channel, length(WP_ELECTRONICS)+1), type="num", data="[data]"))
else // Probably an object or something, just get a ref to it.
ntsl2.send(list(action="subspace_receive", channel=copytext(channel, length(WP_ELECTRONICS)+1), type="ref", data="\ref[data]"))
/*
Sends a command to the Daemon. This is an internal function, and should be avoided when used externally.
*/
/datum/NTSL_interpreter/proc/send(var/list/commands)
while(locked) // Prevent multiple requests being sent simultaneously and thus collisions.
sleep(1)
if(config.ntsl_hostname && config.ntsl_port) // Requires config to be set.
locked = 1
var/http[] = world.Export("http://[config.ntsl_hostname]:[config.ntsl_port]/[list2params(commands)]")
locked = 0
if(http)
return file2text(http["CONTENT"])
return 0
+2 -2
View File
@@ -15,12 +15,12 @@
/datum/TCS_Compiler/ntsl2/Run(var/datum/signal/signal)
if(istype(running_code))
running_code.tc_message(signal)
running_code.cycle(10000)
running_code.cycle(100000)
update_code()
/datum/TCS_Compiler/ntsl2/proc/update_code()
if(istype(running_code))
running_code.cycle(10000)
running_code.cycle(100000)
var/list/dat = json_decode(ntsl2.send(list(action="get_signals",id=running_code.id)))
if(istype(dat) && "content" in dat)
var/datum/signal/sig = null