clang-format & cleanup

This commit is contained in:
Pieter-Jan Briers
2026-09-12 20:42:59 +02:00
parent 03390b807e
commit ab6db7d4e6
28 changed files with 324 additions and 393 deletions
+1 -5
View File
@@ -54,10 +54,6 @@ struct Z2AudioCamera {
/* 0x00 */ JGeometry::TPosition3f32 mViewMatrix;
/* 0x30 */ JGeometry::TVec3<f32> mVel;
/* 0x3C */ JGeometry::TVec3<f32> mPos;
/**
*
*/
/* 0x48 */ JGeometry::TVec3<f32> mLastPos;
/* 0x54 */ f32 mFovySin;
/* 0x58 */ f32 mVolCenterZ;
@@ -281,7 +277,7 @@ struct Z2Audience : public JAIAudience, public JASGlobalInstance<Z2Audience> {
}
Z2Audience3DSetting* getSetting() { return &mSetting; }
const Z2AudioCamera* getAudioCamera(int camID) const { return &mAudioCamera[camID]; }
const Z2AudioCamera* getAudioCamera(int camID) const { return &mAudioCamera[camID]; }
void setUsingOffMicVol(bool value) { mUsingOffMicVol = value; }
+3 -2
View File
@@ -8,11 +8,12 @@ namespace dusk::helpers {
* @param ptr Address to read from.
* @return The copied value.
*/
template <typename T> requires std::is_trivially_copyable_v<T>
template <typename T>
requires std::is_trivially_copyable_v<T>
[[nodiscard]] constexpr T read_unaligned(u8 const* ptr) {
T copy;
memcpy(&copy, ptr, sizeof(T));
return copy;
}
}
} // namespace dusk::helpers
+35 -35
View File
@@ -1,48 +1,48 @@
#pragma once
#include <limits>
#include <utility>
#include <span>
#include <utility>
/**
* Helper functions for performing casts.
*/
namespace dusk::helpers::cast {
/**
* Implementation details of dusk::helpers::cast.
*/
namespace _impl {
[[noreturn]] void overrun_high();
[[noreturn]] void overrun_low();
}
/**
* Implementation details of dusk::helpers::cast.
*/
namespace _impl {
[[noreturn]] void overrun_high();
[[noreturn]] void overrun_low();
} // namespace _impl
template <typename T>
concept IntCastable = std::is_integral_v<T> && std::is_trivially_copyable_v<T>;
template <typename T>
concept IntCastable = std::is_integral_v<T> && std::is_trivially_copyable_v<T>;
/**
* Helper type that allows easily casting between integer types,
* that safely aborts if an overflow were to occur.
* Usage:
* @code
* size_t foobar = 20;
* int real = bounded_cast(foobar);
* @endcode
*/
template <IntCastable Source>
struct bounded_cast {
Source src;
/**
* Helper type that allows easily casting between integer types,
* that safely aborts if an overflow were to occur.
* Usage:
* @code
* size_t foobar = 20;
* int real = bounded_cast(foobar);
* @endcode
*/
template <IntCastable Source>
struct bounded_cast {
Source src;
template <IntCastable Target>
[[nodiscard]] constexpr operator Target() const {
if (std::cmp_greater(src, std::numeric_limits<Target>::max())) [[unlikely]] {
_impl::overrun_high();
}
if (std::cmp_less(src, std::numeric_limits<Target>::min())) [[unlikely]] {
_impl::overrun_low();
}
return static_cast<Target>(src);
template <IntCastable Target>
[[nodiscard]] constexpr operator Target() const {
if (std::cmp_greater(src, std::numeric_limits<Target>::max())) [[unlikely]] {
_impl::overrun_high();
}
};
}
if (std::cmp_less(src, std::numeric_limits<Target>::min())) [[unlikely]] {
_impl::overrun_low();
}
return static_cast<Target>(src);
}
};
} // namespace dusk::helpers::cast
+5 -18
View File
@@ -12,28 +12,15 @@ MOD_EXPORT ModResult mod_initialize(ModError*) {
svc_log->info(mod_ctx, "template_mod initialized");
AudioWaveHandle handle;
svc_audio_res->replace_wave(
mod_ctx,
AUDIO_WAVE_BANK_SOUND_EFFECTS,
4238,
"res/go.opus",
nullptr,
&handle);
mod_ctx, AUDIO_WAVE_BANK_SOUND_EFFECTS, 4238, "res/go.opus", nullptr, &handle);
svc_audio_res->replace_wave(
mod_ctx,
AUDIO_WAVE_BANK_SOUND_EFFECTS,
4237,
"res/go.opus",
nullptr,
&handle);
mod_ctx, AUDIO_WAVE_BANK_SOUND_EFFECTS, 4237, "res/go.opus", nullptr, &handle);
constexpr AudioSoundTableEffectInfo effect(128, 1, 1.5);
svc_audio_res->replace_sound_table_effect(
mod_ctx,
SE_CATEGORY_CHARA_SE,
0, // MIDNA_APPEAR
&effect,
nullptr);
svc_audio_res->replace_sound_table_effect(mod_ctx, SE_CATEGORY_CHARA_SE,
0, // MIDNA_APPEAR
&effect, nullptr);
return MOD_OK;
}
+2 -4
View File
@@ -14,9 +14,7 @@ luabridge::Stack<const luau_runtime::Vm&>::get(lua_State* L, int) {
namespace luau_runtime {
BridgeScriptHandle::BridgeScriptHandle(uint64_t const handle) noexcept : handle(handle) {
}
BridgeScriptHandle::BridgeScriptHandle(uint64_t const handle) noexcept : handle(handle) {}
BridgeScriptHandle::~BridgeScriptHandle() = default;
@@ -37,4 +35,4 @@ void BridgeScriptHandle::unregister(lua_State* state, Vm& vm) {
handle = 0;
}
}
} // namespace luau_runtime
+25 -19
View File
@@ -1,25 +1,29 @@
#pragma once
// clang-format off
#include "lua.h"
#include "lualib.h"
#include "LuaBridge/LuaBridge.h"
// clang-format on
#include "runtime.hpp"
/**
* Defines (i.e. implements) a LuaBridge3 Stack<T> converter for an enum that is passed by string name.
* Defines (i.e. implements) a LuaBridge3 Stack<T> converter for an enum that is passed by string
* name.
*
* @param type The type name of the enum to convert.
* @param names The constant field containing the string name <-> enum value mapping.
* @see DECLARE_STRING_ENUM
*/
#define DEFINE_STRING_ENUM(type, names) \
Result Stack<type>::push(lua_State* L, type value) { \
return Stack<std::string_view>::push(L, ::luau_runtime::enum_value_to_str(L, value, names)); \
} \
\
TypeResult<type> Stack<type>::get(lua_State* L, int index) { \
const char* str = lua_tolstring(L, index, nullptr); \
return ::luau_runtime::enum_str_to_value(L, str, names); \
#define DEFINE_STRING_ENUM(type, names) \
Result Stack<type>::push(lua_State* L, type value) { \
return Stack<std::string_view>::push( \
L, ::luau_runtime::enum_value_to_str(L, value, names)); \
} \
\
TypeResult<type> Stack<type>::get(lua_State* L, int index) { \
const char* str = lua_tolstring(L, index, nullptr); \
return ::luau_runtime::enum_str_to_value(L, str, names); \
}
/**
@@ -28,11 +32,11 @@
* @param type The type name of the enum to convert.
* @see DEFINE_STRING_ENUM
*/
#define DECLARE_STRING_ENUM(type) \
template<> \
struct Stack<type> { \
[[nodiscard]] static Result push(lua_State* L, type value); \
[[nodiscard]] static TypeResult<type> get(lua_State* L, int index); \
#define DECLARE_STRING_ENUM(type) \
template <> \
struct Stack<type> { \
[[nodiscard]] static Result push(lua_State* L, type value); \
[[nodiscard]] static TypeResult<type> get(lua_State* L, int index); \
}
/**
@@ -41,16 +45,18 @@
*/
template <>
struct luabridge::Stack<luau_runtime::Vm&> {
[[nodiscard]] static TypeResult<std::reference_wrapper<luau_runtime::Vm>> get(lua_State* L, int);
[[nodiscard]] static TypeResult<std::reference_wrapper<luau_runtime::Vm>> get(
lua_State* L, int);
};
/**
* Template specialization to allow luau_runtime::Vm const& to be directly acquired
* from a LuaBridge3 function.
*/
template<>
template <>
struct luabridge::Stack<luau_runtime::Vm const&> {
[[nodiscard]] static TypeResult<std::reference_wrapper<luau_runtime::Vm const>> get(lua_State* L, int);
[[nodiscard]] static TypeResult<std::reference_wrapper<luau_runtime::Vm const>> get(
lua_State* L, int);
};
namespace luau_runtime {
@@ -72,7 +78,7 @@ public:
void unregister(lua_State* state, Vm& vm);
};
}
} // namespace luau_runtime
/**
* Convert a @ref luaBridge::LuaRef to an *optional* value.
@@ -100,7 +106,7 @@ std::optional<T> opt(TLuaRef const& value) {
* @param value Lua ref to convert to the desired type.
* @param default_value The default value if the lua item is nil.
*/
template<typename T, typename TLuaRef>
template <typename T, typename TLuaRef>
T opt_or(TLuaRef const& value, T const& default_value) {
return opt<T>(value).value_or(default_value);
}
+1 -1
View File
@@ -115,4 +115,4 @@ int ref_required_function(lua_State* state, int table, const char* field) {
return ref;
}
}
} // namespace luau_runtime
+5 -6
View File
@@ -31,7 +31,7 @@ uint32_t get_uint32(lua_State* state, int table, const char* field);
/**
* Concept that demands things be an enum. C++ is such a cool language.
*/
template<typename T>
template <typename T>
concept Enum = std::is_enum_v<T>;
/**
@@ -44,8 +44,7 @@ struct EnumName {
T value;
std::string_view name;
constexpr EnumName(T value, std::string_view name) : value(value), name(name) {
}
constexpr EnumName(T value, std::string_view name) : value(value), name(name) {}
};
/**
@@ -59,7 +58,7 @@ struct EnumName {
* @param options The predefined set of possible enum names.
*/
template <Enum T, size_t N>
T enum_str_to_value(lua_State* state, char const* str, EnumName<T> const(& options)[N]) {
T enum_str_to_value(lua_State* state, char const* str, EnumName<T> const (&options)[N]) {
std::string_view strv(str);
for (size_t i = 0; i < N; ++i) {
if (options[i].name == strv) {
@@ -81,7 +80,7 @@ T enum_str_to_value(lua_State* state, char const* str, EnumName<T> const(& optio
* @param options The predefined set of possible enum names.
*/
template <Enum T, size_t N>
std::string_view enum_value_to_str(lua_State* state, T value, EnumName<T> const(& options)[N]) {
std::string_view enum_value_to_str(lua_State* state, T value, EnumName<T> const (&options)[N]) {
for (auto [nameValue, name] : options) {
if (nameValue == value) {
return name;
@@ -91,4 +90,4 @@ std::string_view enum_value_to_str(lua_State* state, T value, EnumName<T> const(
luaL_errorL(state, "Attempted to return invalid enum to Lua!");
}
}
} // namespace luau_runtime
+1 -1
View File
@@ -327,7 +327,7 @@ ModResult runtime_activate(ModContext*, ModContext* subject, ModError* outError)
lua_pushlightuserdata(vm->state, vm.get());
lua_rawsetp(vm->state, LUA_REGISTRYINDEX, &vm_registry_index);
lua_callbacks(vm->state)->userdata = vm.get();
#if NDEBUG // Annoying for debuggers
#if NDEBUG // Annoying for debuggers
lua_callbacks(vm->state)->interrupt = [](lua_State* state, int gc) {
auto* current = static_cast<Vm*>(lua_callbacks(state)->userdata);
if (gc < 0 && current != nullptr && current->deadlineActive &&
@@ -5,8 +5,8 @@
#include "mods/svc/audio_res.h"
#include "wsys.hpp"
#include "bst.hpp"
#include "wsys.hpp"
namespace luau_runtime::services {
namespace {
@@ -31,7 +31,7 @@ int open_audio_res(lua_State* state) {
.addFunction("replace_wave", replace_wave)
.addFunction("add_wave", add_wave)
.beginClass<LuaAudioWaveHandle>("AudioWaveHandle")
.addFunction("unregister", &LuaAudioWaveHandle::unregister)
.addFunction("unregister", &LuaAudioWaveHandle::unregister)
.endClass()
// BST
.addFunction("default_effect_info", default_effect_info)
@@ -42,13 +42,11 @@ int open_audio_res(lua_State* state) {
.addFunction("replace_sound_table_stream", replace_sound_table_stream)
.addFunction("add_sound_table_stream", add_sound_table_stream)
.beginClass<LuaSoundTableHandle>("AudioSoundTableHandle")
.addFunction("unregister", &LuaSoundTableHandle::unregister)
.addFunction("unregister", &LuaSoundTableHandle::unregister)
.endClass();
lua_setreadonly(state, -1, true);
return 1;
}
}
} // namespace luau_runtime::services
@@ -2,7 +2,8 @@
namespace luau_runtime::services::audio_res {
LuaSoundTableHandle::LuaSoundTableHandle(AudioSoundTableHandle handle) : BridgeScriptHandle(handle) { }
LuaSoundTableHandle::LuaSoundTableHandle(AudioSoundTableHandle handle)
: BridgeScriptHandle(handle) {}
void LuaSoundTableHandle::unregister_impl(lua_State*, Vm& vm) {
svc_audio_res->remove_sound_table(vm.subject, handle);
@@ -21,19 +22,16 @@ LuaSoundTableHandle replace_sound_table_effect(SoundEffectCategory category_id,
AudioSoundTableHandle handle;
check_result(
state,
svc_audio_res->replace_sound_table_effect(vm.subject, category_id, effect_id, effect_info, &handle),
check_result(state,
svc_audio_res->replace_sound_table_effect(
vm.subject, category_id, effect_id, effect_info, &handle),
"audio_res.replace_sound_table_effect");
return LuaSoundTableHandle(handle);
}
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_effect(
SoundEffectCategory category_id,
std::optional<AudioSoundTableEffectInfo> info,
lua_State* state,
Vm& vm) {
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_effect(SoundEffectCategory category_id,
std::optional<AudioSoundTableEffectInfo> info, lua_State* state, Vm& vm) {
AudioSoundTableEffectInfo const* effect_info = nullptr;
if (info.has_value()) {
effect_info = &*info;
@@ -42,12 +40,12 @@ std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_effect(
uint16_t out_effect_id;
AudioSoundTableHandle handle;
check_result(
state,
svc_audio_res->add_sound_table_effect(vm.subject, category_id, effect_info, &handle, &out_effect_id),
check_result(state,
svc_audio_res->add_sound_table_effect(
vm.subject, category_id, effect_info, &handle, &out_effect_id),
"audio_res.add_sound_table_effect");
return { out_effect_id, LuaSoundTableHandle(handle) };
return {out_effect_id, LuaSoundTableHandle(handle)};
}
AudioSoundTableStreamInfo const& default_stream_info() {
@@ -63,19 +61,16 @@ LuaSoundTableHandle replace_sound_table_stream(uint16_t stream_id, char const* f
AudioSoundTableHandle handle;
check_result(
state,
svc_audio_res->replace_sound_table_stream(vm.subject, stream_id, file_path, stream_info, &handle),
check_result(state,
svc_audio_res->replace_sound_table_stream(
vm.subject, stream_id, file_path, stream_info, &handle),
"audio_res.replace_sound_table_stream");
return LuaSoundTableHandle(handle);
}
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_stream(
char const* file_path,
std::optional<AudioSoundTableStreamInfo> info,
lua_State* state,
Vm& vm) {
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_stream(char const* file_path,
std::optional<AudioSoundTableStreamInfo> info, lua_State* state, Vm& vm) {
AudioSoundTableStreamInfo const* stream_info = nullptr;
if (info.has_value()) {
stream_info = &*info;
@@ -84,15 +79,14 @@ std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_stream(
uint16_t out_stream_id;
AudioSoundTableHandle handle;
check_result(
state,
svc_audio_res->add_sound_table_stream(vm.subject, file_path, stream_info, &handle, &out_stream_id),
check_result(state,
svc_audio_res->add_sound_table_stream(
vm.subject, file_path, stream_info, &handle, &out_stream_id),
"audio_res.add_sound_table_stream");
return { out_stream_id, LuaSoundTableHandle(handle) };
return {out_stream_id, LuaSoundTableHandle(handle)};
}
} // namespace luau_runtime::services::audio_res
namespace luabridge {
@@ -130,10 +124,9 @@ DEFINE_STRING_ENUM(StreamPan, kStreamPanNames);
TypeResult<AudioSoundTableEffectInfo> Stack<AudioSoundTableEffectInfo>::get(
lua_State* L, int index) {
auto const ref = LuaRef::fromStack(L, index);
return AudioSoundTableEffectInfo {
return AudioSoundTableEffectInfo{
.priority = ref["priority"],
.volume = ref["volume"],
.pitch = ref["pitch"],
@@ -153,7 +146,6 @@ TypeResult<AudioSoundTableEffectInfo> Stack<AudioSoundTableEffectInfo>::get(
Result Stack<AudioSoundTableEffectInfo>::push(
lua_State* L, const AudioSoundTableEffectInfo& value) {
LuaRef const ref = newTable(L);
ref["priority"] = value.priority;
@@ -178,12 +170,12 @@ Result Stack<AudioSoundTableEffectInfo>::push(
TypeResult<AudioSoundTableStreamInfo> Stack<AudioSoundTableStreamInfo>::get(
lua_State* L, int index) {
auto const ref = LuaRef::fromStack(L, index);
std::array<std::optional<StreamPan>, STREAM_MAX_CHILDREN> const pan_parameters = ref["pan_parameters"];
std::array<std::optional<StreamPan>, STREAM_MAX_CHILDREN> const pan_parameters =
ref["pan_parameters"];
auto info = AudioSoundTableStreamInfo {
auto info = AudioSoundTableStreamInfo{
.priority = ref["priority"],
.volume = ref["volume"],
.stop_on_scene_change = ref["stop_on_scene_change"],
@@ -198,7 +190,6 @@ TypeResult<AudioSoundTableStreamInfo> Stack<AudioSoundTableStreamInfo>::get(
Result Stack<AudioSoundTableStreamInfo>::push(
lua_State* L, const AudioSoundTableStreamInfo& value) {
LuaRef const ref = newTable(L);
ref["priority"] = value.priority;
@@ -1,59 +1,46 @@
#pragma once
#include "mods/svc/audio_res.h"
#include "../../lua_helpers.hpp"
#include "../../lua_bridge_helpers.hpp"
#include "../../lua_helpers.hpp"
#include "mods/svc/audio_res.h"
namespace luau_runtime::services::audio_res {
class LuaSoundTableHandle final : public BridgeScriptHandle {
protected:
void unregister_impl(lua_State*, Vm& vm) override;
public:
explicit LuaSoundTableHandle(AudioSoundTableHandle handle);
};
AudioSoundTableEffectInfo const& default_effect_info();
LuaSoundTableHandle replace_sound_table_effect(
SoundEffectCategory category_id,
uint16_t effect_id,
std::optional<AudioSoundTableEffectInfo> info,
lua_State* state,
Vm& vm);
LuaSoundTableHandle replace_sound_table_effect(SoundEffectCategory category_id, uint16_t effect_id,
std::optional<AudioSoundTableEffectInfo> info, lua_State* state, Vm& vm);
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_effect(
SoundEffectCategory category_id,
std::optional<AudioSoundTableEffectInfo> info,
lua_State* state,
Vm& vm);
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_effect(SoundEffectCategory category_id,
std::optional<AudioSoundTableEffectInfo> info, lua_State* state, Vm& vm);
AudioSoundTableStreamInfo const& default_stream_info();
LuaSoundTableHandle replace_sound_table_stream(
uint16_t stream_id,
char const* file_path,
std::optional<AudioSoundTableStreamInfo> info,
lua_State* state,
Vm& vm);
LuaSoundTableHandle replace_sound_table_stream(uint16_t stream_id, char const* file_path,
std::optional<AudioSoundTableStreamInfo> info, lua_State* state, Vm& vm);
std::tuple<uint16_t, LuaSoundTableHandle> add_sound_table_stream(
char const* file_path,
std::optional<AudioSoundTableStreamInfo> info,
lua_State* state,
Vm& vm);
char const* file_path, std::optional<AudioSoundTableStreamInfo> info, lua_State* state, Vm& vm);
}
} // namespace luau_runtime::services::audio_res
namespace luabridge {
template<>
template <>
struct Stack<AudioSoundTableEffectInfo> {
[[nodiscard]] static Result push(lua_State* L, const AudioSoundTableEffectInfo& value);
[[nodiscard]] static TypeResult<AudioSoundTableEffectInfo> get(lua_State* L, int index);
};
template<>
template <>
struct Stack<AudioSoundTableStreamInfo> {
[[nodiscard]] static Result push(lua_State* L, const AudioSoundTableStreamInfo& value);
[[nodiscard]] static TypeResult<AudioSoundTableStreamInfo> get(lua_State* L, int index);
@@ -62,4 +49,4 @@ struct Stack<AudioSoundTableStreamInfo> {
DECLARE_STRING_ENUM(SoundEffectCategory);
DECLARE_STRING_ENUM(StreamPan);
}
} // namespace luabridge
@@ -2,7 +2,7 @@
namespace luau_runtime::services::audio_res {
LuaAudioWaveHandle::LuaAudioWaveHandle(AudioWaveHandle handle) : BridgeScriptHandle(handle) { }
LuaAudioWaveHandle::LuaAudioWaveHandle(AudioWaveHandle handle) : BridgeScriptHandle(handle) {}
void LuaAudioWaveHandle::unregister_impl(lua_State*, Vm& vm) {
svc_audio_res->remove_wave(vm.subject, handle);
@@ -12,7 +12,8 @@ AudioWaveInfo const& default_wave_info() {
return *svc_audio_res->default_wave_info;
}
LuaAudioWaveHandle replace_wave(AudioWaveBank bank, uint16_t wave_id, char const* file, std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm) {
LuaAudioWaveHandle replace_wave(AudioWaveBank bank, uint16_t wave_id, char const* file,
std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm) {
AudioWaveInfo const* wave_info = nullptr;
if (info.has_value()) {
wave_info = &info->info;
@@ -20,15 +21,15 @@ LuaAudioWaveHandle replace_wave(AudioWaveBank bank, uint16_t wave_id, char const
AudioWaveHandle handle;
check_result(
state,
check_result(state,
svc_audio_res->replace_wave(vm.subject, bank, wave_id, file, wave_info, &handle),
"audio_res.replace_wave");
return LuaAudioWaveHandle(handle);
}
std::tuple<uint16_t, LuaAudioWaveHandle> add_wave(AudioWaveBank bank, char const* file, std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm) {
std::tuple<uint16_t, LuaAudioWaveHandle> add_wave(AudioWaveBank bank, char const* file,
std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm) {
AudioWaveInfo const* wave_info = nullptr;
if (info.has_value()) {
wave_info = &info->info;
@@ -37,8 +38,7 @@ std::tuple<uint16_t, LuaAudioWaveHandle> add_wave(AudioWaveBank bank, char const
AudioWaveHandle handle;
uint16_t out_wave_id;
check_result(
state,
check_result(state,
svc_audio_res->add_wave(vm.subject, bank, file, wave_info, &handle, &out_wave_id),
"audio_res.replace_wave");
@@ -80,7 +80,7 @@ Result Stack<AudioRawWave>::push(lua_State* L, const AudioRawWave& value) {
TypeResult<AudioRawWave> Stack<AudioRawWave>::get(lua_State* L, int index) {
auto const ref = LuaRef::fromStack(L, index);
return AudioRawWave {
return AudioRawWave{
.format = ref["format"],
.sample_rate = ref["sample_rate"],
.sample_value_last = opt_or<int16_t>(ref["sample_value_last"], 0),
@@ -97,11 +97,12 @@ Result Stack<OwnedWaveInfo>::push(lua_State* L, const OwnedWaveInfo& value) {
TypeResult<OwnedWaveInfo> Stack<OwnedWaveInfo>::get(lua_State* L, int index) {
auto const ref = LuaRef::fromStack(L, index);
AudioWaveInfo info {
AudioWaveInfo info{
.base_key = opt_or<uint8_t>(ref["base_key"], AUDIO_RES_DEFAULT_KEY),
.loop = opt_or<bool>(ref["loop"], false),
.loop_start_sample = opt_or<uint32_t>(ref["loop_start_sample"], 0),
.loop_end_sample = opt_or<uint32_t>(ref["loop_end_sample"], std::numeric_limits<uint32_t>::max()),
.loop_end_sample =
opt_or<uint32_t>(ref["loop_end_sample"], std::numeric_limits<uint32_t>::max()),
};
std::unique_ptr<AudioRawWave> raw;
@@ -110,7 +111,7 @@ TypeResult<OwnedWaveInfo> Stack<OwnedWaveInfo>::get(lua_State* L, int index) {
info.raw_wave = raw.get();
}
return OwnedWaveInfo { info, std::move(raw) };
return OwnedWaveInfo{info, std::move(raw)};
}
namespace {
@@ -118,21 +119,20 @@ namespace {
using namespace std::string_view_literals;
constexpr luau_runtime::EnumName<AudioWaveFormat> kWaveFormatNames[] = {
{ AUDIO_WAVE_FORMAT_ADPCM4, "adpcm4"sv },
{ AUDIO_WAVE_FORMAT_ADPCM2, "adpcm2"sv },
{ AUDIO_WAVE_FORMAT_PCM8, "pcm8"sv },
{ AUDIO_WAVE_FORMAT_PCM16, "pcm16"sv },
{AUDIO_WAVE_FORMAT_ADPCM4, "adpcm4"sv},
{AUDIO_WAVE_FORMAT_ADPCM2, "adpcm2"sv},
{AUDIO_WAVE_FORMAT_PCM8, "pcm8"sv},
{AUDIO_WAVE_FORMAT_PCM16, "pcm16"sv},
};
constexpr luau_runtime::EnumName<AudioWaveBank> kWaveBankNames[] = {
{ AUDIO_WAVE_BANK_SOUND_EFFECTS, "sound_effects"sv } ,
{ AUDIO_WAVE_BANK_MUSIC_SAMPLES, "music_samples"sv } ,
{AUDIO_WAVE_BANK_SOUND_EFFECTS, "sound_effects"sv},
{AUDIO_WAVE_BANK_MUSIC_SAMPLES, "music_samples"sv},
};
}
} // namespace
DEFINE_STRING_ENUM(AudioWaveFormat, kWaveFormatNames);
DEFINE_STRING_ENUM(AudioWaveBank, kWaveBankNames);
} // namespace luabridge
@@ -1,11 +1,11 @@
#pragma once
#include "LuaBridge/LuaBridge.h"
#include "lua.h"
#include "lualib.h"
#include "LuaBridge/LuaBridge.h"
#include "../../runtime.hpp"
#include "../../lua_helpers.hpp"
#include "../../runtime.hpp"
#include "mods/svc/audio_res.h"
#include <memory>
@@ -20,36 +20,41 @@ struct OwnedWaveInfo {
class LuaAudioWaveHandle final : public BridgeScriptHandle {
protected:
void unregister_impl(lua_State*, Vm& vm) override;
public:
explicit LuaAudioWaveHandle(AudioWaveHandle handle);
};
AudioWaveInfo const& default_wave_info();
LuaAudioWaveHandle replace_wave(AudioWaveBank bank, uint16_t wave_id, char const* file, std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm);
std::tuple<uint16_t, LuaAudioWaveHandle> add_wave(AudioWaveBank bank, char const* file, std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm);
LuaAudioWaveHandle replace_wave(AudioWaveBank bank, uint16_t wave_id, char const* file,
std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm);
std::tuple<uint16_t, LuaAudioWaveHandle> add_wave(AudioWaveBank bank, char const* file,
std::optional<OwnedWaveInfo> info, lua_State* state, Vm& vm);
}
} // namespace luau_runtime::services::audio_res
namespace luabridge {
template<>
template <>
struct Stack<AudioWaveInfo> {
[[nodiscard]] static Result push(lua_State* L, const AudioWaveInfo& value);
};
template<>
template <>
struct Stack<AudioRawWave> {
[[nodiscard]] static Result push(lua_State* L, const AudioRawWave& value);
[[nodiscard]] static TypeResult<AudioRawWave> get(lua_State* L, int index);
};
template<>
template <>
struct Stack<luau_runtime::services::audio_res::OwnedWaveInfo> {
[[nodiscard]] static Result push(lua_State* L, const luau_runtime::services::audio_res::OwnedWaveInfo& value);
[[nodiscard]] static TypeResult<luau_runtime::services::audio_res::OwnedWaveInfo> get(lua_State* L, int index);
[[nodiscard]] static Result push(
lua_State* L, const luau_runtime::services::audio_res::OwnedWaveInfo& value);
[[nodiscard]] static TypeResult<luau_runtime::services::audio_res::OwnedWaveInfo> get(
lua_State* L, int index);
};
DECLARE_STRING_ENUM(AudioWaveFormat);
DECLARE_STRING_ENUM(AudioWaveBank);
}
} // namespace luabridge
+1 -1
View File
@@ -338,4 +338,4 @@ int open_texture(lua_State* state) {
return 1;
}
} // namespace luau_runtime
} // namespace luau_runtime::services
+1 -1
View File
@@ -243,4 +243,4 @@ int open_config(lua_State* state) {
return 1;
}
} // namespace luau_runtime
} // namespace luau_runtime::services
+11 -11
View File
@@ -7,20 +7,20 @@ namespace {
using namespace std::string_view_literals;
constexpr std::pair<std::string_view, lua_CFunction> kModules[] = {
{ "dusklight.log"sv, open_log },
{ "dusklight.host"sv, open_host },
{ "dusklight.resource"sv, open_resource },
{ "dusklight.overlay"sv, open_overlay },
{ "dusklight.texture"sv, open_texture },
{ "dusklight.config"sv, open_config },
{ "dusklight.ui"sv, open_ui },
{ "dusklight.audio_res"sv, open_audio_res },
{"dusklight.log"sv, open_log},
{"dusklight.host"sv, open_host},
{"dusklight.resource"sv, open_resource},
{"dusklight.overlay"sv, open_overlay},
{"dusklight.texture"sv, open_texture},
{"dusklight.config"sv, open_config},
{"dusklight.ui"sv, open_ui},
{"dusklight.audio_res"sv, open_audio_res},
};
}
} // namespace
ModuleOpenFn module_factory(std::string_view name) {
for (auto [ modName, ptr ] : kModules) {
for (auto [modName, ptr] : kModules) {
if (name == modName) {
return ptr;
}
@@ -29,4 +29,4 @@ ModuleOpenFn module_factory(std::string_view name) {
return nullptr;
}
}
} // namespace luau_runtime::services
+1 -1
View File
@@ -18,4 +18,4 @@ int open_ui(lua_State* state);
ModuleOpenFn module_factory(std::string_view name);
}
} // namespace luau_runtime::services
+15 -15
View File
@@ -292,14 +292,14 @@ std::vector<UiListItem> list_items(lua_State* state, int table, std::vector<std:
}
constexpr EnumName<UiControlKind> kControlKindNames[] = {
{ UI_CONTROL_BUTTON, "button"sv },
{ UI_CONTROL_TOGGLE, "toggle"sv },
{ UI_CONTROL_NUMBER, "number"sv },
{ UI_CONTROL_STRING, "string"sv },
{ UI_CONTROL_SELECT, "select"sv },
{ UI_CONTROL_COLOR, "color"sv },
{ UI_CONTROL_GROUP, "group"sv },
{ UI_CONTROL_FILE_PICKER, "file_picker"sv },
{UI_CONTROL_BUTTON, "button"sv},
{UI_CONTROL_TOGGLE, "toggle"sv},
{UI_CONTROL_NUMBER, "number"sv},
{UI_CONTROL_STRING, "string"sv},
{UI_CONTROL_SELECT, "select"sv},
{UI_CONTROL_COLOR, "color"sv},
{UI_CONTROL_GROUP, "group"sv},
{UI_CONTROL_FILE_PICKER, "file_picker"sv},
};
UiControlKind control_kind(lua_State* state, const std::string& kind) {
@@ -307,12 +307,12 @@ UiControlKind control_kind(lua_State* state, const std::string& kind) {
}
constexpr EnumName<UiStyleScope> kStyleScopeNames[] = {
{ UI_SCOPE_PRELAUNCH, "prelaunch"sv },
{ UI_SCOPE_WINDOW, "window"sv },
{ UI_SCOPE_MENU_BAR, "menu_bar"sv },
{ UI_SCOPE_OVERLAY, "overlay"sv },
{ UI_SCOPE_TOUCH_CONTROLS, "touch_controls"sv },
{ UI_SCOPE_GRAPHICS_TUNER, "graphics_tuner"sv },
{UI_SCOPE_PRELAUNCH, "prelaunch"sv},
{UI_SCOPE_WINDOW, "window"sv},
{UI_SCOPE_MENU_BAR, "menu_bar"sv},
{UI_SCOPE_OVERLAY, "overlay"sv},
{UI_SCOPE_TOUCH_CONTROLS, "touch_controls"sv},
{UI_SCOPE_GRAPHICS_TUNER, "graphics_tuner"sv},
};
UiStyleScope style_scope(lua_State* state, const std::string& scope) {
@@ -851,4 +851,4 @@ int open_ui(lua_State* state) {
return 1;
}
} // namespace luau_runtime
} // namespace luau_runtime::services
+4 -7
View File
@@ -42,18 +42,15 @@ void sync_audio_replacements() {
bst::sync_audio_replacements();
}
}
} // namespace
} // namespace audio_res
constinit const ServiceModule g_audioResModule{
.id = AUDIO_RES_SERVICE_ID,
constinit const ServiceModule g_audioResModule{.id = AUDIO_RES_SERVICE_ID,
.majorVersion = AUDIO_RES_SERVICE_MAJOR,
.minorVersion = AUDIO_RES_SERVICE_MINOR,
.service = &audio_res::s_audioResService,
.modDetached = audio_res::mod_detached,
.lifecycleApplied = audio_res::sync_audio_replacements,
.frameEnd = audio_res::frame_end
};
};
.frameEnd = audio_res::frame_end};
}; // namespace dusk::mods::svc

Some files were not shown because too many files have changed in this diff Show More