Merge dynamiccore2 into minor

Instead of a global type enum and bitfield, all types now have their own
love::Type static member. This means they automatically assign their ids, build
their bitsets, etc. As a bonus, it simplifies wrapper code since most functions
already know which type they're pushing to or getting from lua, so they can
directly get the static member (if it's called 'type').

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2016-11-30 22:38:30 +01:00
204 changed files with 944 additions and 669 deletions
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace audio
{
love::Type RecordingDevice::type("RecordingDevice", &Object::type);
RecordingDevice::RecordingDevice()
{
}
+3
View File
@@ -34,6 +34,9 @@ namespace audio
class RecordingDevice : public love::Object
{
public:
static love::Type type;
RecordingDevice();
virtual ~RecordingDevice();
+5 -3
View File
@@ -25,8 +25,10 @@ namespace love
namespace audio
{
Source::Source(Type type)
: type(type)
love::Type Source::type("Source", &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:
+21 -21
View File
@@ -179,7 +179,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)
@@ -200,14 +200,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++)
@@ -224,7 +224,7 @@ Source::~Source()
if (valid)
pool->stop(this);
if (type != TYPE_STATIC)
if (sourceType != TYPE_STATIC)
alDeleteBuffers(MAX_BUFFERS, streamBuffers);
}
@@ -265,7 +265,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;
@@ -278,7 +278,7 @@ bool Source::update()
if (!valid)
return false;
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
{
@@ -405,7 +405,7 @@ void Source::seekAtomic(float offset, void *unit)
}
bool wasPlaying = isPlaying();
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
if (valid)
@@ -459,7 +459,7 @@ void Source::seekAtomic(float offset, void *unit)
case TYPE_MAX_ENUM:
break;
}
if (wasPlaying && (alGetError() == AL_INVALID_VALUE || (type == TYPE_STREAM && !isPlaying())))
if (wasPlaying && (alGetError() == AL_INVALID_VALUE || (sourceType == TYPE_STREAM && !isPlaying())))
{
stop();
if (isLooping())
@@ -506,7 +506,7 @@ double Source::getDurationAtomic(void *vunit)
{
Unit unit = *(Unit *) vunit;
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
{
@@ -661,10 +661,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;
@@ -677,7 +677,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 )
@@ -721,7 +721,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;
@@ -742,7 +742,7 @@ void Source::prepareAtomic()
// of the new one.
reset();
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
alSourcei(source, AL_BUFFER, staticBuffer->getBuffer());
@@ -778,7 +778,7 @@ void Source::prepareAtomic()
void Source::teardownAtomic()
{
switch (type)
switch (sourceType)
{
case TYPE_STATIC:
break;
@@ -840,7 +840,7 @@ bool Source::playAtomic(ALuint source)
bool success = alGetError() == AL_NO_ERROR;
if (type == TYPE_STREAM)
if (sourceType == TYPE_STREAM)
{
valid = true; //isPlaying() needs source to be valid
if (!isPlaying())
@@ -857,7 +857,7 @@ bool Source::playAtomic(ALuint source)
valid = true; //stop() needs source to be valid
stop();
}
else if (type != TYPE_STREAM)
if (sourceType != TYPE_STREAM)
offsetSamples = offsetSeconds = 0;
//this is set to success state afterwards anyway, but setting it here
@@ -887,7 +887,7 @@ void Source::resumeAtomic()
{
alSourcePlay(source);
if (alGetError() == AL_INVALID_VALUE || (type == TYPE_STREAM && unusedBufferTop == MAX_BUFFERS - 1))
if (alGetError() == AL_INVALID_VALUE || (sourceType == TYPE_STREAM && unusedBufferTop == MAX_BUFFERS - 1))
stop();
}
}
@@ -918,7 +918,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;
}
@@ -979,7 +979,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);
+12 -12
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));
else if (luax_istype(L, 1, love::sound::Decoder::type))
t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1));
});
if (t != nullptr)
{
luax_pushtype(L, AUDIO_SOURCE_ID, t);
luax_pushtype(L, 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, 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, sources[i]);
lua_rawseti(L, -2, i+1);
}
return 1;
@@ -285,7 +285,7 @@ int w_getRecordingDevices(lua_State *L)
for (unsigned int i = 0; i < devices.size(); i++)
{
luax_pushtype(L, AUDIO_RECORDING_DEVICE_ID, devices[i]);
luax_pushtype(L, devices[i]);
lua_rawseti(L, -2, i + 1);
}
@@ -366,7 +366,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;
+4 -4
View File
@@ -29,7 +29,7 @@ namespace audio
RecordingDevice *luax_checkrecordingdevice(lua_State *L, int idx)
{
return luax_checktype<RecordingDevice>(L, idx, AUDIO_RECORDING_DEVICE_ID);
return luax_checktype<RecordingDevice>(L, idx);
}
int w_RecordingDevice_start(lua_State *L)
@@ -62,7 +62,7 @@ int w_RecordingDevice_stop(lua_State *L)
if (s != nullptr)
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
luax_pushtype(L, s);
s->release();
}
else
@@ -80,7 +80,7 @@ int w_RecordingDevice_getData(lua_State *L)
if (s != nullptr)
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
luax_pushtype(L, s);
s->release();
}
else
@@ -147,7 +147,7 @@ static const luaL_Reg w_RecordingDevice_functions[] =
extern "C" int luaopen_recordingdevice(lua_State *L)
{
int ret = luax_register_type(L, AUDIO_RECORDING_DEVICE_ID, "RecordingDevice", w_RecordingDevice_functions, nullptr);
int ret = luax_register_type(L, &RecordingDevice::type, w_RecordingDevice_functions, nullptr);
return ret;
}
+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);
}
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, 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);
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, w_Source_functions, nullptr);
}
} // audio
+8 -8
View File
@@ -381,7 +381,7 @@ Message *Event::convert(const SDL_Event &e) const
{
Proxy proxy;
proxy.object = new love::filesystem::DroppedFile(e.drop.file);
proxy.type = FILESYSTEM_DROPPED_FILE_ID;
proxy.type = &love::filesystem::DroppedFile::type;
vargs.emplace_back(proxy.type, &proxy);
msg = new Message("filedropped", vargs);
proxy.object->release();
@@ -424,7 +424,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
{
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
proxy.object = joymodule->getJoystickFromID(e.jbutton.which);
if (!proxy.object)
break;
@@ -437,7 +437,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
break;
case SDL_JOYAXISMOTION:
{
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
proxy.object = joymodule->getJoystickFromID(e.jaxis.which);
if (!proxy.object)
break;
@@ -453,7 +453,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!joystick::sdl::Joystick::getConstant(e.jhat.value, hat) || !joystick::Joystick::getConstant(hat, txt))
break;
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
proxy.object = joymodule->getJoystickFromID(e.jhat.which);
if (!proxy.object)
break;
@@ -471,7 +471,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!joystick::Joystick::getConstant(padbutton, txt))
break;
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
proxy.object = joymodule->getJoystickFromID(e.cbutton.which);
if (!proxy.object)
break;
@@ -487,7 +487,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!joystick::Joystick::getConstant(padaxis, txt))
break;
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
proxy.object = joymodule->getJoystickFromID(e.caxis.which);
if (!proxy.object)
break;
@@ -503,7 +503,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
case SDL_JOYDEVICEADDED:
// jdevice.which is the joystick device index.
proxy.object = joymodule->addJoystick(e.jdevice.which);
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
if (proxy.object)
{
vargs.emplace_back(proxy.type, (void *) &proxy);
@@ -513,7 +513,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
case SDL_JOYDEVICEREMOVED:
// jdevice.which is the joystick instance ID now.
proxy.object = joymodule->getJoystickFromID(e.jdevice.which);
proxy.type = JOYSTICK_JOYSTICK_ID;
proxy.type = &love::joystick::Joystick::type;
if (proxy.object)
{
joymodule->removeJoystick((joystick::Joystick *) proxy.object);
+1 -1
View File
@@ -128,7 +128,7 @@ extern "C" int luaopen_love_event(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "event";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = nullptr;
+2
View File
@@ -37,6 +37,8 @@ namespace love
namespace filesystem
{
love::Type DroppedFile::type("DroppedFile", &File::type);
DroppedFile::DroppedFile(const std::string &filename)
: filename(filename)
, file(nullptr)
+2
View File
@@ -41,6 +41,8 @@ class DroppedFile : public File
{
public:
static love::Type type;
DroppedFile(const std::string &filename);
virtual ~DroppedFile();
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace filesystem
{
love::Type File::type("File", &Object::type);
File::~File()
{
}
+2
View File
@@ -44,6 +44,8 @@ class File : public Object
{
public:
static love::Type type;
/**
* File open mode.
**/
+2
View File
@@ -29,6 +29,8 @@ namespace love
namespace filesystem
{
love::Type FileData::type("FileData", &Data::type);
FileData::FileData(uint64 size, const std::string &filename)
: data(nullptr)
, size((size_t) size)
+2
View File
@@ -37,6 +37,8 @@ class FileData : public Data
{
public:
static love::Type type;
FileData(uint64 size, const std::string &filename);
virtual ~FileData();
+2
View File
@@ -42,6 +42,8 @@ namespace love
namespace filesystem
{
love::Type Filesystem::type("filesystem", &Module::type);
Filesystem::Filesystem()
{
}
+2
View File
@@ -61,6 +61,8 @@ class Filesystem : public Module
{
public:
static love::Type type;
Filesystem();
virtual ~Filesystem();
+2 -2
View File
@@ -28,12 +28,12 @@ namespace filesystem
DroppedFile *luax_checkdroppedfile(lua_State *L, int idx)
{
return luax_checktype<DroppedFile>(L, idx, FILESYSTEM_DROPPED_FILE_ID);
return luax_checktype<DroppedFile>(L, idx);
}
extern "C" int luaopen_droppedfile(lua_State *L)
{
return luax_register_type(L, FILESYSTEM_DROPPED_FILE_ID, "DroppedFile", w_File_functions, nullptr);
return luax_register_type(L, &DroppedFile::type, w_File_functions, nullptr);
}
} // filesystem
+5 -5
View File
@@ -43,7 +43,7 @@ int luax_ioError(lua_State *L, const char *fmt, ...)
File *luax_checkfile(lua_State *L, int idx)
{
return luax_checktype<File>(L, idx, FILESYSTEM_FILE_ID);
return luax_checktype<File>(L, idx);
}
int w_File_getSize(lua_State *L)
@@ -148,11 +148,11 @@ int w_File_write(lua_State *L)
return luax_ioError(L, "%s", e.what());
}
}
else if (luax_istype(L, 2, DATA_ID))
else if (luax_istype(L, 2, love::Data::type))
{
try
{
love::Data *data = luax_totype<love::Data>(L, 2, DATA_ID);
love::Data *data = luax_totype<love::Data>(L, 2);
result = file->write(data, luaL_optinteger(L, 3, data->getSize()));
}
catch (love::Exception &e)
@@ -227,7 +227,7 @@ int w_File_lines_i(lua_State *L)
int linesize = 0;
bool newline = false;
File *file = luax_checktype<File>(L, lua_upvalueindex(1), FILESYSTEM_FILE_ID);
File *file = luax_checktype<File>(L, lua_upvalueindex(1));
// Only accept read mode at this point.
if (file->getMode() != File::MODE_READ)
@@ -435,7 +435,7 @@ const luaL_Reg w_File_functions[] =
extern "C" int luaopen_file(lua_State *L)
{
return luax_register_type(L, FILESYSTEM_FILE_ID, "File", w_File_functions, nullptr);
return luax_register_type(L, &File::type, w_File_functions, nullptr);
}
} // filesystem
+2 -2
View File
@@ -29,7 +29,7 @@ namespace filesystem
FileData *luax_checkfiledata(lua_State *L, int idx)
{
return luax_checktype<FileData>(L, idx, FILESYSTEM_FILE_DATA_ID);
return luax_checktype<FileData>(L, idx);
}
int w_FileData_getFilename(lua_State *L)
@@ -56,7 +56,7 @@ static const luaL_Reg w_FileData_functions[] =
extern "C" int luaopen_filedata(lua_State *L)
{
return luax_register_type(L, FILESYSTEM_FILE_DATA_ID, "FileData", w_Data_functions, w_FileData_functions, nullptr);
return luax_register_type(L, &FileData::type, w_Data_functions, w_FileData_functions, nullptr);
}
} // filesystem
+13 -13
View File
@@ -113,9 +113,9 @@ int w_mount(lua_State *L)
{
std::string archive;
if (luax_istype(L, 1, FILESYSTEM_DROPPED_FILE_ID))
if (luax_istype(L, 1, DroppedFile::type))
{
DroppedFile *file = luax_totype<DroppedFile>(L, 1, FILESYSTEM_DROPPED_FILE_ID);
DroppedFile *file = luax_totype<DroppedFile>(L, 1);
archive = file->getFilename();
}
else
@@ -166,7 +166,7 @@ int w_newFile(lua_State *L)
}
}
luax_pushtype(L, FILESYSTEM_FILE_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -190,12 +190,12 @@ FileData *luax_getfiledata(lua_State *L, int idx)
FileData *data = nullptr;
File *file = nullptr;
if (lua_isstring(L, idx) || luax_istype(L, idx, FILESYSTEM_FILE_ID))
if (lua_isstring(L, idx) || luax_istype(L, idx, File::type))
{
file = luax_getfile(L, idx);
file->retain();
}
else if (luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID))
else if (luax_istype(L, idx, FileData::type))
{
data = luax_checkfiledata(L, idx);
data->retain();
@@ -220,7 +220,7 @@ FileData *luax_getfiledata(lua_State *L, int idx)
bool luax_cangetfiledata(lua_State *L, int idx)
{
return lua_isstring(L, idx) || luax_istype(L, idx, FILESYSTEM_FILE_ID) || luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID);
return lua_isstring(L, idx) || luax_istype(L, idx, File::type) || luax_istype(L, idx, FileData::type);
}
int w_newFileData(lua_State *L)
@@ -233,7 +233,7 @@ int w_newFileData(lua_State *L)
luax_convobj(L, 1, "filesystem", "newFile");
// Get FileData from the File.
if (luax_istype(L, 1, FILESYSTEM_FILE_ID))
if (luax_istype(L, 1, File::type))
{
File *file = luax_checkfile(L, 1);
@@ -246,7 +246,7 @@ int w_newFileData(lua_State *L)
{
return luax_ioError(L, "%s", e.what());
}
luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, data);
luax_pushtype(L, data);
return 1;
}
else
@@ -260,7 +260,7 @@ int w_newFileData(lua_State *L)
FileData *t = nullptr;
luax_catchexcept(L, [&](){ t = instance()->newFileData(str, length, filename); });
luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -398,9 +398,9 @@ static int w_write_or_append(lua_State *L, File::Mode mode)
const char *input = 0;
size_t len = 0;
if (luax_istype(L, 2, DATA_ID))
if (luax_istype(L, 2, love::Data::type))
{
love::Data *data = luax_totype<love::Data>(L, 2, DATA_ID);
love::Data *data = luax_totype<love::Data>(L, 2);
input = (const char *) data->getData();
len = data->getSize();
}
@@ -474,7 +474,7 @@ int w_lines(lua_State *L)
return luaL_error(L, "Could not open file.");
}
luax_pushtype(L, FILESYSTEM_FILE_ID, file);
luax_pushtype(L, file);
file->release();
}
else
@@ -810,7 +810,7 @@ extern "C" int luaopen_love_filesystem(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "filesystem";
w.type = MODULE_FILESYSTEM_ID;
w.type = &Filesystem::type;
w.functions = functions;
w.types = types;
+2
View File
@@ -33,6 +33,8 @@ namespace love
namespace font
{
love::Type GlyphData::type("GlyphData", &Data::type);
GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
: glyph(glyph)
, metrics(glyphMetrics)
+2
View File
@@ -55,6 +55,8 @@ class GlyphData : public Data
{
public:
static love::Type type;
enum Format
{
FORMAT_LUMINANCE_ALPHA,
+2
View File
@@ -29,6 +29,8 @@ namespace love
namespace font
{
love::Type Rasterizer::type("Rasterizer", &Object::type);
Rasterizer::~Rasterizer()
{
}
+2
View File
@@ -49,6 +49,8 @@ class Rasterizer : public Object
{
public:
static love::Type type;
virtual ~Rasterizer();
/**
+11 -11
View File
@@ -53,7 +53,7 @@ int w_newRasterizer(lua_State *L)
[&](bool) { d->release(); }
);
luax_pushtype(L, FONT_RASTERIZER_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -84,7 +84,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
{
love::Data *d = nullptr;
if (luax_istype(L, 1, DATA_ID))
if (luax_istype(L, 1, love::Data::type))
{
d = luax_checkdata(L, 1);
d->retain();
@@ -104,14 +104,14 @@ int w_newTrueTypeRasterizer(lua_State *L)
);
}
luax_pushtype(L, FONT_RASTERIZER_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
static void convimagedata(lua_State *L, int idx)
{
if (lua_type(L, 1) == LUA_TSTRING || luax_istype(L, idx, FILESYSTEM_FILE_ID) || luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID))
if (lua_type(L, 1) == LUA_TSTRING || luax_istype(L, idx, love::filesystem::File::type) || luax_istype(L, idx, love::filesystem::FileData::type))
luax_convobj(L, idx, "image", "newImageData");
}
@@ -129,7 +129,7 @@ int w_newBMFontRasterizer(lua_State *L)
lua_rawgeti(L, 2, i);
convimagedata(L, -1);
image::ImageData *id = luax_checktype<image::ImageData>(L, -1, IMAGE_IMAGE_DATA_ID);
image::ImageData *id = luax_checktype<image::ImageData>(L, -1);
images.push_back(id);
id->retain();
@@ -141,7 +141,7 @@ int w_newBMFontRasterizer(lua_State *L)
for (int i = 2; i <= lua_gettop(L); i++)
{
convimagedata(L, i);
image::ImageData *id = luax_checktype<image::ImageData>(L, i, IMAGE_IMAGE_DATA_ID);
image::ImageData *id = luax_checktype<image::ImageData>(L, i);
images.push_back(id);
id->retain();
}
@@ -152,7 +152,7 @@ int w_newBMFontRasterizer(lua_State *L)
[&](bool) { d->release(); for (auto id : images) id->release(); }
);
luax_pushtype(L, FONT_RASTERIZER_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -163,13 +163,13 @@ int w_newImageRasterizer(lua_State *L)
convimagedata(L, 1);
image::ImageData *d = luax_checktype<image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
image::ImageData *d = luax_checktype<image::ImageData>(L, 1);
std::string glyphs = luax_checkstring(L, 2);
int extraspacing = (int) luaL_optnumber(L, 3, 0);
luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); });
luax_pushtype(L, FONT_RASTERIZER_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -191,7 +191,7 @@ int w_newGlyphData(lua_State *L)
t = instance()->newGlyphData(r, g);
}
luax_pushtype(L, FONT_GLYPH_DATA_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -227,7 +227,7 @@ extern "C" int luaopen_love_font(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "font";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
+2 -2
View File
@@ -27,7 +27,7 @@ namespace font
GlyphData *luax_checkglyphdata(lua_State *L, int idx)
{
return luax_checktype<GlyphData>(L, idx, FONT_GLYPH_DATA_ID);
return luax_checktype<GlyphData>(L, idx);
}
int w_GlyphData_getWidth(lua_State *L)
@@ -131,7 +131,7 @@ const luaL_Reg w_GlyphData_functions[] =
extern "C" int luaopen_glyphdata(lua_State *L)
{
return luax_register_type(L, FONT_GLYPH_DATA_ID, "GlyphData", w_Data_functions, w_GlyphData_functions, nullptr);
return luax_register_type(L, &GlyphData::type, w_Data_functions, w_GlyphData_functions, nullptr);
}
} // font
+3 -3
View File
@@ -29,7 +29,7 @@ namespace font
Rasterizer *luax_checkrasterizer(lua_State *L, int idx)
{
return luax_checktype<Rasterizer>(L, idx, FONT_RASTERIZER_ID);
return luax_checktype<Rasterizer>(L, idx);
}
int w_Rasterizer_getHeight(lua_State *L)
@@ -86,7 +86,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
}
});
luax_pushtype(L, FONT_GLYPH_DATA_ID, g);
luax_pushtype(L, g);
g->release();
return 1;
}
@@ -139,7 +139,7 @@ const luaL_Reg w_Rasterizer_functions[] =
extern "C" int luaopen_rasterizer(lua_State *L)
{
return luax_register_type(L, FONT_RASTERIZER_ID, "Rasterizer", w_Rasterizer_functions, nullptr);
return luax_register_type(L, &Rasterizer::type, w_Rasterizer_functions, nullptr);
}
} // font
+32
View File
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2006-2016 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "Drawable.h"
namespace love
{
namespace graphics
{
love::Type Drawable::type("Drawable", &Object::type);
} // graphics
} // love
+2
View File
@@ -38,6 +38,8 @@ class Drawable : public Object
{
public:
static love::Type type;
/**
* Destructor.
**/
+2
View File
@@ -58,6 +58,8 @@ void unGammaCorrectColor(Colorf &c)
}
}
love::Type Graphics::type("graphics", &Module::type);
Graphics::~Graphics()
{
}
+2
View File
@@ -73,6 +73,8 @@ class Graphics : public Module
{
public:
static love::Type type;
enum DrawMode
{
DRAW_LINE,
+2
View File
@@ -50,6 +50,8 @@ float calculate_variation(float inner, float outer, float var)
} // anonymous namespace
love::Type ParticleSystem::type("ParticleSystem", &Drawable::type);
ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
: pMem(nullptr)
, pFree(nullptr)
+3
View File
@@ -45,6 +45,9 @@ namespace graphics
class ParticleSystem : public Drawable
{
public:
static love::Type type;
/**
* Type of distribution new particles are drawn from: None, uniform, normal, ellipse.
*/
+2
View File
@@ -29,6 +29,8 @@ namespace love
namespace graphics
{
love::Type Quad::type("Quad", &Object::type);
Quad::Quad(const Quad::Viewport &v, double sw, double sh)
: sw(sw)
, sh(sh)
+2
View File
@@ -34,6 +34,8 @@ class Quad : public Object
{
public:
static love::Type type;
struct Viewport
{
double x, y;
+1
View File
@@ -25,6 +25,7 @@ namespace love
namespace graphics
{
love::Type Texture::type("Texture", &Drawable::type);
Texture::Filter Texture::defaultFilter;
Texture::Texture()
+2
View File
@@ -41,6 +41,8 @@ class Texture : public Drawable
{
public:
static love::Type type;
enum WrapMode
{
WRAP_CLAMP,
+1
View File
@@ -99,6 +99,7 @@ static bool createMSAABuffer(int width, int height, int &samples, PixelFormat pi
return status == GL_FRAMEBUFFER_COMPLETE && samples > 1;
}
love::Type Canvas::type("Canvas", &Texture::type);
int Canvas::canvasCount = 0;
Canvas::Canvas(int width, int height, PixelFormat format, int msaa)
+2
View File
@@ -43,6 +43,8 @@ class Canvas : public Texture, public Volatile
{
public:
static love::Type type;
Canvas(int width, int height, PixelFormat format = PIXELFORMAT_NORMAL, int msaa = 0);
virtual ~Canvas();
+7 -6
View File
@@ -44,6 +44,7 @@ static inline uint16 normToUint16(double n)
return (uint16) (n * LOVE_UINT16_MAX);
}
love::Type Font::type("Font", &Object::type);
int Font::fontCount = 0;
Font::Font(love::font::Rasterizer *r, const Texture::Filter &filter)
@@ -77,7 +78,7 @@ Font::Font(love::font::Rasterizer *r, const Texture::Filter &filter)
}
love::font::GlyphData *gd = r->getGlyphData(32); // Space character.
type = (gd->getFormat() == font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
fontType = (gd->getFormat() == font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
gd->release();
if (!r->hasGlyph(9)) // No tab character in the Rasterizer.
@@ -142,7 +143,7 @@ void Font::createTexture()
{
OpenGL::TempDebugGroup debuggroup("Font create texture");
size_t bpp = type == FONT_TRUETYPE ? 2 : 4;
size_t bpp = fontType == FONT_TRUETYPE ? 2 : 4;
size_t prevmemsize = textureMemorySize;
if (prevmemsize > 0)
@@ -177,7 +178,7 @@ void Font::createTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLenum internalformat = GL_RGBA;
GLenum format = getTextureFormat(type, &internalformat);
GLenum format = getTextureFormat(fontType, &internalformat);
// Initialize the texture with transparent black.
std::vector<GLubyte> emptydata(size.width * size.height * bpp, 0);
@@ -285,7 +286,7 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
// don't waste space for empty glyphs. also fixes a divide by zero bug with ATI drivers
if (w > 0 && h > 0)
{
GLenum format = getTextureFormat(type);
GLenum format = getTextureFormat(fontType);
g.texture = textures.back();
gl.bindTextureToUnit(g.texture, 0, false);
@@ -1021,7 +1022,7 @@ int Font::getDescent() const
float Font::getBaseline() const
{
// 1.25 is magic line height for true type fonts
return (type == FONT_TRUETYPE) ? floorf(getHeight() / 1.25f + 0.5f) : 0.0f;
return (fontType == FONT_TRUETYPE) ? floorf(getHeight() / 1.25f + 0.5f) : 0.0f;
}
bool Font::hasGlyph(uint32 glyph) const
@@ -1065,7 +1066,7 @@ void Font::setFallbacks(const std::vector<Font *> &fallbacks)
{
for (const Font *f : fallbacks)
{
if (f->type != this->type)
if (f->fontType != this->fontType)
throw love::Exception("Font fallbacks must be of the same font type.");
}
+3 -1
View File
@@ -50,6 +50,8 @@ class Font : public Object, public Volatile
{
public:
static love::Type type;
typedef std::vector<uint32> Codepoints;
enum AlignMode
@@ -235,7 +237,7 @@ private:
// map of left/right glyph pairs to horizontal kerning.
std::unordered_map<uint64, float> kerning;
FontType type;
FontType fontType;
Texture::Filter filter;
int textureX, textureY;
+2
View File
@@ -43,6 +43,8 @@ namespace graphics
namespace opengl
{
love::Type Image::type("Image", &Texture::type);
int Image::imageCount = 0;
float Image::maxMipmapSharpness = 0.0f;
+2
View File
@@ -52,6 +52,8 @@ class Image : public Texture, public Volatile
{
public:
static love::Type type;
enum FlagType
{
FLAG_TYPE_MIPMAPS,
+2
View File
@@ -58,6 +58,8 @@ static std::vector<Mesh::AttribFormat> getDefaultVertexFormat()
return vertexformat;
}
love::Type Mesh::type("Mesh", &Drawable::type);
Mesh::Mesh(const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, DrawMode drawmode, Usage usage)
: vertexFormat(vertexformat)
, vbo(nullptr)
+2
View File
@@ -50,6 +50,8 @@ class Mesh : public Drawable
{
public:
static love::Type type;
// The expected usage pattern of the Mesh's vertex data.
enum Usage
{
+1
View File
@@ -69,6 +69,7 @@ namespace
} // anonymous namespace
love::Type Shader::type("Shader", &Object::type);
Shader *Shader::current = nullptr;
Shader *Shader::defaultShader = nullptr;
Shader *Shader::defaultVideoShader = nullptr;
+2
View File
@@ -46,6 +46,8 @@ class Shader : public Object, public Volatile
{
public:
static love::Type type;
enum ShaderStage
{
STAGE_VERTEX,
@@ -41,6 +41,8 @@ namespace graphics
namespace opengl
{
love::Type SpriteBatch::type("SpriteBatch", &Drawable::type);
SpriteBatch::SpriteBatch(Texture *texture, int size, Mesh::Usage usage)
: texture(texture)
, size(size)
@@ -52,6 +52,8 @@ class SpriteBatch : public Drawable
{
public:
static love::Type type;
SpriteBatch(Texture *texture, int size, Mesh::Usage usage);
virtual ~SpriteBatch();
+2
View File
@@ -30,6 +30,8 @@ namespace graphics
namespace opengl
{
love::Type Text::type("Text", &Drawable::type);
Text::Text(Font *font, const std::vector<Font::ColoredString> &text)
: font(font)
, vbo(nullptr)
+2
View File
@@ -38,6 +38,8 @@ class Text : public Drawable
{
public:
static love::Type type;
Text(Font *font, const std::vector<Font::ColoredString> &text = {});
virtual ~Text();
+2
View File
@@ -30,6 +30,8 @@ namespace graphics
namespace opengl
{
love::Type Video::type("Video", &Drawable::type);
Video::Video(love::video::VideoStream *stream)
: stream(stream)
, filter(Texture::getDefaultFilter())
+2
View File
@@ -40,6 +40,8 @@ class Video : public Drawable, public Volatile
{
public:
static love::Type type;
Video(love::video::VideoStream *stream);
~Video();
+2 -2
View File
@@ -30,7 +30,7 @@ namespace opengl
Canvas *luax_checkcanvas(lua_State *L, int idx)
{
return luax_checktype<Canvas>(L, idx, GRAPHICS_CANVAS_ID);
return luax_checktype<Canvas>(L, idx);
}
int w_Canvas_getFormat(lua_State *L)
@@ -61,7 +61,7 @@ static const luaL_Reg w_Canvas_functions[] =
extern "C" int luaopen_canvas(lua_State *L)
{
return luax_register_type(L, GRAPHICS_CANVAS_ID, "Canvas", w_Texture_functions, w_Canvas_functions, nullptr);
return luax_register_type(L, &Canvas::type, w_Texture_functions, w_Canvas_functions, nullptr);
}
} // opengl
+2 -2
View File
@@ -35,7 +35,7 @@ namespace opengl
Font *luax_checkfont(lua_State *L, int idx)
{
return luax_checktype<Font>(L, idx, GRAPHICS_FONT_ID);
return luax_checktype<Font>(L, idx);
}
int w_Font_getHeight(lua_State *L)
@@ -207,7 +207,7 @@ static const luaL_Reg w_Font_functions[] =
extern "C" int luaopen_font(lua_State *L)
{
return luax_register_type(L, GRAPHICS_FONT_ID, "Font", w_Font_functions, nullptr);
return luax_register_type(L, &Font::type, w_Font_functions, nullptr);
}
} // opengl
+46 -46
View File
@@ -153,7 +153,7 @@ static int w__beginPass(lua_State *L)
luax_catchexcept(L, [&]() { instance()->beginPass(PassInfo::BEGIN_CLEAR, c); });
}
else if (luax_istype(L, 1, GRAPHICS_CANVAS_ID))
else if (luax_istype(L, 1, Canvas::type))
{
PassInfo::ColorAttachment attachment;
attachment.canvas = luax_checkcanvas(L, 1);
@@ -257,7 +257,7 @@ static void screenshotCallback(love::image::ImageData *i, Reference *ref, void *
lua_State *L = (lua_State *) gd;
ref->push(L);
delete ref;
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, i);
luax_pushtype(L, i);
lua_call(L, 1, 0);
}
else
@@ -349,7 +349,7 @@ int w_getPassCanvases(lua_State *L)
const PassInfo &info = instance()->getActivePass();
for (const auto &attachment : info.colorAttachments)
luax_pushtype(L, GRAPHICS_CANVAS_ID, attachment.canvas);
luax_pushtype(L, attachment.canvas);
return info.colorAttachmentCount;
}
@@ -513,7 +513,7 @@ int w_newImage(lua_State *L)
bool releasedata = false;
// Convert to ImageData / CompressedImageData, if necessary.
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))
{
auto imagemodule = Module::getInstance<love::image::Image>(Module::M_IMAGE);
if (imagemodule == nullptr)
@@ -539,7 +539,7 @@ int w_newImage(lua_State *L)
// Lua's GC won't release the image data, so we should do it ourselves.
releasedata = true;
}
else if (luax_istype(L, 1, IMAGE_COMPRESSED_IMAGE_DATA_ID))
else if (luax_istype(L, 1, love::image::CompressedImageData::type))
cdata.push_back(love::image::luax_checkcompressedimagedata(L, 1));
else
data.push_back(love::image::luax_checkimagedata(L, 1));
@@ -558,14 +558,14 @@ int w_newImage(lua_State *L)
if (!data.empty())
{
if (!luax_istype(L, -1, IMAGE_IMAGE_DATA_ID))
if (!luax_istype(L, -1, love::image::ImageData::type))
luax_convobj(L, -1, "image", "newImageData");
data.push_back(love::image::luax_checkimagedata(L, -1));
}
else if (!cdata.empty())
{
if (!luax_istype(L, -1, IMAGE_COMPRESSED_IMAGE_DATA_ID))
if (!luax_istype(L, -1, love::image::CompressedImageData::type))
luax_convobj(L, -1, "image", "newCompressedData");
cdata.push_back(love::image::luax_checkcompressedimagedata(L, -1));
@@ -602,7 +602,7 @@ int w_newImage(lua_State *L)
return luaL_error(L, "Could not load image.");
// Push the type.
luax_pushtype(L, GRAPHICS_IMAGE_ID, image);
luax_pushtype(L, image);
image->release();
return 1;
}
@@ -621,7 +621,7 @@ int w_newQuad(lua_State *L)
double sh = luaL_checknumber(L, 6);
Quad *quad = instance()->newQuad(v, sw, sh);
luax_pushtype(L, GRAPHICS_QUAD_ID, quad);
luax_pushtype(L, quad);
quad->release();
return 1;
}
@@ -633,7 +633,7 @@ int w_newFont(lua_State *L)
Font *font = nullptr;
// Convert to Rasterizer, if necessary.
if (!luax_istype(L, 1, FONT_RASTERIZER_ID))
if (!luax_istype(L, 1, love::font::Rasterizer::type))
{
std::vector<int> idxs;
for (int i = 0; i < lua_gettop(L); i++)
@@ -642,14 +642,14 @@ int w_newFont(lua_State *L)
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newRasterizer");
}
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, FONT_RASTERIZER_ID);
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1);
luax_catchexcept(L, [&]() {
font = instance()->newFont(rasterizer, instance()->getDefaultFilter()); }
);
// Push the type.
luax_pushtype(L, GRAPHICS_FONT_ID, font);
luax_pushtype(L, font);
font->release();
return 1;
}
@@ -662,19 +662,19 @@ int w_newImageFont(lua_State *L)
Texture::Filter filter = instance()->getDefaultFilter();
// Convert to ImageData if necessary.
if (luax_istype(L, 1, GRAPHICS_IMAGE_ID))
if (luax_istype(L, 1, Image::type))
{
Image *i = luax_checktype<Image>(L, 1, GRAPHICS_IMAGE_ID);
Image *i = luax_checktype<Image>(L, 1);
filter = i->getFilter();
const auto &idlevels = i->getImageData();
if (idlevels.empty())
return luaL_argerror(L, 1, "Image must not be compressed.");
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, idlevels[0].get());
luax_pushtype(L, idlevels[0].get());
lua_replace(L, 1);
}
// Convert to Rasterizer if necessary.
if (!luax_istype(L, 1, FONT_RASTERIZER_ID))
if (!luax_istype(L, 1, love::font::Rasterizer::type))
{
luaL_checktype(L, 2, LUA_TSTRING);
@@ -685,13 +685,13 @@ int w_newImageFont(lua_State *L)
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newImageRasterizer");
}
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, FONT_RASTERIZER_ID);
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1);
// Create the font.
Font *font = instance()->newFont(rasterizer, filter);
// Push the type.
luax_pushtype(L, GRAPHICS_FONT_ID, font);
luax_pushtype(L, font);
font->release();
return 1;
}
@@ -715,7 +715,7 @@ int w_newSpriteBatch(lua_State *L)
[&](){ t = instance()->newSpriteBatch(texture, size, usage); }
);
luax_pushtype(L, GRAPHICS_SPRITE_BATCH_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -734,7 +734,7 @@ int w_newParticleSystem(lua_State *L)
[&](){ t = instance()->newParticleSystem(texture, int(size)); }
);
luax_pushtype(L, GRAPHICS_PARTICLE_SYSTEM_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -761,7 +761,7 @@ int w_newCanvas(lua_State *L)
if (canvas == nullptr)
return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
luax_pushtype(L, GRAPHICS_CANVAS_ID, canvas);
luax_pushtype(L, canvas);
canvas->release();
return 1;
}
@@ -854,7 +854,7 @@ int w_newShader(lua_State *L)
try
{
Shader *shader = instance()->newShader(source);
luax_pushtype(L, GRAPHICS_SHADER_ID, shader);
luax_pushtype(L, shader);
shader->release();
}
catch (love::Exception &e)
@@ -1003,10 +1003,10 @@ static Mesh *newCustomMesh(lua_State *L)
int vertexcount = (int) luaL_checknumber(L, 2);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, vertexcount, drawmode, usage); });
}
else if (luax_istype(L, 2, DATA_ID))
else if (luax_istype(L, 2, Data::type))
{
// Vertex data comes directly from a Data object.
Data *data = luax_checktype<Data>(L, 2, DATA_ID);
Data *data = luax_checktype<Data>(L, 2);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, data->getData(), data->getSize(), drawmode, usage); });
}
else
@@ -1086,7 +1086,7 @@ int w_newMesh(lua_State *L)
else
t = newStandardMesh(L);
luax_pushtype(L, GRAPHICS_MESH_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -1108,7 +1108,7 @@ int w_newText(lua_State *L)
luax_catchexcept(L, [&](){ t = instance()->newText(font, text); });
}
luax_pushtype(L, GRAPHICS_TEXT_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -1117,14 +1117,14 @@ int w_newVideo(lua_State *L)
{
luax_checkgraphicscreated(L);
if (!luax_istype(L, 1, VIDEO_VIDEO_STREAM_ID))
if (!luax_istype(L, 1, love::video::VideoStream::type))
luax_convobj(L, 1, "video", "newVideoStream");
auto stream = luax_checktype<love::video::VideoStream>(L, 1, VIDEO_VIDEO_STREAM_ID);
auto stream = luax_checktype<love::video::VideoStream>(L, 1);
Video *video = nullptr;
luax_catchexcept(L, [&]() { video = instance()->newVideo(stream); });
luax_pushtype(L, GRAPHICS_VIDEO_ID, video);
luax_pushtype(L, video);
video->release();
return 1;
}
@@ -1204,14 +1204,14 @@ int w_getBackgroundColor(lua_State *L)
int w_setNewFont(lua_State *L)
{
int ret = w_newFont(L);
Font *font = luax_checktype<Font>(L, -1, GRAPHICS_FONT_ID);
Font *font = luax_checktype<Font>(L, -1);
instance()->setFont(font);
return ret;
}
int w_setFont(lua_State *L)
{
Font *font = luax_checktype<Font>(L, 1, GRAPHICS_FONT_ID);
Font *font = luax_checktype<Font>(L, 1);
instance()->setFont(font);
return 0;
}
@@ -1221,7 +1221,7 @@ int w_getFont(lua_State *L)
Font *f = nullptr;
luax_catchexcept(L, [&](){ f = instance()->getFont(); });
luax_pushtype(L, GRAPHICS_FONT_ID, f);
luax_pushtype(L, f);
return 1;
}
@@ -1463,7 +1463,7 @@ int w_getShader(lua_State *L)
{
Shader *shader = instance()->getShader();
if (shader)
luax_pushtype(L, GRAPHICS_SHADER_ID, shader);
luax_pushtype(L, shader);
else
lua_pushnil(L);
@@ -1626,10 +1626,10 @@ int w_draw(lua_State *L)
Quad *quad = nullptr;
int startidx = 2;
if (luax_istype(L, 2, GRAPHICS_QUAD_ID))
if (luax_istype(L, 2, Quad::type))
{
texture = luax_checktexture(L, 1);
quad = luax_totype<Quad>(L, 2, GRAPHICS_QUAD_ID);
quad = luax_totype<Quad>(L, 2);
startidx = 3;
}
else if (lua_isnil(L, 2) && !lua_isnoneornil(L, 3))
@@ -1638,13 +1638,13 @@ int w_draw(lua_State *L)
}
else
{
drawable = luax_checktype<Drawable>(L, 1, GRAPHICS_DRAWABLE_ID);
drawable = luax_checktype<Drawable>(L, 1);
startidx = 2;
}
if (luax_istype(L, startidx, MATH_TRANSFORM_ID))
if (luax_istype(L, startidx, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, startidx, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, startidx);
luax_catchexcept(L, [&]() {
if (texture && quad)
instance()->drawq(texture, quad, tf->getMatrix());
@@ -1682,9 +1682,9 @@ int w_print(lua_State *L)
std::vector<Font::ColoredString> str;
luax_checkcoloredstring(L, 1, str);
if (luax_istype(L, 2, MATH_TRANSFORM_ID))
if (luax_istype(L, 2, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, 2, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, 2);
luax_catchexcept(L, [&](){ instance()->print(str, tf->getMatrix()); });
}
else
@@ -1716,9 +1716,9 @@ int w_printf(lua_State *L)
int formatidx = 4;
if (luax_istype(L, 2, MATH_TRANSFORM_ID))
if (luax_istype(L, 2, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, 2, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, 2);
m = tf->getMatrix();
formatidx = 3;
}
@@ -2047,9 +2047,9 @@ int w_push(lua_State *L)
luax_catchexcept(L, [&](){ instance()->push(stype); });
if (luax_istype(L, 2, MATH_TRANSFORM_ID))
if (luax_istype(L, 2, math::Transform::type))
{
math::Transform *t = luax_totype<math::Transform>(L, 2, MATH_TRANSFORM_ID);
math::Transform *t = luax_totype<math::Transform>(L, 2);
instance()->applyTransform(t);
}
@@ -2250,7 +2250,7 @@ static const luaL_Reg functions[] =
static int luaopen_drawable(lua_State *L)
{
return luax_register_type(L, GRAPHICS_DRAWABLE_ID, "Drawable", nullptr);
return luax_register_type(L, &Drawable::type, nullptr);
}
// Types for this module.
@@ -2284,7 +2284,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "graphics";
w.type = MODULE_GRAPHICS_ID;
w.type = &Graphics::type;
w.functions = functions;
w.types = types;
+4 -4
View File
@@ -30,7 +30,7 @@ namespace opengl
Image *luax_checkimage(lua_State *L, int idx)
{
return luax_checktype<Image>(L, idx, GRAPHICS_IMAGE_ID);
return luax_checktype<Image>(L, idx);
}
int w_Image_setMipmapFilter(lua_State *L)
@@ -98,7 +98,7 @@ int w_Image_getData(lua_State *L)
{
for (const auto &cdata : i->getCompressedData())
{
luax_pushtype(L, IMAGE_COMPRESSED_IMAGE_DATA_ID, cdata.get());
luax_pushtype(L, cdata.get());
n++;
}
}
@@ -106,7 +106,7 @@ int w_Image_getData(lua_State *L)
{
for (const auto &data : i->getImageData())
{
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, data.get());
luax_pushtype(L, data.get());
n++;
}
}
@@ -150,7 +150,7 @@ static const luaL_Reg w_Image_functions[] =
extern "C" int luaopen_image(lua_State *L)
{
return luax_register_type(L, GRAPHICS_IMAGE_ID, "Image", w_Texture_functions, w_Image_functions, nullptr);
return luax_register_type(L, &Image::type, w_Texture_functions, w_Image_functions, nullptr);
}
} // opengl
+6 -6
View File
@@ -37,7 +37,7 @@ namespace opengl
Mesh *luax_checkmesh(lua_State *L, int idx)
{
return luax_checktype<Mesh>(L, idx, GRAPHICS_MESH_ID);
return luax_checktype<Mesh>(L, idx);
}
static inline size_t writeByteData(lua_State *L, int startidx, int components, char *data)
@@ -117,9 +117,9 @@ int w_Mesh_setVertices(lua_State *L)
size_t stride = t->getVertexStride();
size_t byteoffset = vertoffset * stride;
if (luax_istype(L, 2, DATA_ID))
if (luax_istype(L, 2, Data::type))
{
Data *d = luax_checktype<Data>(L, 2, DATA_ID);
Data *d = luax_checktype<Data>(L, 2);
size_t datasize = std::min(d->getSize(), (t->getVertexCount() - vertoffset) * stride);
char *bytedata = (char *) t->mapVertexData() + byteoffset;
@@ -448,9 +448,9 @@ int w_Mesh_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -540,7 +540,7 @@ static const luaL_Reg w_Mesh_functions[] =
extern "C" int luaopen_mesh(lua_State *L)
{
return luax_register_type(L, GRAPHICS_MESH_ID, "Mesh", w_Mesh_functions, nullptr);
return luax_register_type(L, &Mesh::type, w_Mesh_functions, nullptr);
}
} // opengl
@@ -41,7 +41,7 @@ namespace opengl
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
{
return luax_checktype<ParticleSystem>(L, idx, GRAPHICS_PARTICLE_SYSTEM_ID);
return luax_checktype<ParticleSystem>(L, idx);
}
int w_ParticleSystem_clone(lua_State *L)
@@ -51,7 +51,7 @@ int w_ParticleSystem_clone(lua_State *L)
ParticleSystem *clone = nullptr;
luax_catchexcept(L, [&](){ clone = t->clone(); });
luax_pushtype(L, GRAPHICS_PARTICLE_SYSTEM_ID, clone);
luax_pushtype(L, clone);
clone->release();
return 1;
}
@@ -71,9 +71,9 @@ int w_ParticleSystem_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -584,7 +584,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
{
lua_rawgeti(L, 2, i);
Quad *q = luax_checktype<Quad>(L, -1, GRAPHICS_QUAD_ID);
Quad *q = luax_checktype<Quad>(L, -1);
quads.push_back(q);
lua_pop(L, 1);
@@ -594,7 +594,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
{
for (int i = 2; i <= lua_gettop(L); i++)
{
Quad *q = luax_checktype<Quad>(L, i, GRAPHICS_QUAD_ID);
Quad *q = luax_checktype<Quad>(L, i);
quads.push_back(q);
}
}
@@ -612,7 +612,7 @@ int w_ParticleSystem_getQuads(lua_State *L)
for (int i = 0; i < (int) quads.size(); i++)
{
luax_pushtype(L, GRAPHICS_QUAD_ID, quads[i]);
luax_pushtype(L, quads[i]);
lua_rawseti(L, -2, i + 1);
}
@@ -772,7 +772,7 @@ static const luaL_Reg w_ParticleSystem_functions[] =
extern "C" int luaopen_particlesystem(lua_State *L)
{
return luax_register_type(L, GRAPHICS_PARTICLE_SYSTEM_ID, "ParticleSystem", w_ParticleSystem_functions, nullptr);
return luax_register_type(L, &ParticleSystem::type, w_ParticleSystem_functions, nullptr);
}
} // opengl
+4 -4
View File
@@ -36,7 +36,7 @@ namespace opengl
Shader *luax_checkshader(lua_State *L, int idx)
{
return luax_checktype<Shader>(L, idx, GRAPHICS_SHADER_ID);
return luax_checktype<Shader>(L, idx);
}
int w_Shader_getWarnings(lua_State *L)
@@ -165,9 +165,9 @@ int w_Shader_sendMatrices(lua_State *L, int startidx, Shader *shader, const Shad
for (int i = 0; i < count; i++)
{
if (columns == 4 && rows == 4 && luax_istype(L, startidx + i, MATH_TRANSFORM_ID))
if (columns == 4 && rows == 4 && luax_istype(L, startidx + i, math::Transform::type))
{
math::Transform *t = luax_totype<math::Transform>(L, startidx + i, MATH_TRANSFORM_ID);
math::Transform *t = luax_totype<math::Transform>(L, startidx + i);
memcpy(&values[i * 16], t->getMatrix().getElements(), sizeof(float) * 16);
continue;
}
@@ -328,7 +328,7 @@ static const luaL_Reg w_Shader_functions[] =
extern "C" int luaopen_shader(lua_State *L)
{
return luax_register_type(L, GRAPHICS_SHADER_ID, "Shader", w_Shader_functions, nullptr);
return luax_register_type(L, &Shader::type, w_Shader_functions, nullptr);
}
} // opengl
@@ -37,24 +37,24 @@ namespace opengl
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
{
return luax_checktype<SpriteBatch>(L, idx, GRAPHICS_SPRITE_BATCH_ID);
return luax_checktype<SpriteBatch>(L, idx);
}
static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int startidx, int index)
{
Quad *quad = nullptr;
if (luax_istype(L, startidx, GRAPHICS_QUAD_ID))
if (luax_istype(L, startidx, Quad::type))
{
quad = luax_totype<Quad>(L, startidx, GRAPHICS_QUAD_ID);
quad = luax_totype<Quad>(L, startidx);
startidx++;
}
else if (lua_isnil(L, startidx) && !lua_isnoneornil(L, startidx + 1))
return luax_typerror(L, startidx, "Quad");
if (luax_istype(L, startidx, MATH_TRANSFORM_ID))
if (luax_istype(L, startidx, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, startidx, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, startidx);
luax_catchexcept(L, [&]() {
if (quad)
index = t->addq(quad, tf->getMatrix(), index);
@@ -136,9 +136,9 @@ int w_SpriteBatch_getTexture(lua_State *L)
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, GRAPHICS_IMAGE_ID, tex);
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, GRAPHICS_CANVAS_ID, tex);
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -215,7 +215,7 @@ int w_SpriteBatch_attachAttribute(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
const char *name = luaL_checkstring(L, 2);
Mesh *m = luax_checktype<Mesh>(L, 3, GRAPHICS_MESH_ID);
Mesh *m = luax_checktype<Mesh>(L, 3);
luax_catchexcept(L, [&](){ t->attachAttribute(name, m); });
return 0;
@@ -271,7 +271,7 @@ static const luaL_Reg w_SpriteBatch_functions[] =
extern "C" int luaopen_spritebatch(lua_State *L)
{
return luax_register_type(L, GRAPHICS_SPRITE_BATCH_ID, "SpriteBatch", w_SpriteBatch_functions, nullptr);
return luax_register_type(L, &SpriteBatch::type, w_SpriteBatch_functions, nullptr);
}
} // opengl
+8 -8
View File
@@ -30,7 +30,7 @@ namespace opengl
Text *luax_checktext(lua_State *L, int idx)
{
return luax_checktype<Text>(L, idx, GRAPHICS_TEXT_ID);
return luax_checktype<Text>(L, idx);
}
void luax_checkcoloredstring(lua_State *L, int idx, std::vector<Font::ColoredString> &strings)
@@ -132,9 +132,9 @@ int w_Text_add(lua_State *L)
std::vector<Font::ColoredString> text;
luax_checkcoloredstring(L, 2, text);
if (luax_istype(L, 3, MATH_TRANSFORM_ID))
if (luax_istype(L, 3, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, 3, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, 3);
luax_catchexcept(L, [&](){ index = t->add(text, tf->getMatrix()); });
}
else
@@ -174,9 +174,9 @@ int w_Text_addf(lua_State *L)
if (!Font::getConstant(alignstr, align))
return luaL_error(L, "Invalid align mode: %s", alignstr);
if (luax_istype(L, 5, MATH_TRANSFORM_ID))
if (luax_istype(L, 5, math::Transform::type))
{
math::Transform *tf = luax_totype<math::Transform>(L, 5, MATH_TRANSFORM_ID);
math::Transform *tf = luax_totype<math::Transform>(L, 5);
luax_catchexcept(L, [&](){ index = t->addf(text, wrap, align, tf->getMatrix()); });
}
else
@@ -209,7 +209,7 @@ int w_Text_clear(lua_State *L)
int w_Text_setFont(lua_State *L)
{
Text *t = luax_checktext(L, 1);
Font *f = luax_checktype<Font>(L, 2, GRAPHICS_FONT_ID);
Font *f = luax_checktype<Font>(L, 2);
luax_catchexcept(L, [&](){ t->setFont(f); });
return 0;
}
@@ -218,7 +218,7 @@ int w_Text_getFont(lua_State *L)
{
Text *t = luax_checktext(L, 1);
Font *f = t->getFont();
luax_pushtype(L, GRAPHICS_FONT_ID, f);
luax_pushtype(L, f);
return 1;
}
@@ -264,7 +264,7 @@ static const luaL_Reg w_Text_functions[] =
extern "C" int luaopen_text(lua_State *L)
{
return luax_register_type(L, GRAPHICS_TEXT_ID, "Text", w_Text_functions, nullptr);
return luax_register_type(L, &Text::type, w_Text_functions, nullptr);
}
} // opengl
+6 -6
View File
@@ -34,13 +34,13 @@ namespace opengl
Video *luax_checkvideo(lua_State *L, int idx)
{
return luax_checktype<Video>(L, idx, GRAPHICS_VIDEO_ID);
return luax_checktype<Video>(L, idx);
}
int w_Video_getStream(lua_State *L)
{
Video *video = luax_checkvideo(L, 1);
luax_pushtype(L, VIDEO_VIDEO_STREAM_ID, video->getStream());
luax_pushtype(L, video->getStream());
return 1;
}
@@ -49,7 +49,7 @@ int w_Video_getSource(lua_State *L)
Video *video = luax_checkvideo(L, 1);
auto source = video->getSource();
if (source)
luax_pushtype(L, AUDIO_SOURCE_ID, video->getSource());
luax_pushtype(L, video->getSource());
else
lua_pushnil(L);
return 1;
@@ -62,7 +62,7 @@ int w_Video_setSource(lua_State *L)
video->setSource(nullptr);
else
{
auto source = luax_checktype<love::audio::Source>(L, 2, AUDIO_SOURCE_ID);
auto source = luax_checktype<love::audio::Source>(L, 2);
video->setSource(source);
}
return 0;
@@ -143,10 +143,10 @@ static const luaL_Reg functions[] =
int luaopen_video(lua_State *L)
{
int ret = luax_register_type(L, GRAPHICS_VIDEO_ID, "Video", functions, nullptr);
int ret = luax_register_type(L, &Video::type, functions, nullptr);
luaL_loadbuffer(L, video_lua, sizeof(video_lua), "Video.lua");
luax_gettypemetatable(L, GRAPHICS_VIDEO_ID);
luax_gettypemetatable(L, Video::type);
lua_call(L, 1, 0);
return ret;
+2 -2
View File
@@ -28,7 +28,7 @@ namespace graphics
Quad *luax_checkquad(lua_State *L, int idx)
{
return luax_checktype<Quad>(L, idx, GRAPHICS_QUAD_ID);
return luax_checktype<Quad>(L, idx);
}
int w_Quad_setViewport(lua_State *L)
@@ -84,7 +84,7 @@ static const luaL_Reg w_Quad_functions[] =
extern "C" int luaopen_quad(lua_State *L)
{
return luax_register_type(L, GRAPHICS_QUAD_ID, "Quad", w_Quad_functions, nullptr);
return luax_register_type(L, &Quad::type, w_Quad_functions, nullptr);
}
} // graphics
+2 -2
View File
@@ -27,7 +27,7 @@ namespace graphics
Texture *luax_checktexture(lua_State *L, int idx)
{
return luax_checktype<Texture>(L, idx, GRAPHICS_TEXTURE_ID);
return luax_checktype<Texture>(L, idx);
}
int w_Texture_getWidth(lua_State *L)
@@ -139,7 +139,7 @@ const luaL_Reg w_Texture_functions[] =
extern "C" int luaopen_texture(lua_State *L)
{
return luax_register_type(L, GRAPHICS_TEXTURE_ID, "Texture", w_Texture_functions, nullptr);
return luax_register_type(L, &Texture::type, w_Texture_functions, nullptr);
}
} // graphics
@@ -25,6 +25,8 @@ namespace love
namespace image
{
love::Type CompressedImageData::type("CompressedImageData", &Data::type);
CompressedImageData::CompressedImageData()
: format(PIXELFORMAT_UNKNOWN)
, sRGB(false)
+2
View File
@@ -44,6 +44,8 @@ class CompressedImageData : public Data
{
public:
static love::Type type;
// Compressed image data can have multiple mipmap levels, each represented
// by a sub-image.
struct SubImage
+32
View File
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2006-2016 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "Image.h"
namespace love
{
namespace image
{
love::Type Image::type("image", &Module::type);
} // image
} // love
+2
View File
@@ -44,6 +44,8 @@ class Image : public Module
{
public:
static love::Type type;
virtual ~Image() {}
// Implements Module.
+2
View File
@@ -27,6 +27,8 @@ namespace love
namespace image
{
love::Type ImageData::type("ImageData", &Data::type);
ImageData::ImageData()
: format(PIXELFORMAT_UNKNOWN)
, width(0)
+2
View File
@@ -59,6 +59,8 @@ class ImageData : public Data
{
public:
static love::Type type;
enum EncodedFormat
{
ENCODED_TGA,
@@ -28,7 +28,7 @@ namespace image
CompressedImageData *luax_checkcompressedimagedata(lua_State *L, int idx)
{
return luax_checktype<CompressedImageData>(L, idx, IMAGE_COMPRESSED_IMAGE_DATA_ID);
return luax_checktype<CompressedImageData>(L, idx);
}
int w_CompressedImageData_getWidth(lua_State *L)
@@ -106,7 +106,7 @@ static const luaL_Reg w_CompressedImageData_functions[] =
extern "C" int luaopen_compressedimagedata(lua_State *L)
{
return luax_register_type(L, IMAGE_COMPRESSED_IMAGE_DATA_ID, "CompressedImageData", w_Data_functions, w_CompressedImageData_functions, nullptr);
return luax_register_type(L, &CompressedImageData::type, w_Data_functions, w_CompressedImageData_functions, nullptr);
}
} // image
+4 -4
View File
@@ -73,7 +73,7 @@ int w_newImageData(lua_State *L)
memcpy(t->getData(), bytes, t->getSize());
}
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -87,7 +87,7 @@ int w_newImageData(lua_State *L)
[&](bool) { data->release(); }
);
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -107,7 +107,7 @@ int w_newCompressedData(lua_State *L)
[&](bool) { data->release(); }
);
luax_pushtype(L, IMAGE_COMPRESSED_IMAGE_DATA_ID, t);
luax_pushtype(L, CompressedImageData::type, t);
t->release();
return 1;
}
@@ -151,7 +151,7 @@ extern "C" int luaopen_love_image(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "image";
w.type = MODULE_IMAGE_ID;
w.type = &Image::type;
w.functions = functions;
w.types = types;
+4 -4
View File
@@ -40,7 +40,7 @@ namespace image
ImageData *luax_checkimagedata(lua_State *L, int idx)
{
return luax_checktype<ImageData>(L, idx, IMAGE_IMAGE_DATA_ID);
return luax_checktype<ImageData>(L, idx);
}
int w_ImageData_getFormat(lua_State *L)
@@ -269,7 +269,7 @@ int w_ImageData_encode(lua_State *L)
love::filesystem::FileData *filedata = nullptr;
luax_catchexcept(L, [&](){ filedata = t->encode(format, filename.c_str()); });
luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, filedata);
luax_pushtype(L, filedata);
filedata->release();
if (hasfilename)
@@ -363,9 +363,9 @@ extern "C" int luaopen_imagedata(lua_State *L)
pushFormats[PIXELFORMAT_RGBA16F] = luax_pushpixel_rgba16f;
pushFormats[PIXELFORMAT_RGBA32F] = luax_pushpixel_rgba32f;
int ret = luax_register_type(L, IMAGE_IMAGE_DATA_ID, "ImageData", w_Data_functions, w_ImageData_functions, nullptr);
int ret = luax_register_type(L, &ImageData::type, w_Data_functions, w_ImageData_functions, nullptr);
luax_gettypemetatable(L, IMAGE_IMAGE_DATA_ID);
luax_gettypemetatable(L, ImageData::type);
// Load and execute ImageData.lua, sending the metatable and the ffi
// functions struct pointer as arguments.
+2
View File
@@ -29,6 +29,8 @@ namespace love
namespace joystick
{
love::Type Joystick::type("Joystick", &Object::type);
float Joystick::clampval(float x)
{
if (fabsf(x) < 0.01)
+2
View File
@@ -38,6 +38,8 @@ class Joystick : public Object
{
public:
static love::Type type;
// Joystick hat values.
enum Hat
{
+2 -2
View File
@@ -31,7 +31,7 @@ namespace joystick
Joystick *luax_checkjoystick(lua_State *L, int idx)
{
return luax_checktype<Joystick>(L, idx, JOYSTICK_JOYSTICK_ID);
return luax_checktype<Joystick>(L, idx);
}
int w_Joystick_isConnected(lua_State *L)
@@ -296,7 +296,7 @@ static const luaL_Reg w_Joystick_functions[] =
extern "C" int luaopen_joystick(lua_State *L)
{
return luax_register_type(L, JOYSTICK_JOYSTICK_ID, "Joystick", w_Joystick_functions, nullptr);
return luax_register_type(L, &Joystick::type, w_Joystick_functions, nullptr);
}
} // joystick
+2 -2
View File
@@ -40,7 +40,7 @@ int w_getJoysticks(lua_State *L)
for (int i = 0; i < stickcount; i++)
{
Joystick *stick = instance()->getJoystick(i);
luax_pushtype(L, JOYSTICK_JOYSTICK_ID, stick);
luax_pushtype(L, stick);
lua_rawseti(L, -2, i + 1);
}
@@ -254,7 +254,7 @@ extern "C" int luaopen_love_joystick(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "joystick";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
+1 -1
View File
@@ -201,7 +201,7 @@ extern "C" int luaopen_love_keyboard(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "keyboard";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = 0;
+2
View File
@@ -83,6 +83,8 @@ namespace love
namespace math
{
love::Type BezierCurve::type("BezierCurve", &Object::type);
BezierCurve::BezierCurve(const vector<Vector> &pts)
: controlPoints(pts)
{
+2
View File
@@ -35,6 +35,8 @@ class BezierCurve : public Object
{
public:
static love::Type type;
/**
* @param controlPoints Control polygon of the curve.
**/
+2
View File
@@ -26,6 +26,8 @@ namespace love
namespace math
{
love::Type CompressedData::type("CompressedData", &Data::type);
CompressedData::CompressedData(Compressor::Format format, char *cdata, size_t compressedsize, size_t rawsize, bool own)
: format(format)
, data(nullptr)
+2
View File
@@ -37,6 +37,8 @@ class CompressedData : public love::Data
{
public:
static love::Type type;
/**
* Constructor just stores already-compressed data in the object.
**/
+2
View File
@@ -47,6 +47,8 @@ static uint64 wangHash64(uint64 key)
return key;
}
love::Type RandomGenerator::type("RandomGenerator", &Object::type);
// 64 bit Xorshift implementation taken from the end of Sec. 3 (page 4) in
// George Marsaglia, "Xorshift RNGs", Journal of Statistical Software, Vol.8 (Issue 14), 2003
// Use an 'Xorshift*' variant, as shown here: http://xorshift.di.unimi.it
+2
View File
@@ -41,6 +41,8 @@ class RandomGenerator : public Object
{
public:
static love::Type type;
union Seed
{
uint64 b64;
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace math
{
love::Type Transform::type("Transform", &Object::type);
Transform::Transform()
: matrix()
, inverseDirty(true)
+2
View File
@@ -34,6 +34,8 @@ class Transform : public Object
{
public:
static love::Type type;
Transform();
Transform(const Matrix4 &m);
Transform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
+4 -4
View File
@@ -30,7 +30,7 @@ namespace math
BezierCurve *luax_checkbeziercurve(lua_State *L, int idx)
{
return luax_checktype<BezierCurve>(L, idx, MATH_BEZIER_CURVE_ID);
return luax_checktype<BezierCurve>(L, idx);
}
int w_BezierCurve_getDegree(lua_State *L)
@@ -44,7 +44,7 @@ int w_BezierCurve_getDerivative(lua_State *L)
{
BezierCurve *curve = luax_checkbeziercurve(L, 1);
BezierCurve *deriv = new BezierCurve(curve->getDerivative());
luax_pushtype(L, MATH_BEZIER_CURVE_ID, deriv);
luax_pushtype(L, deriv);
deriv->release();
return 1;
}
@@ -165,7 +165,7 @@ int w_BezierCurve_getSegment(lua_State *L)
BezierCurve *segment;
luax_catchexcept(L, [&](){ segment = curve->getSegment(t1, t2); });
luax_pushtype(L, MATH_BEZIER_CURVE_ID, segment);
luax_pushtype(L, segment);
segment->release();
return 1;
@@ -234,7 +234,7 @@ static const luaL_Reg w_BezierCurve_functions[] =
extern "C" int luaopen_beziercurve(lua_State *L)
{
return luax_register_type(L, MATH_BEZIER_CURVE_ID, "BezierCurve", w_BezierCurve_functions, nullptr);
return luax_register_type(L, &BezierCurve::type, w_BezierCurve_functions, nullptr);
}
} // math
+2 -2
View File
@@ -29,7 +29,7 @@ namespace math
CompressedData *luax_checkcompresseddata(lua_State *L, int idx)
{
return luax_checktype<CompressedData>(L, idx, MATH_COMPRESSED_DATA_ID);
return luax_checktype<CompressedData>(L, idx);
}
int w_CompressedData_getFormat(lua_State *L)
@@ -53,7 +53,7 @@ static const luaL_Reg w_CompressedData_functions[] =
extern "C" int luaopen_compresseddata(lua_State *L)
{
return luax_register_type(L, MATH_COMPRESSED_DATA_ID, "CompressedData", w_Data_functions, w_CompressedData_functions, nullptr);
return luax_register_type(L, &CompressedData::type, w_Data_functions, w_CompressedData_functions, nullptr);
}
} // math
+15 -15
View File
@@ -45,7 +45,7 @@ namespace math
int w__getRandomGenerator(lua_State *L)
{
RandomGenerator *t = Math::instance.getRandomGenerator();
luax_pushtype(L, MATH_RANDOM_GENERATOR_ID, t);
luax_pushtype(L, t);
return 1;
}
@@ -76,7 +76,7 @@ int w_newRandomGenerator(lua_State *L)
return luaL_error(L, "%s", lua_tostring(L, -1));
}
luax_pushtype(L, MATH_RANDOM_GENERATOR_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -115,7 +115,7 @@ int w_newBezierCurve(lua_State *L)
}
BezierCurve *curve = Math::instance.newBezierCurve(points);
luax_pushtype(L, MATH_BEZIER_CURVE_ID, curve);
luax_pushtype(L, curve);
curve->release();
return 1;
}
@@ -140,7 +140,7 @@ int w_newTransform(lua_State *L)
t = Math::instance.newTransform(x, y, a, sx, sy, ox, oy, kx, ky);
}
luax_pushtype(L, MATH_TRANSFORM_ID, t);
luax_pushtype(L, t);
t->release();
return 1;
}
@@ -365,11 +365,11 @@ int w_compress(lua_State *L)
}
else
{
Data *rawdata = luax_checktype<Data>(L, 1, DATA_ID);
Data *rawdata = luax_checktype<Data>(L, 1);
luax_catchexcept(L, [&](){ cdata = compress(format, rawdata, level); });
}
luax_pushtype(L, MATH_COMPRESSED_DATA_ID, cdata);
luax_pushtype(L, cdata);
return 1;
}
@@ -378,7 +378,7 @@ int w_decompress(lua_State *L)
char *rawbytes = nullptr;
size_t rawsize = 0;
if (luax_istype(L, 1, MATH_COMPRESSED_DATA_ID))
if (luax_istype(L, 1, CompressedData::type))
{
CompressedData *data = luax_checkcompresseddata(L, 1);
rawsize = data->getDecompressedSize();
@@ -395,9 +395,9 @@ int w_decompress(lua_State *L)
size_t compressedsize = 0;
const char *cbytes = nullptr;
if (luax_istype(L, 1, DATA_ID))
if (luax_istype(L, 1, Data::type))
{
Data *data = luax_checktype<Data>(L, 1, DATA_ID);
Data *data = luax_checktype<Data>(L, 1);
cbytes = (const char *) data->getData();
compressedsize = data->getSize();
}
@@ -423,9 +423,9 @@ int w_encode(lua_State *L)
size_t srclen = 0;
const char *src = nullptr;
if (luax_istype(L, 2, DATA_ID))
if (luax_istype(L, 2, Data::type))
{
Data *data = luax_totype<Data>(L, 2, DATA_ID);
Data *data = luax_totype<Data>(L, 2);
src = (const char *) data->getData();
srclen = data->getSize();
}
@@ -457,9 +457,9 @@ int w_decode(lua_State *L)
size_t srclen = 0;
const char *src = nullptr;
if (luax_istype(L, 2, DATA_ID))
if (luax_istype(L, 2, Data::type))
{
Data *data = luax_totype<Data>(L, 2, DATA_ID);
Data *data = luax_totype<Data>(L, 2);
src = (const char *) data->getData();
srclen = data->getSize();
}
@@ -495,7 +495,7 @@ int w_hash(lua_State *L)
}
else
{
Data *rawdata = luax_checktype<Data>(L, 2, DATA_ID);
Data *rawdata = luax_checktype<Data>(L, 2);
luax_catchexcept(L, [&](){ hash = love::math::hash(function, rawdata); });
}
@@ -564,7 +564,7 @@ extern "C" int luaopen_love_math(lua_State *L)
WrappedModule w;
w.module = &Math::instance;
w.name = "math";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
+4 -4
View File
@@ -63,7 +63,7 @@ RandomGenerator::Seed luax_checkrandomseed(lua_State *L, int idx)
RandomGenerator *luax_checkrandomgenerator(lua_State *L, int idx)
{
return luax_checktype<RandomGenerator>(L, idx, MATH_RANDOM_GENERATOR_ID);
return luax_checktype<RandomGenerator>(L, idx);
}
int w_RandomGenerator__random(lua_State *L)
@@ -126,7 +126,7 @@ static FFI_RandomGenerator ffifuncs =
[](Proxy *p) -> double // random()
{
// FIXME: We need better type-checking...
if (p == nullptr || p->object == nullptr || !typeFlags[p->type][MATH_RANDOM_GENERATOR_ID])
if (p == nullptr || p->object == nullptr || p->type == nullptr || !p->type->isa(RandomGenerator::type))
return 0.0;
RandomGenerator *rng = (RandomGenerator *) p->object;
@@ -147,9 +147,9 @@ static const luaL_Reg w_RandomGenerator_functions[] =
extern "C" int luaopen_randomgenerator(lua_State *L)
{
int n = luax_register_type(L, MATH_RANDOM_GENERATOR_ID, "RandomGenerator", w_RandomGenerator_functions, nullptr);
int n = luax_register_type(L, &RandomGenerator::type, w_RandomGenerator_functions, nullptr);
luax_gettypemetatable(L, MATH_RANDOM_GENERATOR_ID);
luax_gettypemetatable(L, RandomGenerator::type);
// Load and execute wrap_RandomGenerator.lua, sending the metatable and the
// ffi functions struct pointer as arguments.
+5 -5
View File
@@ -27,14 +27,14 @@ namespace math
Transform *luax_checktransform(lua_State *L, int idx)
{
return luax_checktype<Transform>(L, idx, MATH_TRANSFORM_ID);
return luax_checktype<Transform>(L, idx, Transform::type);
}
int w_Transform_clone(lua_State *L)
{
Transform *t = luax_checktransform(L, 1);
Transform *newtransform = t->clone();
luax_pushtype(L, MATH_TRANSFORM_ID, newtransform);
luax_pushtype(L, newtransform);
newtransform->release();
return 1;
}
@@ -43,7 +43,7 @@ int w_Transform_inverse(lua_State *L)
{
Transform *t = luax_checktransform(L, 1);
Transform *inverse = t->inverse();
luax_pushtype(L, MATH_TRANSFORM_ID, inverse);
luax_pushtype(L, inverse);
inverse->release();
return 1;
}
@@ -274,7 +274,7 @@ int w_Transform__mul(lua_State *L)
Transform *t1 = luax_checktransform(L, 1);
Transform *t2 = luax_checktransform(L, 2);
Transform *t3 = new Transform(t1->getMatrix() * t2->getMatrix());
luax_pushtype(L, MATH_TRANSFORM_ID, t3);
luax_pushtype(L, t3);
t3->release();
return 1;
}
@@ -298,7 +298,7 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_transform(lua_State *L)
{
return luax_register_type(L, MATH_TRANSFORM_ID, "Transform", functions, nullptr);
return luax_register_type(L, &Transform::type, functions, nullptr);
}
} // math
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace mouse
{
love::Type Cursor::type("Cursor", &Object::type);
Cursor::~Cursor()
{
}
+2
View File
@@ -35,6 +35,8 @@ class Cursor : public Object
{
public:
static love::Type type;
// Types of system cursors.
enum SystemCursor
{
+2 -2
View File
@@ -28,7 +28,7 @@ namespace mouse
Cursor *luax_checkcursor(lua_State *L, int idx)
{
return luax_checktype<Cursor>(L, idx, MOUSE_CURSOR_ID);
return luax_checktype<Cursor>(L, idx);
}
int w_Cursor_getType(lua_State *L)
@@ -61,7 +61,7 @@ static const luaL_Reg w_Cursor_functions[] =
extern "C" int luaopen_cursor(lua_State *L)
{
return luax_register_type(L, MOUSE_CURSOR_ID, "Cursor", w_Cursor_functions, nullptr);
return luax_register_type(L, &Cursor::type, w_Cursor_functions, nullptr);
}
} // mouse
+7 -6
View File
@@ -24,6 +24,7 @@
#include "common/config.h"
#include "sdl/Mouse.h"
#include "filesystem/File.h"
namespace love
{
@@ -36,16 +37,16 @@ int w_newCursor(lua_State *L)
{
Cursor *cursor = nullptr;
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, "image", "newImageData");
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1);
int hotx = (int) luaL_optnumber(L, 2, 0);
int hoty = (int) luaL_optnumber(L, 3, 0);
luax_catchexcept(L, [&](){ cursor = instance()->newCursor(data, hotx, hoty); });
luax_pushtype(L, MOUSE_CURSOR_ID, cursor);
luax_pushtype(L, cursor);
cursor->release();
return 1;
}
@@ -61,7 +62,7 @@ int w_getSystemCursor(lua_State *L)
Cursor *cursor = 0;
luax_catchexcept(L, [&](){ cursor = instance()->getSystemCursor(systemCursor); });
luax_pushtype(L, MOUSE_CURSOR_ID, cursor);
luax_pushtype(L, cursor);
return 1;
}
@@ -84,7 +85,7 @@ int w_getCursor(lua_State *L)
Cursor *cursor = instance()->getCursor();
if (cursor)
luax_pushtype(L, MOUSE_CURSOR_ID, cursor);
luax_pushtype(L, cursor);
else
lua_pushnil(L);
@@ -250,7 +251,7 @@ extern "C" int luaopen_love_mouse(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "mouse";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
+2
View File
@@ -25,6 +25,8 @@ namespace love
namespace physics
{
love::Type Body::type("Body", &Object::type);
Body::~Body()
{
}
+2
View File
@@ -34,6 +34,8 @@ class Body : public Object
{
public:
static love::Type type;
enum Type
{
BODY_INVALID,

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