mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
@@ -168,7 +168,11 @@ bool TrueTypeRasterizer::hasGlyph(uint32 glyph) const
|
||||
float TrueTypeRasterizer::getKerning(uint32 leftglyph, uint32 rightglyph) const
|
||||
{
|
||||
FT_Vector kerning = {};
|
||||
FT_Get_Kerning(face, leftglyph, rightglyph, FT_KERNING_DEFAULT, &kerning);
|
||||
FT_Get_Kerning(face,
|
||||
FT_Get_Char_Index(face, leftglyph),
|
||||
FT_Get_Char_Index(face, rightglyph),
|
||||
FT_KERNING_DEFAULT,
|
||||
&kerning);
|
||||
return float(kerning.x >> 6);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,12 +58,10 @@ GLBuffer::GLBuffer(size_t size, const void *data, GLenum target, GLenum usage, u
|
||||
if (data != nullptr)
|
||||
memcpy(memory_map, data, size);
|
||||
|
||||
bool ok = load(data != nullptr);
|
||||
|
||||
if (!ok)
|
||||
if (!load(data != nullptr))
|
||||
{
|
||||
delete[] memory_map;
|
||||
throw love::Exception("Could not load VBO.");
|
||||
throw love::Exception("Could not load vertex buffer (out of VRAM?)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,13 +219,16 @@ bool GLBuffer::load(bool restore)
|
||||
|
||||
GLBuffer::Bind bind(*this);
|
||||
|
||||
while (glGetError() != GL_NO_ERROR)
|
||||
/* Clear the error buffer. */;
|
||||
|
||||
// Copy the old buffer only if 'restore' was requested.
|
||||
const GLvoid *src = restore ? memory_map : nullptr;
|
||||
|
||||
// Note that if 'src' is '0', no data will be copied.
|
||||
glBufferData(getTarget(), (GLsizeiptr) getSize(), src, getUsage());
|
||||
|
||||
return true;
|
||||
return (glGetError() == GL_NO_ERROR);
|
||||
}
|
||||
|
||||
void GLBuffer::unload()
|
||||
|
||||
@@ -166,14 +166,18 @@ void SpriteBatch::setBufferSize(int newsize)
|
||||
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
|
||||
GLBuffer *new_array_buf = nullptr;
|
||||
|
||||
int new_next = std::min(next, newsize);
|
||||
|
||||
try
|
||||
{
|
||||
new_array_buf = new GLBuffer(vertex_size, nullptr, array_buf->getTarget(), array_buf->getUsage(), array_buf->getMapFlags());
|
||||
|
||||
// Copy as much of the old data into the new GLBuffer as can fit.
|
||||
GLBuffer::Bind bind(*new_array_buf);
|
||||
void *new_data = new_array_buf->map();
|
||||
memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size));
|
||||
|
||||
// Copy as much of the old data into the new GLBuffer as can fit.
|
||||
size_t copy_size = sizeof(Vertex) * 4 * new_next;
|
||||
memcpy(new_array_buf->map(), old_data, copy_size);
|
||||
new_array_buf->setMappedRangeModified(0, copy_size);
|
||||
|
||||
quad_indices = QuadIndices(newsize);
|
||||
}
|
||||
@@ -189,7 +193,7 @@ void SpriteBatch::setBufferSize(int newsize)
|
||||
array_buf = new_array_buf;
|
||||
size = newsize;
|
||||
|
||||
next = std::min(next, newsize);
|
||||
next = new_next;
|
||||
}
|
||||
|
||||
int SpriteBatch::getBufferSize() const
|
||||
|
||||
@@ -55,6 +55,12 @@ void ChainShape::setNextVertex(float x, float y)
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
void ChainShape::setNextVertex()
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->m_hasNextVertex = false;
|
||||
}
|
||||
|
||||
void ChainShape::setPreviousVertex(float x, float y)
|
||||
{
|
||||
if (loop)
|
||||
@@ -64,7 +70,43 @@ void ChainShape::setPreviousVertex(float x, float y)
|
||||
}
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
c->SetPrevVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
void ChainShape::setPreviousVertex()
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->m_hasPrevVertex = false;
|
||||
}
|
||||
|
||||
bool ChainShape::getNextVertex(float &x, float &y) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
|
||||
if (c->m_hasNextVertex)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(c->m_nextVertex);
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChainShape::getPreviousVertex(float &x, float &y) const
|
||||
{
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
|
||||
if (c->m_hasPrevVertex)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(c->m_prevVertex);
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
EdgeShape *ChainShape::getChildEdge(int index) const
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setNextVertex(float x, float y);
|
||||
void setNextVertex();
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that precedes
|
||||
@@ -62,6 +63,17 @@ public:
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setPreviousVertex(float x, float y);
|
||||
void setPreviousVertex();
|
||||
|
||||
/**
|
||||
* Gets the vertex that follows the last vertex.
|
||||
**/
|
||||
bool getNextVertex(float &x, float &y) const;
|
||||
|
||||
/**
|
||||
* Gets the vertex that precedes the first vertex.
|
||||
**/
|
||||
bool getPreviousVertex(float &x, float &y) const;
|
||||
|
||||
/**
|
||||
* Returns a child EdgeShape.
|
||||
|
||||
@@ -43,6 +43,64 @@ EdgeShape::~EdgeShape()
|
||||
{
|
||||
}
|
||||
|
||||
void EdgeShape::setNextVertex(float x, float y)
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v(x, y);
|
||||
e->m_vertex3 = Physics::scaleDown(v);
|
||||
e->m_hasVertex3 = true;
|
||||
}
|
||||
|
||||
void EdgeShape::setNextVertex()
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
e->m_hasVertex3 = false;
|
||||
}
|
||||
|
||||
bool EdgeShape::getNextVertex(float &x, float &y) const
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
|
||||
if (e->m_hasVertex3)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(e->m_vertex3);
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EdgeShape::setPreviousVertex(float x, float y)
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v(x, y);
|
||||
e->m_vertex0 = Physics::scaleDown(v);
|
||||
e->m_hasVertex0 = true;
|
||||
}
|
||||
|
||||
void EdgeShape::setPreviousVertex()
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
e->m_hasVertex0 = false;
|
||||
}
|
||||
|
||||
bool EdgeShape::getPreviousVertex(float &x, float &y) const
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
|
||||
if (e->m_hasVertex0)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(e->m_vertex0);
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int EdgeShape::getPoints(lua_State *L)
|
||||
{
|
||||
b2EdgeShape *e = (b2EdgeShape *)shape;
|
||||
|
||||
@@ -47,6 +47,14 @@ public:
|
||||
|
||||
virtual ~EdgeShape();
|
||||
|
||||
void setNextVertex(float x, float y);
|
||||
void setNextVertex();
|
||||
bool getNextVertex(float &x, float &y) const;
|
||||
|
||||
void setPreviousVertex(float x, float y);
|
||||
void setPreviousVertex();
|
||||
bool getPreviousVertex(float &x, float &y) const;
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the edge shape.
|
||||
* This function is useful for debug drawing and such.
|
||||
|
||||
@@ -193,16 +193,28 @@ int Fixture::getMask(lua_State *L)
|
||||
uint16 Fixture::getBits(lua_State *L)
|
||||
{
|
||||
// Get number of args.
|
||||
int argc = lua_gettop(L);
|
||||
bool istable = lua_istable(L, 1);
|
||||
int argc = istable ? (int) luax_objlen(L, 1) : lua_gettop(L);
|
||||
|
||||
// The new bitset.
|
||||
std::bitset<16> b;
|
||||
|
||||
for (int i = 1; i<=argc; i++)
|
||||
for (int i = 1; i <= argc; i++)
|
||||
{
|
||||
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
|
||||
size_t bpos = 0;
|
||||
|
||||
if (istable)
|
||||
{
|
||||
lua_rawgeti(L, 1, i);
|
||||
bpos = (size_t) (lua_tointeger(L, -1) - 1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else
|
||||
bpos = (size_t) (lua_tointeger(L, i) - 1);
|
||||
|
||||
if (bpos >= 16)
|
||||
luaL_error(L, "Values must be in range 1-16.");
|
||||
|
||||
b.set(bpos, true);
|
||||
}
|
||||
|
||||
@@ -272,7 +284,8 @@ int Fixture::rayCast(lua_State *L) const
|
||||
int Fixture::getBoundingBox(lua_State *L) const
|
||||
{
|
||||
int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index
|
||||
b2AABB box = fixture->GetAABB(childIndex);
|
||||
b2AABB box;
|
||||
luax_catchexcept(L, [&]() { box = fixture->GetAABB(childIndex); });
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
|
||||
@@ -36,6 +36,9 @@ MouseJoint::MouseJoint(Body *body1, float x, float y)
|
||||
: Joint(body1)
|
||||
, joint(NULL)
|
||||
{
|
||||
if (body1->getType() == Body::BODY_KINEMATIC)
|
||||
throw love::Exception("Cannot attach a MouseJoint to a kinematic body");
|
||||
|
||||
b2MouseJointDef def;
|
||||
|
||||
def.bodyA = body1->world->getGroundBody();
|
||||
|
||||
@@ -140,8 +140,10 @@ int PrismaticJoint::getLimits(lua_State *L)
|
||||
|
||||
int PrismaticJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
b2Vec2 axis = joint->GetLocalAxisA();
|
||||
getBodyA()->getWorldVector(axis.x, axis.y, axis.x, axis.y);
|
||||
lua_pushnumber(L, axis.x);
|
||||
lua_pushnumber(L, axis.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,8 +115,10 @@ float WheelJoint::getSpringDampingRatio() const
|
||||
|
||||
int WheelJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
b2Vec2 axis = joint->GetLocalAxisA();
|
||||
getBodyA()->getWorldVector(axis.x, axis.y, axis.x, axis.y);
|
||||
lua_pushnumber(L, axis.x);
|
||||
lua_pushnumber(L, axis.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,18 +37,28 @@ ChainShape *luax_checkchainshape(lua_State *L, int idx)
|
||||
int w_ChainShape_setNextVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
|
||||
if (lua_isnoneornil(L, 2))
|
||||
c->setNextVertex();
|
||||
else
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_setPreviousVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
|
||||
if (lua_isnoneornil(L, 2))
|
||||
c->setPreviousVertex();
|
||||
else
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -82,6 +92,32 @@ int w_ChainShape_getPoint(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ChainShape_getNextVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x, y;
|
||||
if (c->getNextVertex(x, y))
|
||||
{
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPreviousVertex(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x, y;
|
||||
if (c->getPreviousVertex(x, y))
|
||||
{
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ChainShape_getPoints(lua_State *L)
|
||||
{
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
@@ -102,6 +138,8 @@ static const luaL_Reg w_ChainShape_functions[] =
|
||||
{
|
||||
{ "setNextVertex", w_ChainShape_setNextVertex },
|
||||
{ "setPreviousVertex", w_ChainShape_setPreviousVertex },
|
||||
{ "getNextVertex", w_ChainShape_getNextVertex },
|
||||
{ "getPreviousVertex", w_ChainShape_getPreviousVertex },
|
||||
{ "getChildEdge", w_ChainShape_getChildEdge },
|
||||
{ "getVertexCount", w_ChainShape_getVertexCount },
|
||||
{ "getPoint", w_ChainShape_getPoint },
|
||||
|
||||
@@ -32,6 +32,60 @@ EdgeShape *luax_checkedgeshape(lua_State *L, int idx)
|
||||
return luax_checktype<EdgeShape>(L, idx, PHYSICS_EDGE_SHAPE_ID);
|
||||
}
|
||||
|
||||
int w_EdgeShape_setNextVertex(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
if (lua_isnoneornil(L, 2))
|
||||
t->setNextVertex();
|
||||
else
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setNextVertex(x, y);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_EdgeShape_setPreviousVertex(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
if (lua_isnoneornil(L, 2))
|
||||
t->setPreviousVertex();
|
||||
else
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setPreviousVertex(x, y);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_EdgeShape_getNextVertex(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
float x, y;
|
||||
if (t->getNextVertex(x, y))
|
||||
{
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPreviousVertex(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
float x, y;
|
||||
if (t->getPreviousVertex(x, y))
|
||||
{
|
||||
lua_pushnumber(L, x);
|
||||
lua_pushnumber(L, y);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPoints(lua_State *L)
|
||||
{
|
||||
EdgeShape *t = luax_checkedgeshape(L, 1);
|
||||
@@ -41,6 +95,10 @@ int w_EdgeShape_getPoints(lua_State *L)
|
||||
|
||||
static const luaL_Reg w_EdgeShape_functions[] =
|
||||
{
|
||||
{ "setNextVertex", w_EdgeShape_setNextVertex },
|
||||
{ "setPreviousVertex", w_EdgeShape_setPreviousVertex },
|
||||
{ "getNextVertex", w_EdgeShape_getNextVertex },
|
||||
{ "getPreviousVertex", w_EdgeShape_getPreviousVertex },
|
||||
{ "getPoints", w_EdgeShape_getPoints },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user