- Java 97.4%
- GLSL 2.4%
- JavaScript 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
The release skill no longer bumps the engine version in game repositories; it only says which games could move to the new version. |
||
| .claude | ||
| .forgejo/workflows | ||
| .mvn | ||
| docs | ||
| release | ||
| src | ||
| .gitignore | ||
| .mcp.json | ||
| .releaserc.json | ||
| CLAUDE.md | ||
| imgui.ini | ||
| pom.xml | ||
| README.md | ||
Engine
Reusable 2D game engine: Java 25 + Vulkan 1.3 (LWJGL). SDF shapes with glow and HDR bloom, sprites, SDF text, particles, a fixed-tick game loop, OpenAL audio with a procedural synth and sequencer, input actions with rebinding, a profiler and Dear ImGui for debug UI. It knows nothing about any game; games depend on it through Maven.
Design decisions: docs/DESIGN.md.
Using the engine in a game
The engine is published to the Forgejo package registry of git.nestplan.cz. The registry
is public, so reading needs no credentials:
<repositories>
<repository>
<id>forgejo</id>
<url>https://git.nestplan.cz/api/packages/tomas/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>cz.nestplan</groupId>
<artifactId>engine</artifactId>
<version>0.3.0</version>
</dependency>
</dependencies>
LWJGL, its Linux natives and imgui-java come along as transitive dependencies. The game's
JVM needs --enable-native-access=ALL-UNNAMED (e.g. in .mvn/jvm.config and the surefire
argLine) and a Vulkan loader from the system (libvulkan.so).
Screens with a state stack
A game with several screens can run a StateStack instead of one App: each screen is a
GameState, only the top one gets input, and a transparent() state (a pause menu) keeps the
one below visible.
new Engine(config).run(new StateStack(engine -> new MainMenu()));
// MainMenu.update: stack.replace(new Run()); Run.update: stack.push(new PauseMenu());
Game UI
engine.gui() is an immediate-mode UI drawn with the engine's shapes and text, above the scene
and below ImGui. Call engine.gui() once in init (it loads the font), then declare the widgets
every frame in render. Sizes are in pixels at the reference resolution (1280 × 720 by default),
scaled to the window.
Ui ui = engine.gui();
ui.panel("wave", Anchor.TOP_CENTER, 0, 12); // sizes to its content; or give a width and height
ui.heading("Wave 3");
ui.row();
ui.label("Next in", ui.theme().dimText);
ui.label("12 s");
ui.end(); // the row
ui.end(); // the panel
Buttons return their click; a game's own widget is an item it paints itself:
if (ui.button("Call the wave")) startWave();
for (int i = 0; i < choices.size(); i++) {
ui.pushId(i); // same id inside, different items
Ui.Item card = ui.item("card", 180, 240); // where it is and what the mouse does with it
paintCard(ui.draw(), card, choices.get(i)); // ui.draw() works in UI units, card.hover() eases 0..1
if (card.clicked()) pick(i);
ui.popId();
}
HUD pieces: ui.meter(infection, color, "62 %"), ui.image(sprite, w, h) and
ui.cooldownButton("fever", icon, 40, remaining, total) (a clockwise wipe, true when clicked while
ready). ui.tooltip("…") after an item shows a text once the pointer rests on it (or
if (ui.tooltip()) { …widgets…; ui.end(); }), ui.beginTooltip() shows one at once (a unit in the
world). ui.modal() dims the screen below the panels declared after it (level-up choice, pause).
Forms: bloom = ui.checkbox("Bloom", bloom), volume = ui.slider("Volume", volume, 0, 1) (an
int overload steps), ui.separator(), and ui.beginDisabled(locked) … ui.endDisabled() fades
and disables what's inside. UiDemoTest renders every widget into target/ui-demo-*.png.
The look is in ui.theme() (colors, rounding, padding, font). While the mouse is over the UI,
engine.uiWantsMouse() is true – pass it to CameraController.setUiCapture(engine::uiWantsMouse, engine::uiWantsKeyboard) and skip world clicks.
Save games
record Meta(int currency, List<String> unlocked) {}
static final SaveFormat<Meta> META = new SaveFormat<>(Meta.class, 2)
.migration(1, json -> json.put("currency", 0)); // version 1 had no currency
engine.saves().save("meta", META, meta); // ~/.config/<game>/saves/meta.json
Meta meta = engine.saves().load("meta", META); // null if there is none yet
Problems come as SaveException with a message to show the player.
Choosing the GPU
By default a discrete GPU is preferred. A game can let the player choose: save a preference
(auto, integrated, discrete or part of a GPU's name) under Engine.GPU_SETTING in
engine.settings(); it applies on the next start. renderer.gpus() lists the GPUs to offer and
renderer.gpuName() tells which one is in use. -Dvk.gpu=... overrides the setting.
Developing the engine together with a game
The version in pom.xml is always dev-SNAPSHOT (releases get their number in CI). To try
engine changes in a game before a release:
mvn installhere – putsdev-SNAPSHOTinto the local~/.m2repository (add-DskipTestsfor a quick round trip).- Point the game's dependency to
dev-SNAPSHOTwhile you work, and back to a released version before committing the game.
Sprites from a packed atlas
Atlas atlas = renderer.loadAtlas(new AtlasBuilder()
.add("tower", paintedImage) // a BufferedImage painted in code
.addPng("spark", "/sprites/spark.png"));
draw.sprite(atlas.get("tower"), x, y, 32, 32, 0);
List<Sprite> walk = atlas.frames("walk"); // walk1, walk2, … walk10
Post effects
Fullscreen effects run on the HDR scene before bloom; the UI is never touched. Ready-made ones:
PostEffects.vignette(renderer, 0.4f, 0.5f, 0.5f); // strength, radius, softness
PostEffects.chromaticAberration(renderer, 3f); // pixels at the screen edges
PostEffect hit = PostEffects.flash(renderer, 1f, 0.1f, 0.05f);
PostEffects.setFlash(hit, 0.6f); // fade it out over a few ticks
A game's own effect is a fragment shader with the contract in PostEffect's javadoc:
PostEffect fx = renderer.addPostEffect("/shaders/fever.frag"); fx.set(0, ...).
Hot reload in dev mode
Run the game with -Dshaders.dir=<engine>/src/main/resources/shaders to edit engine shaders
while it runs: a saved shader rebuilds its pipelines, and one that doesn't compile is reported
while the old pipeline keeps drawing. With -Ddata.dir=src/main/resources/data the game can
reload its own data files:
engine.watchData("towers.json", path -> towers = TowerData.load(path));
Building and testing
mvn verify
Tests render real frames on the GPU through a hidden window and check pixels and Vulkan
validation errors. Without a display or Vulkan they are skipped, unless
REQUIRE_GPU_TESTS=true (set in CI, which uses Mesa lavapipe under Xvfb).
Releasing
Releases are automatic. Commit messages follow Conventional Commits:
| Commit | Release |
|---|---|
feat: … / feat(ui): … |
minor (0.4.0 → 0.5.0) |
fix: …, perf: … |
patch (0.4.0 → 0.4.1) |
feat!: … or a BREAKING CHANGE: footer |
minor while below 1.0 (then major) |
docs:, test:, refactor:, build:, ci:, chore:, style: |
none |
After every green CI run on main, the release job runs semantic-release
(.releaserc.json, tooling pinned in release/package.json): if the commits since the last tag
call for a release, it tags vX.Y.Z, publishes cz.nestplan:engine:X.Y.Z and creates the Forgejo
release with notes grouped by commit type. So pushing to main is releasing. Released versions
can't be overwritten in the registry; a failed publish is fixed by the next release.
To see what the next release would be: npm ci --prefix release once, then
release/node_modules/.bin/semantic-release --dry-run --no-ci (it needs push access to the remote).
Publishing needs the repository secret PACKAGES_TOKEN: a Forgejo access token with the
write:package scope (Settings → Applications → Access tokens, then the repository's
Settings → Actions → Secrets). To publish from your machine instead (mvn deploy), put the
same token into ~/.m2/settings.xml:
<settings>
<servers>
<server>
<id>forgejo</id>
<username>tomas</username>
<password>YOUR_TOKEN</password>
</server>
</servers>
</settings>