diff options
Diffstat (limited to 'nebu/base/system.c')
-rw-r--r-- | nebu/base/system.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/nebu/base/system.c b/nebu/base/system.c new file mode 100644 index 0000000..07a75e7 --- /dev/null +++ b/nebu/base/system.c @@ -0,0 +1,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; +} + |