Wait function based on requestAnimationFrame

This commit is contained in:
kichikuou
2018-02-04 15:58:44 +09:00
parent 9f945f89a1
commit d242a024d1
8 changed files with 38 additions and 8 deletions
+2 -1
View File
@@ -13,8 +13,9 @@ EMFLAGS += -s NO_EXIT_RUNTIME=1
LFLAGS := $(EMFLAGS)
LFLAGS += -s EXPORTED_FUNCTIONS="['_main','_ags_setAntialiasedStringMode', '_ald_getdata', '_ald_freedata', '_sjis2unicode']"
LFLAGS += -s EXTRA_EXPORTED_RUNTIME_METHODS="['getValue','getMemory','addRunDependency','removeRunDependency']"
LFLAGS += --js-library emscripten/library.js
SYNCLIST := -s EMTERPRETIFY_SYNCLIST="['_muspcm_load_no','_muspcm_load_mixlr']"
SYNCLIST := -s EMTERPRETIFY_SYNCLIST="['_muspcm_load_no','_muspcm_load_mixlr','_wait_vsync']"
WASMFLAGS := -s WASM=1 -s "BINARYEN_TRAP_MODE='allow'"
ASMJSFLAGS :=
+10
View File
@@ -0,0 +1,10 @@
mergeInto(LibraryManager.library, {
wait_vsync: function() {
EmterpreterAsync.handle(function(resume) {
window.requestAnimationFrame(function() {
if (ABORT) return; // do this manually; we can't call into Browser.safeSetTimeout, because that is paused/resumed!
resume();
});
});
}
});
+1 -1
View File
@@ -1 +1 @@
-s EMTERPRETIFY_WHITELIST='["_ags_eCopyArea", "_ags_fadeIn", "_ags_fadeOut", "_ags_fader", "_ags_whiteIn", "_ags_whiteOut", "_checkMessage", "_check_command", "_commandCD", "_commandCE", "_commandH", "_commandHH", "_commandIK", "_commandMP", "_commandPF", "_commandPW", "_commandSM", "_commandSP", "_commandSQ", "_commandVA", "_commandY", "_commandZT20", "_commandZT21", "_commands2F1E", "_commands2F21", "_commands2F7C", "_commands2F7D", "_commands2F7E", "_commands2F7F", "_eCopyArea1", "_eCopyArea11", "_eCopyArea12", "_eCopyArea13", "_eCopyArea14", "_eCopyArea15", "_eCopyArea16", "_eCopyArea17", "_eCopyArea18", "_eCopyArea19", "_eCopyArea2", "_eCopyArea20", "_eCopyArea21", "_eCopyArea22", "_eCopyArea23", "_eCopyArea24", "_eCopyArea25", "_eCopyArea26", "_eCopyArea3", "_eCopyArea33", "_eCopyArea34", "_eCopyArea39", "_eCopyArea4", "_eCopyArea40", "_eCopyArea48", "_eCopyArea49", "_eCopyArea5", "_eCopyArea5sp", "_eCopyArea6", "_eCopyArea7", "_eCopyArea8", "_eCopyArea9", "_main", "_msg_putMessage", "_mus_pcm_load", "_mus_pcm_mix", "_mus_pcm_start", "_nact_main", "_sdl_keywait", "_sdl_sleep", "_sel_select", "_sys_addMsg", "_sys_hit_any_key", "_sys_key_releasewait"]'
-s EMTERPRETIFY_WHITELIST='["_ags_eCopyArea", "_ags_fadeIn", "_ags_fadeOut", "_ags_fader", "_ags_whiteIn", "_ags_whiteOut", "_checkMessage", "_check_command", "_commandCD", "_commandCE", "_commandH", "_commandHH", "_commandIK", "_commandMP", "_commandPF", "_commandPW", "_commandSM", "_commandSP", "_commandSQ", "_commandVA", "_commandY", "_commandZT20", "_commandZT21", "_commands2F1E", "_commands2F21", "_commands2F7C", "_commands2F7D", "_commands2F7E", "_commands2F7F", "_eCopyArea1", "_eCopyArea11", "_eCopyArea12", "_eCopyArea13", "_eCopyArea14", "_eCopyArea15", "_eCopyArea16", "_eCopyArea17", "_eCopyArea18", "_eCopyArea19", "_eCopyArea2", "_eCopyArea20", "_eCopyArea21", "_eCopyArea22", "_eCopyArea23", "_eCopyArea24", "_eCopyArea25", "_eCopyArea26", "_eCopyArea3", "_eCopyArea33", "_eCopyArea34", "_eCopyArea39", "_eCopyArea4", "_eCopyArea40", "_eCopyArea48", "_eCopyArea49", "_eCopyArea5", "_eCopyArea5sp", "_eCopyArea6", "_eCopyArea7", "_eCopyArea8", "_eCopyArea9", "_main", "_msg_putMessage", "_mus_pcm_load", "_mus_pcm_mix", "_mus_pcm_start", "_nact_main", "_sdl_keywait", "_sdl_sleep", "_sdl_wait_vsync", "_sel_select", "_sys_addMsg", "_sys_hit_any_key", "_sys_key_releasewait"]'
+2 -4
View File
@@ -225,15 +225,13 @@ void nact_main() {
if (cdrom_getpos_count >= 2) {
if (!nact->is_message_locked && nact->input_state == InputNotChecked)
sys_getInputInfo();
sdl_updateScreen();
Sleep(10);
WaitVsync();
cdrom_getpos_count = 0;
}
#endif
#ifdef ENABLE_SDL
if (nact->input_state == InputCheckMissed) {
sdl_updateScreen();
Sleep(10);
WaitVsync();
}
#endif
}
+7
View File
@@ -101,6 +101,7 @@ extern void sdl_setAutoRepeat(boolean bool);
extern void sdl_mainIteration();
extern boolean RawKeyInfo[];
extern void sdl_sleep(int msec);
extern void sdl_wait_vsync();
extern void sdl_sync();
/* 初期化関係 */
@@ -172,5 +173,11 @@ extern void sdl_sync();
#define ResourceInit(c,v) sdl_ResourceInit((c),(v))
#define SetNoShmMode() /* NO */
#define Sleep(ms) sdl_sleep(ms)
#define WaitVsync() sdl_wait_vsync()
#ifdef __EMSCRIPTEN__
// library.js
void wait_vsync(void);
#endif
#endif /* !__SDL_CORE__ */
+9
View File
@@ -84,6 +84,15 @@ void sdl_sleep(int msec) {
#endif
}
void sdl_wait_vsync() {
sdl_updateScreen();
#ifdef __EMSCRIPTEN__
wait_vsync();
#else
SDL_Delay(16);
#endif
}
/* off-screen の指定領域を Main Window へ転送 */
void sdl_updateArea(MyRectangle *src, MyPoint *dst) {
SDL_Rect rect_s, rect_d;
+6 -2
View File
@@ -22,6 +22,7 @@
#include "config.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -195,10 +196,13 @@ static void sdl_getEvent(void) {
int sdl_keywait(int msec, boolean cancel) {
int key=0, n;
int end = get_high_counter(SYSTEMCOUNTER_MSEC) + msec;
int end = msec == INT_MAX ? INT_MAX : get_high_counter(SYSTEMCOUNTER_MSEC) + msec;
while ((n = end - get_high_counter(SYSTEMCOUNTER_MSEC)) > 0) {
sdl_sleep(n < 16 ? n : 16);
if (n <= 16)
sdl_sleep(n);
else
sdl_wait_vsync();
nact->callback();
sdl_getEvent();
key = check_button() | sdl_getKeyInfo() | joy_getinfo();
+1
View File
@@ -168,5 +168,6 @@ extern boolean RawKeyInfo[256];
// #define MainIteration() Xcore_mainIteration()
#define EventCallback Xcore_eventCallback
#define Sleep(ms) usleep((ms) * 1000)
#define WaitVsync() Sleep(16)
#endif /* !__XCORE_H__ */