@uzuhq/code-sdk 0.8.2 → 0.8.3

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -848,7 +848,8 @@ function replaceRoot(doc, value) {
848
848
  //#region src/dev-prediction-traps.ts
849
849
  /** 描画経路の警告に使う擬似 action 名。 */
850
850
  const RENDER_CONTEXT = "(render)";
851
- const CLOCK_TRAPS = [{ install: (report) => {
851
+ /** 実時刻。先読みでも描画でもサーバーとズレる。 */
852
+ const WALL_CLOCK_TRAPS = [{ install: (report) => {
852
853
  const RealDate = Date;
853
854
  const realNow = Date.now;
854
855
  globalThis.Date = new Proxy(RealDate, { construct: (target, args) => {
@@ -863,7 +864,22 @@ const CLOCK_TRAPS = [{ install: (report) => {
863
864
  Date.now = realNow;
864
865
  globalThis.Date = RealDate;
865
866
  };
866
- } }, { install: (report) => {
867
+ } }];
868
+ /**
869
+ * 単調時計。**描画では張らない。**
870
+ *
871
+ * `gameTime()` の実装がこれを使っている。描画から毎フレーム呼ぶ前提の公開 API なので、
872
+ * 描画でも張ると「時刻は gameTime() から取れ」という指示どおりに書いたコードが
873
+ * そのまま警告される。誤検知が常時出ると本物の `Date.now()` 混入まで無視される。
874
+ *
875
+ * 代償として、生の `performance.now()` を描画で締切に混ぜる誤りは拾えない。実時刻ほど
876
+ * 桁が飛ばず (どちらも小さい数なので静かに少しズレる)、かつ作家が書くのは圧倒的に
877
+ * `Date.now()` の方なので、この取りこぼしを受け入れる。
878
+ *
879
+ * 先読みでは張る。`gameTime()` の値を state に書けばサーバーの結果とズレるので、
880
+ * これは正しい検出になる。
881
+ */
882
+ const MONOTONIC_TRAPS = [{ install: (report) => {
867
883
  const real = globalThis.performance?.now;
868
884
  if (!real) return () => {};
869
885
  const bound = real.bind(globalThis.performance);
@@ -897,7 +913,12 @@ const RANDOM_TRAPS = [{ install: (report) => {
897
913
  globalThis.crypto.randomUUID = real;
898
914
  };
899
915
  } }];
900
- const TRAPS = [...CLOCK_TRAPS, ...RANDOM_TRAPS];
916
+ const PREDICTION_TRAPS = [
917
+ ...WALL_CLOCK_TRAPS,
918
+ ...MONOTONIC_TRAPS,
919
+ ...RANDOM_TRAPS
920
+ ];
921
+ const RENDER_TRAPS = WALL_CLOCK_TRAPS;
901
922
  const warnings = [];
902
923
  const reported = /* @__PURE__ */ new Set();
903
924
  const printWarning = (action, api) => {
@@ -957,7 +978,8 @@ const runPredicted = (action, run) => {
957
978
  /**
958
979
  * `onState` から同期で走る描画を計装する。
959
980
  *
960
- * 乱数は描画で使ってよいので、時刻の罠だけ張る。ここで拾えるのは同期の描画だけで、
981
+ * 張るのは実時刻だけ。乱数は演出に使ってよく、単調時計は `gameTime()` の実装が
982
+ * 使っているので張れない (`MONOTONIC_TRAPS` を見よ)。ここで拾えるのは同期の描画だけで、
961
983
  * `requestAnimationFrame` の中は原理的に拾えない。
962
984
  */
963
985
  const runRendered = (run) => {
@@ -979,7 +1001,7 @@ const runInstrumented = (action, run) => {
979
1001
  printWarning(action, api);
980
1002
  notifyParent(action, api);
981
1003
  };
982
- const restores = (action === RENDER_CONTEXT ? CLOCK_TRAPS : TRAPS).map((trap) => trap.install(report));
1004
+ const restores = (action === RENDER_CONTEXT ? RENDER_TRAPS : PREDICTION_TRAPS).map((trap) => trap.install(report));
983
1005
  try {
984
1006
  run();
985
1007
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uzuhq/code-sdk",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "UZU PlayScreen SDK - Flutter ↔ JS ゲーム通信ライブラリ",
5
5
  "type": "module",
6
6
  "exports": {