Mercurial > molko
changeset 300:3638b39ef2bf
examples: fix with new game_push function
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 11 Apr 2021 17:43:57 +0200 |
parents | 648f5f949afb |
children | f04b4ee04db3 |
files | examples/example-action/main.c examples/example-animation/main.c examples/example-audio/main.c examples/example-battle/main.c examples/example-cursor/main.c examples/example-debug/main.c examples/example-drawable/main.c examples/example-font/main.c examples/example-gridmenu/main.c examples/example-label/main.c examples/example-message/main.c examples/example-sprite/main.c examples/example-trace/main.c examples/example-ui/main.c libmlk-core/core/game.c tests/test-state.c |
diffstat | 16 files changed, 29 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/example-action/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-action/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -372,7 +372,7 @@ action_stack_add(&events, &chest.event); action_stack_add(&events, &guide.event); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-animation/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-animation/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -120,7 +120,7 @@ sprite_init(&sprite, &numbers, 48, 48); animation_init(&animation, &sprite, 1000); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-audio/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-audio/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -138,7 +138,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); music_finish(&music);
--- a/examples/example-battle/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-battle/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -182,7 +182,7 @@ battle_start(bt); fight_state.data = bt; - game_switch(&fight_state, 0); + game_push(&fight_state); } @@ -239,7 +239,7 @@ struct battle *bt = st->data; if (battle_update(bt, ticks)) - game_switch(&empty_state, 0); + game_push(&empty_state); } static void @@ -268,7 +268,7 @@ static void run(void) { - game_switch(&empty_state, 1); + game_push(&empty_state); game_loop(); }
--- a/examples/example-cursor/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-cursor/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -122,7 +122,7 @@ change(cursor); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-debug/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-debug/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -86,7 +86,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-drawable/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-drawable/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -177,7 +177,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-font/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-font/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -120,7 +120,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-gridmenu/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-gridmenu/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -123,7 +123,7 @@ /* Need to repaint at least once. */ gridmenu_repaint(&menu); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-label/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-label/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -167,7 +167,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-message/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-message/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -102,7 +102,7 @@ message_start(msg); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-sprite/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-sprite/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -136,7 +136,7 @@ changed(); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-trace/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-trace/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -101,7 +101,7 @@ .draw = draw }; - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/examples/example-ui/main.c Sun Apr 11 16:41:34 2021 +0200 +++ b/examples/example-ui/main.c Sun Apr 11 17:43:57 2021 +0200 @@ -298,7 +298,7 @@ prepare(); resize(); - game_switch(&state, 1); + game_push(&state); game_loop(); }
--- a/libmlk-core/core/game.c Sun Apr 11 16:41:34 2021 +0200 +++ b/libmlk-core/core/game.c Sun Apr 11 17:43:57 2021 +0200 @@ -77,7 +77,7 @@ void game_draw(void) { - if (game.state && !(game.inhibit & INHIBIT_STATE_DRAW)) + if (*game.state && !(game.inhibit & INHIBIT_STATE_DRAW)) state_draw(*game.state); } @@ -94,7 +94,7 @@ /* Assuming 50.0 FPS. */ frametime = 1000.0 / 50.0; - while (game.state) { + while (*game.state) { clock_start(&clock); for (union event ev; event_poll(&ev); ) @@ -117,5 +117,9 @@ void game_quit(void) { - // TODO: clear. + for (size_t i = 0; i < UTIL_SIZE(game.states); ++i) + if (game.states[i]) + state_finish(game.states[i]); + + *game.state = NULL; }
--- a/tests/test-state.c Sun Apr 11 16:41:34 2021 +0200 +++ b/tests/test-state.c Sun Apr 11 17:43:57 2021 +0200 @@ -224,7 +224,7 @@ * current state to the specified one and call start on it. However, * if there was already a planned state, it is finished immediately. */ - game_switch(&table[0].state, 1); + game_push(&table[0].state); GREATEST_ASSERT_EQ(table[0].inv.start, 1); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -242,7 +242,7 @@ /* Switch from [0] to [1] quickly, [0] should be closed immediately. */ zero(&table[0].inv); - game_switch(&table[1].state, 1); + game_push(&table[1].state); GREATEST_ASSERT_EQ(table[0].inv.start, 0); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -272,7 +272,7 @@ { .state = INIT(&table[1]) } }; - game_switch(&table[0].state, 1); + game_push(&table[0].state); GREATEST_ASSERT_EQ(table[0].inv.start, 1); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -293,7 +293,7 @@ * be done on the next game_update call instead. */ zero(&table[0].inv); - game_switch(&table[1].state, 0); + game_push(&table[1].state); GREATEST_ASSERT_EQ(table[0].inv.start, 0); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -324,11 +324,11 @@ }; /* Start with 0. */ - game_switch(&table[0].state, 1); + game_push(&table[0].state); /* Ask to switch to 1. */ zero(&table[0].inv); - game_switch(&table[1].state, 1); + game_push(&table[1].state); game_update(0); GREATEST_ASSERT_EQ(table[0].inv.start, 0);