Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Mr Bullet: a measuring build, 32 KB kept for Box2D's steps
Mason363d089b6098c09
diff --git a/games/mrbullet/src/main.c b/games/mrbullet/src/main.cindex 09a26968..bf552af0 100644--- a/games/mrbullet/src/main.c+++ b/games/mrbullet/src/main.c@@ -19,14 +19,50 @@ uint32_t perf_step_max __attribute__((used));void np_push(int x, int y, int w, int h, const color_t *px) { plat_push(x, y, w, h, px); }extern char _heap_start[], _heap_end[];+#ifdef MEASURE+/* (a build for tools/emu.py: the levels of MEASURE_LIST played with shots at set angles, each step drawn; perf_max+ is then the slowest step with its drawing, perf_slow the steps over 33 ms) */+#include "game.h"+static const int16_t measure_list[] = {MEASURE_LIST};+static void scene(void *ctx) {+ (void)ctx;+ draw_world(true);+ draw_hud("Level", "Left Right", "turn");+}+int main(void) {+ uint64_t level[LEVEL_MAX_BYTES / 8 + 1];+ uint64_t strip[SCREEN_W * STRIP_H * 2 / 8];+ b2_heap_limit = (long)(_heap_end - _heap_start) - 32768;+ gfx_buf = (uint16_t *)strip;+ for (unsigned k = 0; k < sizeof measure_list / sizeof *measure_list; k++) {+ if (!game_load(measure_list[k] - 1, (uint8_t *)level)) continue;+ for (int s = 0; s < 480; s++) {+ if (s % 90 == 0) {+ g.aim = -0.2f - 0.25f * (float)(s / 90);+ g.ch[g.hero].left = 0;+ game_fire();+ }+ uint32_t t0 = plat_millis();+ game_step();+ gfx_render(scene, 0, 0, SCREEN_H);+ uint32_t dt = plat_millis() - t0;+ if (dt > perf_max) perf_max = dt;+ if (dt > 33) perf_slow++;+ perf_frames++;+ }+ game_end();+ }+ for (;;) plat_sleep(1000);+}+#elseint main(void) {/* on main's stack: the level's bytes, the screen's strip and the save's scratch memory; the heap is Box2D's */uint64_t level[LEVEL_MAX_BYTES / 8 + 1];uint64_t strip[SCREEN_W * STRIP_H * 2 / 8];uint64_t scratch[SAVE_SCRATCH / 8];plat_begin();- /* Box2D makes no new contact past the heap less 16 KB (for a step's islands and the broad phase growing) */- b2_heap_limit = (long)(_heap_end - _heap_start) - 16384;+ /* Box2D makes no new contact past the heap less 32 KB (for a step's islands and the broad phase growing) */+ b2_heap_limit = (long)(_heap_end - _heap_start) - 32768;ui_init((uint8_t *)level, (uint16_t *)strip, scratch);for (;;) {uint32_t now = plat_millis();@@ -46,3 +82,4 @@ int main(void) {return plat_end();}#endif+#endifdiff --git a/games/mrbullet/tests/play.c b/games/mrbullet/tests/play.cindex 2ac40beb..737373e8 100644--- a/games/mrbullet/tests/play.c+++ b/games/mrbullet/tests/play.c@@ -261,6 +261,26 @@ int main(int argc, char **argv) {}return 0;}+ if (argc >= 3 && !strcmp(argv[1], "seq")) {+ /* levels in a row, shot as the calculator's measuring build shoots them: Box2D's memory after each */+ b2_heap_limit = 81000;+ for (int k = 2; k < argc; k++) {+ b2_heap_peak = b2_heap_now;+ game_load(atoi(argv[k]) - 1, (uint8_t *)level_mem);+ for (int s = 0; s < 480; s++) {+ if (s % 90 == 0) {+ g.aim = -0.2f - 0.25f * (float)(s / 90);+ g.ch[g.hero].left = 0;+ game_fire();+ }+ game_step();+ }+ long peak = b2_heap_peak;+ game_end();+ printf("level %s: Box2D's memory at most %ld, %ld left after\n", argv[k], peak, b2_heap_now);+ }+ return 0;+ }if (argc >= 5 && !strcmp(argv[1], "try")) {/* which angles (degrees, by tenths) clear a level with one shot */int l = atoi(argv[2]) - 1;