@combos-fun/engine 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-skill.md +12 -2
- package/dist/engine.cjs.js +54 -9
- package/dist/engine.cjs.js.map +1 -1
- package/dist/engine.cjs.prod.js +1 -1
- package/dist/engine.d.ts +34 -5
- package/dist/engine.esm.js +53 -10
- package/dist/engine.esm.js.map +1 -1
- package/package.json +3 -3
package/agent-skill.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
ECS microkernel. New plugins: `plugin-authoring.md`.
|
|
4
4
|
|
|
5
|
-
- `Game`, `Scene`, `GameObject`, `Component`, `System`, `resource`, `decorators`. Hierarchy: `addChild` / `parent` / `children`.
|
|
5
|
+
- `Game`, `Scene`, `GameObject`, `Component`, `System`, `resource`, `decorators`. Hierarchy: `addChild` / `parent` / `children`. Import `Transform2D` from `plugin-renderer`, `Transform3D` from `plugin-renderer-3d`.
|
|
6
6
|
- `await game.addSystem(new XxxSystem(...))`. `Game({ systems })` awaits each `init`. `addSystem(XxxSystem, [params])` passes the tuple as one argument.
|
|
7
7
|
- `@decorators.componentObserver({ Name: ['prop'] })`, then `componentObserver.clear()` in `update()`.
|
|
8
8
|
- Order: `Component.update` → `Component.lateUpdate` → `System.update` → `System.lateUpdate`. `start()` runs on the first tick.
|
|
@@ -14,5 +14,15 @@ ECS microkernel. New plugins: `plugin-authoring.md`.
|
|
|
14
14
|
- Scene: `game.scene`.
|
|
15
15
|
- Component `game` is a getter (`gameObject?.scene?.game`), after the GameObject is in the scene. System `game` is set in `addSystem`.
|
|
16
16
|
- `componentObserver.clear()` events may omit `gameObject`.
|
|
17
|
-
- `resource.addResource
|
|
17
|
+
- `resource.addResource` takes an array. Use `RESOURCE_TYPE` enum values; each `src` slot must be an object with required `type` (file format). TypeScript rejects string slots and `{ url }`. `preload: true` loads during startup. Lazy `getResource` loads on first use.
|
|
18
18
|
- Inspector fields: `@Field` from `@combos-fun/inspector-decorator`. Engine `IDEProp` is legacy.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { resource, RESOURCE_TYPE } from '@combos-fun/engine';
|
|
22
|
+
|
|
23
|
+
resource.addResource([{
|
|
24
|
+
name: 'hero', type: RESOURCE_TYPE.IMAGE,
|
|
25
|
+
src: { image: { type: 'png', url: './assets/hero.png' } },
|
|
26
|
+
preload: true,
|
|
27
|
+
}]);
|
|
28
|
+
```
|
package/dist/engine.cjs.js
CHANGED
|
@@ -891,7 +891,7 @@ class Scene extends GameObject {
|
|
|
891
891
|
}
|
|
892
892
|
|
|
893
893
|
/** Generated at build from package.json */
|
|
894
|
-
const version = "0.1.
|
|
894
|
+
const version = "0.1.24";
|
|
895
895
|
|
|
896
896
|
/**
|
|
897
897
|
* Sent after each `System.init` completes during `Game.addSystem`.
|
|
@@ -1269,7 +1269,10 @@ class Game extends EventEmitter__default.default {
|
|
|
1269
1269
|
flushObservedComponents() {
|
|
1270
1270
|
for (const system of this.systems) {
|
|
1271
1271
|
try {
|
|
1272
|
-
system.update?.(
|
|
1272
|
+
system.update?.({
|
|
1273
|
+
deltaTime: 0, delta: 0, time: 0, currentTime: 0,
|
|
1274
|
+
frameCount: 0, fps: 0,
|
|
1275
|
+
});
|
|
1273
1276
|
}
|
|
1274
1277
|
catch (e) {
|
|
1275
1278
|
console.error(`${systemClassName(system.constructor)} update error`, e);
|
|
@@ -1897,7 +1900,7 @@ function probeWebGL() {
|
|
|
1897
1900
|
return supported;
|
|
1898
1901
|
}
|
|
1899
1902
|
async function probeWebGPU() {
|
|
1900
|
-
const gpu = (typeof navigator
|
|
1903
|
+
const gpu = (typeof navigator !== 'undefined' && 'gpu' in navigator ? navigator.gpu : undefined);
|
|
1901
1904
|
if (!gpu?.requestAdapter)
|
|
1902
1905
|
return false;
|
|
1903
1906
|
try {
|
|
@@ -2458,25 +2461,25 @@ const ADAPTIVE_SLOW_FRAME_COUNT = 30;
|
|
|
2458
2461
|
const ADAPTIVE_FAST_FRAME_COUNT = 120;
|
|
2459
2462
|
const ADAPTIVE_STEP = 0.5;
|
|
2460
2463
|
const MIN_PIXEL_RATIO = 1;
|
|
2461
|
-
function isPositive(value) {
|
|
2464
|
+
function isPositive$1(value) {
|
|
2462
2465
|
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
2463
2466
|
}
|
|
2464
2467
|
function roundToHalf(value) {
|
|
2465
2468
|
return Math.round(value * 2) / 2;
|
|
2466
2469
|
}
|
|
2467
2470
|
function readDevicePixelRatio(devicePixelRatio) {
|
|
2468
|
-
if (isPositive(devicePixelRatio))
|
|
2471
|
+
if (isPositive$1(devicePixelRatio))
|
|
2469
2472
|
return devicePixelRatio;
|
|
2470
|
-
if (typeof window !== 'undefined' && isPositive(window.devicePixelRatio)) {
|
|
2473
|
+
if (typeof window !== 'undefined' && isPositive$1(window.devicePixelRatio)) {
|
|
2471
2474
|
return window.devicePixelRatio;
|
|
2472
2475
|
}
|
|
2473
2476
|
return 1;
|
|
2474
2477
|
}
|
|
2475
2478
|
function resolveRenderQuality(input = {}, defaults = {}) {
|
|
2476
|
-
const maxPixelRatio = isPositive(input.maxPixelRatio) ? input.maxPixelRatio : DEFAULT_MAX_PIXEL_RATIO;
|
|
2477
|
-
const explicit = isPositive(input.resolution)
|
|
2479
|
+
const maxPixelRatio = isPositive$1(input.maxPixelRatio) ? input.maxPixelRatio : DEFAULT_MAX_PIXEL_RATIO;
|
|
2480
|
+
const explicit = isPositive$1(input.resolution)
|
|
2478
2481
|
? input.resolution
|
|
2479
|
-
: isPositive(input.pixelRatio)
|
|
2482
|
+
: isPositive$1(input.pixelRatio)
|
|
2480
2483
|
? input.pixelRatio
|
|
2481
2484
|
: undefined;
|
|
2482
2485
|
const devicePixelRatio = readDevicePixelRatio(input.devicePixelRatio ?? defaults.devicePixelRatio);
|
|
@@ -2551,6 +2554,46 @@ class AdaptivePixelRatio {
|
|
|
2551
2554
|
}
|
|
2552
2555
|
}
|
|
2553
2556
|
|
|
2557
|
+
function isPositive(value) {
|
|
2558
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
2559
|
+
}
|
|
2560
|
+
/** Backing store for the canvas box, using the caller-supplied pixel ratio. */
|
|
2561
|
+
function displayBufferSize(box, resolution) {
|
|
2562
|
+
if (!isPositive(box.width) || !isPositive(box.height) || !isPositive(resolution))
|
|
2563
|
+
return null;
|
|
2564
|
+
if (box.width < 1 || box.height < 1)
|
|
2565
|
+
return null;
|
|
2566
|
+
const bufferWidth = Math.round(box.width * resolution);
|
|
2567
|
+
const bufferHeight = Math.round(box.height * resolution);
|
|
2568
|
+
if (bufferWidth < 1 || bufferHeight < 1)
|
|
2569
|
+
return null;
|
|
2570
|
+
return { bufferWidth, bufferHeight };
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* Unity orthographic camera: vertical extent stays `height`, the view stays
|
|
2574
|
+
* centered on `(width / 2, height / 2)`, and the horizontal extent follows the
|
|
2575
|
+
* backing-store aspect.
|
|
2576
|
+
*/
|
|
2577
|
+
function fitOrthographicDisplay(input) {
|
|
2578
|
+
if (!isPositive(input.width) || !isPositive(input.height))
|
|
2579
|
+
return null;
|
|
2580
|
+
const buffer = displayBufferSize(input.box, input.resolution);
|
|
2581
|
+
if (!buffer)
|
|
2582
|
+
return null;
|
|
2583
|
+
const visibleHeight = input.height;
|
|
2584
|
+
const pixelRatio = buffer.bufferHeight / visibleHeight;
|
|
2585
|
+
const visibleWidth = buffer.bufferWidth / pixelRatio;
|
|
2586
|
+
return {
|
|
2587
|
+
bufferWidth: buffer.bufferWidth,
|
|
2588
|
+
bufferHeight: buffer.bufferHeight,
|
|
2589
|
+
visibleWidth,
|
|
2590
|
+
visibleHeight,
|
|
2591
|
+
pixelRatio,
|
|
2592
|
+
originX: input.width / 2 - visibleWidth / 2,
|
|
2593
|
+
originY: 0,
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2554
2597
|
/** Decorators util */
|
|
2555
2598
|
const decorators = {
|
|
2556
2599
|
IDEProp,
|
|
@@ -2577,6 +2620,8 @@ exports.applyCompressedImagePreference = applyCompressedImagePreference;
|
|
|
2577
2620
|
exports.componentObserver = componentObserver;
|
|
2578
2621
|
exports.compressedTextureUrl = compressedTextureUrl;
|
|
2579
2622
|
exports.decorators = decorators;
|
|
2623
|
+
exports.displayBufferSize = displayBufferSize;
|
|
2624
|
+
exports.fitOrthographicDisplay = fitOrthographicDisplay;
|
|
2580
2625
|
exports.gpuSupportsCompressedTexture = gpuSupportsCompressedTexture;
|
|
2581
2626
|
exports.imageFallbackUrl = imageFallbackUrl;
|
|
2582
2627
|
exports.isAllowedMessageOrigin = isAllowedMessageOrigin;
|