]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Since viewlocation only applies to players, use a much cheaper loop through clients
authorMario <mario@smbclan.net>
Wed, 27 Dec 2017 14:41:56 +0000 (00:41 +1000)
committerMario <mario@smbclan.net>
Wed, 27 Dec 2017 14:41:56 +0000 (00:41 +1000)
qcsrc/common/triggers/trigger/viewloc.qc

index a99cdb4f2d4218ead31fa4cbdefbc6fa49123fa9..41394ac4318909a62f685c869fbf28970919c523 100644 (file)
@@ -13,13 +13,37 @@ REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER)
 
 void viewloc_think(entity this)
 {
-       entity e;
-
        // we abuse this method, rather than using normal .touch, because touch isn't reliable with multiple clients inside the same trigger, and can't "untouch" entities
 
        // set myself as current viewloc where possible
+#if 1
+       FOREACH_CLIENT(it.viewloc == this,
+       {
+               it.viewloc = NULL;
+       });
+#else
+       entity e;
        for(e = NULL; (e = findentity(e, viewloc, this)); )
                e.viewloc = NULL;
+#endif
+
+#if 1
+       FOREACH_CLIENT(!it.viewloc && IS_PLAYER(it),
+       {
+               vector emin = it.absmin;
+               vector emax = it.absmax;
+               if(this.solid == SOLID_BSP)
+               {
+                       emin -= '1 1 1';
+                       emax += '1 1 1';
+               }
+               if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
+               {
+                       if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
+                               it.viewloc = this;
+               }
+       });
+#else
 
                for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
                        if(!e.viewloc)
@@ -37,6 +61,7 @@ void viewloc_think(entity this)
                                                if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
                                                        e.viewloc = this;
                                }
+#endif
 
        this.nextthink = time;
 }