Skip to content

Commit

Permalink
trying to refactor polaroid camera capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
quardbreak committed Apr 26, 2022
1 parent d3effda commit 18eb6be
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 55 deletions.
5 changes: 0 additions & 5 deletions code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
#define PROJECTILE_CONTINUE -1 //if the projectile should continue flying after calling bullet_act()
#define PROJECTILE_FORCE_MISS -2 //if the projectile should treat the attack as a miss (suppresses attack and admin logs) - only applies to mobs.

//Camera capture modes
#define CAPTURE_MODE_REGULAR 0 //Regular polaroid camera mode
#define CAPTURE_MODE_ALL 1 //Admin camera mode
#define CAPTURE_MODE_PARTIAL 3 //Simular to regular mode, but does not do dummy check

//objectives
#define CONFIG_OBJECTIVE_NONE 2
#define CONFIG_OBJECTIVE_VERB 1
Expand Down
103 changes: 57 additions & 46 deletions code/_helpers/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -872,53 +872,64 @@ The _flatIcons list is a cache for generated icon files.
result.Swap(i, gap + i)
swapped = 1
return result
/*
generate_image function generates image of specified range and location
arguments tx, ty, tz are target coordinates (requred), range defines render distance to opposite corner (requred)
cap_mode is capturing mode (optional), user is capturing mob (requred only wehen cap_mode = CAPTURE_MODE_REGULAR),
lighting determines lighting capturing (optional), suppress_errors suppreses errors and continues to capture (optional).
/**
* Generate_image function generates image of specified range and location:
* * arguments `target_x`, `target_y`, `target_z` are target coordinates (requred).
* * `range` defines render distance to opposite corner (requred).
* * lighting determines lighting capturing (optional), suppress_errors suppreses errors and continues to capture (optional).
* * `checker` is a person from which side will be perfored capture check, should be `/mob/living` target_ype.
*/
/proc/generate_image(var/tx as num, var/ty as num, var/tz as num, var/range as num, var/cap_mode = CAPTURE_MODE_PARTIAL, var/mob/living/user, var/lighting = 1, var/suppress_errors = 1)
var/list/turfstocapture = list()
//Lines below determine what tiles will be rendered
for(var/xoff = 0 to range)
for(var/yoff = 0 to range)
var/turf/T = locate(tx + xoff,ty + yoff,tz)
if(T)
if(cap_mode == CAPTURE_MODE_REGULAR)
if(user.can_capture_turf(T))
turfstocapture.Add(T)
continue
else
turfstocapture.Add(T)
/proc/create_area_image(target_x, target_y, target_z, range, show_lighting = TRUE, mob/living/checker)
// They're all should be set.
ASSERT(target_x)
ASSERT(target_y)
ASSERT(target_z)
ASSERT(range)

// - Collecting list of turfs to render -

var/list/render_turfs = list()
for(var/x_offset = 0 to range)
for(var/y_offset = 0 to range)
var/turf/T = locate(target_x + x_offset, target_y + y_offset, target_z)
if(checker && !checker?.can_capture_turf(T))
continue
else
//Capture includes non-existan turfs
if(!suppress_errors)
return
//Lines below determine what objects will be rendered
var/list/atoms = list()
for(var/turf/T in turfstocapture)
atoms.Add(T)
for(var/atom/A in T)
if(istype(A, /atom/movable/lighting_overlay) && lighting) //Special case for lighting
atoms.Add(A)
render_turfs.Add(T)

// - Collecting list of atoms to render -

var/list/render_atoms = list()
for(var/turf/T as anything in render_turfs)
render_atoms.Add(T)

for(var/atom/A as anything in T)
// In some cases we want to filter lighting overlays.
if(istype(A, /atom/movable/lighting_overlay) && show_lighting)
render_atoms.Add(A)
continue

if(!A.alpha || A.invisibility)
continue
if(A.invisibility) continue
atoms.Add(A)
//Lines below actually render all colected data
atoms = sort_atoms_by_layer(atoms)
var/icon/cap = icon('icons/effects/96x96.dmi', "")
cap.Scale(range*32, range*32)
cap.Blend("#000", ICON_OVERLAY)
for(var/atom/A in atoms)
if(A)
var/icon/img = getFlatIcon(A)
if(istype(img, /icon))
if(istype(A, /mob/living) && A:lying)
img.BecomeLying()
var/xoff = (A.x - tx) * 32
var/yoff = (A.y - ty) * 32
cap.Blend(img, blendMode2iconMode(A.blend_mode), A.pixel_x + xoff, A.pixel_y + yoff)

return cap

render_atoms.Add(A)

// - Performing rendering with collected atoms in list -

render_atoms = sort_atoms_by_layer(render_atoms)
var/icon/capture = icon('icons/effects/96x96.dmi', "")
capture.Scale(range * world.icon_size, range * world.icon_size)
capture.Blend(COLOR_BLACK, ICON_OVERLAY)
for(var/atom/A as anything in render_atoms)
var/icon/image = getFlatIcon(A)

if(ismob(A))
var/mob/M = A
if(M.lying)
image.BecomeLying()

var/x_offset = (A.x - target_x) * world.icon_size
var/y_offset = (A.y - target_y) * world.icon_size
capture.Blend(image, blendMode2iconMode(A.blend_mode), A.pixel_x + x_offset, A.pixel_y + y_offset)

return capture
6 changes: 3 additions & 3 deletions code/modules/admin/map_capture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
var/ligths = 0
if(alert("Do you want lighting to be included in capture?", "Map Capture", "No", "Yes") == "Yes")
ligths = 1
var/cap = generate_image(tx ,ty ,tz ,range, CAPTURE_MODE_PARTIAL, null, ligths, 1)
var/cap = create_area_image(tx ,ty ,tz, range, ligths)
var/file_name = "map_capture_x[tx]_y[ty]_z[tz]_r[range].png"
to_chat(usr, "Saved capture in cache as [file_name].")
send_rsc(usr, cap, file_name)
Expand All @@ -30,7 +30,7 @@

/datum/admins/proc/capture_map_capture_next(currentz, currentx, currenty, ligths)
if(locate(currentx, currenty, currentz))
var/cap = generate_image(currentx ,currenty ,currentz ,32, CAPTURE_MODE_PARTIAL, null, ligths, 1)
var/cap = create_area_image(currentx,currenty, currentz, 32, ligths)
var/file_name = "map_capture_x[currentx]_y[currenty]_z[currentz]_r32.png"
to_chat(usr, "Saved capture in cache as [file_name].")
send_rsc(usr, cap, file_name)
Expand All @@ -41,7 +41,7 @@
currenty = currenty + 32
currentx = 1
if(locate(currentx, currenty, currentz))
var/cap = generate_image(currentx ,currenty ,currentz ,32, CAPTURE_MODE_PARTIAL, null, ligths, 1)
var/cap = create_area_image(currentx,currenty, currentz, 32, ligths)
var/file_name = "map_capture_x[currentx]_y[currenty]_z[currentz]_r32.png"
to_chat(usr, "Saved capture in cache as [file_name].")
send_rsc(usr, cap, file_name)
Expand Down
4 changes: 3 additions & 1 deletion code/modules/paperwork/photography.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ var/global/photo_count = 0
var/icon_on = "camera"
var/icon_off = "camera_off"
var/size = 3

/obj/item/camera/on_update_icon()
var/datum/extension/base_icon_state/bis = get_extension(src, /datum/extension/base_icon_state)
if(on)
icon_state = "[bis.base_icon_state]"
else
icon_state = "[bis.base_icon_state]_off"

/obj/item/camera/Initialize()
set_extension(src, /datum/extension/base_icon_state, icon_state)
update_icon()
Expand Down Expand Up @@ -249,7 +251,7 @@ var/global/photo_count = 0
var/x_c = target.x - (size-1)/2
var/y_c = target.y - (size-1)/2
var/z_c = target.z
var/icon/photoimage = generate_image(x_c, y_c, z_c, size, CAPTURE_MODE_REGULAR, user, 0)
var/icon/photoimage = create_area_image(x_c, y_c, z_c, size, TRUE, user)

var/obj/item/photo/p = new()
p.img = photoimage
Expand Down

0 comments on commit 18eb6be

Please sign in to comment.