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
PolyTrack: all 17 official tracks driven to the finish, a quarter-resolution lowest quality
Mason363124a1ad0f694
diff --git a/games/polytrack/src/render.c b/games/polytrack/src/render.cindex 28512fbf..aa0ceaca 100644--- a/games/polytrack/src/render.c+++ b/games/polytrack/src/render.c@@ -29,13 +29,13 @@ static tri tris[MAX_TRIS];static int ntris;int rd_tris, rd_dropped, rd_mtris, rd_chunks;int rd_detail = RD_LEVELS - 1;-bool rd_half;+bool rd_half, rd_halfx;/* the picture's quality, lowest first: how far it draws, how near the parts keep their whole shape, half the rows,triangles at most */-static const float DRAW[RD_LEVELS] = {70.0f, 100.0f, 100.0f, 140.0f, 180.0f, 230.0f};-static const float NEAR_DETAIL[RD_LEVELS] = {12.0f, 22.0f, 22.0f, 30.0f, 40.0f, 52.0f};-static const uint8_t HALF[RD_LEVELS] = {1, 1, 0, 0, 0, 0};-static const uint16_t CAP[RD_LEVELS] = {1100, MAX_TRIS, MAX_TRIS, MAX_TRIS, MAX_TRIS, MAX_TRIS};+static const float DRAW[RD_LEVELS] = {60.0f, 70.0f, 100.0f, 100.0f, 140.0f, 180.0f, 230.0f};+static const float NEAR_DETAIL[RD_LEVELS] = {10.0f, 12.0f, 22.0f, 22.0f, 30.0f, 40.0f, 52.0f};+static const uint8_t HALF[RD_LEVELS] = {3, 1, 1, 0, 0, 0, 0}; /* 1: half the rows, 2: and of the columns */+static const uint16_t CAP[RD_LEVELS] = {900, 1100, MAX_TRIS, MAX_TRIS, MAX_TRIS, MAX_TRIS, MAX_TRIS};static int cap = MAX_TRIS;/* the camera */@@ -264,7 +264,7 @@ void rd_begin(const camera_t *cam, int env, int sun_byte, bool sky_only) {focal = CY * pt_cosf(half) / pt_sinf(half);int q = rd_detail < 0 ? 0 : rd_detail >= RD_LEVELS ? RD_LEVELS - 1 : rd_detail;far_d = DRAW[q];- rd_half = HALF[q];+ rd_half = HALF[q] & 1, rd_halfx = HALF[q] >> 1;cap = CAP[q];fog0 = far_d * 0.55f;float l = pt_sqrtf(focal * focal + CX * CX);@@ -424,7 +424,7 @@ static void mountains(void) {float rad[8];for (int k = 0; k < 8; k++) rad[k] = W.mr + 100.0f * (float)k;/* (at the lowest qualities: every other segment, the nearer rings) */- int de = rd_detail <= 1 ? 2 : 1, k0 = rd_detail <= 1 ? 3 : 6;+ int de = rd_detail <= 2 ? 2 : 1, k0 = rd_detail <= 2 ? 3 : 6;for (int k = k0; k >= 0; k--)for (int e = 0; e < s; e += de) {int e1 = (e + de) % s;@@ -549,7 +549,7 @@ void rd_car(const car_look *c) {v3 t = to_cam(vadd(c->pos, mrow(&R, V3(0.0f, CAR_MASS_OFFSET, 0.0f))));if (t.z < -6.0f || t.z > far_d) return;car_mesh(pt_body_v, PT_BODY_NV, pt_body_t, PT_BODY_NT, M, t, &R, mat, c);- if (!c->ghost && rd_detail > 1) car_mesh(pt_extra_v, PT_EXTRA_NV, pt_extra_t, PT_EXTRA_NT, M, t, &R, mat, c);+ if (!c->ghost && rd_detail > 2) car_mesh(pt_extra_v, PT_EXTRA_NV, pt_extra_t, PT_EXTRA_NT, M, t, &R, mat, c);/* the wheels: at their suspension's end, turned by the steering (front) and rolling */for (int i = 0; i < 4; i++) {v3 wp = vadd(c->pos, mrow(&R, vadd(car_wheel_pos[i], V3(0.0f, -c->susp[i], 0.0f))));@@ -598,12 +598,15 @@ void rd_shadow(const car_look *c, const car_t *phys) {triangles), up slowly */void rd_adapt(uint32_t spent_ms) {static uint32_t slow, quick;- if (spent_ms > 30 || rd_dropped) slow++, quick = 0;- else if (spent_ms < 18 && rd_tris < cap * 3 / 4) quick++, slow = 0;+ if (spent_ms > 26 || rd_dropped) slow++, quick = 0;+ else if (spent_ms < 16 && rd_tris < cap * 3 / 4) quick++, slow = 0;else slow = quick = 0;int q = rd_detail;+ /* (a frame near 33 ms: down at once, two steps when past it) */+ if (spent_ms > 30) q -= spent_ms > 36 ? 2 : 1, slow = 0;/* (out of triangles but in time, at the nearest distance: not a reason for half the rows) */- if (slow >= 2 && q > 0 && (spent_ms > 30 || q > 2)) q--, slow = 0;+ if (slow >= 2 && q > 0 && (spent_ms > 26 || q > 3)) q--, slow = 0;+ if (q < 0) q = 0;if (quick >= 30 && q < RD_LEVELS - 1) q++, quick = 0;rd_detail = q;}@@ -677,12 +680,32 @@ __attribute__((noinline)) static void raster(const tri *t, int ys, int ye) {float xa = xl < xs ? xl : xs, xb = xl < xs ? xs : xl;if (xa < -1.0f) xa = -1.0f;if (xb > 321.0f) xb = 321.0f;+ uint16_t *p = gfx_buf + (r - ys) * SCREEN_W;+ bool two = step == 2 && r + 1 < ye;+ if (rd_halfx && kind == RK_SOLID) {+ /* half the columns too: blocks of two pixels, each covered when its middle is, depth at its middle */+ int ba = iceil((xa - 1.0f) * 0.5f), bb = iceil((xb - 1.0f) * 0.5f);+ if (ba < 0) ba = 0;+ if (bb > SCREEN_W / 2) bb = SCREEN_W / 2;+ if (bb <= ba) continue;+ float wb = w0 + B * ((float)(2 * ba + 1) - x0) + Cc * (yc - y0);+ wb = pt_clampf(wb, 0.0f, 0.99998f);+ int32_t qb = (int32_t)(wb * 1073741824.0f), d2 = (int32_t)(pt_clampf(2.0f * B, -1.9f, 1.9f) * 1073741824.0f);+ int nb = bb - ba;+ int32_t qe = qb + d2 * (nb - 1);+ if (nb > 1 && (qe < 0 || qe > 1073725440)) d2 = ((qe < 0 ? 0 : 1073725440) - qb) / (nb - 1);+ uint16_t *z = zbuf + (r - ys) * SCREEN_W + 2 * ba, *pp = p + 2 * ba;+ int dn = two ? SCREEN_W : 0;+ for (int k = 0; k < nb; k++, qb += d2, z += 2, pp += 2) {+ uint16_t q = (uint16_t)((uint32_t)qb >> 14);+ if (q > z[0]) z[0] = z[1] = z[dn] = z[dn + 1] = q, pp[0] = pp[1] = pp[dn] = pp[dn + 1] = col;+ }+ continue;+ }int pa = iceil(xa - 0.5f), pb = iceil(xb - 0.5f);if (pa < 0) pa = 0;if (pb > SCREEN_W) pb = SCREEN_W;if (pb <= pa) continue;- uint16_t *p = gfx_buf + (r - ys) * SCREEN_W;- bool two = step == 2 && r + 1 < ye;if (kind == RK_BACK) {for (int x = pa; x < pb; x++) p[x] = col;if (two)diff --git a/games/polytrack/src/render.h b/games/polytrack/src/render.hindex 4c8eabc5..89b40433 100644--- a/games/polytrack/src/render.h+++ b/games/polytrack/src/render.h@@ -30,9 +30,9 @@ car_look car_look_of(const car_t *c);car_look car_look_mix(const car_look *a, const car_look *b, float t);extern const uint32_t rd_paints[8]; /* the car colours */-#define RD_LEVELS 6+#define RD_LEVELS 7extern int rd_detail; /* 0..RD_LEVELS-1: the picture's quality; lowered when a frame is slow */-extern bool rd_half; /* half the rows, each drawn twice (the lowest qualities) */+extern bool rd_half, rd_halfx; /* half the rows, each drawn twice (the lowest qualities); and of the columns */void rd_adapt(uint32_t spent_ms); /* after each race frame: the quality for the next */#define RD_MAX_TRIS 1700 /* triangles in a frame, at most */extern int rd_tris, rd_dropped, rd_mtris, rd_chunks; /* the last frame: triangles kept, some left out, of the mountains; chunks */diff --git a/games/polytrack/tests/armperf.c b/games/polytrack/tests/armperf.cindex fd7e5537..ee3de65f 100644--- a/games/polytrack/tests/armperf.c+++ b/games/polytrack/tests/armperf.c@@ -68,8 +68,8 @@ int main(void) {perf_out[0]++, perf_out[1] += spent;if (spent > perf_out[2]) perf_out[2] = spent;if (spent > 33) perf_out[3]++, perf_out[10] += (uint32_t)rd_tris, perf_out[11] += (uint32_t)rd_chunks;- if (rd_detail < 2) perf_out[rd_detail ? 9 : 12]++;- else perf_out[4 + rd_detail - 2]++;+ if (rd_detail < 3) perf_out[rd_detail == 2 ? 9 : rd_detail == 1 ? 12 : 13]++;+ else perf_out[4 + rd_detail - 3]++;rd_adapt(spent);dt = spent > 33 ? spent : 33; /* (the game's frames: 33 ms at least on these calculators) */}diff --git a/games/polytrack/tests/routes.h b/games/polytrack/tests/routes.hindex 1b232434..d5bdee12 100644--- a/games/polytrack/tests/routes.h+++ b/games/polytrack/tests/routes.h@@ -330,8 +330,21 @@ static const char *const pt_routes[17] = {"b2jbjbjbjbjbjdb10d2bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd2jdb2d2bdbdbdbd3jd2j2djd2j2djdj2dj2bdbdb2d2jbdbdbd""bdbdbdbdbdbdb3djb16d40j14dj2djdjdjdjdjdjd2jdjdbj2dbjdbjbjbjbjg10j9bj2b2j2b2j2dbjbjbjbjbjbjbjbjbjbjbjbjbjbjbjbjbjb""jbjbjbjbjbjbjbjbjdb36e20jbjbjbjbjbjbjbjbjbj2bjbjbjbjbja19",- /* Desert 3: 0 ms */- "b",+ /* Desert 3: 34636 ms */+ "j56djd2jd2jd2jdjd2jd2jdjd2jd2bjbjbjbjbjbjbjbjbjbjbjbjbjbjbjdbjbjbjbiaiaiaiaiadbdbd2bdbdbdjbd2bdbdbdbdbdbdbdj4b2jb"+ "jbjbjbjdb16dbdbdbdbd2bdbdbdbdbdbd3jbdbd2jdjdjd2j2djd2jdjdjd40e10b10j8d2jdjd2jdjd2g10j6b2j2bjbj4dj5djdjdjd2jdjd3jd"+ "jd2jdjd2b2j2d2bjbjbjbjb6dbdbd2bdbdbdbd2bdbd3j2d2jdjdjdjda10m10d19jb20d9ja10e10g10d10j2djdj2djdb30j50d10jd9e10j40"+ "g10d10ci2c7m10d66j3dj2dj3d2jd3jdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd11j5d2jd2jd2jdjdj2djdjdj2djdjdjdj2d"+ "jdjdj2djdjdjdj2djdjbdbdbdjbdbdbdbdbdbdbdbdb2dbdbdbdbdbdbdbdbdbdbdbdb27d30j56dj2d2j2d2jd2jdj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jdjdjdjd2jdjdjdjdjd2j""djdbjbjbjbjbjb2jbjbjbj4djd2jdja10j2bjbjb2jbjbjbjbjbjbjbjbjbjbjbj2bjbjdbjbjbjbjbjbjbjbjbjbjdb25dbdbdbdbdbdbdbdbdbd"@@ -380,8 +393,8 @@ static const char *const pt_routes[17] = {"d2jd2jd4bjbjbjbjbjbjbjbj2bjbjbjb2jbjbjbjbjbjb60j3bjbjbjbj4djdjdjd4bjbjbjbjbjdbjbjb83dbdbdbdbdbdbdbdbdbdbdbdbdbdbd""bdbdbdbdbdbdbdbdbdb31dbdbdbdbdbdbdbdbdbdb61gegegegegegegegegegeb20e10b160d10a60b45jbjbjemg4",};-static const uint32_t pt_route_ms[17] = {32293, 27987, 39521, 66019, 106224, 87739, 59000, 28763, 67052, 72137, 36518, 44386, 50234, 51686, 0, 37852, 76658};+static const uint32_t pt_route_ms[17] = {32293, 27987, 39521, 66019, 106224, 87739, 59000, 28763, 67052, 72137, 36518, 44386, 50234, 51686, 34636, 37852, 76658};static const uint32_t pt_route_hash[17] = {0x46b14d50, 0x41d4075b, 0x97b7dc15, 0x3be09d36, 0x36f6af61, 0x86e1e537, 0xf85a38d1, 0xc7882ade, 0x798ce928,- 0xcf725a2a, 0x5bdaaa3a, 0x2bf4cac6, 0x5855d5a5, 0x5957f905, 0x00000000, 0x919a971f, 0xc8835445};+ 0xcf725a2a, 0x5bdaaa3a, 0x2bf4cac6, 0x5855d5a5, 0x5957f905, 0xe4db5b83, 0x919a971f, 0xc8835445};#endifdiff --git a/games/polytrack/tools/armperf.py b/games/polytrack/tools/armperf.pyindex 1367d415..809cac2e 100644--- a/games/polytrack/tools/armperf.py+++ b/games/polytrack/tools/armperf.py@@ -35,9 +35,9 @@ def main():with ProcessPoolExecutor(max_workers=min(8, len(tracks))) as ex:for t, o, done in ex.map(one, [(nwa, t) for t in tracks]):frames, work, worst, over = o[0], o[1], o[2], o[3]- det = "/".join(str(x) for x in [o[12], o[9]] + list(o[4:8]))+ det = "/".join(str(x) for x in [o[13], o[12], o[9]] + list(o[4:8]))print(f"{NAMES[t]:9}: {frames:5} frames, {work / max(frames, 1):5.1f} ms a frame, slowest {worst:3} ms, "- f"{over:3} over 33 ms (quality 0/1/2/3/4/5: {det}), finish {o[8]} ms" ++ f"{over:3} over 33 ms (quality 0-6: {det}), finish {o[8]} ms" +(f", slow ones: {o[10] // over} triangles, {o[11] // over} chunks" if over else "") + ("" if done else ", NOT done"))bad += over > 0 or not donesys.exit(1 if bad else 0)