audio.play_sound_2d and loop argument
This commit is contained in:
@@ -8,6 +8,38 @@
|
|||||||
|
|
||||||
inline const char* DEFAULT_CHANNEL = "regular";
|
inline const char* DEFAULT_CHANNEL = "regular";
|
||||||
|
|
||||||
|
inline int extract_channel_index(lua_State* L, int idx) {
|
||||||
|
const char* channel = DEFAULT_CHANNEL;
|
||||||
|
if (!lua_isnoneornil(L, idx)) {
|
||||||
|
channel = lua_tostring(L, idx);
|
||||||
|
}
|
||||||
|
return audio::get_channel_index(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline audio::speakerid_t play_sound(
|
||||||
|
const char* name,
|
||||||
|
bool relative,
|
||||||
|
lua::luanumber x,
|
||||||
|
lua::luanumber y,
|
||||||
|
lua::luanumber z,
|
||||||
|
lua::luanumber volume,
|
||||||
|
lua::luanumber pitch,
|
||||||
|
bool loop,
|
||||||
|
int channel
|
||||||
|
) {
|
||||||
|
if (channel == -1)
|
||||||
|
return 0;
|
||||||
|
auto assets = scripting::engine->getAssets();
|
||||||
|
auto sound = assets->getSound(name);
|
||||||
|
if (sound == nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return audio::play(
|
||||||
|
sound, glm::vec3(x, y, z), false, volume, pitch, false, audio::PRIORITY_NORMAL, channel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief audio.play_sound(
|
/// @brief audio.play_sound(
|
||||||
/// name: string,
|
/// name: string,
|
||||||
/// x: number,
|
/// x: number,
|
||||||
@@ -15,33 +47,43 @@ inline const char* DEFAULT_CHANNEL = "regular";
|
|||||||
/// z: number,
|
/// z: number,
|
||||||
/// volume: number,
|
/// volume: number,
|
||||||
/// pitch: number,
|
/// pitch: number,
|
||||||
/// channel: string = "regular"
|
/// channel: string = "regular",
|
||||||
/// )
|
/// loop: bool = false)
|
||||||
static int l_audio_play_sound(lua_State* L) {
|
static int l_audio_play_sound(lua_State* L) {
|
||||||
const char* name = lua_tostring(L, 1);
|
lua_pushinteger(L, static_cast<lua::luaint>(
|
||||||
lua::luanumber x = lua_tonumber(L, 2);
|
play_sound(
|
||||||
lua::luanumber y = lua_tonumber(L, 3);
|
lua_tostring(L, 1),
|
||||||
lua::luanumber z = lua_tonumber(L, 4);
|
false,
|
||||||
lua::luanumber volume = lua_tonumber(L, 5);
|
lua_tonumber(L, 2),
|
||||||
lua::luanumber pitch = lua_tonumber(L, 6);
|
lua_tonumber(L, 3),
|
||||||
const char* channel = DEFAULT_CHANNEL;
|
lua_tonumber(L, 4),
|
||||||
if (!lua_isnoneornil(L, 7)) {
|
lua_tonumber(L, 5),
|
||||||
channel = lua_tostring(L, 7);
|
lua_tonumber(L, 6),
|
||||||
}
|
lua_toboolean(L, 8),
|
||||||
int channel_index = audio::get_channel_index(channel);
|
extract_channel_index(L, 7)
|
||||||
if (channel_index == -1) {
|
)
|
||||||
return 0;
|
));
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
auto assets = scripting::engine->getAssets();
|
/// @brief audio.play_sound_2d(
|
||||||
auto sound = assets->getSound(name);
|
/// name: string,
|
||||||
if (sound == nullptr) {
|
/// volume: number,
|
||||||
return 0;
|
/// pitch: number,
|
||||||
}
|
/// channel: string = "regular",
|
||||||
audio::speakerid_t id = audio::play(
|
/// loop: bool = false)
|
||||||
sound, glm::vec3(x, y, z), false, volume, pitch, false, audio::PRIORITY_NORMAL, channel_index
|
static int l_audio_play_sound_2d(lua_State* L) {
|
||||||
);
|
lua_pushinteger(L, static_cast<lua::luaint>(
|
||||||
lua_pushinteger(L, static_cast<lua::luaint>(id));
|
play_sound(
|
||||||
|
lua_tostring(L, 1),
|
||||||
|
true,
|
||||||
|
0.0, 0.0, 0.0,
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
lua_tonumber(L, 3),
|
||||||
|
lua_toboolean(L, 5),
|
||||||
|
extract_channel_index(L, 4)
|
||||||
|
)
|
||||||
|
));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +270,7 @@ static int l_audio_get_velocity(lua_State* L) {
|
|||||||
|
|
||||||
const luaL_Reg audiolib [] = {
|
const luaL_Reg audiolib [] = {
|
||||||
{"play_sound", lua_wrap_errors<l_audio_play_sound>},
|
{"play_sound", lua_wrap_errors<l_audio_play_sound>},
|
||||||
|
{"play_sound_2d", lua_wrap_errors<l_audio_play_sound_2d>},
|
||||||
{"stop", lua_wrap_errors<l_audio_stop>},
|
{"stop", lua_wrap_errors<l_audio_stop>},
|
||||||
{"pause", lua_wrap_errors<l_audio_pause>},
|
{"pause", lua_wrap_errors<l_audio_pause>},
|
||||||
{"resume", lua_wrap_errors<l_audio_resume>},
|
{"resume", lua_wrap_errors<l_audio_resume>},
|
||||||
|
|||||||
Reference in New Issue
Block a user