mirror of
https://github.com/pevans/erc-c.git
synced 2025-01-03 00:29:38 +00:00
Refresh once every thirtieth of a second
And also refresh on keypress
This commit is contained in:
parent
882cf2c166
commit
cfee8baf25
@ -9,10 +9,13 @@
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "vm_screen.h"
|
||||
|
||||
static struct timeval _time;
|
||||
|
||||
/*
|
||||
* Initialize the video of the vm_screen abstraction. This ends up being
|
||||
* something that depends on our third-party graphics library; in other
|
||||
@ -28,6 +31,8 @@ vm_screen_init()
|
||||
return ERR_GFXINIT;
|
||||
}
|
||||
|
||||
gettimeofday(&_time, NULL);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -165,9 +170,10 @@ vm_screen_free(vm_screen *screen)
|
||||
* determine if there's still a need to continue their run loops.
|
||||
*/
|
||||
bool
|
||||
vm_screen_active(vm_screen *screen)
|
||||
vm_screen_active(vm_screen *scr)
|
||||
{
|
||||
SDL_Event event;
|
||||
struct timeval curtime;
|
||||
char ch;
|
||||
|
||||
// There may be _many_ events in the queue; for example, you may be
|
||||
@ -194,13 +200,14 @@ vm_screen_active(vm_screen *screen)
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
screen->key_pressed = true;
|
||||
screen->last_key = ch;
|
||||
scr->dirty = true;
|
||||
scr->key_pressed = true;
|
||||
scr->last_key = ch;
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
// Note we do not erase the last_key value.
|
||||
screen->key_pressed = false;
|
||||
scr->key_pressed = false;
|
||||
|
||||
if (ch == SDLK_ESCAPE) {
|
||||
return false;
|
||||
@ -210,6 +217,17 @@ vm_screen_active(vm_screen *screen)
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&curtime, NULL);
|
||||
|
||||
// If it's been more than 1/30th of a second since our last update,
|
||||
// mark the screen dirty
|
||||
if (curtime.tv_sec > _time.tv_sec ||
|
||||
curtime.tv_usec > _time.tv_usec + 33333
|
||||
) {
|
||||
memcpy(&_time, &curtime, sizeof(struct timeval));
|
||||
scr->dirty = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user