Merge branch 'love2d:main' into sdf-font-hintingmode

This commit is contained in:
Labrium
2024-06-22 13:20:46 -06:00
committed by GitHub
839 changed files with 51659 additions and 31550 deletions
+5 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -68,6 +68,10 @@ void showRecordingPermissionMissingDialog()
#endif
}
Audio::Audio(const char *name)
: Module(M_AUDIO, name)
{}
bool Audio::setMixWithSystem(bool mix)
{
#ifdef LOVE_IOS
+5 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -101,9 +101,6 @@ public:
virtual ~Audio() {}
// Implements Module.
virtual ModuleType getModuleType() const { return M_AUDIO; }
virtual Source *newSource(love::sound::Decoder *decoder) = 0;
virtual Source *newSource(love::sound::SoundData *soundData) = 0;
virtual Source *newSource(int sampleRate, int bitDepth, int channels, int buffers) = 0;
@@ -312,6 +309,10 @@ public:
*/
virtual void setPlaybackDevice(const char *name);
protected:
Audio(const char *name);
private:
static StringMap<DistanceModel, DISTANCE_MAX_ENUM>::Entry distanceModelEntries[];
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+3 -7
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,8 @@ namespace null
{
Audio::Audio()
: distanceModel(DISTANCE_NONE)
: love::audio::Audio("love.audio.null")
, distanceModel(DISTANCE_NONE)
{
}
@@ -36,11 +37,6 @@ Audio::~Audio()
{
}
const char *Audio::getName() const
{
return "love.audio.null";
}
love::audio::Source *Audio::newSource(love::sound::Decoder *)
{
return new Source();
+1 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -41,9 +41,6 @@ public:
Audio();
virtual ~Audio();
// Implements Module.
const char *getName() const;
// Implements Audio.
love::audio::Source *newSource(love::sound::Decoder *decoder);
love::audio::Source *newSource(love::sound::SoundData *soundData);
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+6 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -106,7 +106,8 @@ static const char *getDeviceSpecifier(ALCdevice *device)
}
Audio::Audio()
: device(nullptr)
: love::audio::Audio("love.audio.openal")
, device(nullptr)
, context(nullptr)
, pool(nullptr)
, poolThread(nullptr)
@@ -144,10 +145,10 @@ Audio::Audio()
context = alcCreateContext(device, attribs.data());
if (context == nullptr)
throw love::Exception("Could not create context.");
throw love::Exception("Could not create context: %s", alcGetString(device, alcGetError(device)));
if (!alcMakeContextCurrent(context) || alcGetError(device) != ALC_NO_ERROR)
throw love::Exception("Could not make context current.");
if (!alcMakeContextCurrent(context))
throw love::Exception("Could not make context current: %s", alcGetString(device, alcGetError(device)));
}
#ifdef ALC_EXT_EFX
@@ -256,11 +257,6 @@ Audio::~Audio()
alcCloseDevice(device);
}
const char *Audio::getName() const
{
return "love.audio.openal";
}
love::audio::Source *Audio::newSource(love::sound::Decoder *decoder)
{
return new Source(pool, decoder);
+4 -7
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -50,9 +50,9 @@
#include <OpenAL-Soft/al.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <AL/alext.h>
#include <alc.h>
#include <al.h>
#include <alext.h>
#endif
namespace love
@@ -78,9 +78,6 @@ public:
**/
static ALenum getFormat(int bitDepth, int channels);
// Implements Module.
const char *getName() const;
// Implements Audio.
love::audio::Source *newSource(love::sound::Decoder *decoder);
love::audio::Source *newSource(love::sound::SoundData *soundData);
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+4 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -34,9 +34,9 @@
#include <OpenAL-Soft/alext.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <AL/alext.h>
#include <alc.h>
#include <al.h>
#include <alext.h>
#endif
#include <vector>
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+4 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -34,9 +34,9 @@
#include <OpenAL-Soft/alext.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <AL/alext.h>
#include <alc.h>
#include <al.h>
#include <alext.h>
#endif
#include <vector>
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+4 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -46,9 +46,9 @@
#include <OpenAL-Soft/alext.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <AL/alext.h>
#include <alc.h>
#include <al.h>
#include <alext.h>
#endif
namespace love
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+3 -3
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -32,8 +32,8 @@
#include <OpenAL-Soft/al.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <alc.h>
#include <al.h>
#endif
#include "audio/RecordingDevice.h"
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+3 -3
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -48,8 +48,8 @@
#include <OpenAL-Soft/al.h>
#endif
#else
#include <AL/alc.h>
#include <AL/al.h>
#include <alc.h>
#include <al.h>
#endif
namespace love
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+2 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -214,6 +214,7 @@ void hash(HashFunction::Function function, const char *input, uint64_t size, Has
}
DataModule::DataModule()
: Module(M_DATA, "love.data")
{
}
+1 -5
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -117,10 +117,6 @@ public:
DataModule();
virtual ~DataModule();
// Implements Module.
ModuleType getModuleType() const override { return M_DATA; }
const char *getName() const override { return "love.data"; }
DataView *newDataView(Data *data, size_t offset, size_t size);
ByteData *newByteData(size_t size);
ByteData *newByteData(const void *d, size_t size);
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+2 -14
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -56,7 +56,7 @@ int w_ByteData_setString(lua_State *L)
if (size == 0)
return 0;
if (offset < 0 || offset + size > (int64) t->getSize())
if (offset < 0 || offset + (int64) size > (int64) t->getSize())
return luaL_error(L, "The given string offset and size don't fit within the Data's size.");
memcpy((char *) t->getData() + (size_t) offset, str, size);
@@ -135,16 +135,6 @@ int w_ByteData_setUInt32(lua_State *L)
return w_ByteData_setT<uint32>(L);
}
int w_ByteData_setInt64(lua_State *L)
{
return w_ByteData_setT<int64>(L);
}
int w_ByteData_setUInt64(lua_State *L)
{
return w_ByteData_setT<uint64>(L);
}
static const luaL_Reg w_ByteData_functions[] =
{
{ "clone", w_ByteData_clone },
@@ -157,8 +147,6 @@ static const luaL_Reg w_ByteData_functions[] =
{ "setUInt16", w_ByteData_setUInt16 },
{ "setInt32", w_ByteData_setInt32 },
{ "setUInt32", w_ByteData_setUInt32 },
{ "setInt64", w_ByteData_setInt64 },
{ "setUInt64", w_ByteData_setUInt64 },
{ 0, 0 }
};
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+23 -13
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -20,6 +20,7 @@
#include "wrap_Data.h"
#include "common/int.h"
#include "thread/threads.h"
// Put the Lua code directly into a raw string literal.
static const char data_lua[] =
@@ -78,6 +79,26 @@ int w_Data_getSize(lua_State *L)
return 1;
}
int w_Data_performAtomic(lua_State *L)
{
Data *t = luax_checkdata(L, 1);
int err = 0;
{
love::thread::Lock lock(t->getMutex());
// call the function, passing any user-specified arguments.
err = lua_pcall(L, lua_gettop(L) - 2, LUA_MULTRET, 0);
}
// Unfortunately, this eats the stack trace, too bad.
if (err != 0)
return lua_error(L);
// The function and everything after it in the stack are eaten by the pcall,
// leaving only the Data object. Everything else is a return value.
return lua_gettop(L) - 1;
}
template <typename T>
static int w_Data_getT(lua_State* L)
{
@@ -139,16 +160,6 @@ int w_Data_getUInt32(lua_State* L)
return w_Data_getT<uint32>(L);
}
int w_Data_getInt64(lua_State* L)
{
return w_Data_getT<int64>(L);
}
int w_Data_getUInt64(lua_State* L)
{
return w_Data_getT<uint64>(L);
}
// C functions in a struct, necessary for the FFI versions of Data methods.
struct FFI_Data
{
@@ -170,6 +181,7 @@ const luaL_Reg w_Data_functions[] =
{ "getPointer", w_Data_getPointer },
{ "getFFIPointer", w_Data_getFFIPointer },
{ "getSize", w_Data_getSize },
{ "performAtomic", w_Data_performAtomic },
{ "getFloat", w_Data_getFloat },
{ "getDouble", w_Data_getDouble },
{ "getInt8", w_Data_getInt8 },
@@ -178,8 +190,6 @@ const luaL_Reg w_Data_functions[] =
{ "getUInt16", w_Data_getUInt16 },
{ "getInt32", w_Data_getInt32 },
{ "getUInt32", w_Data_getUInt32 },
{ "getInt64", w_Data_getInt64 },
{ "getUInt64", w_Data_getUInt64 },
{ 0, 0 }
};
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -3,7 +3,7 @@ R"luastring"--(
-- There is a matching delimiter at the bottom of the file.
--[[
Copyright (c) 2006-2023 LOVE Development Team
Copyright (c) 2006-2024 LOVE Development Team
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
+33 -6
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -302,25 +302,52 @@ int w_decode(lua_State *L)
int w_hash(lua_State *L)
{
const char *fstr = luaL_checkstring(L, 1);
int narg = 0; // used to change the arg position when using the deprecated function variant
ContainerType ctype = CONTAINER_STRING;
HashFunction::Function function;
const char *str = luaL_checkstring(L, 1);
if (!getConstant(str, ctype))
{
if (HashFunction::getConstant(str, function))
{ // check if the argument at 1 is a hash function; deprecated function variant
luax_markdeprecated(L, 1, "love.data.hash", API_FUNCTION_VARIANT, DEPRECATED_REPLACED, "variant with container return type parameter");
narg = -1;
}
else
luax_enumerror(L, "container type", getConstants(ctype), str);
}
const char *fstr = luaL_checkstring(L, 2 + narg);
if (!HashFunction::getConstant(fstr, function))
return luax_enumerror(L, "hash function", HashFunction::getConstants(function), fstr);
HashFunction::Value hashvalue;
if (lua_isstring(L, 2))
if (lua_isstring(L, 3 + narg))
{
size_t rawsize = 0;
const char *rawbytes = luaL_checklstring(L, 2, &rawsize);
const char *rawbytes = luaL_checklstring(L, 3 + narg, &rawsize);
luax_catchexcept(L, [&](){ love::data::hash(function, rawbytes, rawsize, hashvalue); });
}
else
{
Data *rawdata = luax_checktype<Data>(L, 2);
Data *rawdata = luax_checktype<Data>(L, 3 + narg);
luax_catchexcept(L, [&](){ love::data::hash(function, rawdata, hashvalue); });
}
lua_pushlstring(L, hashvalue.data, hashvalue.size);
if (ctype == CONTAINER_DATA)
{
Data* d = nullptr;
luax_catchexcept(L, [&]() { d = instance()->newByteData(hashvalue.size); });
memcpy(d->getData(), hashvalue.data, hashvalue.size);
luax_pushtype(L, Data::type, d);
d->release();
}
else
lua_pushlstring(L, hashvalue.data, hashvalue.size);
return 1;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+6 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -38,6 +38,11 @@ Message::~Message()
{
}
Event::Event(const char *name)
: Module(M_EVENT, name)
{
}
Event::~Event()
{
}
+5 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -54,10 +54,8 @@ public:
class Event : public Module
{
public:
virtual ~Event();
// Implements Module.
virtual ModuleType getModuleType() const { return M_EVENT; }
virtual ~Event();
void push(Message *msg);
bool poll(Message *&msg);
@@ -67,6 +65,9 @@ public:
virtual Message *wait() = 0;
protected:
Event(const char *name);
love::thread::MutexRef mutex;
std::queue<Message *> queue;
+239 -339
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -24,7 +24,6 @@
#include "filesystem/Filesystem.h"
#include "keyboard/sdl/Keyboard.h"
#include "joystick/JoystickModule.h"
#include "joystick/sdl/Joystick.h"
#include "touch/sdl/Touch.h"
#include "graphics/Graphics.h"
#include "window/Window.h"
@@ -38,6 +37,58 @@
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST(3, 0, 0)
#include "joystick/sdl/JoystickSDL3.h"
#else
#include "joystick/sdl/Joystick.h"
#endif
#if !SDL_VERSION_ATLEAST(3, 0, 0)
#define SDL_EVENT_DID_ENTER_BACKGROUND SDL_APP_DIDENTERBACKGROUND
#define SDL_EVENT_WILL_ENTER_FOREGROUND SDL_APP_WILLENTERFOREGROUND
#define SDL_EVENT_KEY_DOWN SDL_KEYDOWN
#define SDL_EVENT_KEY_UP SDL_KEYUP
#define SDL_EVENT_TEXT_INPUT SDL_TEXTINPUT
#define SDL_EVENT_TEXT_EDITING SDL_TEXTEDITING
#define SDL_EVENT_MOUSE_MOTION SDL_MOUSEMOTION
#define SDL_EVENT_MOUSE_BUTTON_DOWN SDL_MOUSEBUTTONDOWN
#define SDL_EVENT_MOUSE_BUTTON_UP SDL_MOUSEBUTTONUP
#define SDL_EVENT_MOUSE_WHEEL SDL_MOUSEWHEEL
#define SDL_EVENT_FINGER_DOWN SDL_FINGERDOWN
#define SDL_EVENT_FINGER_UP SDL_FINGERUP
#define SDL_EVENT_FINGER_MOTION SDL_FINGERMOTION
#define SDL_EVENT_DROP_FILE SDL_DROPFILE
#define SDL_EVENT_QUIT SDL_QUIT
#define SDL_EVENT_TERMINATING SDL_APP_TERMINATING
#define SDL_EVENT_LOW_MEMORY SDL_APP_LOWMEMORY
#define SDL_EVENT_LOCALE_CHANGED SDL_LOCALECHANGED
#define SDL_EVENT_SENSOR_UPDATE SDL_SENSORUPDATE
#define SDL_EVENT_JOYSTICK_BUTTON_DOWN SDL_JOYBUTTONDOWN
#define SDL_EVENT_JOYSTICK_BUTTON_UP SDL_JOYBUTTONUP
#define SDL_EVENT_JOYSTICK_AXIS_MOTION SDL_JOYAXISMOTION
#define SDL_EVENT_JOYSTICK_HAT_MOTION SDL_JOYHATMOTION
#define SDL_EVENT_JOYSTICK_ADDED SDL_JOYDEVICEADDED
#define SDL_EVENT_JOYSTICK_REMOVED SDL_JOYDEVICEREMOVED
#define SDL_EVENT_GAMEPAD_BUTTON_DOWN SDL_CONTROLLERBUTTONDOWN
#define SDL_EVENT_GAMEPAD_BUTTON_UP SDL_CONTROLLERBUTTONUP
#define SDL_EVENT_GAMEPAD_AXIS_MOTION SDL_CONTROLLERAXISMOTION
#define SDL_EVENT_GAMEPAD_SENSOR_UPDATE SDL_CONTROLLERSENSORUPDATE
#define SDL_EVENT_WINDOW_FOCUS_GAINED SDL_WINDOWEVENT_FOCUS_GAINED
#define SDL_EVENT_WINDOW_FOCUS_LOST SDL_WINDOWEVENT_FOCUS_LOST
#define SDL_EVENT_WINDOW_MOUSE_ENTER SDL_WINDOWEVENT_ENTER
#define SDL_EVENT_WINDOW_MOUSE_LEAVE SDL_WINDOWEVENT_LEAVE
#define SDL_EVENT_WINDOW_SHOWN SDL_WINDOWEVENT_SHOWN
#define SDL_EVENT_WINDOW_HIDDEN SDL_WINDOWEVENT_HIDDEN
#define SDL_EVENT_WINDOW_RESIZED SDL_WINDOWEVENT_RESIZED
#define SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED SDL_WINDOWEVENT_SIZE_CHANGED
#define SDL_EVENT_WINDOW_MINIMIZED SDL_WINDOWEVENT_MINIMIZED
#define SDL_EVENT_WINDOW_RESTORED SDL_WINDOWEVENT_RESTORED
#endif
namespace love
{
namespace event
@@ -93,10 +144,10 @@ static int SDLCALL watchAppEvents(void * /*udata*/, SDL_Event *event)
// On iOS, calling any OpenGL ES function after the function which triggers
// SDL_APP_DIDENTERBACKGROUND is called will kill the app, so we handle it
// with an event watch callback, which will be called inside that function.
case SDL_APP_DIDENTERBACKGROUND:
case SDL_APP_WILLENTERFOREGROUND:
case SDL_EVENT_DID_ENTER_BACKGROUND:
case SDL_EVENT_WILL_ENTER_FOREGROUND:
if (gfx)
gfx->setActive(event->type == SDL_APP_WILLENTERFOREGROUND);
gfx->setActive(event->type == SDL_EVENT_WILL_ENTER_FOREGROUND);
break;
default:
break;
@@ -105,12 +156,8 @@ static int SDLCALL watchAppEvents(void * /*udata*/, SDL_Event *event)
return 1;
}
const char *Event::getName() const
{
return "love.event.sdl";
}
Event::Event()
: love::event::Event("love.event.sdl")
{
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0)
throw love::Exception("Could not initialize SDL events subsystem (%s)", SDL_GetError());
@@ -193,16 +240,15 @@ Message *Event::convert(const SDL_Event &e)
const char *txt;
const char *txt2;
std::map<SDL_Keycode, love::keyboard::Keyboard::Key>::const_iterator keyit;
#ifndef LOVE_MACOS
love::touch::sdl::Touch *touchmodule = nullptr;
love::touch::Touch::TouchInfo touchinfo;
love::touch::Touch::TouchInfo touchinfo = {};
#endif
switch (e.type)
{
case SDL_KEYDOWN:
case SDL_EVENT_KEY_DOWN:
if (e.key.repeat)
{
auto kb = Module::getInstance<love::keyboard::Keyboard>(Module::M_KEYBOARD);
@@ -210,10 +256,7 @@ Message *Event::convert(const SDL_Event &e)
break;
}
keyit = keys.find(e.key.keysym.sym);
if (keyit != keys.end())
key = keyit->second;
love::keyboard::sdl::Keyboard::getConstant(e.key.keysym.sym, key);
if (!love::keyboard::Keyboard::getConstant(key, txt))
txt = "unknown";
@@ -226,11 +269,8 @@ Message *Event::convert(const SDL_Event &e)
vargs.emplace_back(e.key.repeat != 0);
msg = new Message("keypressed", vargs);
break;
case SDL_KEYUP:
keyit = keys.find(e.key.keysym.sym);
if (keyit != keys.end())
key = keyit->second;
case SDL_EVENT_KEY_UP:
love::keyboard::sdl::Keyboard::getConstant(e.key.keysym.sym, key);
if (!love::keyboard::Keyboard::getConstant(key, txt))
txt = "unknown";
@@ -242,19 +282,19 @@ Message *Event::convert(const SDL_Event &e)
vargs.emplace_back(txt2, strlen(txt2));
msg = new Message("keyreleased", vargs);
break;
case SDL_TEXTINPUT:
case SDL_EVENT_TEXT_INPUT:
txt = e.text.text;
vargs.emplace_back(txt, strlen(txt));
msg = new Message("textinput", vargs);
break;
case SDL_TEXTEDITING:
case SDL_EVENT_TEXT_EDITING:
txt = e.edit.text;
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:
case SDL_EVENT_MOUSE_MOTION:
{
double x = (double) e.motion.x;
double y = (double) e.motion.y;
@@ -278,8 +318,8 @@ Message *Event::convert(const SDL_Event &e)
msg = new Message("mousemoved", vargs);
}
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
{
// SDL uses button 3 for the right mouse button, but we use button 2
int button = e.button.button;
@@ -305,14 +345,14 @@ Message *Event::convert(const SDL_Event &e)
vargs.emplace_back(e.button.which == SDL_TOUCH_MOUSEID);
vargs.emplace_back((double) e.button.clicks);
bool down = e.type == SDL_MOUSEBUTTONDOWN;
bool down = e.type == SDL_EVENT_MOUSE_BUTTON_DOWN;
msg = new Message(down ? "mousepressed" : "mousereleased", vargs);
}
break;
case SDL_MOUSEWHEEL:
case SDL_EVENT_MOUSE_WHEEL:
vargs.emplace_back((double) e.wheel.x);
vargs.emplace_back((double) e.wheel.y);
#if SDL_VERSION_ATLEAST(2, 0, 18)
#if SDL_VERSION_ATLEAST(2, 0, 18) && !SDL_VERSION_ATLEAST(3, 0, 0)
// These values will be garbage if 2.0.18+ headers are used but a lower
// version of SDL is used at runtime, but other bits of code already
// prevent running in that situation.
@@ -328,15 +368,19 @@ Message *Event::convert(const SDL_Event &e)
msg = new Message("wheelmoved", vargs);
break;
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
case SDL_EVENT_FINGER_DOWN:
case SDL_EVENT_FINGER_UP:
case SDL_EVENT_FINGER_MOTION:
// Touch events are disabled in OS X because we only actually want touch
// screen events, but most touch devices in OS X aren't touch screens
// (and SDL doesn't differentiate.) Non-screen touch devices like Mac
// trackpads won't give touch coords in the window's coordinate-space.
#ifndef LOVE_MACOS
touchinfo.id = (int64) e.tfinger.fingerId;
#if SDL_VERSION_ATLEAST(3, 0, 0)
touchinfo.id = (int64) e.tfinger.fingerID;
#else
touchinfo.id = (int64)e.tfinger.fingerId;
#endif
touchinfo.x = e.tfinger.x;
touchinfo.y = e.tfinger.y;
touchinfo.dx = e.tfinger.dx;
@@ -364,35 +408,51 @@ Message *Event::convert(const SDL_Event &e)
vargs.emplace_back(touchinfo.dy);
vargs.emplace_back(touchinfo.pressure);
if (e.type == SDL_FINGERDOWN)
if (e.type == SDL_EVENT_FINGER_DOWN)
txt = "touchpressed";
else if (e.type == SDL_FINGERUP)
else if (e.type == SDL_EVENT_FINGER_UP)
txt = "touchreleased";
else
txt = "touchmoved";
msg = new Message(txt, vargs);
#endif
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYDEVICEADDED:
case SDL_JOYDEVICEREMOVED:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
case SDL_EVENT_JOYSTICK_ADDED:
case SDL_EVENT_JOYSTICK_REMOVED:
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
#if SDL_VERSION_ATLEAST(2, 0, 14) && defined(LOVE_ENABLE_SENSOR)
case SDL_CONTROLLERSENSORUPDATE:
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE:
#endif
msg = convertJoystickEvent(e);
break;
#if SDL_VERSION_ATLEAST(3, 0, 0)
case SDL_EVENT_WINDOW_FOCUS_GAINED:
case SDL_EVENT_WINDOW_FOCUS_LOST:
case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_WINDOW_SHOWN:
case SDL_EVENT_WINDOW_HIDDEN:
case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
case SDL_EVENT_WINDOW_MINIMIZED:
case SDL_EVENT_WINDOW_RESTORED:
#else
case SDL_WINDOWEVENT:
#endif
msg = convertWindowEvent(e);
break;
#if SDL_VERSION_ATLEAST(3, 0, 0)
case SDL_EVENT_DISPLAY_ORIENTATION:
#else
case SDL_DISPLAYEVENT:
if (e.display.event == SDL_DISPLAYEVENT_ORIENTATION)
#endif
{
auto orientation = window::Window::ORIENTATION_UNKNOWN;
switch ((SDL_DisplayOrientation) e.display.data1)
@@ -418,47 +478,70 @@ Message *Event::convert(const SDL_Event &e)
if (!window::Window::getConstant(orientation, txt))
txt = "unknown";
#if SDL_VERSION_ATLEAST(3, 0, 0)
int count = 0;
int displayindex = 0;
SDL_DisplayID *displays = SDL_GetDisplays(&count);
for (int i = 0; i < count; i++)
{
if (displays[i] == e.display.displayID)
{
displayindex = i;
break;
}
}
SDL_free(displays);
vargs.emplace_back((double)(displayindex + 1));
#else
vargs.emplace_back((double)(e.display.display + 1));
#endif
vargs.emplace_back(txt, strlen(txt));
msg = new Message("displayrotated", vargs);
}
break;
case SDL_DROPFILE:
case SDL_EVENT_DROP_FILE:
filesystem = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
if (filesystem != nullptr)
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
const char *filepath = e.drop.data;
#else
const char *filepath = e.drop.file;
#endif
// Allow mounting any dropped path, so zips or dirs can be mounted.
filesystem->allowMountingForPath(e.drop.file);
filesystem->allowMountingForPath(filepath);
if (filesystem->isRealDirectory(e.drop.file))
if (filesystem->isRealDirectory(filepath))
{
vargs.emplace_back(e.drop.file, strlen(e.drop.file));
vargs.emplace_back(filepath, strlen(filepath));
msg = new Message("directorydropped", vargs);
}
else
{
auto *file = new love::filesystem::NativeFile(e.drop.file, love::filesystem::File::MODE_CLOSED);
auto *file = new love::filesystem::NativeFile(filepath, love::filesystem::File::MODE_CLOSED);
vargs.emplace_back(&love::filesystem::NativeFile::type, file);
msg = new Message("filedropped", vargs);
file->release();
}
}
#if !SDL_VERSION_ATLEAST(3, 0, 0)
SDL_free(e.drop.file);
#endif
break;
case SDL_QUIT:
case SDL_APP_TERMINATING:
case SDL_EVENT_QUIT:
case SDL_EVENT_TERMINATING:
msg = new Message("quit");
break;
case SDL_APP_LOWMEMORY:
case SDL_EVENT_LOW_MEMORY:
msg = new Message("lowmemory");
break;
#if SDL_VERSION_ATLEAST(2, 0, 14)
case SDL_LOCALECHANGED:
case SDL_EVENT_LOCALE_CHANGED:
msg = new Message("localechanged");
break;
#endif
case SDL_SENSORUPDATE:
case SDL_EVENT_SENSOR_UPDATE:
sensorInstance = Module::getInstance<sensor::Sensor>(M_SENSOR);
if (sensorInstance)
{
@@ -467,13 +550,22 @@ Message *Event::convert(const SDL_Event &e)
for (void *s: sensors)
{
SDL_Sensor *sensor = (SDL_Sensor *) s;
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_SensorID id = SDL_GetSensorInstanceID(sensor);
#else
SDL_SensorID id = SDL_SensorGetInstanceID(sensor);
#endif
if (e.sensor.which == id)
{
// Found sensor
const char *sensorType;
if (!sensor::Sensor::getConstant(sensor::sdl::Sensor::convert(SDL_SensorGetType(sensor)), sensorType))
#if SDL_VERSION_ATLEAST(3, 0, 0)
auto sdltype = SDL_GetSensorType(sensor);
#else
auto sdltype = SDL_SensorGetType(sensor);
#endif
if (!sensor::Sensor::getConstant(sensor::sdl::Sensor::convert(sdltype), sensorType))
sensorType = "unknown";
vargs.emplace_back(sensorType, strlen(sensorType));
@@ -516,19 +608,19 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
switch (e.type)
{
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
stick = joymodule->getJoystickFromID(e.jbutton.which);
if (!stick)
break;
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back((double)(e.jbutton.button+1));
msg = new Message((e.type == SDL_JOYBUTTONDOWN) ?
msg = new Message((e.type == SDL_EVENT_JOYSTICK_BUTTON_DOWN) ?
"joystickpressed" : "joystickreleased",
vargs);
break;
case SDL_JOYAXISMOTION:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
{
stick = joymodule->getJoystickFromID(e.jaxis.which);
if (!stick)
@@ -541,7 +633,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
msg = new Message("joystickaxis", vargs);
}
break;
case SDL_JOYHATMOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
if (!joystick::sdl::Joystick::getConstant(e.jhat.value, hat) || !joystick::Joystick::getConstant(hat, txt))
break;
@@ -554,41 +646,59 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
vargs.emplace_back(txt, strlen(txt));
msg = new Message("joystickhat", vargs);
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
if (!joystick::sdl::Joystick::getConstant((SDL_GameControllerButton) e.cbutton.button, padbutton))
break;
if (!joystick::Joystick::getConstant(padbutton, txt))
break;
stick = joymodule->getJoystickFromID(e.cbutton.which);
if (!stick)
break;
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back(txt, strlen(txt));
msg = new Message(e.type == SDL_CONTROLLERBUTTONDOWN ?
"gamepadpressed" : "gamepadreleased", vargs);
break;
case SDL_CONTROLLERAXISMOTION:
if (joystick::sdl::Joystick::getConstant((SDL_GameControllerAxis) e.caxis.axis, padaxis))
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
{
if (!joystick::Joystick::getConstant(padaxis, txt))
#if SDL_VERSION_ATLEAST(3, 0, 0)
const auto &b = e.gbutton;
if (!joystick::sdl::Joystick::getConstant((SDL_GamepadButton) b.button, padbutton))
#else
const auto &b = e.cbutton;
if (!joystick::sdl::Joystick::getConstant((SDL_GameControllerButton) b.button, padbutton))
#endif
break;
stick = joymodule->getJoystickFromID(e.caxis.which);
if (!joystick::Joystick::getConstant(padbutton, txt))
break;
stick = joymodule->getJoystickFromID(b.which);
if (!stick)
break;
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back(txt, strlen(txt));
float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
msg = new Message(e.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN ?
"gamepadpressed" : "gamepadreleased", vargs);
}
break;
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (joystick::sdl::Joystick::getConstant((SDL_GamepadAxis) e.gaxis.axis, padaxis))
#else
if (joystick::sdl::Joystick::getConstant((SDL_GameControllerAxis) e.caxis.axis, padaxis))
#endif
{
if (!joystick::Joystick::getConstant(padaxis, txt))
break;
#if SDL_VERSION_ATLEAST(3, 0, 0)
const auto &a = e.gaxis;
#else
const auto &a = e.caxis;
#endif
stick = joymodule->getJoystickFromID(a.which);
if (!stick)
break;
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back(txt, strlen(txt));
float value = joystick::Joystick::clampval(a.value / 32768.0f);
vargs.emplace_back((double) value);
msg = new Message("gamepadaxis", vargs);
}
break;
case SDL_JOYDEVICEADDED:
case SDL_EVENT_JOYSTICK_ADDED:
// jdevice.which is the joystick device index.
stick = joymodule->addJoystick(e.jdevice.which);
if (stick)
@@ -597,7 +707,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
msg = new Message("joystickadded", vargs);
}
break;
case SDL_JOYDEVICEREMOVED:
case SDL_EVENT_JOYSTICK_REMOVED:
// jdevice.which is the joystick instance ID now.
stick = joymodule->getJoystickFromID(e.jdevice.which);
if (stick)
@@ -608,23 +718,30 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
}
break;
#if SDL_VERSION_ATLEAST(2, 0, 14) && defined(LOVE_ENABLE_SENSOR)
case SDL_CONTROLLERSENSORUPDATE:
stick = joymodule->getJoystickFromID(e.csensor.which);
if (stick)
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE:
{
using Sensor = love::sensor::Sensor;
#if SDL_VERSION_ATLEAST(3, 0, 0)
const auto &sens = e.gsensor;
#else
const auto &sens = e.csensor;
#endif
stick = joymodule->getJoystickFromID(sens.which);
if (stick)
{
using Sensor = love::sensor::Sensor;
const char *sensorName;
Sensor::SensorType sensorType = love::sensor::sdl::Sensor::convert((SDL_SensorType) e.csensor.sensor);
if (!Sensor::getConstant(sensorType, sensorName))
sensorName = "unknown";
const char *sensorName;
Sensor::SensorType sensorType = love::sensor::sdl::Sensor::convert((SDL_SensorType) sens.sensor);
if (!Sensor::getConstant(sensorType, sensorName))
sensorName = "unknown";
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back(sensorName, strlen(sensorName));
vargs.emplace_back(e.csensor.data[0]);
vargs.emplace_back(e.csensor.data[1]);
vargs.emplace_back(e.csensor.data[2]);
msg = new Message("joysticksensorupdated", vargs);
vargs.emplace_back(joysticktype, stick);
vargs.emplace_back(sensorName, strlen(sensorName));
vargs.emplace_back(sens.data[0]);
vargs.emplace_back(sens.data[1]);
vargs.emplace_back(sens.data[2]);
msg = new Message("joysticksensorupdated", vargs);
}
}
break;
#endif // SDL_VERSION_ATLEAST(2, 0, 14) && defined(LOVE_ENABLE_SENSOR)
@@ -645,27 +762,30 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
window::Window *win = nullptr;
graphics::Graphics *gfx = nullptr;
if (e.type != SDL_WINDOWEVENT)
return nullptr;
#if SDL_VERSION_ATLEAST(3, 0, 0)
auto event = e.type;
#else
auto event = e.window.event;
#endif
switch (e.window.event)
switch (event)
{
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED);
case SDL_EVENT_WINDOW_FOCUS_GAINED:
case SDL_EVENT_WINDOW_FOCUS_LOST:
vargs.emplace_back(event == SDL_EVENT_WINDOW_FOCUS_GAINED);
msg = new Message("focus", vargs);
break;
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_LEAVE:
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_ENTER);
case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
vargs.emplace_back(event == SDL_EVENT_WINDOW_MOUSE_ENTER);
msg = new Message("mousefocus", vargs);
break;
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_HIDDEN:
vargs.emplace_back(e.window.event == SDL_WINDOWEVENT_SHOWN);
case SDL_EVENT_WINDOW_SHOWN:
case SDL_EVENT_WINDOW_HIDDEN:
vargs.emplace_back(event == SDL_EVENT_WINDOW_SHOWN);
msg = new Message("visible", vargs);
break;
case SDL_WINDOWEVENT_RESIZED:
case SDL_EVENT_WINDOW_RESIZED:
{
double width = e.window.data1;
double height = e.window.data2;
@@ -693,19 +813,19 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
msg = new Message("resize", vargs);
}
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
win = Module::getInstance<window::Window>(Module::M_WINDOW);
if (win)
win->onSizeChanged(e.window.data1, e.window.data2);
break;
case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_RESTORED:
case SDL_EVENT_WINDOW_MINIMIZED:
case SDL_EVENT_WINDOW_RESTORED:
#ifdef LOVE_ANDROID
if (auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO))
{
if (e.window.event == SDL_WINDOWEVENT_MINIMIZED)
if (event == SDL_EVENT_WINDOW_MINIMIZED)
audio->pauseContext();
else if (e.window.event == SDL_WINDOWEVENT_RESTORED)
else if (event == SDL_EVENT_WINDOW_RESTORED)
audio->resumeContext();
}
#endif
@@ -715,226 +835,6 @@ Message *Event::convertWindowEvent(const SDL_Event &e)
return msg;
}
std::map<SDL_Keycode, love::keyboard::Keyboard::Key> Event::createKeyMap()
{
using love::keyboard::Keyboard;
std::map<SDL_Keycode, Keyboard::Key> k;
k[SDLK_UNKNOWN] = Keyboard::KEY_UNKNOWN;
k[SDLK_RETURN] = Keyboard::KEY_RETURN;
k[SDLK_ESCAPE] = Keyboard::KEY_ESCAPE;
k[SDLK_BACKSPACE] = Keyboard::KEY_BACKSPACE;
k[SDLK_TAB] = Keyboard::KEY_TAB;
k[SDLK_SPACE] = Keyboard::KEY_SPACE;
k[SDLK_EXCLAIM] = Keyboard::KEY_EXCLAIM;
k[SDLK_QUOTEDBL] = Keyboard::KEY_QUOTEDBL;
k[SDLK_HASH] = Keyboard::KEY_HASH;
k[SDLK_PERCENT] = Keyboard::KEY_PERCENT;
k[SDLK_DOLLAR] = Keyboard::KEY_DOLLAR;
k[SDLK_AMPERSAND] = Keyboard::KEY_AMPERSAND;
k[SDLK_QUOTE] = Keyboard::KEY_QUOTE;
k[SDLK_LEFTPAREN] = Keyboard::KEY_LEFTPAREN;
k[SDLK_RIGHTPAREN] = Keyboard::KEY_RIGHTPAREN;
k[SDLK_ASTERISK] = Keyboard::KEY_ASTERISK;
k[SDLK_PLUS] = Keyboard::KEY_PLUS;
k[SDLK_COMMA] = Keyboard::KEY_COMMA;
k[SDLK_MINUS] = Keyboard::KEY_MINUS;
k[SDLK_PERIOD] = Keyboard::KEY_PERIOD;
k[SDLK_SLASH] = Keyboard::KEY_SLASH;
k[SDLK_0] = Keyboard::KEY_0;
k[SDLK_1] = Keyboard::KEY_1;
k[SDLK_2] = Keyboard::KEY_2;
k[SDLK_3] = Keyboard::KEY_3;
k[SDLK_4] = Keyboard::KEY_4;
k[SDLK_5] = Keyboard::KEY_5;
k[SDLK_6] = Keyboard::KEY_6;
k[SDLK_7] = Keyboard::KEY_7;
k[SDLK_8] = Keyboard::KEY_8;
k[SDLK_9] = Keyboard::KEY_9;
k[SDLK_COLON] = Keyboard::KEY_COLON;
k[SDLK_SEMICOLON] = Keyboard::KEY_SEMICOLON;
k[SDLK_LESS] = Keyboard::KEY_LESS;
k[SDLK_EQUALS] = Keyboard::KEY_EQUALS;
k[SDLK_GREATER] = Keyboard::KEY_GREATER;
k[SDLK_QUESTION] = Keyboard::KEY_QUESTION;
k[SDLK_AT] = Keyboard::KEY_AT;
k[SDLK_LEFTBRACKET] = Keyboard::KEY_LEFTBRACKET;
k[SDLK_BACKSLASH] = Keyboard::KEY_BACKSLASH;
k[SDLK_RIGHTBRACKET] = Keyboard::KEY_RIGHTBRACKET;
k[SDLK_CARET] = Keyboard::KEY_CARET;
k[SDLK_UNDERSCORE] = Keyboard::KEY_UNDERSCORE;
k[SDLK_BACKQUOTE] = Keyboard::KEY_BACKQUOTE;
k[SDLK_a] = Keyboard::KEY_A;
k[SDLK_b] = Keyboard::KEY_B;
k[SDLK_c] = Keyboard::KEY_C;
k[SDLK_d] = Keyboard::KEY_D;
k[SDLK_e] = Keyboard::KEY_E;
k[SDLK_f] = Keyboard::KEY_F;
k[SDLK_g] = Keyboard::KEY_G;
k[SDLK_h] = Keyboard::KEY_H;
k[SDLK_i] = Keyboard::KEY_I;
k[SDLK_j] = Keyboard::KEY_J;
k[SDLK_k] = Keyboard::KEY_K;
k[SDLK_l] = Keyboard::KEY_L;
k[SDLK_m] = Keyboard::KEY_M;
k[SDLK_n] = Keyboard::KEY_N;
k[SDLK_o] = Keyboard::KEY_O;
k[SDLK_p] = Keyboard::KEY_P;
k[SDLK_q] = Keyboard::KEY_Q;
k[SDLK_r] = Keyboard::KEY_R;
k[SDLK_s] = Keyboard::KEY_S;
k[SDLK_t] = Keyboard::KEY_T;
k[SDLK_u] = Keyboard::KEY_U;
k[SDLK_v] = Keyboard::KEY_V;
k[SDLK_w] = Keyboard::KEY_W;
k[SDLK_x] = Keyboard::KEY_X;
k[SDLK_y] = Keyboard::KEY_Y;
k[SDLK_z] = Keyboard::KEY_Z;
k[SDLK_CAPSLOCK] = Keyboard::KEY_CAPSLOCK;
k[SDLK_F1] = Keyboard::KEY_F1;
k[SDLK_F2] = Keyboard::KEY_F2;
k[SDLK_F3] = Keyboard::KEY_F3;
k[SDLK_F4] = Keyboard::KEY_F4;
k[SDLK_F5] = Keyboard::KEY_F5;
k[SDLK_F6] = Keyboard::KEY_F6;
k[SDLK_F7] = Keyboard::KEY_F7;
k[SDLK_F8] = Keyboard::KEY_F8;
k[SDLK_F9] = Keyboard::KEY_F9;
k[SDLK_F10] = Keyboard::KEY_F10;
k[SDLK_F11] = Keyboard::KEY_F11;
k[SDLK_F12] = Keyboard::KEY_F12;
k[SDLK_PRINTSCREEN] = Keyboard::KEY_PRINTSCREEN;
k[SDLK_SCROLLLOCK] = Keyboard::KEY_SCROLLLOCK;
k[SDLK_PAUSE] = Keyboard::KEY_PAUSE;
k[SDLK_INSERT] = Keyboard::KEY_INSERT;
k[SDLK_HOME] = Keyboard::KEY_HOME;
k[SDLK_PAGEUP] = Keyboard::KEY_PAGEUP;
k[SDLK_DELETE] = Keyboard::KEY_DELETE;
k[SDLK_END] = Keyboard::KEY_END;
k[SDLK_PAGEDOWN] = Keyboard::KEY_PAGEDOWN;
k[SDLK_RIGHT] = Keyboard::KEY_RIGHT;
k[SDLK_LEFT] = Keyboard::KEY_LEFT;
k[SDLK_DOWN] = Keyboard::KEY_DOWN;
k[SDLK_UP] = Keyboard::KEY_UP;
k[SDLK_NUMLOCKCLEAR] = Keyboard::KEY_NUMLOCKCLEAR;
k[SDLK_KP_DIVIDE] = Keyboard::KEY_KP_DIVIDE;
k[SDLK_KP_MULTIPLY] = Keyboard::KEY_KP_MULTIPLY;
k[SDLK_KP_MINUS] = Keyboard::KEY_KP_MINUS;
k[SDLK_KP_PLUS] = Keyboard::KEY_KP_PLUS;
k[SDLK_KP_ENTER] = Keyboard::KEY_KP_ENTER;
k[SDLK_KP_0] = Keyboard::KEY_KP_0;
k[SDLK_KP_1] = Keyboard::KEY_KP_1;
k[SDLK_KP_2] = Keyboard::KEY_KP_2;
k[SDLK_KP_3] = Keyboard::KEY_KP_3;
k[SDLK_KP_4] = Keyboard::KEY_KP_4;
k[SDLK_KP_5] = Keyboard::KEY_KP_5;
k[SDLK_KP_6] = Keyboard::KEY_KP_6;
k[SDLK_KP_7] = Keyboard::KEY_KP_7;
k[SDLK_KP_8] = Keyboard::KEY_KP_8;
k[SDLK_KP_9] = Keyboard::KEY_KP_9;
k[SDLK_KP_PERIOD] = Keyboard::KEY_KP_PERIOD;
k[SDLK_KP_COMMA] = Keyboard::KEY_KP_COMMA;
k[SDLK_KP_EQUALS] = Keyboard::KEY_KP_EQUALS;
k[SDLK_APPLICATION] = Keyboard::KEY_APPLICATION;
k[SDLK_POWER] = Keyboard::KEY_POWER;
k[SDLK_F13] = Keyboard::KEY_F13;
k[SDLK_F14] = Keyboard::KEY_F14;
k[SDLK_F15] = Keyboard::KEY_F15;
k[SDLK_F16] = Keyboard::KEY_F16;
k[SDLK_F17] = Keyboard::KEY_F17;
k[SDLK_F18] = Keyboard::KEY_F18;
k[SDLK_F19] = Keyboard::KEY_F19;
k[SDLK_F20] = Keyboard::KEY_F20;
k[SDLK_F21] = Keyboard::KEY_F21;
k[SDLK_F22] = Keyboard::KEY_F22;
k[SDLK_F23] = Keyboard::KEY_F23;
k[SDLK_F24] = Keyboard::KEY_F24;
k[SDLK_EXECUTE] = Keyboard::KEY_EXECUTE;
k[SDLK_HELP] = Keyboard::KEY_HELP;
k[SDLK_MENU] = Keyboard::KEY_MENU;
k[SDLK_SELECT] = Keyboard::KEY_SELECT;
k[SDLK_STOP] = Keyboard::KEY_STOP;
k[SDLK_AGAIN] = Keyboard::KEY_AGAIN;
k[SDLK_UNDO] = Keyboard::KEY_UNDO;
k[SDLK_CUT] = Keyboard::KEY_CUT;
k[SDLK_COPY] = Keyboard::KEY_COPY;
k[SDLK_PASTE] = Keyboard::KEY_PASTE;
k[SDLK_FIND] = Keyboard::KEY_FIND;
k[SDLK_MUTE] = Keyboard::KEY_MUTE;
k[SDLK_VOLUMEUP] = Keyboard::KEY_VOLUMEUP;
k[SDLK_VOLUMEDOWN] = Keyboard::KEY_VOLUMEDOWN;
k[SDLK_ALTERASE] = Keyboard::KEY_ALTERASE;
k[SDLK_SYSREQ] = Keyboard::KEY_SYSREQ;
k[SDLK_CANCEL] = Keyboard::KEY_CANCEL;
k[SDLK_CLEAR] = Keyboard::KEY_CLEAR;
k[SDLK_PRIOR] = Keyboard::KEY_PRIOR;
k[SDLK_RETURN2] = Keyboard::KEY_RETURN2;
k[SDLK_SEPARATOR] = Keyboard::KEY_SEPARATOR;
k[SDLK_OUT] = Keyboard::KEY_OUT;
k[SDLK_OPER] = Keyboard::KEY_OPER;
k[SDLK_CLEARAGAIN] = Keyboard::KEY_CLEARAGAIN;
k[SDLK_THOUSANDSSEPARATOR] = Keyboard::KEY_THOUSANDSSEPARATOR;
k[SDLK_DECIMALSEPARATOR] = Keyboard::KEY_DECIMALSEPARATOR;
k[SDLK_CURRENCYUNIT] = Keyboard::KEY_CURRENCYUNIT;
k[SDLK_CURRENCYSUBUNIT] = Keyboard::KEY_CURRENCYSUBUNIT;
k[SDLK_LCTRL] = Keyboard::KEY_LCTRL;
k[SDLK_LSHIFT] = Keyboard::KEY_LSHIFT;
k[SDLK_LALT] = Keyboard::KEY_LALT;
k[SDLK_LGUI] = Keyboard::KEY_LGUI;
k[SDLK_RCTRL] = Keyboard::KEY_RCTRL;
k[SDLK_RSHIFT] = Keyboard::KEY_RSHIFT;
k[SDLK_RALT] = Keyboard::KEY_RALT;
k[SDLK_RGUI] = Keyboard::KEY_RGUI;
k[SDLK_MODE] = Keyboard::KEY_MODE;
k[SDLK_AUDIONEXT] = Keyboard::KEY_AUDIONEXT;
k[SDLK_AUDIOPREV] = Keyboard::KEY_AUDIOPREV;
k[SDLK_AUDIOSTOP] = Keyboard::KEY_AUDIOSTOP;
k[SDLK_AUDIOPLAY] = Keyboard::KEY_AUDIOPLAY;
k[SDLK_AUDIOMUTE] = Keyboard::KEY_AUDIOMUTE;
k[SDLK_MEDIASELECT] = Keyboard::KEY_MEDIASELECT;
k[SDLK_WWW] = Keyboard::KEY_WWW;
k[SDLK_MAIL] = Keyboard::KEY_MAIL;
k[SDLK_CALCULATOR] = Keyboard::KEY_CALCULATOR;
k[SDLK_COMPUTER] = Keyboard::KEY_COMPUTER;
k[SDLK_AC_SEARCH] = Keyboard::KEY_APP_SEARCH;
k[SDLK_AC_HOME] = Keyboard::KEY_APP_HOME;
k[SDLK_AC_BACK] = Keyboard::KEY_APP_BACK;
k[SDLK_AC_FORWARD] = Keyboard::KEY_APP_FORWARD;
k[SDLK_AC_STOP] = Keyboard::KEY_APP_STOP;
k[SDLK_AC_REFRESH] = Keyboard::KEY_APP_REFRESH;
k[SDLK_AC_BOOKMARKS] = Keyboard::KEY_APP_BOOKMARKS;
k[SDLK_BRIGHTNESSDOWN] = Keyboard::KEY_BRIGHTNESSDOWN;
k[SDLK_BRIGHTNESSUP] = Keyboard::KEY_BRIGHTNESSUP;
k[SDLK_DISPLAYSWITCH] = Keyboard::KEY_DISPLAYSWITCH;
k[SDLK_KBDILLUMTOGGLE] = Keyboard::KEY_KBDILLUMTOGGLE;
k[SDLK_KBDILLUMDOWN] = Keyboard::KEY_KBDILLUMDOWN;
k[SDLK_KBDILLUMUP] = Keyboard::KEY_KBDILLUMUP;
k[SDLK_EJECT] = Keyboard::KEY_EJECT;
k[SDLK_SLEEP] = Keyboard::KEY_SLEEP;
#ifdef LOVE_ANDROID
k[SDLK_AC_BACK] = Keyboard::KEY_ESCAPE;
#endif
return k;
}
std::map<SDL_Keycode, love::keyboard::Keyboard::Key> Event::keys = Event::createKeyMap();
} // sdl
} // event
} // love
+1 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -28,9 +28,6 @@
// SDL
#include <SDL_events.h>
// STL
#include <map>
namespace love
{
namespace event
@@ -42,9 +39,6 @@ class Event : public love::event::Event
{
public:
// Implements Module.
const char *getName() const;
Event();
virtual ~Event();
@@ -75,9 +69,6 @@ private:
Message *convertJoystickEvent(const SDL_Event &e) const;
Message *convertWindowEvent(const SDL_Event &e);
static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> createKeyMap();
static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> keys;
}; // Event
} // sdl
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -3,7 +3,7 @@ R"luastring"--(
-- There is a matching delimiter at the bottom of the file.
--[[
Copyright (c) 2006-2023 LOVE Development Team
Copyright (c) 2006-2024 LOVE Development Team
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+18 -3
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -45,7 +45,8 @@ namespace filesystem
love::Type Filesystem::type("filesystem", &Module::type);
Filesystem::Filesystem()
Filesystem::Filesystem(const char *name)
: Module(M_FILESYSTEM, name)
{
}
@@ -132,7 +133,21 @@ static bool createDirectoryRaw(const std::string &path)
std::wstring wpath = to_widestr(path);
return CreateDirectoryW(wpath.c_str(), nullptr) != 0;
#else
return mkdir(path.c_str(), S_IRWXU) == 0;
int mode = S_IRWXU;
#ifdef LOVE_ANDROID
// Need to create save directory with ugo+rwx and setgid bit if
// t.externalstorage is set and it's for save directory.
auto fs = Module::getInstance<Filesystem>(Module::M_FILESYSTEM);
if (fs != nullptr && fs->isAndroidSaveExternal())
{
const std::string &savedir = fs->getFullCommonPath(Filesystem::COMMONPATH_APP_SAVEDIR);
if (path.rfind(savedir, 0) == 0)
mode |= S_IRWXG | S_IRWXO | S_ISGID;
}
#endif
return mkdir(path.c_str(), mode) == 0;
#endif
}
+5 -5
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -108,12 +108,8 @@ public:
static love::Type type;
Filesystem();
virtual ~Filesystem();
// Implements Module.
virtual ModuleType getModuleType() const { return M_FILESYSTEM; }
virtual void init(const char *arg0) = 0;
virtual void setFused(bool fused) = 0;
@@ -317,6 +313,10 @@ public:
STRINGMAP_CLASS_DECLARE(MountPermissions);
STRINGMAP_CLASS_DECLARE(LoadMode);
protected:
Filesystem(const char *name);
private:
bool getRealPathType(const std::string &path, FileType &ftype) const;
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+20 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -27,6 +27,10 @@
#include "Filesystem.h"
#include "filesystem/FileData.h"
#ifdef LOVE_ANDROID
#include "common/android.h"
#endif
namespace love
{
namespace filesystem
@@ -50,6 +54,21 @@ File::File(const std::string &filename, Mode mode)
{
if (!open(mode))
throw love::Exception("Could not open file at path %s", filename.c_str());
#ifdef LOVE_ANDROID
// In Android with t.externalstorage = true, make sure the file opened or
// created in the save directory has permissions of ugo+rw (0666) so that
// it's accessible through MTP.
auto fs = Module::getInstance<love::filesystem::Filesystem>(Module::M_FILESYSTEM);
if (fs != nullptr && fs->isAndroidSaveExternal())
{
const char *realdir = PHYSFS_getRealDir(filename.c_str());
const std::string &savedir = fs->getFullCommonPath(Filesystem::COMMONPATH_APP_SAVEDIR);
if (realdir != nullptr && strcmp(realdir, savedir.c_str()) == 0)
love::android::fixupPermissionSingleFile(savedir, filename);
}
#endif
}
File::File(const File &other)
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+27 -8
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -107,7 +107,8 @@ static bool isAppCommonPath(Filesystem::CommonPath path)
}
Filesystem::Filesystem()
: appendIdentityToPath(false)
: love::filesystem::Filesystem("love.filesystem.physfs")
, appendIdentityToPath(false)
, fused(false)
, fusedSet(false)
, fullPaths()
@@ -128,11 +129,6 @@ Filesystem::~Filesystem()
PHYSFS_deinit();
}
const char *Filesystem::getName() const
{
return "love.filesystem.physfs";
}
void Filesystem::init(const char *arg0)
{
#ifdef LOVE_ANDROID
@@ -194,6 +190,11 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
// These will be re-populated by getFullCommonPath.
for (CommonPath p : appCommonPaths)
fullPaths[p].clear();
#ifdef LOVE_ANDROID
// Ensure COMMONPATH_USER_APPDATA is also cleared in Android to ensure
// `t.externalstorage` works as expected.
fullPaths[COMMONPATH_USER_APPDATA].clear();
#endif
// Store the save directory. getFullCommonPath(COMMONPATH_APP_*) uses this.
saveIdentity = std::string(ident);
@@ -249,8 +250,14 @@ bool Filesystem::setSource(const char *source)
if (hasFusedGame)
{
if (gameLoveIO)
// Actually we should just be able to mount gameLoveIO, but that's experimental.
{
if (PHYSFS_mountIo(gameLoveIO, ".zip", nullptr, 0)) {
gameSource = new_search_path;
return true;
}
gameLoveIO->destroy(gameLoveIO);
}
else
{
if (!love::android::initializeVirtualArchive())
@@ -278,6 +285,8 @@ bool Filesystem::setSource(const char *source)
gameSource = new_search_path;
return true;
}
io->destroy(io);
}
}
#endif
@@ -792,6 +801,16 @@ bool Filesystem::createDirectory(const char *dir)
if (!PHYSFS_mkdir(dir))
return false;
#ifdef LOVE_ANDROID
// In Android with t.externalstorage = true, make sure the directory
// created in the save directory has permissions of ugo+rwx (0777) so that
// it's accessible through MTP.
if (isAndroidSaveExternal())
love::android::fixupExternalStoragePermission(
getFullCommonPath(CommonPath::COMMONPATH_APP_SAVEDIR),
dir
);
#endif
return true;
}
+1 -4
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -43,9 +43,6 @@ public:
Filesystem();
virtual ~Filesystem();
// Implements Module.
const char *getName() const override;
void init(const char *arg0) override;
void setFused(bool fused) override;
+29 -55
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,7 +18,6 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include <cassert>
#include <algorithm>
#include "PhysfsIo.h"
@@ -32,14 +31,15 @@ namespace physfs
bool StripSuffixIo::determineStrippedLength()
{
if (!file) {
if (!file)
return false;
}
const int64_t fullSize = fullLength();
int64_t chunkSize = std::min(fullSize, (int64_t)8192);
const int64 fullSize = file->getSize();
int64 chunkSize = std::min(fullSize, (int64) 8192);
std::string buffer;
buffer.reserve(chunkSize);
int64_t i = fullSize - chunkSize;
int64 i = fullSize - chunkSize;
// I don't think we really need to go through the whole file. The main known use
// case for this functionality is to skip windows codesign signatures, which are
// from what I have seen ~12KB or so, but trying is better than just failing.
@@ -64,7 +64,7 @@ bool StripSuffixIo::determineStrippedLength()
}
if (i == 0)
break;
i = std::max((int64_t)0, i - chunkSize);
i = std::max((int64)0, i - chunkSize);
}
if (i > 0)
@@ -75,7 +75,7 @@ bool StripSuffixIo::determineStrippedLength()
// The comment length (u16) is located 20 bytes from the start of the EOCD record
if (seek(i + 20) == 0)
return false;
uint8_t buffer[2];
uint8 buffer[2];
const auto n = read(buffer, 2);
if (n <= 0)
return false;
@@ -96,17 +96,17 @@ bool StripSuffixIo::determineStrippedLength()
return true;
}
int64_t StripSuffixIo::read(void* buf, uint64_t len)
int64 StripSuffixIo::read(void *buf, uint64 len)
{
if (!file)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
const auto ret = std::fread(buf, 1, len, file);
if (ret == 0)
int64 r = file->read(buf, (int64) len);
if (r == 0)
{
if (std::feof(file))
if (file->isEOF())
{
PHYSFS_setErrorCode(PHYSFS_ERR_OK);
return 0;
@@ -117,85 +117,59 @@ int64_t StripSuffixIo::read(void* buf, uint64_t len)
return -1;
}
}
else if (ret < len && std::ferror(file))
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
PHYSFS_setErrorCode(PHYSFS_ERR_OK);
return ret;
return r;
}
int64_t StripSuffixIo::write(const void* /*buf*/, uint64_t /*len*/)
int64 StripSuffixIo::write(const void */*buf*/, uint64 /*len*/)
{
PHYSFS_setErrorCode(PHYSFS_ERR_READ_ONLY);
return -1;
}
int64_t StripSuffixIo::seek(uint64_t offset)
int64 StripSuffixIo::seek(uint64 offset)
{
if (!file)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return 0;
}
const auto ret = std::fseek(file, offset, SEEK_SET);
PHYSFS_setErrorCode(ret != 0 ? PHYSFS_ERR_OS_ERROR : PHYSFS_ERR_OK);
return ret == 0 ? 1 : 0;
bool success = file->seek(offset, Stream::SEEKORIGIN_BEGIN);
PHYSFS_setErrorCode(success ? PHYSFS_ERR_OK : PHYSFS_ERR_OS_ERROR);
return success ? 1 : 0;
}
int64_t StripSuffixIo::tell()
int64 StripSuffixIo::tell()
{
if (!file)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
return std::ftell(file);
return file->tell();
}
int64_t StripSuffixIo::length()
int64 StripSuffixIo::length()
{
return strippedLength_;
}
int64_t StripSuffixIo::flush()
int64 StripSuffixIo::flush()
{
if (!file)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return 0;
}
return std::fflush(file) == 0 ? 1 : 0;
}
int64_t StripSuffixIo::fullLength()
{
assert(file);
const auto cur = std::ftell(file);
if (cur == -1)
try
{
return file->flush() ? 1 : 0;
}
catch (love::Exception &)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
return 0;
}
if (std::fseek(file, 0, SEEK_END) != 0)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
const auto len = std::ftell(file);
if (len == -1)
{
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
if (std::fseek(file, cur, SEEK_SET) != 0)
{
// We do have the length now, but something is wrong, so we return an error anyways
PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR);
return -1;
}
return len;
}
} // physfs
+35 -30
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -21,11 +21,11 @@
#ifndef LOVE_FILESYSTEM_PHYSFS_PHYSFSIO_H
#define LOVE_FILESYSTEM_PHYSFS_PHYSFSIO_H
#include <cstdint>
#include <cstdio>
#include <string>
#include "libraries/physfs/physfs.h"
#include "common/int.h"
#include "filesystem/NativeFile.h"
#include <string>
namespace love
{
@@ -61,54 +61,54 @@ protected:
private:
// Returns: number of bytes read, 0 on EOF, -1 on failure
static PHYSFS_sint64 staticRead(struct PHYSFS_Io* io, void* buf, PHYSFS_uint64 len)
static PHYSFS_sint64 staticRead(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
{
return derived(io)->read(buf, len);
}
// Returns: number of bytes written, -1 on failure
static PHYSFS_sint64 staticWrite(struct PHYSFS_Io* io, const void* buf, PHYSFS_uint64 len)
static PHYSFS_sint64 staticWrite(struct PHYSFS_Io *io, const void *buf, PHYSFS_uint64 len)
{
return derived(io)->write(buf, len);
}
// Returns: non-zero on success, zero on error
static int staticSeek(struct PHYSFS_Io* io, PHYSFS_uint64 offset)
static int staticSeek(struct PHYSFS_Io *io, PHYSFS_uint64 offset)
{
return derived(io)->seek(offset);
}
// Returns: current offset from start, -1 on error
static PHYSFS_sint64 staticTell(struct PHYSFS_Io* io)
static PHYSFS_sint64 staticTell(struct PHYSFS_Io *io)
{
return derived(io)->tell();
}
// Returns: total size in bytes, -1 on error
static PHYSFS_sint64 staticLength(struct PHYSFS_Io* io)
static PHYSFS_sint64 staticLength(struct PHYSFS_Io *io)
{
return derived(io)->length();
}
static struct PHYSFS_Io* staticDuplicate(struct PHYSFS_Io* io)
static struct PHYSFS_Io *staticDuplicate(struct PHYSFS_Io *io)
{
// Just use copy constructor
return new Derived(*derived(io));
}
// Returns: non-zero on success, zero on error
static int staticFlush(struct PHYSFS_Io* io)
static int staticFlush(struct PHYSFS_Io *io)
{
return derived(io)->flush();
}
static void staticDestroy(struct PHYSFS_Io* io)
static void staticDestroy(struct PHYSFS_Io *io)
{
// Just use destructor
delete derived(io);
}
static Derived* derived(PHYSFS_Io* io)
static Derived* derived(PHYSFS_Io *io)
{
return static_cast<Derived*>(reinterpret_cast<PhysfsIo*>(io->opaque));
}
@@ -116,47 +116,52 @@ private:
struct StripSuffixIo : public PhysfsIo<StripSuffixIo>
{
static const uint32_t version = 0;
static const uint32 version = 0;
std::string filename;
FILE* file = nullptr;
NativeFile *file = nullptr;
// The constructor is private in favor of this function to prevent stack allocation
// because Physfs will take ownership of this object and call destroy on it later.
static StripSuffixIo* create(std::string f) { return new StripSuffixIo(f); }
static StripSuffixIo *create(const std::string &f) { return new StripSuffixIo(f); }
virtual ~StripSuffixIo()
{
if (file)
{
std::fclose(file);
file->release();
}
}
StripSuffixIo(const StripSuffixIo& other)
StripSuffixIo(const StripSuffixIo &other)
: StripSuffixIo(other.filename)
{
}
bool determineStrippedLength();
int64_t read(void* buf, uint64_t len);
int64_t write(const void* buf, uint64_t len);
int64_t seek(uint64_t offset);
int64_t tell();
int64_t length();
int64_t flush();
int64 read(void *buf, uint64 len);
int64 write(const void *buf, uint64 len);
int64 seek(uint64 offset);
int64 tell();
int64 length();
int64 flush();
private:
StripSuffixIo(std::string f)
: filename(std::move(f))
, file(std::fopen(filename.c_str(), "rb"))
StripSuffixIo(const std::string &f)
: filename(f)
, file(nullptr)
{
try
{
file = new NativeFile(f, File::MODE_READ);
}
catch (love::Exception &)
{
}
}
int64_t fullLength();
int64_t strippedLength_ = -1;
};
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+8 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -35,6 +35,7 @@
// SDL
#include <SDL_loadso.h>
#include <SDL_version.h>
// STL
#include <vector>
@@ -987,7 +988,12 @@ int extloader(lua_State *L)
// We look for both loveopen_ and luaopen_, so libraries with specific love support
// can tell when they've been loaded by love.
void *func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str());
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_FunctionPointer func = nullptr;
#else
void *func = nullptr;
#endif
func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str());
if (!func)
func = SDL_LoadFunction(handle, ("luaopen_" + tokenized_function).c_str());
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+2 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -343,6 +343,7 @@ GlyphData *BMFontRasterizer::getGlyphDataForIndex(int index) const
uint8 *pixels = (uint8 *) g->getData();
const uint8 *ipixels = (const uint8 *) imagedata->getData();
// Always lock the mutex since the user can't know when to do it.
love::thread::Lock lock(imagedata->getMutex());
// Copy the subsection of the texture from the ImageData to the GlyphData.
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+6 -15
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -34,7 +34,8 @@ namespace font
// Default TrueType font, gzip-compressed.
#include "NotoSans-Regular.ttf.gzip.h"
Font::Font()
Font::Font(const char *name)
: Module(M_FONT, name)
{
auto compressedbytes = (const char *) NotoSans_Regular_ttf_gzip;
size_t compressedsize = NotoSans_Regular_ttf_gzip_len;
@@ -45,14 +46,9 @@ Font::Font()
defaultFontData.set(new data::ByteData(fontdata, rawsize, true), Acquire::NORETAIN);
}
Rasterizer *Font::newTrueTypeRasterizer(int size, TrueTypeRasterizer::Hinting hinting)
Rasterizer *Font::newTrueTypeRasterizer(int size, const TrueTypeRasterizer::Settings &settings)
{
return newTrueTypeRasterizer(defaultFontData.get(), size, hinting);
}
Rasterizer *Font::newTrueTypeRasterizer(int size, float dpiscale, TrueTypeRasterizer::Hinting hinting)
{
return newTrueTypeRasterizer(defaultFontData.get(), size, dpiscale, hinting);
return newTrueTypeRasterizer(defaultFontData.get(), size, settings);
}
Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images, float dpiscale)
@@ -78,12 +74,7 @@ Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::st
throw love::Exception("UTF-8 decoding error: %s", e.what());
}
return newImageRasterizer(data, &glyphs[0], (int) glyphs.size(), extraspacing, dpiscale);
}
Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale)
{
return new ImageRasterizer(data, glyphs, numglyphs, extraspacing, dpiscale);
return new ImageRasterizer(data, glyphs.data(), (int) glyphs.size(), extraspacing, dpiscale);
}
GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text)
+6 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -43,27 +43,23 @@ class Font : public Module
public:
Font();
virtual ~Font() {}
virtual Rasterizer *newRasterizer(love::filesystem::FileData *data) = 0;
virtual Rasterizer *newTrueTypeRasterizer(int size, TrueTypeRasterizer::Hinting hinting);
virtual Rasterizer *newTrueTypeRasterizer(int size, float dpiscale, TrueTypeRasterizer::Hinting hinting);
virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, TrueTypeRasterizer::Hinting hinting) = 0;
virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, float dpiscale, TrueTypeRasterizer::Hinting hinting) = 0;
Rasterizer *newTrueTypeRasterizer(int size, const TrueTypeRasterizer::Settings &settings);
virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, const TrueTypeRasterizer::Settings &settings) = 0;
virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images, float dpiscale);
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs, int extraspacing, float dpiscale);
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length, int extraspacing, float dpiscale);
virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph);
virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph);
// Implement Module.
virtual ModuleType getModuleType() const { return M_FONT; }
virtual const char *getName() const = 0;
protected:
Font(const char *name);
private:
+28 -18
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -151,8 +151,7 @@ int GenericShaper::computeWordWrapIndex(const ColoredCodepoints &codepoints, Ran
float w = 0.0f;
float outwidth = 0.0f;
float widthbeforelastspace = 0.0f;
int wrapindex = -1;
int lastspaceindex = -1;
int firstindexafterspace = -1;
for (int i = (int)range.getMin(); i <= (int)range.getMax(); i++)
{
@@ -166,37 +165,48 @@ int GenericShaper::computeWordWrapIndex(const ColoredCodepoints &codepoints, Ran
float newwidth = w + getKerning(prevglyph, g) + getGlyphAdvance(g);
// Only wrap when there's a non-space character.
if (newwidth > wraplimit && !isWhitespace(g))
{
// Rewind to the last seen space when wrapping.
if (lastspaceindex != -1)
{
wrapindex = lastspaceindex;
outwidth = widthbeforelastspace;
}
break;
}
// Don't count trailing spaces in the output width.
if (isWhitespace(g))
{
lastspaceindex = i;
if (!isWhitespace(prevglyph))
widthbeforelastspace = w;
}
else
{
if (isWhitespace(prevglyph))
firstindexafterspace = i;
// Only wrap when there's a non-space character.
if (newwidth > wraplimit)
{
// If this is the first character, wrap from the next one instead of this one.
int wrapindex = i > (int)range.first ? i : (int)range.first + 1;
// Rewind to after the last seen space when wrapping.
if (firstindexafterspace != -1)
{
wrapindex = firstindexafterspace;
outwidth = widthbeforelastspace;
}
if (width)
*width = outwidth;
return wrapindex;
}
outwidth = newwidth;
}
w = newwidth;
prevglyph = g;
wrapindex = i;
}
if (width)
*width = outwidth;
return wrapindex;
// There wasn't any wrap in the middle of the range.
return range.last + 1;
}
} // font
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+2 -5
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -90,7 +90,7 @@ GlyphData *ImageRasterizer::getGlyphDataForIndex(int index) const
if (gm.width == 0)
return g;
// We don't want another thread modifying our ImageData mid-copy.
// Always lock the mutex since the user can't know when to do it.
love::thread::Lock lock(imageData->getMutex());
Color32 *gdpixels = (Color32 *) g->getData();
@@ -118,9 +118,6 @@ void ImageRasterizer::load(const uint32 *glyphs, int glyphcount)
int imgw = imageData->getWidth();
int imgh = imageData->getHeight();
// We don't want another thread modifying our ImageData mid-parse.
love::thread::Lock lock(imageData->getMutex());
// Set the only metric that matters
metrics.height = imgh;
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2023 LOVE Development Team
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages

Some files were not shown because too many files have changed in this diff Show More