From f65fd8357b2ffd1929e89bd33df82bba6dfd8004 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Thu, 5 Dec 2024 10:05:39 +0800 Subject: [PATCH] Code cleanup in various files Some suggestions by @drjaska Made client/hud/common_physics.qc formatting consistent with CONTRIBUTING.md --- qcsrc/client/hud/common_physics.qc | 31 +++++++++++------------------- qcsrc/client/hud/panel/physics.qc | 25 +++++++++++++++--------- qcsrc/common/physics/player.qh | 1 + 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/qcsrc/client/hud/common_physics.qc b/qcsrc/client/hud/common_physics.qc index ed2c151eb..27d572307 100644 --- a/qcsrc/client/hud/common_physics.qc +++ b/qcsrc/client/hud/common_physics.qc @@ -11,7 +11,7 @@ void HUD_Physics_Init() { // find out whether the local csqcmodel entity is valid - if(spectatee_status > 0 || isdemo()) + if (spectatee_status > 0 || isdemo()) { islocal = false; strafeplayer = CSQCModel_server2csqc(player_localentnum - 1); @@ -22,14 +22,9 @@ void HUD_Physics_Init() strafeplayer = csqcplayer; } - if(csqcplayer && strafeplayer) - csqc_and_strafe_player = true; - else - { - csqc_and_strafe_player = false; - // Since both huds return (essentially) when this is false, no variables beyond this point need to be computed - return; - } + csqc_and_strafe_player = (csqcplayer && strafeplayer); + if (!csqc_and_strafe_player) + return; // Since both huds return (essentially) when this is false, no variables beyond this point need to be computed predicted = csqcplayer_status == CSQCPLAYERSTATUS_PREDICTED; @@ -54,14 +49,14 @@ void HUD_Physics_Init() keys = STAT(PRESSED_KEYS); // try to ignore if track_canjump is enabled, doesn't work in spectator mode if spectated player uses +jetpack or cl_movement_track_canjump jumpheld = false; - if(islocal) + if (islocal) { - if((PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) && !PHYS_CL_TRACK_CANJUMP(strafeplayer)) + if ((PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) && !PHYS_CL_TRACK_CANJUMP(strafeplayer)) jumpheld = true; } else { - if((keys & KEY_JUMP) && !PHYS_TRACK_CANJUMP(strafeplayer)) + if ((keys & KEY_JUMP) && !PHYS_TRACK_CANJUMP(strafeplayer)) jumpheld = true; } @@ -92,15 +87,13 @@ void HUD_Physics_Init() view_angle = PHYS_INPUT_ANGLES(strafeplayer).y; airstopaccel = PHYS_AIRSTOPACCELERATE(strafeplayer); - if(!airstopaccel) + if (!airstopaccel) airstopaccel = 1; // values of 0 are equivalent to 1 - if(onground) + if (onground) { - if(friction_phys == 0) - { + if (friction_phys == 0) onslick = true; - } else // don't use IS_ONSLICK(), it only works for the local player and only if client prediction is enabled { trace_dphitq3surfaceflags = 0; @@ -112,10 +105,8 @@ void HUD_Physics_Init() onground_lasttime = time; onslick_last = onslick; } - else if(jumpheld || swimming) - { + else if (jumpheld || swimming) onground_lasttime = 0; - } strafefriction = onslick ? friction_slick : friction_phys; alive_player = (!IS_DEAD(strafeplayer) && IS_PLAYER(strafeplayer)); diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index 852c25e66..79759328f 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -51,7 +51,7 @@ void HUD_Physics() HUD_Panel_DrawBg(); if (panel_bg_padding) { - panel_pos += '1 1 0' * panel_bg_padding; + panel_pos += '1 1 0' * panel_bg_padding; panel_size -= '2 2 0' * panel_bg_padding; } @@ -118,7 +118,7 @@ void HUD_Physics() float panel_ar = panel_size.x / panel_size.y; vector speed_offset = '0 0 0', accel_offset = '0 0 0'; if (autocvar_hud_panel_physics_force_layout == PHYSICS_LAYOUT_HORIZONTAL - || (autocvar_hud_panel_physics_force_layout != PHYSICS_LAYOUT_VERTICAL && panel_ar >= 5 && !accel_progressbar_scale)) + || (autocvar_hud_panel_physics_force_layout != PHYSICS_LAYOUT_VERTICAL && panel_ar >= 5 && !accel_progressbar_scale)) { panel_size.x *= 0.5; if (autocvar_hud_panel_physics_flip) @@ -160,14 +160,16 @@ void HUD_Physics() // draw speed if (!immobile) - if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_SPEED) + if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH + || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_SPEED) HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed / max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); // compute jumpspeed text float jump_speed_f = 0; if (autocvar_hud_panel_physics_jumpspeed) - if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) + if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH + || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) { text_bits |= BIT(1); if (autocvar__hud_configure) @@ -193,7 +195,8 @@ void HUD_Physics() // compute and draw topspeed float top_speed_f = 0; if (autocvar_hud_panel_physics_topspeed) - if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) + if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH + || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) { text_bits |= BIT(0); if (autocvar__hud_configure) @@ -220,7 +223,8 @@ void HUD_Physics() if (top_speed_f > 0) { if (speed < top_speed) - if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_SPEED) + if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH + || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_SPEED) { float peak_offsetX; vector peak_size = '0 0 0'; @@ -263,7 +267,8 @@ void HUD_Physics() } // draw speed text - if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) + if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH + || autocvar_hud_panel_physics_text == PHYSICS_TEXT_SPEED) { tmp_size.x = panel_size.x * speed_size; tmp_size.y = panel_size.y * text_scale; @@ -277,7 +282,8 @@ void HUD_Physics() // draw acceleration if (accel) - if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_ACCEL) + if (autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_BOTH + || autocvar_hud_panel_physics_progressbar == PHYSICS_PROGRESSBAR_ACCEL) { vector progressbar_color; if (accel < 0) @@ -315,7 +321,8 @@ void HUD_Physics() } // draw acceleration text - if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH || autocvar_hud_panel_physics_text == PHYSICS_TEXT_ACCEL) + if (autocvar_hud_panel_physics_text == PHYSICS_TEXT_BOTH + || autocvar_hud_panel_physics_text == PHYSICS_TEXT_ACCEL) { tmp_size.x = panel_size.x; tmp_size.y = panel_size.y * text_scale; diff --git a/qcsrc/common/physics/player.qh b/qcsrc/common/physics/player.qh index f66860f6f..2d8fb6552 100644 --- a/qcsrc/common/physics/player.qh +++ b/qcsrc/common/physics/player.qh @@ -214,6 +214,7 @@ STATIC_INIT(PHYS_INPUT_BUTTON) .float teleport_time; #ifdef CSQC + #define PHYS_FIXANGLE(s) ('0 0 0') string autocvar_cl_jumpspeedcap_min; -- 2.39.2