]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
_Movetype_UnstickEntity: optimize
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 12 Mar 2016 11:15:35 +0000 (22:15 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 12 Mar 2016 11:15:35 +0000 (22:15 +1100)
qcsrc/common/physics/movetypes/movetypes.qc
qcsrc/common/physics/movetypes/movetypes.qh

index 0d6b98eaa810db404faed63b61b16477f01253f1..de623b5033d94e3f258f082494763ce82513d5c7 100644 (file)
@@ -411,8 +411,9 @@ void _Movetype_LinkEdict(entity this, bool touch_triggers)  // SV_LinkEdict
                _Movetype_LinkEdict_TouchAreaGrid(this);
 }
 
-bool _Movetype_TestEntityPosition(entity this, vector ofs)  // SV_TestEntityPosition
+bool _Movetype_TestEntityPosition(/*entity this, */ vector ofs)  // SV_TestEntityPosition
 {
+    SELFPARAM(); // XXX: performance
 //     vector org = this.move_origin + ofs;
 
        int cont = this.dphitcontentsmask;
@@ -430,24 +431,34 @@ bool _Movetype_TestEntityPosition(entity this, vector ofs)  // SV_TestEntityPosi
 
 bool _Movetype_UnstickEntity(entity this)  // SV_UnstickEntity
 {
-       if(!_Movetype_TestEntityPosition(this, '0 0 0')) return true;
-       if(!_Movetype_TestEntityPosition(this, '-1 0 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 0 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '0 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '0 1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '-1 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '-1 1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 1 0')) goto success;
-       for (int i = 1; i <= 17; ++i)
+    entity oldself = this;
+    setself(this);
+       if (!_Movetype_TestEntityPosition(/* this, */ ' 0  0  0')) {
+           setself(oldself);
+           return true;
+       }
+       #define X(v) if (_Movetype_TestEntityPosition(/* this, */ v))
+       X('-1  0  0') X(' 1  0  0')
+       X(' 0 -1  0') X(' 0  1  0')
+       X('-1 -1  0') X(' 1 -1  0')
+       X('-1  1  0') X(' 1  1  0')
+       #undef X
        {
-               if(!_Movetype_TestEntityPosition(this, '0 0 -1' * i)) goto success;
-               if(!_Movetype_TestEntityPosition(this, '0 0 1' * i)) goto success;
+        #define X(i) \
+            if (_Movetype_TestEntityPosition(/* this, */ '0 0 -1' * i)) \
+            if (_Movetype_TestEntityPosition(/* this, */ '0 0 1' * i))
+        X(01) X(02) X(03) X(04) X(05) X(06) X(07) X(08)
+        X(09) X(10) X(11) X(12) X(13) X(14) X(15) X(16)
+        X(17)
+        #undef X
+        {
+            setself(oldself);
+            LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)\n",
+                etof(this), this.classname, vtos(this.move_origin));
+            return false;
+        }
        }
-       LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)\n",
-               etof(this), this.classname, vtos(this.move_origin));
-       return false;
-       : success;
+       setself(oldself);
        LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)\n",
                etof(this), this.classname, vtos(this.move_origin));
        _Movetype_LinkEdict(this, true);
index 9342ecb21053320b103340b91bc5cf9407d2f8fa..ada026df9f93cdc5dc6f3613cb311c455031e97d 100644 (file)
@@ -42,8 +42,6 @@ void _Movetype_CheckWaterTransition(entity ent);
 float _Movetype_CheckWater(entity ent);
 void _Movetype_LinkEdict_TouchAreaGrid(entity this);
 void _Movetype_LinkEdict(entity this, float touch_triggers);
-float _Movetype_TestEntityPosition(entity this, vector ofs);
-float _Movetype_UnstickEntity(entity this);
 vector _Movetype_ClipVelocity(vector vel, vector norm, float f);
 void _Movetype_PushEntityTrace(entity this, vector push);
 float _Movetype_PushEntity(entity this, vector push, float failonstartsolid);