Skip to content

Commit 4c47175

Browse files
author
DavidQ
committed
BUILD PR: centralize cloneSnapshot across exact network_sample_c batch.
1 parent c74c5fb commit 4c47175

8 files changed

Lines changed: 124 additions & 48 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
MODEL: GPT-5.3-codex
22
REASONING: high
33
COMMAND:
4-
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_39_SAFE_NORMALIZE_AITARGETDUMMY_BATCH.md exactly.
4+
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_40_CLONE_SNAPSHOT_NETWORK_SAMPLE_C_BATCH.md exactly.
55
Edit only these files:
6-
- src/shared/math/vectorNormalizeUtils.js (new file)
7-
- games/AITargetDummy/game/AITargetDummyController.js
8-
- games/AITargetDummy/game/AITargetDummyWorld.js
6+
- src/shared/utils/snapshotCloneUtils.js (new file)
7+
- games/network_sample_c/game/ReconciliationLayerAdapter.js
8+
- games/network_sample_c/game/StateTimelineBuffer.js
99
Do not expand scope.
10-
Package the delta output to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_39_SAFE_NORMALIZE_AITARGETDUMMY_BATCH_delta.zip
10+
Package the delta output to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_40_CLONE_SNAPSHOT_NETWORK_SAMPLE_C_BATCH_delta.zip

docs/dev/COMMIT_COMMENT.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BUILD PR: centralize safeNormalize across exact AITargetDummy batch.
1+
BUILD PR: centralize cloneSnapshot across exact network_sample_c batch.

docs/dev/NEXT_COMMAND.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Next: run BUILD_PR_SHARED_EXTRACTION_40_CLONE_SNAPSHOT_NETWORK_SAMPLE_C_BATCH after this batch.
1+
Next: continue duplicate-family extraction from the provided duplicate report.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Rebuilt 39 as an execution-grade batch using the exact duplicate-report file list for safeNormalize(x, y).
1+
Rebuilt 40 as an execution-grade batch using the exact duplicate-report file list for cloneSnapshot(snapshot).
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# BUILD_PR_SHARED_EXTRACTION_40_CLONE_SNAPSHOT_NETWORK_SAMPLE_C_BATCH
2+
3+
## Purpose
4+
Centralize duplicated `cloneSnapshot(snapshot)` implementations across the exact network_sample_c batch identified in the duplicate report.
5+
6+
## Single PR Purpose
7+
Normalize ONLY this helper:
8+
9+
- `cloneSnapshot(snapshot)`
10+
11+
## Exact Files Allowed
12+
13+
### New shared file
14+
1. `src/shared/utils/snapshotCloneUtils.js`
15+
16+
### Consumer files
17+
2. `games/network_sample_c/game/ReconciliationLayerAdapter.js`
18+
3. `games/network_sample_c/game/StateTimelineBuffer.js`
19+
20+
Do not edit any other file.
21+
22+
## Source of Truth
23+
This exact scope comes from the provided duplicate report entry for:
24+
25+
`function cloneSnapshot(snapshot)`
26+
27+
Only the 2 listed consumer files are in scope.
28+
29+
## Exact Shared Helper Creation
30+
Create:
31+
32+
`src/shared/utils/snapshotCloneUtils.js`
33+
34+
Export exactly:
35+
36+
```js
37+
export function cloneSnapshot(snapshot) {
38+
// copy one existing implementation exactly
39+
}
40+
```
41+
42+
Implementation rules:
43+
- use ONE existing local implementation as source-of-truth
44+
- do NOT merge logic
45+
- do NOT generalize behavior
46+
- preserve the function signature exactly:
47+
- `cloneSnapshot(snapshot)`
48+
49+
## Exact Consumer Changes
50+
For each of the 2 listed consumer files:
51+
52+
If the file contains a local function definition matching:
53+
```js
54+
function cloneSnapshot(snapshot)
55+
```
56+
then:
57+
- remove the local `cloneSnapshot(snapshot)` function definition
58+
- import `cloneSnapshot` from the correct relative path to:
59+
- `src/shared/utils/snapshotCloneUtils.js`
60+
- if the file already imports from that module, add `cloneSnapshot` with the minimum safe edit
61+
- do not duplicate imports
62+
- do not touch unrelated helpers
63+
- do not change logic
64+
65+
If a listed file already imports and uses shared `cloneSnapshot`, leave it unchanged.
66+
67+
## Relative Import Rule
68+
Use the correct relative path from each consumer file to:
69+
70+
`src/shared/utils/snapshotCloneUtils.js`
71+
72+
Do not use aliases.
73+
Do not change `.js` extension usage.
74+
75+
## Hard Constraints
76+
- no engine changes
77+
- no game files outside the 2 listed consumers
78+
- no sample files
79+
- no repo-wide snapshot/deep-clone cleanup
80+
- no behavior changes
81+
- keep one PR purpose only
82+
83+
## Validation Checklist
84+
1. Confirm no more than the 3 listed files changed
85+
2. Confirm `src/shared/utils/snapshotCloneUtils.js` exists and exports `cloneSnapshot`
86+
3. Confirm local `function cloneSnapshot(snapshot)` definitions no longer exist in changed listed consumer files
87+
4. Confirm changed consumer files import `cloneSnapshot` from the correct relative path to `src/shared/utils/snapshotCloneUtils.js`
88+
5. Confirm no unrelated engine, game, or sample files changed
89+
6. Confirm no behavior changes were made
90+
91+
## Non-Goals
92+
- no cleanup of `clone(value)`
93+
- no cleanup of `cloneJson(value)`
94+
- no cleanup outside the 2 listed consumer files
95+
- no refactor beyond this exact duplicate-removal batch

games/network_sample_c/game/ReconciliationLayerAdapter.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ReconciliationLayerAdapter.js
66
*/
77
import StateTimelineBuffer from "./StateTimelineBuffer.js";
88
import { asFiniteNumber, asPositiveInteger } from "../../../src/shared/utils/numberUtils.js";
9+
import { cloneSnapshot } from "../../../src/shared/utils/snapshotCloneUtils.js";
910

1011
const APPROVED_PUBLIC_EVENT_TYPES = new Set([
1112
"worldState.transition.applied",
@@ -19,26 +20,6 @@ function sanitizeText(value, fallback = "") {
1920
return typeof value === "string" && value.trim() ? value.trim() : fallback;
2021
}
2122

22-
function cloneSnapshot(snapshot) {
23-
if (snapshot === null || typeof snapshot !== "object") {
24-
return {};
25-
}
26-
return {
27-
...snapshot,
28-
entities: Array.isArray(snapshot.entities)
29-
? snapshot.entities.map((entity) => ({
30-
...entity,
31-
position: entity?.position ? { ...entity.position } : undefined,
32-
velocity: entity?.velocity ? { ...entity.velocity } : undefined,
33-
stateFlags: entity?.stateFlags ? { ...entity.stateFlags } : undefined
34-
}))
35-
: [],
36-
meta: snapshot.meta && typeof snapshot.meta === "object"
37-
? { ...snapshot.meta }
38-
: undefined
39-
};
40-
}
41-
4223
function cloneEntitySnapshot(entity) {
4324
const source = entity && typeof entity === "object" ? entity : {};
4425
return {

games/network_sample_c/game/StateTimelineBuffer.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ StateTimelineBuffer.js
66
*/
77

88
import { asPositiveInteger } from "../../../src/shared/utils/numberUtils.js";
9+
import { cloneSnapshot } from "../../../src/shared/utils/snapshotCloneUtils.js";
910

1011
function normalizeFrameId(frameId) {
1112
const numeric = Number(frameId);
@@ -15,26 +16,6 @@ function normalizeFrameId(frameId) {
1516
return Math.floor(numeric);
1617
}
1718

18-
function cloneSnapshot(snapshot) {
19-
if (snapshot === null || typeof snapshot !== "object") {
20-
return {};
21-
}
22-
return {
23-
...snapshot,
24-
entities: Array.isArray(snapshot.entities)
25-
? snapshot.entities.map((entity) => ({
26-
...entity,
27-
position: entity?.position ? { ...entity.position } : undefined,
28-
velocity: entity?.velocity ? { ...entity.velocity } : undefined,
29-
stateFlags: entity?.stateFlags ? { ...entity.stateFlags } : undefined
30-
}))
31-
: [],
32-
meta: snapshot.meta && typeof snapshot.meta === "object"
33-
? { ...snapshot.meta }
34-
: undefined
35-
};
36-
}
37-
3819
function lowerBound(sortedValues, target) {
3920
let left = 0;
4021
let right = sortedValues.length;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function cloneSnapshot(snapshot) {
2+
if (snapshot === null || typeof snapshot !== "object") {
3+
return {};
4+
}
5+
return {
6+
...snapshot,
7+
entities: Array.isArray(snapshot.entities)
8+
? snapshot.entities.map((entity) => ({
9+
...entity,
10+
position: entity?.position ? { ...entity.position } : undefined,
11+
velocity: entity?.velocity ? { ...entity.velocity } : undefined,
12+
stateFlags: entity?.stateFlags ? { ...entity.stateFlags } : undefined
13+
}))
14+
: [],
15+
meta: snapshot.meta && typeof snapshot.meta === "object"
16+
? { ...snapshot.meta }
17+
: undefined
18+
};
19+
}

0 commit comments

Comments
 (0)