EMSCRIPTEN: Merging parts of scummvm/scummvm#3686 for fullscreen support, disabling exit buttons (openURL has been fixed in libsdl-org/SDL@15ebad6e7d and is not needed anymore)

This commit is contained in:
Christian Kündig 2022-03-19 02:26:56 +01:00 committed by Eugene Sandulenko
parent e070781618
commit 8f0174689b
6 changed files with 167 additions and 1 deletions

View File

@ -0,0 +1,50 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/scummsys.h"
#if defined(__EMSCRIPTEN__)
#include "backends/platform/sdl/emscripten/emscripten.h"
#include "backends/plugins/sdl/sdl-provider.h"
#include "base/main.h"
int main(int argc, char *argv[]) {
// Create our OSystem instance
g_system = new OSystem_Emscripten();
assert(g_system);
// Pre initialize the backend
g_system->init();
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new SDLPluginProvider());
#endif
// Invoke the actual ScummVM main entry point:
int res = scummvm_main(argc, argv);
// Free OSystem
g_system->destroy();
return res;
}
#endif

View File

@ -0,0 +1,71 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef __EMSCRIPTEN__
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#include <emscripten.h>
#include "backends/platform/sdl/emscripten/emscripten.h"
// Inline JavaScript, see https://emscripten.org/docs/api_reference/emscripten.h.html#inline-assembly-javascript for details
EM_JS(bool, isFullscreen, (), {
return !!document.fullscreenElement;
});
EM_JS(void, toggleFullscreen, (bool enable), {
let canvas = document.getElementById('canvas');
if (enable && !document.fullscreenElement) {
canvas.requestFullscreen();
}
if (!enable && document.fullscreenElement) {
document.exitFullscreen();
}
});
// Overridden functions
bool OSystem_Emscripten::hasFeature(Feature f) {
if (f == kFeatureFullscreenMode)
return true;
if (f == kFeatureNoQuit)
return true;
return OSystem_POSIX::hasFeature(f);
}
bool OSystem_Emscripten::getFeatureState(Feature f) {
if (f == kFeatureFullscreenMode) {
return isFullscreen();
} else {
return OSystem_POSIX::getFeatureState(f);
}
}
void OSystem_Emscripten::setFeatureState(Feature f, bool enable) {
if (f == kFeatureFullscreenMode) {
toggleFullscreen(enable);
} else {
OSystem_POSIX::setFeatureState(f, enable);
}
}
#endif

View File

@ -0,0 +1,35 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PLATFORM_SDL_EMSCRIPTEN_H
#define PLATFORM_SDL_EMSCRIPTEN_H
#include "backends/platform/sdl/posix/posix.h"
class OSystem_Emscripten : public OSystem_POSIX {
public:
bool hasFeature(Feature f) override;
void setFeatureState(Feature f, bool enable) override;
bool getFeatureState(Feature f) override;
};
#endif

View File

@ -72,6 +72,12 @@ MODULE_OBJS += \
switch/switch.o
endif
ifdef EMSCRIPTEN
MODULE_OBJS += \
emscripten/emscripten-main.o \
emscripten/emscripten.o
endif
# We don't use rules.mk but rather manually update OBJS and MODULE_DIRS.
MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS))
OBJS := $(MODULE_OBJS) $(OBJS)

View File

@ -21,7 +21,7 @@
#include "common/scummsys.h"
#if defined(POSIX) && !defined(MACOSX) && !defined(SAMSUNGTV) && !defined(MAEMO) && !defined(GPH_DEVICE) && !defined(GP2X) && !defined(DINGUX) && !defined(OPENPANDORA) && !defined(PLAYSTATION3) && !defined(PSP2) && !defined(NINTENDO_SWITCH)
#if defined(POSIX) && !defined(MACOSX) && !defined(SAMSUNGTV) && !defined(MAEMO) && !defined(GPH_DEVICE) && !defined(GP2X) && !defined(DINGUX) && !defined(OPENPANDORA) && !defined(PLAYSTATION3) && !defined(PSP2) && !defined(NINTENDO_SWITCH) && !defined(__EMSCRIPTEN__)
#include "backends/platform/sdl/posix/posix.h"
#include "backends/plugins/sdl/sdl-provider.h"

4
configure vendored
View File

@ -2900,6 +2900,10 @@ EOF
_freetype_found="true"
if test "$_debug_build" = no; then
_optimization_level=-O3 -g4
append_var DEFINES "-DEMSCRIPTEN"
add_line_to_config_mk 'EMSCRIPTEN = 1'
else
_optimization_level=-O2
fi