Ensure linux terminal is still working
This commit is contained in:
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#include "linuxhost.h"
|
||||
#include "game.h"
|
||||
#include "game/game.h"
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
|
||||
int32_t LINUX_TERM_HOST_KEY_PRESS;
|
||||
struct termios origionalTermios;
|
||||
@ -50,12 +51,22 @@ int32_t keyboardCharacterRead() {
|
||||
|
||||
int32_t linuxHostHandoff() {
|
||||
gameInit();
|
||||
|
||||
|
||||
struct timespec spec;
|
||||
uint64_t lastTime;
|
||||
clock_gettime(CLOCK_REALTIME, &spec);
|
||||
lastTime = spec.tv_sec * 1000000000 + spec.tv_nsec;
|
||||
|
||||
while(true) {
|
||||
terminalModeSetCONIO();
|
||||
|
||||
while(!keyboardCharacterAvailable()) {
|
||||
uint8_t result = gameUpdate(0.1f);
|
||||
clock_gettime(CLOCK_REALTIME, &spec);
|
||||
uint64_t currentTime = spec.tv_sec * 1000000000 + spec.tv_nsec;
|
||||
float_t delta = (currentTime - lastTime) / 1000000000.0f;
|
||||
lastTime = currentTime;
|
||||
|
||||
uint8_t result = gameUpdate(delta);
|
||||
if(result == GAME_UPDATE_RESULT_EXIT) return 0;
|
||||
if(result != GAME_UPDATE_RESULT_CONTINUE) return -1;
|
||||
|
||||
@ -64,7 +75,11 @@ int32_t linuxHostHandoff() {
|
||||
|
||||
// Clear console and return to left top
|
||||
printf("\033[2J\033[1;1H");
|
||||
usleep(100000);
|
||||
|
||||
// if tick was less than 16ms, sleep for the remaining time
|
||||
if(delta < 0.016f) {
|
||||
usleep((0.016f - delta) * 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
LINUX_TERM_HOST_KEY_PRESS = keyboardCharacterRead();
|
||||
|
Reference in New Issue
Block a user