From 021fc3161076ae0c1e5c0ef611b1a21f02c73a4c Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Thu, 17 Oct 2013 21:44:56 +0200 Subject: [PATCH] Get rid of an useless trace and like 1000 instructions each frame and player. --- qcsrc/server/cheats.qc | 74 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index f04fc8472..53c1853a7 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -718,7 +718,7 @@ float CheatCommand(float argc) END_CHEAT_FUNCTION(); } -float Drag(entity e, float grab, float ischeat); +float Drag(float force_allow_pick, float ischeat); void Drag_Begin(entity dragger, entity draggee, vector touchpoint); void Drag_Finish(entity dragger); float Drag_IsDraggable(entity draggee); @@ -748,40 +748,11 @@ float CheatFrame() { // use cheat dragging if cheats are enabled crosshair_trace_plusvisibletriggers(self); - Drag(trace_ent, TRUE, TRUE); + Drag(TRUE, TRUE); } else { - // drag is TRUE if the object can be picked up. While an object is being carried, the Drag() function - // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace. - // This also makes sure that an object can only pe picked up if in range, but does not get dropped if - // it goes out of range while slinging it around. - - float drag; - crosshair_trace_plusvisibletriggers(self); - drag = FALSE; - if(vlen(self.origin - trace_ent.origin) <= autocvar_g_grab_range) - { - switch(trace_ent.grab) - { - case 0: // can't grab - break; - case 1: // owner can grab - if(trace_ent.owner == self || trace_ent.realowner == self) - drag = TRUE; - break; - case 2: // owner and team mates can grab - if(SAME_TEAM(trace_ent.owner, self) || SAME_TEAM(trace_ent.realowner, self) || trace_ent.team == self.team) - drag = TRUE; - break; - case 3: // anyone can grab - drag = TRUE; - break; - default: - break; - } - } - Drag(trace_ent, drag, FALSE); // execute dragging + Drag(FALSE, FALSE); // execute dragging } break; } @@ -795,7 +766,7 @@ float CheatFrame() // ENTITY DRAGGING -float Drag(entity e, float pick, float ischeat) +float Drag(float force_allow_pick, float ischeat) { BEGIN_CHEAT_FUNCTION(); @@ -840,9 +811,42 @@ float Drag(entity e, float pick, float ischeat) else { if(Drag_CanDrag(self)) - if(self.BUTTON_DRAG && pick) + if(self.BUTTON_DRAG) { - if(e) + crosshair_trace_plusvisibletriggers(self); + entity e = trace_ent; + float pick = force_allow_pick; + if (e && !pick) + { + // pick is TRUE if the object can be picked up. While an object is being carried, the Drag() function + // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace. + // This also makes sure that an object can only pe picked up if in range, but does not get dropped if + // it goes out of range while slinging it around. + + if(vlen(self.origin - e.origin) <= autocvar_g_grab_range) + { + switch(e.grab) + { + case 0: // can't grab + break; + case 1: // owner can grab + if(e.owner == self || e.realowner == self) + pick = TRUE; + break; + case 2: // owner and team mates can grab + if(SAME_TEAM(e.owner, self) || SAME_TEAM(e.realowner, self) || e.team == self.team) + pick = TRUE; + break; + case 3: // anyone can grab + pick = TRUE; + break; + default: + break; + } + } + } + // Find e and pick + if(e && pick) if(Drag_IsDraggable(e)) { if(ischeat) -- 2.39.2