Build type information on first use (load-time), instead of using a hardcoded list

--HG--
branch : dynamiccore2
This commit is contained in:
Bart van Strien
2016-11-13 16:38:57 +01:00
parent 452a8a877e
commit c761202486
192 changed files with 734 additions and 614 deletions
+5 -3
View File
@@ -25,8 +25,10 @@ namespace love
namespace audio
{
Source::Source(Type type)
: type(type)
love::Type Source::type(&Object::type);
Source::Source(Type sourceType)
: sourceType(sourceType)
{
}
@@ -36,7 +38,7 @@ Source::~Source()
Source::Type Source::getType() const
{
return type;
return sourceType;
}
bool Source::getConstant(const char *in, Type &out)
+3 -1
View File
@@ -34,6 +34,8 @@ class Source : public Object
{
public:
static love::Type type;
enum Type
{
TYPE_STATIC,
@@ -114,7 +116,7 @@ public:
protected:
Type type;
Type sourceType;
private:
+18 -18
View File
@@ -178,7 +178,7 @@ Source::Source(Pool *pool, int sampleRate, int bitDepth, int channels)
}
Source::Source(const Source &s)
: love::audio::Source(s.type)
: love::audio::Source(s.sourceType)
, pool(s.pool)
, valid(false)
, staticBuffer(s.staticBuffer)
@@ -199,14 +199,14 @@ Source::Source(const Source &s)
, bitDepth(s.bitDepth)
, decoder(nullptr)
, toLoop(0)
, unusedBufferTop(s.type == TYPE_STREAM ? MAX_BUFFERS - 1 : -1)
, unusedBufferTop(s.sourceType == TYPE_STREAM ? MAX_BUFFERS - 1 : -1)
{
if (type == TYPE_STREAM)
if (sourceType == TYPE_STREAM)
{
if (s.decoder.get())
decoder.set(s.decoder->clone(), Acquire::NORETAIN);
}
if (type != TYPE_STATIC)
if (sourceType != TYPE_STATIC)
{
alGenBuffers(MAX_BUFFERS, streamBuffers);
for (unsigned int i = 0; i < MAX_BUFFERS; i++)
@@ -223,7 +223,7 @@ Source::~Source()
if (valid)
pool->stop(this);
if (type != TYPE_STATIC)
if (sourceType != TYPE_STATIC)
alDeleteBuffers(MAX_BUFFERS, streamBuffers);
}
@@ -264,7 +264,7 @@ bool Source::isFinished() const
if (!valid)
return false;
if (type == TYPE_STREAM && (isLooping() || !decoder->isFinished()))
if (sourceType == TYPE_STREAM && (isLooping() || !decoder->isFinished()))
return false;
ALenum state;
@@ -277,7 +277,7 @@ bool Source::update()
if (!valid)
return false;
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
// Looping mode could have changed.
@@ -401,7 +401,7 @@ void Source::seekAtomic(float offset, void *unit)
break;
}
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
alSourcef(source, AL_SAMPLE_OFFSET, offsetSamples);
@@ -494,7 +494,7 @@ double Source::getDurationAtomic(void *vunit)
{
Unit unit = *(Unit *) vunit;
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
{
@@ -649,10 +649,10 @@ bool Source::isRelative() const
void Source::setLooping(bool enable)
{
if (type == TYPE_QUEUE)
if (sourceType == TYPE_QUEUE)
throw QueueLoopingException();
if (valid && type == TYPE_STATIC)
if (valid && sourceType == TYPE_STATIC)
alSourcei(source, AL_LOOPING, enable ? AL_TRUE : AL_FALSE);
looping = enable;
@@ -665,7 +665,7 @@ bool Source::isLooping() const
bool Source::queue(void *data, size_t length, int dataSampleRate, int dataBitDepth, int dataChannels)
{
if (type != TYPE_QUEUE)
if (sourceType != TYPE_QUEUE)
throw QueueTypeMismatchException();
if (dataSampleRate != sampleRate || dataBitDepth != bitDepth || dataChannels != channels )
@@ -709,7 +709,7 @@ bool Source::queueAtomic(void *data, ALsizei length)
int Source::getFreeBufferCount() const
{
switch (type) //why not :^)
switch (sourceType) //why not :^)
{
case TYPE_STATIC:
return 0;
@@ -730,7 +730,7 @@ void Source::prepareAtomic()
// of the new one.
reset();
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
alSourcei(source, AL_BUFFER, staticBuffer->getBuffer());
@@ -771,7 +771,7 @@ void Source::prepareAtomic()
void Source::teardownAtomic()
{
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
alSourcef(source, AL_SAMPLE_OFFSET, 0);
@@ -839,7 +839,7 @@ bool Source::playAtomic(ALuint source)
valid = true; //if it fails it will be set to false again
//but this prevents a horrible, horrible bug
if (type != TYPE_STREAM)
if (sourceType != TYPE_STREAM)
offsetSamples = offsetSeconds = 0;
return success;
@@ -891,7 +891,7 @@ bool Source::playAtomic(const std::vector<love::audio::Source*> &sources, const
Source *source = (Source*) _source;
source->valid = source->valid || success;
if (success && source->type != TYPE_STREAM)
if (success && source->sourceType != TYPE_STREAM)
source->offsetSamples = source->offsetSeconds = 0;
}
@@ -952,7 +952,7 @@ void Source::reset()
alSourcef(source, AL_REFERENCE_DISTANCE, referenceDistance);
alSourcef(source, AL_ROLLOFF_FACTOR, rolloffFactor);
alSourcef(source, AL_MAX_DISTANCE, maxDistance);
alSourcei(source, AL_LOOPING, (type == TYPE_STATIC) && isLooping() ? AL_TRUE : AL_FALSE);
alSourcei(source, AL_LOOPING, (sourceType == TYPE_STATIC) && isLooping() ? AL_TRUE : AL_FALSE);
alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
alSourcei(source, AL_CONE_INNER_ANGLE, cone.innerAngle);
alSourcei(source, AL_CONE_OUTER_ANGLE, cone.outerAngle);
+13 -13
View File
@@ -46,31 +46,31 @@ int w_newSource(lua_State *L)
{
Source::Type stype = Source::TYPE_STREAM;
if (!luax_istype(L, 1, SOUND_SOUND_DATA_ID) && !luax_istype(L, 1, SOUND_DECODER_ID))
if (!luax_istype(L, 1, love::sound::SoundData::type) && !luax_istype(L, 1, love::sound::Decoder::type))
{
const char *stypestr = luaL_checkstring(L, 2);
if (stypestr && !Source::getConstant(stypestr, stype))
return luaL_error(L, "Invalid source type: %s", stypestr);
}
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_ID) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_ID))
if (lua_isstring(L, 1) || luax_istype(L, 1, love::filesystem::File::type) || luax_istype(L, 1, love::filesystem::FileData::type))
luax_convobj(L, 1, "sound", "newDecoder");
if (stype == Source::TYPE_STATIC && luax_istype(L, 1, SOUND_DECODER_ID))
if (stype == Source::TYPE_STATIC && luax_istype(L, 1, love::sound::Decoder::type))
luax_convobj(L, 1, "sound", "newSoundData");
Source *t = nullptr;
luax_catchexcept(L, [&]() {
if (luax_istype(L, 1, SOUND_SOUND_DATA_ID))
t = instance()->newSource(luax_totype<love::sound::SoundData>(L, 1, SOUND_SOUND_DATA_ID));
else if (luax_istype(L, 1, SOUND_DECODER_ID))
t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1, SOUND_DECODER_ID));
if (luax_istype(L, 1, love::sound::SoundData::type))
t = instance()->newSource(luax_totype<love::sound::SoundData>(L, 1, love::sound::SoundData::type));
else if (luax_istype(L, 1, love::sound::Decoder::type))
t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1, love::sound::Decoder::type));
});
if (t != nullptr)
{
luax_pushtype(L, AUDIO_SOURCE_ID, t);
luax_pushtype(L, love::audio::Source::type, t);
t->release();
return 1;
}
@@ -88,7 +88,7 @@ int w_newQueueableSource(lua_State *L)
if (t != nullptr)
{
luax_pushtype(L, AUDIO_SOURCE_ID, t);
luax_pushtype(L, love::audio::Source::type, t);
t->release();
return 1;
}
@@ -150,7 +150,7 @@ int w_pause(lua_State *L)
lua_createtable(L, (int) sources.size(), 0);
for (int i = 0; i < (int) sources.size(); i++)
{
luax_pushtype(L, AUDIO_SOURCE_ID, sources[i]);
luax_pushtype(L, love::audio::Source::type, sources[i]);
lua_rawseti(L, -2, i+1);
}
return 1;
@@ -270,7 +270,7 @@ int w_getRecordedData(lua_State *L)
lua_pushnil(L);
else
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, sd);
luax_pushtype(L, love::sound::SoundData::type, sd);
sd->release();
}
return 1;
@@ -285,7 +285,7 @@ int w_stopRecording(lua_State *L)
lua_pushnil(L);
else
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, sd);
luax_pushtype(L, love::sound::SoundData::type, sd);
sd->release();
}
return 1;
@@ -395,7 +395,7 @@ extern "C" int luaopen_love_audio(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "audio";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
+5 -5
View File
@@ -30,7 +30,7 @@ namespace audio
Source *luax_checksource(lua_State *L, int idx)
{
return luax_checktype<Source>(L, idx, AUDIO_SOURCE_ID);
return luax_checktype<Source>(L, idx, love::audio::Source::type);
}
int w_Source_clone(lua_State *L)
@@ -38,7 +38,7 @@ int w_Source_clone(lua_State *L)
Source *t = luax_checksource(L, 1);
Source *clone = nullptr;
luax_catchexcept(L, [&](){ clone = t->clone(); });
luax_pushtype(L, AUDIO_SOURCE_ID, clone);
luax_pushtype(L, love::audio::Source::type, clone);
clone->release();
return 1;
}
@@ -342,9 +342,9 @@ int w_Source_queue(lua_State *L)
Source *t = luax_checksource(L, 1);
bool success;
if (luax_istype(L, 2, SOUND_SOUND_DATA_ID))
if (luax_istype(L, 2, love::sound::SoundData::type))
{
auto s = luax_totype<love::sound::SoundData>(L, 2, SOUND_SOUND_DATA_ID);
auto s = luax_totype<love::sound::SoundData>(L, 2, love::sound::SoundData::type);
int offset = 0;
size_t length = s->getSize();
@@ -450,7 +450,7 @@ static const luaL_Reg w_Source_functions[] =
extern "C" int luaopen_source(lua_State *L)
{
return luax_register_type(L, AUDIO_SOURCE_ID, "Source", w_Source_functions, nullptr);
return luax_register_type(L, love::audio::Source::type, "Source", w_Source_functions, nullptr);
}
} // audio