]> git.jsancho.org Git - lugaru.git/commitdiff
rename for readability
authorsf17k <sf171k@gmail.com>
Mon, 30 Jul 2012 04:35:39 +0000 (00:35 -0400)
committersf17k <sf171k@gmail.com>
Mon, 30 Jul 2012 04:35:39 +0000 (00:35 -0400)
findDistancefast -> distsq
findDistancefastflat -> distsqflat

Source/GameDraw.cpp
Source/GameTick.cpp
Source/Models.cpp
Source/Objects.cpp
Source/Person.cpp
Source/Quaternions.h
Source/Sprite.cpp
Source/Terrain.cpp
Source/Weapons.cpp

index a6b02a5ff748f91cc2d64914da7cc0afcad63713..4b60a016c168d84aa9e841f76ed44cb4a39e9173 100644 (file)
@@ -445,7 +445,7 @@ int Game::DrawGLScene(StereoSide side)
                                        glEnable(GL_BLEND);
                                        glEnable(GL_LIGHTING);
                                        terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
-                                       distance=findDistancefast(&viewer,&player[k].coords);
+                                       distance=distsq(&viewer,&player[k].coords);
                                        distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
                                        glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
                                        if(distance>=1)
@@ -470,7 +470,7 @@ int Game::DrawGLScene(StereoSide side)
                }
 
                if(!cameramode&&musictype==stream_fighttheme)
-            playerdist=findDistancefastflat(&player[0].coords,&viewer);
+            playerdist=distsqflat(&player[0].coords,&viewer);
                else
             playerdist=-100;
                glPushMatrix();
@@ -490,7 +490,7 @@ int Game::DrawGLScene(StereoSide side)
                        glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
                        glRotatef(hawkyaw,0,1,0);
                        glTranslatef(25,0,0);
-                       distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
+                       distance=distsq(&viewer,&realhawkcoords)*1.2;
                        glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
                        if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)
                 glColor4f(light.color[0],light.color[1],light.color[2],1);
@@ -508,7 +508,7 @@ int Game::DrawGLScene(StereoSide side)
                                glEnable(GL_BLEND);
                                glEnable(GL_LIGHTING);
                                terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
-                               distance=findDistancefast(&viewer,&player[k].coords);
+                               distance=distsq(&viewer,&player[k].coords);
                                distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
                                glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
                                if(distance>=1)
@@ -917,9 +917,9 @@ int Game::DrawGLScene(StereoSide side)
                 float distance=0;
                 closest=currenthotspot;
                 for(i=0;i<numhotspots;i++){
-                    distance=findDistancefast(&player[0].coords,&hotspot[i]);
+                    distance=distsq(&player[0].coords,&hotspot[i]);
                     if(closestdist==-1||distance<closestdist){
-                        if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
+                        if(distsq(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
                             closestdist=distance;
                             closest=i;
                         }
@@ -929,7 +929,7 @@ int Game::DrawGLScene(StereoSide side)
                     currenthotspot=closest;
                 if(currenthotspot!=-1){
                     if(hotspottype[closest]<=10){
-                        if(findDistancefast(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
+                        if(distsq(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
                             tutorialstagetime=0;
                         tutorialmaxtime=1;
                         tutorialopac=tutorialmaxtime-tutorialstagetime;
@@ -1473,7 +1473,7 @@ int Game::DrawGLScene(StereoSide side)
                        float tempdist;
                        //~ int whichclosest;
                        for(i=0;i<objects.numobjects;i++){
-                               tempdist=findDistancefast(&center,&objects.position[i]);
+                               tempdist=distsq(&center,&objects.position[i]);
                                if(tempdist>maxdistance){
                                        //~ whichclosest=i;
                                        maxdistance=tempdist;
@@ -1481,7 +1481,7 @@ int Game::DrawGLScene(StereoSide side)
                        }
                        for(i=0;i<numplayers;i++){
                                if(!player[i].dead){
-                                       tempdist=findDistancefast(&center,&player[i].coords);
+                                       tempdist=distsq(&center,&player[i].coords);
                                        if(tempdist>maxdistance){
                                                //~ whichclosest=i;
                                                maxdistance=tempdist;
@@ -1500,7 +1500,7 @@ int Game::DrawGLScene(StereoSide side)
                        glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
                        for(i=0;i<objects.numobjects;i++){
                                if(objects.type[i]==treetrunktype){
-                                       distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
+                                       distcheck=distsq(&player[0].coords,&objects.position[i]);
                                        if(distcheck<mapviewdist){
                         Mapcircletexture.bind();
                                                glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
@@ -1522,7 +1522,7 @@ int Game::DrawGLScene(StereoSide side)
                                        }
                                }
                                if(objects.type[i]==boxtype){
-                                       distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
+                                       distcheck=distsq(&player[0].coords,&objects.position[i]);
                                        if(distcheck<mapviewdist){
                                                Mapboxtexture.bind();
                                                glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
@@ -1565,7 +1565,7 @@ int Game::DrawGLScene(StereoSide side)
                                }
                        }
                        for(i=0;i<numplayers;i++){
-                               distcheck=findDistancefast(&player[0].coords,&player[i].coords);
+                               distcheck=distsq(&player[0].coords,&player[i].coords);
                                if(distcheck<mapviewdist){
                                        glPushMatrix();
                     Maparrowtexture.bind();
index 3522f20d6194b8d55ba8e524b1053f08a2b972aa..a53ea7f11d8035c2742ee888992215e358093e05 100644 (file)
@@ -614,7 +614,7 @@ static int findClosestPlayer(){
     float closestdist = std::numeric_limits<float>::max();
 
     for(int i=1; i<numplayers; i++){
-        float distance = findDistancefast(&player[i].coords, &player[0].coords);
+        float distance = distsq(&player[i].coords, &player[0].coords);
         if(distance < closestdist){
             closestdist = distance;
             closest = i;
@@ -628,7 +628,7 @@ static int findClosestObject(){
     float closestdist = std::numeric_limits<float>::max();
 
     for(int i=0; i<objects.numobjects; i++){
-        float distance = findDistancefast(&objects.position[i], &player[0].coords);
+        float distance = distsq(&objects.position[i], &player[0].coords);
         if(distance < closestdist){
             closestdist = distance;
             closest = i;
@@ -1878,7 +1878,7 @@ void Loadlevel(const char *name) {
                        float tempdist;
                        //~ int whichclosest;
                        for(int i=0;i<objects.numobjects;i++){
-                               tempdist=findDistancefast(&objects.center,&objects.position[i]);
+                               tempdist=distsq(&objects.center,&objects.position[i]);
                                if(tempdist>maxdistance){
                                        //~ whichclosest=i;
                                        maxdistance=tempdist;
@@ -2800,7 +2800,7 @@ void doDebugKeys(){
             float closestdist = std::numeric_limits<float>::max();
 
             for(int i=1; i<numplayers; i++){
-                float distance = findDistancefast(&player[i].coords, &player[0].coords);
+                float distance = distsq(&player[i].coords, &player[0].coords);
                 if(!player[i].headless)
                     if(distance < closestdist){
                         closestdist = distance;
@@ -2810,7 +2810,7 @@ void doDebugKeys(){
 
             XYZ flatfacing2,flatvelocity2;
             XYZ blah;
-            if(closest!=-1 && findDistancefast(&player[closest].coords, &player[0].coords)<144){
+            if(closest!=-1 && distsq(&player[closest].coords, &player[0].coords)<144){
                 blah = player[closest].coords;
                 XYZ headspurtdirection;
                 //int i = player[closest].skeleton.jointlabels[head];
@@ -2852,7 +2852,7 @@ void doDebugKeys(){
             int closest=findClosestPlayer();
             XYZ flatfacing2,flatvelocity2;
             XYZ blah;
-            if(closest>=0 && findDistancefast(&player[closest].coords,&player[0].coords)<144){
+            if(closest>=0 && distsq(&player[closest].coords,&player[0].coords)<144){
                 blah=player[closest].coords;
                 emit_sound_at(splattersound, blah);
                 emit_sound_at(breaksound2, blah);
@@ -2909,18 +2909,18 @@ void doDebugKeys(){
                 XYZ temppos;
                 for(int j=0;j<numplayers; j++){
                     if(j!=closest){
-                        if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
-                            player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
+                        if(distsq(&player[j].coords,&player[closest].coords)<25){
+                            player[j].DoDamage((25-distsq(&player[j].coords,&player[closest].coords))*60);
                             if(player[j].skeleton.free==2)
                                 player[j].skeleton.free=1;
                             player[j].skeleton.longdead=0;
                             player[j].RagDoll(0);
                             for(int i=0;i<player[j].skeleton.num_joints; i++){
                                 temppos=player[j].skeleton.joints[i].position+player[j].coords;
-                                if(findDistancefast(&temppos,&player[closest].coords)<25){
+                                if(distsq(&temppos,&player[closest].coords)<25){
                                     flatvelocity2=temppos-player[closest].coords;
                                     Normalise(&flatvelocity2);
-                                    player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
+                                    player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-distsq(&temppos,&player[closest].coords))*20);
                                 }
                             }
                         }
@@ -3188,7 +3188,7 @@ void doDebugKeys(){
                     connected=0;
                     if(numpathpoints>1)
                         for(int i=0;i<numpathpoints;i++){
-                            if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
+                            if(distsq(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
                                 alreadyconnected=0;
                                 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
                                     if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
@@ -3313,8 +3313,8 @@ void doJumpReversals(){
                      player[k].aitype==playercontrolled)&&
                     (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
                      player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
-                if(     findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
-                        findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
+                if(     distsq(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
+                        distsqflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
                     //TODO: refactor two huge similar ifs
                     if(player[i].targetanimation==jumpupanim&&
                             player[k].targetanimation!=getupfrombackanim&&
@@ -3436,13 +3436,13 @@ void doAerialAcrobatics(){
             player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*4);
         }
 
-        /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
+        /*if(player[k].aitype!=passivetype||(distsq(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
         player[k].DoStuff();
         if(player[k].immobile&&k!=0)
             player[k].coords=player[k].realoldcoords;
 
         //if player's position has changed (?)
-        if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
+        if(distsq(&player[k].coords,&player[k].realoldcoords)>0&&
                 !player[k].skeleton.free&&
                 player[k].targetanimation!=climbanim&&
                 player[k].targetanimation!=hanganim){
@@ -3834,7 +3834,7 @@ void doAttacks(){
                                     player[i].targetanimation==knifeslashstartanim||
                                     player[i].targetanimation==staffhitanim||
                                     player[i].targetanimation==staffspinhitanim)
-                                if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
+                                if(distsq(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
                                     player[k].setAnimation(dodgebackanim);
                                     player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
                                     player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
@@ -3870,7 +3870,7 @@ void doAttacks(){
                             if(!player[k].hasvictim)
                                 if(animation[player[k].targetanimation].attack!=reversal){
                                     //choose an attack
-                                    const float distance=findDistancefast(&player[k].coords,&player[i].coords);
+                                    const float distance=distsq(&player[k].coords,&player[i].coords);
                                     if(distance<4.5&&
                                             !player[i].skeleton.free&&
                                             player[i].howactive<typedead1&&
@@ -4139,7 +4139,7 @@ void doAttacks(){
                             if(i==k)continue;
                             if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
                                     animation[player[k].targetanimation].attack==neutral){
-                                const float distance=findDistancefast(&player[k].coords,&player[i].coords);
+                                const float distance=distsq(&player[k].coords,&player[i].coords);
                                 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
                                     if(player[i].skeleton.free)
                                         if(distance<3.5*sq(player[k].scale*5)&&
@@ -4263,8 +4263,8 @@ void doAttacks(){
                             if(i==k||!(i==0||k==0))continue;
                             if(!player[i].skeleton.free){
                                 if(player[k].hasvictim){
-                                    if(findDistancefast(&player[k].coords,&player[i].coords)<
-                                       findDistancefast(&player[k].coords,&player[k].victim->coords))
+                                    if(distsq(&player[k].coords,&player[i].coords)<
+                                       distsq(&player[k].coords,&player[k].victim->coords))
                                         player[k].victim=&player[i];
                                 }else{
                                     player[k].victim=&player[i];
@@ -4279,8 +4279,8 @@ void doAttacks(){
                                 player[k].isRun()&&
                                 player[k].wasRun()&&
                                 ((player[k].hasvictim&&
-                                  findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
-                                  findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
+                                  distsq(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
+                                  distsq(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
                                   !player[k].victim->skeleton.free&&
                                   player[k].victim->targetanimation!=getupfrombackanim&&
                                   player[k].victim->targetanimation!=getupfromfrontanim&&
@@ -4343,7 +4343,7 @@ void doPlayerCollisions(){
                 if(player[i].coords.z>player[k].coords.z-3)
                 if(player[i].coords.z<player[k].coords.z+3){
                     //spread fire from player to player
-                    if(findDistancefast(&player[i].coords,&player[k].coords)
+                    if(distsq(&player[i].coords,&player[k].coords)
                             <3*sq((player[i].scale+player[k].scale)*2.5)){
                         if(player[i].onfire||player[k].onfire){
                             if(!player[i].onfire)player[i].CatchFire();
@@ -4362,8 +4362,8 @@ void doPlayerCollisions(){
                         if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
                             collisionradius=3;
                     if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
-                            (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
-                             findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
+                            (distsq(&tempcoords1,&tempcoords2)<collisionradius||
+                             distsq(&player[i].coords,&player[k].coords)<collisionradius)){
                         //jump down on a dead body
                         if(k==0||i==0){
                             int l=i?i:k;
@@ -4375,7 +4375,7 @@ void doPlayerCollisions(){
                                     player[l].dead&&
                                     player[0].lastcollide<=0&&
                                     fabs(player[l].coords.y-player[0].coords.y)<.2&&
-                                    findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
+                                    distsq(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
                                 player[0].coords.y=player[l].coords.y;
                                 player[l].velocity=player[0].velocity;
                                 player[l].skeleton.free=0;
@@ -4440,7 +4440,7 @@ void doPlayerCollisions(){
                                      animation[player[k].targetanimation].attack==normalattack)){
                                 //If bumped
                                 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
-                                    if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
+                                    if(distsq(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
                                         rotatetarget=player[k].coords-player[i].coords;
                                         Normalise(&rotatetarget);
                                         player[k].coords=(player[k].coords+player[i].coords)/2;
@@ -4518,7 +4518,7 @@ void doAI(int i){
             player[i].stunned=1;
 
         player[i].pause=0;
-        if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
+        if(distsqflat(&player[0].coords,&player[i].coords)<30&&
                 player[0].coords.y>player[i].coords.y+2&&
                 !player[0].onterrain)
             player[i].pause=1;
@@ -4533,8 +4533,8 @@ void doAI(int i){
                 closest=-1;
                 closestdistance=-1;
                 for(int j=0;j<numpathpoints;j++)
-                    if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
-                        closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
+                    if(closest==-1||distsq(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
+                        closestdistance=distsq(&player[i].finalfinaltarget,&pathpoint[j]);
                         closest=j;
                         player[i].finaltarget=pathpoint[j];
                     }
@@ -4563,8 +4563,8 @@ void doAI(int i){
                 if(player[i].lastpathfindpoint==-1){
                     for(int j=0;j<numpathpoints;j++){
                         if(j!=player[i].lastpathfindpoint)
-                            if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
-                                closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
+                            if(closest==-1||(distsq(&player[i].coords,&pathpoint[j])<closestdistance)){
+                                closestdistance=distsq(&player[i].coords,&pathpoint[j]);
                                 closest=j;
                             }
                     }
@@ -4617,7 +4617,7 @@ void doAI(int i){
             player[i].lookyaw=player[i].targetyaw;
 
             //reached target point
-            if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
+            if(distsqflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
@@ -4630,9 +4630,9 @@ void doAI(int i){
                     player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
                 player[i].targetpathfindpoint=-1;
             }
-            if(     findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
-                    findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
-                    findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
+            if(     distsqflat(&player[i].coords,&player[i].finalfinaltarget)<
+                    distsqflat(&player[i].coords,&player[i].finaltarget)||
+                    distsqflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
                     player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
                 player[i].aitype=passivetype;
             }
@@ -4656,14 +4656,14 @@ void doAI(int i){
             if((tutoriallevel!=1||cananger)&&
                     hostile&&
                     !player[0].dead&&
-                    findDistancefast(&player[i].coords,&player[0].coords)<400&&
+                    distsq(&player[i].coords,&player[0].coords)<400&&
                     player[i].occluded<25){
-                if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
+                if(distsq(&player[i].coords,&player[0].coords)<12&&
                         animation[player[0].targetanimation].height!=lowheight&&
                         !editorenabled&&
                         (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
                     player[i].aitype=attacktypecutoff;
-                if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
+                if(distsq(&player[i].coords,&player[0].coords)<30&&
                         animation[player[0].targetanimation].height==highheight&&
                         !editorenabled)
                     player[i].aitype=attacktypecutoff;
@@ -4673,7 +4673,7 @@ void doAI(int i){
                     for(int j=0;j<numplayers;j++)
                         if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
                             if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
-                                if(findDistancefast(&player[i].coords,&player[j].coords)<400)
+                                if(distsq(&player[i].coords,&player[j].coords)<400)
                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
                                         if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
                                             if(!player[j].isWallJump()&&-1==checkcollide(
@@ -4714,7 +4714,7 @@ void doAI(int i){
                     player[i].lookyaw=player[i].targetyaw;
                     player[i].aiupdatedelay=.05;
 
-                    if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
+                    if(distsqflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
                         if(player[i].waypointtype[player[i].waypoint]==wppause)
                             player[i].pausetime=4;
                         player[i].waypoint++;
@@ -4743,8 +4743,8 @@ void doAI(int i){
                         float leftdist,rightdist;
                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
-                        leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
-                        rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+                        leftdist = distsq(&leftpos, &player[i].avoidwhere);
+                        rightdist = distsq(&rightpos, &player[i].avoidwhere);
                         if(leftdist<rightdist)
                             player[i].targetyaw+=90;
                         else
@@ -4764,7 +4764,7 @@ void doAI(int i){
                     if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
                         for(int j=0;j<numenvsounds;j++){
                             float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
-                            if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
+                            if(vol>0&&distsq(&player[i].coords,&envsound[j])<
                                     2*(vol+vol*(player[i].creature==rabbittype)*3))
                                 player[i].aitype=attacktypecutoff;
                         }
@@ -4779,12 +4779,12 @@ void doAI(int i){
             if(player[i].howactive<typesleeping&&
                     ((tutoriallevel!=1||cananger)&&hostile)&&
                     !player[0].dead&&
-                    findDistancefast(&player[i].coords,&player[0].coords)<400&&
+                    distsq(&player[i].coords,&player[0].coords)<400&&
                     player[i].occluded<25){
-                if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
+                if(distsq(&player[i].coords,&player[0].coords)<12&&
                         animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
                     player[i].aitype=attacktypecutoff;
-                if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
+                if(distsq(&player[i].coords,&player[0].coords)<30&&
                         animation[player[0].targetanimation].height==highheight&&!editorenabled)
                     player[i].aitype=attacktypecutoff;
 
@@ -4806,7 +4806,7 @@ void doAI(int i){
                             windsmell=windvector;
                             Normalise(&windsmell);
                             windsmell=windsmell*2+player[j].coords;
-                            if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
+                            if(distsq(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
                                 player[i].aitype=attacktypecutoff;
                         }
                     }
@@ -4817,7 +4817,7 @@ void doAI(int i){
                     for(int j=0;j<numplayers;j++){
                         if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
                             if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
-                                if(findDistancefast(&player[i].coords,&player[j].coords)<400)
+                                if(distsq(&player[i].coords,&player[j].coords)<400)
                                     if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
                                         if((-1==checkcollide(
                                                         DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
@@ -4900,7 +4900,7 @@ void doAI(int i){
                 player[i].aiupdatedelay=.05;
                 player[i].forwardkeydown=1;
 
-                if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
+                if(distsqflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
                     player[i].forwardkeydown=0;
                     player[i].aiupdatedelay=1;
                     player[i].lastseen.x+=(float(Random()%100)-50)/25;
@@ -4922,8 +4922,8 @@ void doAI(int i){
                         float leftdist,rightdist;
                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
-                        leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
-                        rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+                        leftdist = distsq(&leftpos, &player[i].avoidwhere);
+                        rightdist = distsq(&rightpos, &player[i].avoidwhere);
                         if(leftdist<rightdist)player[i].targetyaw+=90;
                         else player[i].targetyaw-=90;
                     }
@@ -4936,7 +4936,7 @@ void doAI(int i){
 
             if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
                 for(int k=0;k<numenvsounds;k++){
-                    if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
+                    if(distsq(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
                         player[i].aitype=attacktypecutoff;
                     }
                 }
@@ -4947,13 +4947,13 @@ void doAI(int i){
                     player[i].occluded<2&&
                     ((tutoriallevel!=1||cananger)&&hostile)){
                 player[i].losupdatedelay=.2;
-                if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
+                if(distsq(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
                     player[i].aitype=attacktypecutoff;
                     player[i].lastseentime=1;
                 }
                 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
                     //TODO: factor out canSeePlayer()
-                    if(findDistancefast(&player[i].coords,&player[0].coords)<400)
+                    if(distsq(&player[i].coords,&player[0].coords)<400)
                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
                             if((checkcollide(
                                         DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
@@ -5006,7 +5006,7 @@ void doAI(int i){
                                 player[k].howactive<typedead1&&
                                 !player[k].skeleton.free&&
                                 player[k].aitype==passivetype) {
-                            float distance=findDistancefast(&player[i].coords,&player[k].coords);
+                            float distance=distsq(&player[i].coords,&player[k].coords);
                             if(closestdist==-1||distance<closestdist) {
                                 closestdist=distance;
                                 closest=k;
@@ -5048,7 +5048,7 @@ void doAI(int i){
                     player[i].aiupdatedelay=.05;
                     player[i].forwardkeydown=1;
 
-                    if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
+                    if(distsqflat(&player[i].coords,&player[player[i].ally].coords)<3){
                         player[i].aitype=searchtype;
                         player[i].lastseentime=12;
                         player[player[i].ally].aitype=searchtype;
@@ -5067,8 +5067,8 @@ void doAI(int i){
                             float leftdist,rightdist;
                             leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
                             rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
-                            leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
-                            rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+                            leftdist = distsq(&leftpos, &player[i].avoidwhere);
+                            rightdist = distsq(&rightpos, &player[i].avoidwhere);
                             if(leftdist<rightdist)
                                 player[i].targetyaw+=90;
                             else
@@ -5103,7 +5103,7 @@ void doAI(int i){
                     float closestdist=-1;
                     for(int k=0;k<weapons.size();k++)
                         if(weapons[k].owner==-1){
-                            float distance=findDistancefast(&player[i].coords,&weapons[k].position);
+                            float distance=distsq(&player[i].coords,&weapons[k].position);
                             if(closestdist==-1||distance<closestdist){
                                 closestdist=distance;
                                 closest=k;
@@ -5126,7 +5126,7 @@ void doAI(int i){
                 if(!player[0].dead)
                     if(player[i].ally>=0){
                         if(weapons[player[i].ally].owner!=-1||
-                                findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
+                                distsq(&player[i].coords,&weapons[player[i].ally].position)>16){
                             player[i].aitype=attacktypecutoff;
                             player[i].lastseentime=1;
                         }
@@ -5145,8 +5145,8 @@ void doAI(int i){
                                 float leftdist,rightdist;
                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
-                                leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
-                                rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
+                                leftdist = distsq(&leftpos, &player[i].avoidwhere);
+                                rightdist = distsq(&rightpos, &player[i].avoidwhere);
                                 if(leftdist<rightdist)
                                     player[i].targetyaw+=90;
                                 else
@@ -5207,7 +5207,7 @@ void doAI(int i){
                     !player[0].skeleton.free&&
                     player[0].targetanimation!=walljumprightkickanim&&
                     player[0].targetanimation!=walljumpleftkickanim){
-                if(findDistancefast(&player[0].coords,&player[i].coords)<25)
+                if(distsq(&player[0].coords,&player[i].coords)<25)
                     if((1-player[i].damage/player[i].damagetolerance)>.5)
                         player[i].stunned=1;
             }
@@ -5220,7 +5220,7 @@ void doAI(int i){
                                 weapons[i].velocity.x==0&&
                                 weapons[i].velocity.z==0&&
                                 weapons[i].velocity.y==0){
-                            if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
+                            if(distsq(&player[i].coords,&weapons[k].position)<16) {
                                 player[i].wentforweapon++;
                                 player[i].lastchecktime=6;
                                 player[i].aitype=getweapontype;
@@ -5294,18 +5294,18 @@ void doAI(int i){
                 //chase player
                 XYZ rotatetarget=player[0].coords+player[0].velocity;
                 XYZ targetpoint=player[0].coords;
-                if(findDistancefast(&player[0].coords,&player[i].coords)<
-                        findDistancefast(&rotatetarget,&player[i].coords))
+                if(distsq(&player[0].coords,&player[i].coords)<
+                        distsq(&rotatetarget,&player[i].coords))
                     targetpoint+=player[0].velocity*
                         findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
                 player[i].targetyaw=roughDirectionTo(player[i].coords,targetpoint);
                 player[i].lookyaw=player[i].targetyaw;
                 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
 
-                if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
+                if(distsq(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
                     player[i].forwardkeydown=1;
-                else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
-                            findDistancefast(&player[i].coords,&player[0].coords)<9)&&
+                else if((distsq(&player[i].coords,&player[0].coords)>16||
+                            distsq(&player[i].coords,&player[0].coords)<9)&&
                         player[0].weaponactive!=-1)
                     player[i].forwardkeydown=1;
                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
@@ -5341,7 +5341,7 @@ void doAI(int i){
                     player[i].attackkeydown=1;
                 else
                     player[i].attackkeydown=0;
-                if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
+                if(player[i].isRun()&&Random()%6&&distsq(&player[i].coords,&player[0].coords)>7)
                     player[i].attackkeydown=0;
 
                 //TODO: wat
@@ -5366,7 +5366,7 @@ void doAI(int i){
                                  player[i].weaponactive!=-1||
                                  player[j].targetanimation==staffhitanim||
                                  player[j].targetanimation==staffspinhitanim))
-                            if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
+                            if(distsq(&player[j].coords,&player[j].victim->coords)<4&&
                                     player[j].victim==&player[i]&&
                                     (player[j].targetanimation==sweepanim||
                                      player[j].targetanimation==spinkickanim||
@@ -5377,7 +5377,7 @@ void doAI(int i){
                                      player[j].targetanimation==wolfslapanim||
                                      player[j].targetanimation==knifeslashstartanim||
                                      player[j].targetanimation==swordslashanim&&
-                                      (findDistancefast(&player[j].coords,&player[i].coords)<2||
+                                      (distsq(&player[j].coords,&player[i].coords)<2||
                                        player[i].weaponactive!=-1))){
                                 if(target>=0)
                                     target=-1;
@@ -5391,7 +5391,7 @@ void doAI(int i){
                 if(player[i].collided<1)
                     player[i].jumpkeydown=0;
                 if(player[i].collided>.8&&player[i].jumppower>=5||
-                        findDistancefast(&player[i].coords,&player[0].coords)>400&&
+                        distsq(&player[i].coords,&player[0].coords)>400&&
                         player[i].onterrain&&
                         player[i].creature==rabbittype)
                     player[i].jumpkeydown=1;
@@ -5399,7 +5399,7 @@ void doAI(int i){
                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
                     player[0].jumpkeydown=0;
                 if(player[0].targetanimation==jumpdownanim&&
-                        findDistancefast(&player[0].coords,&player[i].coords)<40)
+                        distsq(&player[0].coords,&player[i].coords)<40)
                     player[i].crouchkeydown=1;
                 if(player[i].jumpkeydown)
                     player[i].attackkeydown=0;
@@ -6381,7 +6381,7 @@ void Game::Tick(){
                             realdialoguetype>0&&
                             (dialoguegonethrough[i]==0||!special)&&
                             (special||Input::isKeyPressed(attackkey))){
-                        if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
+                        if(distsq(&player[0].coords,&player[realdialoguetype].coords)<6||
                                 player[realdialoguetype].howactive>=typedead1||
                                 dialoguetype[i]>40&&dialoguetype[i]<50){
                             whichdialogue=i;
@@ -6833,14 +6833,14 @@ void Game::Tick(){
                     //avoid flaming things
                     for(int j=0;j<objects.numobjects;j++)
                         if(objects.onfire[j])
-                            if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
-                                if(     findDistancefast(&player[i].coords,&objects.position[j])<
-                                        findDistancefast(&player[i].coords,&player[0].coords)){
+                            if(distsq(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
+                                if(     distsq(&player[i].coords,&objects.position[j])<
+                                        distsq(&player[i].coords,&player[0].coords)){
                                     player[i].collided=0;
                                     player[i].avoidcollided=1;
                                     if(player[i].avoidsomething==0||
-                                            findDistancefast(&player[i].coords,&objects.position[j])<
-                                            findDistancefast(&player[i].coords,&player[i].avoidwhere)){
+                                            distsq(&player[i].coords,&objects.position[j])<
+                                            distsq(&player[i].coords,&player[i].avoidwhere)){
                                         player[i].avoidwhere=objects.position[j];
                                         player[i].avoidsomething=1;
                                     }
@@ -6849,14 +6849,14 @@ void Game::Tick(){
                     //avoid flaming players
                     for(int j=0;j<numplayers;j++)
                         if(player[j].onfire)
-                            if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
-                                if(     findDistancefast(&player[i].coords,&player[j].coords)<
-                                        findDistancefast(&player[i].coords,&player[0].coords)){
+                            if(distsq(&player[j].coords,&player[i].coords)<sq(0.3)*200)
+                                if(     distsq(&player[i].coords,&player[j].coords)<
+                                        distsq(&player[i].coords,&player[0].coords)){
                                     player[i].collided=0;
                                     player[i].avoidcollided=1;
                                     if(player[i].avoidsomething==0||
-                                            findDistancefast(&player[i].coords,&player[j].coords)<
-                                            findDistancefast(&player[i].coords,&player[i].avoidwhere)){
+                                            distsq(&player[i].coords,&player[j].coords)<
+                                            distsq(&player[i].coords,&player[i].avoidwhere)){
                                         player[i].avoidwhere=player[j].coords;
                                         player[i].avoidsomething=1;
                                     }
@@ -6935,8 +6935,8 @@ void Game::Tick(){
                                             player[i].aitype==playercontrolled)&&
                                         weapons[j].owner==-1&&
                                         player[i].weaponactive==-1)
-                                    if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
-                                        if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
+                                    if(distsqflat(&player[i].coords,&weapons[j].position)<2){
+                                        if(distsq(&player[i].coords,&weapons[j].position)<2){
                                             if(player[i].isCrouch()||
                                                     player[i].targetanimation==sneakanim||
                                                     player[i].isRun()||
@@ -6956,8 +6956,8 @@ void Game::Tick(){
                                                             weapons[j].owner==-1||
                                                         player[i].victim&&
                                                         weapons[j].owner==player[i].victim->id)
-                                                    if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
-                                                        if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
+                                                    if(distsqflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
+                                                        if(distsq(&player[i].coords,&weapons[j].position)<1||player[i].victim){
                                                             if(weapons[j].getType()!=staff)
                                                                 emit_sound_at(knifedrawsound, player[i].coords, 128.);
 
@@ -6972,7 +6972,7 @@ void Game::Tick(){
                                         }else if((player[i].isIdle()||
                                                     player[i].isFlip()||
                                                     player[i].aitype!=playercontrolled)&&
-                                                findDistancefast(&player[i].coords,&weapons[j].position)<5&&
+                                                distsq(&player[i].coords,&weapons[j].position)<5&&
                                                 player[i].coords.y<weapons[j].position.y){
                                             if(!player[i].isFlip()){
                                                 player[i].throwtogglekeydown=1;
@@ -6990,7 +6990,7 @@ void Game::Tick(){
                                                                     weapons[k].owner==-1||
                                                                 player[i].victim&&
                                                                  weapons[k].owner==player[i].victim->id)
-                                                            if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
+                                                            if(distsqflat(&player[i].coords,&weapons[k].position)<3&&
                                                                     player[i].weaponactive==-1){
                                                                 if(weapons[k].getType()!=staff)
                                                                     emit_sound_at(knifedrawsound, player[i].coords, 128.);
@@ -7018,7 +7018,7 @@ void Game::Tick(){
                                             if(j!=i)
                                                 if(player[j].num_weapons&&
                                                         player[j].skeleton.free&&
-                                                        findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
+                                                        distsq(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
                                                         (((player[j].skeleton.forward.y<0&&
                                                            player[j].weaponstuckwhere==0)||
                                                           (player[j].skeleton.forward.y>0&&
@@ -7121,8 +7121,8 @@ void Game::Tick(){
                                                 if(tutoriallevel!=1||tutorialstage==49)
                                                     if(hostile)
                                                         if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
-                                                                findDistancefast(&player[i].coords,&player[j].coords)<100&&
-                                                                findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
+                                                                distsq(&player[i].coords,&player[j].coords)<100&&
+                                                                distsq(&player[i].coords,&player[j].coords)>1.5&&
                                                                 !player[j].skeleton.free&&
                                                                 -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*player[i].scale+player[i].coords)){
                                                             if(!player[i].isFlip()){
@@ -7277,14 +7277,14 @@ void Game::Tick(){
                                 if(numplayers>1)
                                     for(int j=0;j<numplayers;j++)
                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
-                                            if(findDistancefast(&player[j].coords,&player[i].coords)<16)
+                                            if(distsq(&player[j].coords,&player[i].coords)<16)
                                                 player[i].superruntoggle=0;
                             }
 
                             if(numplayers>1)
                                 for(int j=0;j<numplayers;j++){
                                     if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
-                                        if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+                                        if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
                                                 player[j].victim==&player[i]&&
                                                 (player[j].targetanimation==sweepanim||
                                                  player[j].targetanimation==upunchanim||
@@ -7293,7 +7293,7 @@ void Game::Tick(){
                                                    player[j].targetanimation==knifeslashstartanim||
                                                    player[j].targetanimation==staffhitanim||
                                                    player[j].targetanimation==staffspinhitanim)&&
-                                                  findDistancefast(&player[j].coords,&player[i].coords)<2))){
+                                                  distsq(&player[j].coords,&player[i].coords)<2))){
                                             if(target>=0)
                                                 target=-1;
                                             else
@@ -7330,7 +7330,7 @@ void Game::Tick(){
                                                 !player[j].skeleton.free&&
                                                 player[j].victim&&
                                                 player[i].highreversaldelay<=0){
-                                            if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+                                            if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
                                                     player[j].victim==&player[i]&&
                                                     (player[j].targetanimation==spinkickanim)&&
                                                     player[i].isCrouch()){
@@ -7511,7 +7511,7 @@ void Game::Tick(){
                                 if(numplayers>1)
                                     for(int j=0;j<numplayers;j++){
                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
-                                            if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
+                                            if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
                                                     player[j].victim==&player[i]&&
                                                     (player[j].targetanimation==sweepanim)){
                                                 if(target>=0)target=-1;
@@ -7665,7 +7665,7 @@ void Game::Tick(){
                 oldtemp=temp;
                 oldtemp2=temp2;
                 if(tutorialstage>=51)
-                    if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+                    if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
                         OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
@@ -7679,7 +7679,7 @@ void Game::Tick(){
                         flash();
                     }
                 if(tutorialstage<51)
-                    if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+                    if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
                         emit_sound_at(fireendsound, player[0].coords);
 
                         player[0].coords=(oldtemp+oldtemp2)/2;
@@ -7687,7 +7687,7 @@ void Game::Tick(){
                         flash();
                     }
                 if(tutorialstage>=14&&tutorialstage<50)
-                    if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
+                    if(distsq(&temp,&player[1].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[1].coords)<4){
                         emit_sound_at(fireendsound, player[1].coords);
 
                         for(int i=0;i<player[1].skeleton.num_joints;i++){
@@ -7913,7 +7913,7 @@ void Game::TickOnceAfter(){
                winhotspot=false;
                for(int i=0;i<numhotspots;i++)
                        if(hotspottype[i]==-1)
-                               if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
+                               if(distsq(&player[0].coords,&hotspot[i])<hotspotsize[i])
                                        winhotspot=true;
 
                int numalarmed=0;
index 95b93fe4c489d238a2efe1afbfd6e1b04fdc7885..9f92cb531d2f5eeabc43b4396ba7e83eb5905f49 100644 (file)
@@ -173,7 +173,7 @@ int Model::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate)
        oldp1=*p1;
        *p1=*p1-*move;
        if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
-       if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1;
+       if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1;
 
        for(i=0;i<4;i++){
                for (j=0;j<TriangleNum;j++){
@@ -230,7 +230,7 @@ int Model::SphereCheckPossible(XYZ *p1,float radius, XYZ *move, float *rotate)
        numpossible=0;
 
        if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
-       if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
+       if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;}
 
        for (j=0;j<TriangleNum;j++){
                intersecting=0;
@@ -458,8 +458,8 @@ bool Model::loadnotex(const char *filename )
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -538,8 +538,8 @@ bool Model::load(const char *filename,bool texture )
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -620,8 +620,8 @@ bool Model::loaddecal(const char *filename,bool texture )
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -769,8 +769,8 @@ void Model::Scale(float xscale,float yscale,float zscale)
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -809,8 +809,8 @@ void Model::Translate(float xtrans,float ytrans,float ztrans)
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -830,8 +830,8 @@ void Model::Rotate(float xang,float yang,float zang)
        boundingsphereradius=0;
        for(i=0;i<vertexNum;i++){
                for(j=0;j<vertexNum;j++){
-                       if(j!=i&&findDistancefast(&vertex[j],&vertex[i])/2>boundingsphereradius){
-                               boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2;
+                       if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){
+                               boundingsphereradius=distsq(&vertex[j],&vertex[i])/2;
                                boundingspherecenter=(vertex[i]+vertex[j])/2;
                        }
                }
@@ -1151,7 +1151,7 @@ void Model::MakeDecal(int atype, XYZ *where,float *size, float *opacity, float *
                static int i,j;
 
                if(*opacity>0)
-                       if(findDistancefast(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size))
+                       if(distsq(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size))
                                for(i=0;i<TriangleNum;i++){
                                        if(facenormals[i].y<-.1&&(vertex[Triangles[i].vertex[0]].y<where->y||vertex[Triangles[i].vertex[1]].y<where->y||vertex[Triangles[i].vertex[2]].y<where->y)){
                                                decalposition[numdecals]=*where;
@@ -1228,7 +1228,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota
                static int i,j;
 
                if(opacity>0)
-                       if(findDistancefast(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size))
+                       if(distsq(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size))
                                for(i=0;i<TriangleNum;i++){
                                        distance=abs(((facenormals[i].x*where.x)+(facenormals[i].y*where.y)+(facenormals[i].z*where.z)-((facenormals[i].x*vertex[Triangles[i].vertex[0]].x)+(facenormals[i].y*vertex[Triangles[i].vertex[0]].y)+(facenormals[i].z*vertex[Triangles[i].vertex[0]].z))));
                                        if(distance<.02&&abs(facenormals[i].y)>abs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){
index 8f2544f905df5a3666839c95130deaf479d75263..06c8b8bdd360f41c9c8f754971a2c514ddde6e71 100644 (file)
@@ -90,9 +90,9 @@ void Objects::Draw()
                if(type[i]!=firetype){
                        moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
                        if(type[i]==tunneltype||frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){   
-                               distance=findDistancefast(&viewer,&position[i]);
+                               distance=distsq(&viewer,&position[i]);
                                distance*=1.2;
-                               hidden=!(findDistancefastflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype));
+                               hidden=!(distsqflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype));
                                if(!hidden){
 
                                        if(detail==2&&distance>viewdistance*viewdistance/4&&environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
@@ -329,7 +329,7 @@ void Objects::Draw()
                if(type[i]==treeleavestype||type[i]==bushtype){
                        moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0);
                        if(frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){   
-                               hidden=findDistancefastflat(&viewer,&position[i])<=playerdist+3;
+                               hidden=distsqflat(&viewer,&position[i])<=playerdist+3;
                                if(hidden){
                                        distance=1;
                                        if(distance>0){
index 87a4bbe952169d8071309255f4847fe9ab399da5..10118c13d56c847d778bd0ead1d6d6e28b239a48 100644 (file)
@@ -93,7 +93,7 @@ void Person::CheckKick()
            && victim != this
            && currentframe >= 2
            && currentanimation == rabbitkickanim)
-       && (findDistancefast(&coords,&victim->coords) < 1.2)
+       && (distsq(&coords,&victim->coords) < 1.2)
        && (!victim->skeleton.free)))
     return;
 
@@ -552,9 +552,9 @@ bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
                        t = dotproduct(&temp,&N)/findLength(&N);
                        r = 1 - (s + t);*/
 
-                       bary.x=findDistancefast(&p0,&p1);
-                       bary.y=findDistancefast(&p0,&p2);
-                       bary.z=findDistancefast(&p0,&p3);
+                       bary.x=distsq(&p0,&p1);
+                       bary.y=distsq(&p0,&p2);
+                       bary.z=distsq(&p0,&p3);
 
                        total=bary.x+bary.y+bary.z;
                        bary.x/=total;
@@ -775,7 +775,7 @@ void Person::Reverse()
     victim->currentanimation=upunchreversalanim;
     victim->targetanimation=upunchreversalanim;
   }
-  if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
+  if(targetanimation==staffhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
     if(victim->weaponactive!=-1){
       victim->throwtogglekeydown=1;
       weapons[victim->weaponids[0]].owner=-1;
@@ -803,7 +803,7 @@ void Person::Reverse()
     victim->currentanimation=staffhitreversalanim;
     victim->targetanimation=staffhitreversalanim;
   }
-  if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
+  if(targetanimation==staffspinhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
     if(victim->weaponactive!=-1){
       victim->throwtogglekeydown=1;
       weapons[victim->weaponids[0]].owner=-1;
@@ -830,7 +830,7 @@ void Person::Reverse()
     victim->currentanimation=staffspinhitreversalanim;
     victim->targetanimation=staffspinhitreversalanim;
   }
-  if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
+  if(targetanimation==swordslashanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
     if(victim->weaponactive!=-1){
       victim->throwtogglekeydown=1;
       weapons[victim->weaponids[0]].owner=-1;
@@ -857,7 +857,7 @@ void Person::Reverse()
     victim->currentanimation=swordslashreversalanim;
     victim->targetanimation=swordslashreversalanim;
   }
-  if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
+  if(targetanimation==knifeslashstartanim&&distsq(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
     if(victim->weaponactive!=-1){
       victim->throwtogglekeydown=1;
       weapons[victim->weaponids[0]].owner=-1;
@@ -1008,7 +1008,7 @@ void Person::Reverse()
   }
   if(hasvictim)
     if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
-      if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
+      if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||distsq(&coords,&victim->coords)>.2){
        victim->targetanimation=dodgebackanim;
        victim->targetframe=0;
        victim->target=0;
@@ -1391,7 +1391,7 @@ void Person::FootLand(int which, float opacity){
                        if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
                        if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
                        //footpoint.y=coords.y;
-                       if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
+                       if(distsq(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
                }
                else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
                        footvel=velocity/5;
@@ -1400,8 +1400,8 @@ void Person::FootLand(int which, float opacity){
                        if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
                        footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
                        terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
-                       if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
-                       if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,yaw);
+                       if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
+                       if(opacity>=1||detail==2)if(detail==2)if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,yaw);
                }
                else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
                        footvel=velocity/5;
@@ -1410,7 +1410,7 @@ void Person::FootLand(int which, float opacity){
                        if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
                        footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
                        terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
-                       if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5*opacity);
+                       if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5*opacity);
                }
                else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
                        footvel=velocity/5;
@@ -1419,8 +1419,8 @@ void Person::FootLand(int which, float opacity){
                        if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
                        footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
                        terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
-                       if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7*opacity);
-                       if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,yaw);
+                       if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7*opacity);
+                       if(opacity>=1||detail==2)if(detail==2)if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,yaw);
                }
                else if(isLanding()||targetanimation==jumpupanim||isLandhard())
                {
@@ -1429,7 +1429,7 @@ void Person::FootLand(int which, float opacity){
                        if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
                        if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
                        //footpoint.y=coords.y;
-                       if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
+                       if(distsq(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
                }
 }
 
@@ -1658,8 +1658,8 @@ void      Person::DoAnimations(){
                                                        if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
                                                                for(i=0;i<weapons.size();i++){
                                                                        if(weapons[i].owner==-1)
-                                                                               if(findDistancefastflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
-                                                                                       if(findDistancefast(&coords,&weapons[i].position)>=1){
+                                                                               if(distsqflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
+                                                                                       if(distsq(&coords,&weapons[i].position)>=1){
                                                                                                if(weapons[i].getType()!=staff){
                                                                                                        emit_sound_at(knifedrawsound, coords, 128.);
                                                                                                }
@@ -1684,8 +1684,8 @@ void      Person::DoAnimations(){
                                                                                        if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i)
                                                                                                if(player[weapons[i].owner].num_weapons>1)willwork=0;
                                                                        if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free))
-                                                                               if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
-                                                                                       if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){
+                                                                               if(willwork&&distsqflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
+                                                                                       if(distsq(&coords,&weapons[i].position)<1||hasvictim){
                                                                                                bool fleshstuck=false;
                                                                                                if(weapons[i].owner!=-1)
                                                                                                        if(victim->weaponstuck!=-1){
@@ -1789,7 +1789,7 @@ void      Person::DoAnimations(){
                                                        dojumpattack=0;
                                                        if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
                                                        if(hasvictim)
-                       if(findDistancefast(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1;                                                  if(!hostile)dojumpattack=0;
+                       if(distsq(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1;                                                    if(!hostile)dojumpattack=0;
                                                        if(dojumpattack){
                                                                if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
                                                                        targetanimation=rabbittackleanim;
@@ -1807,8 +1807,8 @@ void      Person::DoAnimations(){
                                                                targetloc+=coords;
                                                                for(i=0;i<numplayers;i++){
                                                                        if(i!=id)
-                                                                               if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
-                                                                                       closestdist=findDistancefast(&targetloc,&player[i].coords);
+                                                                               if(distsq(&targetloc,&player[i].coords)<closestdist||closestdist==0){
+                                                                                       closestdist=distsq(&targetloc,&player[i].coords);
                                                                                        closestid=i;
                                                                                }
                                                                }
@@ -1842,7 +1842,7 @@ void      Person::DoAnimations(){
                                                        //if(onfire)damagemult=3;
                                                        if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
                                                                if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(Random()%2||creature==wolftype){
@@ -1877,7 +1877,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(Random()%2||creature==wolftype){
@@ -1909,7 +1909,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                victim->spurt=1;
@@ -1944,7 +1944,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                victim->spurt=1;
@@ -1979,7 +1979,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(Random()%2){
@@ -2003,7 +2003,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.2;
                                                                                emit_sound_at(whooshhitsound, victim->coords, 128.);
@@ -2036,7 +2036,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(tutoriallevel!=1){
@@ -2060,7 +2060,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(tutoriallevel!=1){
@@ -2110,7 +2110,7 @@ void      Person::DoAnimations(){
                                                                        }
 
                                                                        if(victim&&hasvictim){
-                                                                               if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+                                                                               if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
 
                                                                                        XYZ where,startpoint,endpoint,movepoint,colpoint;
                                                                                        float rotationpoint;
@@ -2242,7 +2242,7 @@ void      Person::DoAnimations(){
                                                                                }
                                                                                hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
                                                                                if(hasvictim){
-                                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+                                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
                                                                                                victim->skeleton.longdead=0;
                                                                                                victim->skeleton.free=1;
                                                                                                victim->skeleton.broken=0;
@@ -2276,7 +2276,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(Random()%2){
@@ -2313,7 +2313,7 @@ void      Person::DoAnimations(){
 
 
                                                                if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
@@ -2359,7 +2359,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
                                                                                if(victim->id==0)camerashake+=.4;
                                                                                emit_sound_at(landsound2, victim->coords);
 
@@ -2368,7 +2368,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
                                                                                if(victim->id==0)camerashake+=.4;
 
                                                                                if(weaponactive!=-1){
@@ -2414,7 +2414,7 @@ void      Person::DoAnimations(){
 
                                                                if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
                                                                        if(hasvictim)
-                                                                               if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
+                                                                               if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
                                                                                        escapednum=0;
                                                                                        if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
 
@@ -2462,7 +2462,7 @@ void      Person::DoAnimations(){
                                                                                }
                                                                }
                                                                if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
                                                                                if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
                                                                                        award_bonus(id, Slashbonus);
                                                                                        escapednum=0;
@@ -2487,7 +2487,7 @@ void      Person::DoAnimations(){
                                                                                                float bloodlossamount;
                                                                                                bloodlossamount=200+abs((float)(Random()%40))-20;
                                                                                                victim->bloodloss+=bloodlossamount/victim->armorhigh;
-                                                                                               //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
+                                                                                               //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
                                                                                                victim->DoDamage(damagemult*0);
 
                                                                                                XYZ footvel,footpoint;
@@ -2553,7 +2553,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
                                                                                if(tutoriallevel!=1){
                                                                                        weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250;
                                                                                        escapednum=0;
@@ -2587,7 +2587,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
                                                                                if(tutoriallevel!=1){
                                                                                        weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250;
                                                                                        escapednum=0;
@@ -2618,7 +2618,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
                                                                                escapednum=0;
                                                                                if(tutoriallevel!=1){
                                                                                        if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500;
@@ -2672,7 +2672,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
+                                                                       if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.4;
                                                                                XYZ relative;
@@ -2730,7 +2730,7 @@ void      Person::DoAnimations(){
                                                                }
 
                                                                if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
-                                                                       if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
+                                                                       if(victim->targetanimation!=jumpupanim&&distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
                                                                                escapednum=0;
                                                                                if(id==0)camerashake+=.2;
                                                                                if(tutoriallevel!=1){
@@ -3324,7 +3324,7 @@ void      Person::DoAnimations(){
                                                                                if(numplayers>1)
                                                                                        for(i=0;i<numplayers;i++){
                                                                                                if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
-                                                                                                       distance=findDistancefast(&player[i].coords,&coords);
+                                                                                                       distance=distsq(&player[i].coords,&coords);
                                                                                                        if(closestdist==-1||distance<closestdist){
                                                                                                                closestdist=distance;
                                                                                                                closest=i;
@@ -3381,7 +3381,7 @@ void      Person::DoAnimations(){
                                                                                if(numplayers>1)
                                                                                        for(i=0;i<numplayers;i++){
                                                                                                if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
-                                                                                                       distance=findDistancefast(&player[i].coords,&coords);
+                                                                                                       distance=distsq(&player[i].coords,&coords);
                                                                                                        if(closestdist==-1||distance<closestdist){
                                                                                                                closestdist=distance;
                                                                                                                closest=i;
@@ -3795,7 +3795,7 @@ void      Person::DoStuff(){
                superruntoggle=0;
                if(aitype!=passivetype){
                        superruntoggle=1;
-                       if(aitype==attacktypecutoff&&(player[0].isIdle()||player[0].isCrouch()||player[0].skeleton.free||player[0].targetanimation==getupfrombackanim||player[0].targetanimation==getupfromfrontanim||player[0].targetanimation==sneakanim)&&findDistancefast(&coords,&player[0].coords)<16){
+                       if(aitype==attacktypecutoff&&(player[0].isIdle()||player[0].isCrouch()||player[0].skeleton.free||player[0].targetanimation==getupfrombackanim||player[0].targetanimation==getupfromfrontanim||player[0].targetanimation==sneakanim)&&distsq(&coords,&player[0].coords)<16){
                                superruntoggle=0;
                        }
                }
@@ -3954,7 +3954,7 @@ void      Person::DoStuff(){
                }
        }
 
-       if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
+       if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&distsq(&viewer,&coords)<9){
                texupdatedelay=.12;
 
                bloodsize=5-realtexdetail;
@@ -4339,7 +4339,7 @@ void      Person::DoStuff(){
 
 
 
-               if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
+               if((id==0||distsq(&coords,&viewer)<50)&&autoslomo){
                        slomo=1;
                        slomodelay=.2;
                }
@@ -4707,7 +4707,7 @@ void      Person::DoStuff(){
                if(findLengthfast(&velocity)>.1)
                        for(i=0;i<objects.numobjects;i++){
                                if(objects.type[i]==firetype)
-                                       if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
+                                       if(distsqflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&distsq(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
                                                if(onfire){
                                                        if(!objects.onfire[i]){
                                                                emit_sound_at(firestartsound, objects.position[i]);
@@ -4721,7 +4721,7 @@ void      Person::DoStuff(){
                                                }
                                        }
                                        if(objects.type[i]==bushtype)
-                                               if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
+                                               if(distsqflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&distsq(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
                                                        if(onfire){
                                                                if(!objects.onfire[i]){
                                                                        emit_sound_at(firestartsound, objects.position[i]);
@@ -4793,7 +4793,7 @@ void      Person::DoStuff(){
                                                                tempcoord=DoRotation(tempcoord,-objects.pitch[i],0,0);
                                                                tempcoord+=objects.position[i];
                                                        }
-                                                       if(findDistancefastflat(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*8&&findDistancefast(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*300&&tempcoord.y>objects.position[i].y+3*objects.scale[i]){
+                                                       if(distsqflat(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*8&&distsq(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*300&&tempcoord.y>objects.position[i].y+3*objects.scale[i]){
                                                                if(objects.messedwith[i]<=0){
                                                                        XYZ tempvel;
                                                                        XYZ pos;
@@ -5361,7 +5361,7 @@ void      Person::DoStuff(){
                        midterrain=0;
                        midterrain.x=terrain.size*terrain.scale/2;
                        midterrain.z=terrain.size*terrain.scale/2;
-                       if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
+                       if(distsqflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
                                XYZ tempposit;
                                tempposit=coords-midterrain;
                                tempposit.y=0;
@@ -5374,7 +5374,7 @@ void      Person::DoStuff(){
 
 int Person::DrawSkeleton(){
        int oldplayerdetail;
-       if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
+       if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&distsq(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
                if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
                        calcrot=1;
                }
@@ -5394,13 +5394,13 @@ int Person::DrawSkeleton(){
                if(!isnormal(tilt2))tilt2=0;
                oldplayerdetail=playerdetail;
                playerdetail=0;
-               if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
+               if(distsq(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
                        playerdetail=1;
                }
-               if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
+               if(distsq(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
                        playerdetail=1;
                }
-               if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
+               if(distsq(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
                        playerdetail=1;
                }
                if(id==0)
@@ -5792,7 +5792,7 @@ int Person::DrawSkeleton(){
                }
 
                terrainlight=terrain.getLighting(coords.x,coords.z);
-               distance=findDistancefast(&viewer,&coords);
+               distance=distsq(&viewer,&coords);
                distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
                if(distance>1)distance=1;
                if(distance>0){
@@ -6123,7 +6123,7 @@ int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate,
 
        oldp1=*p1;
        *p1=*p1-*move;
-       if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
+       if(distsq(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
        if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
        for(i=0;i<4;i++){
                for (j=0;j<model->TriangleNum;j++){
index 39037b5f2638ca9fc9392f4bcf67eb162ca32ae7..417c299ef27b091ba3876e7045ca5c25f7b35a25 100644 (file)
@@ -105,9 +105,9 @@ inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang);
 inline float findDistance(XYZ *point1, XYZ *point2);
 inline float findLength(XYZ *point1);
 inline float findLengthfast(XYZ *point1);
-inline float findDistancefast(XYZ *point1, XYZ *point2);
-inline float findDistancefast(XYZ point1, XYZ point2);
-inline float findDistancefastflat(XYZ *point1, XYZ *point2);
+inline float distsq(XYZ *point1, XYZ *point2);
+inline float distsq(XYZ point1, XYZ point2);
+inline float distsqflat(XYZ *point1, XYZ *point2);
 inline float dotproduct(const XYZ *point1, const XYZ *point2);
 bool sphere_line_intersection (
                                                           float x1, float y1 , float z1,
@@ -302,15 +302,15 @@ inline float findLengthfast(XYZ *point1){
        return((point1->x)*(point1->x)+(point1->y)*(point1->y)+(point1->z)*(point1->z));
 }
 
-inline float findDistancefast(XYZ *point1, XYZ *point2){
+inline float distsq(XYZ *point1, XYZ *point2){
        return((point1->x-point2->x)*(point1->x-point2->x)+(point1->y-point2->y)*(point1->y-point2->y)+(point1->z-point2->z)*(point1->z-point2->z));
 }
 
-inline float findDistancefast(XYZ point1, XYZ point2){
+inline float distsq(XYZ point1, XYZ point2){
        return((point1.x-point2.x)*(point1.x-point2.x)+(point1.y-point2.y)*(point1.y-point2.y)+(point1.z-point2.z)*(point1.z-point2.z));
 }
 
-inline float findDistancefastflat(XYZ *point1, XYZ *point2){
+inline float distsqflat(XYZ *point1, XYZ *point2){
        return((point1->x-point2->x)*(point1->x-point2->x)+(point1->z-point2->z)*(point1->z-point2->z));
 }
 
index 334a6f5f5c827d4b1f3005667bc79bfb4382d798..8b7385f160e10119009a951f6d87db16b4aa489e 100644 (file)
@@ -189,9 +189,9 @@ void Sprite::Draw()
                        }
                }
                if(sprites[i]->type==snowsprite)
-                       distancemult=(144-(findDistancefast(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144;
+                       distancemult=(144-(distsq(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144;
                else
-                       distancemult=(viewdistsquared-(findDistancefast(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+                       distancemult=(viewdistsquared-(distsq(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                if(sprites[i]->type==flamesprite){
                        if(distancemult>=1) glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity);
                        else glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity*distancemult);
index ecc8757b7dc953971759fb7a595eff6a1b587cd6..1af30585241816c182360a913e813c112270bcfc 100644 (file)
@@ -103,7 +103,7 @@ int Terrain::lineTerrain(XYZ p1,XYZ p2, XYZ *p)
                                triangles[2].z=j;
 
                                intersecting=LineFacet(p1,p2,triangles[0],triangles[1],triangles[2],&point);
-                               distance=findDistancefast(&p1,&point);
+                               distance=distsq(&p1,&point);
                                if((distance<olddistance||firstintersecting==-1)&&intersecting==1){olddistance=distance; firstintersecting=1; *p=point;}
 
                                triangles[0].x=i+1;
@@ -119,7 +119,7 @@ int Terrain::lineTerrain(XYZ p1,XYZ p2, XYZ *p)
                                triangles[2].z=j+1;
 
                                intersecting=LineFacet(p1,p2,triangles[0],triangles[1],triangles[2],&point);
-                               distance=findDistancefast(&p1,&point);
+                               distance=distsq(&p1,&point);
                                if((distance<olddistance||firstintersecting==-1)&&intersecting==1){olddistance=distance; firstintersecting=1; *p=point;}
                        }
                }
@@ -146,7 +146,7 @@ void Terrain::UpdateTransparency(int whichx, int whichy){
                                vertex.x=i*scale;
                                vertex.z=j*scale;
                                vertex.y=heightmap[i][j]*scale;
-                               distance=findDistancefast(&viewer,&vertex);
+                               distance=distsq(&viewer,&vertex);
                                if(distance>viewdistsquared)distance=viewdistsquared;
                                colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                        }
@@ -222,7 +222,7 @@ void Terrain::UpdateTransparencyotherother(int whichx, int whichy){
                                vertex.x=i*scale;
                                vertex.z=j*scale;
                                vertex.y=heightmap[i][j]*scale;
-                               distance=findDistancefast(&viewer,&vertex);
+                               distance=distsq(&viewer,&vertex);
                                if(distance>viewdistsquared)distance=viewdistsquared;
                                colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                        }
@@ -982,7 +982,7 @@ void Terrain::draw(int layer)
                                terrainpoint.x=i*patch_size+(patch_size)/2;
                                terrainpoint.y=viewer.y;//heightmap[i][j]*scale;
                                terrainpoint.z=j*patch_size+(patch_size)/2;
-                               distance[i][j]=findDistancefast(&viewer,&terrainpoint);
+                               distance[i][j]=distsq(&viewer,&terrainpoint);
                        }
                }
        }
@@ -1087,12 +1087,12 @@ void Terrain::drawdecals()
                                }
                        }
                        if(decaltype[i]==shadowdecal||decaltype[i]==shadowdecalpermanent){
-                               distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+                               distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                                if(distancemult>=1)glColor4f(1,1,1,decalopacity[i]);
                                if(distancemult<1)glColor4f(1,1,1,decalopacity[i]*distancemult);
                        }
                        if(decaltype[i]==footprintdecal||decaltype[i]==bodyprintdecal){
-                               distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+                               distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                                if(distancemult>=1){
                                        glColor4f(1,1,1,decalopacity[i]);
                                        if(decalalivetime[i]>3)glColor4f(1,1,1,decalopacity[i]*(5-decalalivetime[i])/2);
@@ -1103,7 +1103,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if((decaltype[i]==blooddecal||decaltype[i]==blooddecalfast||decaltype[i]==blooddecalslow)){
-                               distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
+                               distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
                                if(distancemult>=1){
                                        glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]);
                                        if(decalalivetime[i]<4)glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]*decalalivetime[i]*.25);
index a7d587fca88a1d2958683a620563d373cd89f4ff..5998150e5a1b4796d57e8bc5cde473dc9b2e34f8 100644 (file)
@@ -215,8 +215,8 @@ void Weapon::DoStuff(int i) {
                        for(int j=0;j<numplayers;j++) {
                                footvel=0;
                                footpoint=DoRotation((player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].position+player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].position)/2,0,player[j].yaw,0)*player[j].scale+player[j].coords;
-                               if(owner==-1 && findDistancefastflat(&position,&player[j].coords)<1.5 && 
-                               findDistancefast(&position,&player[j].coords)<4 && player[j].weaponstuck==-1 &&
+                               if(owner==-1 && distsqflat(&position,&player[j].coords)<1.5 && 
+                               distsq(&position,&player[j].coords)<4 && player[j].weaponstuck==-1 &&
                                !player[j].skeleton.free && j!=oldowner) {
                                        if((player[j].aitype!=attacktypecutoff||abs(Random()%6)==0||(player[j].targetanimation!=backhandspringanim&&player[j].targetanimation!=rollanim&&player[j].targetanimation!=flipanim&&Random()%2==0))&&!missed) {
                                                if( (player[j].creature==wolftype       &&      Random()%3!=0 && player[j].weaponactive==-1 && (player[j].isIdle()||player[j].isRun()||player[j].targetanimation==walkanim))||
@@ -331,15 +331,15 @@ void Weapon::DoStuff(int i) {
                                XYZ terrainlight;
                                terrainlight=terrain.getLighting(position.x,position.z);
                                if(environment==snowyenvironment){
-                                       if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                       if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                }
                                else if(environment==grassyenvironment){
-                                       if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                       if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                }
                                else if(environment==desertenvironment){
-                                       if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                       if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                }
 
@@ -654,15 +654,15 @@ void Weapon::DoStuff(int i) {
                                                        XYZ terrainlight;
                                                        terrainlight=terrain.getLighting(position.x,position.z);
                                                        if(environment==snowyenvironment){
-                                                               if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                        }
                                                        else if(environment==grassyenvironment){
-                                                               if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                        }
                                                        else if(environment==desertenvironment){
-                                                               if(findDistancefast(&position,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                        }
                                                }
@@ -705,15 +705,15 @@ void Weapon::DoStuff(int i) {
                                                        XYZ terrainlight;
                                                        terrainlight=terrain.getLighting(tippoint.x,tippoint.z);
                                                        if(environment==snowyenvironment){
-                                                               if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                        }
                                                        else if(environment==grassyenvironment){
-                                                               if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                        }
                                                        else if(environment==desertenvironment){
-                                                               if(findDistancefast(&tippoint,&viewer)<viewdistance*viewdistance/4)
+                                                               if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
                                                                        Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                        }
                                                }
@@ -874,7 +874,7 @@ void Weapon::DoStuff(int i) {
                        flamedelay=.020;
                        flamedelay-=multiplier;
                        normalrot=0;
-                       if(Random()%50==0&&findDistancefast(&position,&viewer)>80) {
+                       if(Random()%50==0&&distsq(&position,&viewer)>80) {
                                XYZ shinepoint;
                                shinepoint=position+(tippoint-position)*(((float)abs(Random()%100))/100);
                                Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
@@ -898,7 +898,7 @@ void Weapon::Draw() {
        static GLfloat M[16];
        
        if((frustum.SphereInFrustum(position.x,position.y,position.z,1)&&
-               findDistancefast(&viewer,&position)<viewdistance*viewdistance))
+               distsq(&viewer,&position)<viewdistance*viewdistance))
        {
                bool draw=false;
                if(owner==-1)
@@ -910,7 +910,7 @@ void Weapon::Draw() {
                                drawhowmany=1;
                } else {
                        if(player[owner].occluded<25)
-                               if((frustum.SphereInFrustum(player[owner].coords.x,player[owner].coords.y+player[owner].scale*3,player[owner].coords.z,player[owner].scale*8)&&findDistancefast(&viewer,&player[owner].coords)<viewdistance*viewdistance)||player[owner].skeleton.free==3)
+                               if((frustum.SphereInFrustum(player[owner].coords.x,player[owner].coords.y+player[owner].scale*3,player[owner].coords.z,player[owner].scale*8)&&distsq(&viewer,&player[owner].coords)<viewdistance*viewdistance)||player[owner].skeleton.free==3)
                                        draw=true;
                        if      (
                                (player[owner].targetanimation==knifeslashstartanim||