Commits

Alex Szpakowski committed a96de92

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

Comments (0)

Files changed (8)

src/modules/audio/Source.cpp

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

src/modules/audio/Source.h

 
 	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;
 	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);
 	static bool getConstant(Unit in, const char  *&out);
 
 protected:
+
 	Type type;
 
 private:

src/modules/audio/null/Source.cpp

 	return looping;
 }
 
-bool Source::isStatic() const
-{
-	return (type == TYPE_STATIC);
-}
-
 void Source::setMinVolume(float volume)
 {
 	this->minVolume = volume;

src/modules/audio/null/Source.h

 	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);

src/modules/audio/openal/Source.cpp

 	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);
 	return decoded;
 }
 
-bool Source::isStatic() const
-{
-	return (type == TYPE_STATIC);
-}
-
 void Source::setMinVolume(float volume)
 {
 	if (valid)

src/modules/audio/openal/Source.h

 	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);

src/modules/audio/wrap_Source.cpp

 	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);
 	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 },
 	{ "isStopped", w_Source_isStopped },
 	{ "isPaused", w_Source_isPaused },
 	{ "isPlaying", w_Source_isPlaying },
-	{ "isStatic", w_Source_isStatic },
 
 	{ "setVolumeLimits", w_Source_setVolumeLimits },
 	{ "getVolumeLimits", w_Source_getVolumeLimits },
 	{ "getRolloff", w_Source_getRolloff},
 
 	{ "getChannels", w_Source_getChannels },
+	{ "getType", w_Source_getType },
 
 	{ 0, 0 }
 };

src/modules/audio/wrap_Source.h

 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);
 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