Browse Source

Added Source:getType, removed Source:isStatic (resolves issue #776)

--HG--
branch : minor
Alex Szpakowski 11 years ago
parent
commit
b1edf5e7bf

+ 5 - 0
src/modules/audio/Source.cpp

@@ -34,6 +34,11 @@ Source::~Source()
 {
 }
 
+Source::Type Source::getType() const
+{
+	return type;
+}
+
 bool Source::getConstant(const char *in, Type &out)
 {
 	return types.find(in, out);

+ 2 - 1
src/modules/audio/Source.h

@@ -88,7 +88,6 @@ public:
 
 	virtual void setLooping(bool looping) = 0;
 	virtual bool isLooping() const = 0;
-	virtual bool isStatic() const = 0;
 
 	virtual void setMinVolume(float volume) = 0;
 	virtual float getMinVolume() const = 0;
@@ -103,6 +102,7 @@ public:
 	virtual float getMaxDistance() const = 0;
 
 	virtual int getChannels() const = 0;
+	virtual Type getType() const;
 
 	static bool getConstant(const char *in, Type &out);
 	static bool getConstant(Type in, const char  *&out);
@@ -110,6 +110,7 @@ public:
 	static bool getConstant(Unit in, const char  *&out);
 
 protected:
+
 	Type type;
 
 private:

+ 0 - 5
src/modules/audio/null/Source.cpp

@@ -169,11 +169,6 @@ bool Source::isLooping() const
 	return looping;
 }
 
-bool Source::isStatic() const
-{
-	return (type == TYPE_STATIC);
-}
-
 void Source::setMinVolume(float volume)
 {
 	this->minVolume = volume;

+ 0 - 1
src/modules/audio/null/Source.h

@@ -66,7 +66,6 @@ public:
 	virtual bool isRelative() const;
 	void setLooping(bool looping);
 	bool isLooping() const;
-	bool isStatic() const;
 	virtual void setMinVolume(float volume);
 	virtual float getMinVolume() const;
 	virtual void setMaxVolume(float volume);

+ 1 - 6
src/modules/audio/openal/Source.cpp

@@ -631,7 +631,7 @@ void Source::reset()
 	alSourcef(source, AL_REFERENCE_DISTANCE, referenceDistance);
 	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_LOOPING, (type == TYPE_STATIC) && isLooping() ? AL_TRUE : AL_FALSE);
 	alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
 	alSourcei(source, AL_CONE_INNER_ANGLE, cone.innerAngle);
 	alSourcei(source, AL_CONE_OUTER_ANGLE, cone.outerAngle);
@@ -693,11 +693,6 @@ int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
 	return decoded;
 }
 
-bool Source::isStatic() const
-{
-	return (type == TYPE_STATIC);
-}
-
 void Source::setMinVolume(float volume)
 {
 	if (valid)

+ 0 - 1
src/modules/audio/openal/Source.h

@@ -105,7 +105,6 @@ public:
 	virtual bool isRelative() const;
 	void setLooping(bool looping);
 	bool isLooping() const;
-	bool isStatic() const;
 	virtual void setMinVolume(float volume);
 	virtual float getMinVolume() const;
 	virtual void setMaxVolume(float volume);

+ 14 - 8
src/modules/audio/wrap_Source.cpp

@@ -275,13 +275,6 @@ int w_Source_isPlaying(lua_State *L)
 	return 1;
 }
 
-int w_Source_isStatic(lua_State *L)
-{
-	Source *t = luax_checksource(L, 1);
-	luax_pushboolean(L, t->isStatic());
-	return 1;
-}
-
 int w_Source_setVolumeLimits(lua_State *L)
 {
 	Source *t = luax_checksource(L, 1);
@@ -346,6 +339,19 @@ int w_Source_getChannels(lua_State *L)
 	return 1;
 }
 
+int w_Source_getType(lua_State *L)
+{
+	Source *t = luax_checksource(L, 1);
+	Source::Type type = t->getType();
+	const char *str = nullptr;
+
+	if (!Source::getConstant(type, str))
+		return luaL_error(L, "Unknown Source type.");
+
+	lua_pushstring(L, str);
+	return 1;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "clone", w_Source_clone },
@@ -379,7 +385,6 @@ static const luaL_Reg functions[] =
 	{ "isStopped", w_Source_isStopped },
 	{ "isPaused", w_Source_isPaused },
 	{ "isPlaying", w_Source_isPlaying },
-	{ "isStatic", w_Source_isStatic },
 
 	{ "setVolumeLimits", w_Source_setVolumeLimits },
 	{ "getVolumeLimits", w_Source_getVolumeLimits },
@@ -389,6 +394,7 @@ static const luaL_Reg functions[] =
 	{ "getRolloff", w_Source_getRolloff},
 
 	{ "getChannels", w_Source_getChannels },
+	{ "getType", w_Source_getType },
 
 	{ 0, 0 }
 };

+ 1 - 1
src/modules/audio/wrap_Source.h

@@ -57,7 +57,6 @@ int w_Source_isLooping(lua_State *L);
 int w_Source_isStopped(lua_State *L);
 int w_Source_isPaused(lua_State *L);
 int w_Source_isPlaying(lua_State *L);
-int w_Source_isStatic(lua_State *L);
 int w_Source_setVolumeLimits(lua_State *L);
 int w_Source_getVolumeLimits(lua_State *L);
 int w_Source_setAttenuationDistances(lua_State *L);
@@ -65,6 +64,7 @@ int w_Source_getAttenuationDistances(lua_State *L);
 int w_Source_setRolloff(lua_State *L);
 int w_Source_getRolloff(lua_State *L);
 int w_Source_getChannels(lua_State *L);
+int w_Source_getType(lua_State *L);
 extern "C" int luaopen_source(lua_State *L);
 
 } // audio