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
circloO: faster drawing, and a speed test with every ring open
Mason363a8e0408eb009
diff --git a/games/circloo/src/game.c b/games/circloo/src/game.cindex a22223d0..9abff4ab 100644--- a/games/circloo/src/game.c+++ b/games/circloo/src/game.c@@ -188,6 +188,10 @@ void game_init(void) {main_menu();#ifdef CO_START /* (speed tests: make EXTRA=-DCO_START=9, or 106 for hard level 6) */start(CO_START % 100, CO_START > 100);+#ifdef CO_RINGS /* (and every ring open: make EXTRA="-DCO_START=106 -DCO_RINGS=6") */+ void level_debug_grow(void);+ for (int r = 0; r < CO_RINGS; r++) level_debug_grow();+#endif#endif}diff --git a/games/circloo/src/gfx.c b/games/circloo/src/gfx.cindex b5bef0a7..c78a5d51 100644--- a/games/circloo/src/gfx.c+++ b/games/circloo/src/gfx.c@@ -33,6 +33,10 @@ uint16_t mix(uint16_t a, uint16_t b, int t) {return (uint16_t)(r << 11 | g << 5 | bl);}+int gfx_visible(float x0, float y0, float x1, float y1) {+ return y1 >= by0 && y0 < by0 + BAND && x1 >= 0 && x0 < SCREEN_W;+}+void gfx_fill(uint16_t c) {int n = SCREEN_W * BAND;for (int i = 0; i < n; i++) fb[i] = c;@@ -51,14 +55,20 @@ static void row(int y, float a0, float b0, float a1, float b1, uint16_t c, int aif (x1 > SCREEN_W) x1 = SCREEN_W;uint16_t *p = fb + (y - by0) * SCREEN_W;int f0 = (int)ceilf(in_lo), f1 = (int)floorf(in_hi); /* fully covered pixels: [f0, f1) */+ if (f0 < x0) f0 = x0;+ if (f1 > x1) f1 = x1;+ if (f1 < f0) f1 = f0;for (int x = x0; x < x1; x++) {- int cov;- if (x >= f0 && x < f1) cov = 256;- else {- float c0 = e0 ? 0 : clampf(fminf(b0, x + 1.0f) - fmaxf(a0, (float)x), 0, 1);- float c1 = e1 ? 0 : clampf(fminf(b1, x + 1.0f) - fmaxf(a1, (float)x), 0, 1);- cov = (int)((c0 + c1) * 128);+ if (x == f0 && f1 > f0) { /* the inside: filled */+ if (alpha >= 256)+ for (; x < f1; x++) p[x] = c;+ else+ for (; x < f1; x++) p[x] = mix(p[x], c, alpha);+ if (x >= x1) break;}+ float c0 = e0 ? 0 : clampf(fminf(b0, x + 1.0f) - fmaxf(a0, (float)x), 0, 1);+ float c1 = e1 ? 0 : clampf(fminf(b1, x + 1.0f) - fmaxf(a1, (float)x), 0, 1);+ int cov = (int)((c0 + c1) * 128);if (alpha < 256) cov = cov * alpha >> 8;if (cov >= 256) p[x] = c;else if (cov > 0) p[x] = mix(p[x], c, cov);diff --git a/games/circloo/src/gfx.h b/games/circloo/src/gfx.hindex a46d3fb2..3944808a 100644--- a/games/circloo/src/gfx.h+++ b/games/circloo/src/gfx.h@@ -16,6 +16,7 @@ void gfx_push(void); /* the band to the screen */uint16_t rgb(int r, int g, int b);uint16_t mix(uint16_t a, uint16_t b, int t); /* a to b, t of 256 */void gfx_fill(uint16_t c);+int gfx_visible(float x0, float y0, float x1, float y1); /* a box that reaches the band */void gfx_rect(float x0, float y0, float x1, float y1, uint16_t c, int alpha);void gfx_disc(float cx, float cy, float r, uint16_t c, int alpha);void gfx_poly(const float *x, const float *y, int n, uint16_t c, int alpha); /* convex */diff --git a/games/circloo/src/level.c b/games/circloo/src/level.cindex 0c5b1cfd..8eb2e5b2 100644--- a/games/circloo/src/level.c+++ b/games/circloo/src/level.c@@ -228,7 +228,7 @@ static void grow(void) {boundary();}-#ifdef HOST+#if defined HOST || defined CO_RINGSvoid level_debug_grow(void) { grow(); } /* (tests: the next ring now) */#endif@@ -299,6 +299,13 @@ void level_tick(uint32_t keys) {static float sx(float x) { return (x - g.camx) * SCALE + SCREEN_W / 2; }static float sy(float y) { return (y - g.camy) * SCALE + SCREEN_H / 2; }+/* a thick line, if it reaches the band */+static void seg(float x1, float y1, float x2, float y2, float w, uint16_t c) {+ float ax = sx(x1), ay = sy(y1), bx = sx(x2), by = sy(y2), h = w * 0.5f + 1;+ if (!gfx_visible(fminf(ax, bx) - h, fminf(ay, by) - h, fmaxf(ax, bx) + h, fmaxf(ay, by) + h)) return;+ gfx_line(ax, ay, bx, by, w, c, 256);+}+static void ring(float x, float y, int alpha, bool io) {gfx_disc(sx(x), sy(y), 20 * SCALE, g.hue_a, 256);gfx_disc(sx(x), sy(y), 16 * SCALE, g.hue_b, alpha);@@ -332,10 +339,9 @@ void level_draw(void) {/* the level's script: lines, chains, boxes, triangles */for (const int16_t *r = L.data; *r != T_END; r += 2 + r[1]) {const int16_t *v = r + 2;- if (r[0] == T_LINE) gfx_line(sx(P8(v[0])), sy(P8(v[1])), sx(P8(v[2])), sy(P8(v[3])), 6 * SCALE, A, 256);+ if (r[0] == T_LINE) seg(P8(v[0]), P8(v[1]), P8(v[2]), P8(v[3]), 6 * SCALE, A);else if (r[0] == T_CHAIN)- for (int k = 0; k + 1 < v[0]; k++)- gfx_line(sx(P8(v[1 + 2 * k])), sy(P8(v[2 + 2 * k])), sx(P8(v[3 + 2 * k])), sy(P8(v[4 + 2 * k])), 6 * SCALE, A, 256);+ for (int k = 0; k + 1 < v[0]; k++) seg(P8(v[1 + 2 * k]), P8(v[2 + 2 * k]), P8(v[3 + 2 * k]), P8(v[4 + 2 * k]), 6 * SCALE, A);else if (r[0] == T_B) gfx_rect(sx(P8(v[0] - v[2])), sy(P8(v[1] - v[3])), sx(P8(v[0] + v[2])), sy(P8(v[1] + v[3])), A, 256);else if (r[0] == T_T) {float x[3], y[3];@@ -368,7 +374,10 @@ void level_draw(void) {const Body *b = &W.b[L.ball];gfx_disc(sx(b->x / PX_M), sy(b->y / PX_M), 32.5f * SCALE, mix(A, 0, 51), 256);}- for (int k = 0; k < W.nsc; k++) gfx_disc(sx(W.sc[k].x / PX_M), sy(W.sc[k].y / PX_M), (W.sc[k].r / PX_M + 0.5f) * SCALE, A, 256);+ for (int k = 0; k < W.nsc; k++) {+ float x = sx(W.sc[k].x / PX_M), y = sy(W.sc[k].y / PX_M), r = (W.sc[k].r / PX_M + 0.5f) * SCALE;+ if (gfx_visible(x - r, y - r, x + r, y + r)) gfx_disc(x, y, r, A, 256);+ }/* the text of this ring, at the bottom (obj_levelguihandler) */int ringno = (int)lroundf(L.R / 200), alpha = 256;int text = ringno >= 1 && ringno <= 7 ? L.info[ringno] : -1;diff --git a/games/circloo/tests/play.c b/games/circloo/tests/play.cindex c340400a..5841f7e2 100644--- a/games/circloo/tests/play.c+++ b/games/circloo/tests/play.c@@ -116,7 +116,7 @@ int main(int argc, char **argv) {for (int r = 0; r < rings; r++) level_debug_grow();}uint32_t fk = 0;- int ended = 0, stuck = 0;+ int ended = 0, stuck = 0, maxc = 0, maxb = 0;float lx = 0, ly = 0;for (int f = 0; f < frames && g.running; f++) {uint32_t k = 0;@@ -151,6 +151,8 @@ int main(int argc, char **argv) {if (b->vx * b->vx + b->vy * b->vy > 9 && b->x == lx && b->y == ly) stuck++;lx = b->x, ly = b->y;}+ if (W.nc > maxc) maxc = W.nc;+ if (W.nb > maxb) maxb = W.nb;int want = every ? f % every == 0 : 0;for (int i = 0; i < nshots; i++) want |= shots[i] == f;if (want || (draw && f % 2 == 0)) game_draw();@@ -165,7 +167,7 @@ int main(int argc, char **argv) {}(void)ended;save_write();- printf("END state %d level %d hard %d taken %d complete %d frames %d R %.0f stuck %d\n", g.state, L.level, L.hard,- L.taken, L.complete, L.frames, L.R, stuck);+ printf("END state %d level %d hard %d taken %d complete %d frames %d R %.0f stuck %d contacts %d bodies %d\n", g.state,+ L.level, L.hard, L.taken, L.complete, L.frames, L.R, stuck, maxc, maxb);return 0;}diff --git a/games/circloo/tools/speed.sh b/games/circloo/tools/speed.shindex 68f6fe7e..f6ed2b7c 100755--- a/games/circloo/tools/speed.sh+++ b/games/circloo/tools/speed.sh@@ -1,6 +1,7 @@#!/bin/sh# Speed of a level in the emulator (about an N0110's speed): tools/speed.sh LEVEL [ms] [keys]-# LEVEL: 1-14, or 101-106 for hard mode. Builds a copy that starts in that level (CO_START).+# LEVEL: 1-14, or 101-106 for hard mode. Builds a copy that starts in that level (CO_START); SPEED_EXTRA=-DCO_RINGS=6+# opens every ring first.set -ecd "$(dirname "$0")/.."ROOT=$(cd ../.. && pwd)@@ -9,6 +10,6 @@ MS=${2:-8000}KEYS=${3:-"500-1500:right,2000-3000:left,3500-4500:right"}OUT=${TMPDIR:-/tmp}/circloo_speed_$Lrm -rf "$OUT"-make -s build NWLINK="node $ROOT/games/numdash/node_modules/nwlink/bin/nwlink" EXTRA=-DCO_START=$L BUILD_DIR="$OUT" >/dev/null+make -s build NWLINK="node $ROOT/games/numdash/node_modules/nwlink/bin/nwlink" EXTRA="-DCO_START=$L $SPEED_EXTRA" BUILD_DIR="$OUT" >/dev/nullPATH="$ROOT/games/numdash/node_modules/.bin:$PATH" python3 "$ROOT/tools/emu.py" "$OUT/circloo.nwa" --ms "$MS" \--keys "$KEYS" --shots "$((MS - 100))" --out "$OUT" --ram-length 133652 | tail -1