With the behaviors fixed, the scene Performance test still ran at about 23 fps with 500 entities. The rest of the frame went to the editor: every spawn or destroy rebuilt the hierarchy with all its rows, redrew the scene view behind the game tab and refreshed every panel. The game itself is cheap. What the panels show of it now follows a preset in the project settings. - New section While playing in the project settings with three presets: Live, Balanced and Minimal. Every project reads as Balanced, including those saved before the setting existed. - Live keeps today's behavior. Balanced brings hierarchy and panel values up to date 4 times a second and stops redrawing the hidden scene view. Minimal updates hierarchy and values only on pause and throttles the graph tabs as well. - The graph and state machine tabs stay live under Balanced. At 4 updates a second the beads on exec edges stutter, and the tabs draw only while on screen. This differs from the issue proposal. - The game itself is never throttled. Pause, step and stop bring every panel up to date at once, and a change of structure that falls between two updates is kept for the next one. - The rule lives in editor/playThrottle.ts as panelPolicy and PanelClock. PlaySession asks it after every frame. - Objects spawned at the top level go into a hierarchy group named after their asset, so hundreds of gold pieces fold into one row. Groups start folded. Measured on a throwaway copy of Performance test, 3 s each, fps: - About 500 entities: Live 38.6, Balanced 56, Minimal 60.6. - About 315 entities: Live 56.9, Balanced 60.5, Minimal 60.6. - p95 frame time at 500 entities: 60 ms, 41 ms and 23 ms. Tests: - ./check.sh: 193 files, 2799 tests, CHECK EXIT 0. - GM_STEPS=1,18,59: ALL PASSED, 54 checks. - Full e2e run (local): ALL PASSED, 1562 checks. - tests/editor/play-throttle.test.ts: presets, update rates, kept structure changes, flush, spawn group and loading old projects. - New e2e module 59: preset chosen with the mouse, measured update rates, scene view behind the game tab, Minimal with pause. - Module 03 now expects spawned objects in their group row after the next update. - Counter-checks: 4 in unit tests and 2 in the browser, each failing as expected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
/**
|
|
* What "Apply" in the Project settings dialog (#183) actually carries out. The dialog itself is a
|
|
* widget and needs a canvas; the rule behind it is a pure function and is tested here.
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { settingsChanges, type ProjectSettings } from '../../src/editor/ProjectSettingsDialog';
|
|
|
|
const before: ProjectSettings = {
|
|
name: 'Demo project',
|
|
playFrom: 'start',
|
|
whilePlaying: 'balanced',
|
|
collisionLayers: ['Default', 'Enemies'],
|
|
symbolScale: 1,
|
|
};
|
|
|
|
describe('project settings', () => {
|
|
it('reports nothing to do when nothing was touched', () => {
|
|
expect(settingsChanges(before, { ...before, collisionLayers: ['Default', 'Enemies'] })).toEqual({});
|
|
});
|
|
|
|
it('renames only when the name really differs', () => {
|
|
expect(settingsChanges(before, { ...before, name: 'Tetris' }).name).toBe('Tetris');
|
|
expect(settingsChanges(before, { ...before, name: 'Demo project' }).name).toBeUndefined();
|
|
});
|
|
|
|
it('trims the name and keeps the old one when only blanks are left', () => {
|
|
expect(settingsChanges(before, { ...before, name: ' Tetris ' }).name).toBe('Tetris');
|
|
expect(settingsChanges(before, { ...before, name: ' ' }).name).toBeUndefined();
|
|
});
|
|
|
|
it('writes the layers when one was added, renamed or dropped', () => {
|
|
const changed = (layers: string[]) => settingsChanges(before, { ...before, collisionLayers: layers });
|
|
expect(changed(['Default', 'Enemies', 'Pickups']).collisionLayers).toEqual([
|
|
'Default',
|
|
'Enemies',
|
|
'Pickups',
|
|
]);
|
|
expect(changed(['Default', 'Foes']).collisionLayers).toEqual(['Default', 'Foes']);
|
|
expect(changed(['Default']).collisionLayers).toEqual(['Default']);
|
|
});
|
|
|
|
it('hands back a copy of the layers, not the array the dialog goes on editing', () => {
|
|
const edited = ['Default', 'Foes'];
|
|
const change = settingsChanges(before, { ...before, collisionLayers: edited });
|
|
edited.push('Later');
|
|
expect(change.collisionLayers).toEqual(['Default', 'Foes']);
|
|
});
|
|
|
|
it('writes the symbol scale only when it changed, kept inside 0.1 to 4', () => {
|
|
expect(settingsChanges(before, { ...before, symbolScale: 1 }).symbolScale).toBeUndefined();
|
|
expect(settingsChanges(before, { ...before, symbolScale: 0.5 }).symbolScale).toBe(0.5);
|
|
expect(settingsChanges(before, { ...before, symbolScale: 0.01 }).symbolScale).toBe(0.1);
|
|
expect(settingsChanges(before, { ...before, symbolScale: 9 }).symbolScale).toBe(4);
|
|
expect(settingsChanges(before, { ...before, symbolScale: Number.NaN }).symbolScale).toBeUndefined();
|
|
});
|
|
|
|
it('writes the start-scene switch only when it changed (#226)', () => {
|
|
expect(settingsChanges(before, { ...before, playFrom: 'active' }).playFrom).toBe('active');
|
|
expect(settingsChanges(before, { ...before, playFrom: 'start' }).playFrom).toBeUndefined();
|
|
});
|
|
|
|
it('writes the While playing preset only when it changed (#265)', () => {
|
|
expect(settingsChanges(before, { ...before, whilePlaying: 'live' }).whilePlaying).toBe('live');
|
|
expect(settingsChanges(before, { ...before, whilePlaying: 'balanced' }).whilePlaying).toBeUndefined();
|
|
});
|
|
});
|