1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include "base/nebu_system.h"
#include "SDL.h"
#include <stdio.h>
Callbacks *current = 0;
static int return_code = -1;
static int redisplay = 0;
void SystemExit() {
fprintf(stderr, "[system] shutting down SDL now\n");
SDL_Quit();
fprintf(stderr, "[system] exiting application\n");
}
unsigned int SystemGetElapsedTime() {
/* fprintf(stderr, "%d\n", SDL_GetTicks()); */
return SDL_GetTicks();
}
int SystemMainLoop() {
SDL_Event event;
return_code = -1;
while(return_code == -1) {
while(SDL_PollEvent(&event) && current) {
switch(event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_JOYAXISMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
SystemHandleInput(&event);
break;
case SDL_QUIT:
SystemExit();
break;
default:
/* ignore event */
break;
}
}
if(redisplay) {
current->display();
redisplay = 0;
} else
current->idle();
}
if(current->exit)
(current->exit)();
return return_code;
}
void SystemRegisterCallbacks(Callbacks *cb) {
current = cb;
}
void SystemExitLoop(int value) {
return_code = value;
}
void SystemPostRedisplay() {
redisplay = 1;
}
|