### OpenAL Exponential Falloff

Scripts and code that enhance the gameplay functionality of the engine.

#### OpenAL Exponential Falloff

marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
This resource will add the exponential falloff to torque3ds sound distance attenuation instead of the linear falloff that it uses as stock... ALOT OF CODE CHANGES INCOMING BACK UP YOUR SOURCE!!! These changes were tested on stock Torque3d 3.10.1 release.

Our first change of many:
in sfxCommon.h around line 152 you should see enum SFXDistanceModel

SFXDistanceModelExponent,
then at line 189 after break; ad
case SFXDistanceModelExponent:
distance = getMax(distance, minDistance);
distance = getMin(distance, maxDistance);

gain = pow((distance / minDistance), (-rolloffFactor));
break;
Then in sfxDSDevice.cpp at line 203 you will see SFXDevice::setDistanceModel

in the switch below break at case SFXDistanceModelLogarithmic:

 case SFXDistanceModelExponent:
Con::errorf("SFXDSDevice::setDistanceModel - 'exponential' distance attenuation not supported by DirectSound");
break;
I'm not sure whether directsound has an exponential attenuation feature but just in case it doesnt i thought it best to sort it out with an error here.

Next in sfxALDevice.cpp find SFXALDevice::setDistanceModel under the case SFXDistanceModelLogarithmic break;

case SFXDistanceModelExponent:
mOpenAL.alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
if (mUserRolloffFactor != mRolloffFactor)
_setRolloffFactor(mUserRolloffFactor);
break;
You could just copy and paste the logarithmic case here and change the values to be exponent but that would just be lazy...........

Next in sfxSystem.cpp

Find around line 94
{ SFXDistanceModelLogarithmic, "Logarithmic",
"Volume attenuates logarithmically starting from the reference distance and halving every reference distance step from there on. "
"Attenuation stops at max distance but volume won't reach zero." },

 { SFXDistanceModelExponent, "Exponential",
"Attenuation stops at max distance but volume won't reach zero." },