Separate SoundData and SoundDataStrema constructors

they take the same arguments so we can't overload
the function parameterically.
also I find it pretty confusing that lovr uses
overloads so much in the api,
so I really don't mind having
a separate constructor :S
This commit is contained in:
Nevyn Bengtsson 2020-12-10 14:24:24 +01:00 committed by Bjorn
parent 35ac33f184
commit 3e003d55b9
1 changed files with 13 additions and 6 deletions

View File

@ -78,12 +78,7 @@ static int l_lovrDataNewSoundData(lua_State* L) {
uint32_t sampleRate = luaL_optinteger(L, 3, 44100);
SampleFormat format = luax_checkenum(L, 4, SampleFormat, "i16");
Blob* blob = luax_totype(L, 5, Blob);
SoundData* soundData;
if(blob) {
soundData = lovrSoundDataCreateRaw(frames, channels, sampleRate, format, blob);
} else {
soundData = lovrSoundDataCreateStream(frames, channels, sampleRate, format);
}
SoundData* soundData = lovrSoundDataCreateRaw(frames, channels, sampleRate, format, blob);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
return 1;
@ -98,6 +93,17 @@ static int l_lovrDataNewSoundData(lua_State* L) {
return 1;
}
static int l_lovrDataNewSoundDataStream(lua_State* L) {
uint64_t frames = luaL_checkinteger(L, 1);
uint32_t channels = luaL_optinteger(L, 2, 2);
uint32_t sampleRate = luaL_optinteger(L, 3, 44100);
SampleFormat format = luax_checkenum(L, 4, SampleFormat, "i16");
SoundData* soundData = lovrSoundDataCreateStream(frames, channels, sampleRate, format);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
return 1;
}
static int l_lovrDataNewTextureData(lua_State* L) {
TextureData* textureData = NULL;
if (lua_type(L, 1) == LUA_TNUMBER) {
@ -128,6 +134,7 @@ static const luaL_Reg lovrData[] = {
{ "newModelData", l_lovrDataNewModelData },
{ "newRasterizer", l_lovrDataNewRasterizer },
{ "newSoundData", l_lovrDataNewSoundData },
{ "newSoundDataStream", l_lovrDataNewSoundDataStream },
{ "newTextureData", l_lovrDataNewTextureData },
{ NULL, NULL }
};