Added Source:setRelativePosition and Source:hasRelativePosition, if enabled the Source's position will always be relative to the listener instead of absolute.

This commit is contained in:
Alex Szpakowski
2013-10-11 02:25:48 -03:00
parent 2710c6c488
commit 7f3cd7f044
7 changed files with 54 additions and 0 deletions
+3
View File
@@ -80,6 +80,9 @@ public:
virtual void setDirection(float *v) = 0;
virtual void getDirection(float *v) const = 0;
virtual void setRelativePosition(bool relative) = 0;
virtual bool hasRelativePosition() const = 0;
virtual void setLooping(bool looping) = 0;
virtual bool isLooping() const = 0;
virtual bool isStatic() const = 0;
+10
View File
@@ -135,6 +135,16 @@ void Source::getDirection(float *) const
{
}
void Source::setRelativePosition(bool relative)
{
relativePosition = relative;
}
bool Source::hasRelativePosition() const
{
return relativePosition;
}
void Source::setLooping(bool looping)
{
this->looping = looping;
+3
View File
@@ -60,6 +60,8 @@ public:
virtual void getVelocity(float *v) const;
virtual void setDirection(float *v);
virtual void getDirection(float *v) const;
virtual void setRelativePosition(bool relative);
virtual bool hasRelativePosition() const;
void setLooping(bool looping);
bool isLooping() const;
bool isStatic() const;
@@ -78,6 +80,7 @@ private:
float pitch;
float volume;
bool relativePosition;
bool looping;
float minVolume;
float maxVolume;
+16
View File
@@ -39,6 +39,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
, valid(false)
, pitch(1.0f)
, volume(1.0f)
, relativePosition(false)
, looping(false)
, paused(false)
, minVolume(0.0f)
@@ -68,6 +69,7 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
, valid(false)
, pitch(1.0f)
, volume(1.0f)
, relativePosition(false)
, looping(false)
, paused(false)
, minVolume(0.0f)
@@ -402,6 +404,19 @@ void Source::getDirection(float *v) const
setFloatv(v, direction);
}
void Source::setRelativePosition(bool relative)
{
if (valid)
alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
relativePosition = relative;
}
bool Source::hasRelativePosition() const
{
return relativePosition;
}
void Source::setLooping(bool looping)
{
if (valid && type == TYPE_STATIC)
@@ -535,6 +550,7 @@ void Source::reset()
alSourcef(source, AL_ROLLOFF_FACTOR, rolloffFactor);
alSourcef(source, AL_MAX_DISTANCE, maxDistance);
alSourcei(source, AL_LOOPING, isStatic() && isLooping() ? AL_TRUE : AL_FALSE);
alSourcei(source, AL_SOURCE_RELATIVE, relativePosition ? AL_TRUE : AL_FALSE);
}
void Source::setFloatv(float *dst, const float *src) const
+3
View File
@@ -78,6 +78,8 @@ public:
virtual void getVelocity(float *v) const;
virtual void setDirection(float *v);
virtual void getDirection(float *v) const;
virtual void setRelativePosition(bool relative);
virtual bool hasRelativePosition() const;
void setLooping(bool looping);
bool isLooping() const;
bool isStatic() const;
@@ -126,6 +128,7 @@ private:
float position[3];
float velocity[3];
float direction[3];
bool relativePosition;
bool looping;
bool paused;
float minVolume;
+17
View File
@@ -190,6 +190,20 @@ int w_Source_getDirection(lua_State *L)
return 3;
}
int w_Source_setRelativePosition(lua_State *L)
{
Source *t = luax_checksource(L, 1);
t->setRelativePosition(luax_toboolean(L, 2));
return 0;
}
int w_Source_hasRelativePosition(lua_State *L)
{
Source *t = luax_checksource(L, 1);
luax_pushboolean(L, t->hasRelativePosition());
return 1;
}
int w_Source_setLooping(lua_State *L)
{
Source *t = luax_checksource(L, 1);
@@ -323,6 +337,9 @@ static const luaL_Reg functions[] =
{ "setDirection", w_Source_setDirection },
{ "getDirection", w_Source_getDirection },
{ "setRelativePosition", w_Source_setRelativePosition },
{ "hasRelativePosition", w_Source_hasRelativePosition },
{ "setLooping", w_Source_setLooping },
{ "isLooping", w_Source_isLooping },
{ "isStopped", w_Source_isStopped },
+2
View File
@@ -47,6 +47,8 @@ int w_Source_setVelocity(lua_State *L);
int w_Source_getVelocity(lua_State *L);
int w_Source_setDirection(lua_State *L);
int w_Source_getDirection(lua_State *L);
int w_Source_setRelativePosition(lua_State *L);
int w_Source_hasRelativePosition(lua_State *L);
int w_Source_setLooping(lua_State *L);
int w_Source_isLooping(lua_State *L);
int w_Source_isStopped(lua_State *L);