From: terencehill Date: Fri, 29 Jun 2018 10:06:39 +0000 (+0200) Subject: Optimize some math code of havocbot_movetogoal X-Git-Tag: xonotic-v0.8.5~1969 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f50b0cef3e9b487946695f7a29bed74219074c7d;p=xonotic%2Fxonotic-data.pk3dir.git Optimize some math code of havocbot_movetogoal --- diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 13e1c24c3..357b37da0 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -525,13 +525,13 @@ void havocbot_movetogoal(entity this) { // Calculate brake distance in xy float d = vlen(vec2(this.origin - (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5)); - float v = vlen(vec2(this.velocity)); - float db = ((v ** 2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100; + float vel2 = vlen2(vec2(this.velocity)); + float db = (vel2 / (autocvar_g_jetpack_acceleration_side * 2)) + 100; //LOG_INFOF("distance %d, velocity %d, brake at %d ", ceil(d), ceil(v), ceil(db)); if(d < db || d < 500) { // Brake - if(v > maxspeed * 0.3) + if (vel2 > (maxspeed * 0.3) ** 2) { CS(this).movement_x = dir * v_forward * -maxspeed; return; @@ -748,9 +748,10 @@ void havocbot_movetogoal(entity this) else PHYS_INPUT_BUTTON_JUMP(this) = false; makevectors(this.v_angle.y * '0 1 0'); - CS(this).movement_x = dir * v_forward * maxspeed; - CS(this).movement_y = dir * v_right * maxspeed; - CS(this).movement_z = dir * v_up * maxspeed; + vector v = dir * maxspeed; + CS(this).movement.x = v * v_forward; + CS(this).movement.y = v * v_right; + CS(this).movement.z = v * v_up; } // if there is nowhere to go, exit