Allow hosting webpages to submit console commands to the web port.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6096 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2021-10-31 18:20:51 +00:00
parent 3afbfc8547
commit 23196df675
3 changed files with 33 additions and 10 deletions

View File

@ -56,6 +56,7 @@ int emscriptenfte_setupcanvas(
void(*Button)(unsigned int devid, int down, int mbutton),
int(*Keyboard)(unsigned int devid, int down, int keycode, int unicode),
void(*LoadFile)(char *url, char *mime, int filehandle),
void(*CbufAdd)(const char *text),
void(*buttonevent)(unsigned int joydev, int button, int ispressed, int isstandard),
void(*axisevent)(unsigned int joydev, int axis, float value, int isstandard),
int (*ShouldSwitchToFullscreen)(void)

View File

@ -80,6 +80,7 @@ mergeInto(LibraryManager.library,
button:0,
key:0,
loadfile:0,
cbufaddtext:0,
jbutton:0,
jaxis:0,
wantfullscreen:0,
@ -90,19 +91,34 @@ mergeInto(LibraryManager.library,
{
if (FTEC.evcb.loadfile != 0)
{
var handle = -1;
let handle = -1;
if (arraybuf !== undefined)
handle = _emscriptenfte_buf_createfromarraybuf(arraybuf);
var urlptr = _malloc(url.length+1);
writeStringToMemory(url, urlptr);
var mimeptr = _malloc(mime.length+1);
writeStringToMemory(mime, mimeptr);
let blen = lengthBytesUTF8(url)+1;
let urlptr = _malloc(blen);
stringToUTF8(url, urlptr, blen);
blen = lengthBytesUTF8(mime)+1;
let mimeptr = _malloc(blen);
stringToUTF8(mime, mimeptr,blen);
{{{makeDynCall('viii')}}}(FTEC.evcb.loadfile, urlptr, mimeptr, handle);
_free(mimeptr);
_free(urlptr);
window.focus();
}
},
cbufadd : function(command)
{
if (FTEC.evcb.cbufaddtext != 0)
{
let handle = -1;
let blen = lengthBytesUTF8(command)+1;
let ptr = _malloc(blen);
stringToUTF8(command, ptr, blen);
{{{makeDynCall('vi')}}}(FTEC.evcb.cbufaddtext, ptr);
_free(ptr);
window.focus();
}
},
step : function(timestamp)
{
@ -364,7 +380,7 @@ mergeInto(LibraryManager.library,
}
},
emscriptenfte_setupcanvas__deps: ['$FTEC', '$Browser', 'emscriptenfte_buf_createfromarraybuf'],
emscriptenfte_setupcanvas : function(nw,nh,evresize,evmouse,evmbutton,evkey,evfile,evjbutton,evjaxis,evwantfullscreen)
emscriptenfte_setupcanvas : function(nw,nh,evresize,evmouse,evmbutton,evkey,evfile,evcbufadd,evjbutton,evjaxis,evwantfullscreen)
{
try
{
@ -373,6 +389,7 @@ mergeInto(LibraryManager.library,
FTEC.evcb.button = evmbutton;
FTEC.evcb.key = evkey;
FTEC.evcb.loadfile = evfile;
FTEC.evcb.cbufaddtext = evcbufadd;
FTEC.evcb.jbutton = evjbutton;
FTEC.evcb.jaxis = evjaxis;
FTEC.evcb.wantfullscreen = evwantfullscreen;

View File

@ -219,12 +219,12 @@ static void DOM_ButtonEvent(unsigned int devid, int down, int button)
IN_KeyEvent(mouseid[devid], down, K_MOUSE1+button, 0);
}
}
void DOM_MouseMove(unsigned int devid, int abs, float x, float y, float z, float size)
static void DOM_MouseMove(unsigned int devid, int abs, float x, float y, float z, float size)
{
IN_MouseMove(mouseid[devid], abs, x, y, z, size);
}
void DOM_LoadFile(char *loc, char *mime, int handle)
static void DOM_LoadFile(char *loc, char *mime, int handle)
{
vfsfile_t *file = NULL;
if (handle != -1)
@ -255,7 +255,11 @@ void DOM_LoadFile(char *loc, char *mime, int handle)
VFS_CLOSE(file);
}
}
int VID_ShouldSwitchToFullscreen(void)
static void DOM_CbufAddText(const char *text)
{
Cbuf_AddText(text, RESTRICT_LOCAL);
}
static int VID_ShouldSwitchToFullscreen(void)
{ //if false, mouse grabs won't work and we'll be forced to touchscreen mode.
//we can only go fullscreen when the user clicks something.
//this means that the user will get pissed off at the fullscreen state changing when they first click on the menus after it loading up.
@ -276,6 +280,7 @@ qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette)
DOM_ButtonEvent,
DOM_KeyEvent,
DOM_LoadFile,
DOM_CbufAddText,
IN_GamePadButtonEvent,
IN_GamePadAxisEvent,
VID_ShouldSwitchToFullscreen
@ -303,7 +308,7 @@ void GLVID_DeInit (void)
{
vid.activeapp = false;
emscriptenfte_setupcanvas(-1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
emscriptenfte_setupcanvas(-1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
GL_ForgetPointers();
}