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
Hollow Knight: the Knight no longer disappears when a room fills with geo, debris and drips (sprites well off the screen take no room, and those give way to the others when there is none left; the room's own sprites leave room for them); no longer stuck in a battle gate that closes on him (pushed out of it whole); a write past the end of the hit list in rooms with more than 64 objects fixed
Mason Chen369f0f71d20c
diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.cindex 5bd73d55..8b5ba083 100644--- a/games/hollowknight/src/enemy.c+++ b/games/hollowknight/src/enemy.c@@ -1821,7 +1821,7 @@ static void spurts_draw(void) {if (!s->on || s->anim.sprite < 0) continue;Inst in;sprite_inst(s->anim.sprite, s->x, s->y, -0.12f, s->scale * s->dir, s->scale, 0, &in);- gfx_actor(&in, SORT_KEY(0, 0));+ gfx_actor_minor(&in, SORT_KEY(0, 0));}}@@ -6761,7 +6761,7 @@ void enemies_draw(void) {if (!g->on) continue;Inst in;sprite_inst(g->anim.sprite, g->x, g->y, 0.0015f, GEO_SCALE, GEO_SCALE, 0, &in);- gfx_actor(&in, SORT_KEY(0, 0));+ gfx_actor_minor(&in, SORT_KEY(0, 0));/* (Gathering Swarm: its bug, eased in from above it to its place, then carrying it; Lamp_Bug_idle from its* start) */float t = g->getter ? g->age - getter_wait(g) : -1;@@ -6772,7 +6772,7 @@ void enemies_draw(void) {int n = clip_frames_count(CLIP_GEOBUG_LAMP_BUG_IDLE);sprite_inst(clip_frame_sprite(CLIP_GEOBUG_LAMP_BUG_IDLE, (int)(t * 12) % n), g->x + bx * GEO_SCALE,g->y + by * GEO_SCALE, 0.0005f, GEO_SCALE * 1.4838f, GEO_SCALE * 1.4838f, 0, &in);- gfx_actor(&in, SORT_KEY(0, 0));+ gfx_actor_minor(&in, SORT_KEY(0, 0));}}diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.cindex 5dbcf939..ddac6f83 100644--- a/games/hollowknight/src/gfx.c+++ b/games/hollowknight/src/gfx.c@@ -383,7 +383,8 @@ static void inst_map(const Inst *in, Map *m) {}}-__attribute__((noinline)) static bool item_box(const Inst *in, Item *it) {+/* an instance's box on screen (pixels, not clipped): false if it is not in front of the camera */+static bool inst_screen_box(const Inst *in, float *x0, float *y0, float *x1, float *y1) {float k = inst_k(in);if (!(k > 0) || k > 400) return false;float bx0, by0, bx1, by1;@@ -412,6 +413,12 @@ __attribute__((noinline)) static bool item_box(const Inst *in, Item *it) {by0 = m.oy < ey ? m.oy : ey, by1 = m.oy < ey ? ey : m.oy;}}+ *x0 = bx0, *y0 = by0, *x1 = bx1, *y1 = by1;+ return true;+}+__attribute__((noinline)) static bool item_box(const Inst *in, Item *it) {+ float bx0, by0, bx1, by1;+ if (!inst_screen_box(in, &bx0, &by0, &bx1, &by1)) return false;if (bx1 <= 0 || by1 <= 0 || bx0 >= VIEW_W || by0 >= VIEW_H) return false;int a = (int)(bx0 + 0.5f), b = (int)(by0 + 0.5f), c = (int)(bx1 + 0.5f), d = (int)(by1 + 0.5f);if (a < 0) a = 0;@@ -1435,6 +1442,7 @@ static bool arena_take(Item *it, bool keep) {/* ---------------------------------------------------------------- the frame */typedef struct {Inst in;+ uint8_t minor; /* (geo, debris, specks: what gives way to the others when there is no room left) */uint32_t group;} Actor;#define MAX_ACTORS 64@@ -1537,17 +1545,40 @@ static void draw_runs(int layer, int sy0, int sy1) {}}-bool gfx_actor(const Inst *in, uint32_t group) {- if (nactors >= MAX_ACTORS) return false;- /* kept in draw order: sorting layer and order, then far first */+#ifdef HOST+uint32_t g_actors_dropped, g_actors_peak, g_items_dropped_total, g_items_peak, g_hero_undrawn;+#endif+/* (kept in draw order: sorting layer and order, then far first; those well off the screen not kept, they take no+ * room; when there is none left, an actor that matters takes a minor one's) */+static bool actor_add(const Inst *in, uint32_t group, bool minor) {+ float x0, y0, x1, y1;+ if (!inst_screen_box(in, &x0, &y0, &x1, &y1) || x1 < -32 || y1 < -32 || x0 > VIEW_W + 32 || y0 > VIEW_H + 32) return true;+#ifdef HOST+ if ((uint32_t)nactors + 1 > g_actors_peak) g_actors_peak = (uint32_t)nactors + 1;+#endif+ if (nactors >= MAX_ACTORS) {+ int m = nactors - 1;+ if (!minor)+ while (m >= 0 && !actors[m].minor) m--;+ if (minor || m < 0) {+#ifdef HOST+ g_actors_dropped++;+#endif+ return false;+ }+ for (nactors--; m < nactors; m++) actors[m] = actors[m + 1];+ }int i = nactors++;while (i > 0 && (actors[i - 1].group > group || (actors[i - 1].group == group && actors[i - 1].in.z < in->z)))actors[i] = actors[i - 1], i--;- actors[i].in = *in, actors[i].group = group;+ actors[i].in = *in, actors[i].group = group, actors[i].minor = minor;return true;}+bool gfx_actor(const Inst *in, uint32_t group) { return actor_add(in, group, false); }+bool gfx_actor_minor(const Inst *in, uint32_t group) { return actor_add(in, group, true); }static bool overlay_on; /* (the overlay's instances: the room kept back to leave them room, g_gfx_reserve) */+static int items_keep; /* (the actors and the HUD still to come: the room's own instances leave them room) */static bool add_item(const Inst *in, float blur_z) {Item cur;cur.in = *in;@@ -1566,8 +1597,11 @@ static bool add_item(const Inst *in, float blur_z) {draw_bg_item(&cur);return false;}- if (nitems >= MAX_ITEMS - (overlay_on ? 0 : g_gfx_reserve)) {+ if (nitems >= MAX_ITEMS - (overlay_on ? 0 : g_gfx_reserve) - items_keep) {g_gfx_dropped++; /* (never in the game's rooms: checked by tests) */+#ifdef HOST+ g_items_dropped_total++;+#endifreturn false;}arena_take(&cur, true);@@ -1618,7 +1652,9 @@ void gfx_frame(void) {while (!roomless && room_next(&cur.in, &group)) {while (na < nactors && (actors[na].group < group || (actors[na].group == group && actors[na].in.z > cur.in.z)))add_item(&actors[na++].in, nitems ? 1e9f : blur_z);+ items_keep = nactors - na + nhud;add_item(&cur.in, blur_z);+ items_keep = 0;}while (na < nactors) add_item(&actors[na++].in, nitems ? 1e9f : blur_z);nactors = 0;@@ -1633,6 +1669,9 @@ void gfx_frame(void) {nhud = 0;if (g_gfx_overlay) overlay_on = true, g_gfx_overlay(), overlay_on = false;g_gfx_items = (uint32_t)nitems;+#ifdef HOST+ if ((uint32_t)nitems > g_items_peak) g_items_peak = (uint32_t)nitems;+#endifif (!strip_ready) {strip_clear();strip_ready = true;diff --git a/games/hollowknight/src/hero.c b/games/hollowknight/src/hero.cindex a039357b..5cba14b0 100644--- a/games/hollowknight/src/hero.c+++ b/games/hollowknight/src/hero.c@@ -830,7 +830,12 @@ void hero_draw(void) {uint8_t tint = 0;if (h->pulsing) tint = gfx_dyn_tint(0, 255, 255, 255, (uint8_t)(255 - 255 * 0.5f * h->pulse_t / 0.1f));sprite_inst(h->anim.sprite, h->body.x, h->body.y, 0.004f, h->cs.facing_right ? -1.0f : 1.0f, 1, tint, &in);- gfx_actor(&in, SORT_KEY(0, 0));+ if (!gfx_actor(&in, SORT_KEY(0, 0))) {+#ifdef HOST+ extern uint32_t g_hero_undrawn; /* (never: checked by tests) */+ g_hero_undrawn++;+#endif+ }slash_draw();}diff --git a/games/hollowknight/src/hk.h b/games/hollowknight/src/hk.hindex 0b2b688b..2a027af4 100644--- a/games/hollowknight/src/hk.h+++ b/games/hollowknight/src/hk.h@@ -210,6 +210,7 @@ void gfx_frame(void); /* draws the room at the camera into the screen/* a sprite of the Knight, an enemy, an effect... for the next frame, among the room's by its sorting layer and order* (SORT_KEY), then depth */bool gfx_actor(const Inst *in, uint32_t group);+bool gfx_actor_minor(const Inst *in, uint32_t group); /* (geo, debris, specks: they give way to the others) *//* the HUD: a sprite in front of all, placed in HUD units from the screen's center (its camera's: 8.7107 units half* height), not graded nor faded with the room (tints from HUD_TINT); clip: 0, or 1 + a circle it is drawn in */bool gfx_hud(const Inst *in, int clip);diff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.cindex 351118c2..de69f89a 100644--- a/games/hollowknight/src/obj.c+++ b/games/hollowknight/src/obj.c@@ -23,7 +23,7 @@ typedef struct {} Obj;static Obj objs[MAX_OBJS];static int nobjs;-static uint32_t swing_hit[MAX_OBJS / 32]; /* (LimitSendEvents: an object is hit once a swing) */+static uint32_t swing_hit[(MAX_OBJS + 31) / 32]; /* (LimitSendEvents: an object is hit once a swing) */enum { BR_WHOLE, BR_BROKEN };@@ -172,7 +172,7 @@ static void pieces_draw(void) {atan2f(q->vy, q->vx) * 57.29578f, 0, &in);} elsesprite_inst_rot(q->sprite, q->x, q->y, q->z, q->mirror, 1, q->ang, 0, &in);- gfx_actor(&in, SORT_KEY(q->layer, (int)q->order - 32768));+ gfx_actor_minor(&in, SORT_KEY(q->layer, (int)q->order - 32768));}}@@ -629,7 +629,7 @@ static void drip_tick(Obj *o, const Ent *e) {static void drip_draw(const Obj *o, const Ent *e) {Inst in;sprite_inst(o->anim.sprite, e->x0, e->y0 + o->jy, e->x1, 1, 1, 0, &in);- gfx_actor(&in, SORT_KEY(e->group, (int)e->a - 32768));+ gfx_actor_minor(&in, SORT_KEY(e->group, (int)e->a - 32768));}/* ---------------------------------------------------------------- lifeblood cocoons (HealthCocoon) and their scuttlersdiff --git a/games/hollowknight/src/phys.c b/games/hollowknight/src/phys.cindex 7b639b86..2c090706 100644--- a/games/hollowknight/src/phys.c+++ b/games/hollowknight/src/phys.c@@ -277,7 +277,8 @@ void body_step(Body *b, float dt) {b->vx -= d * -ny, b->vy -= d * nx;}}- float left = 1;+ float left = 1, pnx = 0, pny = 0;+ int pcol = -1; /* (the last way out, and of what) */for (int it = 0; it < 4 && left > 0; it++) {float dx = b->vx * dt * left, dy = b->vy * dt * left;float cx, cy;@@ -285,6 +286,8 @@ void body_step(Body *b, float dt) {float hx = b->hx + SKIN, hy = b->hy + SKIN;float bx0 = fminf(cx, cx + dx) - hx, bx1 = fmaxf(cx, cx + dx) + hx, by0 = fminf(cy, cy + dy) - hy, by1 = fmaxf(cy, cy + dy) + hy;float best = 2, bnx = 0, bny = 0, deep = 0, dnx = 0, dny = 0;+ int dcol = -1;+ bool caught = false; /* (inside a collider whose sides push opposite ways: out of it whole) */Cand cand[MAX_CAND];int nc = gather(bx0, by0, bx1, by1, b->mask, cand);for (int k = 0; k < nc; k++) {@@ -295,7 +298,7 @@ void body_step(Body *b, float dt) {#ifdef HOSTif (getenv("PHYSDBG")) fprintf(stderr, " deep seg %.3f,%.3f-%.3f,%.3f col %d depth %.3f n %.2f,%.2f box c %.3f,%.3f h %.3f,%.3f\n", s->ax, s->ay, s->bx, s->by, s->col, depth, nx, ny, cx, cy, hx, hy);#endif- if (depth > deep) deep = depth, dnx = nx, dny = ny;+ if (depth > deep) deep = depth, dnx = nx, dny = ny, dcol = s->col;continue;}if (nx * dx + ny * dy >= 0) continue; /* moving away from it */@@ -304,6 +307,29 @@ void body_step(Body *b, float dt) {#ifdef HOSTif (getenv("PHYSDBG")) fprintf(stderr, "it %d d %.4f,%.4f best %.3f n %.2f,%.2f deep %.4f dn %.2f,%.2f nc %d\n", it, dx, dy, best, bnx, bny, deep, dnx, dny, nc);#endif+ /* (pushed back the way it was just pushed out, by the same collider: it is wider than the collider's gap) */+ caught = deep > 0 && dcol > 0 && dcol == pcol && dnx * pnx + dny * pny < -0.5f;+ if (deep > 0) pnx = dnx, pny = dny, pcol = dcol;+ if (caught) {+ /* (a collider closed or moved onto it, narrower than it: its segments' box, and out of that the shortest way,+ * as the physics separates them) */+ float x0 = 1e30f, y0 = 1e30f, x1 = -1e30f, y1 = -1e30f;+ for (int k = 0; k < nc; k++)+ if (cand[k].col == dcol) {+ x0 = fminf(x0, fminf(cand[k].ax, cand[k].bx)), x1 = fmaxf(x1, fmaxf(cand[k].ax, cand[k].bx));+ y0 = fminf(y0, fminf(cand[k].ay, cand[k].by)), y1 = fmaxf(y1, fmaxf(cand[k].ay, cand[k].by));+ }+ float ml = x0 - hx - cx, mr = x1 + hx - cx, md = y0 - hy - cy, mu = y1 + hy - cy;+ float ax = -ml < mr ? ml : mr, ay = -md < mu ? md : mu;+ if (fabsf(ax) <= fabsf(ay)) {+ b->x += ax;+ if (b->vx * ax < 0) b->vx = 0;+ } else {+ b->y += ay;+ if (b->vy * ay < 0) b->vy = 0;+ }+ continue;+ }if (deep > 0) {/* inside the ground (it moved, or the body was put there): out the shortest way */b->x += dnx * deep, b->y += dny * deep;