diff --git a/src/engine.cpp b/src/engine.cpp index d7dad0c9..ee6accc5 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -276,6 +276,10 @@ EnginePaths* Engine::getPaths() { return paths; } +ResPaths* Engine::getResPaths() { + return resPaths.get(); +} + std::shared_ptr Engine::getScreen() { return screen; } diff --git a/src/engine.h b/src/engine.h index 6e986e85..aec0df72 100644 --- a/src/engine.h +++ b/src/engine.h @@ -106,6 +106,9 @@ public: /** Get engine filesystem paths source */ EnginePaths* getPaths(); + /** Get engine resource paths controller */ + ResPaths* getResPaths(); + /** Get current Content instance */ const Content* getContent() const; diff --git a/src/logic/scripting/lua/libaudio.cpp b/src/logic/scripting/lua/libaudio.cpp index a45627c2..ced50826 100644 --- a/src/logic/scripting/lua/libaudio.cpp +++ b/src/logic/scripting/lua/libaudio.cpp @@ -36,10 +36,98 @@ inline audio::speakerid_t play_sound( } return audio::play( - sound, glm::vec3(x, y, z), false, volume, pitch, false, audio::PRIORITY_NORMAL, channel + sound, + glm::vec3( + static_cast(x), + static_cast(y), + static_cast(z) + ), + false, + volume, + pitch, + false, + audio::PRIORITY_NORMAL, + channel ); } +inline audio::speakerid_t play_stream( + const char* filename, + 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 paths = scripting::engine->getResPaths(); + fs::path file = paths->find(fs::path(filename)); + return audio::play_stream( + file, + glm::vec3( + static_cast(x), + static_cast(y), + static_cast(z) + ), + relative, + volume, + pitch, + loop, + channel + ); +} + +/// @brief audio.play_stream( +/// name: string, +/// x: number, +/// y: number, +/// z: number, +/// volume: number, +/// pitch: number, +/// channel: string = "regular", +/// loop: bool = false) +static int l_audio_play_stream(lua_State* L) { + lua_pushinteger(L, static_cast( + play_stream( + lua_tostring(L, 1), + false, + lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4), + lua_tonumber(L, 5), + lua_tonumber(L, 6), + lua_toboolean(L, 8), + extract_channel_index(L, 7) + ) + )); + return 1; +} + +/// @brief audio.play_stream_2d( +/// name: string, +/// volume: number, +/// pitch: number, +/// channel: string = "regular", +/// loop: bool = false) +static int l_audio_play_stream_2d(lua_State* L) { + lua_pushinteger(L, static_cast( + play_stream( + 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; +} + /// @brief audio.play_sound( /// name: string, /// x: number, @@ -271,6 +359,8 @@ static int l_audio_get_velocity(lua_State* L) { const luaL_Reg audiolib [] = { {"play_sound", lua_wrap_errors}, {"play_sound_2d", lua_wrap_errors}, + {"play_stream", lua_wrap_errors}, + {"play_stream_2d", lua_wrap_errors}, {"stop", lua_wrap_errors}, {"pause", lua_wrap_errors}, {"resume", lua_wrap_errors},