X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Ftriggers%2Fsubs.qc;h=bcc7c057c26ef233ea0aa02c87806ea7fef84ccb;hb=daab9330abb8952053b47239d1322cd029b08cd1;hp=f21455dc5f381f88f7ec245ca08280a5f43d9fe1;hpb=125d619e9ab2a307b15b7ee1a2ededed32c7e84d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/triggers/subs.qc b/qcsrc/common/triggers/subs.qc index f21455dc5..bcc7c057c 100644 --- a/qcsrc/common/triggers/subs.qc +++ b/qcsrc/common/triggers/subs.qc @@ -1,20 +1,7 @@ -void SUB_NullThink(void) { } +void SUB_NullThink() { } void() SUB_CalcMoveDone; void() SUB_CalcAngleMoveDone; -//void() SUB_UseTargets; - -/* -================== -SUB_Remove - -Remove self -================== -*/ -void SUB_Remove() -{ - remove (self); -} /* ================== @@ -24,8 +11,8 @@ Applies some friction to self ================== */ .float friction; -void SUB_Friction (void) -{ +void SUB_Friction () +{SELFPARAM(); self.SUB_NEXTTHINK = time; if(self.SUB_FLAGS & FL_ONGROUND) self.SUB_VELOCITY = self.SUB_VELOCITY * (1 - frametime * self.friction); @@ -57,17 +44,17 @@ void SUB_VanishOrRemove (entity ent) } } -void SUB_SetFade_Think (void) -{ - if(self.alpha == 0) - self.alpha = 1; - self.SUB_THINK = SUB_SetFade_Think; - self.SUB_NEXTTHINK = time; - self.alpha -= frametime * self.fade_rate; - if (self.alpha < 0.01) - SUB_VanishOrRemove(self); +void SUB_SetFade_Think () +{SELFPARAM(); + if(this.alpha == 0) + this.alpha = 1; + this.SUB_THINK = SUB_SetFade_Think; + this.SUB_NEXTTHINK = time; + this.alpha -= frametime * this.fade_rate; + if (this.alpha < 0.01) + SUB_VanishOrRemove(this); else - self.SUB_NEXTTHINK = time; + this.SUB_NEXTTHINK = time; } /* @@ -92,8 +79,8 @@ calculate self.SUB_VELOCITY and self.SUB_NEXTTHINK to reach dest from self.SUB_ORIGIN traveling at speed =============== */ -void SUB_CalcMoveDone (void) -{ +void SUB_CalcMoveDone () +{SELFPARAM(); // After moving, set origin to exact final destination SUB_SETORIGIN (self, self.finaldest); @@ -104,9 +91,8 @@ void SUB_CalcMoveDone (void) } .float platmovetype_turn; -void SUB_CalcMove_controller_think (void) -{ - entity oldself; +void SUB_CalcMove_controller_think () +{SELFPARAM(); float traveltime; float phasepos; float nexttick; @@ -135,9 +121,11 @@ void SUB_CalcMove_controller_think (void) destangle_x = -destangle_x; // flip up / down orientation // take the shortest distance for the angles - SUB_ANGLES(self.owner)_x -= 360 * floor((SUB_ANGLES(self.owner)_x - destangle_x) / 360 + 0.5); - SUB_ANGLES(self.owner)_y -= 360 * floor((SUB_ANGLES(self.owner)_y - destangle_y) / 360 + 0.5); - SUB_ANGLES(self.owner)_z -= 360 * floor((SUB_ANGLES(self.owner)_z - destangle_z) / 360 + 0.5); + vector v = SUB_ANGLES(self.owner); + v.x -= 360 * floor((v.x - destangle_x) / 360 + 0.5); + v.y -= 360 * floor((v.y - destangle_y) / 360 + 0.5); + v.z -= 360 * floor((v.z - destangle_z) / 360 + 0.5); + SUB_ANGLES(self.owner) = v; angloc = destangle - SUB_ANGLES(self.owner); angloc = angloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame self.owner.SUB_AVELOCITY = angloc; @@ -154,11 +142,10 @@ void SUB_CalcMove_controller_think (void) else { // derivative: delta + 2 * delta2 (e.g. for angle positioning) - oldself = self; - self.owner.SUB_THINK = self.think1; - self = self.owner; - remove(oldself); - self.SUB_THINK(); + entity own = self.owner; + own.SUB_THINK = self.think1; + remove(self); + WITHSELF(own, own.SUB_THINK()); } } @@ -197,7 +184,7 @@ float TSPEED_END = 2; // TODO average too? void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float tspeed, void() func) -{ +{SELFPARAM(); float traveltime; entity controller; @@ -232,8 +219,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float return; } - controller = spawn(); - controller.classname = "SUB_CalcMove_controller"; + controller = new(SUB_CalcMove_controller); controller.owner = self; controller.platmovetype = self.platmovetype; controller.platmovetype_start = self.platmovetype_start; @@ -242,7 +228,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float controller.finaldest = (tdest + '0 0 0.125'); // where do we want to end? Offset to overshoot a bit. controller.animstate_starttime = time; controller.animstate_endtime = time + traveltime; - controller.think = SUB_CalcMove_controller_think; + setthink(controller, SUB_CalcMove_controller_think); controller.think1 = self.SUB_THINK; // the thinking is now done by the controller @@ -250,13 +236,11 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float self.SUB_NEXTTHINK = self.SUB_LTIME + traveltime; // invoke controller - self = controller; - self.think(); - self = self.owner; + WITHSELF(controller, getthink(controller)()); } void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func) -{ +{SELFPARAM(); vector delta; float traveltime; @@ -306,14 +290,7 @@ void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func) void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void() func) { - entity oldself; - - oldself = self; - self = ent; - - SUB_CalcMove (tdest, tspeedtype, tspeed, func); - - self = oldself; + WITHSELF(ent, SUB_CalcMove(tdest, tspeedtype, tspeed, func)); } /* @@ -326,8 +303,8 @@ self.angles rotating The calling function should make sure self.SUB_THINK is valid =============== */ -void SUB_CalcAngleMoveDone (void) -{ +void SUB_CalcAngleMoveDone () +{SELFPARAM(); // After rotating, set angle to exact final angle self.angles = self.finalangle; self.SUB_AVELOCITY = '0 0 0'; @@ -338,7 +315,7 @@ void SUB_CalcAngleMoveDone (void) // FIXME: I fixed this function only for rotation around the main axes void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void() func) -{ +{SELFPARAM(); vector delta; float traveltime; @@ -381,12 +358,5 @@ void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void() void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void() func) { - entity oldself; - - oldself = self; - self = ent; - - SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func); - - self = oldself; + WITHSELF(ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func)); }