Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camera console now uses camera manager #5310

Merged
merged 7 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/__DEFINES/dcs/signals/atom/signals_item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions code/game/camera_manager/camera_manager.dm
Drulikar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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))
mullenpaul marked this conversation as resolved.
Show resolved Hide resolved

/datum/component/camera_manager/UnregisterFromParent()
. = ..()
Expand All @@ -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
Expand All @@ -113,6 +115,10 @@
target_height = null
show_camera_static()

/datum/component/camera_manager/proc/refresh_area_camera()
SIGNAL_HANDLER
update_target_camera()
mullenpaul marked this conversation as resolved.
Show resolved Hide resolved

/datum/component/camera_manager/proc/set_camera(source, atom/target, w, h)
SIGNAL_HANDLER
render_mode = RENDER_MODE_TARGET
Expand Down
105 changes: 18 additions & 87 deletions code/game/machinery/computer/camera_console.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -160,55 +134,18 @@
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)
mullenpaul marked this conversation as resolved.
Show resolved Hide resolved

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)
var/is_living = isliving(user)
// 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
mullenpaul marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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()
Expand Down
Loading