From 94715559295a854b772becac8eb92f71f98c10e1 Mon Sep 17 00:00:00 2001 From: paulrpg Date: Tue, 26 Dec 2023 15:39:31 +0000 Subject: [PATCH 1/6] camera console now uses camera manager --- .../dcs/signals/atom/signals_item.dm | 1 + code/game/camera_manager/camera_manager.dm | 6 + .../game/machinery/computer/camera_console.dm | 105 +++--------------- 3 files changed, 25 insertions(+), 87 deletions(-) diff --git a/code/__DEFINES/dcs/signals/atom/signals_item.dm b/code/__DEFINES/dcs/signals/atom/signals_item.dm index 7b3b218e658a..f0456f8dd9f6 100644 --- a/code/__DEFINES/dcs/signals/atom/signals_item.dm +++ b/code/__DEFINES/dcs/signals/atom/signals_item.dm @@ -77,3 +77,4 @@ #define COMSIG_CAMERA_SET_TARGET "camera_manager_set_target" #define COMSIG_CAMERA_SET_AREA "camera_manager_set_area" #define COMSIG_CAMERA_CLEAR "camera_manager_clear_target" +#define COMSIG_CAMERA_REFRESH "camera_manager_refresh" diff --git a/code/game/camera_manager/camera_manager.dm b/code/game/camera_manager/camera_manager.dm index 93d56aca443c..89a052ae7cd0 100644 --- a/code/game/camera_manager/camera_manager.dm +++ b/code/game/camera_manager/camera_manager.dm @@ -87,6 +87,7 @@ RegisterSignal(parent, COMSIG_CAMERA_SET_AREA, PROC_REF(set_camera_rect)) RegisterSignal(parent, COMSIG_CAMERA_SET_TARGET, PROC_REF(set_camera)) RegisterSignal(parent, COMSIG_CAMERA_CLEAR, PROC_REF(clear_camera)) + RegisterSignal(parent, COMSIG_CAMERA_REFRESH, PROC_REF(refresh_area_camera)) /datum/component/camera_manager/UnregisterFromParent() . = ..() @@ -99,6 +100,7 @@ UnregisterSignal(parent, COMSIG_CAMERA_SET_AREA) UnregisterSignal(parent, COMSIG_CAMERA_SET_TARGET) UnregisterSignal(parent, COMSIG_CAMERA_CLEAR) + UnregisterSignal(parent, COMSIG_CAMERA_REFRESH) /datum/component/camera_manager/proc/clear_camera() SIGNAL_HANDLER @@ -113,6 +115,10 @@ target_height = null show_camera_static() +/datum/component/camera_manager/proc/refresh_area_camera() + SIGNAL_HANDLER + update_target_camera() + /datum/component/camera_manager/proc/set_camera(source, atom/target, w, h) SIGNAL_HANDLER render_mode = RENDER_MODE_TARGET diff --git a/code/game/machinery/computer/camera_console.dm b/code/game/machinery/computer/camera_console.dm index cad4fd4fc747..7c9a0c6eea7d 100644 --- a/code/game/machinery/computer/camera_console.dm +++ b/code/game/machinery/computer/camera_console.dm @@ -13,58 +13,35 @@ var/list/concurrent_users = list() // Stuff needed to render the map - var/map_name - var/atom/movable/screen/map_view/cam_screen - var/atom/movable/screen/background/cam_background + var/camera_map_name var/colony_camera_mapload = TRUE var/admin_console = FALSE - /// All the plane masters that need to be applied. - var/list/cam_plane_masters - /obj/structure/machinery/computer/cameras/Initialize(mapload) . = ..() - // Map name has to start and end with an A-Z character, - // and definitely NOT with a square bracket or even a number. - // I wasted 6 hours on this. :agony: - map_name = "camera_console_[REF(src)]_map" + + RegisterSignal(src, COMSIG_CAMERA_MAPNAME_ASSIGNED, PROC_REF(camera_mapname_update)) + + // camera setup + AddComponent(/datum/component/camera_manager) + SEND_SIGNAL(src, COMSIG_CAMERA_CLEAR) if(colony_camera_mapload && mapload && is_ground_level(z)) network = list(CAMERA_NET_COLONY) - cam_plane_masters = list() - for(var/plane in subtypesof(/atom/movable/screen/plane_master) - /atom/movable/screen/plane_master/blackness) - var/atom/movable/screen/plane_master/instance = new plane() - instance.assigned_map = map_name - instance.del_on_map_removal = FALSE - if(instance.blend_mode_override) - instance.blend_mode = instance.blend_mode_override - instance.screen_loc = "[map_name]:CENTER" - cam_plane_masters += instance - - // Initialize map objects - cam_screen = new - cam_screen.icon = null - cam_screen.name = "screen" - cam_screen.assigned_map = map_name - cam_screen.del_on_map_removal = FALSE - cam_screen.screen_loc = "[map_name]:1,1" - cam_background = new - cam_background.assigned_map = map_name - cam_background.del_on_map_removal = FALSE /obj/structure/machinery/computer/cameras/Destroy() SStgui.close_uis(src) QDEL_NULL(current) - QDEL_NULL(cam_screen) - qdel(cam_screen) - QDEL_NULL(cam_background) - qdel(cam_background) + UnregisterSignal(src, COMSIG_CAMERA_MAPNAME_ASSIGNED) last_camera_turf = null concurrent_users = null return ..() +/obj/structure/machinery/computer/cameras/proc/camera_mapname_update(source, value) + camera_map_name = value + /obj/structure/machinery/computer/cameras/attack_remote(mob/user as mob) return attack_hand(user) @@ -91,8 +68,7 @@ // Update UI ui = SStgui.try_update_ui(user, src, ui) - // Update the camera, showing static if necessary and updating data if the location has moved. - update_active_camera_screen() + SEND_SIGNAL(src, COMSIG_CAMERA_REFRESH) if(!ui) var/user_ref = WEAKREF(user) @@ -104,11 +80,9 @@ // Turn on the console if(length(concurrent_users) == 1 && is_living) update_use_power(USE_POWER_ACTIVE) - // Register map objects - user.client.register_map_obj(cam_screen) - user.client.register_map_obj(cam_background) - for(var/plane in cam_plane_masters) - user.client.register_map_obj(plane) + + SEND_SIGNAL(src, COMSIG_CAMERA_REGISTER_UI, user) + // Open UI ui = new(user, src, "CameraConsole", name) ui.open() @@ -126,7 +100,7 @@ /obj/structure/machinery/computer/cameras/ui_static_data() var/list/data = list() - data["mapRef"] = map_name + data["mapRef"] = camera_map_name var/list/cameras = get_available_cameras() data["cameras"] = list() for(var/i in cameras) @@ -160,47 +134,10 @@ if(!selected_camera) return TRUE - update_active_camera_screen() + SEND_SIGNAL(src, COMSIG_CAMERA_SET_TARGET, selected_camera, selected_camera.view_range, selected_camera.view_range) return TRUE -/obj/structure/machinery/computer/cameras/proc/update_active_camera_screen() - // Show static if can't use the camera - if(!current?.can_use()) - show_camera_static() - return - - // Is this camera located in or attached to a living thing, Vehicle or helmet? If so, assume the camera's loc is the living (or non) thing. - var/cam_location = current - if(isliving(current.loc) || isVehicle(current.loc)) - cam_location = current.loc - else if(istype(current.loc, /obj/item/clothing/head/helmet/marine)) - var/obj/item/clothing/head/helmet/marine/helmet = current.loc - cam_location = helmet.loc - - // If we're not forcing an update for some reason and the cameras are in the same location, - // we don't need to update anything. - // Most security cameras will end here as they're not moving. - var/newturf = get_turf(cam_location) - if(last_camera_turf == newturf) - return - - // Cameras that get here are moving, and are likely attached to some moving atom such as cyborgs. - last_camera_turf = get_turf(cam_location) - - var/list/visible_things = current.isXRay() ? range(current.view_range, cam_location) : view(current.view_range, cam_location) - - var/list/visible_turfs = list() - for(var/turf/visible_turf in visible_things) - visible_turfs += visible_turf - - var/list/bbox = get_bbox_of_atoms(visible_turfs) - var/size_x = bbox[3] - bbox[1] + 1 - var/size_y = bbox[4] - bbox[2] + 1 - - cam_screen.vis_contents = visible_turfs - cam_background.icon_state = "clear" - cam_background.fill_rect(1, 1, size_x, size_y) /obj/structure/machinery/computer/cameras/ui_close(mob/user) var/user_ref = WEAKREF(user) @@ -208,7 +145,7 @@ // Living creature or not, we remove you anyway. concurrent_users -= user_ref // Unregister map objects - user.client.clear_map(map_name) + SEND_SIGNAL(src, COMSIG_CAMERA_UNREGISTER_UI, user) // Turn off the console if(length(concurrent_users) == 0 && is_living) current = null @@ -217,12 +154,6 @@ update_use_power(USE_POWER_IDLE) user.unset_interaction() -/obj/structure/machinery/computer/cameras/proc/show_camera_static() - cam_screen.vis_contents.Cut() - last_camera_turf = null - cam_background.icon_state = "scanline2" - cam_background.fill_rect(1, 1, DEFAULT_MAP_SIZE, DEFAULT_MAP_SIZE) - // Returns the list of cameras accessible from this computer /obj/structure/machinery/computer/cameras/proc/get_available_cameras() var/list/D = list() From 55aaa417e46157cde8d12f4a9163b5bd36651199 Mon Sep 17 00:00:00 2001 From: Paul Mullen <101871009+mullenpaul@users.noreply.github.com> Date: Sat, 30 Dec 2023 10:51:39 +0000 Subject: [PATCH 2/6] Update code/game/machinery/computer/camera_console.dm Co-authored-by: Drathek <76988376+Drulikar@users.noreply.github.com> --- code/game/machinery/computer/camera_console.dm | 1 + 1 file changed, 1 insertion(+) diff --git a/code/game/machinery/computer/camera_console.dm b/code/game/machinery/computer/camera_console.dm index 7c9a0c6eea7d..87f9a9999f21 100644 --- a/code/game/machinery/computer/camera_console.dm +++ b/code/game/machinery/computer/camera_console.dm @@ -149,6 +149,7 @@ // Turn off the console if(length(concurrent_users) == 0 && is_living) current = null + SEND_SIGNAL(src, COMSIG_CAMERA_CLEAR) last_camera_turf = null if(use_power) update_use_power(USE_POWER_IDLE) From 322dc76f362d428eca0b4b242941e22c7580881d Mon Sep 17 00:00:00 2001 From: Paul Mullen <101871009+mullenpaul@users.noreply.github.com> Date: Sat, 30 Dec 2023 10:52:17 +0000 Subject: [PATCH 3/6] Update code/game/camera_manager/camera_manager.dm Co-authored-by: Drathek <76988376+Drulikar@users.noreply.github.com> --- code/game/camera_manager/camera_manager.dm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/game/camera_manager/camera_manager.dm b/code/game/camera_manager/camera_manager.dm index 89a052ae7cd0..b418bc64d628 100644 --- a/code/game/camera_manager/camera_manager.dm +++ b/code/game/camera_manager/camera_manager.dm @@ -115,8 +115,11 @@ target_height = null show_camera_static() -/datum/component/camera_manager/proc/refresh_area_camera() +/datum/component/camera_manager/proc/refresh_camera() SIGNAL_HANDLER + if(render_mode == RENDER_MODE_AREA) + update_area_camera() + return update_target_camera() /datum/component/camera_manager/proc/set_camera(source, atom/target, w, h) From 6a8f27da172f2357bb7f852083f4e71de98b014c Mon Sep 17 00:00:00 2001 From: Paul Mullen <101871009+mullenpaul@users.noreply.github.com> Date: Sat, 30 Dec 2023 11:01:12 +0000 Subject: [PATCH 4/6] Update code/game/camera_manager/camera_manager.dm Co-authored-by: Drathek <76988376+Drulikar@users.noreply.github.com> --- code/game/camera_manager/camera_manager.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/camera_manager/camera_manager.dm b/code/game/camera_manager/camera_manager.dm index b418bc64d628..c343d8fffceb 100644 --- a/code/game/camera_manager/camera_manager.dm +++ b/code/game/camera_manager/camera_manager.dm @@ -87,7 +87,7 @@ RegisterSignal(parent, COMSIG_CAMERA_SET_AREA, PROC_REF(set_camera_rect)) RegisterSignal(parent, COMSIG_CAMERA_SET_TARGET, PROC_REF(set_camera)) RegisterSignal(parent, COMSIG_CAMERA_CLEAR, PROC_REF(clear_camera)) - RegisterSignal(parent, COMSIG_CAMERA_REFRESH, PROC_REF(refresh_area_camera)) + RegisterSignal(parent, COMSIG_CAMERA_REFRESH, PROC_REF(refresh_camera)) /datum/component/camera_manager/UnregisterFromParent() . = ..() From 0d4e9caed8b2741b8a57daff5f72cbf6a1d411f6 Mon Sep 17 00:00:00 2001 From: paulrpg Date: Sat, 30 Dec 2023 11:31:46 +0000 Subject: [PATCH 5/6] camera manager now uses target width and height --- code/game/camera_manager/camera_manager.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/camera_manager/camera_manager.dm b/code/game/camera_manager/camera_manager.dm index c343d8fffceb..53c238bcb2d2 100644 --- a/code/game/camera_manager/camera_manager.dm +++ b/code/game/camera_manager/camera_manager.dm @@ -200,7 +200,7 @@ // Cameras that get here are moving, and are likely attached to some moving atom such as cyborgs. last_camera_turf = get_turf(cam_location) - var/list/visible_things = current.isXRay() ? range(current.view_range, cam_location) : view(current.view_range, cam_location) + var/list/visible_things = current.isXRay() ? range("[target_width]x[target_height]", cam_location) : view("[target_width]x[target_height]", cam_location) render_objects(visible_things) /datum/component/camera_manager/proc/update_area_camera() From bbcc4d1e9fe0eac57f906755bbe3c12a020fc79d Mon Sep 17 00:00:00 2001 From: paulrpg Date: Sun, 28 Jan 2024 14:09:39 +0000 Subject: [PATCH 6/6] resolve view issue --- code/game/camera_manager/camera_manager.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/camera_manager/camera_manager.dm b/code/game/camera_manager/camera_manager.dm index d12ec1c36267..95292830d49b 100644 --- a/code/game/camera_manager/camera_manager.dm +++ b/code/game/camera_manager/camera_manager.dm @@ -202,7 +202,7 @@ // Cameras that get here are moving, and are likely attached to some moving atom such as cyborgs. last_camera_turf = get_turf(cam_location) - var/list/visible_things = current.isXRay() ? range("[target_width]x[target_height]", cam_location) : view("[target_width]x[target_height]", cam_location) + var/list/visible_things = current.isXRay() ? range(current.view_range, cam_location) : view(current.view_range, cam_location) render_objects(visible_things) /datum/component/camera_manager/proc/update_area_camera()