diff --git a/include/modules/audio/Audio.hpp b/include/modules/audio/Audio.hpp index fabce477..6edffaa9 100644 --- a/include/modules/audio/Audio.hpp +++ b/include/modules/audio/Audio.hpp @@ -26,6 +26,8 @@ namespace love bool play(Source* source); + void stop(); + void stop(Source* source); void pause(Source* source); @@ -34,6 +36,14 @@ namespace love float getVolume() const; + static bool play(const std::vector& sources); + + static void stop(const std::vector& sources); + + static void pause(const std::vector& sources); + + std::vector pause(); + private: Pool* pool; diff --git a/include/modules/audio/wrap_Audio.hpp b/include/modules/audio/wrap_Audio.hpp index 3e45618c..4966c67d 100644 --- a/include/modules/audio/wrap_Audio.hpp +++ b/include/modules/audio/wrap_Audio.hpp @@ -13,5 +13,9 @@ namespace Wrap_Audio int stop(lua_State* L); + int setVolume(lua_State* L); + + int getVolume(lua_State* L); + int open(lua_State* L); } // namespace Wrap_Audio diff --git a/platform/hac/include/driver/display/Framebuffer.hpp b/platform/hac/include/driver/display/Framebuffer.hpp index 6fb4e9cd..1f1b888b 100644 --- a/platform/hac/include/driver/display/Framebuffer.hpp +++ b/platform/hac/include/driver/display/Framebuffer.hpp @@ -31,6 +31,5 @@ namespace love dk::Image image; CMemPool::Handle memory; - dk::ImageLayout layout; }; } // namespace love diff --git a/platform/hac/source/common/screen.cpp b/platform/hac/source/common/screen.cpp index f7979a5f..66ad3efe 100644 --- a/platform/hac/source/common/screen.cpp +++ b/platform/hac/source/common/screen.cpp @@ -7,12 +7,12 @@ namespace love // clang-format off inline constinit ScreenInfo HANDHELD_MODE[0x01] = { - { 0, 0, "default", 1280, 720 }, + { 0, 0, "default", 1280, 720 } }; inline constinit ScreenInfo DOCKED_MODE[0x01] = { - { 0, 0, "default", 1920, 1080 }, + { 0, 0, "default", 1920, 1080 } }; // clang-format on diff --git a/platform/hac/source/driver/display/Framebuffer.cpp b/platform/hac/source/driver/display/Framebuffer.cpp index 97ba9928..fc471541 100644 --- a/platform/hac/source/driver/display/Framebuffer.cpp +++ b/platform/hac/source/driver/display/Framebuffer.cpp @@ -13,26 +13,19 @@ namespace love const auto flags = depth ? BASE_FLAGS : MAIN_FLAGS; const auto format = depth ? DkImageFormat_Z24S8 : DkImageFormat_RGBA8_Unorm; + dk::ImageLayout layout {}; dk::ImageLayoutMaker { device } .setFlags(flags) .setFormat(format) .setDimensions(info.width, info.height) - .initialize(this->layout); + .initialize(layout); - const auto layoutSize = this->layout.getSize(); - const auto alignment = this->layout.getAlignment(); - - this->memory = images.allocate(layoutSize, alignment); - - const auto& memoryBlock = this->memory.getMemBlock(); - auto memoryOffset = this->memory.getOffset(); - - this->image.initialize(this->layout, memoryBlock, memoryOffset); + this->memory = images.allocate(layout.getSize(), layout.getAlignment()); + this->image.initialize(layout, this->memory.getMemBlock(), this->memory.getOffset()); } void Framebuffer::destroy() { - if (this->memory) - this->memory.destroy(); + this->memory.destroy(); } } // namespace love diff --git a/source/modules/audio/Audio.cpp b/source/modules/audio/Audio.cpp index 7ab9af2f..c5a2130c 100644 --- a/source/modules/audio/Audio.cpp +++ b/source/modules/audio/Audio.cpp @@ -71,16 +71,41 @@ namespace love return source->play(); } + bool Audio::play(const std::vector& sources) + { + return Source::play(sources); + } + + void Audio::stop() + { + Source::stop(this->pool); + } + void Audio::stop(Source* source) { source->stop(); } + void Audio::stop(const std::vector& sources) + { + Source::stop(sources); + } + void Audio::pause(Source* source) { source->pause(); } + void Audio::pause(const std::vector& sources) + { + Source::pause(sources); + } + + std::vector Audio::pause() + { + return Source::pause(this->pool); + } + void Audio::setVolume(float volume) { DigitalSound::getInstance().setMasterVolume(volume); diff --git a/source/modules/audio/wrap_Audio.cpp b/source/modules/audio/wrap_Audio.cpp index 2614d525..88ee8468 100644 --- a/source/modules/audio/wrap_Audio.cpp +++ b/source/modules/audio/wrap_Audio.cpp @@ -62,29 +62,63 @@ int Wrap_Audio::newSource(lua_State* L) return luax_typeerror(L, 1, "Decoder or SoundData"); } +static std::vector readSourceList(lua_State* L, int index) +{ + if (index < 0) + index += lua_gettop(L) + 1; + + int count = luax_objlen(L, index); + std::vector sources(count); + + for (int i = 0; i < count; i++) + { + lua_rawgeti(L, index, i + 1); + sources[i] = luax_checksource(L, -1); + lua_pop(L, 1); + } + + return sources; +} + +static std::vector readSourceVararg(lua_State* L, int index) +{ + const auto top = lua_gettop(L); + + if (index < 0) + index += top + 1; + + int count = top - index + 1; + std::vector sources(count); + + for (int i = 0; i <= top; index++, i++) + sources[i] = luax_checksource(L, -1); + + return sources; +} + int Wrap_Audio::play(lua_State* L) { if (lua_istable(L, 1)) - return 0; + luax_pushboolean(L, instance()->play(readSourceList(L, 1))); else if (lua_gettop(L) > 1) - return 0; + luax_pushboolean(L, instance()->play(readSourceVararg(L, 1))); else { auto* source = luax_checksource(L, 1); luax_pushboolean(L, source->play()); - - return 1; } + + return 1; } int Wrap_Audio::stop(lua_State* L) { if (lua_isnone(L, 1)) - return 0; + instance()->stop(); if (lua_istable(L, 1)) - return 0; + instance()->stop(readSourceList(L, 1)); else if (lua_gettop(L) > 1) - return 0; + instance()->stop(readSourceVararg(L, 1)); else { auto* source = luax_checksource(L, 1); @@ -96,10 +130,23 @@ int Wrap_Audio::stop(lua_State* L) int Wrap_Audio::pause(lua_State* L) { - if (lua_istable(L, 1)) - return 0; + if (lua_isnone(L, 1)) + { + auto sources = instance()->pause(); + lua_createtable(L, (int)sources.size(), 0); + + for (int index = 0; index < (int)sources.size(); index++) + { + luax_pushtype(L, sources[index]); + lua_rawseti(L, -2, index + 1); + } + + return 1; + } + else if (lua_istable(L, 1)) + instance()->pause(readSourceList(L, 1)); else if (lua_gettop(L) > 1) - return 0; + instance()->pause(readSourceVararg(L, 1)); else { auto* source = luax_checksource(L, 1); @@ -109,13 +156,30 @@ int Wrap_Audio::pause(lua_State* L) return 0; } +int Wrap_Audio::setVolume(lua_State* L) +{ + float volume = luaL_checknumber(L, 1); + instance()->setVolume(volume); + + return 0; +} + +int Wrap_Audio::getVolume(lua_State* L) +{ + lua_pushnumber(L, instance()->getVolume()); + + return 1; +} + // clang-format off static constexpr luaL_Reg functions[]= { { "newSource", Wrap_Audio::newSource }, { "play", Wrap_Audio::play }, { "stop", Wrap_Audio::stop }, - { "pause", Wrap_Audio::pause } + { "pause", Wrap_Audio::pause }, + { "setVolume", Wrap_Audio::setVolume }, + { "getVolume", Wrap_Audio::getVolume } }; static constexpr lua_CFunction types[]=