mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
Merge pull request #11202 from VOREStation/vplk-optimize-machines
Optimize machinery processing
This commit is contained in:
committed by
Chompstation Bot
parent
7fece7574f
commit
279f027dca
@@ -100,6 +100,7 @@ SUBSYSTEM_DEF(machines)
|
|||||||
if (!resumed)
|
if (!resumed)
|
||||||
src.current_run = global.pipe_networks.Copy()
|
src.current_run = global.pipe_networks.Copy()
|
||||||
//cache for sanic speed (lists are references anyways)
|
//cache for sanic speed (lists are references anyways)
|
||||||
|
var/wait = src.wait
|
||||||
var/list/current_run = src.current_run
|
var/list/current_run = src.current_run
|
||||||
while(current_run.len)
|
while(current_run.len)
|
||||||
var/datum/pipe_network/PN = current_run[current_run.len]
|
var/datum/pipe_network/PN = current_run[current_run.len]
|
||||||
@@ -117,6 +118,7 @@ SUBSYSTEM_DEF(machines)
|
|||||||
if (!resumed)
|
if (!resumed)
|
||||||
src.current_run = global.processing_machines.Copy()
|
src.current_run = global.processing_machines.Copy()
|
||||||
|
|
||||||
|
var/wait = src.wait
|
||||||
var/list/current_run = src.current_run
|
var/list/current_run = src.current_run
|
||||||
while(current_run.len)
|
while(current_run.len)
|
||||||
var/obj/machinery/M = current_run[current_run.len]
|
var/obj/machinery/M = current_run[current_run.len]
|
||||||
@@ -132,6 +134,7 @@ SUBSYSTEM_DEF(machines)
|
|||||||
if (!resumed)
|
if (!resumed)
|
||||||
src.current_run = global.powernets.Copy()
|
src.current_run = global.powernets.Copy()
|
||||||
|
|
||||||
|
var/wait = src.wait
|
||||||
var/list/current_run = src.current_run
|
var/list/current_run = src.current_run
|
||||||
while(current_run.len)
|
while(current_run.len)
|
||||||
var/datum/powernet/PN = current_run[current_run.len]
|
var/datum/powernet/PN = current_run[current_run.len]
|
||||||
@@ -151,6 +154,7 @@ SUBSYSTEM_DEF(machines)
|
|||||||
if (!resumed)
|
if (!resumed)
|
||||||
src.current_run = global.processing_power_items.Copy()
|
src.current_run = global.processing_power_items.Copy()
|
||||||
|
|
||||||
|
var/wait = src.wait
|
||||||
var/list/current_run = src.current_run
|
var/list/current_run = src.current_run
|
||||||
while(current_run.len)
|
while(current_run.len)
|
||||||
var/obj/item/I = current_run[current_run.len]
|
var/obj/item/I = current_run[current_run.len]
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
|
|
||||||
/obj/machinery/power/solar/Destroy()
|
/obj/machinery/power/solar/Destroy()
|
||||||
unset_control() //remove from control computer
|
unset_control() //remove from control computer
|
||||||
..()
|
. = ..()
|
||||||
|
|
||||||
//set the control of the panel to a given computer if closer than SOLAR_MAX_DIST
|
//set the control of the panel to a given computer if closer than SOLAR_MAX_DIST
|
||||||
/obj/machinery/power/solar/proc/set_control(var/obj/machinery/power/solar_control/SC)
|
/obj/machinery/power/solar/proc/set_control(var/obj/machinery/power/solar_control/SC)
|
||||||
|
ASSERT(!control)
|
||||||
if(SC && (get_dist(src, SC) > SOLAR_MAX_DIST))
|
if(SC && (get_dist(src, SC) > SOLAR_MAX_DIST))
|
||||||
return 0
|
return 0
|
||||||
control = SC
|
control = SC
|
||||||
@@ -50,7 +51,7 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
//set the control of the panel to null and removes it from the control list of the previous control computer if needed
|
//set the control of the panel to null and removes it from the control list of the previous control computer if needed
|
||||||
/obj/machinery/power/solar/proc/unset_control()
|
/obj/machinery/power/solar/proc/unset_control()
|
||||||
if(control)
|
if(control)
|
||||||
control.connected_panels.Remove(src)
|
control.remove_panel(src)
|
||||||
control = null
|
control = null
|
||||||
|
|
||||||
/obj/machinery/power/solar/attackby(obj/item/weapon/W, mob/user)
|
/obj/machinery/power/solar/attackby(obj/item/weapon/W, mob/user)
|
||||||
@@ -114,21 +115,16 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
sunfrac = cos(p_angle) ** 2
|
sunfrac = cos(p_angle) ** 2
|
||||||
//isn't the power recieved from the incoming light proportionnal to cos(p_angle) (Lambert's cosine law) rather than cos(p_angle)^2 ?
|
//isn't the power recieved from the incoming light proportionnal to cos(p_angle) (Lambert's cosine law) rather than cos(p_angle)^2 ?
|
||||||
|
|
||||||
/obj/machinery/power/solar/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY
|
/obj/machinery/power/solar/proc/get_power_supplied()
|
||||||
if(stat & BROKEN)
|
if(stat & BROKEN)
|
||||||
return
|
return 0
|
||||||
if(!SSsun.sun || !control) //if there's no SSsun.sun or the panel is not linked to a solar control computer, no need to proceed
|
if(!SSsun.sun || !control)
|
||||||
return
|
return 0 //if there's no SSsun.sun or the panel is not linked to a solar control computer, no need to proceed
|
||||||
|
if(!powernet || powernet != control.powernet)
|
||||||
if(powernet)
|
return 0 // We aren't connected to the controller
|
||||||
if(powernet == control.powernet)//check if the panel is still connected to the computer
|
if(obscured)
|
||||||
if(obscured) //get no light from the SSsun.sun, so don't generate power
|
return 0 //get no light from the SSsun.sun, so don't generate power
|
||||||
return
|
return GLOB.solar_gen_rate * sunfrac
|
||||||
var/sgen = GLOB.solar_gen_rate * sunfrac
|
|
||||||
add_avail(sgen)
|
|
||||||
control.gen += sgen
|
|
||||||
else //if we're no longer on the same powernet, remove from control computer
|
|
||||||
unset_control()
|
|
||||||
|
|
||||||
/obj/machinery/power/solar/proc/broken()
|
/obj/machinery/power/solar/proc/broken()
|
||||||
stat |= BROKEN
|
stat |= BROKEN
|
||||||
@@ -159,14 +155,6 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
broken()
|
broken()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
/obj/machinery/power/solar/fake/New(var/turf/loc, var/glass_type)
|
|
||||||
..(loc, glass_type, 0)
|
|
||||||
|
|
||||||
/obj/machinery/power/solar/fake/process()
|
|
||||||
. = PROCESS_KILL
|
|
||||||
return
|
|
||||||
|
|
||||||
//trace towards SSsun.sun to see if we're in shadow
|
//trace towards SSsun.sun to see if we're in shadow
|
||||||
/obj/machinery/power/solar/proc/occlusion()
|
/obj/machinery/power/solar/proc/occlusion()
|
||||||
|
|
||||||
@@ -190,6 +178,11 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
obscured = 0 // if hit the edge or stepped 20 times, not obscured
|
obscured = 0 // if hit the edge or stepped 20 times, not obscured
|
||||||
update_solar_exposure()
|
update_solar_exposure()
|
||||||
|
|
||||||
|
/// Looks nice but doesn't generate power.
|
||||||
|
/obj/machinery/power/solar/fake
|
||||||
|
|
||||||
|
/obj/machinery/power/solar/fake/get_power_supplied()
|
||||||
|
return 0
|
||||||
|
|
||||||
//
|
//
|
||||||
// Solar Assembly - For construction of solar arrays.
|
// Solar Assembly - For construction of solar arrays.
|
||||||
@@ -271,13 +264,13 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
var/id = 0
|
var/id = 0
|
||||||
var/cdir = 0
|
var/cdir = 0
|
||||||
var/targetdir = 0 // target angle in manual tracking (since it updates every game minute)
|
var/targetdir = 0 // target angle in manual tracking (since it updates every game minute)
|
||||||
var/gen = 0
|
|
||||||
var/lastgen = 0
|
|
||||||
var/track = 0 // 0= off 1=timed 2=auto (tracker)
|
var/track = 0 // 0= off 1=timed 2=auto (tracker)
|
||||||
var/trackrate = 600 // 300-900 seconds
|
var/trackrate = 600 // 300-900 seconds
|
||||||
var/nexttime = 0 // time for a panel to rotate of 1<> in manual tracking
|
var/nexttime = 0 // time for a panel to rotate of 1<> in manual tracking
|
||||||
var/obj/machinery/power/tracker/connected_tracker = null
|
var/obj/machinery/power/tracker/connected_tracker = null
|
||||||
var/list/connected_panels = list()
|
var/needs_panel_check // Powernet has been updated, need to check if panels are still connected.
|
||||||
|
var/connected_power // Sum of power supplied by connected panels.
|
||||||
|
VAR_PRIVATE/list/connected_panels = list()
|
||||||
var/auto_start = SOLAR_AUTO_START_NO
|
var/auto_start = SOLAR_AUTO_START_NO
|
||||||
|
|
||||||
// Used for mapping in solar arrays which automatically start itself.
|
// Used for mapping in solar arrays which automatically start itself.
|
||||||
@@ -318,17 +311,29 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
SC.auto_start()
|
SC.auto_start()
|
||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
|
/obj/machinery/power/solar_control/proc/add_panel(var/obj/machinery/power/solar/P)
|
||||||
|
var/sgen = P.get_power_supplied()
|
||||||
|
connected_power -= connected_panels[P] // Just in case it was already in there
|
||||||
|
connected_panels[P] = sgen
|
||||||
|
connected_power += sgen
|
||||||
|
|
||||||
|
/obj/machinery/power/solar_control/proc/remove_panel(var/obj/machinery/power/solar/P)
|
||||||
|
connected_power -= connected_panels[P]
|
||||||
|
connected_panels.Remove(P)
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/drain_power()
|
/obj/machinery/power/solar_control/drain_power()
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/disconnect_from_network()
|
/obj/machinery/power/solar_control/disconnect_from_network()
|
||||||
..()
|
. = ..()
|
||||||
GLOB.solars_list.Remove(src)
|
GLOB.solars_list.Remove(src)
|
||||||
|
needs_panel_check = TRUE
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/connect_to_network()
|
/obj/machinery/power/solar_control/connect_to_network()
|
||||||
var/to_return = ..()
|
var/to_return = ..()
|
||||||
if(powernet) //if connected and not already in solar_list...
|
if(powernet) //if connected and not already in solar_list...
|
||||||
GLOB.solars_list |= src //... add it
|
GLOB.solars_list |= src //... add it
|
||||||
|
needs_panel_check = TRUE
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
//search for unconnected panels and trackers in the computer powernet and connect them
|
//search for unconnected panels and trackers in the computer powernet and connect them
|
||||||
@@ -337,9 +342,8 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
for(var/obj/machinery/power/M in powernet.nodes)
|
for(var/obj/machinery/power/M in powernet.nodes)
|
||||||
if(istype(M, /obj/machinery/power/solar))
|
if(istype(M, /obj/machinery/power/solar))
|
||||||
var/obj/machinery/power/solar/S = M
|
var/obj/machinery/power/solar/S = M
|
||||||
if(!S.control) //i.e unconnected
|
if(!S.control && S.set_control(src)) //i.e unconnected
|
||||||
S.set_control(src)
|
add_panel(S)
|
||||||
connected_panels |= S
|
|
||||||
else if(istype(M, /obj/machinery/power/tracker))
|
else if(istype(M, /obj/machinery/power/tracker))
|
||||||
if(!connected_tracker) //if there's already a tracker connected to the computer don't add another
|
if(!connected_tracker) //if there's already a tracker connected to the computer don't add another
|
||||||
var/obj/machinery/power/tracker/T = M
|
var/obj/machinery/power/tracker/T = M
|
||||||
@@ -392,7 +396,7 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
/obj/machinery/power/solar_control/tgui_data()
|
/obj/machinery/power/solar_control/tgui_data()
|
||||||
var/data = list()
|
var/data = list()
|
||||||
|
|
||||||
data["generated"] = round(lastgen)
|
data["generated"] = round(connected_power)
|
||||||
data["generated_ratio"] = data["generated"] / round(max(connected_panels.len, 1) * GLOB.solar_gen_rate)
|
data["generated_ratio"] = data["generated"] / round(max(connected_panels.len, 1) * GLOB.solar_gen_rate)
|
||||||
|
|
||||||
data["sun_angle"] = SSsun.sun.angle
|
data["sun_angle"] = SSsun.sun.angle
|
||||||
@@ -438,9 +442,6 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
return
|
return
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/process()
|
/obj/machinery/power/solar_control/process()
|
||||||
lastgen = gen
|
|
||||||
gen = 0
|
|
||||||
|
|
||||||
if(stat & (NOPOWER | BROKEN))
|
if(stat & (NOPOWER | BROKEN))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -453,6 +454,13 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
targetdir = (targetdir + trackrate/abs(trackrate) + 360) % 360 //... do it
|
targetdir = (targetdir + trackrate/abs(trackrate) + 360) % 360 //... do it
|
||||||
nexttime += 36000/abs(trackrate) //reset the counter for the next 1<>
|
nexttime += 36000/abs(trackrate) //reset the counter for the next 1<>
|
||||||
|
|
||||||
|
if(needs_panel_check)
|
||||||
|
for(var/obj/machinery/power/solar/S in connected_panels)
|
||||||
|
if (S.powernet != powernet)
|
||||||
|
S.unset_control()
|
||||||
|
if(powernet)
|
||||||
|
add_avail(connected_power)
|
||||||
|
|
||||||
updateDialog()
|
updateDialog()
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/tgui_act(action, params)
|
/obj/machinery/power/solar_control/tgui_act(action, params)
|
||||||
@@ -501,17 +509,20 @@ GLOBAL_LIST_EMPTY(solars_list)
|
|||||||
|
|
||||||
//rotates the panel to the passed angle
|
//rotates the panel to the passed angle
|
||||||
/obj/machinery/power/solar_control/proc/set_panels(var/cdir)
|
/obj/machinery/power/solar_control/proc/set_panels(var/cdir)
|
||||||
|
var/sum = 0
|
||||||
for(var/obj/machinery/power/solar/S in connected_panels)
|
for(var/obj/machinery/power/solar/S in connected_panels)
|
||||||
S.adir = cdir //instantly rotates the panel
|
S.adir = cdir //instantly rotates the panel
|
||||||
S.occlusion()//and
|
S.occlusion()//and
|
||||||
S.update_icon() //update it
|
S.update_icon() //update it
|
||||||
|
var/sgen = S.get_power_supplied()
|
||||||
|
connected_panels[S] = sgen
|
||||||
|
sum += sgen
|
||||||
|
connected_power = sum
|
||||||
update_icon()
|
update_icon()
|
||||||
|
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/power_change()
|
/obj/machinery/power/solar_control/power_change()
|
||||||
..()
|
if((. = ..()))
|
||||||
update_icon()
|
update_icon()
|
||||||
|
|
||||||
|
|
||||||
/obj/machinery/power/solar_control/proc/broken()
|
/obj/machinery/power/solar_control/proc/broken()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
plane = TURF_PLANE
|
plane = TURF_PLANE
|
||||||
layer = ABOVE_TURF_LAYER
|
layer = ABOVE_TURF_LAYER
|
||||||
anchored = TRUE
|
anchored = TRUE
|
||||||
|
active_power_usage = 100
|
||||||
circuit = /obj/item/weapon/circuitboard/conveyor
|
circuit = /obj/item/weapon/circuitboard/conveyor
|
||||||
var/operating = OFF // 1 if running forward, -1 if backwards, 0 if off
|
var/operating = OFF // 1 if running forward, -1 if backwards, 0 if off
|
||||||
var/operable = 1 // true if can operate (no broken segments in this belt run)
|
var/operable = 1 // true if can operate (no broken segments in this belt run)
|
||||||
@@ -35,8 +36,7 @@
|
|||||||
update_dir()
|
update_dir()
|
||||||
|
|
||||||
if(on)
|
if(on)
|
||||||
operating = FORWARDS
|
set_operating(FORWARDS)
|
||||||
setmove()
|
|
||||||
|
|
||||||
default_apply_parts()
|
default_apply_parts()
|
||||||
|
|
||||||
@@ -46,13 +46,15 @@
|
|||||||
else
|
else
|
||||||
speed_process = !speed_process // switching gears
|
speed_process = !speed_process // switching gears
|
||||||
if(speed_process) // high gear
|
if(speed_process) // high gear
|
||||||
STOP_MACHINE_PROCESSING(src)
|
update_active_power_usage(initial(idle_power_usage) * 4)
|
||||||
START_PROCESSING(SSfastprocess, src)
|
|
||||||
else // low gear
|
else // low gear
|
||||||
STOP_PROCESSING(SSfastprocess, src)
|
update_active_power_usage(initial(idle_power_usage))
|
||||||
START_MACHINE_PROCESSING(src)
|
update()
|
||||||
|
|
||||||
/obj/machinery/conveyor/proc/setmove()
|
/obj/machinery/conveyor/proc/set_operating(var/new_operating)
|
||||||
|
if(new_operating == operating)
|
||||||
|
return // No change
|
||||||
|
operating = new_operating
|
||||||
if(operating == FORWARDS)
|
if(operating == FORWARDS)
|
||||||
movedir = forwards
|
movedir = forwards
|
||||||
else if(operating == BACKWARDS)
|
else if(operating == BACKWARDS)
|
||||||
@@ -77,6 +79,7 @@
|
|||||||
if(stat & BROKEN)
|
if(stat & BROKEN)
|
||||||
icon_state = "conveyor-broken"
|
icon_state = "conveyor-broken"
|
||||||
operating = OFF
|
operating = OFF
|
||||||
|
update_use_power(USE_POWER_OFF)
|
||||||
return
|
return
|
||||||
if(!operable)
|
if(!operable)
|
||||||
operating = OFF
|
operating = OFF
|
||||||
@@ -84,14 +87,25 @@
|
|||||||
operating = OFF
|
operating = OFF
|
||||||
icon_state = "conveyor[operating]"
|
icon_state = "conveyor[operating]"
|
||||||
|
|
||||||
|
if(!operating)
|
||||||
|
update_use_power(USE_POWER_OFF)
|
||||||
|
return
|
||||||
|
if(speed_process) // high gear
|
||||||
|
STOP_MACHINE_PROCESSING(src)
|
||||||
|
START_PROCESSING(SSfastprocess, src)
|
||||||
|
update_use_power(USE_POWER_ACTIVE)
|
||||||
|
else // low gear
|
||||||
|
STOP_PROCESSING(SSfastprocess, src)
|
||||||
|
START_MACHINE_PROCESSING(src)
|
||||||
|
update_use_power(USE_POWER_ACTIVE)
|
||||||
|
|
||||||
// machine process
|
// machine process
|
||||||
// move items to the target location
|
// move items to the target location
|
||||||
/obj/machinery/conveyor/process()
|
/obj/machinery/conveyor/process()
|
||||||
if(stat & (BROKEN | NOPOWER))
|
if(stat & (BROKEN | NOPOWER))
|
||||||
return
|
return PROCESS_KILL
|
||||||
if(!operating)
|
if(!operating)
|
||||||
return
|
return PROCESS_KILL
|
||||||
use_power(100)
|
|
||||||
|
|
||||||
affecting = loc.contents - src // moved items will be all in loc
|
affecting = loc.contents - src // moved items will be all in loc
|
||||||
spawn(1) // slight delay to prevent infinite propagation due to map order //TODO: please no spawn() in process(). It's a very bad idea
|
spawn(1) // slight delay to prevent infinite propagation due to map order //TODO: please no spawn() in process(). It's a very bad idea
|
||||||
@@ -177,8 +191,8 @@
|
|||||||
C.set_operable(stepdir, id, op)
|
C.set_operable(stepdir, id, op)
|
||||||
|
|
||||||
/obj/machinery/conveyor/power_change()
|
/obj/machinery/conveyor/power_change()
|
||||||
..()
|
if((. = ..()))
|
||||||
update()
|
update()
|
||||||
|
|
||||||
// the conveyor control switch
|
// the conveyor control switch
|
||||||
//
|
//
|
||||||
@@ -242,8 +256,7 @@
|
|||||||
operated = 0
|
operated = 0
|
||||||
|
|
||||||
for(var/obj/machinery/conveyor/C in conveyors)
|
for(var/obj/machinery/conveyor/C in conveyors)
|
||||||
C.operating = position
|
C.set_operating(position)
|
||||||
C.setmove()
|
|
||||||
|
|
||||||
// attack with hand, switch position
|
// attack with hand, switch position
|
||||||
/obj/machinery/conveyor_switch/attack_hand(mob/user)
|
/obj/machinery/conveyor_switch/attack_hand(mob/user)
|
||||||
|
|||||||
Reference in New Issue
Block a user