Skip to content

Commit e1c142e

Browse files
author
DavidQ
committed
BUILD PR: centralize clamp(value,min,max) across core game batch.
1 parent a0b17dd commit e1c142e

27 files changed

Lines changed: 134 additions & 103 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
MODEL: GPT-5.3-codex
22
REASONING: high
33
COMMAND:
4-
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_27_AS_OBJECT_AS_ARRAY_DEBUG_BATCH.md exactly.
5-
Edit only these files:
6-
- src/engine/debug/inspectors/shared/inspectorUtils.js (only if minimum export fix is needed)
7-
- games/Asteroids/debug/asteroidsShowcaseDebug.js
8-
- games/network_sample_a/debug/networkSampleADebug.js
9-
- games/network_sample_b/debug/networkSampleBDebug.js
10-
- games/network_sample_c/debug/networkSampleCDebug.js
11-
- tools/dev/inspectors/inspectorStore.js
12-
- tools/dev/plugins/debugPluginSystem.js
13-
Fail fast unless src/engine/debug/inspectors/shared/inspectorUtils.js exists and exposes asObject and asArray, or can be fixed with a minimum export-only change.
4+
Execute docs/pr/BUILD_PR_SHARED_EXTRACTION_28_CLAMP_CORE_BATCH.md exactly.
5+
Edit only:
6+
- src/engine/utils/math.js (export fix only if needed)
7+
- listed game files
8+
Fail fast if clamp is not available.
149
Do not expand scope.
15-
Package the delta output to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_27_AS_OBJECT_AS_ARRAY_DEBUG_BATCH_delta.zip
10+
Package to <project folder>/tmp/BUILD_PR_SHARED_EXTRACTION_28_CLAMP_CORE_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 asObject/asArray across debug batch to inspectorUtils shared helper.
1+
BUILD PR: centralize clamp(value,min,max) across core game batch.

docs/dev/NEXT_COMMAND.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Next: continue duplicate-family batch extraction from the provided duplicate report.
1+
Next: continue duplicate-family extraction.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Batch extraction for asObject/asArray across selected debug consumers only.
1+
clamp core batch extraction
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
asObject/asArray batch moved to shared helper with consumer imports updated.
1+
clamp centralized
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# BUILD_PR_SHARED_EXTRACTION_28_CLAMP_CORE_BATCH
2+
3+
## Purpose
4+
Centralize duplicated `clamp(value, min, max)` implementations across core/game usage into the engine math utility.
5+
6+
## Single PR Purpose
7+
Normalize ONLY this helper:
8+
9+
- clamp(value, min, max)
10+
11+
Target batch (core + games using identical signature):
12+
13+
1. games/AITargetDummy/game/AITargetDummyController.js
14+
2. games/AITargetDummy/game/AITargetDummyInputController.js
15+
3. games/AITargetDummy/game/AITargetDummyWorld.js
16+
4. games/Asteroids/game/AsteroidsAttractAdapter.js
17+
5. games/Bouncing-ball/game/BouncingBallWorld.js
18+
6. games/Breakout/game/BreakoutWorld.js
19+
7. games/Gravity/game/GravityInputController.js
20+
8. games/Gravity/game/GravityWorld.js
21+
9. games/MultiBallChaos/game/MultiBallChaosWorld.js
22+
10. games/network_sample_a/game/FakeLoopbackNetworkModel.js
23+
11. games/network_sample_a/game/NetworkSampleAScene.js
24+
12. games/network_sample_b/game/FakeHostClientNetworkModel.js
25+
13. games/network_sample_c/game/FakeDivergenceTraceNetworkModel.js
26+
14. games/PacmanLite/game/PacmanLitePlayerController.js
27+
15. games/PaddleIntercept/game/PaddleInterceptWorld.js
28+
16. games/Pong/game/PongWorld.js
29+
17. games/SpaceDuel/game/SpaceDuelAttractAdapter.js
30+
18. games/SpaceInvaders/game/SpaceInvadersInputController.js
31+
19. games/SpaceInvaders/game/SpaceInvadersWorld.js
32+
20. games/Thruster/game/ThrusterInputController.js
33+
21. games/Thruster/game/ThrusterWorld.js
34+
35+
## Exact Files Allowed
36+
37+
### Canonical shared source
38+
1. src/engine/utils/math.js
39+
40+
### Consumers
41+
(only the 21 listed files)
42+
43+
## Shared Helper
44+
Use:
45+
- src/engine/utils/math.js
46+
47+
Fail fast unless it exports:
48+
- clamp
49+
50+
If present but not exported correctly → minimal export fix only.
51+
52+
## Change Rules
53+
54+
### Shared file
55+
Allowed:
56+
- ensure clamp exists
57+
- ensure clamp is exported
58+
59+
Not allowed:
60+
- no behavior change
61+
62+
### Consumer files
63+
If local:
64+
```js
65+
function clamp(value, min, max)
66+
```
67+
68+
Then:
69+
- remove local definition
70+
- import clamp from src/engine/utils/math.js
71+
- merge into existing import if present
72+
73+
Do NOT touch:
74+
- clamp with fallback param
75+
- clamp variants with different signatures
76+
77+
## Constraints
78+
- no tools
79+
- no debug
80+
- no samples
81+
- no behavior change
82+
- exact batch only
83+
84+
## Validation
85+
- only listed files changed
86+
- no local clamp definitions remain in listed files
87+
- imports added correctly
88+
- no signature mismatch introduced
89+
90+
## Non-Goals
91+
- no clamp(fallback) variants
92+
- no tools clamp cleanup

games/AITargetDummy/game/AITargetDummyController.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ AITargetDummyController.js
66
*/
77
import AITargetDummyConfig from './AITargetDummyConfig.js';
88
import AITargetDummyStateMachine from './AITargetDummyStateMachine.js';
9-
10-
function clamp(value, min, max) {
11-
return Math.max(min, Math.min(max, value));
12-
}
9+
import { clamp } from '../../../src/engine/utils/math.js';
1310

1411
function safeNormalize(x, y) {
1512
const length = Math.hypot(x, y);

games/AITargetDummy/game/AITargetDummyInputController.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ David Quesenberry
55
AITargetDummyInputController.js
66
*/
77
import { GamepadInputAdapter } from '../../../src/engine/input/index.js';
8-
9-
function clamp(value, min, max) {
10-
return Math.max(min, Math.min(max, value));
11-
}
8+
import { clamp } from '../../../src/engine/utils/math.js';
129

1310
export default class AITargetDummyInputController {
1411
constructor(input) {

games/AITargetDummy/game/AITargetDummyWorld.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ AITargetDummyWorld.js
66
*/
77
import AITargetDummyConfig from './AITargetDummyConfig.js';
88
import AITargetDummyController from './AITargetDummyController.js';
9+
import { clamp } from '../../../src/engine/utils/math.js';
910

1011
const MAX_STEP_SECONDS = 1 / 120;
1112

12-
function clamp(value, min, max) {
13-
return Math.max(min, Math.min(max, value));
14-
}
15-
1613
function safeNormalize(x, y) {
1714
const length = Math.hypot(x, y);
1815
if (length <= 1e-6) {

games/Asteroids/game/AsteroidsAttractAdapter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ David Quesenberry
44
03/25/2026
55
AsteroidsAttractAdapter.js
66
*/
7-
function clamp(value, min, max) {
8-
return Math.max(min, Math.min(max, value));
9-
}
7+
import { clamp } from '../../../src/engine/utils/math.js';
108

119
function estimateTextWidth(text, fontPx) {
1210
return String(text ?? '').length * (fontPx * 0.62);

0 commit comments

Comments
 (0)