]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Rotor.cpp
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / YASim / Rotor.cpp
index 8c756c75bf413f8ca50fea4bb4a6ec15ba42c8f4..c222358142e18d6095a70a571ad1e4eb5d88192f 100644 (file)
@@ -16,9 +16,8 @@
 #include <iostream>
 #include <iomanip>
 
-#ifdef TEST_DEBUG
+
 #include <stdio.h>
-#endif
 #include <string.h>
 #include <iostream>
 #include <sstream>
@@ -274,7 +273,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f)
     if (4>numRotorparts()) return 0; //compile first!
     if (j==0)
     {
-        sprintf(text,"/rotors/%s/cone-deg", _name);
+        snprintf(text, 256, "/rotors/%s/cone-deg", _name);
         *f=(_balance1>-1)?( ((Rotorpart*)getRotorpart(0))->getrealAlpha()
             +((Rotorpart*)getRotorpart(1*(_number_of_parts>>2)))->getrealAlpha()
             +((Rotorpart*)getRotorpart(2*(_number_of_parts>>2)))->getrealAlpha()
@@ -284,7 +283,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f)
     else
         if (j==1)
         {
-            sprintf(text,"/rotors/%s/roll-deg", _name);
+            snprintf(text, 256, "/rotors/%s/roll-deg", _name);
             _roll = ( ((Rotorpart*)getRotorpart(0))->getrealAlpha()
                 -((Rotorpart*)getRotorpart(2*(_number_of_parts>>2)))->getrealAlpha()
                 )/2*(_ccw?-1:1);
@@ -293,7 +292,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f)
         else
             if (j==2)
             {
-                sprintf(text,"/rotors/%s/yaw-deg", _name);
+                snprintf(text, 256, "/rotors/%s/yaw-deg", _name);
                 _yaw=( ((Rotorpart*)getRotorpart(1*(_number_of_parts>>2)))->getrealAlpha()
                     -((Rotorpart*)getRotorpart(3*(_number_of_parts>>2)))->getrealAlpha()
                     )/2;
@@ -302,38 +301,38 @@ int Rotor::getValueforFGSet(int j,char *text,float *f)
             else
                 if (j==3)
                 {
-                    sprintf(text,"/rotors/%s/rpm", _name);
+                    snprintf(text, 256, "/rotors/%s/rpm", _name);
                     *f=(_balance1>-1)?_omega/2/pi*60:0;
                 }
                 else
                     if (j==4)
                     {
-                        sprintf(text,"/rotors/%s/tilt/pitch-deg",_name);
+                        snprintf(text, 256, "/rotors/%s/tilt/pitch-deg",_name);
                         *f=_tilt_pitch*180/pi;
                     }
                     else if (j==5)
                     {
-                        sprintf(text,"/rotors/%s/tilt/roll-deg",_name);
+                        snprintf(text, 256, "/rotors/%s/tilt/roll-deg",_name);
                         *f=_tilt_roll*180/pi;
                     }
                     else if (j==6)
                     {
-                        sprintf(text,"/rotors/%s/tilt/yaw-deg",_name);
+                        snprintf(text, 256, "/rotors/%s/tilt/yaw-deg",_name);
                         *f=_tilt_yaw*180/pi;
                     }
                     else if (j==7)
                     {
-                        sprintf(text,"/rotors/%s/balance", _name);
+                        snprintf(text, 256, "/rotors/%s/balance", _name);
                         *f=_balance1;
                     }
                     else if (j==8)
                     {
-                        sprintf(text,"/rotors/%s/stall",_name);
+                        snprintf(text, 256, "/rotors/%s/stall",_name);
                         *f=getOverallStall();
                     }
                     else if (j==9)
                     {
-                        sprintf(text,"/rotors/%s/torque",_name);
+                        snprintf(text, 256, "/rotors/%s/torque",_name);
                         *f=-_torque;;
                     }
                     else
@@ -344,7 +343,7 @@ int Rotor::getValueforFGSet(int j,char *text,float *f)
                             return 0;
                         }
                         int w=j%3;
-                        sprintf(text,"/rotors/%s/blade[%i]/%s",
+                        snprintf(text, 256, "/rotors/%s/blade[%i]/%s",
                             _name,b,
                             w==0?"position-deg":(w==1?"flap-deg":"incidence-deg"));
                         *f=((Rotorpart*)getRotorpart(0))->getPhi()*180/pi
@@ -1160,7 +1159,7 @@ void Rotor::updateDirectionsAndPositions(float *rot)
 void Rotor::compile()
 {
     // Have we already been compiled?
-    if(_rotorparts.size() != 0) return;
+    if(! _rotorparts.empty()) return;
 
     //rotor is divided into _number_of_parts parts
     //each part is calcualted at _number_of_segments points
@@ -1307,7 +1306,7 @@ void Rotor::compile()
         &(torque[1]),&(lift[1])); //pitch b
     rps[0]->calculateAlpha(v_wind,rho_null,0,0,0,
         &(torque[3]),&(lift[3])); //pitch 0
-    SG_LOG(SG_GENERAL, SG_INFO,
+    SG_LOG(SG_FLIGHT, SG_INFO,
         "Rotor: coefficients for airfoil:" << endl << setprecision(6)
         << " drag0: " << _dragcoef0*_number_of_parts/_number_of_blades/_c2
         << " drag1: " << _dragcoef1*_number_of_parts/_number_of_blades/_c2
@@ -1499,7 +1498,7 @@ void Rotorgear::initRotorIteration(float *lrot,float dt)
 {
     int i;
     float omegarel;
-    if (!_rotors.size()) return;
+    if (_rotors.empty()) return;
     Rotor* r0 = (Rotor*)_rotors.get(0);
     omegarel= r0->getOmegaRelNeu();
     for(i=0; i<_rotors.size(); i++) {
@@ -1515,7 +1514,7 @@ void Rotorgear::calcForces(float* torqueOut)
     // check,<if the engine can handle the torque of the rotors. 
     // If not reduce the torque to the fueselage and change rotational 
     // speed of the rotors instead
-    if (_rotors.size())
+    if (! _rotors.empty())
     {
         float omegarel,omegan;
         Rotor* r0 = (Rotor*)_rotors.get(0);
@@ -1543,6 +1542,8 @@ void Rotorgear::calcForces(float* torqueOut)
         }
         total_torque*=-1;
         _ddt_omegarel=0;
+
+#if 0
         float rel_torque_engine=1;
         if (total_torque<=0)
             rel_torque_engine=0;
@@ -1551,10 +1552,11 @@ void Rotorgear::calcForces(float* torqueOut)
                 rel_torque_engine=1/max_torque_of_engine*total_torque;
             else
                 rel_torque_engine=0;
+#endif
 
         //add the rotor brake and the gear fritcion
         float dt=0.1f;
-        if (r0->_rotorparts.size()) dt=((Rotorpart*)r0->_rotorparts.get(0))->getDt();
+        if (! r0->_rotorparts.empty()) dt=((Rotorpart*)r0->_rotorparts.get(0))->getDt();
 
         float rotor_brake_torque;
         rotor_brake_torque=_rotorbrake*_max_power_rotor_brake+_rotorgear_friction;