mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -153,7 +153,6 @@ StringMap<Graphics::Support, Graphics::SUPPORT_MAX_ENUM>::Entry Graphics::suppor
|
||||
{ "multicanvas", Graphics::SUPPORT_MULTI_CANVAS },
|
||||
{ "dxt", Graphics::SUPPORT_DXT },
|
||||
{ "bc5", Graphics::SUPPORT_BC5 },
|
||||
{ "instancing", Graphics::SUPPORT_INSTANCING },
|
||||
{ "srgb", Graphics::SUPPORT_SRGB },
|
||||
};
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@ public:
|
||||
SUPPORT_MULTI_CANVAS,
|
||||
SUPPORT_DXT,
|
||||
SUPPORT_BC5,
|
||||
SUPPORT_INSTANCING,
|
||||
SUPPORT_SRGB,
|
||||
SUPPORT_MAX_ENUM
|
||||
};
|
||||
|
||||
@@ -1112,6 +1112,27 @@ double Graphics::getSystemLimit(SystemLimit limittype) const
|
||||
return limit;
|
||||
}
|
||||
|
||||
bool Graphics::isSupported(Support feature) const
|
||||
{
|
||||
switch (feature)
|
||||
{
|
||||
case SUPPORT_HDR_CANVAS:
|
||||
return Canvas::isFormatSupported(Canvas::FORMAT_HDR);
|
||||
case SUPPORT_MULTI_CANVAS:
|
||||
return Canvas::isMultiCanvasSupported();
|
||||
case SUPPORT_DXT:
|
||||
return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5);
|
||||
case SUPPORT_BC5:
|
||||
return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5);
|
||||
case SUPPORT_SRGB:
|
||||
// sRGB support for the screen is guaranteed if it's supported as a
|
||||
// Canvas format.
|
||||
return Canvas::isFormatSupported(Canvas::FORMAT_SRGB);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::push()
|
||||
{
|
||||
if (userMatrices == matrixLimit)
|
||||
|
||||
@@ -442,6 +442,11 @@ public:
|
||||
**/
|
||||
double getSystemLimit(SystemLimit limittype) const;
|
||||
|
||||
/**
|
||||
* Gets whether a graphics feature is supported on this system.
|
||||
**/
|
||||
bool isSupported(Support feature) const;
|
||||
|
||||
void push();
|
||||
void pop();
|
||||
void rotate(float r);
|
||||
|
||||
@@ -960,59 +960,63 @@ int w_getShader(lua_State *L)
|
||||
int w_isSupported(lua_State *L)
|
||||
{
|
||||
bool supported = true;
|
||||
size_t len = lua_gettop(L);
|
||||
Graphics::Support support;
|
||||
for (unsigned int i = 1; i <= len; i++)
|
||||
|
||||
for (int i = 1; i <= lua_gettop(L); i++)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, i);
|
||||
if (!Graphics::getConstant(str, support))
|
||||
Graphics::Support feature;
|
||||
if (!Graphics::getConstant(str, feature))
|
||||
return luaL_error(L, "Invalid graphics feature: %s", str);
|
||||
|
||||
switch (support)
|
||||
if (!instance->isSupported(feature))
|
||||
{
|
||||
case Graphics::SUPPORT_HDR_CANVAS:
|
||||
if (!Canvas::isFormatSupported(Canvas::FORMAT_HDR))
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_MULTI_CANVAS:
|
||||
if (!Canvas::isMultiCanvasSupported())
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_DXT:
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5))
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_BC5:
|
||||
if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5))
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_INSTANCING:
|
||||
if (!GLEE_ARB_draw_instanced)
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_SRGB:
|
||||
if (!Canvas::isFormatSupported(Canvas::FORMAT_SRGB))
|
||||
supported = false;
|
||||
break;
|
||||
default:
|
||||
supported = false;
|
||||
}
|
||||
if (!supported)
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pushboolean(L, supported);
|
||||
|
||||
luax_pushboolean(L, supported);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_hasCanvasFormat(lua_State *L)
|
||||
int w_getCanvasFormats(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
Canvas::Format format;
|
||||
lua_createtable(L, 0, (int) Canvas::FORMAT_MAX_ENUM);
|
||||
|
||||
if (!Canvas::getConstant(str, format))
|
||||
return luaL_error(L, "Invalid canvas format: %s", str);
|
||||
for (int i = 0; i < (int) Canvas::FORMAT_MAX_ENUM; i++)
|
||||
{
|
||||
Canvas::Format format = (Canvas::Format) i;
|
||||
const char *name = nullptr;
|
||||
|
||||
if (!Canvas::getConstant(format, name))
|
||||
continue;
|
||||
|
||||
luax_pushboolean(L, Canvas::isFormatSupported(format));
|
||||
lua_setfield(L, -2, name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getCompressedImageFormats(lua_State *L)
|
||||
{
|
||||
lua_createtable(L, 0, (int) image::CompressedData::FORMAT_MAX_ENUM);
|
||||
|
||||
for (int i = 0; i < (int) image::CompressedData::FORMAT_MAX_ENUM; i++)
|
||||
{
|
||||
image::CompressedData::Format format = (image::CompressedData::Format) i;
|
||||
const char *name = nullptr;
|
||||
|
||||
if (format == image::CompressedData::FORMAT_UNKNOWN)
|
||||
continue;
|
||||
|
||||
if (!image::CompressedData::getConstant(format, name))
|
||||
continue;
|
||||
|
||||
luax_pushboolean(L, Image::hasCompressedTextureSupport(format));
|
||||
lua_setfield(L, -2, name);
|
||||
}
|
||||
|
||||
luax_pushboolean(L, Canvas::isFormatSupported(format));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1389,7 +1393,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getShader", w_getShader },
|
||||
|
||||
{ "isSupported", w_isSupported },
|
||||
{ "hasCanvasFormat", w_hasCanvasFormat },
|
||||
{ "getCanvasFormats", w_getCanvasFormats },
|
||||
{ "getCompressedImageFormats", w_getCompressedImageFormats },
|
||||
{ "getRendererInfo", w_getRendererInfo },
|
||||
{ "getSystemLimit", w_getSystemLimit },
|
||||
|
||||
|
||||
@@ -89,7 +89,8 @@ int w_getCanvas(lua_State *L);
|
||||
int w_setShader(lua_State *L);
|
||||
int w_getShader(lua_State *L);
|
||||
int w_isSupported(lua_State *L);
|
||||
int w_hasCanvasFormat(lua_State *L);
|
||||
int w_getCanvasFormats(lua_State *L);
|
||||
int w_getCompressedImageFormats(lua_State *L);
|
||||
int w_getRendererInfo(lua_State *L);
|
||||
int w_getSystemLimit(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
|
||||
@@ -444,6 +444,30 @@ int Body::getFixtureList(lua_State *L) const
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Body::getContactList(lua_State *L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
const b2ContactEdge *ce = body->GetContactList();
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
if (!ce)
|
||||
break;
|
||||
|
||||
Contact *contact = (Contact *) Memoizer::find(ce->contact);
|
||||
if (!contact)
|
||||
contact = new Contact(ce->contact);
|
||||
else
|
||||
contact->retain();
|
||||
|
||||
luax_pushtype(L, "Contact", PHYSICS_CONTACT_T, contact);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
while ((ce = ce->next));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
|
||||
@@ -393,6 +393,13 @@ public:
|
||||
**/
|
||||
int getFixtureList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all active Contacts attached to this Body.
|
||||
* This list changes during World:update and you may miss some collisions
|
||||
* if you don't use the collision callbacks.
|
||||
**/
|
||||
int getContactList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroy this body.
|
||||
**/
|
||||
|
||||
@@ -142,6 +142,15 @@ void Contact::getChildren(int &childA, int &childB)
|
||||
childB = contact->GetChildIndexB();
|
||||
}
|
||||
|
||||
void Contact::getFixtures(Fixture *&fixtureA, Fixture *&fixtureB)
|
||||
{
|
||||
fixtureA = (Fixture *) Memoizer::find(contact->GetFixtureA());
|
||||
fixtureB = (Fixture *) Memoizer::find(contact->GetFixtureB());
|
||||
|
||||
if (!fixtureA || !fixtureB)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -148,6 +148,11 @@ public:
|
||||
|
||||
void getChildren(int &childA, int &childB);
|
||||
|
||||
/**
|
||||
* Gets the Fixtures associated with this Contact.
|
||||
**/
|
||||
void getFixtures(Fixture *&fixtureA, Fixture *&fixtureB);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
|
||||
@@ -318,10 +318,8 @@ bool World::ShouldCollide(b2Fixture *fixtureA, b2Fixture *fixtureB)
|
||||
{
|
||||
// Fixtures should be memoized, if we created them
|
||||
Fixture *a = (Fixture *)Memoizer::find(fixtureA);
|
||||
if (!a)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
Fixture *b = (Fixture *)Memoizer::find(fixtureB);
|
||||
if (!b)
|
||||
if (!a || !b)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
return filter.process(a, b);
|
||||
}
|
||||
|
||||
@@ -540,6 +540,15 @@ int w_Body_getFixtureList(lua_State *L)
|
||||
return n;
|
||||
}
|
||||
|
||||
int w_Body_getContactList(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int n = 0;
|
||||
luax_catchexcept(L, [&](){ n = t->getContactList(L); });
|
||||
return n;
|
||||
}
|
||||
|
||||
int w_Body_destroy(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
@@ -615,6 +624,7 @@ static const luaL_Reg functions[] =
|
||||
{ "isFixedRotation", w_Body_isFixedRotation },
|
||||
{ "getWorld", w_Body_getWorld },
|
||||
{ "getFixtureList", w_Body_getFixtureList },
|
||||
{ "getContactList", w_Body_getContactList },
|
||||
{ "destroy", w_Body_destroy },
|
||||
{ "setUserData", w_Body_setUserData },
|
||||
{ "getUserData", w_Body_getUserData },
|
||||
|
||||
@@ -85,6 +85,7 @@ int w_Body_setFixedRotation(lua_State *L);
|
||||
int w_Body_isFixedRotation(lua_State *L);
|
||||
int w_Body_getWorld(lua_State *L);
|
||||
int w_Body_getFixtureList(lua_State *L);
|
||||
int w_Body_getContactList(lua_State *L);
|
||||
int w_Body_destroy(lua_State *L);
|
||||
int w_Body_setUserData(lua_State *L);
|
||||
int w_Body_getUserData(lua_State *L);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
**/
|
||||
|
||||
#include "wrap_Contact.h"
|
||||
#include "Fixture.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -138,6 +139,20 @@ int w_Contact_getChildren(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Contact_getFixtures(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
Fixture *a = nullptr;
|
||||
Fixture *b = nullptr;
|
||||
luax_catchexcept(L, [&](){ t->getFixtures(a, b); });
|
||||
|
||||
a->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a);
|
||||
b->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, b);
|
||||
return 2;
|
||||
}
|
||||
|
||||
extern "C" int luaopen_contact(lua_State *L)
|
||||
{
|
||||
static const luaL_Reg functions[] =
|
||||
@@ -156,6 +171,7 @@ extern "C" int luaopen_contact(lua_State *L)
|
||||
{ "setTangentSpeed", w_Contact_setTangentSpeed },
|
||||
{ "getTangentSpeed", w_Contact_getTangentSpeed },
|
||||
{ "getChildren", w_Contact_getChildren },
|
||||
{ "getFixtures", w_Contact_getFixtures },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ int w_Contact_resetRestitution(lua_State *L);
|
||||
int w_Contact_setTangentSpeed(lua_State *L);
|
||||
int w_Contact_getTangentSpeed(lua_State *L);
|
||||
int w_Contact_getChildren(lua_State *L);
|
||||
int w_Contact_getFixtures(lua_State *L);
|
||||
extern "C" int luaopen_contact(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -108,6 +108,8 @@ public:
|
||||
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
||||
virtual love::image::ImageData *getIcon() = 0;
|
||||
|
||||
virtual void minimize() = 0;
|
||||
|
||||
// default no-op implementation
|
||||
virtual void swapBuffers();
|
||||
|
||||
|
||||
@@ -591,6 +591,12 @@ love::image::ImageData *Window::getIcon()
|
||||
return curMode.icon;
|
||||
}
|
||||
|
||||
void Window::minimize()
|
||||
{
|
||||
if (window != nullptr)
|
||||
SDL_MinimizeWindow(window);
|
||||
}
|
||||
|
||||
void Window::swapBuffers()
|
||||
{
|
||||
SDL_GL_SwapWindow(window);
|
||||
|
||||
@@ -65,6 +65,8 @@ public:
|
||||
bool setIcon(love::image::ImageData *imgd);
|
||||
love::image::ImageData *getIcon();
|
||||
|
||||
void minimize();
|
||||
|
||||
void swapBuffers();
|
||||
|
||||
bool hasFocus() const;
|
||||
|
||||
@@ -308,6 +308,12 @@ int w_getPixelScale(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_minimize(lua_State* /*L*/)
|
||||
{
|
||||
instance->minimize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getDisplayCount", w_getDisplayCount },
|
||||
@@ -327,6 +333,7 @@ static const luaL_Reg functions[] =
|
||||
{ "hasMouseFocus", w_hasMouseFocus },
|
||||
{ "isVisible", w_isVisible },
|
||||
{ "getPixelScale", w_getPixelScale },
|
||||
{ "minimize", w_minimize },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ int w_hasFocus(lua_State *L);
|
||||
int w_hasMouseFocus(lua_State *L);
|
||||
int w_isVisible(lua_State *L);
|
||||
int w_getPixelScale(lua_State *L);
|
||||
int w_minimize(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_window(lua_State *L);
|
||||
|
||||
} // window
|
||||
|
||||
Reference in New Issue
Block a user