Merge branch 'dev' into debugging-client

This commit is contained in:
MihailRis
2025-11-11 21:38:11 +03:00
58 changed files with 2287 additions and 1018 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
#include "graphics/core/Texture.hpp"
#include "graphics/core/Atlas.hpp"
#include "util/Buffer.hpp"
#include "../lua_custom_types.hpp"
#include "../usertypes/lua_type_canvas.hpp"
using namespace scripting;
+91 -2
View File
@@ -68,6 +68,26 @@ inline audio::speakerid_t play_stream(
if (channel == -1) {
return 0;
}
if (!scripting::engine->isHeadless()) {
auto assets = scripting::engine->getAssets();
auto stream = assets->getShared<audio::PCMStream>(filename);
if (stream) {
return audio::play(
audio::open_stream(std::move(stream), true),
glm::vec3(
static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(z)
),
relative,
volume,
pitch,
loop,
channel
);
}
}
io::path file;
if (std::strchr(filename, ':')) {
file = std::string(filename);
@@ -360,16 +380,80 @@ static int l_audio_get_velocity(lua::State* L) {
return 0;
}
// @brief audio.count_speakers() -> integer
/// @brief audio.count_speakers() -> integer
static int l_audio_count_speakers(lua::State* L) {
return lua::pushinteger(L, audio::count_speakers());
}
// @brief audio.count_streams() -> integer
/// @brief audio.count_streams() -> integer
static int l_audio_count_streams(lua::State* L) {
return lua::pushinteger(L, audio::count_streams());
}
/// @brief audio.input.fetch(size) -> Bytearray
static int l_audio_fetch_input(lua::State* L) {
auto device = audio::get_input_device();
if (device == nullptr) {
return 0;
}
size_t size = lua::touinteger(L, 1);
const size_t MAX_BUFFER_SIZE = audio::MAX_INPUT_SAMPLES * 4;
if (size == 0) {
size = MAX_BUFFER_SIZE;
}
size = std::min<size_t>(size, MAX_BUFFER_SIZE);
ubyte buffer[MAX_BUFFER_SIZE];
size = device->read(reinterpret_cast<char*>(buffer), size);
std::vector<ubyte> bytes(buffer, buffer + size);
return lua::create_bytearray(L, std::move(bytes));
}
static int l_audio_get_input_devices_names(lua::State* L) {
auto device_names = audio::get_input_devices_names();
lua::createtable(L, device_names.size(), 0);
int index = 1;
for (const auto& name : device_names) {
lua::pushstring(L, name.c_str());
lua::rawseti(L, index++);
}
return 1;
}
static int l_audio_get_output_devices_names(lua::State* L) {
auto device_names = audio::get_output_devices_names();
lua::createtable(L, device_names.size(), 0);
int index = 1;
for (const auto& name : device_names) {
lua::pushstring(L, name.c_str());
lua::rawseti(L, index++);
}
return 1;
}
static int l_audio_set_input_device(lua::State* L) {
auto device_name = lua::tostring(L, 1);
audio::set_input_device(device_name);
return 0;
}
static int l_audio_get_input_info(lua::State* L) {
auto device = audio::get_input_device();
if (device == nullptr) {
return 0;
}
lua::createtable(L, 0, 4);
lua::pushlstring(L, device->getDeviceSpecifier());
lua::setfield(L, "device_specifier");
lua::pushinteger(L, device->getChannels());
lua::setfield(L, "channels");
lua::pushinteger(L, device->getSampleRate());
lua::setfield(L, "sample_rate");
lua::pushinteger(L, device->getBitsPerSample());
lua::setfield(L, "bits_per_sample");
return 1;
}
const luaL_Reg audiolib[] = {
{"play_sound", lua::wrap<l_audio_play_sound>},
{"play_sound_2d", lua::wrap<l_audio_play_sound_2d>},
@@ -395,5 +479,10 @@ const luaL_Reg audiolib[] = {
{"get_velocity", lua::wrap<l_audio_get_velocity>},
{"count_speakers", lua::wrap<l_audio_count_speakers>},
{"count_streams", lua::wrap<l_audio_count_streams>},
{"__fetch_input", lua::wrap<l_audio_fetch_input>},
{"get_input_devices_names", lua::wrap<l_audio_get_input_devices_names>},
{"get_output_devices_names", lua::wrap<l_audio_get_output_devices_names>},
{"set_input_device", lua::wrap<l_audio_set_input_device>},
{"get_input_info", lua::wrap<l_audio_get_input_info>},
{nullptr, nullptr}
};
@@ -1,7 +1,6 @@
#include "coders/binary_json.hpp"
#include "api_lua.hpp"
#include "util/Buffer.hpp"
#include "../lua_custom_types.hpp"
static int l_tobytes(lua::State* L) {
auto value = lua::tovalue(L, 1);
@@ -10,7 +10,7 @@
#include "content/ContentControl.hpp"
#include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "../lua_custom_types.hpp"
#include "../usertypes/lua_type_voxelfragment.hpp"
using namespace scripting;
+1
View File
@@ -24,6 +24,7 @@
#include "items/Inventories.hpp"
#include "util/stringutil.hpp"
#include "world/Level.hpp"
#include "../usertypes/lua_type_canvas.hpp"
using namespace gui;
using namespace scripting;
-1
View File
@@ -3,7 +3,6 @@
#include <vector>
#include <cwctype>
#include "../lua_custom_types.hpp"
#include "util/stringutil.hpp"
static int l_tobytes(lua::State* L) {