From 98873b593a4c2110737a80b6816da1c0dee32cbf Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Mar 2014 02:55:03 -0300 Subject: [PATCH 01/24] Updated ENet to version 1.3.11 --- src/libraries/enet/libenet/ChangeLog | 6 ++++++ src/libraries/enet/libenet/include/enet/enet.h | 2 +- src/libraries/enet/libenet/include/enet/protocol.h | 4 ++-- src/libraries/enet/libenet/include/enet/unix.h | 2 +- src/libraries/enet/libenet/include/enet/win32.h | 2 +- src/libraries/enet/libenet/protocol.c | 5 +++-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libraries/enet/libenet/ChangeLog b/src/libraries/enet/libenet/ChangeLog index c8f91a090..5277b2c9a 100644 --- a/src/libraries/enet/libenet/ChangeLog +++ b/src/libraries/enet/libenet/ChangeLog @@ -1,3 +1,9 @@ +ENet 1.3.11 (December 26, 2013): + +* allow an ENetHost to connect to itself +* fixed possible bug with disconnect notifications during connect attempts +* fixed some preprocessor definition bugs + ENet 1.3.10 (October 23, 2013); * doubled maximum reliable window size diff --git a/src/libraries/enet/libenet/include/enet/enet.h b/src/libraries/enet/libenet/include/enet/enet.h index 4dda5517d..d5d5b8feb 100644 --- a/src/libraries/enet/libenet/include/enet/enet.h +++ b/src/libraries/enet/libenet/include/enet/enet.h @@ -25,7 +25,7 @@ extern "C" #define ENET_VERSION_MAJOR 1 #define ENET_VERSION_MINOR 3 -#define ENET_VERSION_PATCH 10 +#define ENET_VERSION_PATCH 11 #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch)) #define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF) #define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF) diff --git a/src/libraries/enet/libenet/include/enet/protocol.h b/src/libraries/enet/libenet/include/enet/protocol.h index b8f841629..a7c73c690 100644 --- a/src/libraries/enet/libenet/include/enet/protocol.h +++ b/src/libraries/enet/libenet/include/enet/protocol.h @@ -54,7 +54,7 @@ typedef enum _ENetProtocolFlag ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12 } ENetProtocolFlag; -#ifdef _MSC_VER_ +#ifdef _MSC_VER #pragma pack(push, 1) #define ENET_PACKED #elif defined(__GNUC__) || defined(__clang__) @@ -191,7 +191,7 @@ typedef union _ENetProtocol ENetProtocolThrottleConfigure throttleConfigure; } ENET_PACKED ENetProtocol; -#ifdef _MSC_VER_ +#ifdef _MSC_VER #pragma pack(pop) #endif diff --git a/src/libraries/enet/libenet/include/enet/unix.h b/src/libraries/enet/libenet/include/enet/unix.h index 9683c09b4..a59e34060 100644 --- a/src/libraries/enet/libenet/include/enet/unix.h +++ b/src/libraries/enet/libenet/include/enet/unix.h @@ -40,7 +40,7 @@ typedef fd_set ENetSocketSet; #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) -#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset)) +#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset)) #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) #endif /* __ENET_UNIX_H__ */ diff --git a/src/libraries/enet/libenet/include/enet/win32.h b/src/libraries/enet/libenet/include/enet/win32.h index 197dfc047..d8968ee56 100644 --- a/src/libraries/enet/libenet/include/enet/win32.h +++ b/src/libraries/enet/libenet/include/enet/win32.h @@ -50,7 +50,7 @@ typedef fd_set ENetSocketSet; #define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) #define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) -#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset)) +#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset)) #define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) #endif /* __ENET_WIN32_H__ */ diff --git a/src/libraries/enet/libenet/protocol.c b/src/libraries/enet/libenet/protocol.c index 3438a5dad..b8d4863eb 100644 --- a/src/libraries/enet/libenet/protocol.c +++ b/src/libraries/enet/libenet/protocol.c @@ -297,7 +297,8 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet peer = currentPeer; } else - if (currentPeer -> address.host == host -> receivedAddress.host) + if (currentPeer -> state != ENET_PEER_STATE_CONNECTING && + currentPeer -> address.host == host -> receivedAddress.host) { if (currentPeer -> address.port == host -> receivedAddress.port && currentPeer -> connectID == command -> connect.connectID) @@ -819,7 +820,7 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro enet_peer_reset_queues (peer); - if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED || peer -> state == ENET_PEER_STATE_DISCONNECTING) + if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED || peer -> state == ENET_PEER_STATE_DISCONNECTING || peer -> state == ENET_PEER_STATE_CONNECTING) enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); else if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) From a13fd761ccb73213ac56acb18755c32de14dd64c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Mar 2014 06:19:56 -0300 Subject: [PATCH 02/24] Updated love.filesystem's C library loader for require to look in paths added via love.filesystem.mount, when in fused mode --- src/modules/filesystem/physfs/Filesystem.cpp | 10 +++++++ src/modules/filesystem/physfs/Filesystem.h | 5 ++++ .../filesystem/physfs/wrap_Filesystem.cpp | 28 +++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index 25e4efbc9..aa2f5e826 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -397,6 +397,16 @@ std::string Filesystem::getSourceBaseDirectory() const return game_source.substr(0, base_end_pos); } +std::string Filesystem::getRealDirectory(const char *filename) const +{ + const char *dir = PHYSFS_getRealDir(filename); + + if (dir == nullptr) + throw love::Exception("File does not exist."); + + return std::string(dir); +} + bool Filesystem::exists(const char *file) const { return PHYSFS_exists(file); diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index a6ef9af5a..f9ccfecb3 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -166,6 +166,11 @@ public: **/ std::string getSourceBaseDirectory() const; + /** + * Gets the real directory path containing the file. + **/ + std::string getRealDirectory(const char *filename) const; + /** * Checks whether a file exists in the current search path * or not. diff --git a/src/modules/filesystem/physfs/wrap_Filesystem.cpp b/src/modules/filesystem/physfs/wrap_Filesystem.cpp index 6e76cbb52..0a89387e6 100644 --- a/src/modules/filesystem/physfs/wrap_Filesystem.cpp +++ b/src/modules/filesystem/physfs/wrap_Filesystem.cpp @@ -526,9 +526,31 @@ int extloader(lua_State *L) tokenized_name += library_extension(); - void *handle = SDL_LoadObject((std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name).c_str()); - if (!handle && instance->isFused()) - handle = SDL_LoadObject((std::string(instance->getSaveDirectory()) + LOVE_PATH_SEPARATOR + tokenized_name).c_str()); + void *handle = nullptr; + + // If the game is fused, try looking for the DLL in the game's read paths. + if (instance->isFused()) + { + try + { + std::string dir = instance->getRealDirectory(tokenized_name.c_str()); + + // We don't want to look in the game's source, because it can be a + // zip sometimes and a folder other times. + if (dir.find(instance->getSource()) == std::string::npos) + handle = SDL_LoadObject((dir + LOVE_PATH_SEPARATOR + tokenized_name).c_str()); + } + catch (love::Exception &) + { + // Nothing... + } + } + + if (!handle) + { + std::string path = std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name; + handle = SDL_LoadObject(path.c_str()); + } if (!handle) { From 4faddcd9aacba9ffe79a644de5f4f646624c25e7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Mar 2014 17:55:19 -0300 Subject: [PATCH 03/24] Fixed some trivial compiler warnings --- .../love-framework.xcodeproj/project.pbxproj | 15 +++++++++++ src/modules/audio/openal/Source.cpp | 4 +-- src/modules/math/MathModule.cpp | 26 +++++++++---------- src/modules/math/wrap_Math.cpp | 4 +-- src/modules/physics/box2d/Fixture.cpp | 2 +- src/scripts/auto.lua | 3 ++- src/scripts/boot.lua.h | 2 +- src/scripts/graphics.lua.h | 2 +- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/platform/macosx/love-framework.xcodeproj/project.pbxproj b/platform/macosx/love-framework.xcodeproj/project.pbxproj index 84e5457de..352ad4137 100644 --- a/platform/macosx/love-framework.xcodeproj/project.pbxproj +++ b/platform/macosx/love-framework.xcodeproj/project.pbxproj @@ -2345,11 +2345,16 @@ ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; DEAD_CODE_STRIPPING = YES; FRAMEWORK_SEARCH_PATHS = /Library/Frameworks; GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = LOVE_MACOSX_USE_FRAMEWORKS; GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; @@ -2381,11 +2386,16 @@ ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = /Library/Frameworks; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = LOVE_MACOSX_USE_FRAMEWORKS; GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; @@ -2417,11 +2427,16 @@ ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; DEAD_CODE_STRIPPING = YES; FRAMEWORK_SEARCH_PATHS = /Library/Frameworks; GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = LOVE_MACOSX_USE_FRAMEWORKS; GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index 237cf02b1..e9ef1a434 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -468,8 +468,8 @@ void Source::getDirection(float *v) const void Source::setCone(float innerAngle, float outerAngle, float outerVolume) { - cone.innerAngle = LOVE_TODEG(innerAngle); - cone.outerAngle = LOVE_TODEG(outerAngle); + cone.innerAngle = (int) LOVE_TODEG(innerAngle); + cone.outerAngle = (int) LOVE_TODEG(outerAngle); cone.outerVolume = outerVolume; if (valid) diff --git a/src/modules/math/MathModule.cpp b/src/modules/math/MathModule.cpp index ed096ebd7..2f92bf075 100644 --- a/src/modules/math/MathModule.cpp +++ b/src/modules/math/MathModule.cpp @@ -198,14 +198,14 @@ bool Math::isConvex(const std::vector &polygon) **/ float Math::gammaToLinear(float c) const { - if (c > 1.0) - return 1.0; - else if (c < 0.0) - return 0.0; + if (c > 1.0f) + return 1.0f; + else if (c < 0.0f) + return 0.0f; else if (c <= 0.04045) - return c / 12.92; + return c / 12.92f; else - return powf((c + 0.055) / 1.055, 2.4); + return powf((c + 0.055f) / 1.055f, 2.4f); } /** @@ -213,14 +213,14 @@ float Math::gammaToLinear(float c) const **/ float Math::linearToGamma(float c) const { - if (c > 1.0) - return 1.0; - else if (c < 0.0) - return 0.0; - else if (c < 0.0031308) - return c * 12.92; + if (c > 1.0f) + return 1.0f; + else if (c < 0.0f) + return 0.0f; + else if (c < 0.0031308f) + return c * 12.92f; else - return 1.055 * powf(c, 0.41666) - 0.055; + return 1.055f * powf(c, 0.41666f) - 0.055f; } } // math diff --git a/src/modules/math/wrap_Math.cpp b/src/modules/math/wrap_Math.cpp index 50b78f956..093f30e42 100644 --- a/src/modules/math/wrap_Math.cpp +++ b/src/modules/math/wrap_Math.cpp @@ -259,7 +259,7 @@ static int getGammaArgs(lua_State *L, float color[4]) for (int i = 1; i <= n && i <= 4; i++) { lua_rawgeti(L, 1, i); - color[i - 1] = (float) luaL_checknumber(L, -1) / 255.0; + color[i - 1] = (float) luaL_checknumber(L, -1) / 255.0f; numcomponents++; } @@ -270,7 +270,7 @@ static int getGammaArgs(lua_State *L, float color[4]) int n = lua_gettop(L); for (int i = 1; i <= n && i <= 4; i++) { - color[i - 1] = (float) luaL_checknumber(L, i) / 255.0; + color[i - 1] = (float) luaL_checknumber(L, i) / 255.0f; numcomponents++; } } diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index 9b80ef222..9d5b8f6f1 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -202,7 +202,7 @@ uint16 Fixture::getBits(lua_State *L) { size_t bpos = (size_t)(lua_tointeger(L, i)-1); if (bpos >= 16) - return luaL_error(L, "Values must be in range 1-16."); + luaL_error(L, "Values must be in range 1-16."); b.set(bpos, true); } diff --git a/src/scripts/auto.lua b/src/scripts/auto.lua index 5d027e339..dbd8c6bd6 100644 --- a/src/scripts/auto.lua +++ b/src/scripts/auto.lua @@ -34,7 +34,8 @@ const unsigned char %s[] = { %s }; // [%s] -} // love]] +} // love +]] --formatting parameters: -- - input file name -- - c variable name diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 5e6f539ad..0c2b2712b 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -5388,4 +5388,4 @@ const unsigned char boot_lua[] = 0x65, 0x74, 0x76, 0x61, 0x6c, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x30, 0x0a, 0x65, 0x6e, 0x64, 0x0a, }; // [boot.lua] -} // love \ No newline at end of file +} // love diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index b89461c99..461742872 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6626,4 +6626,4 @@ const unsigned char graphics_lua[] = 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, }; // [graphics.lua] -} // love \ No newline at end of file +} // love From 89e9288a85adc923f991c41c0be467e3ba20b64d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 13 Mar 2014 05:34:16 -0300 Subject: [PATCH 04/24] Make sure SoundData objects aren't initialized with garbage sample values --- src/modules/sound/SoundData.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/sound/SoundData.cpp b/src/modules/sound/SoundData.cpp index cbb9383c1..ae1007699 100644 --- a/src/modules/sound/SoundData.cpp +++ b/src/modules/sound/SoundData.cpp @@ -145,6 +145,8 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo if (newData) memcpy(data, newData, size); + else + memset(data, 0, size); } void *SoundData::getData() const From fc77e8f9f03f556d7185604dbdb8eb206227eee7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 15 Mar 2014 21:43:25 -0300 Subject: [PATCH 05/24] Throw away the first 3 love.math.random results after seeding it (xorshift outputs less random results the first few times when the seed is very similar to a previous one) --- src/libraries/enet/enet.cpp | 2 +- src/scripts/boot.lua | 1 + src/scripts/boot.lua.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libraries/enet/enet.cpp b/src/libraries/enet/enet.cpp index 34e215c78..7d915cfce 100644 --- a/src/libraries/enet/enet.cpp +++ b/src/libraries/enet/enet.cpp @@ -89,7 +89,7 @@ static void parse_address(lua_State *l, const char *addr_str, ENetAddress *addre /** * Find the index of a given peer for which we only have the pointer. */ -size_t find_peer_index (lua_State *l, ENetHost *enet_host, ENetPeer *peer) { +static size_t find_peer_index(lua_State *l, ENetHost *enet_host, ENetPeer *peer) { size_t peer_index; for (peer_index = 0; peer_index < enet_host->peerCount; peer_index++) { if (peer == &(enet_host->peers[peer_index])) diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 183b1725f..577b615fe 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -468,6 +468,7 @@ function love.run() if love.math then love.math.setRandomSeed(os.time()) + for i=1,3 do love.math.random() end end if love.event then diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 0c2b2712b..69c5998ee 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -836,6 +836,9 @@ const unsigned char boot_lua[] = 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x73, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x53, 0x65, 0x65, 0x64, 0x28, 0x6f, 0x73, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x28, 0x29, 0x29, 0x0a, + 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x33, 0x20, 0x64, 0x6f, 0x20, 0x6c, 0x6f, 0x76, + 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x28, 0x29, 0x20, 0x65, 0x6e, + 0x64, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, From 9e6a3b8d5ed0847aa93023a9ddc42bb95759d834 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 17 Mar 2014 15:06:04 -0300 Subject: [PATCH 06/24] Fixed 8-bit SoundData samples when used in a love.audio Source --- src/modules/sound/SoundData.cpp | 16 ++++++++++------ src/modules/sound/SoundData.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/sound/SoundData.cpp b/src/modules/sound/SoundData.cpp index ae1007699..6b7dbc538 100644 --- a/src/modules/sound/SoundData.cpp +++ b/src/modules/sound/SoundData.cpp @@ -52,7 +52,7 @@ SoundData::SoundData(Decoder *decoder) { while (bufferSize < (size_t) size + decoded) bufferSize <<= 1; - data = (int8 *) realloc(data, bufferSize); + data = (uint8 *) realloc(data, bufferSize); } if (!data) @@ -76,7 +76,7 @@ SoundData::SoundData(Decoder *decoder) // Shrink buffer if necessary. if (data && bufferSize > (size_t) size) - data = (int8 *) realloc(data, size); + data = (uint8 *) realloc(data, size); channels = decoder->getChannels(); bitDepth = decoder->getBitDepth(); @@ -139,14 +139,14 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo if (realsize > INT_MAX) throw love::Exception("Data is too big!"); - data = (int8 *) malloc(size); + data = (uint8 *) malloc(size); if (!data) throw love::Exception("Not enough memory."); if (newData) memcpy(data, newData, size); else - memset(data, 0, size); + memset(data, bitDepth == 8 ? 128 : 0, size); } void *SoundData::getData() const @@ -192,12 +192,14 @@ void SoundData::setSample(int i, float sample) if (bitDepth == 16) { + // 16-bit sample values are signed. int16 *s = (int16 *) data; s[i] = (int16) (sample * (float) LOVE_INT16_MAX); } else { - data[i] = (int8) (sample * (float) LOVE_INT8_MAX); + // 8-bit sample values are unsigned internally. + data[i] = (uint8) ((sample * 127.0f) + 128.0f); } } @@ -209,12 +211,14 @@ float SoundData::getSample(int i) const if (bitDepth == 16) { + // 16-bit sample values are signed. int16 *s = (int16 *) data; return (float) s[i] / (float) LOVE_INT16_MAX; } else { - return (float) data[i] / (float) LOVE_INT8_MAX; + // 8-bit sample values are unsigned internally. + return ((float) data[i] - 128.0f) / 127.0f; } } diff --git a/src/modules/sound/SoundData.h b/src/modules/sound/SoundData.h index e12e55ba0..cdc8734a4 100644 --- a/src/modules/sound/SoundData.h +++ b/src/modules/sound/SoundData.h @@ -59,7 +59,7 @@ private: void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0); - int8 *data; + uint8 *data; int size; int sampleRate; From aba17607aa253cd8655d932c8e03d5ac5f980b8f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 17 Mar 2014 20:14:53 -0300 Subject: [PATCH 07/24] Added an optional callback function argument to love.filesystem.getDirectoryItems. Callback function takes a single argument containing a filepath string. For example: love.filesystem.getDirectoryItems("", print) --- src/modules/filesystem/physfs/Filesystem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index aa2f5e826..748dbceea 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -477,6 +477,10 @@ void Filesystem::append(const char *filename, const void *data, int64 size) cons int Filesystem::getDirectoryItems(lua_State *L) { const char *dir = luaL_checkstring(L, 1); + bool hascallback = !lua_isnoneornil(L, 2); + + if (hascallback) + luaL_checktype(L, 2, LUA_TFUNCTION); char **rc = PHYSFS_enumerateFiles(dir); int index = 1; @@ -485,6 +489,13 @@ int Filesystem::getDirectoryItems(lua_State *L) for (char **i = rc; *i != 0; i++) { + if (hascallback) + { + lua_pushvalue(L, 2); + lua_pushstring(L, *i); + lua_call(L, 1, 0); + } + lua_pushstring(L, *i); lua_rawseti(L, -2, index); index++; From 50916825d09a24e5f56cebeab0a9fb0fccf1b0e2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 18 Mar 2014 03:50:00 -0300 Subject: [PATCH 08/24] Data::getSize now uses size_t instead of int --- src/common/Data.h | 5 ++++- src/common/wrap_Data.cpp | 4 ++-- src/modules/filesystem/FileData.cpp | 17 ++++++----------- src/modules/filesystem/FileData.h | 4 +--- src/modules/font/GlyphData.cpp | 6 +++--- src/modules/font/GlyphData.h | 2 +- src/modules/image/CompressedData.cpp | 8 ++++---- src/modules/image/CompressedData.h | 4 ++-- src/modules/image/ImageData.cpp | 4 ++-- src/modules/image/ImageData.h | 2 +- src/modules/sound/SoundData.cpp | 28 ++++++++++++++-------------- src/modules/sound/SoundData.h | 4 ++-- 12 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/common/Data.h b/src/common/Data.h index ffea71cf9..1ba34c49e 100644 --- a/src/common/Data.h +++ b/src/common/Data.h @@ -25,6 +25,9 @@ #include "config.h" #include "Object.h" +// C +#include + namespace love { @@ -49,7 +52,7 @@ public: /** * Gets the size of the Data in bytes. **/ - virtual int getSize() const = 0; + virtual size_t getSize() const = 0; }; // Data diff --git a/src/common/wrap_Data.cpp b/src/common/wrap_Data.cpp index c093a78ff..76a8b6871 100644 --- a/src/common/wrap_Data.cpp +++ b/src/common/wrap_Data.cpp @@ -31,7 +31,7 @@ Data *luax_checkdata(lua_State *L, int idx) int w_Data_getString(lua_State *L) { Data *t = luax_checkdata(L, 1); - lua_pushlstring(L, (const char *) t->getData(), (size_t) t->getSize()); + lua_pushlstring(L, (const char *) t->getData(), t->getSize()); return 1; } @@ -45,7 +45,7 @@ int w_Data_getPointer(lua_State *L) int w_Data_getSize(lua_State *L) { Data *t = luax_checkdata(L, 1); - lua_pushinteger(L, t->getSize()); + lua_pushnumber(L, (lua_Number) t->getSize()); return 1; } diff --git a/src/modules/filesystem/FileData.cpp b/src/modules/filesystem/FileData.cpp index dd59c73e9..4da8ea431 100644 --- a/src/modules/filesystem/FileData.cpp +++ b/src/modules/filesystem/FileData.cpp @@ -20,9 +20,9 @@ #include "FileData.h" -// STD +// C++ #include -#include +#include namespace love { @@ -31,7 +31,7 @@ namespace filesystem FileData::FileData(uint64 size, const std::string &filename) : data(new char[(size_t) size]) - , size(size) + , size((size_t) size) , filename(filename) { if (filename.rfind('.') != std::string::npos) @@ -48,15 +48,10 @@ void *FileData::getData() const return (void *)data; } -// TODO: Enable this -/*uint64 FileData::getSize() const +size_t FileData::getSize() const { - return size; -}*/ - -int FileData::getSize() const -{ - return size > INT_MAX ? INT_MAX : (int) size; + size_t sizemax = std::numeric_limits::max(); + return size > sizemax ? sizemax : (size_t) size; } const std::string &FileData::getFilename() const diff --git a/src/modules/filesystem/FileData.h b/src/modules/filesystem/FileData.h index e74866be5..55a0eee06 100644 --- a/src/modules/filesystem/FileData.h +++ b/src/modules/filesystem/FileData.h @@ -49,9 +49,7 @@ public: // Implements Data. void *getData() const; - //TODO: Enable this - //uint64 getSize() const; - int getSize() const; + size_t getSize() const; const std::string &getFilename() const; const std::string &getExtension() const; diff --git a/src/modules/font/GlyphData.cpp b/src/modules/font/GlyphData.cpp index 27cf32af8..7ed2b3db2 100644 --- a/src/modules/font/GlyphData.cpp +++ b/src/modules/font/GlyphData.cpp @@ -64,16 +64,16 @@ void *GlyphData::getData() const return (void *) data; } -int GlyphData::getSize() const +size_t GlyphData::getSize() const { switch (format) { case GlyphData::FORMAT_LUMINANCE_ALPHA: - return getWidth() * getHeight() * 2; + return size_t(getWidth() * getHeight() * 2); break; case GlyphData::FORMAT_RGBA: default: - return getWidth() * getHeight() * 4; + return size_t(getWidth() * getHeight() * 4); break; } diff --git a/src/modules/font/GlyphData.h b/src/modules/font/GlyphData.h index 6144dcb9b..a77755944 100644 --- a/src/modules/font/GlyphData.h +++ b/src/modules/font/GlyphData.h @@ -67,7 +67,7 @@ public: // Implements Data. void *getData() const; - int getSize() const; + size_t getSize() const; /** * Gets the height of the glyph. diff --git a/src/modules/image/CompressedData.cpp b/src/modules/image/CompressedData.cpp index fc85e51f0..e4d47331c 100644 --- a/src/modules/image/CompressedData.cpp +++ b/src/modules/image/CompressedData.cpp @@ -36,9 +36,9 @@ CompressedData::~CompressedData() { } -int CompressedData::getSize() const +size_t CompressedData::getSize() const { - return int(dataSize); + return dataSize; } void *CompressedData::getData() const @@ -51,11 +51,11 @@ int CompressedData::getMipmapCount() const return dataImages.size(); } -int CompressedData::getSize(int miplevel) const +size_t CompressedData::getSize(int miplevel) const { checkMipmapLevelExists(miplevel); - return int(dataImages[miplevel].size); + return dataImages[miplevel].size; } void *CompressedData::getData(int miplevel) const diff --git a/src/modules/image/CompressedData.h b/src/modules/image/CompressedData.h index 9df985b4f..42ee5e58d 100644 --- a/src/modules/image/CompressedData.h +++ b/src/modules/image/CompressedData.h @@ -71,7 +71,7 @@ public: // Implements Data. virtual void *getData() const; - virtual int getSize() const; + virtual size_t getSize() const; /** * Gets the number of mipmaps in this Compressed Image Data. @@ -82,7 +82,7 @@ public: /** * Gets the size in bytes of a sub-image at the specified mipmap level. **/ - int getSize(int miplevel) const; + size_t getSize(int miplevel) const; /** * Gets the byte data of a sub-image at the specified mipmap level. diff --git a/src/modules/image/ImageData.cpp b/src/modules/image/ImageData.cpp index e71f7feb3..4264555da 100644 --- a/src/modules/image/ImageData.cpp +++ b/src/modules/image/ImageData.cpp @@ -38,9 +38,9 @@ ImageData::~ImageData() delete mutex; } -int ImageData::getSize() const +size_t ImageData::getSize() const { - return getWidth()*getHeight()*sizeof(pixel); + return size_t(getWidth()*getHeight())*sizeof(pixel); } void *ImageData::getData() const diff --git a/src/modules/image/ImageData.h b/src/modules/image/ImageData.h index 3349722fd..f85494d8b 100644 --- a/src/modules/image/ImageData.h +++ b/src/modules/image/ImageData.h @@ -130,7 +130,7 @@ public: // Implements Data. virtual void *getData() const; - virtual int getSize() const; + virtual size_t getSize() const; protected: diff --git a/src/modules/sound/SoundData.cpp b/src/modules/sound/SoundData.cpp index 6b7dbc538..81b5f5f5c 100644 --- a/src/modules/sound/SoundData.cpp +++ b/src/modules/sound/SoundData.cpp @@ -21,11 +21,11 @@ #include "SoundData.h" // C -#include #include #include -// STL +// C++ +#include #include #include @@ -48,9 +48,9 @@ SoundData::SoundData(Decoder *decoder) { // Expand or allocate buffer. Note that realloc may move // memory to other locations. - if (!data || bufferSize < (size_t) size + decoded) + if (!data || bufferSize < size + decoded) { - while (bufferSize < (size_t) size + decoded) + while (bufferSize < size + decoded) bufferSize <<= 1; data = (uint8 *) realloc(data, bufferSize); } @@ -61,21 +61,21 @@ SoundData::SoundData(Decoder *decoder) // Copy memory into new part of memory. memcpy(data + size, decoder->getBuffer(), decoded); - // Keep this up to date. - size += decoded; - // Overflow check. - if (size < 0) + if (size > std::numeric_limits::max() - decoded) { free(data); throw love::Exception("Not enough memory."); } + // Keep this up to date. + size += decoded; + decoded = decoder->decode(); } // Shrink buffer if necessary. - if (data && bufferSize > (size_t) size) + if (data && bufferSize > size) data = (uint8 *) realloc(data, size); channels = decoder->getChannels(); @@ -136,7 +136,7 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo double realsize = samples; realsize *= (bitDepth / 8) * channels; - if (realsize > INT_MAX) + if (realsize > std::numeric_limits::max()) throw love::Exception("Data is too big!"); data = (uint8 *) malloc(size); @@ -154,9 +154,9 @@ void *SoundData::getData() const return (void *)data; } -int SoundData::getSize() const +size_t SoundData::getSize() const { - return (int)size; + return size; } int SoundData::getChannels() const @@ -187,7 +187,7 @@ float SoundData::getDuration() const void SoundData::setSample(int i, float sample) { // Check range. - if (i < 0 || i >= size/(bitDepth/8)) + if (i < 0 || (size_t) i >= size/(bitDepth/8)) throw love::Exception("Attempt to set out-of-range sample!"); if (bitDepth == 16) @@ -206,7 +206,7 @@ void SoundData::setSample(int i, float sample) float SoundData::getSample(int i) const { // Check range. - if (i < 0 || i >= size/(bitDepth/8)) + if (i < 0 || (size_t) i >= size/(bitDepth/8)) throw love::Exception("Attempt to get out-of-range sample!"); if (bitDepth == 16) diff --git a/src/modules/sound/SoundData.h b/src/modules/sound/SoundData.h index cdc8734a4..1a06e6964 100644 --- a/src/modules/sound/SoundData.h +++ b/src/modules/sound/SoundData.h @@ -43,7 +43,7 @@ public: // Implements Data. void *getData() const; - int getSize() const; + size_t getSize() const; virtual int getChannels() const; virtual int getBitDepth() const; @@ -60,7 +60,7 @@ private: void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0); uint8 *data; - int size; + size_t size; int sampleRate; int bitDepth; From b95a02772a368fe33822d9f5206b69cb1f7ec6cd Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 18 Mar 2014 19:46:14 -0300 Subject: [PATCH 09/24] Include the freetype error code in the error message when truetype font/glyph loading fails --- .../font/freetype/TrueTypeRasterizer.cpp | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/modules/font/freetype/TrueTypeRasterizer.cpp b/src/modules/font/freetype/TrueTypeRasterizer.cpp index e09328f70..3cdfac6c3 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.cpp +++ b/src/modules/font/freetype/TrueTypeRasterizer.cpp @@ -33,12 +33,15 @@ namespace freetype TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size) : data(data) { - if (FT_New_Memory_Face(library, - (const FT_Byte *)data->getData(), /* first byte in memory */ - data->getSize(), /* size in bytes */ - 0, /* face_index */ - &face)) - throw love::Exception("TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)"); + FT_Error err = FT_Err_Ok; + err = FT_New_Memory_Face(library, + (const FT_Byte *)data->getData(), /* first byte in memory */ + data->getSize(), /* size in bytes */ + 0, /* face_index */ + &face); + + if (err != FT_Err_Ok) + throw love::Exception("TrueType Font Loading error: FT_New_Face failed: 0x%x (problem with font file?)", err); FT_Set_Pixel_Sizes(face, size, size); @@ -68,12 +71,18 @@ GlyphData *TrueTypeRasterizer::getGlyphData(uint32 glyph) const love::font::GlyphMetrics glyphMetrics = {}; FT_Glyph ftglyph; - // Initialize - if (FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT)) - throw love::Exception("TrueTypeFont Loading error: FT_Load_Glyph failed"); + FT_Error err = FT_Err_Ok; - if (FT_Get_Glyph(face->glyph, &ftglyph)) - throw love::Exception("TrueTypeFont Loading error: FT_Get_Glyph failed"); + // Initialize + err = FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT); + + if (err != FT_Err_Ok) + throw love::Exception("TrueType Font Loading error: FT_Load_Glyph failed (0x%x)", err); + + err = FT_Get_Glyph(face->glyph, &ftglyph); + + if (err != FT_Err_Ok) + throw love::Exception("TrueType Font Loading error: FT_Get_Glyph failed (0x%x)", err); FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1); From fcb24871d568a9a326c834c4633818f678fe4612 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 21 Mar 2014 04:45:19 -0300 Subject: [PATCH 10/24] Updated changelog --- changes.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/changes.txt b/changes.txt index 1401af364..c425122e2 100644 --- a/changes.txt +++ b/changes.txt @@ -23,6 +23,9 @@ LOVE 0.9.1 [Baby Inspector] * Added love.graphics.isSupported("srgb"). * Added love.math.gammaToLinear and love.math.linearToGamma. * Added RandomGenerator:getState and RandomGenerator:setState. + * Added Body:setUserData and Body:getUserData. + * Added some missing obscure key constants. + * Added optional callback function argument to love.filesystem.getDirectoryItems. * Deprecated Mesh/SpriteBatch/ParticleSystem:setImage. * Deprecated love.graphics.getMaxImageSize and love.graphics.getMaxPointSize. @@ -35,6 +38,9 @@ LOVE 0.9.1 [Baby Inspector] * Fixed love.graphics.reset causing crashes when called in between love.graphics.push/pop. * Fixed tab characters ("\t") to display properly with love.graphics.print. * Fixed World:getBodyList and World:getJointList causing hard crashes. + * Fixed loading BC4 compressed textures. + * Fixed SoundData objects being initialized with garbage values. + * Fixed 8-bit SoundData samples when used in love.audio Sources. * Renamed love.graphics.getMaxImageSize to love.graphics.getMaxTextureSize (old function still exists.) @@ -47,6 +53,11 @@ LOVE 0.9.1 [Baby Inspector] * Updated Source:play to return a boolean indicating success. * Updated t.console in conf.lua to create the console before modules are loaded in Windows. * Updated Mesh vertex maps (index buffers) to use less space in VRAM. + * Updated love.graphics.newMesh and Mesh:setVertices to default the UV parameters to 0,0. + * Updated Fixture:set/getUserData to work in Coroutines. + * Updated fullscreen-desktop and resizable window modes in OS X to use Mac OS 10.7's fullscreen Spaces. + * Updated love.filesystem's C library loader to look in paths added via love.filesystem.mount, in Fused mode. + * Updated the default love.run code to make initial love.math.random calls more random. LOVE 0.9.0 [Baby Inspector] --------------------------- From 1fd5d492fe14cebeda528d8159d6351287a11652 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 21 Mar 2014 04:51:37 -0300 Subject: [PATCH 11/24] Removed obsolete change from the changelog --- changes.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/changes.txt b/changes.txt index c425122e2..c6aae4820 100644 --- a/changes.txt +++ b/changes.txt @@ -42,8 +42,6 @@ LOVE 0.9.1 [Baby Inspector] * Fixed SoundData objects being initialized with garbage values. * Fixed 8-bit SoundData samples when used in love.audio Sources. - * Renamed love.graphics.getMaxImageSize to love.graphics.getMaxTextureSize (old function still exists.) - * Updated the error text for love.filesystem’s module searchers when require fails. * Updated the love.filesystem module searchers to be tried after package.preload instead of before. * Updated love.graphics.newParticleSystem, newSpriteBatch, and newMesh to accept Canvases. From 146b3cff19870dfb2d1853eec4f7376c0137b1bb Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 27 Mar 2014 23:28:36 -0300 Subject: [PATCH 12/24] Added blend mode "screen". --- src/modules/graphics/Graphics.cpp | 1 + src/modules/graphics/Graphics.h | 1 + src/modules/graphics/opengl/Graphics.cpp | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 10f8cf8e1..516c8530c 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -144,6 +144,7 @@ StringMap::Entry Graphics::blendM { "subtractive", Graphics::BLEND_SUBTRACTIVE }, { "multiplicative", Graphics::BLEND_MULTIPLICATIVE }, { "premultiplied", Graphics::BLEND_PREMULTIPLIED }, + { "screen", Graphics::BLEND_SCREEN }, { "replace", Graphics::BLEND_REPLACE }, }; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index e91d96e8f..95406e485 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -57,6 +57,7 @@ public: BLEND_SUBTRACTIVE, BLEND_MULTIPLICATIVE, BLEND_PREMULTIPLIED, + BLEND_SCREEN, BLEND_REPLACE, BLEND_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 3630e3216..80a0c3026 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -642,6 +642,10 @@ void Graphics::setBlendMode(Graphics::BlendMode mode) state.srcRGB = state.srcA = GL_SRC_ALPHA; state.dstRGB = state.dstA = GL_ONE; break; + case BLEND_SCREEN: + state.srcRGB = state.srcA = GL_ONE; + state.dstRGB = state.dstA = GL_ONE_MINUS_SRC_COLOR; + break; case BLEND_REPLACE: default: state.srcRGB = state.srcA = GL_ONE; @@ -669,6 +673,8 @@ Graphics::BlendMode Graphics::getBlendMode() const return BLEND_MULTIPLICATIVE; else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_ALPHA) return BLEND_PREMULTIPLIED; + else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_COLOR) + return BLEND_SCREEN; else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ZERO) return BLEND_REPLACE; } From e7947d9d2e6fbdae5a7fe012def7cd85d9cd747e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 29 Mar 2014 16:30:48 -0300 Subject: [PATCH 13/24] Pulled Mesh:set/getInstanceCount from 0.9.1 for now. The feature is difficult to use well unless custom vertex attributes are added. --- changes.txt | 1 - src/modules/graphics/opengl/wrap_Mesh.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/changes.txt b/changes.txt index c6aae4820..64b39b5b3 100644 --- a/changes.txt +++ b/changes.txt @@ -9,7 +9,6 @@ LOVE 0.9.1 [Baby Inspector] * Added ParticleSystem:setRelativeRotation. * Added love.graphics.setWireframe for debugging. * Added Mesh:setDrawRange and Mesh:getDrawRange. - * Added instancing support to Meshes with Mesh:setInstanceCount. * Added CircleShape:getPoint and CircleShape:setPoint. * Added Mesh/SpriteBatch/ParticleSystem:setTexture, accepts Canvases and Images. * Added high-dpi window support for Retina displays in OS X, via the 'highdpi' window flag. diff --git a/src/modules/graphics/opengl/wrap_Mesh.cpp b/src/modules/graphics/opengl/wrap_Mesh.cpp index 83e21afd3..c70d7970d 100644 --- a/src/modules/graphics/opengl/wrap_Mesh.cpp +++ b/src/modules/graphics/opengl/wrap_Mesh.cpp @@ -371,8 +371,12 @@ static const luaL_Reg functions[] = { "getVertexCount", w_Mesh_getVertexCount }, { "setVertexMap", w_Mesh_setVertexMap }, { "getVertexMap", w_Mesh_getVertexMap }, - { "setInstanceCount", w_Mesh_setInstanceCount }, - { "getInstanceCount", w_Mesh_getInstanceCount }, + + // Disabled for now, since implementation is incomplete and might change + // if/when VertexBuffers / custom vertex attributes are added. + // { "setInstanceCount", w_Mesh_setInstanceCount }, + // { "getInstanceCount", w_Mesh_getInstanceCount }, + { "setTexture", w_Mesh_setTexture }, { "getTexture", w_Mesh_getTexture }, { "setDrawMode", w_Mesh_setDrawMode }, From f65e9826d99aae17da14152dda04da179f049700 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 29 Mar 2014 17:51:33 -0300 Subject: [PATCH 14/24] Disabled shader code for instancing --- src/scripts/graphics.lua | 15 ++++++++------- src/scripts/graphics.lua.h | 34 ++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 4b2b9b814..80cef656d 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1317,13 +1317,14 @@ uniform vec4 love_ScreenSize;]] #define VaryingTexCoord gl_TexCoord[0] #define VaryingColor gl_FrontColor -#if defined(GL_ARB_draw_instanced) - #extension GL_ARB_draw_instanced : enable - #define love_InstanceID gl_InstanceIDARB -#else - attribute float love_PseudoInstanceID; - int love_InstanceID = int(love_PseudoInstanceID); -#endif]], +// #if defined(GL_ARB_draw_instanced) +// #extension GL_ARB_draw_instanced : enable +// #define love_InstanceID gl_InstanceIDARB +// #else +// attribute float love_PseudoInstanceID; +// int love_InstanceID = int(love_PseudoInstanceID); +// #endif +]], FOOTER = [[ void main() { diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 461742872..0b9c7d48a 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6313,22 +6313,24 @@ const unsigned char graphics_lua[] = 0x30, 0x5d, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a, - 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, - 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x29, 0x0a, - 0x09, 0x23, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, - 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x3a, 0x20, - 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x0a, - 0x09, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74, - 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x20, 0x67, 0x6c, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, - 0x49, 0x44, 0x41, 0x52, 0x42, 0x0a, - 0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a, - 0x09, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c, - 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, - 0x49, 0x44, 0x3b, 0x0a, - 0x09, 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, - 0x49, 0x44, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x74, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75, - 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x29, 0x3b, 0x0a, - 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5d, 0x5d, 0x2c, 0x0a, + 0x2f, 0x2f, 0x20, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f, + 0x41, 0x52, 0x42, 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, + 0x29, 0x0a, + 0x2f, 0x2f, 0x09, 0x23, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x47, 0x4c, 0x5f, 0x41, + 0x52, 0x42, 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x20, + 0x3a, 0x20, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x0a, + 0x2f, 0x2f, 0x09, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, + 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x20, 0x67, 0x6c, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x49, 0x44, 0x41, 0x52, 0x42, 0x0a, + 0x2f, 0x2f, 0x20, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a, + 0x2f, 0x2f, 0x09, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, + 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x49, 0x44, 0x3b, 0x0a, + 0x2f, 0x2f, 0x09, 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x49, 0x44, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x74, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, + 0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x29, 0x3b, 0x0a, + 0x2f, 0x2f, 0x20, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, + 0x5d, 0x5d, 0x2c, 0x0a, 0x09, 0x09, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x3d, From 2698fd2c2cff93718d8a03a0eeab3b4fd8357714 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sun, 30 Mar 2014 14:15:36 +0200 Subject: [PATCH 15/24] Use debian's name for libsdl2 in the debian package dependency list --- platform/unix/debian/control.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/unix/debian/control.in b/platform/unix/debian/control.in index d79d3a375..52a48b5ee 100644 --- a/platform/unix/debian/control.in +++ b/platform/unix/debian/control.in @@ -33,7 +33,7 @@ Depends: ${misc:Depends}, libgl1-mesa-glx, libluajit-5.1-2, libphysfs-1.0-0, - libsdl2 (>= 2.0.0), + libsdl2-2.0-0 (>= 2.0.0), libopenal1, libogg0, libvorbis0a, From a22c4b5f924e589e7cbe0e12b03f0f7e038781ba Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 31 Mar 2014 03:45:22 -0300 Subject: [PATCH 16/24] Explicitly #ifdef'd out SDL 2.0.1+ function calls for Linux to avoid runtime function resolving problems when love is built with SDL 2.0.1+ headers but run using SDL 2.0.0. --- src/modules/event/sdl/Event.cpp | 4 +++- src/modules/window/sdl/Window.cpp | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index 425da01fa..c2a2b648c 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -27,6 +27,7 @@ #include "graphics/Graphics.h" #include "window/Window.h" #include "common/Exception.h" +#include "common/config.h" #include @@ -427,7 +428,8 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const int px_w = e.window.data1; int px_h = e.window.data2; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) SDL_Window *sdlwin = SDL_GetWindowFromID(e.window.windowID); if (sdlwin) SDL_GL_GetDrawableSize(sdlwin, &px_w, &px_h); diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index af8a0940e..6854e11f9 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -116,7 +116,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) if (f.borderless) sdlflags |= SDL_WINDOW_BORDERLESS; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) if (f.highdpi) sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif @@ -130,7 +131,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) Uint32 testflags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) testflags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif @@ -202,7 +204,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) int width = curMode.width; int height = curMode.height; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) SDL_GL_GetDrawableSize(window, &width, &height); #endif @@ -431,7 +434,8 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype) int width = curMode.width; int height = curMode.height; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) SDL_GL_GetDrawableSize(window, &width, &height); #endif @@ -633,7 +637,8 @@ double Window::getPixelScale() const { double scale = 1.0; -#if SDL_VERSION_ATLEAST(2,0,1) + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) if (window) { int wheight; From be8c19911f96be997b6beb670a3364fcaa737b06 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 31 Mar 2014 04:56:29 -0300 Subject: [PATCH 17/24] Fixed love.graphics.isCreated to properly return false if love.window.setMode failed --- src/modules/graphics/opengl/Graphics.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 80a0c3026..68b71f379 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -246,15 +246,19 @@ bool Graphics::setMode(int width, int height, bool &sRGB) void Graphics::unSetMode() { + if (!isCreated()) + return; + // Window re-creation may destroy the GL context, so we must save the state. - if (isCreated()) - savedState = saveState(); + savedState = saveState(); // Unload all volatile objects. These must be reloaded after the display // mode change. Volatile::unloadAll(); gl.deInitContext(); + + created = false; } static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, GLvoid* /*usr*/) From c985b1f2f75f382f3e4a454baf127c7482e0d3e5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 31 Mar 2014 05:01:29 -0300 Subject: [PATCH 18/24] Don't destroy OpenGL resources before checking whether the fullscreen size is supported in love.window.setMode. --- src/modules/window/sdl/Window.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 6854e11f9..7ea6044e8 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -70,10 +70,6 @@ Window::_currentMode::_currentMode() bool Window::setWindow(int width, int height, WindowSettings *settings) { - graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics."); - if (gfx != nullptr) - gfx->unSetMode(); - WindowSettings f; if (settings) @@ -122,6 +118,10 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif + graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics."); + if (gfx != nullptr) + gfx->unSetMode(); + // Destroy and recreate the window if the dimensions or flags have changed. if (window) { @@ -155,6 +155,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) if (!window) { + created = false; + // In Windows and Linux, some GL attributes are set on window creation. setWindowGLAttributes(f.fsaa, f.sRGB); From 38497d23dab5ff55531223b2d8296be7ab45b073 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 31 Mar 2014 16:13:05 -0300 Subject: [PATCH 19/24] Added love.system.openURL (resolves issue #863) --- .../love-framework.xcodeproj/project.pbxproj | 6 +- src/common/utf8.cpp | 21 +++++ src/common/utf8.h | 7 ++ src/modules/system/System.cpp | 83 ++++++++++++++++++- src/modules/system/System.h | 10 +++ src/modules/system/wrap_System.cpp | 8 ++ src/modules/system/wrap_System.h | 1 + 7 files changed, 132 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/common/utf8.cpp mode change 100644 => 100755 src/common/utf8.h mode change 100644 => 100755 src/modules/system/System.cpp diff --git a/platform/macosx/love-framework.xcodeproj/project.pbxproj b/platform/macosx/love-framework.xcodeproj/project.pbxproj index 352ad4137..b6ed48d4e 100644 --- a/platform/macosx/love-framework.xcodeproj/project.pbxproj +++ b/platform/macosx/love-framework.xcodeproj/project.pbxproj @@ -272,6 +272,7 @@ FA9B4A0816E1578300074F42 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA9B4A0716E1578300074F42 /* SDL2.framework */; }; FA9FC0B0173D6E3E005027FF /* wrap_Window.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA9FC0AE173D6E3E005027FF /* wrap_Window.cpp */; }; FA9FC0B1173D6E3E005027FF /* wrap_Window.h in Headers */ = {isa = PBXBuildFile; fileRef = FA9FC0AF173D6E3E005027FF /* wrap_Window.h */; }; + FAA627CE18E7E1560080752D /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAA627CD18E7E1560080752D /* CoreServices.framework */; }; FAAC6B02170A373B008A61C5 /* CompressedData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAAC6B00170A373A008A61C5 /* CompressedData.cpp */; }; FAAC6B03170A373B008A61C5 /* CompressedData.h in Headers */ = {isa = PBXBuildFile; fileRef = FAAC6B01170A373A008A61C5 /* CompressedData.h */; }; FAAFF04416CB11C700CCDE45 /* OpenAL-Soft.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAAFF04316CB11C700CCDE45 /* OpenAL-Soft.framework */; }; @@ -831,6 +832,7 @@ FA9B4A0716E1578300074F42 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = /Library/Frameworks/SDL2.framework; sourceTree = ""; }; FA9FC0AE173D6E3E005027FF /* wrap_Window.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Window.cpp; sourceTree = ""; }; FA9FC0AF173D6E3E005027FF /* wrap_Window.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Window.h; sourceTree = ""; }; + FAA627CD18E7E1560080752D /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; FAAC6B00170A373A008A61C5 /* CompressedData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompressedData.cpp; sourceTree = ""; }; FAAC6B01170A373A008A61C5 /* CompressedData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressedData.h; sourceTree = ""; }; FAAFF04316CB11C700CCDE45 /* OpenAL-Soft.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "OpenAL-Soft.framework"; path = "/Library/Frameworks/OpenAL-Soft.framework"; sourceTree = ""; }; @@ -895,6 +897,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + FAA627CE18E7E1560080752D /* CoreServices.framework in Frameworks */, FA9B4A0816E1578300074F42 /* SDL2.framework in Frameworks */, FAAFF04416CB11C700CCDE45 /* OpenAL-Soft.framework in Frameworks */, FA577AB016C7507900860150 /* Cocoa.framework in Frameworks */, @@ -1830,8 +1833,8 @@ FA577A6616C7199700860150 /* Frameworks */ = { isa = PBXGroup; children = ( - FA9B4A0716E1578300074F42 /* SDL2.framework */, FA577A7916C71A1700860150 /* Cocoa.framework */, + FAA627CD18E7E1560080752D /* CoreServices.framework */, FA577A6716C719D900860150 /* FreeType.framework */, FA577A6916C719DE00860150 /* IL.framework */, FA577A8216C71A5300860150 /* libmodplug.framework */, @@ -1841,6 +1844,7 @@ FAAFF04316CB11C700CCDE45 /* OpenAL-Soft.framework */, FA577A7C16C71A2600860150 /* OpenGL.framework */, FA577A7316C719F900860150 /* physfs.framework */, + FA9B4A0716E1578300074F42 /* SDL2.framework */, FA577A7716C71A0800860150 /* Vorbis.framework */, ); name = Frameworks; diff --git a/src/common/utf8.cpp b/src/common/utf8.cpp old mode 100644 new mode 100755 index fb12997aa..2d593c752 --- a/src/common/utf8.cpp +++ b/src/common/utf8.cpp @@ -45,6 +45,27 @@ std::string to_utf8(LPCWSTR wstr) return ret; } +std::wstring to_widestr(const std::string &str) +{ + if (str.empty()) + return std::wstring(); + + int wide_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), nullptr, 0); + + if (wide_size == 0) + return std::wstring(); + + std::wstring widestr; + widestr.resize(wide_size); + + int ok = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), &widestr[0], widestr.length()); + + if (!ok) + return std::wstring(); + + return widestr; +} + void replace_char(std::string &str, char find, char replace) { int length = str.length(); diff --git a/src/common/utf8.h b/src/common/utf8.h old mode 100644 new mode 100755 index 9a2c51e9b..cd7867ecc --- a/src/common/utf8.h +++ b/src/common/utf8.h @@ -35,6 +35,13 @@ namespace love **/ std::string to_utf8(LPCWSTR wstr); +/** + * Convert a UTF-8 encoded string to a wide string. + * @param str The UTF-8 string. + * @return A wide string. +**/ +std::wstring to_widestr(const std::string &str); + /** * Replace all occurences of 'find' with 'replace' in a string. * @param str The string to modify. diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp old mode 100644 new mode 100755 index 78b3fea7a..0aacda0b7 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -18,8 +18,22 @@ * 3. This notice may not be removed or altered from any source distribution. **/ +// LOVE +#include "common/config.h" #include "System.h" +#if defined(LOVE_MACOSX) +#include +#elif defined(LOVE_LINUX) +#include +#include +#elif defined(LOVE_WINDOWS) +#include "common/utf8.h" +#include +#include +#pragma comment(lib, "shell32.lib") +#endif + namespace love { namespace system @@ -27,17 +41,80 @@ namespace system std::string System::getOS() const { -#ifdef LOVE_MACOSX +#if defined(LOVE_MACOSX) return "OS X"; -#elif LOVE_WINDOWS +#elif defined(LOVE_WINDOWS) return "Windows"; -#elif LOVE_LINUX +#elif defined(LOVE_LINUX) return "Linux"; #else return "Unknown"; #endif } +bool System::openURL(const std::string &url) const +{ + bool success = false; + +#if defined(LOVE_MACOSX) + + // We could be lazy and use system("open " + url), but this is safer. + CFURLRef cfurl = CFURLCreateWithBytes(nullptr, + (const UInt8 *) url.c_str(), + url.length(), + kCFStringEncodingUTF8, + nullptr); + + success = LSOpenCFURLRef(cfurl, nullptr) == noErr; + CFRelease(cfurl); + +#elif defined(LOVE_LINUX) + + // Spawn a child process, which we'll replace with xdg-open. + pid_t pid = vfork(); + + if (pid == 0) // Child process. + { + // Replace the child process with xdg-open and pass in the URL. + execlp("xdg-open", "xdg-open", url.c_str(), nullptr); + + // exec will only return if it errored, so we should exit with non-zero. + _exit(1); + } + else if (pid > 0) // Parent process. + { + // Wait for xdg-open to complete (or fail.) + int status = 0; + if (waitpid(pid, &status, 0) == pid) + success = (status == 0); + else + success = false; + } + else + { + // vfork() failed. + success = false; + } + +#elif defined(LOVE_WINDOWS) + + // Unicode-aware WinAPI functions don't accept UTF-8, so we need to convert. + std::wstring wurl = to_widestr(url); + + HINSTANCE result = ShellExecuteW(nullptr, + L"open", + wurl.c_str(), + nullptr, + nullptr, + SW_SHOW); + + success = (int) result > 32; + +#endif + + return success; +} + bool System::getConstant(const char *in, System::PowerState &out) { return powerStates.find(in, out); diff --git a/src/modules/system/System.h b/src/modules/system/System.h index 03fa26332..212a4be04 100644 --- a/src/modules/system/System.h +++ b/src/modules/system/System.h @@ -85,6 +85,16 @@ public: **/ virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0; + /** + * Opens the specified URL with the user's default program to handle that + * particular URL type. + * + * @param url The URL to open. + * + * @return Whether the URL was opened successfully. + **/ + virtual bool openURL(const std::string &url) const; + static bool getConstant(const char *in, PowerState &out); static bool getConstant(PowerState in, const char *&out); diff --git a/src/modules/system/wrap_System.cpp b/src/modules/system/wrap_System.cpp index c17c29c3c..6cea1be76 100644 --- a/src/modules/system/wrap_System.cpp +++ b/src/modules/system/wrap_System.cpp @@ -79,6 +79,13 @@ int w_getPowerInfo(lua_State *L) return 3; } +int w_openURL(lua_State *L) +{ + std::string url = luax_checkstring(L, 1); + luax_pushboolean(L, instance->openURL(url)); + return 1; +} + static const luaL_Reg functions[] = { { "getOS", w_getOS }, @@ -86,6 +93,7 @@ static const luaL_Reg functions[] = { "setClipboardText", w_setClipboardText }, { "getClipboardText", w_getClipboardText }, { "getPowerInfo", w_getPowerInfo }, + { "openURL", w_openURL }, { 0, 0 } }; diff --git a/src/modules/system/wrap_System.h b/src/modules/system/wrap_System.h index 3cb89d424..9d89240a8 100644 --- a/src/modules/system/wrap_System.h +++ b/src/modules/system/wrap_System.h @@ -35,6 +35,7 @@ int w_getProcessorCount(lua_State *L); int w_setClipboardText(lua_State *L); int w_getClipboardText(lua_State *L); int w_getPowerInfo(lua_State *L); +int w_openURL(lua_State *L); extern "C" LOVE_EXPORT int luaopen_love_system(lua_State *L); } // system From a1158599ab3d564ebaaf5146cee9da594e719805 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 1 Apr 2014 16:54:51 +0200 Subject: [PATCH 20/24] Use '=' instead of '==' for test command in configure scripts (fixes #866) --- platform/unix/configure.ac | 2 +- platform/unix/genmodules | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/unix/configure.ac b/platform/unix/configure.ac index 4347329f0..219709a7c 100644 --- a/platform/unix/configure.ac +++ b/platform/unix/configure.ac @@ -118,7 +118,7 @@ AS_VAR_IF([enable_exe], [no], [], #else AC_DEFINE([LOVE_BUILD_EXE], [], [Skip building launcher])) AM_CONDITIONAL([LOVE_BUILD_EXE], [test "x$enable_exe" != xno]) -AM_CONDITIONAL([LOVE_NOMPG123], [test "x$enable_mpg123" == xno]) +AM_CONDITIONAL([LOVE_NOMPG123], [test "x$enable_mpg123" = xno]) AM_CONDITIONAL([LOVE_TARGET_OSX], [test "x$enable_osx" != xno]) # Automatic script file rebuilding diff --git a/platform/unix/genmodules b/platform/unix/genmodules index 5be29fae5..1b1ed65e7 100644 --- a/platform/unix/genmodules +++ b/platform/unix/genmodules @@ -96,10 +96,10 @@ genflags() amflag="$(upper $(echo love-$flag | sed 's/-/_/g'))" printf "AC_ARG_ENABLE([$flag], [ --disable-$flag Turn off $prettyflag], [], [$varflag=true])\n" printf "AH_TEMPLATE([$defineflag], [])\n" - printf "if test x\"\$$varflag\" == xtrue; then\n" + printf "if test x\"\$$varflag\" = xtrue; then\n" printf " AC_DEFINE([$defineflag], [])\n" printf "fi\n" - printf "AM_CONDITIONAL([$amflag], [test x\$$varflag == xtrue])\n\n" + printf "AM_CONDITIONAL([$amflag], [test x\$$varflag = xtrue])\n\n" done } From 820d8a8267eaa2bf60bb11969ef0cd22dbf9f1cc Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 1 Apr 2014 16:57:07 +0200 Subject: [PATCH 21/24] Add correct header for waitpid in openURL --- src/modules/system/System.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 0aacda0b7..397cfbb41 100755 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -27,6 +27,7 @@ #elif defined(LOVE_LINUX) #include #include +#include #elif defined(LOVE_WINDOWS) #include "common/utf8.h" #include From 45979471060588edc702c988a7059246d9695ee0 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 1 Apr 2014 20:23:52 +0200 Subject: [PATCH 22/24] Added tag 0.9.1 for changeset 8b113c345e97 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index c1795ff2b..e12439c6a 100644 --- a/.hgtags +++ b/.hgtags @@ -6,3 +6,4 @@ db7cd0682883ed357adef013a326bbb26de28c98 0.6.2 bcca82b60d0f5cd724edbe4ed65db18ab95d4691 0.7.2 e0f98d53debb62347c6433ca0534a0f77f15f76f 0.8.0 38c00c788bcb03bda2ad40efebcdfe7a6be85b4a 0.9.0 +8b113c345e97e7bb7e963e5d67451abdfb05cfde 0.9.1 From 9e49514db97afb2ef6736cf5170f5cd59409da36 Mon Sep 17 00:00:00 2001 From: rude Date: Tue, 1 Apr 2014 20:50:17 +0200 Subject: [PATCH 23/24] Set release date for 0.9.1 in changes.txt. --- changes.txt | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/changes.txt b/changes.txt index 64b39b5b3..cb008f02d 100644 --- a/changes.txt +++ b/changes.txt @@ -1,7 +1,7 @@ LOVE 0.9.1 [Baby Inspector] --------------------------- - Released: N/A + Released: 2014-04-01 * Added Source:clone. * Added ParticleSystem:clone. @@ -59,7 +59,7 @@ LOVE 0.9.1 [Baby Inspector] LOVE 0.9.0 [Baby Inspector] --------------------------- - Released: 2013-12-13 + Released: 2013-12-13 * Added better multiplayer networking support via ENet. * Added --fused command line argument, to simulate fusing. @@ -277,7 +277,7 @@ LOVE 0.9.0 [Baby Inspector] LOVE 0.8.0 [Rubber Piggy] ------------------------- - Released: 2012-04-02 + Released: 2012-04-02 * Added release error screen. * Added alpha to love.graphics.setBackgroundColor. @@ -368,7 +368,7 @@ LOVE 0.8.0 [Rubber Piggy] LOVE 0.7.2 [Game Slave] ----------------------- - Released: 2011-05-04 + Released: 2011-05-04 * Added Framebuffer:get/setWrap. * Added love.event.clear. @@ -394,7 +394,7 @@ LOVE 0.7.2 [Game Slave] LOVE 0.7.1 [Game Slave] ----------------------- - Released: 2011-02-14 + Released: 2011-02-14 * Added source:isPaused() * Added error when initial window can't be created. @@ -430,7 +430,7 @@ LOVE 0.7.1 [Game Slave] LOVE 0.7.0 [Game Slave] ----------------------- - Released: 2010-12-05 + Released: 2010-12-05 * Added love.thread. * Added love.font. @@ -486,7 +486,7 @@ LOVE 0.7.0 [Game Slave] LOVE 0.6.2 [Jiggly Juice] ------------------------- - Released: 2010-03-06 + Released: 2010-03-06 * Fixed a bug causing ImageFonts to cut off some pixels. * Fixed a bug where filled rectangles were too small. @@ -500,7 +500,7 @@ LOVE 0.6.2 [Jiggly Juice] LOVE 0.6.1 [Jiggly Juice] ------------------------- - Released: 2010-02-07 + Released: 2010-02-07 * Added Shape:setGroupIndex and getGroupIndex. * Added Body:setFixedRotation and Body:getFixedRotation. @@ -525,7 +525,7 @@ LOVE 0.6.1 [Jiggly Juice] LOVE 0.6.0 [Jiggly Juice] ------------------------- - Released: 2009-12-24 + Released: 2009-12-24 * Lost track of 0.6.0 changes a long while ago. Don't trust the list below. @@ -562,7 +562,7 @@ LOVE 0.6.0 [Jiggly Juice] LOVE 0.5.0 [Salted Nuts] ------------------------ - Released: 2009-01-02 + Released: 2009-01-02 * Added love.joystick. * Added network support via LuaSocket. @@ -599,7 +599,7 @@ LOVE 0.5.0 [Salted Nuts] LOVE 0.4.0 [Taco Beam] ---------------------- - Released: 2008-08-29 + Released: 2008-08-29 * Added love.physics. (YES!) * Added love.audio.setMode(). @@ -613,7 +613,7 @@ LOVE 0.4.0 [Taco Beam] LOVE 0.3.2 [Lemony Fresh] ------------------------- - Released: 2008-07-04 + Released: 2008-07-04 * Added love.graphics.rectangle() * Added love.graphics.setLineWidth() @@ -632,7 +632,7 @@ LOVE 0.3.2 [Lemony Fresh] LOVE 0.3.1 [Space Meat] ----------------------- - Released: 2008-06-21 + Released: 2008-06-21 * Fixed segfault related to graphics. * Fixed wait-forever bug related to audio. @@ -643,7 +643,7 @@ LOVE 0.3.1 [Space Meat] LOVE 0.3.0 [Mutant Vermin] -------------------------- - Released: 2008-06-17 + Released: 2008-06-17 * Added ParticleSystem. * Added visual error reporting. @@ -663,7 +663,7 @@ LOVE 0.3.0 [Mutant Vermin] LOVE 0.2.1 [Impending Doom] --------------------------- - Released: 2008-03-29 + Released: 2008-03-29 * Added many functions in love.filesystem. * Added a dedicated save-folder for each game. @@ -699,7 +699,7 @@ LOVE 0.2.1 [Impending Doom] LOVE 0.2.0 [Mini-Moose] ----------------------- - Released: 2008-02-06 + Released: 2008-02-06 * Added ImageFont * Added Animation @@ -720,7 +720,7 @@ LOVE 0.1.1 [Santa-Power] ------------------------ Initial release! - Released: 2008-01-13 + Released: 2008-01-13 * Image loading and rendering. * Sound loading and playing. From 606c9b8fb10fe7e0d323ec69b4bb7b5ca760a074 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 1 Apr 2014 20:42:57 -0300 Subject: [PATCH 24/24] Updated changelog --- changes.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changes.txt b/changes.txt index cb008f02d..8c79dab51 100644 --- a/changes.txt +++ b/changes.txt @@ -4,6 +4,7 @@ LOVE 0.9.1 [Baby Inspector] Released: 2014-04-01 * Added Source:clone. + * Added blend mode "screen". * Added ParticleSystem:clone. * Added ParticleSystem:moveTo, has smoother emitter movement compared to setPosition. * Added ParticleSystem:setRelativeRotation. @@ -25,6 +26,7 @@ LOVE 0.9.1 [Baby Inspector] * Added Body:setUserData and Body:getUserData. * Added some missing obscure key constants. * Added optional callback function argument to love.filesystem.getDirectoryItems. + * Added love.system.openURL. * Deprecated Mesh/SpriteBatch/ParticleSystem:setImage. * Deprecated love.graphics.getMaxImageSize and love.graphics.getMaxPointSize. @@ -36,6 +38,8 @@ LOVE 0.9.1 [Baby Inspector] * Fixed TrueType font glyphs which request a monochrome bitmap pixel mode. * Fixed love.graphics.reset causing crashes when called in between love.graphics.push/pop. * Fixed tab characters ("\t") to display properly with love.graphics.print. + * Fixed love.graphics.isCreated to return false when love.window.setMode fails completely. + * Fixed love.window.setMode to not destroy OpenGL resources before checking whether a fullsceren size is supported. * Fixed World:getBodyList and World:getJointList causing hard crashes. * Fixed loading BC4 compressed textures. * Fixed SoundData objects being initialized with garbage values.