mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-22 04:21:23 +00:00
Merge branch 'fix-insane-tty-latency' into 'next'
Fix insane TTY input latency See merge request STJr/SRB2!2360
This commit is contained in:
commit
aa5383e7e0
2 changed files with 90 additions and 68 deletions
|
@ -96,6 +96,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
|
|||
#endif
|
||||
|
||||
#if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__))
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <sys/wait.h>
|
||||
#define NEWSIGNALHANDLER
|
||||
|
@ -855,11 +856,21 @@ static void I_GetConsoleEvents(void)
|
|||
// we use this when sending back commands
|
||||
event_t ev = {0};
|
||||
char key = 0;
|
||||
ssize_t d;
|
||||
struct pollfd pfd =
|
||||
{
|
||||
.fd = STDIN_FILENO,
|
||||
.events = POLLIN,
|
||||
.revents = 0,
|
||||
};
|
||||
|
||||
if (!consolevent)
|
||||
return;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (poll(&pfd, 1, 0) < 1 || !(pfd.revents & POLLIN))
|
||||
return;
|
||||
|
||||
ev.type = ev_console;
|
||||
ev.key = 0;
|
||||
if (read(STDIN_FILENO, &key, 1) == -1 || !key)
|
||||
|
@ -886,7 +897,7 @@ static void I_GetConsoleEvents(void)
|
|||
tty_con.cursor = 0;
|
||||
ev.key = KEY_ENTER;
|
||||
}
|
||||
else return;
|
||||
else continue;
|
||||
}
|
||||
else if (tty_con.cursor < sizeof(tty_con.buffer))
|
||||
{
|
||||
|
@ -894,11 +905,11 @@ static void I_GetConsoleEvents(void)
|
|||
ev.key = tty_con.buffer[tty_con.cursor] = key;
|
||||
tty_con.cursor++;
|
||||
// print the current line (this is differential)
|
||||
d = write(STDOUT_FILENO, &key, 1);
|
||||
write(STDOUT_FILENO, &key, 1);
|
||||
}
|
||||
if (ev.key) D_PostEvent(&ev);
|
||||
//tty_FlushIn();
|
||||
(void)d;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (_WIN32)
|
||||
|
|
|
@ -109,6 +109,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
|
|||
#endif
|
||||
|
||||
#if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__))
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <sys/wait.h>
|
||||
#define NEWSIGNALHANDLER
|
||||
|
@ -616,11 +617,21 @@ void I_GetConsoleEvents(void)
|
|||
// we use this when sending back commands
|
||||
event_t ev = {0};
|
||||
char key = 0;
|
||||
ssize_t d;
|
||||
struct pollfd pfd =
|
||||
{
|
||||
.fd = STDIN_FILENO,
|
||||
.events = POLLIN,
|
||||
.revents = 0,
|
||||
};
|
||||
|
||||
if (!consolevent)
|
||||
return;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (poll(&pfd, 1, 0) < 1 || !(pfd.revents & POLLIN))
|
||||
return;
|
||||
|
||||
ev.type = ev_console;
|
||||
ev.key = 0;
|
||||
if (read(STDIN_FILENO, &key, 1) == -1 || !key)
|
||||
|
@ -647,7 +658,7 @@ void I_GetConsoleEvents(void)
|
|||
tty_con.cursor = 0;
|
||||
ev.key = KEY_ENTER;
|
||||
}
|
||||
else return;
|
||||
else continue;
|
||||
}
|
||||
else if (tty_con.cursor < sizeof (tty_con.buffer))
|
||||
{
|
||||
|
@ -655,11 +666,11 @@ void I_GetConsoleEvents(void)
|
|||
ev.key = tty_con.buffer[tty_con.cursor] = key;
|
||||
tty_con.cursor++;
|
||||
// print the current line (this is differential)
|
||||
d = write(STDOUT_FILENO, &key, 1);
|
||||
write(STDOUT_FILENO, &key, 1);
|
||||
}
|
||||
if (ev.key) D_PostEvent(&ev);
|
||||
//tty_FlushIn();
|
||||
(void)d;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (_WIN32)
|
||||
|
|
Loading…
Reference in a new issue