]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_subs.qc
properly compute velocity to go into final position
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
index 1d1f0bb9bd0f1bfee26d37846ad17085026bbdb4..180dee305a320d98771e93824db928aca539e6e1 100644 (file)
@@ -177,10 +177,52 @@ void SUB_CalcMoveDone (void)
                self.think1 ();
 }
 
+void SUB_CalcMove_controller_think (void)
+{
+       entity oldself;
+       float traveltime;
+       float phasepos;
+       float nexttick;
+       vector delta;
+       vector veloc;
+       vector nextpos;
+       if(time < self.animstate_endtime) {
+               delta = self.destvec;
+               nexttick = time + 0.1;
+
+               if(nexttick < self.animstate_endtime) {
+                       traveltime = self.animstate_endtime - self.animstate_starttime;
+                       phasepos = (nexttick - self.animstate_starttime) / traveltime; // range: [0, 1]
+                       phasepos = 3.14159265 + (phasepos * 3.14159265); // range: [pi, 2pi]
+                       phasepos = cos(phasepos); // cos [pi, 2pi] is in [-1, 1]
+                       phasepos = phasepos + 1; // correct range to [0, 2]
+                       phasepos = phasepos / 2; // correct range to [0, 1]
+                       nextpos = self.origin + (delta * phasepos);
+
+                       veloc = nextpos - self.owner.origin;
+                       veloc = veloc * 10; // so it arrives in 0.1 seconds
+
+               } else {
+                       veloc = self.finaldest - self.owner.origin;
+                       veloc = veloc * 10; // so it arrives in 0.1 seconds
+                       self.nextthink = self.animstate_endtime;
+               }
+               self.owner.velocity = veloc;
+               self.nextthink = nexttick;
+       } else {
+               oldself = self;
+               self.owner.think = self.think1;
+               self = self.owner;
+               remove(oldself);
+               self.think();
+       }
+}
+
 void SUB_CalcMove (vector tdest, float tspeed, void() func)
 {
        vector  delta;
        float   traveltime;
+       entity controller;
 
        if (!tspeed)
                objerror ("No speed is defined!");
@@ -206,9 +248,34 @@ void SUB_CalcMove (vector tdest, float tspeed, void() func)
                return;
        }
 
-       self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+       // the controller only thinks every 0.1 seconds, so very short
+       // animations should just use the traditional movement
+       if (traveltime < 0.3)
+       {
+               self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+               self.nextthink = self.ltime + traveltime;
+               return;
+       }
 
+       controller = spawn();
+       controller.classname = "SUB_CalcMove_controller";
+       controller.owner = self;
+       controller.origin = self.origin; // starting point
+       controller.finaldest = tdest; // where do we want to end?
+       controller.destvec = delta;
+       controller.animstate_starttime = time;
+       controller.animstate_endtime = time + traveltime;
+       controller.think = SUB_CalcMove_controller_think;
+       controller.think1 = self.think;
+
+       // the thinking is now done by the controller
+       self.think = SUB_Null;
        self.nextthink = self.ltime + traveltime;
+       
+       // invoke controller
+       self = controller;
+       self.think();
+       self = self.owner;
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
@@ -605,7 +672,6 @@ float angc (float a1, float a2)
 .float loddistance1;
 .float loddistance2;
 
-vector NearestPointOnBox(entity box, vector org);
 float LOD_customize()
 {
        float d;
@@ -615,7 +681,7 @@ float LOD_customize()
                d = cvar("loddebug");
                if(d == 1)
                        self.modelindex = self.lodmodelindex0;
-               else if(d == 2)
+               else if(d == 2 || !self.lodmodelindex2)
                        self.modelindex = self.lodmodelindex1;
                else // if(d == 3)
                        self.modelindex = self.lodmodelindex2;
@@ -695,7 +761,8 @@ void LODmodel_attach()
        }
 
        if(self.lodmodelindex1)
-               SetCustomizer(self, LOD_customize, LOD_uncustomize);
+               if not(self.SendEntity)
+                       SetCustomizer(self, LOD_customize, LOD_uncustomize);
 }
 
 void SetBrushEntityModel()