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: six picture qualities down to half the rows, the screenshots, thumbnail and GIF; PolyGT's pictures gone
Mason363bb27b0cdaaf3
diff --git a/docs/media/gallery/polygt3d.gif b/docs/media/gallery/polygt3d.gifdeleted file mode 100644index f103f799..00000000Binary files a/docs/media/gallery/polygt3d.gif and /dev/null differdiff --git a/docs/media/gallery/polytrack.gif b/docs/media/gallery/polytrack.gifnew file mode 100644index 00000000..8402fa98Binary files /dev/null and b/docs/media/gallery/polytrack.gif differdiff --git a/docs/media/thumb_polygt3d.png b/docs/media/thumb_polygt3d.pngdeleted file mode 100644index 4d1c91bf..00000000Binary files a/docs/media/thumb_polygt3d.png and /dev/null differdiff --git a/docs/media/thumb_polytrack.png b/docs/media/thumb_polytrack.pngnew file mode 100644index 00000000..5fccf2ceBinary files /dev/null and b/docs/media/thumb_polytrack.png differdiff --git a/games/polytrack/README.md b/games/polytrack/README.mdindex 45cfb3f7..f906a6d0 100644--- a/games/polytrack/README.md+++ b/games/polytrack/README.md@@ -17,7 +17,7 @@</p><p align="center">- <img src="../../docs/media/gallery/polytrack.gif" width="640" alt="PolyTrack: Summer 2, flat out towards the wall ride">+ <img src="../../docs/media/gallery/polytrack.gif" width="640" alt="PolyTrack: Desert 4, through a checkpoint and round its tube"></p>## Highlights@@ -32,12 +32,12 @@<table><tr>- <td align="center"><img src="docs/shot.png" width="390" alt="Racing on Summer 1"><br><sub>Summer 1: down from the start</sub></td>+ <td align="center"><img src="docs/shot.png" width="390" alt="Racing on Summer 1"><br><sub>Summer 1, after the first checkpoint</sub></td><td align="center"><img src="docs/wallride.png" width="390" alt="The wall ride on Summer 2"><br><sub>Summer 2's wall ride</sub></td></tr><tr>- <td align="center"><img src="docs/winter.png" width="390" alt="Racing on a Winter track"><br><sub>Winter 2</sub></td>- <td align="center"><img src="docs/desert.png" width="390" alt="Racing on a Desert track"><br><sub>Desert 4</sub></td>+ <td align="center"><img src="docs/winter.png" width="390" alt="Racing on Winter 2"><br><sub>Winter 2, flat out</sub></td>+ <td align="center"><img src="docs/desert.png" width="390" alt="Inside Desert 4's tube"><br><sub>Desert 4's tube</sub></td></tr><tr><td align="center"><img src="docs/tracks.png" width="390" alt="Choosing a track"><br><sub>The tracks, each with its map and record</sub></td>diff --git a/games/polytrack/docs/akagi.png b/games/polytrack/docs/akagi.pngdeleted file mode 100644index 2aed76d7..00000000Binary files a/games/polytrack/docs/akagi.png and /dev/null differdiff --git a/games/polytrack/docs/desert.png b/games/polytrack/docs/desert.pngnew file mode 100644index 00000000..3235d1ecBinary files /dev/null and b/games/polytrack/docs/desert.png differdiff --git a/games/polytrack/docs/endless.png b/games/polytrack/docs/endless.pngdeleted file mode 100644index c3a5dcf2..00000000Binary files a/games/polytrack/docs/endless.png and /dev/null differdiff --git a/games/polytrack/docs/horse.png b/games/polytrack/docs/horse.pngdeleted file mode 100644index 388886f1..00000000Binary files a/games/polytrack/docs/horse.png and /dev/null differdiff --git a/games/polytrack/docs/result.png b/games/polytrack/docs/result.pngnew file mode 100644index 00000000..8b8cc245Binary files /dev/null and b/games/polytrack/docs/result.png differdiff --git a/games/polytrack/docs/setup.png b/games/polytrack/docs/setup.pngdeleted file mode 100644index fc5d8b2a..00000000Binary files a/games/polytrack/docs/setup.png and /dev/null differdiff --git a/games/polytrack/docs/shot.png b/games/polytrack/docs/shot.pngindex d0cf5487..3a1abcb6 100644Binary files a/games/polytrack/docs/shot.png and b/games/polytrack/docs/shot.png differdiff --git a/games/polytrack/docs/tracks.png b/games/polytrack/docs/tracks.pngnew file mode 100644index 00000000..61885dbdBinary files /dev/null and b/games/polytrack/docs/tracks.png differdiff --git a/games/polytrack/docs/wallride.png b/games/polytrack/docs/wallride.pngnew file mode 100644index 00000000..fe7d12dbBinary files /dev/null and b/games/polytrack/docs/wallride.png differdiff --git a/games/polytrack/docs/wangan.png b/games/polytrack/docs/wangan.pngdeleted file mode 100644index 8df28085..00000000Binary files a/games/polytrack/docs/wangan.png and /dev/null differdiff --git a/games/polytrack/docs/winter.png b/games/polytrack/docs/winter.pngnew file mode 100644index 00000000..a6bfd294Binary files /dev/null and b/games/polytrack/docs/winter.png differdiff --git a/games/polytrack/src/render.c b/games/polytrack/src/render.cindex fa674333..28512fbf 100644--- a/games/polytrack/src/render.c+++ b/games/polytrack/src/render.c@@ -28,10 +28,15 @@ typedef struct {static tri tris[MAX_TRIS];static int ntris;int rd_tris, rd_dropped, rd_mtris, rd_chunks;-int rd_detail = 2;+int rd_detail = RD_LEVELS - 1;bool rd_half;-static const float DRAW[4] = {100.0f, 140.0f, 180.0f, 230.0f};-static const float NEAR_DETAIL[4] = {22.0f, 30.0f, 40.0f, 52.0f};+/* 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 int cap = MAX_TRIS;/* the camera */static camera_t C;@@ -155,7 +160,7 @@ static int iceil(float f) {}static void store(const sv *a, const sv *b, const sv *c, uint16_t col, int kind) {- if (ntris >= MAX_TRIS) {+ if (ntris >= cap) {rd_dropped = 1;return;}@@ -257,7 +262,10 @@ void rd_begin(const camera_t *cam, int env, int sun_byte, bool sky_only) {ntris = 0, rd_dropped = 0;float half = C.fov * 0.5f * (PT_PI / 180.0f);focal = CY * pt_cosf(half) / pt_sinf(half);- far_d = DRAW[rd_detail & 3];+ int q = rd_detail < 0 ? 0 : rd_detail >= RD_LEVELS ? RD_LEVELS - 1 : rd_detail;+ far_d = DRAW[q];+ rd_half = HALF[q];+ cap = CAP[q];fog0 = far_d * 0.55f;float l = pt_sqrtf(focal * focal + CX * CX);px_n[0] = focal / l, px_n[1] = CX / l;@@ -333,7 +341,7 @@ static void collect(int i, void *ctx) {v = &vis[far];}v->inst = (uint16_t)i, v->chunk = (uint8_t)k, v->dist = d;- v->lod = d < NEAR_DETAIL[rd_detail & 3] ? 0 : 1;+ v->lod = d < NEAR_DETAIL[rd_detail < 0 ? 0 : rd_detail >= RD_LEVELS ? RD_LEVELS - 1 : rd_detail] ? 0 : 1;}}@@ -415,11 +423,13 @@ static void mountains(void) {if (!s) return;float rad[8];for (int k = 0; k < 8; k++) rad[k] = W.mr + 100.0f * (float)k;- for (int k = 6; k >= 0; k--)- for (int e = 0; e < s; e++) {- float a0 = (float)e / (float)s * 2.0f * PT_PI, a1 = (float)(e + 1) / (float)s * 2.0f * PT_PI;+ /* (at the lowest qualities: every other segment, the nearer rings) */+ int de = rd_detail <= 1 ? 2 : 1, k0 = rd_detail <= 1 ? 3 : 6;+ for (int k = k0; k >= 0; k--)+ for (int e = 0; e < s; e += de) {+ int e1 = (e + de) % s;+ float a0 = (float)e / (float)s * 2.0f * PT_PI, a1 = (float)(e + de) / (float)s * 2.0f * PT_PI;float c0 = pt_cosf(a0), s0 = pt_sinf(a0), c1 = pt_cosf(a1), s1 = pt_sinf(a1);- int e1 = (e + 1) % s;float h00 = (float)W.mh[e][k] * (100.0f / 255.0f), h10 = (float)W.mh[e1][k] * (100.0f / 255.0f);float h01 = (float)W.mh[e][k + 1] * (100.0f / 255.0f), h11 = (float)W.mh[e1][k + 1] * (100.0f / 255.0f);if (h00 + h10 + h01 + h11 == 0.0f) continue;@@ -450,7 +460,7 @@ void rd_track(void) {}/* (when the room runs short, the further ones simplified) */for (int i = 0; i < nvis; i++) {- if (ntris > MAX_TRIS * 3 / 5) vis[i].lod = 1;+ if (ntris > cap * 3 / 5) vis[i].lod = 1;draw_chunk(&vis[i]);}rd_chunks = nvis;@@ -539,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) car_mesh(pt_extra_v, PT_EXTRA_NV, pt_extra_t, PT_EXTRA_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);/* 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))));@@ -585,19 +595,17 @@ void rd_shadow(const car_look *c, const car_t *phys) {}/* the picture's quality follows the time a race frame takes: down at once when slow (or out of room for- triangles), up slowly; below the nearest drawing distance, half the rows */+ 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 < RD_MAX_TRIS * 3 / 4) quick++, slow = 0;+ else if (spent_ms < 18 && rd_tris < cap * 3 / 4) quick++, slow = 0;else slow = quick = 0;- int q = rd_half ? 0 : 1 + (rd_detail & 3);- if (slow >= 2 && q > 0) q--, slow = 0;- if (quick >= 30 && q < 4) q++, quick = 0;- /* (a frame out of triangles at the nearest distance: not a reason for half the rows) */- if (q == 0 && spent_ms <= 30 && !rd_half) q = 1;- rd_half = q == 0;- rd_detail = q ? q - 1 : 0;+ int q = rd_detail;+ /* (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 (quick >= 30 && q < RD_LEVELS - 1) q++, quick = 0;+ rd_detail = q;}/* ------------------------------------------------------------------ drawing a strip */diff --git a/games/polytrack/src/render.h b/games/polytrack/src/render.hindex d115ec1e..4c8eabc5 100644--- a/games/polytrack/src/render.h+++ b/games/polytrack/src/render.h@@ -30,8 +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 */-extern int rd_detail; /* 0..3: how far it draws; lowered when a frame is slow */-extern bool rd_half; /* half the rows (each drawn twice), when even 0 is too slow */+#define RD_LEVELS 6+extern 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) */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 a2eebd14..fd7e5537 100644--- a/games/polytrack/tests/armperf.c+++ b/games/polytrack/tests/armperf.c@@ -14,9 +14,9 @@ const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;/* in: the track, then go (set by the emulator once the app waits); out: frames, work (ms) in all, the slowest,- frames over 33 ms, frames at each detail level, the finish, frames at half the rows */+ frames over 33 ms, frames at qualities 2..5, the finish, at 1, the triangles and the chunks of the slow frames in all, at 0 */__attribute__((used, externally_visible)) volatile uint32_t perf_track, perf_go;-__attribute__((used, externally_visible)) uint32_t perf_out[8 + 4], perf_done;+__attribute__((used, externally_visible)) uint32_t perf_out[16], perf_done;void plat_push(int x, int y, int w, int h, const uint16_t *px) {eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, (const eadk_color_t *)px);@@ -55,7 +55,7 @@ int main(void) {chase_reset(&chase, car.pos, car.rot);memset(&ui, 0, sizeof ui);ui.screen = V_RACE, ui.started = 1;- rd_detail = 3;+ rd_detail = RD_LEVELS - 1;uint32_t dt = 33, f = 0;while (!car.finish && f < 600000) {uint32_t t0 = (uint32_t)eadk_timing_millis();@@ -67,9 +67,9 @@ int main(void) {uint32_t spent = (uint32_t)eadk_timing_millis() - t0;perf_out[0]++, perf_out[1] += spent;if (spent > perf_out[2]) perf_out[2] = spent;- if (spent > 33) perf_out[3]++;- if (rd_half) perf_out[9]++;- else perf_out[4 + (rd_detail & 3)]++;+ 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]++;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/play.c b/games/polytrack/tests/play.cindex bc40b8d4..654e99f1 100644--- a/games/polytrack/tests/play.c+++ b/games/polytrack/tests/play.c@@ -297,7 +297,7 @@ static void reset_app(void) {memset(&ui, 0, sizeof ui);memset(&sv, 0, sizeof sv);memset(&car, 0, sizeof car);- rd_detail = 3;+ rd_detail = RD_LEVELS - 1;calls = 0, quit_at = 0;app_phase = 0, loaded = -1;}@@ -635,7 +635,7 @@ int main(int argc, char **argv) {if (f % 33 == 0) chase_update(&chase, &cam, 0.033f, car.pos, car.rot, car.speed);}sv.p.track = (uint8_t)t;- rd_detail = argc > 5 ? atoi(argv[5]) : 3;+ rd_detail = argc > 5 ? atoi(argv[5]) : RD_LEVELS - 1;render_race(&car, &chase, 0.0f);printf("track %s frame %u pos %.2f %.2f %.2f speed %.1f cp %d tris %d (mountains %d, chunks %d)%s\n", pt_tracks[t].name, car.frames,(double)car.pos.x, (double)car.pos.y, (double)car.pos.z, (double)car.speed, car.next_cp, rd_tris, rd_mtris, rd_chunks,@@ -672,7 +672,7 @@ int main(int argc, char **argv) {sv.p.guide = 1;for (int t = 0; t < PT_NTRACKS; t++)if (t % 3 != 2) sv.p.best[t] = 31000u + (uint32_t)t * 2345u;- rd_detail = 3;+ rd_detail = RD_LEVELS - 1;world_load(0);car_reset(&car);look = car_look_of(&car);@@ -735,7 +735,7 @@ int main(int argc, char **argv) {c.right = vnorm(vcross(c.fwd, V3(0.0f, 1.0f, 0.0f)));c.up = vcross(c.right, c.fwd);c.fov = 70.0f;- rd_detail = 3;+ rd_detail = RD_LEVELS - 1;rd_begin(&c, W.t->env, W.t->sun, false);rd_track();color_t *old = gfx_buf;@@ -758,7 +758,7 @@ int main(int argc, char **argv) {car_reset(&car);chase_reset(&chase, car.pos, car.rot);sv.p.track = (uint8_t)t;- rd_detail = 3;+ rd_detail = RD_LEVELS - 1;int n = 0;for (uint32_t f = 0; f < ms; f++) {car_step(&car, route_keys(f));diff --git a/games/polytrack/tests/route.c b/games/polytrack/tests/route.cindex f35e2430..1cfd6a57 100644--- a/games/polytrack/tests/route.c+++ b/games/polytrack/tests/route.c@@ -216,6 +216,7 @@ static int vcost = 1; /* up or down a slope or a wall (VC=) */static int air_up = 0; /* up through the air (AU=; 0: never) */static int height_buckets; /* HB= */static double speed_w = 0.5; /* SPEEDW=: what a faster class is worth, in metres of the way */+static double energy_w; /* ENERGY=: archive by energy instead, each 150 J/kg worth this many metres */static int *bucket[NB], bcount[NB], bcap[NB];static void push(int b, int i) {if (bcount[b] == bcap[b]) bcap[b] = bcap[b] ? bcap[b] * 2 : 4096, bucket[b] = realloc(bucket[b], sizeof(int) * (size_t)bcap[b]);@@ -470,6 +471,14 @@ typedef struct {(back, across, on) and how fast (under 20, 80, 140, 200, 260, 320 km/h, or over) */static uint32_t cell_key(const car_t *c) {int k = target_of(c);+ if (energy_w > 0.0) {+ /* (ENERGY=w: the stretch in 8 m steps and the car's energy, speed and height, in steps of 150 J/kg: for a+ jump that wants all the speed there is) */+ int d8 = (int)(dist_of(c) / 8.0f);+ float e = 0.5f * vlen2(c->vel) + 9.82f * c->pos.y;+ int eb = (int)pt_clampf(e / 150.0f, 0.0f, 1023.0f);+ return (uint32_t)stage_of(c) << 24 | (uint32_t)(d8 < 16383 ? d8 : 16383) << 10 | (uint32_t)eb;+ }int d = (int)(dist_of(c) / 4.0f);float v = pt_absf(c->speed);int sb = v < 20.0f ? 0 : v < 80.0f ? 1 : v < 140.0f ? 2 : v < 200.0f ? 3 : v < 260.0f ? 4 : v < 320.0f ? 5 : 6, ab = 1;@@ -484,6 +493,8 @@ static uint32_t cell_key(const car_t *c) {return (uint32_t)stage_of(c) << 24 | (uint32_t)(d < 65535 ? d : 65535) << 8 | hb << 6 | (uint32_t)ab << 4 | (uint32_t)sb;}static double progress(const cell_t *e) {+ if (energy_w > 0.0)+ return (double)(e->key >> 24) * 1e6 - (double)((e->key >> 10) & 0x3FFF) * 8.0 + (double)(e->key & 1023) * energy_w;return (double)(e->key >> 24) * 1e6 - (double)((e->key >> 8) & 0xFFFF) * 4.0 + (double)((e->key >> 4) & 3) +(double)(e->key & 7) * speed_w;}@@ -759,6 +770,7 @@ int main(int argc, char **argv) {if (getenv("AU")) air_up = atoi(getenv("AU"));if (getenv("HB")) height_buckets = atoi(getenv("HB"));if (getenv("SPEEDW")) speed_w = atof(getenv("SPEEDW"));+ if (getenv("ENERGY")) energy_w = atof(getenv("ENERGY"));int list[PT_NTRACKS], n = 0;for (int i = 1; i < argc; i++) list[n++] = atoi(argv[i]);if (!n)diff --git a/games/polytrack/tools/armperf.py b/games/polytrack/tools/armperf.pyindex c3280022..1367d415 100644--- a/games/polytrack/tools/armperf.py+++ b/games/polytrack/tools/armperf.py@@ -23,7 +23,7 @@ def one(args):c.uc.mem_write(c.symbols["perf_track"], struct.pack("<I", t))c.uc.mem_write(c.symbols["perf_go"], struct.pack("<I", 1))c.run(30 * 60 * 1000)- out = struct.unpack("<12I", bytes(c.uc.mem_read(c.symbols["perf_out"], 48)))+ out = struct.unpack("<16I", bytes(c.uc.mem_read(c.symbols["perf_out"], 64)))done, = struct.unpack("<I", bytes(c.uc.mem_read(c.symbols["perf_done"], 4)))return t, out, done@@ -35,9 +35,10 @@ 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[9]] + list(o[4:8]))+ det = "/".join(str(x) for x in [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 (half rows/detail 0/1/2/3: {det}), finish {o[8]} ms" + ("" if done else ", NOT done"))+ f"{over:3} over 33 ms (quality 0/1/2/3/4/5: {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)