Rework internal module registration to happen in constructors.

This commit is contained in:
Sasha Szpakowski
2024-02-24 15:21:38 -04:00
parent c7e4dafd88
commit 1e97e09b28
73 changed files with 154 additions and 248 deletions
+4 -1
View File
@@ -62,9 +62,12 @@ namespace love
love::Type Module::type("Module", &Object::type);
Module *Module::instances[] = {};
Module::Module()
Module::Module(Module::ModuleType moduleType, const char *name)
: moduleType(moduleType)
, name(name)
{
initDeprecation();
registerInstance(this);
}
Module::~Module()
+8 -10
View File
@@ -62,13 +62,13 @@ public:
M_MAX_ENUM
};
Module();
Module(ModuleType moduleType, const char *name);
virtual ~Module();
/**
* Gets the base type of the module.
**/
virtual ModuleType getModuleType() const = 0;
ModuleType getModuleType() const { return moduleType; }
/**
* Gets the name of the module. This is used in case of errors
@@ -76,14 +76,7 @@ public:
*
* @return The full name of the module, eg. love.graphics.opengl.
**/
virtual const char *getName() const = 0;
/**
* Add module to internal registry. To be used /only/ in
* runtime.cpp:luax_register_module()
* @param instance The module instance.
*/
static void registerInstance(Module *instance);
const char *getName() const { return name.c_str(); }
/**
* Retrieve module instance from internal registry. May return NULL
@@ -106,6 +99,11 @@ public:
private:
static void registerInstance(Module *instance);
ModuleType moduleType;
std::string name;
static Module *instances[M_MAX_ENUM];
}; // Module
-3
View File
@@ -473,9 +473,6 @@ int luax_register_module(lua_State *L, const WrappedModule &m)
lua_setfield(L, -3, m.name); // love.graphics = table
lua_remove(L, -2); // love
// Register module instance
Module::registerInstance(m.module);
return 1;
}
+4
View File
@@ -68,6 +68,10 @@ void showRecordingPermissionMissingDialog()
#endif
}
Audio::Audio(const char *name)
: Module(M_AUDIO, name)
{}
bool Audio::setMixWithSystem(bool mix)
{
#ifdef LOVE_IOS
+4 -3
View File
@@ -101,9 +101,6 @@ public:
virtual ~Audio() {}
// Implements Module.
virtual ModuleType getModuleType() const { return M_AUDIO; }
virtual Source *newSource(love::sound::Decoder *decoder) = 0;
virtual Source *newSource(love::sound::SoundData *soundData) = 0;
virtual Source *newSource(int sampleRate, int bitDepth, int channels, int buffers) = 0;
@@ -312,6 +309,10 @@ public:
*/
virtual void setPlaybackDevice(const char *name);
protected:
Audio(const char *name);
private:
static StringMap<DistanceModel, DISTANCE_MAX_ENUM>::Entry distanceModelEntries[];
+2 -6
View File
@@ -28,7 +28,8 @@ namespace null
{
Audio::Audio()
: distanceModel(DISTANCE_NONE)
: love::audio::Audio("love.audio.null")
, distanceModel(DISTANCE_NONE)
{
}
@@ -36,11 +37,6 @@ Audio::~Audio()
{
}
const char *Audio::getName() const
{
return "love.audio.null";
}
love::audio::Source *Audio::newSource(love::sound::Decoder *)
{
return new Source();
-3
View File
@@ -41,9 +41,6 @@ public:
Audio();
virtual ~Audio();
// Implements Module.
const char *getName() const;
// Implements Audio.
love::audio::Source *newSource(love::sound::Decoder *decoder);
love::audio::Source *newSource(love::sound::SoundData *soundData);
+2 -6
View File
@@ -106,7 +106,8 @@ static const char *getDeviceSpecifier(ALCdevice *device)
}
Audio::Audio()
: device(nullptr)
: love::audio::Audio("love.audio.openal")
, device(nullptr)
, context(nullptr)
, pool(nullptr)
, poolThread(nullptr)
@@ -256,11 +257,6 @@ Audio::~Audio()
alcCloseDevice(device);
}
const char *Audio::getName() const
{
return "love.audio.openal";
}
love::audio::Source *Audio::newSource(love::sound::Decoder *decoder)
{
return new Source(pool, decoder);
-3
View File
@@ -78,9 +78,6 @@ public:
**/
static ALenum getFormat(int bitDepth, int channels);
// Implements Module.
const char *getName() const;
// Implements Audio.
love::audio::Source *newSource(love::sound::Decoder *decoder);
love::audio::Source *newSource(love::sound::SoundData *soundData);
+1
View File
@@ -214,6 +214,7 @@ void hash(HashFunction::Function function, const char *input, uint64_t size, Has
}
DataModule::DataModule()
: Module(M_DATA, "love.data")
{
}
-4
View File
@@ -117,10 +117,6 @@ public:
DataModule();
virtual ~DataModule();
// Implements Module.
ModuleType getModuleType() const override { return M_DATA; }
const char *getName() const override { return "love.data"; }
DataView *newDataView(Data *data, size_t offset, size_t size);
ByteData *newByteData(size_t size);
ByteData *newByteData(const void *d, size_t size);
+5
View File
@@ -38,6 +38,11 @@ Message::~Message()
{
}
Event::Event(const char *name)
: Module(M_EVENT, name)
{
}
Event::~Event()
{
}
+4 -3
View File
@@ -54,10 +54,8 @@ public:
class Event : public Module
{
public:
virtual ~Event();
// Implements Module.
virtual ModuleType getModuleType() const { return M_EVENT; }
virtual ~Event();
void push(Message *msg);
bool poll(Message *&msg);
@@ -67,6 +65,9 @@ public:
virtual Message *wait() = 0;
protected:
Event(const char *name);
love::thread::MutexRef mutex;
std::queue<Message *> queue;
+1 -5
View File
@@ -105,12 +105,8 @@ static int SDLCALL watchAppEvents(void * /*udata*/, SDL_Event *event)
return 1;
}
const char *Event::getName() const
{
return "love.event.sdl";
}
Event::Event()
: love::event::Event("love.event.sdl")
{
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0)
throw love::Exception("Could not initialize SDL events subsystem (%s)", SDL_GetError());
-3
View File
@@ -42,9 +42,6 @@ class Event : public love::event::Event
{
public:
// Implements Module.
const char *getName() const;
Event();
virtual ~Event();
+2 -1
View File
@@ -45,7 +45,8 @@ namespace filesystem
love::Type Filesystem::type("filesystem", &Module::type);
Filesystem::Filesystem()
Filesystem::Filesystem(const char *name)
: Module(M_FILESYSTEM, name)
{
}
+4 -4
View File
@@ -108,12 +108,8 @@ public:
static love::Type type;
Filesystem();
virtual ~Filesystem();
// Implements Module.
virtual ModuleType getModuleType() const { return M_FILESYSTEM; }
virtual void init(const char *arg0) = 0;
virtual void setFused(bool fused) = 0;
@@ -317,6 +313,10 @@ public:
STRINGMAP_CLASS_DECLARE(MountPermissions);
STRINGMAP_CLASS_DECLARE(LoadMode);
protected:
Filesystem(const char *name);
private:
bool getRealPathType(const std::string &path, FileType &ftype) const;
+2 -6
View File
@@ -107,7 +107,8 @@ static bool isAppCommonPath(Filesystem::CommonPath path)
}
Filesystem::Filesystem()
: appendIdentityToPath(false)
: love::filesystem::Filesystem("love.filesystem.physfs")
, appendIdentityToPath(false)
, fused(false)
, fusedSet(false)
, fullPaths()
@@ -128,11 +129,6 @@ Filesystem::~Filesystem()
PHYSFS_deinit();
}
const char *Filesystem::getName() const
{
return "love.filesystem.physfs";
}
void Filesystem::init(const char *arg0)
{
#ifdef LOVE_ANDROID
@@ -43,9 +43,6 @@ public:
Filesystem();
virtual ~Filesystem();
// Implements Module.
const char *getName() const override;
void init(const char *arg0) override;
void setFused(bool fused) override;
+2 -1
View File
@@ -34,7 +34,8 @@ namespace font
// Default TrueType font, gzip-compressed.
#include "NotoSans-Regular.ttf.gzip.h"
Font::Font()
Font::Font(const char *name)
: Module(M_FONT, name)
{
auto compressedbytes = (const char *) NotoSans_Regular_ttf_gzip;
size_t compressedsize = NotoSans_Regular_ttf_gzip_len;
+3 -4
View File
@@ -43,7 +43,6 @@ class Font : public Module
public:
Font();
virtual ~Font() {}
virtual Rasterizer *newRasterizer(love::filesystem::FileData *data) = 0;
@@ -58,9 +57,9 @@ public:
virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph);
virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph);
// Implement Module.
virtual ModuleType getModuleType() const { return M_FONT; }
virtual const char *getName() const = 0;
protected:
Font(const char *name);
private:
+1 -5
View File
@@ -36,6 +36,7 @@ namespace freetype
{
Font::Font()
: love::font::Font("love.font.freetype")
{
if (FT_Init_FreeType(&library))
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed");
@@ -66,11 +67,6 @@ Rasterizer *Font::newTrueTypeRasterizer(love::Data *data, int size, const font::
return new TrueTypeRasterizer(library, data, size, settings, defaultdpiscale);
}
const char *Font::getName() const
{
return "love.font.freetype";
}
} // freetype
} // font
} // love
-3
View File
@@ -47,9 +47,6 @@ public:
Rasterizer *newRasterizer(love::filesystem::FileData *data) override;
Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, const font::TrueTypeRasterizer::Settings &settings) override;
// Implement Module
const char *getName() const override;
private:
// FreeType library
+3 -2
View File
@@ -180,8 +180,9 @@ Graphics::DisplayState::DisplayState()
defaultSamplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_LINEAR;
}
Graphics::Graphics()
: width(0)
Graphics::Graphics(const char *name)
: Module(M_GRAPHICS, name)
, width(0)
, height(0)
, pixelWidth(0)
, pixelHeight(0)
+1 -4
View File
@@ -451,12 +451,9 @@ public:
}
};
Graphics();
Graphics(const char *name);
virtual ~Graphics();
// Implements Module.
virtual ModuleType getModuleType() const { return M_GRAPHICS; }
virtual Texture *newTexture(const Texture::Settings &settings, const Texture::Slices *data = nullptr) = 0;
Quad *newQuad(Quad::Viewport v, double sw, double sh);
-3
View File
@@ -60,9 +60,6 @@ public:
Graphics();
virtual ~Graphics();
// Implements Module.
const char *getName() const override { return "love.graphics.metal"; }
love::graphics::Texture *newTexture(const Texture::Settings &settings, const Texture::Slices *data = nullptr) override;
love::graphics::Buffer *newBuffer(const Buffer::Settings &settings, const std::vector<Buffer::DataDeclaration> &format, const void *data, size_t size, size_t arraylength) override;
+2 -1
View File
@@ -263,7 +263,8 @@ struct DefaultVertexAttributes
Graphics *Graphics::graphicsInstance = nullptr;
Graphics::Graphics()
: device(nil)
: love::graphics::Graphics("love.graphics.metal")
, device(nil)
, commandQueue(nil)
, commandBuffer(nil)
, renderEncoder(nil)
+2 -6
View File
@@ -106,7 +106,8 @@ love::graphics::Graphics *createInstance()
}
Graphics::Graphics()
: windowHasStencil(false)
: love::graphics::Graphics("love.graphics.opengl")
, windowHasStencil(false)
, mainVAO(0)
, internalBackbufferFBO(0)
, requestedBackbufferMSAA(0)
@@ -147,11 +148,6 @@ Graphics::~Graphics()
delete[] bufferMapMemory;
}
const char *Graphics::getName() const
{
return "love.graphics.opengl";
}
love::graphics::StreamBuffer *Graphics::newStreamBuffer(BufferUsage type, size_t size)
{
return CreateStreamBuffer(type, size);
-3
View File
@@ -56,9 +56,6 @@ public:
Graphics();
virtual ~Graphics();
// Implements Module.
const char *getName() const override;
love::graphics::Texture *newTexture(const Texture::Settings &settings, const Texture::Slices *data = nullptr) override;
love::graphics::Buffer *newBuffer(const Buffer::Settings &settings, const std::vector<Buffer::DataDeclaration> &format, const void *data, size_t size, size_t arraylength) override;
+1 -5
View File
@@ -60,11 +60,6 @@ static const std::vector<const char*> deviceExtensions = {
constexpr uint32_t USAGES_POLL_INTERVAL = 5000;
const char *Graphics::getName() const
{
return "love.graphics.vulkan";
}
VkDevice Graphics::getDevice() const
{
return device;
@@ -95,6 +90,7 @@ static void checkOptionalInstanceExtensions(OptionalInstanceExtensions& ext)
}
Graphics::Graphics()
: love::graphics::Graphics("love.graphics.vulkan")
{
if (SDL_Vulkan_LoadLibrary(nullptr))
throw love::Exception("could not find vulkan");
-1
View File
@@ -274,7 +274,6 @@ public:
~Graphics();
// implementation for virtual functions
const char *getName() const override;
love::graphics::Texture *newTexture(const love::graphics::Texture::Settings &settings, const love::graphics::Texture::Slices *data) override;
love::graphics::Buffer *newBuffer(const love::graphics::Buffer::Settings &settings, const std::vector<love::graphics::Buffer::DataDeclaration>& format, const void *data, size_t size, size_t arraylength) override;
graphics::GraphicsReadback *newReadbackInternal(ReadbackMethod method, love::graphics::Buffer *buffer, size_t offset, size_t size, data::ByteData *dest, size_t destoffset) override;
+1 -5
View File
@@ -40,6 +40,7 @@ namespace image
love::Type Image::type("image", &Module::type);
Image::Image()
: Module(M_IMAGE, "love.image.magpie")
{
using namespace magpie;
@@ -65,11 +66,6 @@ Image::~Image()
handler->release();
}
const char *Image::getName() const
{
return "love.image.magpie";
}
love::image::ImageData *Image::newImageData(Data *data)
{
return new ImageData(data);
-4
View File
@@ -52,10 +52,6 @@ public:
Image();
virtual ~Image();
// Implements Module.
ModuleType getModuleType() const override { return M_IMAGE; }
const char *getName() const override;
/**
* Creates new ImageData from FileData.
* @param data The FileData containing the encoded image data.
+6 -3
View File
@@ -36,9 +36,6 @@ public:
virtual ~JoystickModule() {}
// Implements Module.
ModuleType getModuleType() const override { return M_JOYSTICK; }
/**
* Adds a connected Joystick device and opens it for use.
* Returns NULL if the Joystick could not be added.
@@ -101,6 +98,12 @@ public:
**/
virtual std::string getGamepadMappingString(const std::string &guid) const = 0;
protected:
JoystickModule(const char *name)
: Module(M_JOYSTICK, name)
{}
}; // JoystickModule
} // joystick
+1 -5
View File
@@ -40,6 +40,7 @@ namespace sdl
{
JoystickModule::JoystickModule()
: love::joystick::JoystickModule("love.joystick.sdl")
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0)
throw love::Exception("Could not initialize SDL joystick subsystem (%s)", SDL_GetError());
@@ -69,11 +70,6 @@ JoystickModule::~JoystickModule()
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
}
const char *JoystickModule::getName() const
{
return "love.joystick.sdl";
}
love::joystick::Joystick *JoystickModule::getJoystick(int joyindex)
{
if (joyindex < 0 || (size_t) joyindex >= activeSticks.size())
@@ -44,9 +44,6 @@ public:
JoystickModule();
virtual ~JoystickModule();
// Implements Module.
const char *getName() const override;
// Implements JoystickModule.
love::joystick::Joystick *addJoystick(int deviceindex) override;
void removeJoystick(love::joystick::Joystick *joystick) override;
+5
View File
@@ -27,6 +27,11 @@ namespace love
namespace keyboard
{
Keyboard::Keyboard(const char *name)
: Module(M_KEYBOARD, name)
{
}
bool Keyboard::getConstant(const char *in, Key &out)
{
return keys.find(in, out);
+4 -3
View File
@@ -533,9 +533,6 @@ public:
virtual ~Keyboard() {}
// Implements Module.
virtual ModuleType getModuleType() const { return M_KEYBOARD; }
/**
* Sets whether repeat keypress events should be sent if a key is held down.
* Does not affect text input events.
@@ -614,6 +611,10 @@ public:
static bool getConstant(const char *in, ModifierKey &out);
static bool getConstant(ModifierKey in, const char *&out);
protected:
Keyboard(const char *name);
private:
static StringMap<Key, KEY_MAX_ENUM>::Entry keyEntries[];
+2 -6
View File
@@ -36,15 +36,11 @@ namespace sdl
{
Keyboard::Keyboard()
: key_repeat(false)
: love::keyboard::Keyboard("love.keyboard.sdl")
, key_repeat(false)
{
}
const char *Keyboard::getName() const
{
return "love.keyboard.sdl";
}
void Keyboard::setKeyRepeat(bool enable)
{
key_repeat = enable;
-3
View File
@@ -41,9 +41,6 @@ public:
Keyboard();
// Implements Module.
const char *getName() const;
void setKeyRepeat(bool enable);
bool hasKeyRepeat() const;
bool isDown(const std::vector<Key> &keylist) const;
+2 -1
View File
@@ -200,7 +200,8 @@ float linearToGamma(float c)
}
Math::Math()
: rng()
: Module(M_MATH, "love.math")
, rng()
{
RandomGenerator::Seed seed;
seed.b64 = (uint64) time(nullptr);
-11
View File
@@ -118,17 +118,6 @@ public:
Transform *newTransform();
Transform *newTransform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
// Implements Module.
virtual ModuleType getModuleType() const
{
return M_MATH;
}
virtual const char *getName() const
{
return "love.math";
}
private:
RandomGenerator rng;
+6
View File
@@ -64,6 +64,12 @@ public:
virtual bool setRelativeMode(bool relative) = 0;
virtual bool getRelativeMode() const = 0;
protected:
Mouse(const char *name)
: Module(M_MOUSE, name)
{}
}; // Mouse
} // mouse
+2 -6
View File
@@ -56,13 +56,9 @@ static void clampToWindow(double *x, double *y)
window->clampPositionInWindow(x, y);
}
const char *Mouse::getName() const
{
return "love.mouse.sdl";
}
Mouse::Mouse()
: curCursor(nullptr)
: love::mouse::Mouse("love.mouse.sdl")
, curCursor(nullptr)
{
// SDL may need the video subsystem in order to clean up the cursor when
// quitting. Subsystems are reference-counted.
-3
View File
@@ -39,9 +39,6 @@ class Mouse : public love::mouse::Mouse
{
public:
// Implements Module.
const char *getName() const override;
Mouse();
virtual ~Mouse();
+2 -6
View File
@@ -35,7 +35,8 @@ namespace box2d
float Physics::meter = Physics::DEFAULT_METER;
Physics::Physics()
: blockAllocator()
: Module(M_PHYSICS, "love.physics.box2d")
, blockAllocator()
{
meter = DEFAULT_METER;
}
@@ -44,11 +45,6 @@ Physics::~Physics()
{
}
const char *Physics::getName() const
{
return "love.physics.box2d";
}
World *Physics::newWorld(float gx, float gy, bool sleep)
{
return new World(b2Vec2(gx, gy), sleep);
-4
View File
@@ -65,10 +65,6 @@ public:
Physics();
virtual ~Physics();
// Implements Module.
const char *getName() const;
virtual ModuleType getModuleType() const { return M_PHYSICS; }
/**
* Creates a new World.
* @param gx Gravity along x-axis.
+5
View File
@@ -26,6 +26,11 @@ namespace love
namespace sensor
{
Sensor::Sensor(const char *name)
: Module(M_SENSOR, name)
{
}
STRINGMAP_CLASS_BEGIN(Sensor, Sensor::SensorType, Sensor::SENSOR_MAX_ENUM, sensorType)
{
{ "accelerometer", Sensor::SENSOR_ACCELEROMETER },
+4 -3
View File
@@ -43,9 +43,6 @@ public:
virtual ~Sensor() {}
// Implements Module.
ModuleType getModuleType() const override { return M_SENSOR; }
/**
* Check the availability of the sensor.
**/
@@ -75,6 +72,10 @@ public:
STRINGMAP_CLASS_DECLARE(SensorType);
protected:
Sensor(const char *name);
}; // Sensor
} // sensor
+2 -6
View File
@@ -33,7 +33,8 @@ namespace sdl
{
Sensor::Sensor()
: sensors()
: love::sensor::Sensor("love.sensor.sdl")
, sensors()
{
if (SDL_InitSubSystem(SDL_INIT_SENSOR) < 0)
throw love::Exception("Could not initialize SDL sensor subsystem (%s)", SDL_GetError());
@@ -44,11 +45,6 @@ Sensor::~Sensor()
SDL_QuitSubSystem(SDL_INIT_SENSOR);
}
const char *Sensor::getName() const
{
return "love.sensor.sdl";
}
bool Sensor::hasSensor(SensorType type)
{
for (int i = 0; i < SDL_NumSensors(); i++)
-3
View File
@@ -43,9 +43,6 @@ public:
Sensor();
~Sensor() override;
// Implements Module.
const char *getName() const override;
bool hasSensor(SensorType type) override;
bool isEnabled(SensorType type) override;
void setEnabled(SensorType type, bool enable) override;
+5
View File
@@ -27,6 +27,11 @@ namespace sound
love::Type Sound::type("Sound", &Module::type);
Sound::Sound(const char *name)
: Module(M_SOUND, name)
{
}
Sound::~Sound()
{
}
+4 -3
View File
@@ -46,9 +46,6 @@ public:
virtual ~Sound();
// Implements Module.
virtual ModuleType getModuleType() const { return M_SOUND; }
/**
* Creates new SoundData from a decoder. Fully expands the
* encoded sound data into raw sound data. Not recommended
@@ -89,6 +86,10 @@ public:
**/
virtual Decoder *newDecoder(Stream *stream, int bufferSize) = 0;
protected:
Sound(const char *name);
}; // Sound
} // sound
+1 -5
View File
@@ -59,6 +59,7 @@ namespace lullaby
{
Sound::Sound()
: love::sound::Sound("love.sound.lullaby")
{
}
@@ -66,11 +67,6 @@ Sound::~Sound()
{
}
const char *Sound::getName() const
{
return "love.sound.lullaby";
}
sound::Decoder *Sound::newDecoder(Stream *stream, int bufferSize)
{
std::vector<DecoderImpl> possibleDecoders = {
-3
View File
@@ -48,9 +48,6 @@ public:
Sound();
virtual ~Sound();
/// @copydoc love::Module::getName
const char *getName() const override;
/// @copydoc love::sound::Sound::newDecoder
sound::Decoder *newDecoder(Stream *stream, int bufferSize) override;
+2 -1
View File
@@ -58,7 +58,8 @@ namespace love
namespace system
{
System::System()
System::System(const char *name)
: Module(M_SYSTEM, name)
{
}
+1 -4
View File
@@ -48,12 +48,9 @@ public:
POWER_MAX_ENUM
};
System();
System(const char *name);
virtual ~System() {}
// Implements Module.
virtual ModuleType getModuleType() const { return M_SYSTEM; }
/**
* Gets the current operating system.
**/
+1 -5
View File
@@ -39,14 +39,10 @@ namespace sdl
{
System::System()
: love::system::System("love.system.sdl")
{
}
const char *System::getName() const
{
return "love.system.sdl";
}
int System::getProcessorCount() const
{
return SDL_GetCPUCount();
-3
View File
@@ -42,9 +42,6 @@ public:
System();
virtual ~System() {}
// Implements Module.
const char *getName() const override;
int getProcessorCount() const override;
void setClipboardText(const std::string &text) const override;
+5 -5
View File
@@ -25,6 +25,11 @@ namespace love
namespace thread
{
ThreadModule::ThreadModule()
: love::Module(M_THREAD, "love.thread.sdl")
{
}
LuaThread *ThreadModule::newThread(const std::string &name, love::Data *data)
{
return new LuaThread(name, data);
@@ -48,10 +53,5 @@ Channel *ThreadModule::getChannel(const std::string &name)
return c;
}
const char *ThreadModule::getName() const
{
return "love.thread.sdl";
}
} // thread
} // love
+1 -4
View File
@@ -43,15 +43,12 @@ class ThreadModule : public love::Module
{
public:
ThreadModule();
virtual ~ThreadModule() {}
virtual LuaThread *newThread(const std::string &name, love::Data *data);
virtual Channel *newChannel();
virtual Channel *getChannel(const std::string &name);
// Implements Module.
virtual const char *getName() const;
virtual ModuleType getModuleType() const { return M_THREAD; }
private:
std::map<std::string, StrongRef<Channel>> namedChannels;
+2 -1
View File
@@ -43,7 +43,8 @@ namespace timer
{
Timer::Timer()
: currTime(0)
: Module(M_TIMER, "love.timer")
, currTime(0)
, prevFpsUpdate(0)
, fps(0)
, averageDelta(0)
-4
View File
@@ -36,10 +36,6 @@ public:
Timer();
virtual ~Timer() {}
// Implements Module.
ModuleType getModuleType() const override { return M_TIMER; }
const char *getName() const override { return "love.timer"; }
/**
* Measures the time between this call and the previous call,
* and updates internal values accordingly.
+6 -3
View File
@@ -51,9 +51,6 @@ public:
virtual ~Touch() {}
// Implements Module.
virtual ModuleType getModuleType() const { return M_TOUCH; }
/**
* Gets all currently active touches.
**/
@@ -64,6 +61,12 @@ public:
**/
virtual const TouchInfo &getTouch(int64 id) const = 0;
protected:
Touch(const char *name)
: Module(M_TOUCH, name)
{}
}; // Touch
} // touch
+5 -5
View File
@@ -33,6 +33,11 @@ namespace touch
namespace sdl
{
Touch::Touch()
: love::touch::Touch("love.touch.sdl")
{
}
const std::vector<Touch::TouchInfo> &Touch::getTouches() const
{
return touches;
@@ -49,11 +54,6 @@ const Touch::TouchInfo &Touch::getTouch(int64 id) const
throw love::Exception("Invalid active touch ID: %d", id);
}
const char *Touch::getName() const
{
return "love.touch.sdl";
}
void Touch::onEvent(Uint32 eventtype, const TouchInfo &info)
{
auto compare = [&](const TouchInfo &touch) -> bool
+1 -3
View File
@@ -38,14 +38,12 @@ class Touch : public love::touch::Touch
{
public:
Touch();
virtual ~Touch() {}
const std::vector<TouchInfo> &getTouches() const override;
const TouchInfo &getTouch(int64 id) const override;
// Implements Module.
const char *getName() const override;
// SDL has functions to query the state of touch presses, but unfortunately
// they are updated on a different thread in some backends, which causes
// issues especially if the user is iterating through the current touches
+8 -3
View File
@@ -35,15 +35,20 @@ namespace video
class Video : public Module
{
public:
virtual ~Video() {}
// Implements Module
virtual ModuleType getModuleType() const { return M_VIDEO; }
virtual ~Video() {}
/**
* Create a VideoStream representing video frames
**/
virtual VideoStream *newVideoStream(love::filesystem::File *file) = 0;
protected:
Video(const char *name)
: Module(M_VIDEO, name)
{}
}; // Video
} // video
+1 -5
View File
@@ -34,6 +34,7 @@ namespace theora
{
Video::Video()
: love::video::Video("love.video.theora")
{
workerThread = new Worker();
workerThread->start();
@@ -51,11 +52,6 @@ VideoStream *Video::newVideoStream(love::filesystem::File *file)
return stream;
}
const char *Video::getName() const
{
return "love.video.theora";
}
Worker::Worker()
: stopping(false)
{
-3
View File
@@ -46,9 +46,6 @@ public:
Video();
virtual ~Video();
// Implements Module
virtual const char *getName() const;
VideoStream *newVideoStream(love::filesystem::File* file);
private:
+5
View File
@@ -43,6 +43,11 @@ bool isHighDPIAllowed()
return highDPIAllowed;
}
Window::Window(const char *name)
: Module(M_WINDOW, name)
{
}
Window::~Window()
{
}
+4 -3
View File
@@ -131,9 +131,6 @@ public:
virtual ~Window();
// Implements Module.
virtual ModuleType getModuleType() const { return M_WINDOW; }
virtual void setGraphics(graphics::Graphics *graphics) = 0;
virtual bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr) = 0;
@@ -239,6 +236,10 @@ public:
static bool getConstant(DisplayOrientation in, const char *&out);
static std::vector<std::string> getConstants(DisplayOrientation);
protected:
Window(const char *name);
private:
static StringMap<Setting, SETTING_MAX_ENUM>::Entry settingEntries[];
+2 -6
View File
@@ -88,7 +88,8 @@ namespace sdl
{
Window::Window()
: open(false)
: love::window::Window("love.window.sdl")
, open(false)
, mouseGrabbed(false)
, window(nullptr)
, glcontext(nullptr)
@@ -1503,11 +1504,6 @@ void Window::requestAttention(bool continuous)
// TODO: Linux?
}
const char *Window::getName() const
{
return "love.window.sdl";
}
} // sdl
} // window
} // love
-2
View File
@@ -130,8 +130,6 @@ public:
void requestAttention(bool continuous) override;
const char *getName() const override;
private:
struct ContextAttribs