Epsilon Engine Source code

Projects and persistence

Use EpsilonProject to move between authored scenes, evaluate entity transforms and serialize the production. Its codec takes the application's preset catalog and a cast normalizer. Load audio-core.js and spatial-core.js before project-core.js. For game presets, also load arcade-core.js and game-core.js.

Project and scene documents#

The envelope has schema: "epsilon-prime.studio/project@3", id, name, activeSceneId and an ordered scenes array. Each scene has its own id, the parent projectId, a preset, scene settings, a duration in authored seconds and a playback speed. A scene stores entities, cast slots, audio cues, its spatial component and, for game presets, a level. The codec also accepts legacy v1 and v2 scene documents and wraps them in a single-scene production.

Call Result and behavior
EpsilonProject.codec(presets, cleanCast, makeId?) Returns scene, project, parse, serialize, add, replace, remove and move. A preset supplies id, type, settings, actors, dialogue, four palette colors, filter and duration. Studio uses MeldCasting.cleanCast.
codec.scene(raw, projectId), codec.project(raw) Normalize one scene or a complete project. A current project requires unique scene IDs, correct parent bindings and an existing active scene.
codec.parse(text), codec.serialize(project) Read or write canonical JSON. The UTF-8 limit is 2 MiB. Unknown presets, invalid bindings and excess counts throw.
codec.add(project, rawScene), codec.replace(project, rawScene) Return the edited project. Adding assigns a new scene ID and selects it. Replacing requires an existing scene ID.
codec.move(project, sceneId, delta), codec.remove(project, sceneId) Move one slot using -1 or 1. At an end, a move returns the input project. Removing the only scene throws.
EpsilonProject.entity(raw), evaluate(entity, t) Normalize a rectangle, ellipse or text entity and sample its interpolated x, y, scale, rotation and opacity at scene time t.
EpsilonProject.duration(project), locate(project, t) Return production seconds, or {index, id, time, offset}. Each scene occupies duration / speed seconds. At an interior boundary, the next scene starts at local time zero.

A project can hold 32 scenes. Each scene can hold 64 authored entities, with up to 64 unique transform key times per entity. Each scene's duration is 4–30 authored seconds and speed is 0.25–2.

Locate a cut#

The opening scene below plays eight authored seconds at double speed. At production second four the second scene begins. The same cut survives a JSON round trip.

import './src/audio-core.js';
import './src/spatial-core.js';
import './src/cast-core.js';
import './src/project-core.js';

const P = globalThis.EpsilonProject;
const stage = {
  id: 'hangar', type: 'toon', settings: ['Bay'], actors: '', dialogue: '',
  palette: ['#102030', '#305060', '#709080', '#f0f0d0'], filter: 'clean', duration: 8
};
const codec = P.codec([stage], globalThis.MeldCasting.cleanCast);
const opening = codec.project({
  schema: P.SCHEMA, id: 'shift', name: 'Dock shift', activeSceneId: 'arrival',
  scenes: [{ id: 'arrival', projectId: 'shift', preset: 'hangar', duration: 8, speed: 2 }]
});
const sequence = codec.add(opening, { preset: 'hangar', duration: 6 });
const saved = codec.parse(codec.serialize(sequence));
const cut = P.locate(saved, 4);
console.log(P.duration(saved), cut.index, cut.time);
10 1 0

Autosave and checkpoints#

EpsilonProject.store(storage, key?) takes a getItem/setItem store such as localStorage. Call read() to establish the baseline, then write(codec.serialize(project)). If another tab changed the stored text, the write throws. Keep the unsaved document in memory so the user can export it or reconcile against the new baseline. The default key is epsilon-prime.studio.project.v3.

EpsilonCheckpoints.library(codec, indexedDB?) opens a separate project history. Its methods return promises.

Call Result
list() Summaries of local projects, newest update first, including each latest revision and available revision numbers.
save(project, expectedRevision) A summary after the transaction commits. Use 0 for a new project and the last observed latest for an existing one. An identical document at that revision reuses it. A stale expected revision rejects.
read(projectId, revision) The parsed project at that revision. A pruned or missing revision rejects.

The library retains up to 32 projects and the five most recent revisions per project. Checkpoints contain document data. Actor image bytes and private models live in their respective asset stores. Use a portable project package to move authorized actor images with a project.