From 5bb972c94a45c357cf46ae4377d0508bee001286 Mon Sep 17 00:00:00 2001 From: Fikou <23585223+Fikou@users.noreply.github.com> Date: Tue, 1 Nov 2022 21:02:13 +0100 Subject: [PATCH] (hopefully) improvements to use of scope and kinesis module (#70934) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## About The Pull Request so, scope and kinesis are the only things in the game (other than the body zone selector) which use the function MouseMove. this tracks every mouse movement, which meant we had to stuff a cooldown on it to not calculate a ton of useless stuff. this time can misalign if you move your mouse fast, not registering at all, as well as not working out with the 0.2 second processing time of the things handling it (the scope component and kinesis module) instead of doing that, we are now keeping the mouse parameters as a variable, which we update with every mousemove to the current parameters. then we handle the calculations right as we need them (in the kinesis/scope) module, rather than relying on mousemove cooldowns, this should hopefully feel way better ## Why It's Good For The Game 😁 ## Changelog :cl: qol: sniper scopes and kinesis module should feel better to use /:cl: --- .../signals/signals_mob/signals_mob_main.dm | 2 + code/_onclick/hud/hud.dm | 6 +++ code/datums/components/scope.dm | 53 +++++++++++++------ code/datums/view.dm | 4 +- code/modules/mod/modules/module_kinesis.dm | 49 ++++++++++------- code/modules/mod/modules/modules_antag.dm | 6 +-- code/modules/mod/modules/modules_science.dm | 6 +-- code/modules/mod/modules/modules_supply.dm | 2 +- .../projectiles/guns/ballistic/automatic.dm | 9 +++- 9 files changed, 90 insertions(+), 47 deletions(-) diff --git a/code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm b/code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm index 4ccf0203cf3..f4cda43da86 100644 --- a/code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm +++ b/code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm @@ -46,6 +46,8 @@ #define COMSIG_MOB_RESET_PERSPECTIVE "mob_reset_perspective" /// from base of /client/proc/set_eye() : (atom/old_eye, atom/new_eye) #define COMSIG_CLIENT_SET_EYE "client_set_eye" +/// from base of /datum/view_data/proc/afterViewChange() : (view) +#define COMSIG_VIEWDATA_UPDATE "viewdata_update" ///from mind/transfer_to. Sent to the receiving mob. diff --git a/code/_onclick/hud/hud.dm b/code/_onclick/hud/hud.dm index 96a0e6bcb65..1a2e0f7dc19 100644 --- a/code/_onclick/hud/hud.dm +++ b/code/_onclick/hud/hud.dm @@ -128,6 +128,7 @@ GLOBAL_LIST_INIT(available_ui_styles, list( RegisterSignal(mymob, COMSIG_MOB_LOGIN, .proc/client_refresh) RegisterSignal(mymob, COMSIG_MOB_LOGOUT, .proc/clear_client) RegisterSignal(mymob, COMSIG_MOB_SIGHT_CHANGE, .proc/update_sightflags) + RegisterSignal(mymob, COMSIG_VIEWDATA_UPDATE, .proc/on_viewdata_update) update_sightflags(mymob, mymob.sight, NONE) /datum/hud/proc/client_refresh(datum/source) @@ -138,6 +139,11 @@ GLOBAL_LIST_INIT(available_ui_styles, list( if(mymob.canon_client) UnregisterSignal(mymob.canon_client, COMSIG_CLIENT_SET_EYE) +/datum/hud/proc/on_viewdata_update(datum/source, view) + SIGNAL_HANDLER + + view_audit_buttons() + /datum/hud/proc/on_eye_change(datum/source, atom/old_eye, atom/new_eye) SIGNAL_HANDLER if(old_eye) diff --git a/code/datums/components/scope.dm b/code/datums/components/scope.dm index 693028a823c..e6d928ce97a 100644 --- a/code/datums/components/scope.dm +++ b/code/datums/components/scope.dm @@ -32,9 +32,10 @@ if(!tracker.marksman.client) stop_zooming(tracker.marksman) return + tracker.calculate_params() if(!length(tracker.marksman.client.keys_held & tracker.marksman.client.movement_keys)) tracker.marksman.face_atom(tracker.given_turf) - animate(tracker.marksman.client, 0.2 SECONDS, easing = SINE_EASING, flags = EASE_OUT, pixel_x = tracker.given_x, pixel_y = tracker.given_y) + animate(tracker.marksman.client, world.tick_lag, pixel_x = tracker.given_x, pixel_y = tracker.given_y) /datum/component/scope/proc/on_move(atom/movable/source, atom/oldloc, dir, forced) SIGNAL_HANDLER @@ -84,6 +85,8 @@ if(iseffect(possible_target)) continue if(ismob(possible_target)) + if(possible_target == tracker.marksman) + continue return possible_target if(!possible_target.density) non_dense_targets += possible_target @@ -110,9 +113,12 @@ tracker = user.overlay_fullscreen("scope", /atom/movable/screen/fullscreen/scope, 0) tracker.range_modifier = range_modifier tracker.marksman = user + tracker.view_list = getviewsize(user.client.view) tracker.RegisterSignal(user, COMSIG_MOVABLE_MOVED, /atom/movable/screen/fullscreen/scope.proc/on_move) + tracker.RegisterSignal(user, COMSIG_VIEWDATA_UPDATE, /atom/movable/screen/fullscreen/scope.proc/on_viewdata_update) + tracker.calculate_params() RegisterSignal(user, COMSIG_MOB_SWAP_HANDS, .proc/stop_zooming) - START_PROCESSING(SSfastprocess, src) + START_PROCESSING(SSprojectiles, src) /** * We stop zooming, canceling processing, resetting stuff back to normal and deleting our tracker. @@ -123,7 +129,7 @@ /datum/component/scope/proc/stop_zooming(mob/user) SIGNAL_HANDLER - STOP_PROCESSING(SSfastprocess, src) + STOP_PROCESSING(SSprojectiles, src) UnregisterSignal(user, COMSIG_MOB_SWAP_HANDS) if(user.client) animate(user.client, 0.2 SECONDS, pixel_x = 0, pixel_y = 0) @@ -141,14 +147,16 @@ var/range_modifier = 1 /// The mob the scope is on. var/mob/marksman + /// Client view size of the scoping mob. + var/list/view_list /// Pixel x we send to the scope component. - var/given_x = 0 + var/given_x /// Pixel y we send to the scope component. - var/given_y = 0 + var/given_y /// The turf we send to the scope component. var/turf/given_turf - /// The coordinate on our mouseentered, for performance reasons. - COOLDOWN_DECLARE(coordinate_cooldown) + /// Mouse parameters, for calculation. + var/mouse_params /atom/movable/screen/fullscreen/scope/proc/on_move(atom/source, atom/oldloc, dir, forced) SIGNAL_HANDLER @@ -159,20 +167,31 @@ var/y_offset = source.loc.y - oldloc.y given_turf = locate(given_turf.x+x_offset, given_turf.y+y_offset, given_turf.z) +/atom/movable/screen/fullscreen/scope/proc/on_viewdata_update(datum/source, view) + SIGNAL_HANDLER + + view_list = getviewsize(view) + /atom/movable/screen/fullscreen/scope/MouseEntered(location, control, params) . = ..() MouseMove(location, control, params) + if(usr == marksman) + calculate_params() /atom/movable/screen/fullscreen/scope/MouseMove(location, control, params) - if(!marksman?.client || usr != marksman) + if(usr != marksman) return - if(!COOLDOWN_FINISHED(src, coordinate_cooldown)) - return - COOLDOWN_START(src, coordinate_cooldown, 0.2 SECONDS) - var/list/modifiers = params2list(params) - var/icon_x = text2num(LAZYACCESS(modifiers, VIS_X)) - var/icon_y = text2num(LAZYACCESS(modifiers, VIS_Y)) - var/list/view = getviewsize(marksman.client.view) - given_x = round(range_modifier * (icon_x - view[1]*world.icon_size/2)) - given_y = round(range_modifier * (icon_y - view[2]*world.icon_size/2)) + mouse_params = params + +/atom/movable/screen/fullscreen/scope/Click(location, control, params) + if(usr == marksman) + calculate_params() + return ..() + +/atom/movable/screen/fullscreen/scope/proc/calculate_params() + var/list/modifiers = params2list(mouse_params) + var/icon_x = text2num(LAZYACCESS(modifiers, VIS_X)) || view_list[1]*world.icon_size/2 + var/icon_y = text2num(LAZYACCESS(modifiers, VIS_Y)) || view_list[2]*world.icon_size/2 + given_x = round(range_modifier * (icon_x - view_list[1]*world.icon_size/2)) + given_y = round(range_modifier * (icon_y - view_list[2]*world.icon_size/2)) given_turf = locate(marksman.x+round(given_x/world.icon_size, 1),marksman.y+round(given_y/world.icon_size, 1),marksman.z) diff --git a/code/datums/view.dm b/code/datums/view.dm index e8b6c1cfe82..19ba66c3900 100644 --- a/code/datums/view.dm +++ b/code/datums/view.dm @@ -38,8 +38,8 @@ assertFormat() else resetFormat() - var/datum/hud/our_hud = chief?.mob?.hud_used - our_hud.view_audit_buttons() // Make sure our hud's buttons are in our new size + if(chief?.mob) + SEND_SIGNAL(chief.mob, COMSIG_VIEWDATA_UPDATE, getView()) /datum/view_data/proc/assertFormat()//T-Pose winset(chief, "mapwindow.map", "zoom=0") diff --git a/code/modules/mod/modules/module_kinesis.dm b/code/modules/mod/modules/module_kinesis.dm index f2c321a2633..d88ce78ffb0 100644 --- a/code/modules/mod/modules/module_kinesis.dm +++ b/code/modules/mod/modules/module_kinesis.dm @@ -48,6 +48,8 @@ . = ..() if(!.) return + if(!mod.wearer.client) + return if(grabbed_atom) launch() clear_grab(playsound = FALSE) @@ -64,15 +66,18 @@ var/mob/living/grabbed_mob = grabbed_atom grabbed_mob.Stun(mob_stun_time) playsound(grabbed_atom, 'sound/effects/contractorbatonhit.ogg', 75, TRUE) - START_PROCESSING(SSfastprocess, src) kinesis_icon = mutable_appearance(icon='icons/effects/effects.dmi', icon_state="kinesis", layer=grabbed_atom.layer-0.1) kinesis_icon.appearance_flags = RESET_ALPHA|RESET_COLOR|RESET_TRANSFORM grabbed_atom.add_overlay(kinesis_icon) kinesis_beam = mod.wearer.Beam(grabbed_atom, "kinesis") kinesis_catcher = mod.wearer.overlay_fullscreen("kinesis", /atom/movable/screen/fullscreen/kinesis, 0) kinesis_catcher.kinesis_user = mod.wearer + kinesis_catcher.view_list = getviewsize(mod.wearer.client.view) kinesis_catcher.RegisterSignal(mod.wearer, COMSIG_MOVABLE_MOVED, /atom/movable/screen/fullscreen/kinesis.proc/on_move) + kinesis_catcher.RegisterSignal(mod.wearer, COMSIG_VIEWDATA_UPDATE, /atom/movable/screen/fullscreen/kinesis.proc/on_viewdata_update) + kinesis_catcher.calculate_params() soundloop.start() + START_PROCESSING(SSfastprocess, src) /obj/item/mod/module/anomaly_locked/kinesis/on_deactivation(display_message = TRUE, deleting = FALSE) . = ..() @@ -88,7 +93,9 @@ balloon_alert(mod.wearer, "out of range!") clear_grab() return + kinesis_catcher.calculate_params() if(!kinesis_catcher.given_turf) + clear_grab() return drain_power(use_power_cost/10) mod.wearer.setDir(get_dir(mod.wearer, grabbed_atom)) @@ -226,10 +233,11 @@ plane = HUD_PLANE mouse_opacity = MOUSE_OPACITY_ICON var/mob/kinesis_user - var/given_x = 16 - var/given_y = 16 + var/list/view_list + var/given_x + var/given_y var/turf/given_turf - COOLDOWN_DECLARE(coordinate_cooldown) + var/mouse_params /atom/movable/screen/fullscreen/kinesis/proc/on_move(atom/source, atom/oldloc, dir, forced) SIGNAL_HANDLER @@ -239,28 +247,29 @@ var/y_offset = source.loc.y - oldloc.y given_turf = locate(given_turf.x+x_offset, given_turf.y+y_offset, given_turf.z) +/atom/movable/screen/fullscreen/kinesis/proc/on_viewdata_update(datum/source, view) + SIGNAL_HANDLER + + view_list = getviewsize(view) + /atom/movable/screen/fullscreen/kinesis/MouseEntered(location, control, params) . = ..() MouseMove(location, control, params) + if(usr == kinesis_user) + calculate_params() /atom/movable/screen/fullscreen/kinesis/MouseMove(location, control, params) - if(!kinesis_user?.client || usr != kinesis_user) + if(usr != kinesis_user) return - if(!COOLDOWN_FINISHED(src, coordinate_cooldown)) - return - COOLDOWN_START(src, coordinate_cooldown, 0.2 SECONDS) - var/list/modifiers = params2list(params) - var/icon_x = text2num(LAZYACCESS(modifiers, ICON_X)) - var/icon_y = text2num(LAZYACCESS(modifiers, ICON_Y)) - var/list/view = getviewsize(kinesis_user.client.view) - icon_x *= view[1]/FULLSCREEN_OVERLAY_RESOLUTION_X - icon_y *= view[2]/FULLSCREEN_OVERLAY_RESOLUTION_Y - var/our_x = round(icon_x / world.icon_size, 1) - var/our_y = round(icon_y / world.icon_size, 1) - var/mob_x = kinesis_user.x - var/mob_y = kinesis_user.y - var/mob_z = kinesis_user.z - given_turf = locate(mob_x+our_x-round(view[1]/2),mob_y+our_y-round(view[2]/2),mob_z) + mouse_params = params + +/atom/movable/screen/fullscreen/kinesis/proc/calculate_params() + var/list/modifiers = params2list(mouse_params) + var/icon_x = text2num(LAZYACCESS(modifiers, VIS_X)) || view_list[1]*world.icon_size/2 + var/icon_y = text2num(LAZYACCESS(modifiers, VIS_Y)) || view_list[2]*world.icon_size/2 + var/our_x = round(icon_x / world.icon_size) + var/our_y = round(icon_y / world.icon_size) + given_turf = locate(kinesis_user.x+our_x-round(view_list[1]/2),kinesis_user.y+our_y-round(view_list[2]/2),kinesis_user.z) given_x = round(icon_x - world.icon_size * our_x, 1) given_y = round(icon_y - world.icon_size * our_y, 1) diff --git a/code/modules/mod/modules/modules_antag.dm b/code/modules/mod/modules/modules_antag.dm index d3a9e606f72..d016f8e8697 100644 --- a/code/modules/mod/modules/modules_antag.dm +++ b/code/modules/mod/modules/modules_antag.dm @@ -315,10 +315,10 @@ blind_message = span_hear("You hear a charging sound.")) playsound(src, 'sound/items/modsuit/loader_charge.ogg', 75, TRUE) balloon_alert(mod.wearer, "you start charging...") - animate(mod.wearer, 0.3 SECONDS, pixel_z = 16, flags = ANIMATION_RELATIVE|SINE_EASING|EASE_OUT) + animate(mod.wearer, 0.3 SECONDS, pixel_z = 16, flags = ANIMATION_RELATIVE, easing = SINE_EASING|EASE_OUT) addtimer(CALLBACK(mod.wearer, /atom.proc/SpinAnimation, 3, 2), 0.3 SECONDS) if(!do_after(mod.wearer, 1 SECONDS, target = mod)) - animate(mod.wearer, 0.2 SECONDS, pixel_z = -16, flags = ANIMATION_RELATIVE|SINE_EASING|EASE_IN) + animate(mod.wearer, 0.2 SECONDS, pixel_z = -16, flags = ANIMATION_RELATIVE, easing = SINE_EASING|EASE_IN) return animate(mod.wearer) drain_power(use_power_cost) @@ -332,7 +332,7 @@ if(!user) return user.transform = user.transform.Turn(angle) - animate(user, 0.2 SECONDS, pixel_z = -16, flags = ANIMATION_RELATIVE|SINE_EASING|EASE_IN) + animate(user, 0.2 SECONDS, pixel_z = -16, flags = ANIMATION_RELATIVE, easing = SINE_EASING|EASE_IN) /obj/item/mod/module/power_kick/proc/on_throw_impact(mob/living/source, atom/target, datum/thrownthing/thrownthing) SIGNAL_HANDLER diff --git a/code/modules/mod/modules/modules_science.dm b/code/modules/mod/modules/modules_science.dm index 36b78df768f..501d04efddf 100644 --- a/code/modules/mod/modules/modules_science.dm +++ b/code/modules/mod/modules/modules_science.dm @@ -118,12 +118,12 @@ pre_matrix.Scale(4, 0.25) var/matrix/post_matrix = matrix() post_matrix.Scale(0.25, 4) - animate(mod.wearer, teleport_time, color = COLOR_CYAN, transform = pre_matrix.Multiply(mod.wearer.transform), easing = EASE_OUT) + animate(mod.wearer, teleport_time, color = COLOR_CYAN, transform = pre_matrix.Multiply(mod.wearer.transform), easing = SINE_EASING|EASE_OUT) if(!do_after(mod.wearer, teleport_time, target = mod)) balloon_alert(mod.wearer, "interrupted!") - animate(mod.wearer, teleport_time*0.1, color = null, transform = post_matrix.Multiply(mod.wearer.transform), easing = EASE_IN) + animate(mod.wearer, teleport_time*0.1, color = null, transform = post_matrix.Multiply(mod.wearer.transform), easing = SINE_EASING|EASE_IN) return - animate(mod.wearer, teleport_time*0.1, color = null, transform = post_matrix.Multiply(mod.wearer.transform), easing = EASE_IN) + animate(mod.wearer, teleport_time*0.1, color = null, transform = post_matrix.Multiply(mod.wearer.transform), easing = SINE_EASING|EASE_IN) if(!do_teleport(mod.wearer, target_turf, asoundin = 'sound/effects/phasein.ogg')) return drain_power(use_power_cost) diff --git a/code/modules/mod/modules/modules_supply.dm b/code/modules/mod/modules/modules_supply.dm index d562953ad0c..7a90c90dfa0 100644 --- a/code/modules/mod/modules/modules_supply.dm +++ b/code/modules/mod/modules/modules_supply.dm @@ -234,7 +234,7 @@ var/atom/game_renderer = mod.wearer.hud_used.get_plane_master(RENDER_PLANE_GAME) var/matrix/render_matrix = matrix(game_renderer.transform) render_matrix.Scale(1.25, 1.25) - animate(game_renderer, launch_time, flags = SINE_EASING|EASE_IN, transform = render_matrix) + animate(game_renderer, launch_time, transform = render_matrix) var/current_time = world.time mod.wearer.visible_message(span_warning("[mod.wearer] starts whirring!"), \ blind_message = span_hear("You hear a whirring sound.")) diff --git a/code/modules/projectiles/guns/ballistic/automatic.dm b/code/modules/projectiles/guns/ballistic/automatic.dm index f2bd23ade9c..4422042cad6 100644 --- a/code/modules/projectiles/guns/ballistic/automatic.dm +++ b/code/modules/projectiles/guns/ballistic/automatic.dm @@ -328,7 +328,7 @@ recoil = 2 weapon_weight = WEAPON_HEAVY mag_type = /obj/item/ammo_box/magazine/sniper_rounds - fire_delay = 40 + fire_delay = 4 SECONDS burst_size = 1 w_class = WEIGHT_CLASS_NORMAL slot_flags = ITEM_SLOT_BACK @@ -341,6 +341,13 @@ . = ..() AddComponent(/datum/component/scope, range_modifier = 2) +/obj/item/gun/ballistic/automatic/sniper_rifle/reset_semicd() + . = ..() + if(suppressed) + playsound(src, 'sound/machines/eject.ogg', 25, TRUE, ignore_walls = FALSE, extrarange = SILENCED_SOUND_EXTRARANGE, falloff_distance = 0) + else + playsound(src, 'sound/machines/eject.ogg', 50, TRUE) + /obj/item/gun/ballistic/automatic/sniper_rifle/syndicate name = "syndicate sniper rifle" desc = "An illegally modified .50 cal sniper rifle with suppression compatibility. Quickscoping still doesn't work."