Skip to content

Commit

Permalink
GetFlatIcon improvements. (#86077)
Browse files Browse the repository at this point in the history
## About The Pull Request
I've added an get_icon_dimensions() call to a place where `icon.Width()`
and `icon.Height()` are called twice each. get_icon_dimensions uses a
cache of values so follow-up getFlatIcon() calls with the same current
icon won't have it call`icon.Width()` or `icon.Height()` which aren't
exactly cheap procs iirc.

I've also removed two of the fairly expensive
`length(icon_states(icon(curicon, curstate, dir)))` checks, because all
icon states have NORTH, EAST and WEST directions except 1-dir
icon_states which are always facing SOUTH. That is, unless there is some
farfetched procgenned bullshit that's probably not even possible and
worth checking against. We'll see.

## Why It's Good For The Game
GetFlatIcon is a very expensive proc, every bit of improvement is worth
it.

## Changelog
N/A
  • Loading branch information
Ghommie authored and Absolucy committed Sep 15, 2024
1 parent 0d32e10 commit a583a3a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,20 @@ world

var/base_icon_dir //We'll use this to get the icon state to display if not null BUT NOT pass it to overlays as the dir we have

//Try to remove/optimize this section ASAP, CPU hog.
//Determines if there's directionals.
if(render_icon && curdir != SOUTH)
if (
!length(icon_states(icon(curicon, curstate, NORTH))) \
&& !length(icon_states(icon(curicon, curstate, EAST))) \
&& !length(icon_states(icon(curicon, curstate, WEST))) \
)
base_icon_dir = SOUTH
if(render_icon)
//Try to remove/optimize this section if you can, it's a CPU hog.
//Determines if there're directionals.
if (curdir != SOUTH)
// icon states either have 1, 4 or 8 dirs. We only have to check
// one of NORTH, EAST or WEST to know that this isn't a 1-dir icon_state since they just have SOUTH.
if(!length(icon_states(icon(curicon, curstate, NORTH))))
base_icon_dir = SOUTH

var/list/icon_dimensions = get_icon_dimensions(curicon)
var/icon_width = icon_dimensions["width"]
var/icon_height = icon_dimensions["height"]
if(icon_width != 32 || icon_height != 32)
flat.Scale(icon_width, icon_height)

Check failure on line 787 in code/__HELPERS/icons.dm

View workflow job for this annotation

GitHub Actions / Run Linters

undefined var: "flat"

Check warning on line 787 in code/__HELPERS/icons.dm

View workflow job for this annotation

GitHub Actions / Run Linters

proc call requires static type: "Scale"

Check failure on line 787 in code/__HELPERS/icons.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD0404: Unknown identifier "flat"

if(!base_icon_dir)
base_icon_dir = curdir
Expand Down

0 comments on commit a583a3a

Please sign in to comment.