1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-03 13:49:36 +00:00

Refresh once every 30th of a second

*Roughly...
This commit is contained in:
Peter Evans 2018-03-07 00:20:27 -06:00
parent 91291be889
commit d5450bf743

View File

@ -15,6 +15,8 @@
#include "vm_event.h" #include "vm_event.h"
#include "vm_screen.h" #include "vm_screen.h"
struct timeval refresh_time;
/* /*
* Initialize the video of the vm_screen abstraction. This ends up being * Initialize the video of the vm_screen abstraction. This ends up being
* something that depends on our third-party graphics library; in other * something that depends on our third-party graphics library; in other
@ -30,6 +32,8 @@ vm_screen_init()
return ERR_GFXINIT; return ERR_GFXINIT;
} }
memset(&refresh_time, 0, sizeof(struct timeval));
return OK; return OK;
} }
@ -260,5 +264,23 @@ vm_screen_last_key(vm_screen *scr)
bool bool
vm_screen_dirty(vm_screen *scr) vm_screen_dirty(vm_screen *scr)
{ {
return scr->dirty; struct timeval now;
if (scr->dirty) {
// If this returns an error, I have to assume the computer
// itself may be on fire, or has grown fangs and is presently
// nibbling on the user
if (gettimeofday(&now, NULL) < 0) {
return false;
}
if (now.tv_sec > refresh_time.tv_sec ||
(now.tv_usec > refresh_time.tv_usec + 33333)
) {
memcpy(&refresh_time, &now, sizeof(struct timeval));
return true;
}
}
return false;
} }