diff options
author | Oxore <oxore@protonmail.com> | 2019-07-28 21:23:27 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2019-07-28 22:03:03 +0300 |
commit | 1a0886d852bb8a0d9428dc6f54c1e503d06073a0 (patch) | |
tree | 0b49cd355b514f4bd5877f08a41fad7f6269a3e1 /src/target/tetris.c | |
parent | eae3a50f9c791c9aa7dae39cc87d63e0488c4cee (diff) |
Refactor idlist, move all global vars to local scope
- Replace list_foreach with LIST_FOREACH macro.
- Remove `game` global variable and make it local everywhere.
- Move global vars `fld`, `nxt` and `texts` into `game` struct.
- Add `static` qualifier to engine.c's specific global vars.
- Move `sfRenderWindow window` global var to local scope
Diffstat (limited to 'src/target/tetris.c')
-rw-r--r-- | src/target/tetris.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/target/tetris.c b/src/target/tetris.c index 81b2afc..1ef2836 100644 --- a/src/target/tetris.c +++ b/src/target/tetris.c @@ -19,20 +19,10 @@ #include "engine.h" #include "tet_conf.h" -sfRenderWindow *window; -struct idlist *texts; -struct field fld, nxt; -struct game game = { - .started = 0, - .paused = 0, - .scoreCurrent = 0, - .level = 1, - .moveLatency = L00LATENCY, - .lines = 0 -}; - -static void handleWindowEvents() { +static void handleWindowEvents(sfRenderWindow *window) +{ sfEvent event; + while (sfRenderWindow_pollEvent(window, &event)) if (event.type == sfEvtClosed) sfRenderWindow_close(window); @@ -46,6 +36,22 @@ static void register_text(void *obj) int main() { + sfRenderWindow *window; + + struct idlist *texts; + struct field fld, nxt; + struct game game = { + .started = 0, + .paused = 0, + .scoreCurrent = 0, + .level = 1, + .moveLatency = L00LATENCY, + .lines = 0, + .fld = &fld, + .nxt = &nxt, + .texts = NULL, + }; + srand(time(NULL)); game.gameTick = sfClock_create(); game.over_wait_tick = sfClock_create(); @@ -89,15 +95,22 @@ int main() painter_update_field(nxt.id, &nxt); texts = load_texts("dat/texts.yaml"); - list_foreach(texts, register_text); + LIST_FOREACH(texts, text) { + register_text(text->obj); + } - transition_init(); + game.texts = texts; + + transition_init(&game); while (sfRenderWindow_isOpen(window)) { - handleWindowEvents(); - main_loop(); + handleWindowEvents(window); + main_loop(&game); + } + + LIST_FOREACH(texts, text) { + text_destroy(text->obj); } - list_foreach(texts, text_destroy); list_destroy(texts); painter_destroy_drawables(); |