Emscripten: use EMSCRIPTEN_KEEALIVE

This commit is contained in:
Alam Ed Arias 2025-03-29 14:00:20 -04:00
parent 2749ed1438
commit c99e29b74f
3 changed files with 45 additions and 13 deletions

View file

@ -16,6 +16,10 @@
///
/// code shamelessly inspired by the QuakeC sources, thanks Id :)
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "doomdef.h"
#include "doomstat.h"
#include "command.h"
@ -277,7 +281,11 @@ void COM_BufExecute(void)
/** Executes a string immediately. Used for skirting around WAIT commands.
*/
void COM_ImmedExecute(const char *ptext)
void
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
#endif
COM_ImmedExecute(const char *ptext)
{
size_t i = 0, j = 0;
char line[1024] = "";

View file

@ -774,18 +774,16 @@ void D_SRB2Loop(void)
static boolean D_LockFrame = false;
#ifdef __EMSCRIPTEN__
int pause_loop(void)
int EMSCRIPTEN_KEEPALIVE pause_loop(void)
{
D_LockFrame = true;
//emscripten_sleep(1000);
emscripten_pause_main_loop();
return 0;
}
int resume_loop(void)
int EMSCRIPTEN_KEEPALIVE resume_loop(void)
{
D_LockFrame = false;
//emscripten_sleep(1000);
emscripten_resume_main_loop();
return 0;
}

View file

@ -1979,14 +1979,40 @@ UINT32 I_GetRefreshRate(void)
}
#ifdef __EMSCRIPTEN__
int change_resolution(int x, int y)
int EMSCRIPTEN_KEEPALIVE change_resolution(int x, int y)
{
vid.width = x;
vid.height = y;
return VID_CheckRenderer();
int newmode = -1;
if ( x < BASEVIDWIDTH*1 && y < BASEVIDHEIGHT*1)
newmode = VID_GetModeForSize(BASEVIDWIDTH*1, BASEVIDHEIGHT*1);
else if (x < BASEVIDWIDTH*2 && y < BASEVIDHEIGHT*2)
newmode = VID_GetModeForSize(BASEVIDWIDTH*1, BASEVIDHEIGHT*1);
else if (x < BASEVIDWIDTH*3 && y < BASEVIDHEIGHT*3)
newmode = VID_GetModeForSize(BASEVIDWIDTH*2, BASEVIDHEIGHT*2);
#if 0
else if (x < BASEVIDWIDTH*4 && y < BASEVIDHEIGHT*4)
newmode = VID_GetModeForSize(BASEVIDWIDTH*3, BASEVIDHEIGHT*3);
else if (x < BASEVIDWIDTH*5 && y < BASEVIDHEIGHT*5)
newmode = VID_GetModeForSize(BASEVIDWIDTH*4, BASEVIDHEIGHT*4);
else if (x < BASEVIDWIDTH*6 && y < BASEVIDHEIGHT*6)
newmode = VID_GetModeForSize(BASEVIDWIDTH*5, BASEVIDHEIGHT*5);
else
newmode = VID_GetModeForSize(BASEVIDWIDTH*6, BASEVIDHEIGHT*6);
#else
else
newmode = VID_GetModeForSize(BASEVIDWIDTH*2, BASEVIDHEIGHT*2);
#endif
if (newmode != -1)
setmodeneeded = newmode;
if (setmodeneeded)
return 1;
return 0;
}
void inject_text(const char *text)
void EMSCRIPTEN_KEEPALIVE inject_text(const char *text)
{
event_t event;
size_t len = 0;
@ -1998,7 +2024,7 @@ void inject_text(const char *text)
} while (text[len] != 0x00);
}
void inject_keycode(int key, int type)
void EMSCRIPTEN_KEEPALIVE inject_keycode(int key, int type)
{
event_t event;
if (type == true)
@ -2017,12 +2043,12 @@ void inject_keycode(int key, int type)
if (event.key) D_PostEvent(&event);
}
void unlock_mouse(void)
void EMSCRIPTEN_KEEPALIVE unlock_mouse(void)
{
SDLforceUngrabMouse();
}
void lock_mouse(void)
void EMSCRIPTEN_KEEPALIVE lock_mouse(void)
{
SDLdoGrabMouse();
}