Game Development Community

seemingly wrong code in shapeBase.cpp

by Dan Keller · in Torque Game Engine Advanced · 05/14/2011 (11:12 am) · 0 replies

In shapeBase.cpp around line 1000 there is this code
F32 store = mEnergy;
      mEnergy += mRechargeRate;
      if (mEnergy > mDataBlock->maxEnergy)
         mEnergy = mDataBlock->maxEnergy;
      else
         if (mEnergy < 0)
            mEnergy = 0;

      // Virtual setEnergyLevel is used here by some derived classes to
      // decide whether they really want to set the energy mask bit.
      if (mEnergy != store)
         setEnergyLevel(mEnergy);

setEnergyLevel is virtual, which makes sense because derived objects might want to do their own energy management. But shapeBase modifies mEnergy and passes it as an argument to setEnergyLevel, which doesn't make sense considering setEnergyLevel sets mEnergy. So derived classes really can't manage their energy correctly if mEnergy is already set before the function is called.

It would make more sense if store and mEnergy were switched here, so derived classes could veto the energy change if necessary.