mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-07-20 12:29:23 +01:00
Documentation and stuff
Documentation, documentation, documentation. Safety checks. Reshuffled some code. Modified wifi senders and receivers to both use var/id, instead of two different vars for basically the same purpose.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
//-------------------------------
|
||||
/* Spawn sync helper
|
||||
/*
|
||||
Spawn sync helper
|
||||
|
||||
Helps syncronize spawn()ing multiple processes in loops.
|
||||
Helps syncronize spawn()ing multiple processes in loops.
|
||||
|
||||
Example for using this:
|
||||
Example for using this:
|
||||
|
||||
//Create new spawn_sync datum
|
||||
var/datum/spawn_sync/sync = new()
|
||||
@@ -12,24 +13,27 @@
|
||||
//Open a sync counter before a spawn call
|
||||
sync.open()
|
||||
spawn()
|
||||
//Utilise try/catch keywords here so the code continues even if an error occurs
|
||||
//Utilise try/catch keywords here so the code continues even if an error occurs.
|
||||
try
|
||||
//code to do stuff goes here
|
||||
O.do_stuff()
|
||||
catch
|
||||
//code here under catch is optional
|
||||
|
||||
//Close the sync counter
|
||||
//Close a sync counter
|
||||
sync.close()
|
||||
|
||||
//Call sync.finalize() after the last spawn call to finalize the syncronize process
|
||||
//Call sync.finalize() after the last spawn call to finalize the syncronize process.
|
||||
sync.finalize()
|
||||
|
||||
//Create a while loop to check if the sync is complete yet, it will return true once all the spawn threads have completed
|
||||
//Create a while loop to check if the sync is complete yet, it will return true once all the spawn threads have
|
||||
// completed.
|
||||
while(sync.check())
|
||||
//Add a sleep call to delay each check
|
||||
//Add a sleep call to delay each check.
|
||||
sleep(1)
|
||||
|
||||
//Once all the threads have closed, or the failsafe has triggered, the code will continue
|
||||
//Once all the threads have closed, or the failsafe has triggered, the code will continue. By default the failsafe
|
||||
// is aprox 10 seconds.
|
||||
*/
|
||||
//-------------------------------
|
||||
/datum/spawn_sync
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
//-------------------------------
|
||||
/*
|
||||
Wireless controller
|
||||
|
||||
Used for connecting devices to each other (i.e. machinery, doors, emitters, etc.)
|
||||
Unlike the radio controller, the wireless controller does not pass communications between devices. Once the devices
|
||||
have been connected they call each others procs directly, they do not use the wireless controller to communicate.
|
||||
|
||||
See code\modules\wireless\interfaces.dm for details of how to connect devices.
|
||||
*/
|
||||
//-------------------------------
|
||||
|
||||
var/datum/controller/process/wireless/wirelessProcess
|
||||
|
||||
/datum/controller/process/wireless
|
||||
@@ -16,29 +28,41 @@ var/datum/controller/process/wireless/wirelessProcess
|
||||
wirelessProcess = src
|
||||
|
||||
/datum/controller/process/wireless/proc/add_device(var/datum/wifi/receiver/R)
|
||||
receiver_list |= R
|
||||
if(receiver_list)
|
||||
receiver_list |= R
|
||||
else
|
||||
receiver_list = new()
|
||||
receiver_list |= R
|
||||
|
||||
/datum/controller/process/wireless/proc/remove_device(var/datum/wifi/receiver/R)
|
||||
receiver_list -= R
|
||||
if(receiver_list)
|
||||
receiver_list -= R
|
||||
|
||||
/datum/controller/process/wireless/proc/add_request(var/datum/connection_request/C)
|
||||
pending_connections += C
|
||||
if(pending_connections)
|
||||
pending_connections += C
|
||||
else
|
||||
pending_connections = new()
|
||||
pending_connections += C
|
||||
|
||||
/datum/controller/process/wireless/doWork()
|
||||
//process any pending connection requests
|
||||
if(pending_connections.len > 0)
|
||||
//any that fail are moved to the retry queue
|
||||
process_queue(pending_connections, retry_connections)
|
||||
return //quit here so the retry connection attempt is delayed
|
||||
//quit here so the retry connection attempt is delayed one cycle
|
||||
return
|
||||
|
||||
//process any connection request waiting to be retried
|
||||
//process any connection requests waiting to be retried
|
||||
if(retry_connections.len > 0)
|
||||
//any that fail are moved into the failed connections list
|
||||
process_queue(retry_connections, failed_connections)
|
||||
|
||||
/datum/controller/process/wireless/proc/process_queue(var/list/input_queue, var/list/output_queue)
|
||||
for(var/datum/connection_request/C in input_queue)
|
||||
var/target_found = 0
|
||||
for(var/datum/wifi/receiver/R in receiver_list)
|
||||
if(R.id == C.target)
|
||||
if(R.id == C.id)
|
||||
var/datum/wifi/sender/S = C.source
|
||||
S.connect_device(R)
|
||||
R.connect_device(S)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
idle_power_usage = 2
|
||||
active_power_usage = 4
|
||||
var/_wifi_id
|
||||
var/_wifi_toggle = 0
|
||||
var/_wifi_toggle = 0 //set this to 1 if you want the button to have both an on and off state, not just fire a single command
|
||||
var/datum/wifi/sender/button/wifi_sender
|
||||
|
||||
/obj/machinery/button/initialize()
|
||||
@@ -26,16 +26,17 @@
|
||||
return..()
|
||||
|
||||
/obj/machinery/button/attack_ai(mob/user as mob)
|
||||
return src.attack_hand(user)
|
||||
return attack_hand(user)
|
||||
|
||||
/obj/machinery/button/attackby(obj/item/weapon/W, mob/user as mob) return src.attack_hand(user)
|
||||
/obj/machinery/button/attackby(obj/item/weapon/W, mob/user as mob)
|
||||
return attack_hand(user)
|
||||
|
||||
/obj/machinery/button/attack_hand(mob/living/user)
|
||||
..()
|
||||
activate(user)
|
||||
|
||||
/obj/machinery/button/proc/activate(mob/living/user)
|
||||
if(operating || !wifi_sender)
|
||||
if(operating || !istype(wifi_sender))
|
||||
return
|
||||
|
||||
operating = 1
|
||||
@@ -63,6 +64,7 @@
|
||||
else
|
||||
icon_state = "launcherbtt"
|
||||
|
||||
//alternate button with the same functionality, except has a lightswitch sprite instead
|
||||
/obj/machinery/button/alternate
|
||||
icon = 'icons/obj/power.dmi'
|
||||
icon_state = "light0"
|
||||
@@ -82,7 +84,7 @@
|
||||
sender = new(_wifi_id, src)
|
||||
|
||||
/obj/machinery/button/mass_driver/activate(mob/living/user)
|
||||
if(active || !wifi_sender)
|
||||
if(active || !istype(wifi_sender))
|
||||
return
|
||||
use_power(5)
|
||||
active = 1
|
||||
@@ -102,7 +104,7 @@
|
||||
sender = new(_wifi_id, src)
|
||||
|
||||
/obj/machinery/button/door/activate(mob/living/user)
|
||||
if(operating || !wifi_sender)
|
||||
if(operating || !istype(sender))
|
||||
return
|
||||
|
||||
operating = 1
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
//-------------------------------
|
||||
// Doors
|
||||
// Sender: sends an open/close request to all connected /door receivers. Utilises spawn_sync to trigger all doors to
|
||||
// open at approximately the same time. Waits until all doors have finished opening before returning.
|
||||
// Receiver: will try to open/close the parent door when activate/deactivate is called.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/door/activate()
|
||||
var/obj/machinery/door/D = parent
|
||||
if(istype(D) && D.can_open())
|
||||
D.open()
|
||||
|
||||
/datum/wifi/receiver/button/door/deactivate()
|
||||
var/obj/machinery/door/D = parent
|
||||
if(istype(D) && D.can_close())
|
||||
D.close()
|
||||
|
||||
/datum/wifi/sender/door/proc/open()
|
||||
var/datum/spawn_sync/S = new()
|
||||
|
||||
@@ -45,15 +38,23 @@
|
||||
sleep(1)
|
||||
return
|
||||
|
||||
/datum/wifi/receiver/button/door/activate()
|
||||
var/obj/machinery/door/D = parent
|
||||
if(istype(D) && D.can_open())
|
||||
D.open()
|
||||
|
||||
/datum/wifi/receiver/button/door/deactivate()
|
||||
var/obj/machinery/door/D = parent
|
||||
if(istype(D) && D.can_close())
|
||||
D.close()
|
||||
|
||||
//-------------------------------
|
||||
// Buttons
|
||||
// Sender: intended to be used by buttons, when the button is pressed it will call activate() on all connected /button
|
||||
// receivers.
|
||||
// Receiver: does whatever the subtype does. deactivate() by default calls activate(), so you will have to override in
|
||||
// it in a subtype if you want it to do something.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/proc/activate(mob/living/user)
|
||||
|
||||
/datum/wifi/receiver/button/proc/deactivate(mob/living/user)
|
||||
activate(user) //override this if you want deactivate to actually do something
|
||||
|
||||
/datum/wifi/sender/button/proc/activate(mob/living/user)
|
||||
for(var/datum/wifi/receiver/button/B in connected_devices)
|
||||
B.activate(user)
|
||||
@@ -62,8 +63,14 @@
|
||||
for(var/datum/wifi/receiver/button/B in connected_devices)
|
||||
B.deactivate(user)
|
||||
|
||||
/datum/wifi/receiver/button/proc/activate(mob/living/user)
|
||||
|
||||
/datum/wifi/receiver/button/proc/deactivate(mob/living/user)
|
||||
activate(user) //override this if you want deactivate to actually do something
|
||||
|
||||
//-------------------------------
|
||||
// Emitter
|
||||
// Activates/deactivates the parent emitter.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/emitter/activate(mob/living/user)
|
||||
..()
|
||||
@@ -78,6 +85,7 @@
|
||||
|
||||
//-------------------------------
|
||||
// Crematorium
|
||||
// Triggers cremate() on the parent /crematorium.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/crematorium/activate(mob/living/user)
|
||||
..()
|
||||
@@ -87,6 +95,7 @@
|
||||
|
||||
//-------------------------------
|
||||
// Mounted Flash
|
||||
// Triggers flash() on the parent /flasher.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/flasher/activate(mob/living/user)
|
||||
..()
|
||||
@@ -96,6 +105,7 @@
|
||||
|
||||
//-------------------------------
|
||||
// Holosign
|
||||
// Turns the parent /holosign on/off.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/holosign/activate(mob/living/user)
|
||||
..()
|
||||
@@ -110,6 +120,7 @@
|
||||
|
||||
//-------------------------------
|
||||
// Igniter
|
||||
// Turns the parent /igniter on/off.
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/igniter/activate(mob/living/user)
|
||||
..()
|
||||
@@ -126,6 +137,7 @@
|
||||
|
||||
//-------------------------------
|
||||
// Sparker
|
||||
// Triggers the parent /sparker to ignite().
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/sparker/activate(mob/living/user)
|
||||
..()
|
||||
@@ -134,16 +146,10 @@
|
||||
S.ignite()
|
||||
|
||||
//-------------------------------
|
||||
// Mass Driver Button
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver/button/mass_driver/activate(mob/living/user)
|
||||
..()
|
||||
var/obj/machinery/mass_driver/M = parent
|
||||
if(istype(M))
|
||||
M.drive()
|
||||
|
||||
//-------------------------------
|
||||
// Mass Driver Process
|
||||
// Mass Driver
|
||||
// Sender: carries out a sequence of first opening all connected doors, then activating all connected mass drivers,
|
||||
// then closes all connected doors. It will wait before continuing the sequence after opening/closing the doors.
|
||||
// Receiver: Triggers the parent mass dirver to activate.
|
||||
//-------------------------------
|
||||
/datum/wifi/sender/mass_driver/proc/cycle()
|
||||
var/datum/spawn_sync/S = new()
|
||||
@@ -187,3 +193,9 @@
|
||||
while(S.check())
|
||||
sleep(1)
|
||||
return
|
||||
|
||||
/datum/wifi/receiver/button/mass_driver/activate(mob/living/user)
|
||||
..()
|
||||
var/obj/machinery/mass_driver/M = parent
|
||||
if(istype(M))
|
||||
M.drive()
|
||||
|
||||
@@ -1,12 +1,53 @@
|
||||
//-------------------------------
|
||||
/*
|
||||
Interfaces
|
||||
|
||||
These are the datums that an object needs to connect via the wireless controller. You will need a /wifi/receiver to
|
||||
allow other devices to connect to your device and send it instructions. You will need a /wifi/sender to send signals
|
||||
to other devices with wifi receivers. You can have multiple devices (senders and receivers) if you program your
|
||||
device to handle them.
|
||||
|
||||
Each wifi interface has one "id". This identifies which devices can connect to each other. Multiple senders can
|
||||
connect to multiple receivers as long as they have the same id.
|
||||
|
||||
Variants are found in devices.dm
|
||||
|
||||
To add a receiver to an object:
|
||||
Add the following variables to the object:
|
||||
var/_wifi_id << variable that can be configured on the map, this is passed to the receiver later
|
||||
var/datum/wifi/receiver/subtype/wifi_receiver << the receiver (and subtype itself)
|
||||
|
||||
Add or modify the objects initialize() proc to include:
|
||||
if(_wifi_id) << only creates a wifi receiver if an id is set
|
||||
wifi_receiver = new(_wifi_id, src) << this needs to be in initialize() as New() is usually too
|
||||
early, and the receiver will try to connect to the controller
|
||||
before it is setup.
|
||||
|
||||
Add or modify the objects Destroy() proc to include:
|
||||
qdel(wifi_receiver)
|
||||
wifi_receiver = null
|
||||
|
||||
Senders are setup the same way, except with a var/datum/wifi/sender/subtype/wifi_sender variable instead of (or in
|
||||
addition to) a /wifi/receiver variable.
|
||||
You will however need to call the /wifi/senders code to pass commands onto any connected receivers.
|
||||
Example:
|
||||
/obj/machinery/button/attack_hand()
|
||||
wifi_sender.activate()
|
||||
*/
|
||||
//-------------------------------
|
||||
|
||||
|
||||
//-------------------------------
|
||||
// Wifi
|
||||
//-------------------------------
|
||||
/datum/wifi
|
||||
var/obj/parent
|
||||
var/list/connected_devices
|
||||
var/id
|
||||
|
||||
/datum/wifi/New(var/obj/O)
|
||||
/datum/wifi/New(var/new_id, var/obj/O)
|
||||
connected_devices = new()
|
||||
id = new_id
|
||||
if(istype(O))
|
||||
parent = O
|
||||
|
||||
@@ -18,44 +59,41 @@
|
||||
return ..()
|
||||
|
||||
/datum/wifi/proc/connect_device(var/datum/wifi/device)
|
||||
connected_devices |= device
|
||||
if(connected_devices)
|
||||
connected_devices |= device
|
||||
else
|
||||
connected_devices = new()
|
||||
connected_devices |= device
|
||||
|
||||
/datum/wifi/proc/disconnect_device(var/datum/wifi/device)
|
||||
connected_devices -= device
|
||||
|
||||
if(connected_devices)
|
||||
connected_devices -= device
|
||||
|
||||
//-------------------------------
|
||||
// Receiver
|
||||
//-------------------------------
|
||||
/datum/wifi/receiver
|
||||
var/id
|
||||
|
||||
/datum/wifi/receiver/New(var/new_id, var/obj/O)
|
||||
..(O)
|
||||
id = new_id
|
||||
wirelessProcess.add_device(src)
|
||||
/datum/wifi/receiver/New()
|
||||
..()
|
||||
if(wirelessProcess)
|
||||
wirelessProcess.add_device(src)
|
||||
|
||||
/datum/wifi/receiver/Destroy()
|
||||
wirelessProcess.remove_device(src)
|
||||
if(wirelessProcess)
|
||||
wirelessProcess.remove_device(src)
|
||||
return ..()
|
||||
|
||||
|
||||
//-------------------------------
|
||||
// Sender
|
||||
//-------------------------------
|
||||
/datum/wifi/sender
|
||||
var/target
|
||||
|
||||
/datum/wifi/sender/New(var/new_target, var/obj/O)
|
||||
..(O)
|
||||
target = new_target
|
||||
/datum/wifi/sender/New()
|
||||
..()
|
||||
send_connection_request()
|
||||
|
||||
/datum/wifi/sender/proc/set_target(var/new_target)
|
||||
target = new_target
|
||||
id = new_target
|
||||
|
||||
/datum/wifi/sender/proc/send_connection_request()
|
||||
var/datum/connection_request/C = new(src, target)
|
||||
var/datum/connection_request/C = new(src, id)
|
||||
wirelessProcess.add_request(C)
|
||||
|
||||
|
||||
@@ -63,17 +101,18 @@
|
||||
// Connection request
|
||||
//-------------------------------
|
||||
/datum/connection_request
|
||||
var/datum/wifi/sender/source //wifi_sender object creating the request
|
||||
var/target //id tag of the target device to try to connect to
|
||||
var/datum/wifi/sender/source //wifi/sender object creating the request
|
||||
var/id //id tag of the target device(s) to try to connect to
|
||||
|
||||
/datum/connection_request/New(var/datum/wifi/sender/sender, var/receiver)
|
||||
source = sender
|
||||
target = receiver
|
||||
|
||||
if(istype(sender))
|
||||
source = sender
|
||||
id = receiver
|
||||
|
||||
//-------------------------------
|
||||
// Wireless tool (temp)
|
||||
//-------------------------------
|
||||
/*
|
||||
/obj/item/device/wireless_tool
|
||||
name = "wireless tool"
|
||||
desc = "Used for connecting machinery to controls for remote operation."
|
||||
@@ -84,3 +123,4 @@
|
||||
icon_state = "wirelesstool_on"
|
||||
else
|
||||
icon_state = "wirelesstool_off"
|
||||
*/
|
||||
Reference in New Issue
Block a user