mirror of https://github.com/bjornbytes/lovr.git
phonon: Change falloff to a boolean;
This commit is contained in:
parent
87bbec7018
commit
90ca17c454
|
@ -193,32 +193,17 @@ static int l_lovrSourceSetDirectivity(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetFalloff(lua_State* L) {
|
||||
static int l_lovrSourceIsFalloffEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
float falloff = lovrSourceGetFalloff(source);
|
||||
if (falloff <= 0.f) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
lua_pushnumber(L, falloff);
|
||||
}
|
||||
bool enabled = lovrSourceIsFalloffEnabled(source);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetFalloff(lua_State* L) {
|
||||
static int l_lovrSourceSetFalloffEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
float falloff = 0.f;
|
||||
switch (lua_type(L, 2)) {
|
||||
case LUA_TNONE:
|
||||
case LUA_TNIL:
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
falloff = lua_toboolean(L, 2) ? 1.f : 0.f;
|
||||
break;
|
||||
default:
|
||||
falloff = luax_checkfloat(L, 2);
|
||||
break;
|
||||
}
|
||||
lovrSourceSetFalloff(source, falloff);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetFalloffEnabled(source, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -242,7 +227,7 @@ const luaL_Reg lovrSource[] = {
|
|||
{ "setAbsorption", l_lovrSourceSetAbsorption },
|
||||
{ "getDirectivity", l_lovrSourceGetDirectivity },
|
||||
{ "setDirectivity", l_lovrSourceSetDirectivity },
|
||||
{ "getFalloff", l_lovrSourceGetFalloff },
|
||||
{ "setFalloff", l_lovrSourceSetFalloff },
|
||||
{ "isFalloffEnabled", l_lovrSourceIsFalloffEnabled },
|
||||
{ "setFalloffEnabled", l_lovrSourceSetFalloffEnabled },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ struct Source {
|
|||
float absorption[3];
|
||||
float dipoleWeight;
|
||||
float dipolePower;
|
||||
float falloff;
|
||||
bool falloff;
|
||||
bool playing;
|
||||
bool looping;
|
||||
bool spatial;
|
||||
|
@ -509,11 +509,11 @@ void lovrSourceSetDirectivity(Source* source, float weight, float power) {
|
|||
source->dipolePower = power;
|
||||
}
|
||||
|
||||
float lovrSourceGetFalloff(Source* source) {
|
||||
bool lovrSourceIsFalloffEnabled(Source* source) {
|
||||
return source->falloff;
|
||||
}
|
||||
|
||||
void lovrSourceSetFalloff(Source* source, float falloff) {
|
||||
void lovrSourceSetFalloffEnabled(Source* source, bool falloff) {
|
||||
source->falloff = falloff;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,6 @@ void lovrSourceGetAbsorption(Source* source, float absorption[3]);
|
|||
void lovrSourceSetAbsorption(Source* source, float absorption[3]);
|
||||
void lovrSourceGetDirectivity(Source* source, float* weight, float* power);
|
||||
void lovrSourceSetDirectivity(Source* source, float weight, float power);
|
||||
float lovrSourceGetFalloff(Source* source);
|
||||
void lovrSourceSetFalloff(Source* source, float falloff);
|
||||
bool lovrSourceIsFalloffEnabled(Source* source);
|
||||
void lovrSourceSetFalloffEnabled(Source* source, bool enabled);
|
||||
intptr_t* lovrSourceGetSpatializerMemoField(Source* source);
|
||||
|
|
|
@ -174,7 +174,6 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
float dipoleWeight;
|
||||
float dipolePower;
|
||||
lovrSourceGetDirectivity(source, &dipoleWeight, &dipolePower);
|
||||
float falloff = lovrSourceGetFalloff(source);
|
||||
|
||||
IPLSource iplSource = {
|
||||
.position = (IPLVector3) { position[0], position[1], position[2] },
|
||||
|
@ -183,8 +182,6 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
.right = (IPLVector3) { right[0], right[1], right[2] },
|
||||
.directivity.dipoleWeight = dipoleWeight,
|
||||
.directivity.dipolePower = dipolePower,
|
||||
.distanceAttenuationModel.type = IPL_DISTANCEATTENUATION_INVERSEDISTANCE,
|
||||
.distanceAttenuationModel.minDistance = falloff,
|
||||
.airAbsorptionModel.type = IPL_AIRABSORPTION_EXPONENTIAL,
|
||||
.airAbsorptionModel.coefficients = { absorption[0], absorption[1], absorption[2] }
|
||||
};
|
||||
|
@ -194,7 +191,7 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
IPLDirectSoundPath path = phonon_iplGetDirectSoundPath(state.environment, listenerPosition, listenerForward, listenerUp, iplSource, .5f, 32, occlusionMode, occlusionMethod);
|
||||
|
||||
IPLDirectSoundEffectOptions options = {
|
||||
.applyDistanceAttenuation = falloff > 0.f ? IPL_TRUE : IPL_FALSE,
|
||||
.applyDistanceAttenuation = lovrSourceIsFalloffEnabled(source) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyAirAbsorption = (absorption[0] > 0.f || absorption[1] > 0.f || absorption[2] > 0.f) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyDirectivity = dipoleWeight > 0.f ? IPL_TRUE : IPL_FALSE,
|
||||
.directOcclusionMode = occlusionMode
|
||||
|
|
Loading…
Reference in New Issue