[gnome-games] Add libretro plugin
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] Add libretro plugin
- Date: Mon, 20 Feb 2017 08:23:18 +0000 (UTC)
commit 7b2b6bc79e5a5dafe4ec6f6b39fb19a72005d2de
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Feb 19 17:52:05 2017 +0100
Add libretro plugin
Add the libretro plugin, allowing to run standalone Libretro games
shipping a Libretro core descriptor.
https://bugzilla.gnome.org/show_bug.cgi?id=777371
configure.ac | 1 +
plugins/Makefile.am | 4 ++
plugins/libretro/Makefile.am | 3 +
plugins/libretro/configure.ac | 15 ++++++
plugins/libretro/data/Makefile.am | 6 +++
plugins/libretro/data/libretro.plugin | 6 +++
plugins/libretro/src/Makefile.am | 58 ++++++++++++++++++++++++
plugins/libretro/src/libretro-game-source.vala | 41 +++++++++++++++++
plugins/libretro/src/libretro-icon.vala | 23 +++++++++
plugins/libretro/src/libretro-plugin.vala | 12 +++++
plugins/libretro/src/libretro-title.vala | 13 +++++
plugins/libretro/src/libretro-uid.vala | 15 ++++++
12 files changed, 197 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e84a540..d66d6ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,7 @@ m4_include([plugins/nes/configure.ac])
m4_include([plugins/game-boy/configure.ac])
m4_include([plugins/game-boy-advance/configure.ac])
m4_include([plugins/game-cube/configure.ac])
+m4_include([plugins/libretro/configure.ac])
m4_include([plugins/love/configure.ac])
m4_include([plugins/mame/configure.ac])
m4_include([plugins/master-system/configure.ac])
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index e52cdc6..cd409c4 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -36,6 +36,10 @@ if ENABLE_GAME_CUBE_PLUGIN
SUBDIRS += game-cube
endif
+if ENABLE_LIBRETRO_PLUGIN
+SUBDIRS += libretro
+endif
+
if ENABLE_LOVE_PLUGIN
SUBDIRS += love
endif
diff --git a/plugins/libretro/Makefile.am b/plugins/libretro/Makefile.am
new file mode 100644
index 0000000..5d55ad0
--- /dev/null
+++ b/plugins/libretro/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = data src
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/libretro/configure.ac b/plugins/libretro/configure.ac
new file mode 100644
index 0000000..5a490e8
--- /dev/null
+++ b/plugins/libretro/configure.ac
@@ -0,0 +1,15 @@
+PKG_CHECK_MODULES(LIBRETRO_PLUGIN, [
+ gio-2.0
+ glib-2.0 >= $GLIB_MIN_VERSION
+ gtk+-3.0
+ retro-gtk-0.10
+ tracker-sparql-1.0
+], [enable_libretro_plugin=yes], [enable_libretro_plugin=no])
+
+AM_CONDITIONAL(ENABLE_LIBRETRO_PLUGIN, test x$enable_libretro_plugin != xno)
+
+AC_CONFIG_FILES([
+ plugins/libretro/Makefile
+ plugins/libretro/data/Makefile
+ plugins/libretro/src/Makefile
+])
diff --git a/plugins/libretro/data/Makefile.am b/plugins/libretro/data/Makefile.am
new file mode 100644
index 0000000..4c8d3a3
--- /dev/null
+++ b/plugins/libretro/data/Makefile.am
@@ -0,0 +1,6 @@
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-games/plugins
+dist_plugin_DATA = libretro.plugin
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/libretro/data/libretro.plugin b/plugins/libretro/data/libretro.plugin
new file mode 100644
index 0000000..9cab0ab
--- /dev/null
+++ b/plugins/libretro/data/libretro.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=libgames-libretro-plugin
+Name=Libretro Plugin
+Description=Provides support for standalone Libretro games.
+Authors=Adrien Plazas <kekun plazas laposte net>
+Copyright=Copyright © 2017 Adrien Plazas
diff --git a/plugins/libretro/src/Makefile.am b/plugins/libretro/src/Makefile.am
new file mode 100644
index 0000000..39026a0
--- /dev/null
+++ b/plugins/libretro/src/Makefile.am
@@ -0,0 +1,58 @@
+plugindir = $(libdir)/gnome-games/plugins
+plugin_LTLIBRARIES = libgames-libretro-plugin.la
+
+libgames_libretro_plugin_la_DEPENDENCIES = \
+ $(top_builddir)/src/gnome-games.vapi \
+ $(NULL)
+
+libgames_libretro_plugin_la_SOURCES = \
+ libretro-game-source.vala \
+ libretro-icon.vala \
+ libretro-plugin.vala \
+ libretro-title.vala \
+ libretro-uid.vala \
+ $(NULL)
+
+libgames_libretro_plugin_la_VALAFLAGS = \
+ --target-glib=@GLIB_MIN_VERSION@ \
+ --pkg gnome-games \
+ --pkg gio-2.0 \
+ --pkg glib-2.0 \
+ --pkg gtk+-3.0 \
+ --pkg retro-gtk-0.10 \
+ --pkg tracker-sparql-1.0 \
+ --vapidir $(top_builddir)/src \
+ $(NULL)
+
+libgames_libretro_plugin_la_CFLAGS = \
+ $(LIBRETRO_PLUGIN_CFLAGS) \
+ $(GNOME_GAMES_CFLAGS) \
+ -DG_LOG_DOMAIN=\"GamesLibretro\" \
+ -DLOCALEDIR=\"$(localedir)\" \
+ $(NULL)
+
+libgames_libretro_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src \
+ $(NULL)
+
+libgames_libretro_plugin_la_LIBADD = \
+ $(LIBRETRO_PLUGIN_LIBS) \
+ $(GNOME_GAMES_LIBS) \
+ $(NULL)
+
+libgames_libretro_plugin_la_LDFLAGS = \
+ -no-undefined \
+ -module \
+ -avoid-version \
+ $(NULL)
+
+EXTRA_DIST = \
+ $(plugin_DATA) \
+ $(NULL)
+
+MAINTAINERCLEANFILES = \
+ $(BUILT_SOURCES) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/libretro/src/libretro-game-source.vala b/plugins/libretro/src/libretro-game-source.vala
new file mode 100644
index 0000000..774cb3e
--- /dev/null
+++ b/plugins/libretro/src/libretro-game-source.vala
@@ -0,0 +1,41 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.LibretroGameSource : Object, GameSource {
+ private Retro.CoreDescriptor[] descriptors;
+
+ public async void each_game (GameCallback callback) {
+ if (descriptors == null) {
+ descriptors = {};
+ // TODO Should yield for each core descriptor.
+ Retro.ModuleQuery.foreach_core_descriptor (parse_core_descriptor);
+ }
+
+ foreach (var core_descriptor in descriptors) {
+ var game = game_for_core_descriptor (core_descriptor);
+ callback (game);
+ yield;
+ }
+ }
+
+ private bool parse_core_descriptor (Retro.CoreDescriptor core_descriptor) {
+ try {
+ if (core_descriptor.get_is_game ())
+ descriptors += core_descriptor;
+ }
+ catch (Error e) {
+ debug (e.message);
+ }
+
+ return false;
+ }
+
+ private static Game game_for_core_descriptor (Retro.CoreDescriptor core_descriptor) throws Error {
+ var uid = new LibretroUid (core_descriptor);
+ var title = new LibretroTitle (core_descriptor);
+ var icon = new LibretroIcon (core_descriptor);
+ var cover = new DummyCover ();
+ var runner = new RetroRunner.for_core_descriptor (core_descriptor, uid);
+
+ return new GenericGame (title, icon, cover, runner);
+ }
+}
diff --git a/plugins/libretro/src/libretro-icon.vala b/plugins/libretro/src/libretro-icon.vala
new file mode 100644
index 0000000..6ed65c6
--- /dev/null
+++ b/plugins/libretro/src/libretro-icon.vala
@@ -0,0 +1,23 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.LibretroIcon : Object, Icon {
+ private Retro.CoreDescriptor core_descriptor;
+
+ public LibretroIcon (Retro.CoreDescriptor core_descriptor) {
+ this.core_descriptor = core_descriptor;
+ }
+
+ public GLib.Icon? get_icon () {
+ if (!core_descriptor.has_icon ())
+ return null;
+
+ try {
+ return core_descriptor.get_icon ();
+ }
+ catch (Error e) {
+ debug (e.message);
+
+ return null;
+ }
+ }
+}
diff --git a/plugins/libretro/src/libretro-plugin.vala b/plugins/libretro/src/libretro-plugin.vala
new file mode 100644
index 0000000..55c30f6
--- /dev/null
+++ b/plugins/libretro/src/libretro-plugin.vala
@@ -0,0 +1,12 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.LibretroPlugin : Object, Plugin {
+ public GameSource get_game_source () throws Error {
+ return new LibretroGameSource ();
+ }
+}
+
+[ModuleInit]
+public Type register_games_plugin (TypeModule module) {
+ return typeof(Games.LibretroPlugin);
+}
diff --git a/plugins/libretro/src/libretro-title.vala b/plugins/libretro/src/libretro-title.vala
new file mode 100644
index 0000000..7763c05
--- /dev/null
+++ b/plugins/libretro/src/libretro-title.vala
@@ -0,0 +1,13 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.LibretroTitle : Object, Title {
+ private Retro.CoreDescriptor core_descriptor;
+
+ public LibretroTitle (Retro.CoreDescriptor core_descriptor) {
+ this.core_descriptor = core_descriptor;
+ }
+
+ public string get_title () throws Error {
+ return core_descriptor.get_name ();
+ }
+}
diff --git a/plugins/libretro/src/libretro-uid.vala b/plugins/libretro/src/libretro-uid.vala
new file mode 100644
index 0000000..e125864
--- /dev/null
+++ b/plugins/libretro/src/libretro-uid.vala
@@ -0,0 +1,15 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.LibretroUid : Object, Uid {
+ private Retro.CoreDescriptor core_descriptor;
+
+ public LibretroUid (Retro.CoreDescriptor core_descriptor) {
+ this.core_descriptor = core_descriptor;
+ }
+
+ public string get_uid () throws Error {
+ var id = core_descriptor.get_id ();
+
+ return @"libretro-$id";
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]