Update LÖVE to changeset 7cb21c8bdd64 (pre 0.10.0)

This commit is contained in:
fysx
2015-12-01 23:07:34 +01:00
parent 7e877716d6
commit 686e1d5f3e
196 changed files with 820 additions and 64699 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ Variant::~Variant()
Variant *Variant::fromLua(lua_State *L, int n, bool allowTables)
{
Variant *v = NULL;
Variant *v = nullptr;
size_t len;
const char *str;
if (n < 0) // Fix the stack position, we might modify it later
+6 -6
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2014 LOVE Development Team
* 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
@@ -90,7 +90,7 @@ double getScreenScale()
return result;
}
const char* getSelectedGameFile()
const char *getSelectedGameFile()
{
static const char *path = NULL;
@@ -191,19 +191,19 @@ bool directoryExists(const char *path)
if (err == -1)
{
if (errno != ENOENT)
SDL_Log ("Error checking for directory %s errno = %d: %s", path, errno, strerror(errno));
SDL_Log("Error checking for directory %s errno = %d: %s", path, errno, strerror(errno));
return false;
}
return S_ISDIR(s.st_mode);
}
bool mkdir(const char* path)
bool mkdir(const char *path)
{
int err = ::mkdir (path, 0770);
int err = ::mkdir(path, 0770);
if (err == -1)
{
SDL_Log ("Error: Could not create directory %s", path);
SDL_Log("Error: Could not create directory %s", path);
return false;
}
+11 -11
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2014 LOVE Development Team
* 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
@@ -35,8 +35,8 @@ namespace android
/**
* Enables or disables immersive mode where the navigation bar is hidden.
**/
void setImmersive (bool immersive_active);
bool getImmersive ();
void setImmersive(bool immersive_active);
bool getImmersive();
/**
* Gets the scale factor of the window's screen, e.g. on Retina displays this
@@ -47,24 +47,24 @@ double getScreenScale();
/**
* Gets the selected love file in the device filesystem.
**/
const char* getSelectedGameFile();
const char *getSelectedGameFile();
bool openURL (const std::string &url);
bool openURL(const std::string &url);
void vibrate (double seconds);
void vibrate(double seconds);
/*
* Helper functions for the filesystem module
*/
void freeGameArchiveMemory (void *ptr);
void freeGameArchiveMemory(void *ptr);
bool loadGameArchiveToMemory (const char* filename, char **ptr, size_t *size);
bool loadGameArchiveToMemory(const char *filename, char **ptr, size_t *size);
bool directoryExists(const char* path);
bool directoryExists(const char *path);
bool mkdir (const char* path);
bool mkdir(const char *path);
bool createStorageDirectories ();
bool createStorageDirectories();
} // android
} // love
-9
View File
@@ -21,15 +21,6 @@
#ifndef LOVE_INT_H
#define LOVE_INT_H
// fixes compile errors of the form:
// "error: expected unqualified-id before '__extension__'"
#ifdef LOVE_ANDROID
#include <sys/endian.h>
#undef swap16
#undef swap32
#undef swap64
#endif
// C standard sized integer types.
#include <stdint.h>
+71
View File
@@ -0,0 +1,71 @@
/**
* 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 <string>
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();
/**
* Causes devices with vibration support to vibrate for about 0.5 seconds.
**/
void vibrate();
} // ios
} // love
#endif // LOVE_IOS
#endif // LOVE_IOS_H
+350
View File
@@ -0,0 +1,350 @@
/**
* 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 <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
#include <vector>
#include <SDL_events.h>
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()
{
NSMutableArray *paths = [NSMutableArray new];
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *enumerator = [manager enumeratorAtPath:getDocumentsDirectory()];
NSString *path = nil;
while ((path = [enumerator nextObject]))
{
// Add .love files plus folders that contain main.lua to our list.
if ([path.pathExtension isEqualToString:@"love"])
[paths addObject:path];
else if ([path.lastPathComponent isEqualToString:@"main.lua"])
[paths addObject:path.stringByDeletingLastPathComponent];
}
return paths;
}
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);
}
}
void vibrate()
{
@autoreleasepool
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
} // ios
} // love
#endif // LOVE_IOS
+63
View File
@@ -0,0 +1,63 @@
/**
* 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 <string>
namespace love
{
namespace macosx
{
/**
* 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);
} // macosx
} // love
#endif // LOVE_MACOSX
#endif // LOVE_OSX_H
+95
View File
@@ -0,0 +1,95 @@
/**
* 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 "macosx.h"
#ifdef LOVE_MACOSX
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include <SDL2/SDL.h>
namespace love
{
namespace macosx
{
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