Skip to content

Commit

Permalink
Changes clickcatcher to dynamically scale based on view range (tgstat…
Browse files Browse the repository at this point in the history
…ion#29370)

Scale()s the icon when range is below 16, if it's above 16, scales the icon to 16 and transforms the rest of the way.

This replaces the other method of creating one click catcher image per tile in the range of the users view, which was pretty memory hungry and inefficient. A single icon operation while the view range changes should still be pretty performant and require less memory bookkeeping.l

This ensures it works when the users view range changes, but does not result in a loss of precision for view ranges up to 16 when moving the mouse (it triggers per pixel which simply get larger when transformed)

fixes tgstation#29342
  • Loading branch information
silicons authored and optimumtact committed Jul 23, 2017
1 parent bb37810 commit e568f29
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
26 changes: 16 additions & 10 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -432,28 +432,34 @@

/obj/screen/click_catcher
icon = 'icons/mob/screen_gen.dmi'
icon_state = "click_catcher"
icon_state = "flash"
plane = CLICKCATCHER_PLANE
mouse_opacity = 2
screen_loc = "CENTER"

/obj/screen/click_catcher/proc/UpdateGreed(view_size_x = 7, view_size_y = 7)
screen_loc = "CENTER-[view_size_x],CENTER-[view_size_y]"
var/list/ret = list()
for(var/X in 0 to (view_size_x * 2))
for(var/Y in 0 to (view_size_y * 2))
var/obj/screen/click_catcher/CC = new()
CC.screen_loc = "EAST-[X],NORTH-[Y]"
ret += CC
return ret
var/icon/newicon = icon('icons/mob/screen_gen.dmi', "flash")
if(view_size_x > 16 || view_size_y > 16)
newicon.Scale((16 * 2 + 1) * world.icon_size,(16 * 2 + 1) * world.icon_size)
icon = newicon
var/tx = view_size_x/16
var/ty = view_size_y/16
var/matrix/M = new
M.Scale(tx, ty)
transform = M
screen_loc = "CENTER-16,CENTER-16"
else
screen_loc = "CENTER-[view_size_x],CENTER-[view_size_y]"
newicon.Scale((view_size_x * 2 + 1) * world.icon_size,(view_size_y * 2 + 1) * world.icon_size)
icon = newicon

/obj/screen/click_catcher/Click(location, control, params)
var/list/modifiers = params2list(params)
if(modifiers["middle"] && iscarbon(usr))
var/mob/living/carbon/C = usr
C.swap_hand()
else
var/turf/T = screen_loc2turf(screen_loc, get_turf(usr))
var/turf/T = params2turf(modifiers["screen-loc"], get_turf(usr))
params += "&catcher=1"
if(T)
T.Click(location, control, params)
Expand Down
3 changes: 1 addition & 2 deletions code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@

preload_rsc = PRELOAD_RSC

var/global/obj/screen/click_catcher/void
var/list/obj/screen/click_catcher/click_catcher_tiles
var/obj/screen/click_catcher/void

// Used by html_interface module.
var/hi_last_pos
Expand Down
12 changes: 1 addition & 11 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,6 @@ GLOBAL_LIST(external_rsc_urls)
if ("key")
return FALSE

/client/proc/clear_click_catcher()
if(!LAZYLEN(click_catcher_tiles))
return
for(var/I in click_catcher_tiles)
screen -= I
qdel(I)

/client/proc/change_view(new_size)
if (isnull(new_size))
Expand All @@ -663,12 +657,8 @@ GLOBAL_LIST(external_rsc_urls)
screen += void

/client/proc/apply_clickcatcher()
clear_click_catcher()
generate_clickcatcher()
click_catcher_tiles = void.UpdateGreed(view,view)
for(var/obj/screen/OS in click_catcher_tiles)
screen += OS

void.UpdateGreed(view,view)

/client/proc/AnnouncePR(announcement)
if(prefs && prefs.chat_toggles & CHAT_PULLR)
Expand Down

0 comments on commit e568f29

Please sign in to comment.