Skip to content

Scratch for Java 7.0 - #60

Merged
mikebarkmin merged 21 commits into
mainfrom
v7
Oct 26, 2026
Merged

mikebarkmin merged 21 commits into
mainfrom
v7

Conversation

@mikebarkmin

Copy link
Copy Markdown
Member

7.0: LWJGL instead of Processing, extensions as jars of their own, the learner API cleanup and the scratch-gamepad extension. The changesets (major) bump the version to 7.0.0; docs/book/migrate-to-7.md lists every breaking change.

- Own renderer on LWJGL (OpenGL 3.3, 4.1 on macOS), sound on OpenAL Soft,
  images and fonts through stb; no Processing, JOGL or java.desktop.
- A window thread and a game thread in lockstep: run() is called 60 times
  per second of game time, and the scene reaches the renderer as a draw
  list. Collisions, colour sensing and text layout are computed on the CPU,
  the same on every GPU and in headless tests.
- Modules: core (scratch); the extensions tiled, save, recorder and drawing
  as jars of their own on a public extension API; the fat jar with build
  checks (all); the examples (demos, reference examples, parity probes,
  documentation tools). The 6.x single-module sources are removed.
- The API cleaned up for learners: time in seconds, animations and
  nine-slicing on every sprite, layers, an immutable Color, Scratch's colour
  effect next to the tint, a shorter shader format, Scratch's ask box.
  docs/book/migrate-to-7.md lists every change.
- templates/extension-starter for extensions by others.
- run.sh, visual-parity.sh, reference-docs.sh and update-demo-pages.sh build
  in the reactor; migrate-7.py moves 6.x projects to 7.0 and marks what
  needs a person.
- The release workflow versions and publishes the modules in lockstep.
- Catalogs and the compatibility contract regenerated from the 7.0 API.
- "Moving from 6.x to 7.0" lists every change; the major changeset.
- Setup with Studio instead of BlueJ, the extension artifacts for Maven.
- Tutorial projects and the VS Code starter on 7.0.
The standalone checks behind the move to LWJGL (window, game loop, text,
audio, the macOS launch routes) and the workflow that runs them on macOS.
Module layout, build commands, testing without a window, the architecture
and the documentation pipeline for 7.0, in one file for every tool.
…x calls

- target/ and hidden folders (.scratch4j/, .vscode/, …) are copied, not migrated:
  Studio's generated launcher got a note it should not have
- the row/column addAnimation hint matched the sheet calls the script had
  just written; it now needs six arguments, or seven ending in true/false
- A sprite keeps its world hitbox until it moves, turns, grows or changes
  costume or hitbox; touching checks asked for it twice per pair.
- The stage keeps its sprites in order until they change, instead of copying
  the list for every touching check.
- Colour checks leave out sprites whose painted pixels cannot lie under the
  sensing sprite, and a picture decides once whether it has effects to apply.

With 400 sprites each asking which others it touches, a tick takes 6 ms
instead of 25 ms (39 ns per pair; 6.x needed 58 ns).
- examples/src/main/java/benchmark: the stress test, n sprites asking which
  others they touch, n sprites looking for a colour; the same source runs on
  6.x (scripts/benchmark/Main6.java against a build of main)
- every run appends updates/s, frames/s, CPU and the cost per check, with
  commit, display, renderer and CPU, to scripts/benchmark/history.csv
- the history starts with the runs under Xvfb before and after the faster
  collision and colour checks
getTouchingSprite(s) and isTouchingSprite ask for the sprite's own hitbox
once, not again for every other sprite (800 sprites checking each other:
24.5 → 21 ms per tick). The benchmark can exit normally for a profiler
(-Dbenchmark.exit=true).
- the graphic effects travel with the vertices instead of uniforms, so
  sprites with different effects are drawn together
- consecutive sprites and image regions with the built-in program form one
  run: program and projection are set once, and only a change of texture
  draws what was collected (before: about eight GL calls per sprite)
- costumes up to 512 pixels go into 2048-pixel atlas pages, each on an
  8-pixel grid with its edge pixels repeated around it and three mip levels,
  so they look as in a texture of their own; shaders still get the costume
  as a texture of its own

Stress test on a Radeon 780M: 540 figures 0.31 → 0.15 cores, 2160 figures
0.89 → 0.29 cores, both at 60 frames per second. visual-parity unchanged.
… swaps

The window decided that vsync works unless 30 frames in a row came in under
half a period (counting the tick work too). Once drawing got faster, frames
alternated around that mark under Xvfb and the window drew up to 127 identical
frames a second. Now the time between swaps is compared with the monitor's
refresh period, and most of 60 swaps have to come too fast. A 144 Hz monitor,
whose swaps the old rule took for "not waiting", keeps its vsync.
F12 keeps toggling debug mode; while it is on, a chip in the bottom right
opens a checkbox list: hitboxes, positions (with the sprite's name), mouse
and camera, touching pairs, hidden sprites, clone count, frame rate.
-Dscratch4j.debug=... presets the options for headless runs. Clicks on
the panel never reach the learner, and it rides the capture-excluded
overlayItems, so captures stay reproducible.
The donutIO background grid covers the whole stage and follows the
camera, so it counted as touching every donut (the debug overlay's
touching pairs made it visible); it is scenery: disableHitbox(). Also
remove leftovers the debug line, a println, the vestigial per-tick
pen eraseAll (v7 has no canvas until a pen draws) and unused imports.
Controllers for up to four players: Gamepad asks anywhere for buttons,
sticks (y up, as on the stage, with a dead zone), triggers and
connections, and stages and sprites implementing GamepadListener are
told about presses, releases and controllers connecting (changeset:
minor). Wired into the fat jar, the examples and the build checks; the
Online IDE does not offer the example yet.

Smooth pixel art now scales the letterbox to fit, like its camera zoom,
instead of whole numbers; plain pixel art keeps stepping whole pixels
(changeset: patch).

Also: the docs embed the online IDE instead of loading it from a CDN,
the README and the docs index state that the project is independent of
the Scratch Foundation, the benchmark history gets the runs after the
batching and costume atlas changes, and the catalogs and browser
compatibility files are regenerated with the gamepad API.
@mikebarkmin
mikebarkmin merged commit 3031245 into main Oct 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant