updated to latest love-android (changeset 7b5f223900b)

This commit is contained in:
fysx
2015-01-22 10:48:45 +01:00
parent 31cd05551e
commit 542c029666
22 changed files with 529 additions and 53 deletions
+33 -2
View File
@@ -33,6 +33,17 @@ namespace audio
namespace openal
{
class InvalidFormatException : public love::Exception
{
public:
InvalidFormatException(int channels, int bitdepth)
: Exception("%d-channel Sources with %d bits per sample are not supported.", channels, bitdepth)
{
}
};
StaticDataBuffer::StaticDataBuffer(ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
{
alGenBuffers(1, &buffer);
@@ -68,6 +79,9 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
, toLoop(0)
{
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
if (fmt == 0)
throw InvalidFormatException(soundData->getChannels(), soundData->getBitDepth());
staticBuffer.set(new StaticDataBuffer(fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate()));
// The buffer has a +2 retain count right now, but we want it to have +1.
@@ -103,6 +117,9 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
, decoder(decoder)
, toLoop(0)
{
if (getFormat(decoder->getChannels(), decoder->getBitDepth()) == 0)
throw InvalidFormatException(decoder->getChannels(), decoder->getBitDepth());
alGenBuffers(MAX_BUFFERS, streamBuffers);
float z[3] = {0, 0, 0};
@@ -651,8 +668,22 @@ ALenum Source::getFormat(int channels, int bitDepth) const
return AL_FORMAT_STEREO8;
else if (channels == 2 && bitDepth == 16)
return AL_FORMAT_STEREO16;
else
return 0;
#ifdef AL_EXT_MCFORMATS
if (alIsExtensionPresent("AL_EXT_MCFORMATS"))
{
if (channels == 6 && bitDepth == 8)
return AL_FORMAT_51CHN8;
else if (channels == 6 && bitDepth == 16)
return AL_FORMAT_51CHN16;
else if (channels == 8 && bitDepth == 8)
return AL_FORMAT_71CHN8;
else if (channels == 8 && bitDepth == 16)
return AL_FORMAT_71CHN16;
}
#endif
return 0;
}
int Source::streamAtomic(ALuint buffer, love::sound::Decoder *d)
+6 -4
View File
@@ -58,10 +58,12 @@ int w_newSource(lua_State *L)
Source *t = 0;
if (luax_istype(L, 1, SOUND_SOUND_DATA_T))
t = instance()->newSource(luax_totype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T));
else if (luax_istype(L, 1, SOUND_DECODER_T))
t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T));
luax_catchexcept(L, [&]() {
if (luax_istype(L, 1, SOUND_SOUND_DATA_T))
t = instance()->newSource(luax_totype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T));
else if (luax_istype(L, 1, SOUND_DECODER_T))
t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T));
});
if (t)
{
+28 -10
View File
@@ -42,14 +42,14 @@ namespace sdl
// SDL reports mouse coordinates in the window coordinate system in OS X, but
// we want them in pixel coordinates (may be different with high-DPI enabled.)
static void windowToPixelCoords(int *x, int *y)
static void windowToPixelCoords(double *x, double *y)
{
#ifndef LOVE_ANDROID
window::Window *window = Module::getInstance<window::Window>(Module::M_WINDOW);
if (window && x)
*x = (int) window->toPixels(*x);
*x = window->toPixels(*x);
if (window && y)
*y = (int) window->toPixels(*y);
*y = window->toPixels(*y);
#endif
}
@@ -201,15 +201,30 @@ Message *Event::convert(const SDL_Event &e) const
vargs.push_back(new Variant((double) e.edit.length));
msg = new Message("textedit", vargs);
break;
case SDL_MOUSEMOTION:
{
double x = (double) e.motion.x;
double y = (double) e.motion.y;
double xrel = (double) e.motion.xrel;
double yrel = (double) e.motion.yrel;
windowToPixelCoords(&x, &y);
windowToPixelCoords(&xrel, &yrel);
vargs.push_back(new Variant(x));
vargs.push_back(new Variant(y));
vargs.push_back(new Variant(xrel));
vargs.push_back(new Variant(yrel));
msg = new Message("mousemoved", vargs);
}
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
if (buttons.find(e.button.button, button) && mouse::Mouse::getConstant(button, txt))
{
int x = e.button.x;
int y = e.button.y;
double x = (double) e.button.x;
double y = (double) e.button.y;
windowToPixelCoords(&x, &y);
vargs.push_back(new Variant((double) x));
vargs.push_back(new Variant((double) y));
vargs.push_back(new Variant(x));
vargs.push_back(new Variant(y));
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.push_back(new Variant(e.button.which == SDL_TOUCH_MOUSEID));
msg = new Message((e.type == SDL_MOUSEBUTTONDOWN) ?
@@ -225,11 +240,14 @@ Message *Event::convert(const SDL_Event &e) const
break;
int mx, my;
double dmx, dmy;
SDL_GetMouseState(&mx, &my);
windowToPixelCoords(&mx, &my);
dmx = (double) mx;
dmy = (double) my;
windowToPixelCoords(&dmx, &dmy);
vargs.push_back(new Variant((double) mx));
vargs.push_back(new Variant((double) my));
vargs.push_back(new Variant(dmx));
vargs.push_back(new Variant(dmy));
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.push_back(new Variant(false));
msg = new Message("mousepressed", vargs);
@@ -51,6 +51,8 @@ Graphics::Graphics()
, active(true)
, activeStencil(false)
{
gl = OpenGL();
states.reserve(10);
states.push_back(DisplayState());
+6 -2
View File
@@ -47,6 +47,9 @@
#ifdef LOVE_ENABLE_ENET
# include "libraries/enet/lua-enet.h"
#endif
#ifdef LOVE_ENABLE_LUAUTF8
# include "libraries/luautf8/lutf8lib.h"
#endif
// Scripts
#include "scripts/boot.lua.h"
@@ -249,9 +252,7 @@ int luaopen_love(lua_State * L)
// Preload module loaders.
for (int i = 0; modules[i].name != 0; i++)
{
love::luax_preload(L, modules[i].func, modules[i].name);
}
#ifdef LOVE_ENABLE_LUASOCKET
love::luasocket::__open(L);
@@ -259,6 +260,9 @@ int luaopen_love(lua_State * L)
#ifdef LOVE_ENABLE_ENET
love::luax_preload(L, luaopen_enet, "enet");
#endif
#ifdef LOVE_ENABLE_LUAUTF8
love::luax_preload(L, luaopen_luautf8, "utf8");
#endif
return 1;
}
+1 -1
View File
@@ -247,7 +247,7 @@ int w_isConvex(lua_State *L)
}
}
lua_pushboolean(L, Math::instance.isConvex(vertices));
luax_pushboolean(L, Math::instance.isConvex(vertices));
return 1;
}
+2
View File
@@ -75,6 +75,8 @@ public:
virtual bool isVisible() const = 0;
virtual void setGrabbed(bool grab) = 0;
virtual bool isGrabbed() const = 0;
virtual bool setRelative(bool relative) = 0;
virtual bool isRelative() const = 0;
static bool getConstant(const char *in, Button &out);
static bool getConstant(Button in, const char *&out);
+10
View File
@@ -220,6 +220,16 @@ bool Mouse::isGrabbed() const
return false;
}
bool Mouse::setRelative(bool relative)
{
return SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == 0;
}
bool Mouse::isRelative() const
{
return SDL_GetRelativeMouseMode() != SDL_FALSE;
}
} // sdl
} // mouse
} // love
+2
View File
@@ -66,6 +66,8 @@ public:
bool isVisible() const;
void setGrabbed(bool grab);
bool isGrabbed() const;
bool setRelative(bool relative);
bool isRelative() const;
private:
+15
View File
@@ -185,6 +185,19 @@ int w_isGrabbed(lua_State *L)
return 1;
}
int w_setRelative(lua_State *L)
{
bool relative = luax_toboolean(L, 1);
luax_pushboolean(L, instance()->setRelative(relative));
return 1;
}
int w_isRelative(lua_State *L)
{
luax_pushboolean(L, instance()->isRelative());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
@@ -204,6 +217,8 @@ static const luaL_Reg functions[] =
{ "getPosition", w_getPosition },
{ "setGrabbed", w_setGrabbed },
{ "isGrabbed", w_isGrabbed },
{ "setRelative", w_setRelative },
{ "isRelative", w_isRelative },
{ 0, 0 }
};
+2
View File
@@ -46,6 +46,8 @@ int w_setVisible(lua_State *L);
int w_isVisible(lua_State *L);
int w_setGrabbed(lua_State *L);
int w_isGrabbed(lua_State *L);
int w_setRelative(lua_State *L);
int w_isRelative(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_mouse(lua_State *L);
} // mouse
+9 -3
View File
@@ -55,12 +55,18 @@ 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);
if (context)
SDL_GL_DeleteContext(context);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}