@combos-fun/engine 0.1.23 → 0.1.25

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/README.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  Keywords: `engine`, `ecs`, `kernel`, `runtime`, `game`, `system`, `component`.
6
6
 
7
+ All five outbound `combos-game:*` lifecycle/resource messages support `duration`,
8
+ the elapsed milliseconds from the game window's `window.startTime` to message
9
+ dispatch. Set `window.startTime = Date.now()` before loading the engine to measure
10
+ startup. The field is omitted when `startTime` is missing or is not a finite
11
+ number; negative elapsed times are clamped to `0`. This applies to iframe and
12
+ native bridge messages.
13
+
7
14
  ## Documentation
8
15
 
9
16
  - Per-package agent / developer notes: [`agent-skill.md`](./agent-skill.md)
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`. 2D pose: `Transform2D`. 3D pose: `Transform3D`.
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`. Each `src` slot is a url string or `{ type, url }`. `preload: true` loads during startup. Lazy `getResource` loads on first use.
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
+ ```
@@ -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.23";
894
+ const version = "0.1.25";
895
895
 
896
896
  /**
897
897
  * Sent after each `System.init` completes during `Game.addSystem`.
@@ -935,10 +935,17 @@ function setParentNotifyTargetOrigin(targetOrigin) {
935
935
  function postToParent(payload, targetOrigin) {
936
936
  if (typeof window === "undefined")
937
937
  return;
938
+ const startTime = window.startTime;
939
+ const message = {
940
+ ...payload,
941
+ ...(typeof startTime === "number" && Number.isFinite(startTime)
942
+ ? { duration: Math.max(0, Date.now() - startTime) }
943
+ : {}),
944
+ };
938
945
  const parent = window.parent;
939
946
  if (parent && parent !== window) {
940
947
  try {
941
- parent.postMessage(payload, targetOrigin);
948
+ parent.postMessage(message, targetOrigin);
942
949
  }
943
950
  catch {
944
951
  /* ignore cross-origin or detached frame */
@@ -946,7 +953,7 @@ function postToParent(payload, targetOrigin) {
946
953
  return;
947
954
  }
948
955
  try {
949
- const body = JSON.stringify(payload);
956
+ const body = JSON.stringify(message);
950
957
  const host = window;
951
958
  const bridge = host.CombosRuntimeBridge;
952
959
  if (typeof bridge?.postMessage === "function") {
@@ -1269,7 +1276,10 @@ class Game extends EventEmitter__default.default {
1269
1276
  flushObservedComponents() {
1270
1277
  for (const system of this.systems) {
1271
1278
  try {
1272
- system.update?.();
1279
+ system.update?.({
1280
+ deltaTime: 0, delta: 0, time: 0, currentTime: 0,
1281
+ frameCount: 0, fps: 0,
1282
+ });
1273
1283
  }
1274
1284
  catch (e) {
1275
1285
  console.error(`${systemClassName(system.constructor)} update error`, e);
@@ -1897,7 +1907,7 @@ function probeWebGL() {
1897
1907
  return supported;
1898
1908
  }
1899
1909
  async function probeWebGPU() {
1900
- const gpu = (typeof navigator === 'undefined' ? undefined : navigator.gpu);
1910
+ const gpu = (typeof navigator !== 'undefined' && 'gpu' in navigator ? navigator.gpu : undefined);
1901
1911
  if (!gpu?.requestAdapter)
1902
1912
  return false;
1903
1913
  try {