Skip to content

Commit

Permalink
improved caching and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Aug 31, 2023
1 parent d561774 commit 749cad0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 106 deletions.
3 changes: 3 additions & 0 deletions code/modules/mob/living/carbon/human/human_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
///list of weakrefs of recently dropped objects
var/list/remembered_dropped_objects = list()

var/list/icon_render_keys = list()
var/static/list/icon_render_image_cache = list()

/client/var/cached_human_playtime

/client/proc/get_total_human_playtime(skip_cache = FALSE)
Expand Down
19 changes: 17 additions & 2 deletions code/modules/mob/living/carbon/human/update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,25 @@ There are several things that need to be remembered:

update_damage_overlays()

var/list/needs_update = list()
for(var/obj/limb/part as anything in limbs)
part.update_limb()

var/old_key = icon_render_keys?[part.icon_name]
icon_render_keys[part.icon_name] = part.get_limb_icon_key()
if(icon_render_keys[part.icon_name] == old_key)
continue

needs_update += part

var/list/new_limbs = list()
for(var/obj/limb/part as anything in limbs)
var/bodypart_icon = part.get_limb_icon()
new_limbs += bodypart_icon
if(part in needs_update)
var/bodypart_icon = part.get_limb_icon()
new_limbs += bodypart_icon
icon_render_image_cache[icon_render_keys[part.icon_name]] = bodypart_icon
else
new_limbs += icon_render_image_cache[icon_render_keys[part.icon_name]]

remove_overlay(BODYPARTS_LAYER)
overlays_standing[BODYPARTS_LAYER] = new_limbs
Expand Down
159 changes: 55 additions & 104 deletions code/modules/organs/limbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
var/status = LIMB_ORGANIC
var/processing = FALSE

var/ethnicity = "western"
var/body_type = "mesomorphic"

var/datum/species/species
var/limb_gender = MALE


/obj/limb/Initialize(mapload, obj/limb/P, mob/mob_owner)
. = ..()
if(P)
Expand Down Expand Up @@ -361,7 +368,7 @@

SEND_SIGNAL(src, COMSIG_LIMB_TAKEN_DAMAGE, is_ff, previous_brute, previous_burn)
owner.updatehealth()
update_icon()
owner.update_damage_overlays()
start_processing()

///Special delimbs for different limbs
Expand Down Expand Up @@ -651,7 +658,7 @@ This function completely restores a damaged organ to perfect condition.

// sync the organ's damage with its wounds
update_damages()
update_icon()
owner.update_damage_overlays()
if(wound_disappeared)
owner.update_med_icon()
remove_wound_bleeding()
Expand All @@ -670,76 +677,31 @@ This function completely restores a damaged organ to perfect condition.

number_wounds += W.amount

/obj/limb/update_icon(forced = FALSE)
if(parent && parent.status & LIMB_DESTROYED)
overlays.Cut()
icon_state = ""
return

if(status & LIMB_DESTROYED)
if(forced)
overlays.Cut()
if(has_stump_icon && !(status & LIMB_AMPUTATED))
icon = 'icons/mob/humans/dam_human.dmi'
icon_state = "stump_[icon_name]_bone"
var/image/blood_overlay = new('icons/mob/humans/dam_human.dmi', "stump_[icon_name]_blood")
blood_overlay.color = owner.species.blood_color
overlays += blood_overlay
else
icon_state = ""
return

var/race_icon = owner.species.icobase

if ((status & LIMB_ROBOT) && !(owner.species && owner.species.flags & IS_SYNTHETIC))
overlays.Cut()
icon = 'icons/mob/robotic.dmi'
icon_state = "[icon_name]"
return

var/datum/ethnicity/E = GLOB.ethnicities_list[owner.ethnicity]
var/datum/body_type/B = GLOB.body_types_list[owner.body_type]
/obj/limb/proc/update_limb()
SHOULD_CALL_PARENT(TRUE)

var/e_icon
var/b_icon
var/datum/ethnicity/owner_ethnicity = GLOB.ethnicities_list[owner.ethnicity]

if (!E)
e_icon = "western"
if(owner_ethnicity)
ethnicity = owner_ethnicity.icon_name
else
e_icon = E.icon_name
ethnicity = "western"

var/datum/body_type/owner_body_type = GLOB.body_types_list[owner.body_type]

if (!B)
b_icon = "mesomorphic"
if(owner_body_type)
body_type = owner_body_type.icon_name
else
b_icon = B.icon_name
body_type = "mesomorphic"

if(isspeciesyautja(owner))
e_icon = owner.ethnicity
b_icon = owner.body_type

icon = race_icon
icon_state = "[get_limb_icon_name(owner.species, b_icon, owner.gender, icon_name, e_icon)]"
wound_overlay.color = owner.species.blood_color

var/n_is = damage_state_text()
if (forced || n_is != damage_state)
overlays.Cut()
damage_state = n_is
update_overlays()


/obj/limb/proc/update_overlays()
var/brutestate = copytext(damage_state, 1, 2)
var/burnstate = copytext(damage_state, 2)
if(brutestate != "0")
wound_overlay.icon_state = "grayscale_[brutestate]"
overlays += wound_overlay
ethnicity = owner.ethnicity
body_type = owner.body_type

if(burnstate != "0")
burn_overlay.icon_state = "burn_[burnstate]"
overlays += burn_overlay
species = owner.species
limb_gender = owner.gender

/obj/limb/proc/get_limb_icon(dropped)
/obj/limb/proc/get_limb_icon()
SHOULD_CALL_PARENT(TRUE)
RETURN_TYPE(/list)

Expand All @@ -750,50 +712,31 @@ This function completely restores a damaged organ to perfect condition.
if(parent?.status & LIMB_DESTROYED)
return

var/image_dir = dropped ? SOUTH : NONE

if(status & LIMB_DESTROYED)
if(has_stump_icon && !(status & LIMB_AMPUTATED))
. += image('icons/mob/humans/dam_human.dmi', "stump_[icon_name]_blood", -DAMAGE_LAYER, image_dir)
. += image('icons/mob/humans/dam_human.dmi', "stump_[icon_name]_blood", -DAMAGE_LAYER)
return

var/image/limb = image(layer = -BODYPARTS_LAYER, dir = image_dir)
var/image/limb = image(layer = -BODYPARTS_LAYER)

var/race_icon = owner.species.icobase
var/race_icon = species.icobase

if ((status & LIMB_ROBOT) && !(owner.species && owner.species.flags & IS_SYNTHETIC))
limb.icon = 'icons/mob/robotic.dmi'
limb.icon_state = "[icon_name]"
. += limb
return

var/datum/ethnicity/E = GLOB.ethnicities_list[owner.ethnicity]
var/datum/body_type/B = GLOB.body_types_list[owner.body_type]

var/e_icon
var/b_icon

if (!E)
e_icon = "western"
else
e_icon = E.icon_name

if (!B)
b_icon = "mesomorphic"
else
b_icon = B.icon_name

if(isspeciesyautja(owner))
e_icon = owner.ethnicity
b_icon = owner.body_type

limb.icon = race_icon
limb.icon_state = "[get_limb_icon_name(owner.species, b_icon, owner.gender, icon_name, e_icon)]"
limb.icon_state = "[get_limb_icon_name(species, body_type, limb_gender, icon_name, ethnicity)]"

. += limb

return

/obj/limb/proc/get_limb_icon_key()
return "[species.name]-[body_type]-[limb_gender]-[icon_name]-[ethnicity]"

// new damage icon system
// returns just the brute/burn damage code
/obj/limb/proc/damage_state_text()
Expand Down Expand Up @@ -829,7 +772,7 @@ This function completely restores a damaged organ to perfect condition.
//Recursive setting of self and all child organs to amputated
/obj/limb/proc/setAmputatedTree()
status |= LIMB_AMPUTATED
update_icon(TRUE)
owner.update_body()
for(var/obj/limb/O as anything in children)
O.setAmputatedTree()

Expand Down Expand Up @@ -1195,7 +1138,7 @@ treat_grafted var tells it to apply to grafted but unsalved wounds, for burn kit
for(var/obj/limb/T as anything in children)
T.robotize(uncalibrated = uncalibrated, synth_skin = synth_skin)

update_icon(TRUE)
owner.update_body(TRUE)

/obj/limb/proc/calibrate_prosthesis()
status &= ~LIMB_UNCALIBRATED_PROSTHETIC
Expand Down Expand Up @@ -1458,29 +1401,37 @@ treat_grafted var tells it to apply to grafted but unsalved wounds, for burn kit
bandage_icon_amount = 4
var/disfigured = 0 //whether the head is disfigured.

///Specifically, damage overlays. Severed limb gore effects are applied elsewhere.
/obj/limb/head/update_overlays()
..()
var/eyes_r
var/eyes_g
var/eyes_b

var/image/eyes = new/image('icons/mob/humans/onmob/human_face.dmi', owner.species.eyes)
eyes.color = list(null, null, null, null, rgb(owner.r_eyes, owner.g_eyes, owner.b_eyes))
overlays += eyes
var/lip_style

if(owner.lip_style && (owner.species && owner.species.flags & HAS_LIPS))
var/icon/lips = new /icon('icons/mob/humans/onmob/human_face.dmi', "paint_[owner.lip_style]")
overlays += lips
/obj/limb/head/update_limb()
. = ..()

/obj/limb/head/get_limb_icon(dropped)
eyes_r = owner.r_eyes
eyes_g = owner.g_eyes
eyes_b = owner.b_eyes

lip_style = owner.lip_style

/obj/limb/head/get_limb_icon()
. = ..()

var/image/eyes = image('icons/mob/humans/onmob/human_face.dmi', owner.species.eyes, layer = -BODYPARTS_LAYER)
var/image/eyes = image('icons/mob/humans/onmob/human_face.dmi', species.eyes, layer = -BODYPARTS_LAYER)
eyes.color = list(null, null, null, null, rgb(owner.r_eyes, owner.g_eyes, owner.b_eyes))
. += eyes

if(owner.lip_style && (owner.species && owner.species.flags & HAS_LIPS))
var/image/lips = image('icons/mob/humans/onmob/human_face.dmi', "paint_[owner.lip_style]", layer = -BODYPARTS_LAYER)
if(lip_style && (species && species.flags & HAS_LIPS))
var/image/lips = image('icons/mob/humans/onmob/human_face.dmi', "paint_[lip_style]", layer = -BODYPARTS_LAYER)
. += lips

/obj/limb/head/get_limb_icon_key()
. = ..()

return "[.]-[eyes_r]-[eyes_g]-[eyes_b]-[lip_style]"

/obj/limb/head/take_damage(brute, burn, sharp, edge, used_weapon = null,\
list/forbidden_limbs = list(), no_limb_loss,\
mob/attack_source = null,\
Expand Down

0 comments on commit 749cad0

Please sign in to comment.