Skip to content

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.

Hollow Knight: drawn fast when the calculator is slow (a frame's work over 45 ms on average, back under 20): the room at half the height, each row of its pixels sampled between two of the screen's, where no HUD, text or menu is, and its far background so too; about 1.8 times as quick, the same pixels otherwise. The tile decoder's probabilities, the cache's tiles and the background copied and cleared by words (the calculator's C library goes a byte at a time). make test plays and walks drawn fast too

Mason Chenc763b0d25037
diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.c
index e01d28b9..ffbc3fc1 100644
--- a/games/hollowknight/src/gfx.c
+++ b/games/hollowknight/src/gfx.c
@@ -18,6 +18,11 @@
#define NPAL 104
#endif
#define NPX (STRIP_H * VIEW_W)
+bool g_gfx_fast;
+/* the strip's rows: each one of the screen's, or (fast) each two of them, where no HUD, text or menu is: the room's
+ * drawn at half the height, its pixels' rows sampled between the two */
+static int vsf = 1;
+#define SY(y) ((y) * (float)vsf + vsf * 0.5f) /* (a row's middle, in the screen's rows) */
float g_cam_x, g_cam_y;
uint32_t g_gfx_items, g_gfx_pixels, g_gfx_dropped;
@@ -981,7 +986,7 @@ static void run_turned(const Ctx *c, int y, int a, int b, int *last_key, const u
uint16_t *rtp = c->it->ar != 0xFFFF ? arena + c->it->ar : NULL;
int32_t dux = (int32_t)(m->iux * 65536), dvx = (int32_t)(m->ivx * 65536);
int32_t W16 = (int32_t)r->w << 16, H16 = (int32_t)r->h << 16;
- float fx = a + 0.5f - m->ox, fy = y + 0.5f - m->oy;
+ float fx = a + 0.5f - m->ox, fy = SY(y) - m->oy;
int32_t u = (int32_t)((m->iux * fx + m->iuy * fy) * 65536), v = (int32_t)((m->ivx * fx + m->ivy * fy) * 65536);
int i0 = 0, i1 = b - a;
clip_lin(u, dux, W16, b - a, &i0, &i1);
@@ -1046,7 +1051,7 @@ static void run_soft(const Ctx *c, int y, int a, int b, const uint32_t *tx, uint
int mode = c->mode, row = c->row, W = r->w, H = r->h;
bool mono = r->fmt == FMT_SOFTA;
const uint8_t *al = (const uint8_t *)tx;
- float fx = a + 0.5f - m->ox, fy = y + 0.5f - m->oy;
+ float fx = a + 0.5f - m->ox, fy = SY(y) - m->oy;
int32_t u0 = (int32_t)((m->iux * fx + m->iuy * fy - 0.5f) * 65536), v0 = (int32_t)((m->ivx * fx + m->ivy * fy - 0.5f) * 65536);
int32_t dux = (int32_t)(m->iux * 65536), dvx = (int32_t)(m->ivx * 65536);
/* where all four texels are inside (the edges of these textures are clear) */
@@ -1098,7 +1103,7 @@ static void run_soft(const Ctx *c, int y, int a, int b, const uint32_t *tx, uint
static void run_bilinear(const Ctx *c, int y, int a, int b, BiTex *bt) {
const Map *m = c->m;
int mode = c->mode, row = c->row;
- float fx = a + 0.5f - m->ox, fy = y + 0.5f - m->oy;
+ float fx = a + 0.5f - m->ox, fy = SY(y) - m->oy;
int32_t u = (int32_t)((m->iux * fx + m->iuy * fy - 0.5f) * 65536) + 65536, v = (int32_t)((m->ivx * fx + m->ivy * fy - 0.5f) * 65536) + 65536;
int32_t dux = (int32_t)(m->iux * 65536), dvx = (int32_t)(m->ivx * 65536);
int i0 = 0, i1 = b - a;
@@ -1113,7 +1118,8 @@ static void run_bilinear(const Ctx *c, int y, int a, int b, BiTex *bt) {
__attribute__((noinline)) static void draw_item(int idx, Item *it, int sy0, int sy1) {
const Inst *in = &it->in;
- int ya = it->y0 > sy0 ? it->y0 : sy0, yb = it->y1 < sy1 ? it->y1 : sy1;
+ int iy0 = it->y0 / vsf, iy1 = (it->y1 + vsf - 1) / vsf; /* (its rows, in the strip's) */
+ int ya = iy0 > sy0 ? iy0 : sy0, yb = iy1 < sy1 ? iy1 : sy1;
/* (its rows from the first with light left in its box: none, nothing to make ready) */
while (ya < yb && open_from(cov[ya - sy0], it->x0, it->x1) >= it->x1) ya++;
if (ya >= yb) return;
@@ -1179,7 +1185,7 @@ __attribute__((noinline)) static void draw_item(int idx, Item *it, int sy0, int
if (x >= it->x1) continue;
int ty = 0, vr = 0;
if (kind == 1) {
- int v = (int)((y + 0.5f - m.oy) * m.ivy);
+ int v = (int)((SY(y) - m.oy) * m.ivy);
if (v < 0 || v >= c.r->h) continue;
ty = v / TILE, vr = v & (TILE - 1);
if (ty != it->cty || g_tex_overload) {
@@ -1193,10 +1199,10 @@ __attribute__((noinline)) static void draw_item(int idx, Item *it, int sy0, int
const HudClip *k = &hud_clips[it->clip - 1];
int ca, cb;
if (k->box) {
- if (y + 0.5f < k->y0 || y + 0.5f >= k->y1) continue;
+ if (SY(y) < k->y0 || SY(y) >= k->y1) continue;
ca = (int)(k->x0 + 0.5f), cb = (int)(k->x1 + 0.5f);
} else {
- float dy = y + 0.5f - k->cy, w2 = k->r * k->r - dy * dy;
+ float dy = SY(y) - k->cy, w2 = k->r * k->r - dy * dy;
if (w2 <= 0) continue;
float w = sqrtf(w2);
ca = (int)(k->cx - w + 0.5f), cb = (int)(k->cx + w + 0.5f);
@@ -1227,7 +1233,8 @@ __attribute__((noinline)) static void draw_item(int idx, Item *it, int sy0, int
#define BG_S 4
#define BG_W (VIEW_W / BG_S)
#define BG_H (VIEW_H / BG_S)
-static uint16_t bgbuf[BG_W * BG_H]; /* RGB565 */
+static uint16_t bgbuf[BG_W * BG_H] __attribute__((aligned(4))); /* RGB565 */
+static int bg_step = 1; /* (its rows drawn: all, or every other one when the room is drawn fast) */
static bool bg_on;
static inline void bg_put(uint16_t *d, uint32_t s, int mode) {
@@ -1245,7 +1252,7 @@ static void draw_bg_item(Item *it) {
if (in->flags & F_SOLID) {
/* the pixels whose centers are in the box */
int a = (it->x0 + BG_S / 2) / BG_S, b = (it->x1 + BG_S / 2) / BG_S, c = (it->y0 + BG_S / 2) / BG_S, d = (it->y1 + BG_S / 2) / BG_S;
- for (int by = c; by < d; by++)
+ for (int by = (c + bg_step - 1) / bg_step * bg_step; by < d; by += bg_step)
for (int bx = a; bx < b; bx++) bg_put(bgbuf + by * BG_W + bx, pal[1], mode);
return;
}
@@ -1272,7 +1279,7 @@ static void draw_bg_item(Item *it) {
int W = r->w, H = r->h;
/* texel coordinates (16.16) less half a texel: where bilinear samples are centered */
int32_t du = (int32_t)(m.iux * BG_S * 65536), dv = (int32_t)(m.ivx * BG_S * 65536);
- for (int by = by0; by < by1; by++) {
+ for (int by = (by0 + bg_step - 1) / bg_step * bg_step; by < by1; by += bg_step) {
uint16_t *d16 = bgbuf + by * BG_W;
float fx = bx0 * BG_S + BG_S * 0.5f - m.ox, fy = by * BG_S + BG_S * 0.5f - m.oy;
int32_t u = (int32_t)((m.iux * fx + m.iuy * fy - 0.5f) * 65536), v = (int32_t)((m.ivx * fx + m.ivy * fy - 0.5f) * 65536);
@@ -1431,7 +1438,7 @@ __attribute__((noinline)) static void finish_strip(int sy0, int rows) {
#endif
uint16_t *out = (uint16_t *)(void *)acc; /* in place: each 16-bit pixel goes where its 8 bytes were read */
for (int y = 0; y < rows; y++) {
- int sy = sy0 + y;
+ float sy = sy0 + y * vsf + (vsf - 1) * 0.5f; /* (the screen's row, or between two) */
bool bg = bg_on;
if (bg) { /* (not if no light is left anywhere on the row) */
uint32_t all = ~0u;
@@ -1440,17 +1447,21 @@ __attribute__((noinline)) static void finish_strip(int sy0, int rows) {
}
if (bg) {
/* the background's row, between two of its own rows */
- float fy = (sy + 0.5f) / BG_S - 0.5f;
- int r0 = (int)(fy + 4096.0f) - 4096;
+ float fy = ((sy + 0.5f) / BG_S - 0.5f) / bg_step;
+ int r0 = (int)(fy + 4096.0f) - 4096, last = BG_H - bg_step;
uint32_t wv = (uint32_t)((fy - r0) * 256);
- const uint16_t *a16 = bgbuf + (r0 < 0 ? 0 : r0 >= BG_H ? BG_H - 1 : r0) * BG_W;
- const uint16_t *b16 = bgbuf + (r0 + 1 < 0 ? 0 : r0 + 1 >= BG_H ? BG_H - 1 : r0 + 1) * BG_W;
+ r0 *= bg_step;
+ int r1 = r0 + bg_step;
+ const uint16_t *a16 = bgbuf + (r0 < 0 ? 0 : r0 > last ? last : r0) * BG_W;
+ const uint16_t *b16 = bgbuf + (r1 < 0 ? 0 : r1 > last ? last : r1) * BG_W;
for (int i = 0; i < BG_W; i++) bgline[i + 1] = lerp4(rgb_of565(a16[i]), rgb_of565(b16[i]), wv);
bgline[0] = bgline[1], bgline[BG_W + 1] = bgline[BG_W];
}
- row_out(acc + y * VIEW_W, out + y * VIEW_W, bg ? bgline : NULL);
+ /* (two rows each: the second where the first's 8 bytes were read) */
+ row_out(acc + y * VIEW_W, out + y * vsf * VIEW_W, bg ? bgline : NULL);
+ if (vsf == 2) copy_words(out + (2 * y + 1) * VIEW_W, out + 2 * y * VIEW_W, VIEW_W * 2);
}
- plat_push(0, VIEW_Y + sy0, VIEW_W, rows, out);
+ plat_push(0, VIEW_Y + sy0, VIEW_W, rows * vsf, out);
strip_clear();
}
@@ -1629,7 +1640,7 @@ static bool add_item(const Inst *in, float blur_z) {
cur.pal = (uint8_t)pal_get(cur.in.flags & F_SOLID ? TEX_NONE : cur.in.tex, cur.in.tint, cur.in.flags, alpha, cur.screen);
if (!front) {
arena_take(&cur, false);
- if (!bg_on) memset(bgbuf, 0, sizeof bgbuf), bg_on = true;
+ if (!bg_on) zero_words(bgbuf, sizeof bgbuf), bg_on = true;
draw_bg_item(&cur);
return false;
}
@@ -1678,6 +1689,7 @@ void gfx_frame(void) {
bg_on = false;
g_gfx_dropped = 0;
float blur_z = roomless ? 1e9f : g_room.h->blur_z;
+ bg_step = g_gfx_fast && !roomless ? 2 : 1;
/* the instances near the camera, back to front, and the actors among them: what is behind the blur plane is drawn
* now (small), the rest kept */
Item cur;
@@ -1725,13 +1737,27 @@ void gfx_frame(void) {
if ((uint32_t)arena_top > g_peak_arena) g_peak_arena = (uint32_t)arena_top;
}
#endif
- for (int sy0 = 0; sy0 < VIEW_H; sy0 += STRIP_H) {
- int sy1 = sy0 + STRIP_H;
- tex_strip(sy0 / STRIP_H + 1);
- memset(cov, 0, sizeof cov);
+ /* (the rows where the HUD, text or a menu are: drawn whole) */
+ uint8_t busy[VIEW_H / STRIP_H];
+ memset(busy, 0, sizeof busy);
+ if (g_gfx_fast && !roomless) {
+ for (int i = nscene; i < nitems; i++)
+ for (int b = items[i].y0 / STRIP_H; b < (items[i].y1 + STRIP_H - 1) / STRIP_H; b++) busy[b] = 1;
+ for (int k = 0; k < nruns; k++)
+ for (int b = runs[k].y0 / STRIP_H; b < (runs[k].y1 + STRIP_H - 1) / STRIP_H; b++)
+ if (b >= 0 && b < VIEW_H / STRIP_H) busy[b] = 1;
+ }
+ int nstrip = 0;
+ for (int sy0 = 0, sy1; sy0 < VIEW_H; sy0 = sy1) {
+ int b = sy0 / STRIP_H;
+ vsf = g_gfx_fast && !roomless && sy0 + 2 * STRIP_H <= VIEW_H && !busy[b] && !busy[b + 1] ? 2 : 1;
+ sy1 = sy0 + STRIP_H * vsf;
+ int r0 = sy0 / vsf, r1 = r0 + STRIP_H; /* (the strip's rows) */
+ tex_strip(++nstrip);
+ zero_words(cov, sizeof cov);
if (nruns) draw_runs(0, sy0, sy1);
for (int i = nitems - 1; i >= nscene; i--)
- if (items[i].y0 < sy1 && items[i].y1 > sy0) draw_item(i, &items[i], sy0, sy1);
+ if (items[i].y0 < sy1 && items[i].y1 > sy0) draw_item(i, &items[i], r0, r1);
if (g_screen_fade) {
/* (the camera fading to black: a black layer between the HUD and the room) */
uint32_t k = 255u - g_screen_fade;
@@ -1744,9 +1770,10 @@ void gfx_frame(void) {
if (g_screen_fade < 255 && nruns) draw_runs(1, sy0, sy1);
if (g_screen_fade < 255)
for (int i = nscene - 1; i >= 0; i--)
- if (items[i].y0 < sy1 && items[i].y1 > sy0) draw_item(i, &items[i], sy0, sy1);
+ if (items[i].y0 < sy1 && items[i].y1 > sy0) draw_item(i, &items[i], r0, r1);
finish_strip(sy0, STRIP_H);
}
+ vsf = 1;
nruns = 0;
#ifdef HOST
{
diff --git a/games/hollowknight/src/hk.h b/games/hollowknight/src/hk.h
index dde772ef..6b77d2be 100644
--- a/games/hollowknight/src/hk.h
+++ b/games/hollowknight/src/hk.h
@@ -43,9 +43,22 @@ const uint8_t *section(int id);
uint32_t section_size(int id);
static inline uint16_t rd16(const uint8_t *p) { return (uint16_t)(p[0] | p[1] << 8); }
static inline uint32_t rd32(const uint8_t *p) { return (uint32_t)(p[0] | p[1] << 8 | p[2] << 16 | (uint32_t)p[3] << 24); }
+/* (the calculator's C library copies and clears a byte at a time: these go by words, for n a multiple of 4, d aligned) */
+typedef uint32_t __attribute__((may_alias, aligned(1))) u32_any;
+static inline void copy_words(void *d, const void *s, size_t n) {
+ uint32_t *dw = (uint32_t *)d;
+ const u32_any *sw = (const u32_any *)s;
+ for (; n >= 16; n -= 16, dw += 4, sw += 4) dw[0] = sw[0], dw[1] = sw[1], dw[2] = sw[2], dw[3] = sw[3];
+ for (; n; n -= 4) *dw++ = *sw++;
+}
+static inline void zero_words(void *d, size_t n) {
+ uint32_t *dw = (uint32_t *)d;
+ for (; n >= 16; n -= 16, dw += 4) dw[0] = dw[1] = dw[2] = dw[3] = 0;
+ for (; n; n -= 4) *dw++ = 0;
+}
void lz_decode(const uint8_t *src, uint32_t comp, uint8_t *dst, uint32_t raw);
/* decoders' working memory (LZMA probabilities or the tile coder's), one at a time */
-extern uint16_t g_scratch[4096];
+extern uint16_t g_scratch[4096] __attribute__((aligned(4)));
float f16(uint16_t h);
const char *str_at(int id); /* the shared string table (SEC_STR) */
@@ -224,6 +237,7 @@ uint8_t gfx_dyn_tint(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*
uint8_t gfx_dyn_flash(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t fr, uint8_t fg, uint8_t fb, uint8_t amount);
extern uint8_t g_screen_fade; /* 0 .. 255: the screen faded to black */
extern bool g_gfx_no_room; /* (the room not drawn: the menus') */
+extern bool g_gfx_fast; /* the room drawn at half the height where no HUD, text or menu is (main.c: when slow) */
/* an overlay over the HUD (the inventory): drawn by g_gfx_overlay as the frame is made, its instances (HUD units)
* straight into the frame's; g_gfx_reserve of them kept from the room's */
extern void (*g_gfx_overlay)(void);
diff --git a/games/hollowknight/src/main.c b/games/hollowknight/src/main.c
index a19f1400..7c84de21 100644
--- a/games/hollowknight/src/main.c
+++ b/games/hollowknight/src/main.c
@@ -17,6 +17,8 @@ uint32_t perf_updates __attribute__((used));
#define TICK_MS 20 /* the game's step (Unity's fixed step) */
#define MAX_TICKS 4 /* steps caught up before a frame is drawn */
+#define SLOW_MS 45 /* a frame's work (on average) over which the room is drawn fast (g_gfx_fast)... */
+#define QUICK_MS 20 /* ...and under which, fast, it is drawn whole again (whole, about 36) */
#ifdef PERF_BENCH
/* timing: a few views (rooms by number), panning a little: each one's ms per frame x 100 (read by the emulator; the
@@ -27,6 +29,9 @@ uint32_t perf_bench[sizeof bench / sizeof bench[0]] __attribute__((used));
int main(void) {
plat_begin();
hk_bin = hk_data;
+#ifdef PERF_FAST
+ g_gfx_fast = true;
+#endif
for (unsigned i = 0; i < sizeof bench / sizeof bench[0]; i++) {
room_load(bench[i].room);
g_cam_x = bench[i].x, g_cam_y = bench[i].y;
@@ -108,7 +113,7 @@ int main(void) {
hk_bin = hk_data;
plat_fill(0, 0, SCREEN_W, SCREEN_H, 0);
menu_start();
- uint32_t last = plat_millis(), acc = 0;
+ uint32_t last = plat_millis(), acc = 0, avg8 = 0; /* (the frames' work: ms x 8, an average of the last few) */
for (;;) {
uint32_t keys = plat_keys();
if (keys & K_HOME) {
@@ -135,6 +140,11 @@ int main(void) {
menu_draw();
gfx_frame();
perf_frames++;
+ if (menu_in_game()) {
+ avg8 = avg8 - avg8 / 8 + (plat_millis() - now);
+ if (!g_gfx_fast && avg8 > SLOW_MS * 8) g_gfx_fast = true;
+ else if (g_gfx_fast && avg8 < QUICK_MS * 8) g_gfx_fast = false;
+ }
}
return plat_end();
}
diff --git a/games/hollowknight/src/res.c b/games/hollowknight/src/res.c
index 089fbca7..cc11e372 100644
--- a/games/hollowknight/src/res.c
+++ b/games/hollowknight/src/res.c
@@ -7,7 +7,7 @@ const uint8_t *hk_bin;
const uint8_t *section(int id) { return hk_bin + rd32(hk_bin + 8 + 8 * id); }
uint32_t section_size(int id) { return rd32(hk_bin + 12 + 8 * id); }
-uint16_t g_scratch[4096];
+uint16_t g_scratch[4096] __attribute__((aligned(4)));
#define LZ_PROBS ((CLzmaProb *)g_scratch) /* NUM_BASE_PROBS + LZMA_LIT_SIZE << (lc + lp) = 2752, lc = lp = 0 */
/* a raw LZMA stream (lc = lp = pb = 0) decoded whole: the output is its own dictionary */
diff --git a/games/hollowknight/src/tex.c b/games/hollowknight/src/tex.c
index e53cb706..84edef49 100644
--- a/games/hollowknight/src/tex.c
+++ b/games/hollowknight/src/tex.c
@@ -9,7 +9,7 @@
#define NO 0xFFFF
#define BLOCK_TILES 16
-static uint8_t slot_px[NSLOTS][128];
+static uint8_t slot_px[NSLOTS][128] __attribute__((aligned(4)));
static uint16_t slot_box[NSLOTS]; /* where each tile's texels that are not clear are (tile_box) */
static uint32_t slot_key[NSLOTS];
static uint16_t slot_next[NSLOTS], slot_frame[NSLOTS];
@@ -18,7 +18,7 @@ static uint8_t cur_strip;
static bool full; /* the last frame needed all the slots */
static uint16_t head[NHASH];
static uint16_t frame = 1, hand;
-static uint8_t block_buf[BLOCK_TILES * 128];
+static uint8_t block_buf[BLOCK_TILES * 128] __attribute__((aligned(4)));
static int block_tex = -1, block_first; /* (whose tiles block_buf holds) */
#define tcp g_scratch /* TC_N4 */
_Static_assert(TC_N4 <= sizeof g_scratch / 2, "the tile decoder's probabilities: in g_scratch");
@@ -63,8 +63,8 @@ static int texel_at(const uint8_t *t, int x, int y, bool two) {
static void decode_block(const uint8_t *src, int n, bool two, const uint8_t *left, const uint8_t *up, uint8_t *out) {
/* the trained probabilities, ready to use (pack.py) */
const uint8_t *prior = section(SEC_PRIOR);
- if (two) memcpy(tcp, prior + TC_N4 * 2, TC_N2 * 2);
- else memcpy(tcp, prior, TC_N4 * 2);
+ if (two) copy_words(tcp, prior + TC_N4 * 2, TC_N2 * 2);
+ else copy_words(tcp, prior, TC_N4 * 2);
uint32_t rng = 0xFFFFFFFFu, code = 0;
for (int i = 0; i < 4; i++) code = code << 8 | *src++;
int w = two ? 32 : 16, s = TC_STRIDE(w);
@@ -271,7 +271,7 @@ static int insert(uint32_t key, const uint8_t *px, int bytes) {
unsigned h = hash(key);
slot_next[s] = head[h];
head[h] = (uint16_t)s;
- memcpy(slot_px[s], px, (size_t)bytes);
+ copy_words(slot_px[s], px, (size_t)bytes);
slot_box[s] = tile_box(px);
return s;
}
@@ -356,7 +356,7 @@ int tex_slot(uint16_t t, int tx, int ty) {
unsigned hh = hash(k);
slot_next[ns] = head[hh];
head[hh] = (uint16_t)ns;
- memcpy(slot_px[ns], block_buf + i * bytes, (size_t)bytes);
+ copy_words(slot_px[ns], block_buf + i * bytes, (size_t)bytes);
slot_box[ns] = tile_box(block_buf + i * bytes);
slot_frame[ns] = (uint16_t)(frame - 2); /* not drawn yet: the first to go */
}
diff --git a/games/hollowknight/tests/check.py b/games/hollowknight/tests/check.py
index 03578784..12eb2632 100644
--- a/games/hollowknight/tests/check.py
+++ b/games/hollowknight/tests/check.py
@@ -5,7 +5,8 @@
back to a good place
- a long walk of made up keys from every room: the Knight never out of the room, without control, wedged, undrawn or
out of the view
-- every room played with its enemies hit, in a new game and after the bosses: the sanitizers stop on any fault
+- every room played with its enemies hit, in a new game and after the bosses, drawn whole and fast (as a slow
+ calculator draws it): the sanitizers stop on any fault
"""
import os
import subprocess
@@ -44,19 +45,20 @@ def main():
rc, out = play("--gates", "all")
results.append(report("gates", rc, out, ("FAIL",)))
with ThreadPoolExecutor(JOBS) as pool:
- walks = list(pool.map(lambda w: play("--gates", "wander:all:%d:%d" % w), WALKS))
+ walks = list(pool.map(lambda w: play("--gates", "wander:all:%d:%d" % w, env={"HKFAST": "1"} if w[0] % 2 else None), WALKS))
for (seed, ticks), (rc, out) in zip(WALKS, walks):
- results.append(report("walk %d (%d s from every room)" % (seed, ticks // 50), rc, out, ("FAIL",)))
+ results.append(report("walk %d (%d s from every room%s)" % (seed, ticks // 50, ", drawn fast" if seed % 2 else ""), rc, out, ("FAIL",)))
rc, out = play("--list")
rooms = out.split()
- runs = [(r, w) for r in rooms for w in WORLDS]
+ runs = [(r, w, f) for r in rooms for w in WORLDS for f in ("", "1")]
env = {"HKGOD": "1", "HKHIT": "50", "HKHITN": "20", "HKHITD": "10"}
with ThreadPoolExecutor(JOBS) as pool:
- played = list(pool.map(lambda rw: play("--room", rw[0], "--play", SWEEP_KEYS, env=dict(env, HKFLAGS=rw[1])), runs))
- bad = [(r, w, rc, out) for (r, w), (rc, out) in zip(runs, played) if rc != 0 or faults(out)]
+ played = list(pool.map(lambda rwf: play("--room", rwf[0], "--play", SWEEP_KEYS, "--shot", os.devnull,
+ env=dict(env, HKFLAGS=rwf[1], **({"HKFAST": "1"} if rwf[2] else {}))), runs))
+ bad = [(r, w, f, rc, out) for (r, w, f), (rc, out) in zip(runs, played) if rc != 0 or faults(out)]
print("%s every room played (%d runs)" % ("FAIL" if bad else "ok ", len(runs)))
- for r, w, rc, out in bad:
- print(" %s [%s] exit %d" % (r, w, rc))
+ for r, w, f, rc, out in bad:
+ print(" %s [%s]%s exit %d" % (r, w, " fast" if f else "", rc))
for l in faults(out)[:3]:
print(" " + l)
results.append(not bad)
diff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.c
index 0e498a40..c36e14b2 100644
--- a/games/hollowknight/tests/play.c
+++ b/games/hollowknight/tests/play.c
@@ -291,6 +291,7 @@ int main(int argc, char **argv) {
if (fread(data, 1, (size_t)n, f) != (size_t)n) return 1;
fclose(f);
hk_bin = data;
+ g_gfx_fast = getenv("HKFAST") != NULL; /* (as the calculator draws when it is slow) */
const char *room = "Tutorial_01", *shot = NULL;
float cx = 40, cy = 14;
int repeat = 1, pan = 0, sweep = 0;