mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
libsuperderpy: Make main event queue public
This allows games to register custom event sources, such as audio recorder.
This commit is contained in:
parent
e58b95e887
commit
3cc20cdf32
3 changed files with 15 additions and 15 deletions
|
@ -359,8 +359,8 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
||||||
|
|
||||||
al_init_user_event_source(&(game->event_source));
|
al_init_user_event_source(&(game->event_source));
|
||||||
|
|
||||||
game->_priv.event_queue = al_create_event_queue();
|
game->event_queue = al_create_event_queue();
|
||||||
if (!game->_priv.event_queue) {
|
if (!game->event_queue) {
|
||||||
FatalError(game, true, "Failed to create event queue.");
|
FatalError(game, true, "Failed to create event queue.");
|
||||||
al_destroy_display(game->display);
|
al_destroy_display(game->display);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -408,28 +408,28 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
||||||
static void ProgressStub(struct Game* game) {}
|
static void ProgressStub(struct Game* game) {}
|
||||||
|
|
||||||
SYMBOL_EXPORT int libsuperderpy_start(struct Game* game) {
|
SYMBOL_EXPORT int libsuperderpy_start(struct Game* game) {
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_display_event_source(game->display));
|
al_register_event_source(game->event_queue, al_get_display_event_source(game->display));
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_keyboard_event_source());
|
al_register_event_source(game->event_queue, al_get_keyboard_event_source());
|
||||||
if (game->input.available.mouse) {
|
if (game->input.available.mouse) {
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_mouse_event_source());
|
al_register_event_source(game->event_queue, al_get_mouse_event_source());
|
||||||
}
|
}
|
||||||
if (game->input.available.joystick) {
|
if (game->input.available.joystick) {
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_joystick_event_source());
|
al_register_event_source(game->event_queue, al_get_joystick_event_source());
|
||||||
}
|
}
|
||||||
if (game->input.available.touch) {
|
if (game->input.available.touch) {
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_touch_input_event_source());
|
al_register_event_source(game->event_queue, al_get_touch_input_event_source());
|
||||||
#ifdef LIBSUPERDERPY_MOUSE_EMULATION
|
#ifdef LIBSUPERDERPY_MOUSE_EMULATION
|
||||||
al_register_event_source(game->_priv.event_queue, al_get_touch_input_mouse_emulation_event_source());
|
al_register_event_source(game->event_queue, al_get_touch_input_mouse_emulation_event_source());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
al_register_event_source(game->_priv.event_queue, &(game->event_source));
|
al_register_event_source(game->event_queue, &(game->event_source));
|
||||||
|
|
||||||
// HACK: some backends correct the window size only after the display has been already created.
|
// HACK: some backends correct the window size only after the display has been already created.
|
||||||
// if we start loading with wrong size, it won't be corrected until the main loop is entered back,
|
// if we start loading with wrong size, it won't be corrected until the main loop is entered back,
|
||||||
// so the loading screen will stay at the wrong size.
|
// so the loading screen will stay at the wrong size.
|
||||||
// Turns out SDL/Wayland needs some help with emitting the resize event before it's too late.
|
// Turns out SDL/Wayland needs some help with emitting the resize event before it's too late.
|
||||||
ALLEGRO_EVENT event;
|
ALLEGRO_EVENT event;
|
||||||
al_peek_next_event(game->_priv.event_queue, &event);
|
al_peek_next_event(game->event_queue, &event);
|
||||||
ClearScreen(game);
|
ClearScreen(game);
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
|
||||||
Console_Unload(game);
|
Console_Unload(game);
|
||||||
al_destroy_display(game->display);
|
al_destroy_display(game->display);
|
||||||
al_destroy_user_event_source(&(game->event_source));
|
al_destroy_user_event_source(&(game->event_source));
|
||||||
al_destroy_event_queue(game->_priv.event_queue);
|
al_destroy_event_queue(game->event_queue);
|
||||||
al_restore_default_mixer();
|
al_restore_default_mixer();
|
||||||
al_destroy_mixer(game->audio.fx);
|
al_destroy_mixer(game->audio.fx);
|
||||||
al_destroy_mixer(game->audio.music);
|
al_destroy_mixer(game->audio.music);
|
||||||
|
|
|
@ -153,6 +153,7 @@ struct Params {
|
||||||
struct Game {
|
struct Game {
|
||||||
ALLEGRO_DISPLAY* display; /*!< Main Allegro display. */
|
ALLEGRO_DISPLAY* display; /*!< Main Allegro display. */
|
||||||
ALLEGRO_EVENT_SOURCE event_source; /*!< Event source for user events. */
|
ALLEGRO_EVENT_SOURCE event_source; /*!< Event source for user events. */
|
||||||
|
ALLEGRO_EVENT_QUEUE* event_queue; /*!< Main event queue. */
|
||||||
struct {
|
struct {
|
||||||
ALLEGRO_VOICE* v; /*!< Main voice used by the game. */
|
ALLEGRO_VOICE* v; /*!< Main voice used by the game. */
|
||||||
ALLEGRO_MIXER* mixer; /*!< Main mixer of the game. */
|
ALLEGRO_MIXER* mixer; /*!< Main mixer of the game. */
|
||||||
|
@ -216,7 +217,6 @@ struct Game {
|
||||||
ALLEGRO_FONT* font_bsod; /*!< Font used in Blue Screens of Derp. */
|
ALLEGRO_FONT* font_bsod; /*!< Font used in Blue Screens of Derp. */
|
||||||
char console[5][1024];
|
char console[5][1024];
|
||||||
unsigned int console_pos;
|
unsigned int console_pos;
|
||||||
ALLEGRO_EVENT_QUEUE* event_queue; /*!< Main event queue. */
|
|
||||||
bool show_timeline;
|
bool show_timeline;
|
||||||
|
|
||||||
double speed; /*!< Speed of the game */
|
double speed; /*!< Speed of the game */
|
||||||
|
|
|
@ -226,8 +226,8 @@ static inline bool MainloopEvents(struct Game* game) {
|
||||||
|
|
||||||
if (game->_priv.paused && !IS_EMSCRIPTEN) {
|
if (game->_priv.paused && !IS_EMSCRIPTEN) {
|
||||||
// there's no frame flipping when paused, so avoid pointless busylooping
|
// there's no frame flipping when paused, so avoid pointless busylooping
|
||||||
al_wait_for_event(game->_priv.event_queue, &ev);
|
al_wait_for_event(game->event_queue, &ev);
|
||||||
} else if (!al_get_next_event(game->_priv.event_queue, &ev)) {
|
} else if (!al_get_next_event(game->event_queue, &ev)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ static inline bool MainloopEvents(struct Game* game) {
|
||||||
al_unref_user_event(&ev.user);
|
al_unref_user_event(&ev.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (!al_is_event_queue_empty(game->_priv.event_queue));
|
} while (!al_is_event_queue_empty(game->event_queue));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue