Merged default into minor.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-02-14 19:59:34 -04:00
93 changed files with 2264 additions and 2448 deletions
+1 -1
View File
@@ -574,7 +574,7 @@ void Source::setRelative(bool enable)
throw SpatialSupportException();
if (valid)
alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
alSourcei(source, AL_SOURCE_RELATIVE, enable ? AL_TRUE : AL_FALSE);
relative = enable;
}
+8 -13
View File
@@ -28,7 +28,7 @@ namespace love
namespace event
{
Message::Message(const std::string &name, const std::vector<StrongRef<Variant>> &vargs)
Message::Message(const std::string &name, const std::vector<Variant> &vargs)
: name(name)
, args(vargs)
{
@@ -42,13 +42,8 @@ int Message::toLua(lua_State *L)
{
luax_pushstring(L, name);
for (const StrongRef<Variant> &v : args)
{
if (v.get() != nullptr)
v->toLua(L);
else
lua_pushnil(L);
}
for (const Variant &v : args)
v.toLua(L);
return (int) args.size() + 1;
}
@@ -56,26 +51,26 @@ int Message::toLua(lua_State *L)
Message *Message::fromLua(lua_State *L, int n)
{
std::string name = luax_checkstring(L, n);
std::vector<StrongRef<Variant>> vargs;
std::vector<Variant> vargs;
int count = lua_gettop(L) - n;
n++;
Variant varg;
for (int i = 0; i < count; i++)
{
if (lua_isnoneornil(L, n+i))
break;
vargs.push_back(Variant::fromLua(L, n+i));
if (!vargs.back().get())
if (!Variant::fromLua(L, n+i, &varg))
{
vargs.clear();
luaL_error(L, "Argument %d can't be stored safely\nExpected boolean, number, string or userdata.", n+i);
return nullptr;
}
vargs.back()->release(); // fromLua gave a +1 ref.
vargs.push_back(varg);
}
return new Message(name, vargs);
+2 -2
View File
@@ -43,7 +43,7 @@ class Message : public Object
{
public:
Message(const std::string &name, const std::vector<StrongRef<Variant>> &vargs = {});
Message(const std::string &name, const std::vector<Variant> &vargs = {});
~Message();
int toLua(lua_State *L);
@@ -52,7 +52,7 @@ public:
private:
std::string name;
std::vector<StrongRef<Variant>> args;
std::vector<Variant> args;
}; // Message
+67 -89
View File
@@ -150,7 +150,7 @@ Message *Event::convert(const SDL_Event &e) const
{
Message *msg = nullptr;
std::vector<StrongRef<Variant>> vargs;
std::vector<Variant> vargs;
vargs.reserve(4);
love::filesystem::Filesystem *filesystem = nullptr;
@@ -192,9 +192,9 @@ Message *Event::convert(const SDL_Event &e) const
if (!love::keyboard::Keyboard::getConstant(scancode, txt2))
txt2 = "unknown";
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.push_back(new Variant(txt2, strlen(txt2)));
vargs.push_back(new Variant(e.key.repeat != 0));
vargs.emplace_back(txt, strlen(txt));
vargs.emplace_back(txt2, strlen(txt2));
vargs.emplace_back(e.key.repeat != 0);
msg = new Message("keypressed", vargs);
break;
case SDL_KEYUP:
@@ -209,20 +209,20 @@ Message *Event::convert(const SDL_Event &e) const
if (!love::keyboard::Keyboard::getConstant(scancode, txt2))
txt2 = "unknown";
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.push_back(new Variant(txt2, strlen(txt2)));
vargs.emplace_back(txt, strlen(txt));
vargs.emplace_back(txt2, strlen(txt2));
msg = new Message("keyreleased", vargs);
break;
case SDL_TEXTINPUT:
txt = e.text.text;
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.emplace_back(txt, strlen(txt));
msg = new Message("textinput", vargs);
break;
case SDL_TEXTEDITING:
txt = e.edit.text;
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.push_back(new Variant((double) e.edit.start));
vargs.push_back(new Variant((double) e.edit.length));
vargs.emplace_back(txt, strlen(txt));
vargs.emplace_back((double) e.edit.start);
vargs.emplace_back((double) e.edit.length);
msg = new Message("textedited", vargs);
break;
case SDL_MOUSEMOTION:
@@ -233,11 +233,11 @@ Message *Event::convert(const SDL_Event &e) const
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));
vargs.push_back(new Variant(e.motion.which == SDL_TOUCH_MOUSEID));
vargs.emplace_back(x);
vargs.emplace_back(y);
vargs.emplace_back(xrel);
vargs.emplace_back(yrel);
vargs.emplace_back(e.motion.which == SDL_TOUCH_MOUSEID);
msg = new Message("mousemoved", vargs);
}
break;
@@ -260,18 +260,18 @@ Message *Event::convert(const SDL_Event &e) const
double x = (double) e.button.x;
double y = (double) e.button.y;
windowToPixelCoords(&x, &y);
vargs.push_back(new Variant(x));
vargs.push_back(new Variant(y));
vargs.push_back(new Variant((double) button));
vargs.push_back(new Variant(e.button.which == SDL_TOUCH_MOUSEID));
vargs.emplace_back(x);
vargs.emplace_back(y);
vargs.emplace_back((double) button);
vargs.emplace_back(e.button.which == SDL_TOUCH_MOUSEID);
msg = new Message((e.type == SDL_MOUSEBUTTONDOWN) ?
"mousepressed" : "mousereleased",
vargs);
}
break;
case SDL_MOUSEWHEEL:
vargs.push_back(new Variant((double) e.wheel.x));
vargs.push_back(new Variant((double) e.wheel.y));
vargs.emplace_back((double) e.wheel.x);
vargs.emplace_back((double) e.wheel.y);
msg = new Message("wheelmoved", vargs);
break;
case SDL_FINGERDOWN:
@@ -316,12 +316,12 @@ Message *Event::convert(const SDL_Event &e) const
// bits as can fit in a pointer (for now.)
// We use lightuserdata instead of a lua_Number (double) because doubles
// can't represent all possible id values on 64-bit systems.
vargs.push_back(new Variant((void *) (intptr_t) touchinfo.id));
vargs.push_back(new Variant(touchinfo.x));
vargs.push_back(new Variant(touchinfo.y));
vargs.push_back(new Variant(touchinfo.dx));
vargs.push_back(new Variant(touchinfo.dy));
vargs.push_back(new Variant(touchinfo.pressure));
vargs.emplace_back((void *) (intptr_t) touchinfo.id);
vargs.emplace_back(touchinfo.x);
vargs.emplace_back(touchinfo.y);
vargs.emplace_back(touchinfo.dx);
vargs.emplace_back(touchinfo.dy);
vargs.emplace_back(touchinfo.pressure);
if (e.type == SDL_FINGERDOWN)
txt = "touchpressed";
@@ -356,7 +356,7 @@ Message *Event::convert(const SDL_Event &e) const
if (filesystem->isRealDirectory(e.drop.file))
{
vargs.push_back(new Variant(e.drop.file, strlen(e.drop.file)));
vargs.emplace_back(e.drop.file, strlen(e.drop.file));
msg = new Message("directorydropped", vargs);
}
else
@@ -364,7 +364,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;
vargs.push_back(new Variant(proxy.type, &proxy));
vargs.emplace_back(proxy.type, &proxy);
msg = new Message("filedropped", vargs);
proxy.object->release();
}
@@ -382,13 +382,6 @@ Message *Event::convert(const SDL_Event &e) const
break;
}
// We gave +1 refs to the StrongRef list, so we should release them.
for (const StrongRef<Variant> &v : vargs)
{
if (v.get() != nullptr)
v->release();
}
return msg;
}
@@ -400,7 +393,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
Message *msg = nullptr;
std::vector<StrongRef<Variant>> vargs;
std::vector<Variant> vargs;
vargs.reserve(4);
Proxy proxy;
@@ -418,8 +411,8 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!proxy.object)
break;
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.push_back(new Variant((double)(e.jbutton.button+1)));
vargs.emplace_back(proxy.type, (void *) &proxy);
vargs.emplace_back((double)(e.jbutton.button+1));
msg = new Message((e.type == SDL_JOYBUTTONDOWN) ?
"joystickpressed" : "joystickreleased",
vargs);
@@ -431,10 +424,10 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!proxy.object)
break;
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.push_back(new Variant((double)(e.jaxis.axis+1)));
vargs.emplace_back(proxy.type, (void *) &proxy);
vargs.emplace_back((double)(e.jaxis.axis+1));
float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f);
vargs.push_back(new Variant((double) value));
vargs.emplace_back((double) value);
msg = new Message("joystickaxis", vargs);
}
break;
@@ -447,9 +440,9 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!proxy.object)
break;
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.push_back(new Variant((double)(e.jhat.hat+1)));
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.emplace_back(proxy.type, (void *) &proxy);
vargs.emplace_back((double)(e.jhat.hat+1));
vargs.emplace_back(txt, strlen(txt));
msg = new Message("joystickhat", vargs);
break;
case SDL_CONTROLLERBUTTONDOWN:
@@ -465,8 +458,8 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!proxy.object)
break;
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.emplace_back(proxy.type, (void *) &proxy);
vargs.emplace_back(txt, strlen(txt));
msg = new Message(e.type == SDL_CONTROLLERBUTTONDOWN ?
"gamepadpressed" : "gamepadreleased", vargs);
break;
@@ -481,11 +474,11 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (!proxy.object)
break;
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.emplace_back(proxy.type, (void *) &proxy);
vargs.push_back(new Variant(txt, strlen(txt)));
vargs.emplace_back(txt, strlen(txt));
float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
vargs.push_back(new Variant((double) value));
vargs.emplace_back((double) value);
msg = new Message("gamepadaxis", vargs);
}
break;
@@ -495,7 +488,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
proxy.type = JOYSTICK_JOYSTICK_ID;
if (proxy.object)
{
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.emplace_back(proxy.type, (void *) &proxy);
msg = new Message("joystickadded", vargs);
}
break;
@@ -506,37 +499,14 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
if (proxy.object)
{
joymodule->removeJoystick((joystick::Joystick *) proxy.object);
vargs.push_back(new Variant(proxy.type, (void *) &proxy));
vargs.emplace_back(proxy.type, (void *) &proxy);
msg = new Message("joystickremoved", vargs);
}
break;
#ifdef LOVE_ANDROID
case SDL_WINDOWEVENT_MINIMIZED:
{
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
audio->pause();
}
break;
case SDL_WINDOWEVENT_RESTORED:
{
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
audio->resume();
}
break;
#endif
default:
break;
}
// We gave +1 refs to the StrongRef list, so we should release them.
for (const StrongRef<Variant> &v : vargs)
{
if (v.get() != nullptr)
v->release();
}
return msg;
}
@@ -544,7 +514,7 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
{
Message *msg = nullptr;
std::vector<StrongRef<Variant>> vargs;
std::vector<Variant> vargs;
vargs.reserve(4);
window::Window *win = nullptr;
@@ -556,17 +526,17 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
{
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED));
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED);
msg = new Message("focus", vargs);
break;
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_LEAVE:
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_ENTER));
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_ENTER);
msg = new Message("mousefocus", vargs);
break;
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_HIDDEN:
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_SHOWN));
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_SHOWN);
msg = new Message("visible", vargs);
break;
case SDL_WINDOWEVENT_RESIZED:
@@ -578,10 +548,10 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
if (sdlwin)
SDL_GL_GetDrawableSize(sdlwin, &px_w, &px_h);
vargs.push_back(new Variant((double) px_w));
vargs.push_back(new Variant((double) px_h));
vargs.push_back(new Variant((double) e.window.data1));
vargs.push_back(new Variant((double) e.window.data2));
vargs.emplace_back((double) px_w);
vargs.emplace_back((double) px_h);
vargs.emplace_back((double) e.window.data1);
vargs.emplace_back((double) e.window.data2);
msg = new Message("resize", vargs);
}
break;
@@ -590,13 +560,21 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
if (win)
win->onSizeChanged(e.window.data1, e.window.data2);
break;
}
// We gave +1 refs to the StrongRef list, so we should release them.
for (const StrongRef<Variant> &v : vargs)
case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_RESTORED:
#ifdef LOVE_ANDROID
{
if (v.get() != nullptr)
v->release();
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
{
if (e.window.event == SDL_WINDOWEVENT_MINIMIZED)
audio->pause();
else if (e.window.event == SDL_WINDOWEVENT_RESTORED)
audio->resume();
}
}
#endif
break;
}
return msg;
+3 -6
View File
@@ -95,14 +95,11 @@ int w_clear(lua_State *)
int w_quit(lua_State *L)
{
std::vector<StrongRef<Variant>> args;
std::vector<Variant> args;
Variant *v = Variant::fromLua(L, 1);
if (v)
{
Variant v;
if (Variant::fromLua(L, 1, &v))
args.push_back(v);
v->release();
}
Message *m = new Message("quit", args);
instance()->push(m);
+1 -1
View File
@@ -117,6 +117,7 @@ public:
return actual_samples;
}
static Format getSizedFormat(Format format);
static bool isSupported();
static bool isMultiFormatMultiCanvasSupported();
static bool isFormatSupported(Format format);
@@ -143,7 +144,6 @@ private:
void drawv(const Matrix4 &t, const Vertex *v);
static Format getSizedFormat(Format format);
static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type);
static size_t getFormatBitsPerPixel(Format format);
+19 -10
View File
@@ -459,17 +459,23 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors)
if (colors.size() == 0)
return;
if (states.back().canvases.size() == 0)
size_t numcanvases = states.back().canvases.size();
if (numcanvases > 0 && colors.size() != numcanvases)
throw love::Exception("Number of clear colors must match the number of active canvases (%ld)", states.back().canvases.size());
// We want to take the single-color codepath if there's no active Canvas, or
// if there's only one active Canvas. The multi-color codepath (in the loop
// below) assumes MRT functions are available, and also may call more
// expensive GL functions which are unnecessary if only one Canvas is active.
if (numcanvases <= 1)
{
if (colors[0].enabled)
clear({colors[0].r, colors[0].g, colors[0].b, colors[0].a});
clear(colors[0].toColor());
return;
}
if (colors.size() != states.back().canvases.size())
throw love::Exception("Number of clear colors must match the number of active canvases (%ld)", states.back().canvases.size());
bool drawbuffermodified = false;
for (int i = 0; i < (int) colors.size(); i++)
@@ -840,11 +846,14 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int msaa)
{
if (!Canvas::isSupported())
throw love::Exception("Canvases are not supported by your OpenGL drivers!");
if (!Canvas::isFormatSupported(format))
{
const char *fstr = "rgba8";
Canvas::getConstant(format, fstr);
throw love::Exception("The %s canvas format is not supported by your OpenGL implementation.", fstr);
Canvas::getConstant(Canvas::getSizedFormat(format), fstr);
throw love::Exception("The %s canvas format is not supported by your OpenGL drivers.", fstr);
}
if (width > gl.getMaxTextureSize())
@@ -868,7 +877,7 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int ms
switch (err)
{
case GL_FRAMEBUFFER_UNSUPPORTED:
error_string << "Not supported by your OpenGL implementation.";
error_string << "Not supported by your OpenGL drivers.";
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
error_string << "Texture format cannot be rendered to on this system.";
@@ -879,14 +888,14 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int ms
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
error_string << "Error in implementation.";
error_string << "Error in graphics driver.";
break;
default:
// my intel hda card wrongly returns 0 to glCheckFramebufferStatus() but sets
// no error flag. I think it meant to return GL_FRAMEBUFFER_UNSUPPORTED, but who
// knows.
if (glGetError() == GL_NO_ERROR)
error_string << "May not be supported by your OpenGL implementation.";
error_string << "May not be supported by your OpenGL drivers.";
// the remaining error is an indication of a serious fuckup since it should
// only be returned if glCheckFramebufferStatus() was called with the wrong
// arguments.
+2
View File
@@ -66,6 +66,8 @@ public:
{
float r, g, b, a;
bool enabled;
Colorf toColor() const { return Colorf(r, g, b, a); }
};
Graphics();
@@ -47,6 +47,13 @@ namespace opengl
#define instance() (Module::getInstance<Graphics>(Module::M_GRAPHICS))
static int luax_checkgraphicscreated(lua_State *L)
{
if (!instance()->isCreated())
return luaL_error(L, "love.graphics cannot function without a window!");
return 0;
}
int w_reset(lua_State *)
{
instance()->reset();
@@ -290,6 +297,8 @@ static const char *imageFlagName(Image::FlagType flagtype)
int w_newImage(lua_State *L)
{
luax_checkgraphicscreated(L);
std::vector<love::image::ImageData *> data;
std::vector<love::image::CompressedImageData *> cdata;
@@ -400,6 +409,8 @@ int w_newImage(lua_State *L)
int w_newQuad(lua_State *L)
{
luax_checkgraphicscreated(L);
Quad::Viewport v;
v.x = luaL_checknumber(L, 1);
v.y = luaL_checknumber(L, 2);
@@ -417,6 +428,8 @@ int w_newQuad(lua_State *L)
int w_newFont(lua_State *L)
{
luax_checkgraphicscreated(L);
Font *font = nullptr;
// Convert to Rasterizer, if necessary.
@@ -443,6 +456,8 @@ int w_newFont(lua_State *L)
int w_newImageFont(lua_State *L)
{
luax_checkgraphicscreated(L);
// filter for glyphs
Texture::Filter filter = instance()->getDefaultFilter();
@@ -483,6 +498,8 @@ int w_newImageFont(lua_State *L)
int w_newSpriteBatch(lua_State *L)
{
luax_checkgraphicscreated(L);
Texture *texture = luax_checktexture(L, 1);
int size = (int) luaL_optnumber(L, 2, 1000);
Mesh::Usage usage = Mesh::USAGE_DYNAMIC;
@@ -505,6 +522,8 @@ int w_newSpriteBatch(lua_State *L)
int w_newParticleSystem(lua_State *L)
{
luax_checkgraphicscreated(L);
Texture *texture = luax_checktexture(L, 1);
lua_Number size = luaL_optnumber(L, 2, 1000);
ParticleSystem *t = 0;
@@ -522,6 +541,8 @@ int w_newParticleSystem(lua_State *L)
int w_newCanvas(lua_State *L)
{
luax_checkgraphicscreated(L);
// check if width and height are given. else default to screen dimensions.
int width = (int) luaL_optnumber(L, 1, instance()->getWidth());
int height = (int) luaL_optnumber(L, 2, instance()->getHeight());
@@ -547,6 +568,8 @@ int w_newCanvas(lua_State *L)
int w_newShader(lua_State *L)
{
luax_checkgraphicscreated(L);
// clamp stack to 2 elements
lua_settop(L, 2);
@@ -848,6 +871,8 @@ static Mesh *newCustomMesh(lua_State *L)
int w_newMesh(lua_State *L)
{
luax_checkgraphicscreated(L);
// Check first argument: table or number of vertices.
int arg1type = lua_type(L, 1);
if (arg1type != LUA_TTABLE && arg1type != LUA_TNUMBER)
@@ -868,6 +893,8 @@ int w_newMesh(lua_State *L)
int w_newText(lua_State *L)
{
luax_checkgraphicscreated(L);
Font *font = luax_checkfont(L, 1);
Text *t = nullptr;
@@ -888,6 +915,8 @@ int w_newText(lua_State *L)
int w_newVideo(lua_State *L)
{
luax_checkgraphicscreated(L);
if (!luax_istype(L, 1, VIDEO_VIDEO_STREAM_ID))
luax_convobj(L, 1, "video", "newVideoStream");
+3 -4
View File
@@ -55,6 +55,7 @@ bool Keyboard::isDown(const std::vector<Key> &keylist) const
for (Key key : keylist)
{
SDL_Scancode scancode = SDL_GetScancodeFromKey(keymap[key]);
if (state[scancode])
return true;
}
@@ -68,11 +69,9 @@ bool Keyboard::isScancodeDown(const std::vector<Scancode> &scancodelist) const
for (Scancode scancode : scancodelist)
{
SDL_Scancode sdlscancode = SDL_SCANCODE_UNKNOWN;
if (!scancodes.find(scancode, sdlscancode))
continue;
SDL_Scancode sdlcode = SDL_SCANCODE_UNKNOWN;
if (state[sdlscancode])
if (scancodes.find(scancode, sdlcode) && state[sdlcode])
return true;
}
+2 -1
View File
@@ -42,7 +42,7 @@ MotorJoint::MotorJoint(Body *body1, Body *body2)
joint = (b2MotorJoint *) createJoint(&def);
}
MotorJoint::MotorJoint(Body *body1, Body *body2, float correctionFactor)
MotorJoint::MotorJoint(Body *body1, Body *body2, float correctionFactor, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
{
@@ -50,6 +50,7 @@ MotorJoint::MotorJoint(Body *body1, Body *body2, float correctionFactor)
def.Initialize(body1->body, body2->body);
def.correctionFactor = correctionFactor;
def.collideConnected = collideConnected;
joint = (b2MotorJoint *) createJoint(&def);
}
+1 -1
View File
@@ -41,7 +41,7 @@ class MotorJoint : public Joint
public:
MotorJoint(Body *body1, Body* body2);
MotorJoint(Body *body1, Body* body2, float correctionFactor);
MotorJoint(Body *body1, Body* body2, float correctionFactor, bool collideConnected);
virtual ~MotorJoint();
/// Set/get the target linear offset, in frame A, in meters.
+2 -2
View File
@@ -268,9 +268,9 @@ MotorJoint *Physics::newMotorJoint(Body *body1, Body *body2)
return new MotorJoint(body1, body2);
}
MotorJoint *Physics::newMotorJoint(Body *body1, Body *body2, float correctionFactor)
MotorJoint *Physics::newMotorJoint(Body *body1, Body *body2, float correctionFactor, bool collideConnected)
{
return new MotorJoint(body1, body2, correctionFactor);
return new MotorJoint(body1, body2, correctionFactor, collideConnected);
}
+1 -1
View File
@@ -257,7 +257,7 @@ public:
* and body2.
**/
MotorJoint *newMotorJoint(Body *body1, Body *body2);
MotorJoint *newMotorJoint(Body *body1, Body *body2, float correctionFactor);
MotorJoint *newMotorJoint(Body *body1, Body *body2, float correctionFactor, bool collideConnected);
/**
* Creates a new Fixture attaching shape to body.
+2 -1
View File
@@ -419,8 +419,9 @@ int w_newMotorJoint(lua_State *L)
if (!lua_isnoneornil(L, 3))
{
float correctionFactor = (float)luaL_checknumber(L, 3);
bool collideConnected = luax_optboolean(L, 4, false);
luax_catchexcept(L, [&]() {
j = instance()->newMotorJoint(body1, body2, correctionFactor);
j = instance()->newMotorJoint(body1, body2, correctionFactor, collideConnected);
});
}
else
+22 -39
View File
@@ -88,12 +88,6 @@ Channel::Channel(const std::string &name)
Channel::~Channel()
{
while (!queue.empty())
{
queue.front()->release();
queue.pop();
}
delete mutex;
delete cond;
@@ -101,13 +95,9 @@ Channel::~Channel()
namedChannels.erase(name);
}
unsigned long Channel::push(Variant *var)
unsigned long Channel::push(const Variant &var)
{
if (!var)
return 0;
Lock l(mutex);
var->retain();
// Keep a reference to ourselves
// if we're non-empty and named.
@@ -120,11 +110,8 @@ unsigned long Channel::push(Variant *var)
return ++sent;
}
void Channel::supply(Variant *var)
void Channel::supply(const Variant &var)
{
if (!var)
return;
Lock l(mutex);
unsigned long id = push(var);
@@ -132,13 +119,14 @@ void Channel::supply(Variant *var)
cond->wait(mutex);
}
Variant *Channel::pop()
bool Channel::pop(Variant *var)
{
Lock l(mutex);
if (queue.empty())
return 0;
Variant *var = queue.front();
if (queue.empty())
return false;
*var = queue.front();
queue.pop();
received++;
@@ -149,28 +137,26 @@ Variant *Channel::pop()
if (named && queue.empty())
release();
return var;
} // NOTE: Returns a retained Variant
Variant *Channel::demand()
{
Variant *var;
Lock l(mutex);
while (!(var = pop()))
cond->wait(mutex);
return var;
return true;
}
Variant *Channel::peek()
void Channel::demand(Variant *var)
{
Lock l(mutex);
if (queue.empty())
return 0;
Variant *var = queue.front();
var->retain();
return var;
while (!pop(var))
cond->wait(mutex);
}
bool Channel::peek(Variant *var)
{
Lock l(mutex);
if (queue.empty())
return false;
*var = queue.front();
return true;
}
int Channel::getCount()
@@ -188,10 +174,7 @@ void Channel::clear()
return;
while (!queue.empty())
{
queue.front()->release();
queue.pop();
}
// Finish all the supply waits
received = sent;
+6 -8
View File
@@ -37,8 +37,6 @@ namespace thread
class Channel : public love::Object
{
// FOR WRAPPER USE ONLY
friend void retainVariant(Channel *, Variant *);
friend void releaseVariant(Channel *, Variant *);
friend int w_Channel_performAtomic(lua_State *);
public:
@@ -48,11 +46,11 @@ public:
static Channel *getChannel(const std::string &name);
unsigned long push(Variant *var);
void supply(Variant *var); // blocking push
Variant *pop();
Variant *demand(); // blocking pop
Variant *peek();
unsigned long push(const Variant &var);
void supply(const Variant &var); // blocking push
bool pop(Variant *var);
void demand(Variant *var); // blocking pop
bool peek(Variant *var);
int getCount();
void clear();
@@ -67,7 +65,7 @@ private:
Mutex *mutex;
Conditional *cond;
std::queue<Variant *> queue;
std::queue<Variant> queue;
bool named;
std::string name;
+10 -29
View File
@@ -33,18 +33,12 @@ namespace thread
LuaThread::LuaThread(const std::string &name, love::Data *code)
: code(code)
, name(name)
, args(nullptr)
, nargs(0)
{
threadName = name;
}
LuaThread::~LuaThread()
{
// No args should still exist at this point,
// but you never know.
for (int i = 0; i < nargs; ++i)
args[i]->release();
}
void LuaThread::threadFunction()
@@ -74,16 +68,12 @@ void LuaThread::threadFunction()
error = luax_tostring(L, -1);
else
{
int pushedargs = nargs;
for (int i = 0; i < nargs; ++i)
{
args[i]->toLua(L);
args[i]->release();
}
// Set both args and nargs to nil, prevents the deconstructor from
// accessing it again.
nargs = 0;
args = nullptr;
int pushedargs = (int) args.size();
for (int i = 0; i < pushedargs; i++)
args[i].toLua(L);
args.clear();
if (lua_pcall(L, pushedargs, 0, 0) != 0)
error = luax_tostring(L, -1);
@@ -97,14 +87,9 @@ void LuaThread::threadFunction()
this->release();
}
bool LuaThread::start(Variant **args, int nargs)
bool LuaThread::start(const std::vector<Variant> &args)
{
for (int i = 0; i < this->nargs; ++i)
this->args[i]->release();
this->args = args;
this->nargs = nargs;
return Threadable::start();
}
@@ -126,16 +111,12 @@ void LuaThread::onError()
p.type = THREAD_THREAD_ID;
p.object = this;
std::vector<StrongRef<Variant>> vargs = {
new Variant(THREAD_THREAD_ID, &p),
new Variant(error.c_str(), error.length())
std::vector<Variant> vargs = {
Variant(p.type, &p),
Variant(error.c_str(), error.length())
};
event::Message *msg = new event::Message("threaderror", vargs);
for (const StrongRef<Variant> &v : vargs)
v->release();
eventmodule->push(msg);
msg->release();
}
+3 -3
View File
@@ -23,6 +23,7 @@
// STL
#include <string>
#include <vector>
// LOVE
#include "common/Data.h"
@@ -44,7 +45,7 @@ public:
void threadFunction();
const std::string &getError() const;
bool start(Variant **args, int nargs);
bool start(const std::vector<Variant> &args);
private:
@@ -54,8 +55,7 @@ private:
std::string name;
std::string error;
Variant **args;
int nargs;
std::vector<Variant> args;
}; // LuaThread
+13 -35
View File
@@ -25,20 +25,6 @@ namespace love
namespace thread
{
void retainVariant(Channel *c, Variant *v)
{
c->lockMutex();
v->retain();
c->unlockMutex();
}
void releaseVariant(Channel *c, Variant *v)
{
c->lockMutex();
v->release();
c->unlockMutex();
}
Channel *luax_checkchannel(lua_State *L, int idx)
{
return luax_checktype<Channel>(L, idx, THREAD_CHANNEL_ID);
@@ -47,34 +33,29 @@ Channel *luax_checkchannel(lua_State *L, int idx)
int w_Channel_push(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant *var = lua_isnoneornil(L, 2) ? 0 : Variant::fromLua(L, 2);
if (!var)
Variant var;
if (!Variant::fromLua(L, 2, &var))
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
c->push(var);
releaseVariant(c, var);
return 0;
}
int w_Channel_supply(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant *var = lua_isnoneornil(L, 2) ? 0 : Variant::fromLua(L, 2);
if (!var)
Variant var;
if (!Variant::fromLua(L, 2, &var))
return luaL_argerror(L, 2, "boolean, number, string, love type, or flat table expected");
c->supply(var);
releaseVariant(c, var);
return 0;
}
int w_Channel_pop(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant *var = c->pop();
if (var)
{
var->toLua(L);
releaseVariant(c, var);
}
Variant var;
if (c->pop(&var))
var.toLua(L);
else
lua_pushnil(L);
return 1;
@@ -83,21 +64,18 @@ int w_Channel_pop(lua_State *L)
int w_Channel_demand(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant *var = c->demand();
var->toLua(L);
releaseVariant(c, var);
Variant var;
c->demand(&var);
var.toLua(L);
return 1;
}
int w_Channel_peek(lua_State *L)
{
Channel *c = luax_checkchannel(L, 1);
Variant *var = c->peek();
if (var)
{
var->toLua(L);
releaseVariant(c, var);
}
Variant var;
if (c->peek(&var))
var.toLua(L);
else
lua_pushnil(L);
return 1;
+9 -13
View File
@@ -33,26 +33,22 @@ LuaThread *luax_checkthread(lua_State *L, int idx)
int w_Thread_start(lua_State *L)
{
LuaThread *t = luax_checkthread(L, 1);
std::vector<Variant> args;
int nargs = lua_gettop(L) - 1;
Variant **args = 0;
if (nargs > 0)
Variant v;
for (int i = 0; i < nargs; ++i)
{
args = new Variant*[nargs];
for (int i = 0; i < nargs; ++i)
if (!Variant::fromLua(L, i+2, &v))
{
args[i] = Variant::fromLua(L, i+2);
if (!args[i])
{
for (int j = i; j >= 0; j--)
delete args[j];
delete[] args;
return luaL_argerror(L, i+2, "boolean, number, string, love type, or flat table expected");
}
args.clear();
return luaL_argerror(L, i+2, "boolean, number, string, love type, or flat table expected");
}
args.push_back(v);
}
luax_pushboolean(L, t->start(args, nargs));
luax_pushboolean(L, t->start(args));
return 1;
}