Merge branch 'love2d:12.0-development' into 12.0-development

This commit is contained in:
nikeinikei
2023-02-11 20:28:28 +01:00
committed by GitHub
9 changed files with 202 additions and 11 deletions
+45 -2
View File
@@ -24,8 +24,10 @@ misrepresented as being the original software.
local table_concat = table.concat
local ipairs = ipairs
local pcall = pcall
local graphics = love.graphics
function love.graphics.newVideo(file, settings)
function graphics.newVideo(file, settings)
settings = settings == nil and {} or settings
if type(settings) ~= "table" then error("bad argument #2 to newVideo (expected table)", 2) end
@@ -50,7 +52,48 @@ function love.graphics.newVideo(file, settings)
return video
end
function love.graphics._transformGLSLErrorMessages(message)
function graphics.stencil(func, action, value, keepvalues)
love.markDeprecated(2, "love.graphics.stencil", "function", "replaced", "love.graphics.setStencilMode")
if not keepvalues then
graphics.clear(false, true, false)
end
if value == nil then value = 1 end
graphics.setStencilMode(action, "always", value)
local mr, mg, mb, ma = graphics.getColorMask()
graphics.setColorMask(false)
local success, err = pcall(func)
graphics.setColorMask(mr, mg, mb, ma)
graphics.setStencilMode()
if not success then
error(err, 2)
end
end
function graphics.setStencilTest(mode, value)
love.markDeprecated(2, "love.graphics.setStencilTest", "function", "replaced", "love.graphics.setStencilMode")
if mode ~= nil then
graphics.setStencilMode("keep", mode, value)
else
graphics.setStencilMode()
end
end
function graphics.getStencilTest()
love.markDeprecated(2, "love.graphics.getStencilTest", "function", "replaced", "love.graphics.getStencilMode")
local action, mode, value = graphics.getStencilMode()
return mode, value
end
function graphics._transformGLSLErrorMessages(message)
local shadertype = message:match("Cannot compile (%a+) shader code")
local compiling = shadertype ~= nil
if not shadertype then
+15
View File
@@ -56,6 +56,21 @@ STRINGMAP_CLASS_BEGIN(Joystick, Joystick::Hat, Joystick::HAT_MAX_ENUM, hat)
}
STRINGMAP_CLASS_END(Joystick, Joystick::Hat, Joystick::HAT_MAX_ENUM, hat)
STRINGMAP_CLASS_BEGIN(Joystick, Joystick::JoystickType, Joystick::JOYSTICK_TYPE_MAX_ENUM, joystickType)
{
{ "unknown", Joystick::JOYSTICK_TYPE_UNKNOWN },
{ "gamepad", Joystick::JOYSTICK_TYPE_GAMEPAD },
{ "wheel", Joystick::JOYSTICK_TYPE_WHEEL },
{ "arcadestick", Joystick::JOYSTICK_TYPE_ARCADE_STICK },
{ "flightstick", Joystick::JOYSTICK_TYPE_FLIGHT_STICK },
{ "dancepad", Joystick::JOYSTICK_TYPE_DANCE_PAD },
{ "guitar", Joystick::JOYSTICK_TYPE_GUITAR },
{ "drumkit", Joystick::JOYSTICK_TYPE_DRUM_KIT },
{ "arcadepad", Joystick::JOYSTICK_TYPE_ARCADE_PAD },
{ "throttle", Joystick::JOYSTICK_TYPE_THROTTLE },
}
STRINGMAP_CLASS_END(Joystick, Joystick::JoystickType, Joystick::JOYSTICK_TYPE_MAX_ENUM, joystickType)
STRINGMAP_CLASS_BEGIN(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MAX_ENUM, gamepadType)
{
{ "unknown", Joystick::GAMEPAD_TYPE_UNKNOWN },
+18
View File
@@ -59,6 +59,21 @@ public:
HAT_MAX_ENUM = 16
};
enum JoystickType
{
JOYSTICK_TYPE_UNKNOWN,
JOYSTICK_TYPE_GAMEPAD,
JOYSTICK_TYPE_WHEEL,
JOYSTICK_TYPE_ARCADE_STICK,
JOYSTICK_TYPE_FLIGHT_STICK,
JOYSTICK_TYPE_DANCE_PAD,
JOYSTICK_TYPE_GUITAR,
JOYSTICK_TYPE_DRUM_KIT,
JOYSTICK_TYPE_ARCADE_PAD,
JOYSTICK_TYPE_THROTTLE,
JOYSTICK_TYPE_MAX_ENUM
};
enum GamepadType
{
GAMEPAD_TYPE_UNKNOWN,
@@ -164,6 +179,8 @@ public:
virtual const char *getName() const = 0;
virtual JoystickType getJoystickType() const = 0;
virtual int getAxisCount() const = 0;
virtual int getButtonCount() const = 0;
virtual int getHatCount() const = 0;
@@ -207,6 +224,7 @@ public:
virtual std::vector<float> getSensorData(Sensor::SensorType type) const = 0;
STRINGMAP_CLASS_DECLARE(Hat);
STRINGMAP_CLASS_DECLARE(JoystickType);
STRINGMAP_CLASS_DECLARE(GamepadType);
STRINGMAP_CLASS_DECLARE(GamepadAxis);
STRINGMAP_CLASS_DECLARE(GamepadButton);
+40
View File
@@ -46,6 +46,7 @@ Joystick::Joystick(int id)
: joyhandle(nullptr)
, controller(nullptr)
, haptic(nullptr)
, joystickType(JOYSTICK_TYPE_UNKNOWN)
, instanceid(-1)
, id(id)
, vibration()
@@ -96,6 +97,40 @@ bool Joystick::open(int deviceindex)
if (joyname)
name = joyname;
switch (SDL_JoystickGetType(joyhandle))
{
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
joystickType = JOYSTICK_TYPE_GAMEPAD;
break;
case SDL_JOYSTICK_TYPE_WHEEL:
joystickType = JOYSTICK_TYPE_WHEEL;
break;
case SDL_JOYSTICK_TYPE_ARCADE_STICK:
joystickType = JOYSTICK_TYPE_ARCADE_STICK;
break;
case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
joystickType = JOYSTICK_TYPE_FLIGHT_STICK;
break;
case SDL_JOYSTICK_TYPE_DANCE_PAD:
joystickType = JOYSTICK_TYPE_DANCE_PAD;
break;
case SDL_JOYSTICK_TYPE_GUITAR:
joystickType = JOYSTICK_TYPE_GUITAR;
break;
case SDL_JOYSTICK_TYPE_DRUM_KIT:
joystickType = JOYSTICK_TYPE_DRUM_KIT;
break;
case SDL_JOYSTICK_TYPE_ARCADE_PAD:
joystickType = JOYSTICK_TYPE_ARCADE_PAD;
break;
case SDL_JOYSTICK_TYPE_THROTTLE:
joystickType = JOYSTICK_TYPE_THROTTLE;
break;
default:
joystickType = JOYSTICK_TYPE_UNKNOWN;
break;
}
}
return isConnected();
@@ -129,6 +164,11 @@ const char *Joystick::getName() const
return name.c_str();
}
Joystick::JoystickType Joystick::getJoystickType() const
{
return joystickType;
}
int Joystick::getAxisCount() const
{
return isConnected() ? SDL_JoystickNumAxes(joyhandle) : 0;
+4
View File
@@ -51,6 +51,8 @@ public:
const char *getName() const override;
JoystickType getJoystickType() const override;
int getAxisCount() const override;
int getButtonCount() const override;
int getHatCount() const override;
@@ -113,6 +115,8 @@ private:
SDL_GameController *controller;
SDL_Haptic *haptic;
JoystickType joystickType;
SDL_JoystickID instanceid;
std::string pguid;
int id;
+10
View File
@@ -86,6 +86,15 @@ int w_Joystick_getDeviceInfo(lua_State *L)
return 3;
}
int w_Joystick_getJoystickType(lua_State *L)
{
Joystick *j = luax_checkjoystick(L, 1);
const char* str = "unknown";
Joystick::getConstant(j->getJoystickType(), str);
lua_pushstring(L, str);
return 1;
}
int w_Joystick_getAxisCount(lua_State *L)
{
Joystick *j = luax_checkjoystick(L, 1);
@@ -448,6 +457,7 @@ static const luaL_Reg w_Joystick_functions[] =
{ "getID", w_Joystick_getID },
{ "getGUID", w_Joystick_getGUID },
{ "getDeviceInfo", w_Joystick_getDeviceInfo },
{ "getJoystickType", w_Joystick_getJoystickType },
{ "getAxisCount", w_Joystick_getAxisCount },
{ "getButtonCount", w_Joystick_getButtonCount },
{ "getHatCount", w_Joystick_getHatCount },