mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-03-04 09:11:27 +01:00
Add pre/post logic/draw handlers
This commit is contained in:
parent
c6b71f1686
commit
52fbb86d2f
3 changed files with 20 additions and 0 deletions
|
@ -28,6 +28,9 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
ClearScreen(game);
|
||||
al_set_target_backbuffer(game->display);
|
||||
struct Gamestate* tmp = game->_priv.gamestates;
|
||||
if (game->handlers.predraw) {
|
||||
(*game->handlers.predraw)(game);
|
||||
}
|
||||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
|
@ -35,10 +38,16 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (game->handlers.postdraw) {
|
||||
(*game->handlers.postdraw)(game);
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void LogicGamestates(struct Game* game, double delta) {
|
||||
struct Gamestate* tmp = game->_priv.gamestates;
|
||||
if (game->handlers.prelogic) {
|
||||
(*game->handlers.prelogic)(game, delta);
|
||||
}
|
||||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started) && (!tmp->paused)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
|
@ -46,6 +55,9 @@ SYMBOL_INTERNAL void LogicGamestates(struct Game* game, double delta) {
|
|||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (game->handlers.postlogic) {
|
||||
(*game->handlers.postlogic)(game, delta);
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void ReloadGamestates(struct Game* game) {
|
||||
|
|
|
@ -76,6 +76,10 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
|
||||
game->handlers.event = NULL;
|
||||
game->handlers.destroy = NULL;
|
||||
game->handlers.prelogic = NULL;
|
||||
game->handlers.postlogic = NULL;
|
||||
game->handlers.predraw = NULL;
|
||||
game->handlers.postdraw = NULL;
|
||||
|
||||
game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10);
|
||||
game->config.music = strtol(GetConfigOptionDefault(game, "SuperDerpy", "music", "10"), NULL, 10);
|
||||
|
|
|
@ -143,6 +143,10 @@ struct Game {
|
|||
struct {
|
||||
bool (*event)(struct Game* game, ALLEGRO_EVENT* ev);
|
||||
void (*destroy)(struct Game* game);
|
||||
void (*prelogic)(struct Game* game, double delta);
|
||||
void (*postlogic)(struct Game* game, double delta);
|
||||
void (*predraw)(struct Game* game);
|
||||
void (*postdraw)(struct Game* game);
|
||||
} handlers;
|
||||
|
||||
LIBSUPERDERPY_DATA_TYPE* data;
|
||||
|
|
Loading…
Add table
Reference in a new issue