From e568f29bc544ea2d3e73b161d2b9ed7da5835aa1 Mon Sep 17 00:00:00 2001 From: kevinz000 Date: Sun, 23 Jul 2017 15:23:37 -0700 Subject: [PATCH] Changes clickcatcher to dynamically scale based on view range (#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 #29342 --- code/_onclick/click.dm | 26 ++++++++++++++++---------- code/modules/client/client_defines.dm | 3 +-- code/modules/client/client_procs.dm | 12 +----------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 87e6bdc47c1..7e38d599989 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -432,20 +432,26 @@ /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) @@ -453,7 +459,7 @@ 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) diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 51cf83d0ae8..5dfd9ecd4bc 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -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 diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 827ea252fc9..18db4166182 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -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)) @@ -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)