From 26a6c423f96514083204daf491e869ec74c780a6 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 22 Dec 2015 10:06:57 +0100 Subject: [PATCH] =?UTF-8?q?Updated=20to=20latest=20L=C3=96VE=20code=202f5d?= =?UTF-8?q?329b07d7=20(android:=20disable=20JIT=20by=20default=20as=20it?= =?UTF-8?q?=20may=20cause=20performance=20problems)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidManifest.xml | 4 +- jni/love/src/common/OSX.h | 63 ---- jni/love/src/common/OSX.mm | 95 ----- jni/love/src/common/iOS.h | 66 ---- jni/love/src/common/iOS.mm | 327 ------------------ jni/love/src/love.cpp | 5 + jni/love/src/modules/graphics/opengl/Font.cpp | 8 +- jni/love/src/modules/graphics/opengl/Font.h | 2 +- .../src/modules/graphics/opengl/wrap_Font.cpp | 8 +- jni/love/src/modules/keyboard/Keyboard.cpp | 2 +- 10 files changed, 19 insertions(+), 561 deletions(-) delete mode 100644 jni/love/src/common/OSX.h delete mode 100644 jni/love/src/common/OSX.mm delete mode 100644 jni/love/src/common/iOS.h delete mode 100644 jni/love/src/common/iOS.mm diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7db15279..a5faf9a5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ diff --git a/jni/love/src/common/OSX.h b/jni/love/src/common/OSX.h deleted file mode 100644 index 69664679..00000000 --- a/jni/love/src/common/OSX.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2006-2015 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 - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#ifndef LOVE_OSX_H -#define LOVE_OSX_H - -#include "config.h" - -#ifdef LOVE_MACOSX - -#include - -namespace love -{ -namespace osx -{ - -/** - * Returns the filepath of the first detected love file in the Resources folder - * in the main bundle (love.app.) - * Returns an empty string if no love file is found. - **/ -std::string getLoveInResources(); - -/** - * Checks for drop-file events. Returns the filepath if an event occurred, or - * an empty string otherwise. - **/ -std::string checkDropEvents(); - -/** - * Returns the full path to the executable. - **/ -std::string getExecutablePath(); - -/** - * Bounce the dock icon, if the app isn't in the foreground. - **/ -void requestAttention(bool continuous); - -} // osx -} // love - -#endif // LOVE_MACOSX - -#endif // LOVE_OSX_H diff --git a/jni/love/src/common/OSX.mm b/jni/love/src/common/OSX.mm deleted file mode 100644 index e5112b24..00000000 --- a/jni/love/src/common/OSX.mm +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (c) 2006-2015 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 - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "OSX.h" - -#ifdef LOVE_MACOSX - -#import -#import - -#include - -namespace love -{ -namespace osx -{ - -std::string getLoveInResources() -{ - std::string path; - - @autoreleasepool - { - // Check to see if there are any .love files in Resources. - NSString *lovepath = [[NSBundle mainBundle] pathForResource:nil ofType:@"love"]; - - if (lovepath != nil) - path = lovepath.UTF8String; - } - - return path; -} - -std::string checkDropEvents() -{ - std::string dropstr; - SDL_Event event; - - SDL_InitSubSystem(SDL_INIT_VIDEO); - - SDL_PumpEvents(); - if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_DROPFILE, SDL_DROPFILE) > 0) - { - if (event.type == SDL_DROPFILE) - { - dropstr = std::string(event.drop.file); - SDL_free(event.drop.file); - } - } - - SDL_QuitSubSystem(SDL_INIT_VIDEO); - - return dropstr; -} - -std::string getExecutablePath() -{ - @autoreleasepool - { - return std::string([NSBundle mainBundle].executablePath.UTF8String); - } -} - -void requestAttention(bool continuous) -{ - @autoreleasepool - { - if (continuous) - [NSApp requestUserAttention:NSCriticalRequest]; - else - [NSApp requestUserAttention:NSInformationalRequest]; - } -} - -} // osx -} // love - -#endif // LOVE_MACOSX diff --git a/jni/love/src/common/iOS.h b/jni/love/src/common/iOS.h deleted file mode 100644 index 84c1e271..00000000 --- a/jni/love/src/common/iOS.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2006-2015 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 - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#ifndef LOVE_IOS_H -#define LOVE_IOS_H - -#include "config.h" - -#ifdef LOVE_IOS - -#include - -namespace love -{ -namespace ios -{ - -/** - * Gets the filepath of the first detected love file. The main .app Bundle is - * searched first, and then the app's Documents folder. - **/ -std::string getLoveInResources(bool &fused); - -/** - * Gets the directory path where files should be stored. - **/ -std::string getAppdataDirectory(); - -/** - * Get the home directory (on iOS, this really means the app's sandbox dir.) - **/ -std::string getHomeDirectory(); - -/** - * Opens the specified URL with the default program associated with the URL's - * scheme. - **/ -bool openURL(const std::string &url); - -/** - * Returns the full path to the executable. - **/ -std::string getExecutablePath(); - -} // ios -} // love - -#endif // LOVE_IOS -#endif // LOVE_IOS_H diff --git a/jni/love/src/common/iOS.mm b/jni/love/src/common/iOS.mm deleted file mode 100644 index 297f463b..00000000 --- a/jni/love/src/common/iOS.mm +++ /dev/null @@ -1,327 +0,0 @@ -/** - * Copyright (c) 2006-2015 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 - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "iOS.h" - -#ifdef LOVE_IOS - -#import -#import - -#include - -#include - -static NSArray *getLovesInDocuments(); -static bool deleteFileInDocuments(NSString *filename); - -@interface LOVETableViewController : UITableViewController - -- (instancetype)initWithGameList:(NSArray *)list; - -@property (nonatomic) NSMutableArray *gameList; -@property (nonatomic, readonly, copy) NSString *selectedGame; - -@end - -@implementation LOVETableViewController - -- (instancetype)initWithGameList:(NSArray *)list -{ - if ((self = [super init])) - { - _gameList = [[NSMutableArray alloc] initWithArray:list copyItems:YES]; - - self.title = @"LÖVE Games"; - self.navigationItem.rightBarButtonItem = self.editButtonItem; - } - - return self; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - #pragma unused(tableView) - #pragma unused(section) - // We want to list all games plus the no-game screen. - return self.gameList.count + 1; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - static NSString *cellIdentifier = @"LOVETableCell"; - - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; - if (cell == nil) - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; - - if (indexPath.row < (NSInteger) self.gameList.count) - cell.textLabel.text = self.gameList[indexPath.row]; - else - cell.textLabel.text = @"No-game screen"; - - return cell; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - #pragma unused(tableView) - if (indexPath.row < (NSInteger) self.gameList.count) - _selectedGame = [(NSString *)(self.gameList[indexPath.row]) copy]; - else - { - // We test against nil to check if a game has been selected, so we'll - // just use an empty string instead to represent the no-game screen. - _selectedGame = @""; - } -} - -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (editingStyle != UITableViewCellEditingStyleDelete) - return; - - if (indexPath.row >= (NSInteger) self.gameList.count) - return; - - NSString *filename = self.gameList[indexPath.row]; - - // Delete the file. - if (deleteFileInDocuments(filename)) - { - [self.gameList removeObjectAtIndex:indexPath.row]; - [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; - } -} - -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath; -{ - #pragma unused(tableView) - // The no-game screen isn't removable. - return indexPath.row < (NSInteger) self.gameList.count; -} - -@end - -static NSString *getDocumentsDirectory() -{ - NSArray *docdirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - return docdirs[0]; -} - -static NSArray *getLovesInDocuments() -{ - NSString *documents = getDocumentsDirectory(); - NSArray *filepaths = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documents error:nil]; - return [filepaths pathsMatchingExtensions:@[@"love"]]; -} - -static bool deleteFileInDocuments(NSString *filename) -{ - NSString *documents = getDocumentsDirectory(); - - NSString *file = [documents stringByAppendingPathComponent:filename]; - bool success = [[NSFileManager defaultManager] removeItemAtPath:file error:nil]; - - if (success) - NSLog(@"Deleted file %@ in Documents folder.", filename); - - return success; -} - -static int dropFileEventFilter(void *userdata, SDL_Event *event) -{ - @autoreleasepool - { - if (event->type != SDL_DROPFILE) - return 1; - - NSString *fname = @(event->drop.file); - NSFileManager *fmanager = [NSFileManager defaultManager]; - - if ([fmanager fileExistsAtPath:fname] && [fname.pathExtension isEqual:@"love"]) - { - NSString *documents = getDocumentsDirectory(); - - documents = documents.stringByStandardizingPath.stringByResolvingSymlinksInPath; - fname = fname.stringByStandardizingPath.stringByResolvingSymlinksInPath; - - // Is the file inside the Documents directory? - if ([fname hasPrefix:documents]) - { - LOVETableViewController *vc = (__bridge LOVETableViewController *) userdata; - - // Update the game list. - NSArray *games = getLovesInDocuments(); - vc.gameList = [[NSMutableArray alloc] initWithArray:games copyItems:YES]; - [vc.tableView reloadData]; - - SDL_free(event->drop.file); - return 0; - } - } - - return 1; - } -} - -namespace love -{ -namespace ios -{ - -/** - * Displays a full-screen list of available LOVE games for the user to choose. - * Returns the index of the selected game from the list. The list of games - * includes the no-game screen, and the function will return an index outside - * of the array's range if that is selected. - **/ -static NSString *showGameList(NSArray *filenames) -{ - // Game list view controller. - LOVETableViewController *tablecontroller = [[LOVETableViewController alloc] initWithGameList:filenames]; - - // Navigation view controller (only used for the header bar right now.) - // Contains the game list view/controller. - UINavigationController *navcontroller = [[UINavigationController alloc] initWithRootViewController:tablecontroller]; - - UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - window.rootViewController = navcontroller; - - SDL_EventFilter oldfilter = nullptr; - void *oldudata = nullptr; - SDL_GetEventFilter(&oldfilter, &oldudata); - - // Manually retain the table VC and use it for the event filter userdata. - // We need to set a custom event filter to update the table when .love files - // are opened by the user. - void *tableudata = (void *) CFBridgingRetain(tablecontroller); - SDL_SetEventFilter(dropFileEventFilter, tableudata); - - [window makeKeyAndVisible]; - - // Process events until a game in the list is selected. - NSRunLoop *runloop = [NSRunLoop currentRunLoop]; - while (tablecontroller.selectedGame == nil) - { - [runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantPast]]; - [runloop runMode:UITrackingRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0/60.0]]; - } - - // The window will get released and cleaned up once we go out of scope. - window.hidden = YES; - - SDL_SetEventFilter(oldfilter, oldudata); - CFBridgingRelease(tableudata); - - return tablecontroller.selectedGame; -} - -std::string getLoveInResources(bool &fused) -{ - fused = false; - std::string path; - - @autoreleasepool - { - // Start by looking in the main bundle (.app) folder for .love files. - NSArray *bundlepaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"love" inDirectory:nil]; - - if (bundlepaths.count > 0) - { - // The game should be fused if we have something here. - fused = true; - return [bundlepaths[0] UTF8String]; - } - - // Otherwise look in the app's Documents directory. The game won't be - // fused. - NSArray *filepaths = getLovesInDocuments(); - - // Let the user select a game from the un-fused list. - NSString *selectedfile = showGameList(filepaths); - - // The string length might be 0 if the no-game screen was selected. - if (selectedfile != nil && selectedfile.length > 0) - { - NSString *documents = getDocumentsDirectory(); - path = [documents stringByAppendingPathComponent:selectedfile].UTF8String; - } - } - - return path; -} - -std::string getAppdataDirectory() -{ - NSSearchPathDirectory searchdir = NSApplicationSupportDirectory; - std::string path; - - @autoreleasepool - { - NSArray *dirs = NSSearchPathForDirectoriesInDomains(searchdir, NSUserDomainMask, YES); - - if (dirs.count > 0) - path = [dirs[0] UTF8String]; - } - - return path; -} - -std::string getHomeDirectory() -{ - std::string path; - - @autoreleasepool - { - path = [NSHomeDirectory() UTF8String]; - } - - return path; -} - -bool openURL(const std::string &url) -{ - bool success = false; - - @autoreleasepool - { - UIApplication *app = [UIApplication sharedApplication]; - NSURL *nsurl = [NSURL URLWithString:@(url.c_str())]; - - if ([app canOpenURL:nsurl]) - success = [app openURL:nsurl]; - } - - return success; -} - -std::string getExecutablePath() -{ - @autoreleasepool - { - return std::string([NSBundle mainBundle].executablePath.UTF8String); - } -} - -} // ios -} // love - -#endif // LOVE_IOS diff --git a/jni/love/src/love.cpp b/jni/love/src/love.cpp index 4d08b8d0..1a3e3636 100644 --- a/jni/love/src/love.cpp +++ b/jni/love/src/love.cpp @@ -46,6 +46,10 @@ extern "C" { #ifdef LOVE_ANDROID #include "common/android.h" +extern "C" +{ +#include "luajit.h" +} #endif #ifdef LOVE_WINDOWS @@ -252,6 +256,7 @@ int main(int argc, char **argv) luaL_openlibs(L); #ifdef LOVE_ANDROID + luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE| LUAJIT_MODE_OFF); lua_register(L, "print", l_print_sdl_log); #endif diff --git a/jni/love/src/modules/graphics/opengl/Font.cpp b/jni/love/src/modules/graphics/opengl/Font.cpp index d98372ec..404bd85d 100644 --- a/jni/love/src/modules/graphics/opengl/Font.cpp +++ b/jni/love/src/modules/graphics/opengl/Font.cpp @@ -901,13 +901,13 @@ void Font::getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::ve } } -void Font::getWrap(const std::string &text, float wraplimit, std::vector &lines, std::vector *linewidths) +void Font::getWrap(const std::vector &text, float wraplimit, std::vector &lines, std::vector *linewidths) { - ColoredCodepoints codepoints; - getCodepointsFromString(text, codepoints.cps); + ColoredCodepoints cps; + getCodepointsFromString(text, cps); std::vector codepointlines; - getWrap(codepoints, wraplimit, codepointlines, linewidths); + getWrap(cps, wraplimit, codepointlines, linewidths); std::string line; diff --git a/jni/love/src/modules/graphics/opengl/Font.h b/jni/love/src/modules/graphics/opengl/Font.h index 3f65d777..df5fcd90 100644 --- a/jni/love/src/modules/graphics/opengl/Font.h +++ b/jni/love/src/modules/graphics/opengl/Font.h @@ -160,7 +160,7 @@ public: * @param max_width Optional output of the maximum width * Returns a vector with the lines. **/ - void getWrap(const std::string &text, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); + void getWrap(const std::vector &text, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); void getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); /** diff --git a/jni/love/src/modules/graphics/opengl/wrap_Font.cpp b/jni/love/src/modules/graphics/opengl/wrap_Font.cpp index d449925b..b47dabde 100644 --- a/jni/love/src/modules/graphics/opengl/wrap_Font.cpp +++ b/jni/love/src/modules/graphics/opengl/wrap_Font.cpp @@ -21,6 +21,7 @@ // LOVE #include "common/config.h" #include "wrap_Font.h" +#include "wrap_Text.h" // C++ #include @@ -56,13 +57,16 @@ int w_Font_getWidth(lua_State *L) int w_Font_getWrap(lua_State *L) { Font *t = luax_checkfont(L, 1); - const char *str = luaL_checkstring(L, 2); + + std::vector text; + luax_checkcoloredstring(L, 2, text); + float wrap = (float) luaL_checknumber(L, 3); int max_width = 0; std::vector lines; std::vector widths; - luax_catchexcept(L, [&]() { t->getWrap(str, wrap, lines, &widths); }); + luax_catchexcept(L, [&]() { t->getWrap(text, wrap, lines, &widths); }); for (int width : widths) max_width = std::max(max_width, width); diff --git a/jni/love/src/modules/keyboard/Keyboard.cpp b/jni/love/src/modules/keyboard/Keyboard.cpp index 969e27f2..d865ab98 100644 --- a/jni/love/src/modules/keyboard/Keyboard.cpp +++ b/jni/love/src/modules/keyboard/Keyboard.cpp @@ -368,7 +368,7 @@ StringMap::Entry Keyboard::scan {"nonusbackslash", SCANCODE_NONUSBACKSLASH}, {"application", SCANCODE_APPLICATION}, {"power", SCANCODE_POWER}, - {"=", SCANCODE_KP_EQUALS}, + {"kp=", SCANCODE_KP_EQUALS}, {"f13", SCANCODE_F13}, {"f14", SCANCODE_F14}, {"f15", SCANCODE_F15},