Skip to content

Commit

Permalink
port(Proximity System): заменяем проверку на MOVABLE_FLAG_PROXMOVE но…
Browse files Browse the repository at this point in the history
…вым объектом
  • Loading branch information
HonkyDonky authored Mar 25, 2020
1 parent 4244bee commit 545c157
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 266 deletions.
1 change: 1 addition & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@
#include "code\game\objects\effects\misc.dm"
#include "code\game\objects\effects\overlays.dm"
#include "code\game\objects\effects\portals.dm"
#include "code\game\objects\effects\proximity.dm"
#include "code\game\objects\effects\spiders.dm"
#include "code\game\objects\effects\step_triggers.dm"
#include "code\game\objects\effects\temporary_effect.dm"
Expand Down
2 changes: 0 additions & 2 deletions code/__defines/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define ATOM_FLAG_OPEN_CONTAINER 0x0010 // Is an open container for chemistry purposes.
#define ATOM_FLAG_INITIALIZED 0x0020 // Has this atom been initialized

#define MOVABLE_FLAG_PROXMOVE 0x0001 // Does this object require proximity checking in Enter()?

#define OBJ_FLAG_ANCHORABLE 0x0001 // This object can be stuck in place with a tool
#define OBJ_FLAG_CONDUCTIBLE 0x0002 // Conducts electricity. (metal etc.)

Expand Down
6 changes: 6 additions & 0 deletions code/_helpers/game.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31

#define RANGE_TURFS(RADIUS, CENTER) \
block( \
locate(max(CENTER.x-(RADIUS),1), max(CENTER.y-(RADIUS),1), CENTER.z), \
locate(min(CENTER.x+(RADIUS),world.maxx), min(CENTER.y+(RADIUS),world.maxy), CENTER.z) \
)

/proc/dopage(src,target)
var/href_list
var/href
Expand Down
4 changes: 4 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
var/simulated = 1 //filter for actions - used by lighting overlays
var/fluorescent // Shows up under a UV light.

///Proximity monitor associated with this atom
var/datum/proximity_monitor/proximity_monitor

///Chemistry.
var/datum/reagents/reagents = null

Expand Down Expand Up @@ -65,6 +68,7 @@

/atom/Destroy()
QDEL_NULL(reagents)
QDEL_NULL(proximity_monitor)
. = ..()

/atom/proc/reveal_blood()
Expand Down
2 changes: 0 additions & 2 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
appearance_flags = TILE_BOUND
glide_size = 8

var/movable_flags

var/last_move = null
var/anchored = 0
// var/elevation = 2 - not used anywhere
Expand Down
5 changes: 4 additions & 1 deletion code/game/machinery/camera/motion.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
var/list/motionTargets = list()
var/detectTime = 0
var/alarm_delay = 100 // Don't forget, there's another 10 seconds in queueAlarm()
movable_flags = MOVABLE_FLAG_PROXMOVE

/obj/machinery/camera/Initialize()
. = ..()
proximity_monitor = new(src, 2)

/obj/machinery/camera/internal_process()
..()
Expand Down
24 changes: 13 additions & 11 deletions code/game/machinery/flasher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
var/base_state = "mflash"
anchored = 1
idle_power_usage = 2
movable_flags = MOVABLE_FLAG_PROXMOVE
var/_wifi_id
var/datum/wifi/receiver/button/flasher/wifi_receiver

Expand All @@ -30,6 +29,7 @@
. = ..()
if(_wifi_id)
wifi_receiver = new(_wifi_id, src)
proximity_monitor = new(src, 0)

/obj/machinery/flasher/Destroy()
qdel(wifi_receiver)
Expand Down Expand Up @@ -112,27 +112,29 @@
flash()
..(severity)

/obj/machinery/flasher/portable/HasProximity(atom/movable/AM as mob|obj)
if ((src.disable) || (src.last_flash && world.time < src.last_flash + 150))
/obj/machinery/flasher/portable/HasProximity(atom/movable/AM)
if (disable || (last_flash && world.time < last_flash + 150))
return

if(istype(AM, /mob/living/carbon))
if(iscarbon(AM))
var/mob/living/carbon/M = AM
if ((M.m_intent != "walk") && (src.anchored))
src.flash()
if ((M.m_intent != "walk") && (anchored))
flash()

/obj/machinery/flasher/portable/attackby(obj/item/weapon/W as obj, mob/user as mob)
/obj/machinery/flasher/portable/attackby(obj/item/weapon/W, mob/user)
if(isWrench(W))
add_fingerprint(user)
src.anchored = !src.anchored
anchored = !anchored

if (!src.anchored)
if (!anchored)
user.show_message(text("<span class='warning'>[src] can now be moved.</span>"))
src.overlays.Cut()
overlays.Cut()
proximity_monitor.SetRange(0)

else if (src.anchored)
user.show_message(text("<span class='warning'>[src] is now secured.</span>"))
src.overlays += "[base_state]-s"
overlays += "[base_state]-s"
proximity_monitor.SetRange(range)

/obj/machinery/button/flasher
name = "flasher button"
Expand Down
123 changes: 123 additions & 0 deletions code/game/objects/effects/proximity.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/datum/proximity_monitor
var/atom/host //the atom we are tracking
var/atom/hasprox_receiver //the atom that will receive HasProximity calls.
var/atom/last_host_loc
var/list/checkers //list of /obj/effect/abstract/proximity_checkers
var/current_range
var/ignore_if_not_on_turf //don't check turfs in range if the host's loc isn't a turf
var/wire = FALSE

/datum/proximity_monitor/New(atom/_host, range, _ignore_if_not_on_turf = TRUE)
checkers = list()
last_host_loc = _host.loc
ignore_if_not_on_turf = _ignore_if_not_on_turf
current_range = range
SetHost(_host)

/datum/proximity_monitor/proc/SetHost(atom/H, atom/R)
if(H == host)
return
if(host)
GLOB.moved_event.unregister(host, src, .proc/HandleMove)
if(R)
hasprox_receiver = R
else if(hasprox_receiver == host) //Default case
hasprox_receiver = H
host = H
GLOB.moved_event.register(host, src, .proc/HandleMove)
last_host_loc = host.loc
SetRange(current_range,TRUE)

/datum/proximity_monitor/Destroy()
host = null
last_host_loc = null
hasprox_receiver = null
QDEL_NULL_LIST(checkers)
return ..()

/datum/proximity_monitor/proc/HandleMove()
var/atom/_host = host
var/atom/new_host_loc = ignore_if_not_on_turf ? _host.loc : get_turf(_host)
if(last_host_loc != new_host_loc)
last_host_loc = new_host_loc //hopefully this won't cause GC issues with containers
var/curr_range = current_range
SetRange(curr_range, TRUE)
if(curr_range)
hasprox_receiver.HasProximity(host) //if we are processing, we're guaranteed to be a movable

/datum/proximity_monitor/proc/SetRange(range, force_rebuild = FALSE)
if(!force_rebuild && range == current_range)
return FALSE
. = TRUE

current_range = range

var/list/checkers_local = checkers
var/old_checkers_len = checkers_local.len

var/atom/_host = host

var/atom/loc_to_use = ignore_if_not_on_turf ? _host.loc : get_turf(_host)
if(wire && !isturf(loc_to_use)) //it makes assemblies attached on wires work
loc_to_use = get_turf(loc_to_use)
if(!isturf(loc_to_use)) //only check the host's loc
if(range)
var/obj/effect/abstract/proximity_checker/pc
if(old_checkers_len)
pc = checkers_local[old_checkers_len]
--checkers_local.len
QDEL_NULL_LIST(checkers_local)
else
pc = new(loc_to_use, src)

checkers_local += pc //only check the host's loc
return

var/list/turfs = RANGE_TURFS(range, loc_to_use)
var/turfs_len = turfs.len
var/old_checkers_used = min(turfs_len, old_checkers_len)

//reuse what we can
for(var/I in 1 to old_checkers_len)
if(I <= old_checkers_used)
var/obj/effect/abstract/proximity_checker/pc = checkers_local[I]
if(pc)
pc.loc = turfs[I]
else
checkers += new /obj/effect/abstract/proximity_checker(turfs[I], src)
else
qdel(checkers_local[I]) //delete the leftovers

if(old_checkers_len < turfs_len)
//create what we lack
for(var/I in (old_checkers_used + 1) to turfs_len)
checkers_local += new /obj/effect/abstract/proximity_checker(turfs[I], src)
else
checkers_local.Cut(old_checkers_used + 1, old_checkers_len)

// for some reasons proximity_monitor removes himself from GLOB.moved_event.event_sources
// so we want to re-check
if(!(host in GLOB.moved_event.event_sources))
GLOB.moved_event.register(host, src, .proc/HandleMove)

/obj/effect/abstract/proximity_checker
invisibility = INVISIBILITY_SYSTEM
anchored = TRUE
var/datum/proximity_monitor/monitor

/obj/effect/abstract/proximity_checker/Initialize(mapload, datum/proximity_monitor/_monitor)
. = ..()
if(_monitor)
monitor = _monitor
else
crash_with("proximity_checker created without host")
return INITIALIZE_HINT_QDEL

/obj/effect/abstract/proximity_checker/Destroy()
monitor = null
return ..()

/obj/effect/abstract/proximity_checker/Crossed(atom/movable/AM)
set waitfor = FALSE
if(monitor)
monitor.hasprox_receiver.HasProximity(AM)
16 changes: 7 additions & 9 deletions code/game/objects/items/devices/transfer_valve.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
var/mob/attacher = null
var/valve_open = 0
var/toggle = 1
movable_flags = MOVABLE_FLAG_PROXMOVE

/obj/item/device/transfer_valve/proc/process_activation(obj/item/device/D)

Expand Down Expand Up @@ -61,6 +60,8 @@
if(attached_device)
to_chat(user, "<span class='warning'>There is already an device attached to the valve, remove it first.</span>")
return
if(A.proximity_monitor)
A.proximity_monitor.SetHost(src, A)
user.remove_from_mob(item)
attached_device = A
A.forceMove(src)
Expand All @@ -75,13 +76,6 @@
SSnano.update_uis(src) // update all UIs attached to src
return


/obj/item/device/transfer_valve/HasProximity(atom/movable/AM as mob|obj)
if(!attached_device) return
attached_device.HasProximity(AM)
return


/obj/item/device/transfer_valve/attack_self(mob/user as mob)
ui_interact(user)

Expand Down Expand Up @@ -121,8 +115,12 @@
toggle_valve()
else if(attached_device)
if(href_list["rem_device"])
if(attached_device.proximity_monitor)
attached_device.proximity_monitor.SetHost(attached_device, attached_device)
if(istype(attached_device, /obj/item/device/assembly))
var/obj/item/device/assembly/A = attached_device
A.holder = null
attached_device.loc = get_turf(src)
attached_device:holder = null
attached_device = null
update_icon()
if(href_list["device"])
Expand Down
12 changes: 0 additions & 12 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ var/const/enterloopsanity = 100
M.inertia_dir = 0
M.make_floating(0) //we know we're not on solid ground so skip the checks to save a bit of processing

var/objects = 0
if(A && (A.movable_flags & MOVABLE_FLAG_PROXMOVE))
for(var/atom/movable/thing in range(1))
if(objects > enterloopsanity) break
objects++
spawn(0)
if(A)
A.HasProximity(thing, 1)
if ((thing && A) && (thing.movable_flags & MOVABLE_FLAG_PROXMOVE))
thing.HasProximity(A, 1)
return

/turf/proc/adjacent_fire_act(turf/simulated/floor/source, temperature, volume)
return

Expand Down
Loading

0 comments on commit 545c157

Please sign in to comment.