mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-21 19:17:50 +01:00
* Refactor/deduplicate camera eye code Camera Eyes previously had duplicated logic across several files. This change uncooks the spaghetti. Additionally, half-baked support for TG's multicam feature has been removed, as it was not functional or in use. * lets ff now * Camera Eye refactor fixes and finishing touches This change completes a refactor of AI eyes, which were previously used by xenobio consoles, syndicate and abductor camera consoles, shuttle docking computers, holograms, and, of course, the AI. Duplicated logic has been extracted to an abstract base mob, /mob/camera/eye, from which new types for each of the above now derive. Functionality is largely the same, with only a few minor cosmetic differences (i.e. camera eyes are now appropriately named given their type and user), as well as a quality-of-life enhancement for holograms, slowing their movement speed to base run speed to prevent users from accidentally zooming out of calls. * Camera eye refactor: Fix AI acceleration toggle The acceleration toggle was broken in the camera eye refactor, as previously the boolean was stored on the AI rather than its eye. This change fixes that. * Camera eye refactor: Fix syndicate cam visibility With the camera eye refactor, the syndicate advanced camera consoles lost the ability to view maintenance tunnels and other areas without active cameras, seeing static in their place instead (as all other cameras do). This change reinstates the original behavior. * Camera eye refactor: Convert spaces to tabs * Camera eye refactor: Fix CRLF * Apply suggestions from code review General minor code quality improvements suggested by GDNgit Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com> * Apply suggestions from code review Rename parameter names to avoid src accesses, remove an ambiguous and unused mob_define and holopad range variable from a previous WIP, change the for loop in /mob/camera/eye/relaymove to a for-to loop, and change the chat message warning, sent when an AI Eye is created on an AI that already has one, to a stack trace * Adds toggle to AI commands for fast holograms * Refactor ripped Hologram Eye relaymove Previously, the relaymove proc for hologram eyes was redundant and nearly impossible to read. It has been separated out into a few different named procs, and has had its use of `spawn` removed. * Remove unnecessary src access * Fix bug involving shuttle placement outlines The camera eye refactor that this commit is a part of introduced a bug that prevented shuttle placement outlines from showing up on first use of the shuttle console. This change fixes that bug. * Unrevert some changes from #26306 lost in merge * Remove erroneous free xray vision on advanced cams * Autodoc camera acceleration vars * Remove redundant null var initialization per code review Co-authored-by: Drsmail <60036448+Drsmail@users.noreply.github.com> Signed-off-by: asciodev <81930475+asciodev@users.noreply.github.com> * Changed variables to camel_case, autodocs, cleanup Changed a number of camera eye-related variables to camel_case style, added appropriate autodoc comments, as per code review. Also removed an unused cameranet function, modified the call signature of a cameranet function to be more semantic, and changed a qdel-on-initialize in camera eyes to return INITIALIZE_HINT_QDEL instead. Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Remove stray qdel(src) per code review Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> Signed-off-by: asciodev <81930475+asciodev@users.noreply.github.com> --------- Signed-off-by: asciodev <81930475+asciodev@users.noreply.github.com> Co-authored-by: GDN <96800819+GDNgit@users.noreply.github.com> Co-authored-by: Drsmail <60036448+Drsmail@users.noreply.github.com> Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
161 lines
5.5 KiB
Plaintext
161 lines
5.5 KiB
Plaintext
// CAMERA NET
|
|
//
|
|
// The datum containing all the chunks.
|
|
GLOBAL_DATUM_INIT(cameranet, /datum/cameranet, new())
|
|
|
|
/datum/cameranet
|
|
var/name = "Camera Net"
|
|
|
|
/// The cameras on the map, no matter if they work or not. Updated in obj/machinery/camera.dm by New() and Destroy().
|
|
var/list/cameras = list()
|
|
/// The chunks of the map, mapping the areas that the cameras can see.
|
|
var/list/chunks = list()
|
|
var/ready = FALSE
|
|
|
|
/// Returns the chunk at (x, y, z) if it exists, otherwise returns null.
|
|
/datum/cameranet/proc/chunk_generated(x, y, z)
|
|
x &= ~(CAMERA_CHUNK_SIZE - 1)
|
|
y &= ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/key = "[x],[y],[z]"
|
|
return (chunks[key])
|
|
|
|
/// Returns the chunk at (x, y, z) if it exists, otherwise returns a new chunk at that location.
|
|
/datum/cameranet/proc/get_camera_chunk(x, y, z)
|
|
x &= ~(CAMERA_CHUNK_SIZE - 1)
|
|
y &= ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/key = "[x],[y],[z]"
|
|
if(!chunks[key])
|
|
chunks[key] = new /datum/camerachunk(null, x, y, z)
|
|
|
|
return chunks[key]
|
|
|
|
/// Updates what the camera network can see.
|
|
/datum/cameranet/proc/visibility(list/moved_eyes, client/C)
|
|
if(!islist(moved_eyes))
|
|
moved_eyes = moved_eyes ? list(moved_eyes) : list()
|
|
|
|
var/list/chunks_pre_seen = list()
|
|
var/list/chunks_post_seen = list()
|
|
|
|
for(var/V in moved_eyes)
|
|
var/mob/camera/eye/eye = V
|
|
if(C)
|
|
chunks_pre_seen |= eye.visible_camera_chunks
|
|
// 0xf = 15
|
|
var/static_range = eye.static_visibility_range
|
|
var/x1 = max(0, eye.x - static_range) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/y1 = max(0, eye.y - static_range) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/x2 = min(world.maxx, eye.x + static_range) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/y2 = min(world.maxy, eye.y + static_range) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
|
|
var/list/visible_chunks = list()
|
|
|
|
for(var/x = x1; x <= x2; x += CAMERA_CHUNK_SIZE)
|
|
for(var/y = y1; y <= y2; y += CAMERA_CHUNK_SIZE)
|
|
visible_chunks |= get_camera_chunk(x, y, eye.z)
|
|
|
|
var/list/remove = eye.visible_camera_chunks - visible_chunks
|
|
var/list/add = visible_chunks - eye.visible_camera_chunks
|
|
|
|
for(var/chunk in remove)
|
|
var/datum/camerachunk/c = chunk
|
|
c.remove(eye, FALSE)
|
|
|
|
for(var/chunk in add)
|
|
var/datum/camerachunk/c = chunk
|
|
c.add(eye, FALSE)
|
|
|
|
if(C)
|
|
chunks_post_seen |= eye.visible_camera_chunks
|
|
|
|
if(C)
|
|
var/list/remove = chunks_pre_seen - chunks_post_seen
|
|
var/list/add = chunks_post_seen - chunks_pre_seen
|
|
|
|
for(var/chunk in remove)
|
|
var/datum/camerachunk/c = chunk
|
|
C.images -= c.obscured
|
|
|
|
for(var/chunk in add)
|
|
var/datum/camerachunk/c = chunk
|
|
C.images += c.obscured
|
|
|
|
|
|
/// Updates the chunks that the turf is located in. Use this when obstacles are destroyed or when doors open.
|
|
/datum/cameranet/proc/update_visibility(atom/A, opacity_check = 1)
|
|
if(!SSticker || (opacity_check && !A.opacity))
|
|
return
|
|
major_chunk_change(update = A)
|
|
|
|
/// Removes a camera from a chunk.
|
|
/datum/cameranet/proc/remove_camera(obj/machinery/camera/c)
|
|
major_chunk_change(remove = c)
|
|
|
|
/// Add a camera to a chunk.
|
|
/datum/cameranet/proc/add_camera(obj/machinery/camera/c)
|
|
major_chunk_change(add = c)
|
|
|
|
/// Refreshes the chunk location of a portable camera. Used by Cyborgs.
|
|
/datum/cameranet/proc/update_portable_camera(obj/machinery/camera/c, turf/old_loc)
|
|
major_chunk_change(add = c, old_loc = old_loc)
|
|
|
|
/// Private method for updating the chunk an atom is in, and all surrounding chunks.
|
|
/// `add` will be added as a camera to the chunk of its current location and all surrounding chunks.
|
|
/// `remove` will be removed as a camera from the chunk of its current location and all surrounding chunks.
|
|
/// `update` will not be added or removed as a camera, but its surrounding chunks will be updated.
|
|
/// These parameters are mutually exclusive.
|
|
/datum/cameranet/proc/major_chunk_change(atom/add = null, atom/remove = null, atom/update = null, turf/old_loc = null)
|
|
// 0xf = 15
|
|
if(!add && !remove && !update)
|
|
return
|
|
if(add && remove)
|
|
CRASH("Adding and removing a camera to the cameranet simultaneously is not implemented")
|
|
|
|
var/atom/c = remove
|
|
if(!c)
|
|
c = add
|
|
if(!c)
|
|
c = update
|
|
|
|
var/turf/T = get_turf(c)
|
|
if(!T)
|
|
return
|
|
|
|
// Check if the turf to add falls in the same chunk as the old_loc. If so, do nothing
|
|
if(old_loc)
|
|
if(T.x & ~(CAMERA_CHUNK_SIZE - 1) == old_loc.x & ~(CAMERA_CHUNK_SIZE - 1) && T.y & ~(CAMERA_CHUNK_SIZE - 1) == old_loc.y & ~(CAMERA_CHUNK_SIZE - 1))
|
|
return
|
|
|
|
// Use camera view distance here to actually know how far a camera can max watch
|
|
var/x1 = max(0, T.x - CAMERA_VIEW_DISTANCE) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/y1 = max(0, T.y - CAMERA_VIEW_DISTANCE) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/x2 = min(world.maxx, T.x + CAMERA_VIEW_DISTANCE) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
var/y2 = min(world.maxy, T.y + CAMERA_VIEW_DISTANCE) & ~(CAMERA_CHUNK_SIZE - 1)
|
|
|
|
for(var/x = x1; x <= x2; x += CAMERA_CHUNK_SIZE)
|
|
for(var/y = y1; y <= y2; y += CAMERA_CHUNK_SIZE)
|
|
if(chunk_generated(x, y, T.z))
|
|
var/datum/camerachunk/chunk = get_camera_chunk(x, y, T.z)
|
|
if(remove)
|
|
// Remove the camera.
|
|
chunk.remove_camera(c)
|
|
else if(add)
|
|
// You can't have the same camera in the list twice.
|
|
chunk.add_camera(c)
|
|
chunk.has_changed()
|
|
|
|
/// Returns 1 if a mob is on a viewable turf, otherwise returns 0.
|
|
/datum/cameranet/proc/check_camera_vis(mob/living/target as mob)
|
|
// 0xf = 15
|
|
var/turf/position = get_turf(target)
|
|
return check_turf_vis(position)
|
|
|
|
/datum/cameranet/proc/check_turf_vis(turf/position)
|
|
var/datum/camerachunk/chunk = get_camera_chunk(position.x, position.y, position.z)
|
|
if(chunk)
|
|
if(chunk.changed)
|
|
chunk.has_changed(1) // Update now, no matter if it's visible or not.
|
|
if(chunk.visible_turfs[position])
|
|
return 1
|
|
return 0
|