mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Slightly reduced internal reliance on specific module backends
This commit is contained in:
+15
-2
@@ -54,9 +54,9 @@ void Module::registerInstance(Module *instance)
|
||||
registry.insert(make_pair(name, instance));
|
||||
}
|
||||
|
||||
Module *Module::getInstance(const char *name)
|
||||
Module *Module::getInstance(const std::string &name)
|
||||
{
|
||||
std::map<std::string, Module*>::iterator it = registry.find(std::string(name));
|
||||
std::map<std::string, Module*>::const_iterator it = registry.find(name);
|
||||
|
||||
if (registry.end() == it)
|
||||
return NULL;
|
||||
@@ -64,4 +64,17 @@ Module *Module::getInstance(const char *name)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Module *Module::findInstance(const std::string &name)
|
||||
{
|
||||
std::map<std::string, Module*>::const_iterator it;
|
||||
|
||||
for (it = registry.begin(); it != registry.end(); ++it)
|
||||
{
|
||||
if (it->first.find(name) == 0)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // love
|
||||
|
||||
+11
-2
@@ -59,9 +59,18 @@ public:
|
||||
* Retrieve module instance from internal registry. May return NULL
|
||||
* if module not registered.
|
||||
* @param name The full name of the module.
|
||||
* @returns Module instance of NULL if the module is not registered.
|
||||
* @return Module instance or NULL if the module is not registered.
|
||||
*/
|
||||
static Module *getInstance(const char *name);
|
||||
static Module *getInstance(const std::string &name);
|
||||
|
||||
/**
|
||||
* Find the first module instance from the internal registry whose name
|
||||
* starts with the supplied name. May return NULL if module is not
|
||||
* registered or the supplied name is not part of any module name.
|
||||
* @param name The partial name of the module.
|
||||
* @return Module instance or NULL if the module is not registered.
|
||||
**/
|
||||
static Module *findInstance(const std::string &name);
|
||||
|
||||
}; // Module
|
||||
|
||||
|
||||
@@ -106,8 +106,7 @@ void LuaThread::onError()
|
||||
if (error.empty())
|
||||
return;
|
||||
|
||||
// FIXME: We shouldn't specify any particular Event module implementation.
|
||||
event::Event *event = (event::Event *) Module::getInstance("love.event.sdl");
|
||||
event::Event *event = (event::Event *) Module::findInstance("love.event.");
|
||||
if (!event)
|
||||
return;
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
// LOVE
|
||||
#include "common/Module.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -56,7 +55,7 @@ public:
|
||||
|
||||
virtual ~Window();
|
||||
|
||||
virtual bool setWindow(int width = 800, int height = 600, graphics::Graphics *graphics = 0, WindowFlags *flags = 0) = 0;
|
||||
virtual bool setWindow(int width = 800, int height = 600, WindowFlags *flags = 0) = 0;
|
||||
virtual void getWindow(int &width, int &height, WindowFlags &flags) const = 0;
|
||||
|
||||
virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "graphics/Graphics.h"
|
||||
#include "Window.h"
|
||||
|
||||
// SDL
|
||||
@@ -59,10 +60,11 @@ Window::_currentMode::_currentMode()
|
||||
{
|
||||
}
|
||||
|
||||
bool Window::setWindow(int width, int height, graphics::Graphics *graphics, WindowFlags *flags)
|
||||
bool Window::setWindow(int width, int height, WindowFlags *flags)
|
||||
{
|
||||
if (graphics)
|
||||
graphics->unSetMode();
|
||||
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
|
||||
if (gfx)
|
||||
gfx->unSetMode();
|
||||
|
||||
bool fullscreen = false;
|
||||
bool vsync = true;
|
||||
@@ -191,8 +193,8 @@ bool Window::setWindow(int width, int height, graphics::Graphics *graphics, Wind
|
||||
currentMode.flags.borderless = ((surface->flags & SDL_NOFRAME) != 0);
|
||||
currentMode.flags.centered = centered;
|
||||
|
||||
if (graphics)
|
||||
graphics->setMode(width, height);
|
||||
if (gfx)
|
||||
gfx->setMode(width, height);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
Window();
|
||||
~Window();
|
||||
|
||||
bool setWindow(int width = 800, int height = 600, graphics::Graphics *graphics = 0, WindowFlags *flags = 0);
|
||||
bool setWindow(int width = 800, int height = 600, WindowFlags *flags = 0);
|
||||
void getWindow(int &width, int &height, WindowFlags &flags) const;
|
||||
|
||||
bool checkWindowSize(int width, int height, bool fullscreen) const;
|
||||
|
||||
@@ -42,11 +42,9 @@ int w_setMode(lua_State *L)
|
||||
int w = luaL_checkint(L, 1);
|
||||
int h = luaL_checkint(L, 2);
|
||||
|
||||
graphics::Graphics *g = luax_optmodule<graphics::Graphics>(L, "graphics", MODULE_GRAPHICS_T);
|
||||
|
||||
if (lua_isnoneornil(L, 3))
|
||||
{
|
||||
luax_pushboolean(L, instance->setWindow(w, h, g, 0));
|
||||
luax_pushboolean(L, instance->setWindow(w, h, 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -63,7 +61,7 @@ int w_setMode(lua_State *L)
|
||||
|
||||
try
|
||||
{
|
||||
luax_pushboolean(L, instance->setWindow(w, h, g, &flags));
|
||||
luax_pushboolean(L, instance->setWindow(w, h, &flags));
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
@@ -138,8 +136,6 @@ int w_getModes(lua_State *L)
|
||||
|
||||
int w_toggleFullscreen(lua_State *L)
|
||||
{
|
||||
graphics::Graphics *g = luax_optmodule<graphics::Graphics>(L, "graphics", MODULE_GRAPHICS_T);
|
||||
|
||||
int width, height;
|
||||
WindowFlags flags;
|
||||
instance->getWindow(width, height, flags);
|
||||
@@ -147,7 +143,7 @@ int w_toggleFullscreen(lua_State *L)
|
||||
|
||||
try
|
||||
{
|
||||
luax_pushboolean(L, instance->setWindow(width, height, g, &flags));
|
||||
luax_pushboolean(L, instance->setWindow(width, height, &flags));
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user