GameMode integration (#258)

This commit is contained in:
Andrei Alexeyev 2020-11-19 01:12:51 +02:00 committed by GitHub
parent 6a44aa433a
commit 103079496e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 109 additions and 0 deletions

View file

@ -29,6 +29,8 @@ Optional:
- OpenSSL (for a better SHA-256 implementation; used in shader cache)
- SPIRV-Cross >= 2019-03-22 (for OpenGL ES backends)
- libshaderc (for OpenGL ES backends)
- GameMode headers (Linux only; for automatic `GameMode
<https://github.com/FeralInteractive/gamemode>`__ integration)
Build-only dependencies
^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -200,6 +200,16 @@ Timing
cases. ``TAISEI_FRAMELIMITER_SLEEP``, ``TAISEI_FRAMELIMITER_COMPENSATE``,
and the ``frameskip`` setting have no effect in this mode.
Miscellaneous
~~~~~~~~~~~~~
**TAISEI_GAMEMODE**
| Default: ``1``
| *Linux only*
If ``1``, enables automatic integration with Feral Interactive's GameMode
daemon. Only meaningful for GameMode-enabled builds.
Logging
~~~~~~~

View file

@ -145,6 +145,7 @@ dep_webpdecoder = dependency('libwebpdecoder', version : '>=0.5', required : f
dep_zip = dependency('libzip', version : '>=1.2', required : false, static : static, fallback : ['libzip', 'libzip_dep'])
dep_zlib = dependency('zlib', required : true, static : static, fallback : ['zlib', 'zlib_dep'])
dep_crypto = dependency('libcrypto', required : false, static : static)
dep_gamemode = dependency('gamemode', required : false, static : static)
dep_m = cc.find_library('m', required : false)
@ -157,6 +158,7 @@ taisei_deps = [
dep_basisu_transcoder,
dep_cglm,
dep_freetype,
dep_gamemode,
dep_koishi,
dep_m,
dep_png,

View file

@ -26,6 +26,7 @@
#include "credits.h"
#include "taskmanager.h"
#include "coroutine.h"
#include "util/gamemode.h"
attr_unused
static void taisei_shutdown(void) {
@ -38,6 +39,7 @@ static void taisei_shutdown(void) {
progress_unload();
gamemode_shutdown();
free_all_refs();
free_resources(true);
taskmgr_global_shutdown();
@ -281,6 +283,7 @@ static void main_post_vfsinit(CallChainResult ccr) {
init_sdl();
taskmgr_global_init();
gamemode_init();
time_init();
init_global(&ctx->cli);
events_init();

49
src/util/gamemode.c Normal file
View file

@ -0,0 +1,49 @@
/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "gamemode.h"
#include "util.h"
#include "taskmanager.h"
#include <gamemode_client.h>
// NOTE: These dbus requests may block, so proxy them off to a background worker thread to not affect load times.
static void *gamemode_init_task(void *a) {
if(gamemode_request_start() < 0) {
log_error("gamemode_request_start() failed: %s", gamemode_error_string());
}
return NULL;
}
static void *gamemode_shutdown_task(void *a) {
if(gamemode_request_end() < 0) {
log_error("gamemode_request_end() failed: %s", gamemode_error_string());
}
return NULL;
}
static inline bool gamemode_control_enabled(void) {
return env_get_int("TAISEI_GAMEMODE", true);
}
void gamemode_init(void) {
if(gamemode_control_enabled()) {
task_detach(taskmgr_global_submit((TaskParams) { .callback = gamemode_init_task }));
}
}
void gamemode_shutdown(void) {
if(gamemode_control_enabled()) {
task_detach(taskmgr_global_submit((TaskParams) { .callback = gamemode_shutdown_task }));
}
}

17
src/util/gamemode.h Normal file
View file

@ -0,0 +1,17 @@
/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#ifndef IGUARD_util_gamemode_h
#define IGUARD_util_gamemode_h
#include "taisei.h"
void gamemode_init(void);
void gamemode_shutdown(void);
#endif // IGUARD_util_gamemode_h

20
src/util/gamemode_stub.c Normal file
View file

@ -0,0 +1,20 @@
/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "gamemode.h"
#include "util.h"
void gamemode_init(void) {
log_info("Compiled without GameMode integration");
}
void gamemode_shutdown(void) {
}

View file

@ -53,3 +53,9 @@ else
# No have_posix check, it might just work.
util_src += files('platform_posix.c')
endif
if dep_gamemode.found()
util_src += files('gamemode.c')
else
util_src += files('gamemode_stub.c')
endif