Using latest love-android branch (9a508a54700d)

This commit is contained in:
fysx
2015-08-13 11:12:17 +02:00
parent c91dbb6957
commit f3dd769e98
63 changed files with 738 additions and 556 deletions
-4
View File
@@ -26,12 +26,8 @@ namespace love
namespace window
{
Window *Window::singleton = nullptr;
Window::~Window()
{
if (singleton == this)
singleton = nullptr;
}
void Window::swapBuffers()
+3 -8
View File
@@ -112,6 +112,8 @@ public:
virtual bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr) = 0;
virtual void getWindow(int &width, int &height, WindowSettings &settings) = 0;
virtual void close() = 0;
virtual bool setFullscreen(bool fullscreen, FullscreenType fstype) = 0;
virtual bool setFullscreen(bool fullscreen) = 0;
@@ -128,7 +130,7 @@ public:
virtual void setPosition(int x, int y, int displayindex) = 0;
virtual void getPosition(int &x, int &y, int &displayindex) = 0;
virtual bool isCreated() const = 0;
virtual bool isOpen() const = 0;
virtual void setWindowTitle(const std::string &title) = 0;
virtual const std::string &getWindowTitle() const = 0;
@@ -173,9 +175,6 @@ public:
virtual void requestAttention(bool continuous) = 0;
//virtual static Window *createSingleton() = 0;
// No virtual statics, of course, but you are supposed to implement this static.
static bool getConstant(const char *in, Setting &out);
static bool getConstant(Setting in, const char *&out);
@@ -185,10 +184,6 @@ public:
static bool getConstant(const char *in, MessageBoxType &out);
static bool getConstant(MessageBoxType in, const char *&out);
protected:
static Window *singleton;
private:
static StringMap<Setting, SETTING_MAX_ENUM>::Entry settingEntries[];
+46 -64
View File
@@ -56,7 +56,7 @@ namespace sdl
{
Window::Window()
: created(false)
: open(false)
, mouseGrabbed(false)
, window(nullptr)
, context(nullptr)
@@ -69,17 +69,7 @@ Window::Window()
Window::~Window()
{
if (context)
{
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->unSetMode();
SDL_GL_DeleteContext(context);
}
if (window)
SDL_DestroyWindow(window);
close();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
@@ -104,6 +94,13 @@ void Window::setGLFramebufferAttributes(int msaa, bool sRGB)
#if !defined(LOVE_LINUX)
SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, sRGB ? 1 : 0);
#endif
#if defined(LOVE_WINDOWS)
// Avoid the Microsoft OpenGL 1.1 software renderer on Windows. Apparently
// older Intel drivers like to use it as a fallback when requesting some
// unsupported framebuffer attribute values, rather than properly failing.
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#endif
}
void Window::setGLContextAttributes(const ContextAttribs &attribs)
@@ -349,22 +346,12 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
}
}
if (context)
{
SDL_GL_DeleteContext(context);
context = nullptr;
}
if (window)
{
SDL_DestroyWindow(window);
SDL_FlushEvent(SDL_WINDOWEVENT);
window = nullptr;
}
close();
return false;
}
open = true;
return true;
}
@@ -448,33 +435,11 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(f.display);
}
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->unSetMode();
if (context)
{
SDL_GL_DeleteContext(context);
context = nullptr;
}
if (window)
{
SDL_DestroyWindow(window);
window = nullptr;
// The old window may have generated pending events which are no longer
// relevant. Destroy them all!
SDL_FlushEvent(SDL_WINDOWEVENT);
}
created = false;
close();
if (!createWindowAndContext(x, y, width, height, sdlflags, f.msaa, f.sRGB))
return false;
created = true;
// Make sure the window keeps any previously set icon.
setIcon(curMode.icon.get());
@@ -493,6 +458,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
updateSettings(f);
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->setMode(curMode.pixelwidth, curMode.pixelheight, curMode.settings.sRGB);
@@ -513,7 +479,7 @@ bool Window::onSizeChanged(int width, int height)
SDL_GL_GetDrawableSize(window, &curMode.pixelwidth, &curMode.pixelheight);
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->setViewportSize(curMode.pixelwidth, curMode.pixelheight);
@@ -601,6 +567,31 @@ void Window::getWindow(int &width, int &height, WindowSettings &settings)
settings = curMode.settings;
}
void Window::close()
{
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->unSetMode();
if (context)
{
SDL_GL_DeleteContext(context);
context = nullptr;
}
if (window)
{
SDL_DestroyWindow(window);
window = nullptr;
// The old window may have generated pending events which are no longer
// relevant. Destroy them all!
SDL_FlushEvent(SDL_WINDOWEVENT);
}
open = false;
}
bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
{
if (!window)
@@ -639,7 +630,7 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
updateSettings(newsettings);
// Update the viewport size now instead of waiting for event polling.
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
if (gfx != nullptr)
gfx->setViewportSize(curMode.pixelwidth, curMode.pixelheight);
@@ -739,21 +730,22 @@ void Window::getPosition(int &x, int &y, int &displayindex)
SDL_GetWindowPosition(window, &x, &y);
// SDL always reports 0, 0 for fullscreen windows.
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN))
// In SDL <= 2.0.3, fullscreen windows are always reported as 0,0. In every
// other case we need to convert the position from global coordinates to the
// monitor's coordinate space.
if (x != 0 || y != 0)
{
SDL_Rect displaybounds = {};
SDL_GetDisplayBounds(displayindex, &displaybounds);
// The position needs to be in the monitor's coordinate space.
x -= displaybounds.x;
y -= displaybounds.y;
}
}
bool Window::isCreated() const
bool Window::isOpen() const
{
return created;
return open;
}
void Window::setWindowTitle(const std::string &title)
@@ -1034,16 +1026,6 @@ void Window::requestAttention(bool continuous)
// TODO: Linux?
}
love::window::Window *Window::createSingleton()
{
if (!singleton)
singleton = new Window();
else
singleton->retain();
return singleton;
}
const char *Window::getName() const
{
return "love.window.sdl";
+4 -4
View File
@@ -44,6 +44,8 @@ public:
bool setWindow(int width = 800, int height = 600, WindowSettings *settings = nullptr);
void getWindow(int &width, int &height, WindowSettings &settings);
void close();
bool setFullscreen(bool fullscreen, FullscreenType fstype);
bool setFullscreen(bool fullscreen);
@@ -60,7 +62,7 @@ public:
void setPosition(int x, int y, int displayindex);
void getPosition(int &x, int &y, int &displayindex);
bool isCreated() const;
bool isOpen() const;
void setWindowTitle(const std::string &title);
const std::string &getWindowTitle() const;
@@ -102,8 +104,6 @@ public:
void requestAttention(bool continuous);
static love::window::Window *createSingleton();
const char *getName() const;
private:
@@ -139,7 +139,7 @@ private:
} curMode;
bool created;
bool open;
bool mouseGrabbed;
+19 -8
View File
@@ -194,7 +194,7 @@ int w_getFullscreenModes(lua_State *L)
{
int displayindex = 0;
if (!lua_isnoneornil(L, 1))
displayindex = (int) luaL_checknumber(L, 1);
displayindex = (int) luaL_checknumber(L, 1) - 1;
else
{
int x, y;
@@ -260,18 +260,24 @@ int w_getFullscreen(lua_State *L)
return 2;
}
int w_isCreated(lua_State *L)
int w_isOpen(lua_State *L)
{
luax_pushboolean(L, instance()->isCreated());
luax_pushboolean(L, instance()->isOpen());
return 1;
}
int w_close(lua_State * /*L*/)
{
instance()->close();
return 0;
}
int w_getDesktopDimensions(lua_State *L)
{
int width = 0, height = 0;
int displayindex = 0;
if (!lua_isnoneornil(L, 1))
displayindex = (int) luaL_checknumber(L, 1);
displayindex = (int) luaL_checknumber(L, 1) - 1;
else
{
int x, y;
@@ -290,7 +296,7 @@ int w_setPosition(lua_State *L)
int displayindex = 0;
if (!lua_isnoneornil(L, 3))
displayindex = (int) luaL_checknumber(L, 3);
displayindex = (int) luaL_checknumber(L, 3) - 1;
else
{
int x_unused, y_unused;
@@ -499,7 +505,9 @@ static const luaL_Reg functions[] =
{ "getFullscreenModes", w_getFullscreenModes },
{ "setFullscreen", w_setFullscreen },
{ "getFullscreen", w_getFullscreen },
{ "isCreated", w_isCreated },
{ "isOpen", w_isOpen },
{ "isCreated", w_isOpen }, // For compatibility with old error handlers...
{ "close", w_close },
{ "getDesktopDimensions", w_getDesktopDimensions },
{ "setPosition", w_setPosition },
{ "getPosition", w_getPosition },
@@ -522,8 +530,11 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_love_window(lua_State *L)
{
Window *instance = nullptr;
luax_catchexcept(L, [&](){ instance = sdl::Window::createSingleton(); });
Window *instance = instance();
if (instance == nullptr)
luax_catchexcept(L, [&](){ instance = new love::window::sdl::Window(); });
else
instance->retain();
WrappedModule w;
w.module = instance;
+2 -1
View File
@@ -36,7 +36,8 @@ int w_getMode(lua_State *L);
int w_getFullscreenModes(lua_State *L);
int w_setFullscreen(lua_State *L);
int w_getFullscreen(lua_State *L);
int w_isCreated(lua_State *L);
int w_isOpen(lua_State *L);
int w_close(lua_State *L);
int w_getDesktopDimensions(lua_State *L);
int w_setPosition(lua_State *L);
int w_getPosition(lua_State *L);