Skip to content

Icon and filter optimization stuff #4825

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

Merged
34 changes: 22 additions & 12 deletions code/datums/datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,24 @@
* * priority - Priority used when sorting the filter.
* * params - Parameters of the filter.
*/
/datum/proc/add_filter(name, priority, list/params)
/datum/proc/add_filter(name, priority, list/params, update = TRUE)
LAZYINITLIST(filter_data)
var/list/copied_parameters = params.Copy()
copied_parameters["priority"] = priority
filter_data[name] = copied_parameters
update_filters()
if(update)
update_filters()

///A version of add_filter that takes a list of filters to add rather than being individual, to limit calls to update_filters().
/datum/proc/add_filters(list/list/filters)
/datum/proc/add_filters(list/list/filters, update = TRUE)
LAZYINITLIST(filter_data)
for(var/list/individual_filter as anything in filters)
var/list/params = individual_filter["params"]
var/list/copied_parameters = params.Copy()
copied_parameters["priority"] = individual_filter["priority"]
filter_data[individual_filter["name"]] = copied_parameters
update_filters()
if(update)
update_filters()

/// Reapplies all the filters.
/datum/proc/update_filters()
Expand All @@ -341,14 +343,15 @@
. = ..()
update_item_action_buttons()

/** Update a filter's parameter to the new one. If the filter doesnt exist we won't do anything.
/** Update a filter's parameter to the new one. If the filter doesn't exist we won't do anything.
*
* Arguments:
* * name - Filter name
* * new_params - New parameters of the filter
* * overwrite - TRUE means we replace the parameter list completely. FALSE means we only replace the things on new_params.
* * update - TRUE means we automatically call update_filters() afterwards. This should be FALSE if you're going to be doing other filter changes next.
*/
/datum/proc/modify_filter(name, list/new_params, overwrite = FALSE)
/datum/proc/modify_filter(name, list/new_params, overwrite = FALSE, update = TRUE)
var/filter = get_filter(name)
if(!filter)
return
Expand All @@ -357,9 +360,10 @@
else
for(var/thing in new_params)
filter_data[name][thing] = new_params[thing]
update_filters()
if(update)
update_filters()

/** Update a filter's parameter and animate this change. If the filter doesnt exist we won't do anything.
/** Update a filter's parameter and animate this change. If the filter doesn't exist we won't do anything.
* Basically a [datum/proc/modify_filter] call but with animations. Unmodified filter parameters are kept.
*
* Arguments:
Expand All @@ -379,12 +383,13 @@
modify_filter(name, new_params)

/// Updates the priority of the passed filter key
/datum/proc/change_filter_priority(name, new_priority)
/datum/proc/change_filter_priority(name, new_priority, update = TRUE)
if(!filter_data || !filter_data[name])
return

filter_data[name]["priority"] = new_priority
update_filters()
if(update)
update_filters()

/// Returns the filter associated with the passed key
/datum/proc/get_filter(name)
Expand All @@ -399,16 +404,21 @@
return filter_data?.Find(name)

/// Removes the passed filter, or multiple filters, if supplied with a list.
/datum/proc/remove_filter(name_or_names)
/datum/proc/remove_filter(name_or_names, update = TRUE)
if(!filter_data)
return

var/list/names = islist(name_or_names) ? name_or_names : list(name_or_names)

. = FALSE
for(var/name in names)
if(filter_data[name])
filter_data -= name
update_filters()
. = TRUE

if(. && update)
update_filters()
return .

/datum/proc/clear_filters()
ASSERT(isatom(src) || isimage(src))
Expand Down
56 changes: 35 additions & 21 deletions code/modules/mob/living/carbon/human/human_update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -950,26 +950,36 @@ generate/load female uniform sprites matching all previously decided variables
// Move the filter up if the image has been moved down, and vice versa
var/adjust_y = -appearance.pixel_y - parent_adjust_y

var/icon/cut_torso_mask = icon(mask_icon, "Cut1")
var/icon/cut_legs_mask = icon(mask_icon, "Cut2")
var/icon/lenghten_torso_mask = icon(mask_icon, "Cut3")
var/icon/lenghten_legs_mask = icon(mask_icon, "Cut4")
var/icon/lenghten_ankles_mask = icon(mask_icon, "Cut5")
var/static/list/cached_masks = list()
var/list/masks = cached_masks[mask_icon]
if(isnull(masks))
cached_masks[mask_icon] = masks = list(
icon(mask_icon, "Cut1"),
icon(mask_icon, "Cut2"),
icon(mask_icon, "Cut3"),
icon(mask_icon, "Cut4"),
icon(mask_icon, "Cut5"),
)
var/icon/cut_torso_mask = masks[1]
var/icon/cut_legs_mask = masks[2]
var/icon/lengthen_torso_mask = masks[3]
var/icon/lengthen_legs_mask = masks[4]
var/icon/lengthen_ankles_mask = masks[5]
//MONKESTATION EDIT END

appearance.remove_filter(list(
var/should_update = appearance.remove_filter(list(
"Cut_Torso",
"Cut_Legs",
"Lenghten_Ankles", // MONKESTATION ADDITION
"Lenghten_Legs",
"Lenghten_Torso",
"Lengthen_Ankles", // MONKESTATION ADDITION
"Lengthen_Legs",
"Lengthen_Torso",
"Gnome_Cut_Torso",
"Gnome_Cut_Legs",
"Monkey_Torso",
"Monkey_Legs",
"Monkey_Gnome_Cut_Torso",
"Monkey_Gnome_Cut_Legs",
))
), update = FALSE) // note: the add_filter(s) calls after this will call update_filters on their own. so by not calling it here, we avoid calling it twice.

switch(get_mob_height())
// Don't set this one directly, use TRAIT_DWARF
Expand Down Expand Up @@ -1029,40 +1039,44 @@ generate/load female uniform sprites matching all previously decided variables
if(HUMAN_HEIGHT_SHORT)
appearance.add_filter("Cut_Legs", 1, displacement_map_filter(cut_legs_mask, x = 0, y = adjust_y, size = 1))
if(HUMAN_HEIGHT_TALL)
appearance.add_filter("Lenghten_Legs", 1, displacement_map_filter(lenghten_legs_mask, x = 0, y = adjust_y, size = 1))
appearance.add_filter("Lengthen_Legs", 1, displacement_map_filter(lengthen_legs_mask, x = 0, y = adjust_y, size = 1))
if(HUMAN_HEIGHT_TALLER)
appearance.add_filters(list(
list(
"name" = "Lenghten_Torso",
"name" = "Lengthen_Torso",
"priority" = 1,
"params" = displacement_map_filter(lenghten_torso_mask, x = 0, y = adjust_y, size = 1),
"params" = displacement_map_filter(lengthen_torso_mask, x = 0, y = adjust_y, size = 1),
),
list(
"name" = "Lenghten_Legs",
"name" = "Lengthen_Legs",
"priority" = 1,
"params" = displacement_map_filter(lenghten_legs_mask, x = 0, y = adjust_y, size = 1),
"params" = displacement_map_filter(lengthen_legs_mask, x = 0, y = adjust_y, size = 1),
),
))
if(HUMAN_HEIGHT_TALLEST)
appearance.add_filters(list(
list(
"name" = "Lenghten_Torso",
"name" = "Lengthen_Torso",
"priority" = 1,
"params" = displacement_map_filter(lenghten_torso_mask, x = 0, y = adjust_y, size = 1),
"params" = displacement_map_filter(lengthen_torso_mask, x = 0, y = adjust_y, size = 1),
),
list(
"name" = "Lenghten_Legs",
"name" = "Lengthen_Legs",
"priority" = 1,
"params" = displacement_map_filter(lenghten_legs_mask, x = 0, y = adjust_y, size = 1 /* monke edit: 2 -> 1 */),
"params" = displacement_map_filter(lengthen_legs_mask, x = 0, y = adjust_y, size = 1 /* monke edit: 2 -> 1 */),
),
// MONKESTATION EDIT START
list(
"name" = "Lenghten_Ankles",
"name" = "Lengthen_Ankles",
"priority" = 1,
"params" = displacement_map_filter(lenghten_ankles_mask, x = 0, y = adjust_y, size = 1),
"params" = displacement_map_filter(lengthen_ankles_mask, x = 0, y = adjust_y, size = 1),
),
// MONKESTATION EDIT END
))
else
// as we don't add any filters - we need to make sure to run update_filters ourselves, as we didn't update during our previous remove_filter, and any other case would've ran it at the end of add_filter(s)
if(should_update)
appearance.update_filters()

// Kinda gross but because many humans overlays do not use KEEP_TOGETHER we need to manually propogate the filter
// Otherwise overlays, such as worn overlays on icons, won't have the filter "applied", and the effect kinda breaks
Expand Down
Loading