@vesviet/agent-skills 5.8.0 → 5.10.0
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/INDEX.md +8 -7
- package/README.md +3 -2
- package/VERSION +1 -1
- package/adapters/antigravity/ANTIGRAVITY.md +2 -2
- package/adapters/antigravity/INDEX_TIER1.json +68 -61
- package/adapters/antigravity/a2a-config.template.yaml +1 -1
- package/adapters/antigravity/role-skill-index.json +21 -12
- package/adapters/claude/CLAUDE_ADAPTER.md +1 -1
- package/adapters/claude/settings.template.json +7 -3
- package/adapters/cursor/hooks.template.json +3 -1
- package/core/policies/action-boundaries.yaml +10 -1
- package/core/policies/mcp-tool-map.yaml +28 -0
- package/core/roles/README.md +1 -1
- package/core/roles/frontend-developer.md +1 -0
- package/core/roles/references/vietnam-accounting-specialist-review-checklist.md +6 -6
- package/core/roles/role-standard.md +8 -0
- package/core/roles/technical-architect.md +1 -0
- package/core/roles/vietnam-accounting-specialist.md +20 -20
- package/core/rules/code.md +11 -6
- package/core/skills/README.md +3 -2
- package/core/skills/agent/agent-memory-compaction/SKILL.md +27 -0
- package/core/skills/agent/configure-agent-commerce/SKILL.md +2 -0
- package/core/skills/agent/configure-agent-commerce/examples/ucp-commerce-manifest-and-endpoints.json +55 -0
- package/core/skills/agent/configure-agent-commerce/references/acp-ucp-agent-commerce-manifest-specs.md +66 -0
- package/core/skills/agent/manage-agent-identity/SKILL.md +2 -0
- package/core/skills/agent/manage-agent-identity/examples/agent-identity-spire-workload.yaml +72 -0
- package/core/skills/agent/manage-agent-identity/references/nhi-lifecycle-and-token-rotation.md +45 -0
- package/core/skills/ai/openrouter-task/SKILL.md +5 -5
- package/core/skills/ai-agent/context-optimization/SKILL.md +2 -0
- package/core/skills/ai-agent/context-optimization/examples/context-pruner-and-reorderer.py +85 -0
- package/core/skills/ai-agent/context-optimization/references/token-budgeting-and-attention-allocation.md +47 -0
- package/core/skills/ai-agent/memory-hygiene/SKILL.md +13 -0
- package/core/skills/ai-agent/memory-hygiene/examples/memory-audit-and-compaction-routine.py +90 -0
- package/core/skills/ai-agent/memory-hygiene/references/agent-memory-vault-spec.md +137 -0
- package/core/skills/ai-agent/memory-hygiene/references/owasp-asi06-and-memory-poisoning-defense.md +38 -0
- package/core/skills/backend/add-api-endpoint/examples/express-zod-rfc9457-endpoint.md +329 -0
- package/core/skills/backend/add-api-endpoint/examples/kratos-go-clean-architecture-endpoint.md +405 -0
- package/core/skills/backend/add-api-endpoint/references/idempotency-and-rate-limiting.md +116 -0
- package/core/skills/backend/add-event-handler/SKILL.md +1 -1
- package/core/skills/backend/scaffold-new-service/SKILL.md +2 -1
- package/core/skills/backend/scaffold-new-service/references/deep-modules-and-seams.md +43 -0
- package/core/skills/business/elicit-requirements/SKILL.md +1 -0
- package/core/skills/commerce/handle-checkout-flow/SKILL.md +3 -1
- package/core/skills/commerce/handle-checkout-flow/examples/production-checkout-orchestrator.ts +185 -0
- package/core/skills/commerce/handle-checkout-flow/references/pci-dss-v4-and-agentic-checkout-specs.md +72 -0
- package/core/skills/commerce/integrate-payment-gateway/SKILL.md +3 -1
- package/core/skills/commerce/integrate-payment-gateway/examples/resilient-webhook-and-mpp-handler.ts +164 -0
- package/core/skills/commerce/integrate-payment-gateway/references/mpp-x402-and-webhook-security-specs.md +47 -0
- package/core/skills/commerce/manage-order-fulfillment/SKILL.md +3 -1
- package/core/skills/commerce/manage-order-fulfillment/examples/temporal-fulfillment-saga.ts +104 -0
- package/core/skills/commerce/manage-order-fulfillment/references/event-sourced-fulfillment-and-carrier-webhooks.md +58 -0
- package/core/skills/commerce/manage-product-catalog/SKILL.md +3 -1
- package/core/skills/commerce/manage-product-catalog/examples/hybrid-search-and-governance-pipeline.ts +120 -0
- package/core/skills/commerce/manage-product-catalog/references/semantic-vector-catalog-and-graphrag.md +54 -0
- package/core/skills/content/write-article/SKILL.md +1 -1
- package/core/skills/document/pdf/SKILL.md +1 -0
- package/core/skills/document/pdf/references/pdf-acroforms-and-pdfplumber-specs.md +54 -0
- package/core/skills/document/pdf/scripts/check_fillable_fields.py +144 -0
- package/core/skills/document/pdf/scripts/fill_fillable_fields.py +145 -0
- package/core/skills/documentation/configure-llms-txt/SKILL.md +2 -0
- package/core/skills/documentation/configure-llms-txt/examples/canonical-llms-txt-and-full-txt.md +45 -0
- package/core/skills/documentation/configure-llms-txt/references/llms-txt-and-llms-full-txt-standard.md +37 -0
- package/core/skills/documentation/write-documentation/SKILL.md +3 -1
- package/core/skills/documentation/write-documentation/examples/microservice-production-readme-and-api-docs.md +70 -0
- package/core/skills/documentation/write-documentation/references/diataxis-framework-and-doc-standards.md +62 -0
- package/core/skills/foundation/ai-risk-assessment/SKILL.md +3 -5
- package/core/skills/foundation/ai-risk-assessment/examples/genai-system-risk-register.md +67 -0
- package/core/skills/foundation/ai-risk-assessment/references/nist-ai-rmf-and-eu-ai-act-taxonomy.md +49 -0
- package/core/skills/foundation/conduct-research/SKILL.md +1 -1
- package/core/skills/foundation/discernment-nudge/SKILL.md +1 -0
- package/core/skills/foundation/plan-technical-delivery/SKILL.md +2 -1
- package/core/skills/foundation/release-notes/SKILL.md +2 -3
- package/core/skills/foundation/release-notes/examples/enterprise-platform-release-notes.md +42 -0
- package/core/skills/foundation/release-notes/references/keep-a-changelog-and-semver-governance.md +43 -0
- package/core/skills/foundation/systematic-debugging/SKILL.md +5 -0
- package/core/skills/foundation/write-tests/examples/anti-tautological-tdd-walkthrough.md +204 -0
- package/core/skills/foundation/write-tests/examples/testcontainers-kratos-integration-test.md +186 -0
- package/core/skills/foundation/write-tests/references/contract-and-chaos-testing.md +187 -0
- package/core/skills/frontend/INDEX.json +16 -0
- package/core/skills/frontend/add-page-route/SKILL.md +3 -1
- package/core/skills/frontend/add-page-route/examples/streaming-rsc-page-with-view-transition.tsx +133 -0
- package/core/skills/frontend/add-page-route/references/rsc-routing-and-view-transitions.md +72 -0
- package/core/skills/frontend/add-ui-component/SKILL.md +3 -1
- package/core/skills/frontend/add-ui-component/examples/compound-dialog-and-form-actions.tsx +193 -0
- package/core/skills/frontend/add-ui-component/references/react19-component-standards-and-anti-slop.md +55 -0
- package/core/skills/frontend/component-composition/SKILL.md +2 -1
- package/core/skills/frontend/component-composition/examples/headless-combobox-compound-component.tsx +207 -0
- package/core/skills/frontend/frontend-testing/SKILL.md +3 -1
- package/core/skills/frontend/frontend-testing/examples/playwright-e2e-with-msw-and-axe.spec.ts +87 -0
- package/core/skills/frontend/frontend-testing/references/playwright-msw-and-a11y-testing-standards.md +78 -0
- package/core/skills/frontend/implement-ai-disclosure/SKILL.md +118 -0
- package/core/skills/frontend/implement-webmcp/SKILL.md +3 -1
- package/core/skills/frontend/implement-webmcp/examples/webmcp-provider-and-hitl-modal.tsx +163 -0
- package/core/skills/frontend/implement-webmcp/references/webmcp-architecture-and-hitl-security.md +48 -0
- package/core/skills/frontend/integrate-api-client/SKILL.md +3 -1
- package/core/skills/frontend/integrate-api-client/examples/orval-query-and-streaming-mutation.ts +102 -0
- package/core/skills/frontend/integrate-api-client/references/orval-tanstack-query-and-streaming-specs.md +57 -0
- package/core/skills/frontend/setup-design-system/SKILL.md +3 -1
- package/core/skills/frontend/setup-design-system/examples/tailwind-v4-theme-and-dtcg-tokens.css +87 -0
- package/core/skills/frontend/setup-design-system/references/tailwind-v4-oklch-and-dtcg-tokens.md +61 -0
- package/core/skills/frontend/setup-visual-regression/SKILL.md +3 -1
- package/core/skills/frontend/setup-visual-regression/examples/visual-regression-playwright.config.ts +83 -0
- package/core/skills/frontend/setup-visual-regression/references/visual-regression-docker-and-masking-specs.md +46 -0
- package/core/skills/gamedev/abstract-input-actions/SKILL.md +2 -0
- package/core/skills/gamedev/abstract-input-actions/examples/input-action-manager.ts +85 -0
- package/core/skills/gamedev/abstract-input-actions/references/action-mapping-and-analog-deadzones.md +54 -0
- package/core/skills/gamedev/architect-ecs-systems/SKILL.md +2 -0
- package/core/skills/gamedev/architect-ecs-systems/examples/bevy-flecs-combat-system.rs +73 -0
- package/core/skills/gamedev/architect-ecs-systems/references/data-oriented-design-and-archetype-ecs.md +39 -0
- package/core/skills/gamedev/author-game-ai/SKILL.md +2 -0
- package/core/skills/gamedev/author-game-ai/examples/modular-behavior-tree-ai.ts +98 -0
- package/core/skills/gamedev/author-game-ai/references/behavior-trees-and-utility-ai-curves.md +47 -0
- package/core/skills/gamedev/configure-physics-collision/SKILL.md +2 -0
- package/core/skills/gamedev/configure-physics-collision/examples/kinematic-physics-substepping.cpp +100 -0
- package/core/skills/gamedev/configure-physics-collision/references/continuous-collision-detection-and-substepping.md +50 -0
- package/core/skills/gamedev/develop-gameplay-systems/SKILL.md +2 -0
- package/core/skills/gamedev/develop-gameplay-systems/examples/kinematic-character-controller.gd +86 -0
- package/core/skills/gamedev/develop-gameplay-systems/references/deterministic-gameplay-state-machines.md +42 -0
- package/core/skills/gamedev/implement-save-persistence/SKILL.md +2 -0
- package/core/skills/gamedev/implement-save-persistence/examples/versioned-save-manager.ts +127 -0
- package/core/skills/gamedev/implement-save-persistence/references/versioned-save-schemas-and-checksums.md +44 -0
- package/core/skills/gamedev/render-webgl-threejs/SKILL.md +2 -0
- package/core/skills/gamedev/render-webgl-threejs/examples/production-threejs-webgpu-scene.ts +116 -0
- package/core/skills/gamedev/render-webgl-threejs/references/webgpu-threejs-pbr-pipeline.md +56 -0
- package/core/skills/mmo/analyze-campaign-roi/SKILL.md +2 -0
- package/core/skills/mmo/analyze-campaign-roi/examples/campaign-roi-and-roas-dashboard.py +80 -0
- package/core/skills/mmo/analyze-campaign-roi/references/multi-touch-attribution-and-cpa-analytics.md +33 -0
- package/core/skills/mmo/create-automation-script/SKILL.md +2 -0
- package/core/skills/mmo/create-automation-script/examples/stealth-browser-automation-flow.ts +65 -0
- package/core/skills/mmo/create-automation-script/references/stealth-cdp-and-behavioral-mimicry.md +37 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/SKILL.md +2 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/examples/proxy-health-probe-and-rotation-daemon.py +75 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/references/proxy-pool-rotation-and-anti-detect-specs.md +45 -0
- package/core/skills/mmo/deploy-proxyware-fleet/SKILL.md +2 -0
- package/core/skills/mmo/deploy-proxyware-fleet/examples/docker-compose-depin-light-node-fleet.yaml +52 -0
- package/core/skills/mmo/deploy-proxyware-fleet/references/depin-bandwidth-monetization-node-specs.md +43 -0
- package/core/skills/mmo/generate-mmo-content/SKILL.md +2 -0
- package/core/skills/mmo/generate-mmo-content/examples/pseo-programmatic-page-generator.ts +76 -0
- package/core/skills/mmo/generate-mmo-content/references/pseo-landing-pages-and-social-video-hooks.md +39 -0
- package/core/skills/mmo/manage-mmo-assets/SKILL.md +2 -0
- package/core/skills/mmo/manage-mmo-assets/examples/mmo-asset-vault-manager.py +63 -0
- package/core/skills/mmo/manage-mmo-assets/references/mmo-asset-rbac-and-vault-isolation.md +38 -0
- package/core/skills/mmo/setup-tracking-system/SKILL.md +2 -0
- package/core/skills/mmo/setup-tracking-system/examples/meta-capi-s2s-event-dispatcher.ts +79 -0
- package/core/skills/mmo/setup-tracking-system/references/server-to-server-postback-and-capi-specs.md +45 -0
- package/core/skills/platform/add-telemetry-instrumentation/SKILL.md +2 -0
- package/core/skills/platform/add-telemetry-instrumentation/examples/kratos-otel-middleware-instrumentation.go +87 -0
- package/core/skills/platform/add-telemetry-instrumentation/references/opentelemetry-semantic-conventions-2026.md +37 -0
- package/core/skills/platform/aws-infrastructure/SKILL.md +2 -0
- package/core/skills/platform/aws-infrastructure/examples/opentofu-eks-pod-identity-vpc.tf +101 -0
- package/core/skills/platform/aws-infrastructure/references/opentofu-aws-zero-trust-and-irsa.md +40 -0
- package/core/skills/platform/setup-deployment/SKILL.md +4 -0
- package/core/skills/platform/setup-deployment/examples/kustomize-production-service-manifests.yaml +123 -0
- package/core/skills/platform/setup-deployment/references/interactive-hitl-wizard.md +55 -0
- package/core/skills/platform/setup-deployment/references/k8s-gitops-and-kustomize-invariants.md +40 -0
- package/core/skills/platform/supply-chain-security/SKILL.md +2 -0
- package/core/skills/platform/supply-chain-security/examples/github-actions-sbom-cosign.yaml +57 -0
- package/core/skills/platform/supply-chain-security/references/slsa-provenance-and-sbom-sigstore.md +60 -0
- package/core/skills/product/build-story-map/SKILL.md +2 -0
- package/core/skills/repo-ops/review-code/SKILL.md +2 -2
- package/core/skills/repo-ops/review-code/examples/adversarial-two-axis-pr-review.md +167 -0
- package/core/skills/repo-ops/review-code/examples/ai-vibe-slop-remediation.md +220 -0
- package/core/skills/repo-ops/review-code/references/supply-chain-and-migration-safety.md +103 -0
- package/core/skills/repo-ops/review-service/SKILL.md +1 -1
- package/core/skills/security-data/database-maintenance/SKILL.md +1 -1
- package/core/skills/security-data/manage-secrets/SKILL.md +2 -0
- package/core/skills/security-data/manage-secrets/examples/external-secrets-vault-crds.yaml +53 -0
- package/core/skills/security-data/manage-secrets/references/zero-trust-secret-rotation-and-eso.md +30 -0
- package/core/skills/security-data/manage-vietnam-accounting/SKILL.md +7 -7
- package/core/skills/security-data/prompt-injection-defense/SKILL.md +2 -0
- package/core/skills/security-data/prompt-injection-defense/examples/bounded-tool-execution-wrapper.py +78 -0
- package/core/skills/security-data/prompt-injection-defense/references/prompt-injection-taxonomy-and-delimiters.md +37 -0
- package/core/skills/security-data/reverse-engineer-binary/SKILL.md +2 -0
- package/core/skills/security-data/reverse-engineer-binary/examples/binary-triage-and-vulnerability-dossier.md +58 -0
- package/core/skills/security-data/reverse-engineer-binary/references/ghidra-radare2-and-rea-evidence-ledgers.md +43 -0
- package/core/skills/security-data/security-audit/SKILL.md +3 -1
- package/core/skills/security-data/security-audit/examples/enterprise-service-security-audit-report.md +54 -0
- package/core/skills/security-data/security-audit/references/owasp-asi-and-cvss4-threat-modeling.md +39 -0
- package/core/skills/security-data/skill-preflight-ast-check/SKILL.md +2 -0
- package/core/skills/security-data/skill-preflight-ast-check/references/ast-lethal-trifecta-and-static-vetting.md +38 -0
- package/core/skills/security-data/skill-preflight-ast-check/scripts/scan-skill-ast.py +127 -0
- package/package.json +2 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Continuous Collision Detection (CCD) & Substepping Specifications (2026)
|
|
2
|
+
|
|
3
|
+
## 1. Physics Solver Architecture & The Tunneling Problem
|
|
4
|
+
|
|
5
|
+
Discrete collision detection evaluates entity overlaps only at discrete timestep intervals $t_0, t_1, \dots$. When an object's per-tick displacement $\Delta x = v \cdot \Delta t$ exceeds its collision boundary thickness $2r$, discrete evaluation fails, resulting in "tunneling" (passing through solid obstacles without triggering collision events).
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Discrete Collision Tunneling:
|
|
9
|
+
Tick t_0: [Collider (r)] ────────► (Wall) ────────► Tick t_1: [Collider (r)]
|
|
10
|
+
(Before Wall) (Passed Through!)
|
|
11
|
+
|
|
12
|
+
Continuous Collision Detection (CCD Swept Volume):
|
|
13
|
+
Tick t_0: [=== Swept Capsule / Sphere Cast ============] (Wall)
|
|
14
|
+
Collision Time-of-Impact (TOI) Detected at t_hit!
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 2. Continuous Collision Detection Strategies
|
|
18
|
+
|
|
19
|
+
1. **Swept Sphere / Capsule Casts**:
|
|
20
|
+
- Sweeps a sphere or capsule along the entity's velocity vector $\vec{v}$.
|
|
21
|
+
- Solves for the earliest Time-of-Impact (TOI) $\tau \in [0, \Delta t]$.
|
|
22
|
+
- Caps movement at $\tau \cdot \vec{v}$ and generates contact normal at impact point.
|
|
23
|
+
2. **Speculative Contacts (Predictive Constraints)**:
|
|
24
|
+
- Extends the collision envelope by the distance covered in the upcoming tick.
|
|
25
|
+
- Adds contact constraints into the LCP solver before actual geometric penetration occurs.
|
|
26
|
+
- Prevents tunneling with lower CPU overhead than repeated swept tests.
|
|
27
|
+
|
|
28
|
+
## 3. Substepping & Spiral of Death Prevention
|
|
29
|
+
|
|
30
|
+
When a frame experiences a CPU hitch or large physics delta, the accumulator loop must not enter an infinite substepping loop:
|
|
31
|
+
```cpp
|
|
32
|
+
const float FIXED_DELTA = 1.0f / 60.0f;
|
|
33
|
+
const int MAX_SUBSTEPS = 4; // Bounded substepping ceiling
|
|
34
|
+
|
|
35
|
+
accumulator += frame_delta;
|
|
36
|
+
int steps = 0;
|
|
37
|
+
while (accumulator >= FIXED_DELTA && steps < MAX_SUBSTEPS) {
|
|
38
|
+
PhysicsWorld::StepSimulation(FIXED_DELTA);
|
|
39
|
+
accumulator -= FIXED_DELTA;
|
|
40
|
+
steps++;
|
|
41
|
+
}
|
|
42
|
+
if (accumulator >= FIXED_DELTA) {
|
|
43
|
+
accumulator = 0.0f; // Drop excess time to prevent spiral of death
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 4. Contact Normal Stabilization & Ground Snapping
|
|
48
|
+
|
|
49
|
+
- Distinguish ground from steep walls: $\cos(\theta) = \vec{n}_{\text{contact}} \cdot \vec{u}_{\text{up}} \ge \cos(\theta_{\text{max\_slope}})$.
|
|
50
|
+
- Downward raycast snap distance ($0.2\text{m}$) prevents separation bounce when descending slopes or modular floor junctions.
|
|
@@ -69,3 +69,5 @@ When completing a gameplay system implementation, emit:
|
|
|
69
69
|
- **tune-game-feel**: layered audiovisual responsiveness and timing buffers
|
|
70
70
|
- **integrate-game-engine**: engine lifecycle integration and headless runner execution
|
|
71
71
|
- **optimize-3d-assets**: mesh and texture budget conformance
|
|
72
|
+
- Companion reference: `references/deterministic-gameplay-state-machines.md`
|
|
73
|
+
- Companion example: `examples/kinematic-character-controller.gd`
|
package/core/skills/gamedev/develop-gameplay-systems/examples/kinematic-character-controller.gd
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
class_name KinematicCharacterController
|
|
2
|
+
extends CharacterBody3D
|
|
3
|
+
|
|
4
|
+
@export var move_speed: float = 6.0
|
|
5
|
+
@export var jump_impulse: float = 9.0
|
|
6
|
+
@export var gravity: float = 24.0
|
|
7
|
+
@export var acceleration: float = 40.0
|
|
8
|
+
@export var friction: float = 30.0
|
|
9
|
+
|
|
10
|
+
# State Machine definitions
|
|
11
|
+
enum State { IDLE, RUN, JUMP, FALL }
|
|
12
|
+
var current_state: State = State.IDLE
|
|
13
|
+
|
|
14
|
+
# Input Buffers & Coyote Time
|
|
15
|
+
var coyote_timer: float = 0.0
|
|
16
|
+
var jump_buffer_timer: float = 0.0
|
|
17
|
+
const COYOTE_DURATION: float = 0.12
|
|
18
|
+
const JUMP_BUFFER_DURATION: float = 0.15
|
|
19
|
+
|
|
20
|
+
func _physics_process(delta: float) -> void:
|
|
21
|
+
# Update timers
|
|
22
|
+
if is_on_floor():
|
|
23
|
+
coyote_timer = COYOTE_DURATION
|
|
24
|
+
else:
|
|
25
|
+
coyote_timer = max(0.0, coyote_timer - delta)
|
|
26
|
+
|
|
27
|
+
jump_buffer_timer = max(0.0, jump_buffer_timer - delta)
|
|
28
|
+
|
|
29
|
+
# Read Input Actions
|
|
30
|
+
var input_dir: Vector2 = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
|
31
|
+
var move_vector: Vector3 = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
32
|
+
|
|
33
|
+
if Input.is_action_just_pressed("jump"):
|
|
34
|
+
jump_buffer_timer = JUMP_BUFFER_DURATION
|
|
35
|
+
|
|
36
|
+
# State Transitions & Physics Integration
|
|
37
|
+
match current_state:
|
|
38
|
+
State.IDLE:
|
|
39
|
+
apply_horizontal_velocity(Vector3.ZERO, friction, delta)
|
|
40
|
+
if not is_on_floor() and coyote_timer <= 0.0:
|
|
41
|
+
transition_to(State.FALL)
|
|
42
|
+
elif jump_buffer_timer > 0.0 and coyote_timer > 0.0:
|
|
43
|
+
execute_jump()
|
|
44
|
+
elif move_vector.length_squared() > 0.01:
|
|
45
|
+
transition_to(State.RUN)
|
|
46
|
+
|
|
47
|
+
State.RUN:
|
|
48
|
+
apply_horizontal_velocity(move_vector * move_speed, acceleration, delta)
|
|
49
|
+
if not is_on_floor() and coyote_timer <= 0.0:
|
|
50
|
+
transition_to(State.FALL)
|
|
51
|
+
elif jump_buffer_timer > 0.0 and coyote_timer > 0.0:
|
|
52
|
+
execute_jump()
|
|
53
|
+
elif move_vector.length_squared() <= 0.01:
|
|
54
|
+
transition_to(State.IDLE)
|
|
55
|
+
|
|
56
|
+
State.JUMP:
|
|
57
|
+
velocity.y -= gravity * delta
|
|
58
|
+
apply_horizontal_velocity(move_vector * move_speed, acceleration * 0.5, delta)
|
|
59
|
+
if velocity.y <= 0.0:
|
|
60
|
+
transition_to(State.FALL)
|
|
61
|
+
|
|
62
|
+
State.FALL:
|
|
63
|
+
velocity.y -= gravity * delta
|
|
64
|
+
apply_horizontal_velocity(move_vector * move_speed, acceleration * 0.5, delta)
|
|
65
|
+
if is_on_floor():
|
|
66
|
+
if move_vector.length_squared() > 0.01:
|
|
67
|
+
transition_to(State.RUN)
|
|
68
|
+
else:
|
|
69
|
+
transition_to(State.IDLE)
|
|
70
|
+
|
|
71
|
+
move_and_slide()
|
|
72
|
+
|
|
73
|
+
func transition_to(new_state: State) -> void:
|
|
74
|
+
current_state = new_state
|
|
75
|
+
|
|
76
|
+
func execute_jump() -> void:
|
|
77
|
+
velocity.y = jump_impulse
|
|
78
|
+
coyote_timer = 0.0
|
|
79
|
+
jump_buffer_timer = 0.0
|
|
80
|
+
transition_to(State.JUMP)
|
|
81
|
+
|
|
82
|
+
func apply_horizontal_velocity(target_vel: Vector3, rate: float, delta: float) -> void:
|
|
83
|
+
var h_vel: Vector3 = Vector3(velocity.x, 0, velocity.z)
|
|
84
|
+
h_vel = h_vel.move_toward(target_vel, rate * delta)
|
|
85
|
+
velocity.x = h_vel.x
|
|
86
|
+
velocity.z = h_vel.z
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Deterministic Gameplay State Machines & Kinematics (2026)
|
|
2
|
+
|
|
3
|
+
## 1. Architectural Foundations: Fixed-Timestep Simulation
|
|
4
|
+
|
|
5
|
+
Deterministic gameplay simulation requires complete decoupling of render framerates from physics calculation:
|
|
6
|
+
|
|
7
|
+
$$\Delta t_{\text{fixed}} = \frac{1}{\text{TickRate}} \quad (\text{typically } 60\text{Hz or } 120\text{Hz})$$
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Render Frame (Variable Delta)
|
|
11
|
+
│
|
|
12
|
+
├─► Accumulator += frame_delta
|
|
13
|
+
│
|
|
14
|
+
▼
|
|
15
|
+
While Accumulator >= fixed_delta:
|
|
16
|
+
├─► Process Input Buffers
|
|
17
|
+
├─► Integrate Velocities: x_{t+1} = x_t + v_t * fixed_delta
|
|
18
|
+
├─► Resolve CCD & Kinematic Collisions
|
|
19
|
+
├─► Advance State Machine
|
|
20
|
+
└─► Accumulator -= fixed_delta
|
|
21
|
+
│
|
|
22
|
+
▼
|
|
23
|
+
Render Interpolation: alpha = Accumulator / fixed_delta
|
|
24
|
+
Render State = lerp(PreviousState, CurrentState, alpha)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 2. Hierarchical State Machine (HSM) Invariants
|
|
28
|
+
|
|
29
|
+
1. **Single Active State Invariant**: At any discrete tick $t$, an entity possesses exactly one leaf state in its state hierarchy (e.g. `Root -> Grounded -> Moving`).
|
|
30
|
+
2. **Transition Authority**: State transitions can only occur via explicit transition triggers evaluated against deterministic condition flags (e.g., `is_on_floor`, `jump_buffered`, `stamina > 0`). Direct mutation of state flags from outside callers is prohibited.
|
|
31
|
+
3. **Lifecycle Contracts**:
|
|
32
|
+
- `Enter(context)`: Pre-allocates resources, initializes timers, triggers animation events.
|
|
33
|
+
- `PhysicsUpdate(delta)`: Evaluates motion vector, applies gravity, triggers collision queries.
|
|
34
|
+
- `Exit()`: Resets timers, clears transient buffers, cancels incomplete actions.
|
|
35
|
+
|
|
36
|
+
## 3. Kinematic Motion & Collision Handling
|
|
37
|
+
|
|
38
|
+
- **Ground Contact Snapping**: Snap character to slopes within the maximum slope angle ($\theta \le 45^\circ$) to prevent airborne jitter when descending.
|
|
39
|
+
- **Coyote Time & Input Buffering**:
|
|
40
|
+
- Coyote Time: Grace window (e.g., $100\text{ms}$) permitting jump initiation after walking off an edge.
|
|
41
|
+
- Jump Buffering: Queue jump inputs received within $150\text{ms}$ before landing on ground.
|
|
42
|
+
- **Zero-Allocation Spatial Queries**: Pre-allocate raycast hit arrays and query shapes. Never instantiate temporary vector arrays or lambda closures in the fixed loop.
|
|
@@ -82,3 +82,5 @@ When completing save persistence implementation, emit:
|
|
|
82
82
|
- **manage-scene-lifecycle**: hydrating and persisting scene state across level transitions
|
|
83
83
|
- **integrate-game-engine**: configuring platform user directories and headless test runners
|
|
84
84
|
- **integrate-dialogue-narrative**: persisting narrative condition flags and branching choices
|
|
85
|
+
- Companion reference: `references/versioned-save-schemas-and-checksums.md`
|
|
86
|
+
- Companion example: `examples/versioned-save-manager.ts`
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as crypto from 'crypto';
|
|
4
|
+
|
|
5
|
+
export interface SaveEnvelope<T> {
|
|
6
|
+
magic: string;
|
|
7
|
+
schemaVersion: number;
|
|
8
|
+
timestampUtc: number;
|
|
9
|
+
playtimeSeconds: number;
|
|
10
|
+
checksumSha256: string;
|
|
11
|
+
payload: T;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type MigrationStep = (oldPayload: any) => any;
|
|
15
|
+
|
|
16
|
+
export class VersionedSaveManager {
|
|
17
|
+
private readonly currentVersion: number;
|
|
18
|
+
private readonly migrations: Map<number, MigrationStep> = new Map();
|
|
19
|
+
private readonly saveDirectory: string;
|
|
20
|
+
|
|
21
|
+
constructor(saveDir: string, currentVersion: number) {
|
|
22
|
+
this.saveDirectory = saveDir;
|
|
23
|
+
this.currentVersion = currentVersion;
|
|
24
|
+
if (!fs.existsSync(saveDir)) {
|
|
25
|
+
fs.mkdirSync(saveDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public registerMigration(fromVersion: number, step: MigrationStep) {
|
|
30
|
+
this.migrations.set(fromVersion, step);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private computeChecksum(payload: any): string {
|
|
34
|
+
const serialized = JSON.stringify(payload);
|
|
35
|
+
return crypto.createHash('sha256').update(serialized).digest('hex');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public saveSlot(slotName: string, payload: any, playtimeSeconds: number) {
|
|
39
|
+
// Sanitize slot name against path traversal
|
|
40
|
+
if (!/^[a-zA-Z0-9_-]{1,32}$/.test(slotName)) {
|
|
41
|
+
throw new Error(`Invalid slot name: ${slotName}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const envelope: SaveEnvelope<any> = {
|
|
45
|
+
magic: 'GMSV',
|
|
46
|
+
schemaVersion: this.currentVersion,
|
|
47
|
+
timestampUtc: Math.floor(Date.now() / 1000),
|
|
48
|
+
playtimeSeconds,
|
|
49
|
+
checksumSha256: this.computeChecksum(payload),
|
|
50
|
+
payload,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const targetFile = path.join(this.saveDirectory, `${slotName}.sav`);
|
|
54
|
+
const tempFile = path.join(this.saveDirectory, `${slotName}.sav.tmp`);
|
|
55
|
+
const backupFile = path.join(this.saveDirectory, `${slotName}.sav.bak`);
|
|
56
|
+
|
|
57
|
+
// 1. Write to temp file
|
|
58
|
+
fs.writeFileSync(tempFile, JSON.stringify(envelope, null, 2), 'utf-8');
|
|
59
|
+
|
|
60
|
+
// 2. Backup existing save if present
|
|
61
|
+
if (fs.existsSync(targetFile)) {
|
|
62
|
+
fs.copyFileSync(targetFile, backupFile);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 3. Atomic rename
|
|
66
|
+
fs.renameSync(tempFile, targetFile);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public loadSlot(slotName: string): any {
|
|
70
|
+
const targetFile = path.join(this.saveDirectory, `${slotName}.sav`);
|
|
71
|
+
const backupFile = path.join(this.saveDirectory, `${slotName}.sav.bak`);
|
|
72
|
+
|
|
73
|
+
let raw: string;
|
|
74
|
+
try {
|
|
75
|
+
raw = fs.readFileSync(targetFile, 'utf-8');
|
|
76
|
+
} catch {
|
|
77
|
+
if (fs.existsSync(backupFile)) {
|
|
78
|
+
console.warn(`Primary save missing for ${slotName}. Falling back to .bak.`);
|
|
79
|
+
raw = fs.readFileSync(backupFile, 'utf-8');
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error(`Save slot not found: ${slotName}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const envelope: SaveEnvelope<any> = JSON.parse(raw);
|
|
86
|
+
|
|
87
|
+
// Verify magic bytes
|
|
88
|
+
if (envelope.magic !== 'GMSV') {
|
|
89
|
+
throw new Error('Invalid save envelope magic bytes');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Verify payload integrity checksum
|
|
93
|
+
const computed = this.computeChecksum(envelope.payload);
|
|
94
|
+
if (computed !== envelope.checksumSha256) {
|
|
95
|
+
if (fs.existsSync(backupFile)) {
|
|
96
|
+
console.warn('Checksum failure! Recovering from .bak.');
|
|
97
|
+
return this.loadSlotFromPath(backupFile);
|
|
98
|
+
}
|
|
99
|
+
throw new Error('Corrupted save payload: checksum mismatch');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Run sequential migrations if save is older
|
|
103
|
+
let currentPayload = envelope.payload;
|
|
104
|
+
let version = envelope.schemaVersion;
|
|
105
|
+
|
|
106
|
+
if (version > this.currentVersion) {
|
|
107
|
+
throw new Error(`Save version ${version} is newer than game engine version ${this.currentVersion}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
while (version < this.currentVersion) {
|
|
111
|
+
const step = this.migrations.get(version);
|
|
112
|
+
if (!step) {
|
|
113
|
+
throw new Error(`Missing migration step for schema version ${version} -> ${version + 1}`);
|
|
114
|
+
}
|
|
115
|
+
currentPayload = step(currentPayload);
|
|
116
|
+
version++;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return currentPayload;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private loadSlotFromPath(filePath: string): any {
|
|
123
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
124
|
+
const envelope: SaveEnvelope<any> = JSON.parse(raw);
|
|
125
|
+
return envelope.payload;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Versioned Save Schemas & Checksum Integrity (2026)
|
|
2
|
+
|
|
3
|
+
## 1. Architectural Foundations: Fault-Tolerant Persistence
|
|
4
|
+
|
|
5
|
+
Game save persistence must withstand sudden hardware power loss, process termination, disk corruption, and patch-induced schema evolution:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌────────────────────────────────────────────────────────┐
|
|
9
|
+
│ SAVE ENVELOPE │
|
|
10
|
+
├────────────────────┬───────────────────────────────────┤
|
|
11
|
+
│ magic_bytes │ "GMSV" (4 bytes) │
|
|
12
|
+
│ schema_version │ uint32 (e.g. 3) │
|
|
13
|
+
│ timestamp_utc │ uint64 (epoch seconds) │
|
|
14
|
+
│ playtime_seconds │ uint32 │
|
|
15
|
+
│ payload_sha256 │ hex string (64 characters) │
|
|
16
|
+
├────────────────────┴───────────────────────────────────┤
|
|
17
|
+
│ SERIALIZED PAYLOAD │
|
|
18
|
+
│ (JSON in dev / MessagePack or FlatBuffers in prod) │
|
|
19
|
+
│ { player: { hp: 100, pos: [...] }, inventory: [...] } │
|
|
20
|
+
└────────────────────────────────────────────────────────┘
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 2. Monotonic Step-by-Step Migration Pipeline
|
|
24
|
+
|
|
25
|
+
When a save file with version $N$ is loaded by a game build expecting version $M$ ($M > N$):
|
|
26
|
+
- Direct multi-version jumps ($N \to M$) are prohibited.
|
|
27
|
+
- The loader executes sequential, composable transforms:
|
|
28
|
+
$$N \xrightarrow{\text{migrate}_{N\to N+1}} N+1 \xrightarrow{\text{migrate}_{N+1\to N+2}} \dots \xrightarrow{\text{migrate}_{M-1\to M}} M$$
|
|
29
|
+
- Invariants are verified after each individual transform step.
|
|
30
|
+
- If $N > M$ (save from a newer patch), the save is rejected safely to prevent forward-incompatible corruption.
|
|
31
|
+
|
|
32
|
+
## 3. Transactional Write-and-Swap (Atomic Persistence)
|
|
33
|
+
|
|
34
|
+
Direct overwriting of active save files causes data loss on crash:
|
|
35
|
+
1. Serialize envelope and payload to `.tmp` file (`slot_0.sav.tmp`).
|
|
36
|
+
2. Flush OS file buffers using `fsync` / `flush()`.
|
|
37
|
+
3. If valid previous save exists (`slot_0.sav`), copy to `slot_0.sav.bak`.
|
|
38
|
+
4. Atomically rename `slot_0.sav.tmp` to `slot_0.sav`.
|
|
39
|
+
5. On load failure (corrupted checksum or truncated bytes), auto-recover from `.bak`.
|
|
40
|
+
|
|
41
|
+
## 4. Cross-Platform Cloud Storage Invariants
|
|
42
|
+
|
|
43
|
+
- Cloud conflict resolution prioritizes `max(timestamp_utc)` with `playtime_seconds` as tiebreaker.
|
|
44
|
+
- Slot identifiers must be sanitized: `^[a-zA-Z0-9_-]{1,32}$` to prevent directory traversal attacks (`../../etc/passwd`).
|
|
@@ -79,3 +79,5 @@ When completing WebGL and Three.js rendering implementation, emit:
|
|
|
79
79
|
|
|
80
80
|
- **program-game-shaders**: custom GLSL vertex/fragment shaders and post-processing effects
|
|
81
81
|
- **profile-game-performance**: WebGL/WebGPU draw call batching and VRAM disposal profiling
|
|
82
|
+
- Companion reference: `references/webgpu-threejs-pbr-pipeline.md`
|
|
83
|
+
- Companion example: `examples/production-threejs-webgpu-scene.ts`
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
3
|
+
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
4
|
+
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js';
|
|
5
|
+
|
|
6
|
+
export interface SceneConfig {
|
|
7
|
+
canvas: HTMLCanvasElement;
|
|
8
|
+
dracoPath: string;
|
|
9
|
+
basisTranscoderPath: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ProductionWebGPUScene {
|
|
13
|
+
private renderer!: THREE.WebGLRenderer;
|
|
14
|
+
private scene: THREE.Scene;
|
|
15
|
+
private camera: THREE.PerspectiveCamera;
|
|
16
|
+
private animationFrameId: number | null = null;
|
|
17
|
+
private gltfLoader: GLTFLoader;
|
|
18
|
+
|
|
19
|
+
constructor(config: SceneConfig) {
|
|
20
|
+
this.scene = new THREE.Scene();
|
|
21
|
+
this.camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
22
|
+
this.camera.position.set(0, 2, 5);
|
|
23
|
+
|
|
24
|
+
// Initialize renderer with clamped DPR and sRGB ACESFilmic tone mapping
|
|
25
|
+
this.renderer = new THREE.WebGLRenderer({
|
|
26
|
+
canvas: config.canvas,
|
|
27
|
+
antialias: true,
|
|
28
|
+
powerPreference: 'high-performance',
|
|
29
|
+
});
|
|
30
|
+
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
31
|
+
this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
32
|
+
this.renderer.toneMappingExposure = 1.0;
|
|
33
|
+
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2.0));
|
|
34
|
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
35
|
+
|
|
36
|
+
// Setup asset loaders with worker decoders
|
|
37
|
+
const dracoLoader = new DRACOLoader();
|
|
38
|
+
dracoLoader.setDecoderPath(config.dracoPath);
|
|
39
|
+
|
|
40
|
+
const ktx2Loader = new KTX2Loader();
|
|
41
|
+
ktx2Loader.setTranscoderPath(config.basisTranscoderPath);
|
|
42
|
+
ktx2Loader.detectSupport(this.renderer);
|
|
43
|
+
|
|
44
|
+
this.gltfLoader = new GLTFLoader();
|
|
45
|
+
this.gltfLoader.setDRACOLoader(dracoLoader);
|
|
46
|
+
this.gltfLoader.setKTX2Loader(ktx2Loader);
|
|
47
|
+
|
|
48
|
+
// Setup WebGL Context Loss Handlers
|
|
49
|
+
config.canvas.addEventListener('webglcontextlost', this.onContextLost, false);
|
|
50
|
+
config.canvas.addEventListener('webglcontextrestored', this.onContextRestored, false);
|
|
51
|
+
|
|
52
|
+
window.addEventListener('resize', this.onResize);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private onContextLost = (e: Event) => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
if (this.animationFrameId !== null) {
|
|
58
|
+
cancelAnimationFrame(this.animationFrameId);
|
|
59
|
+
this.animationFrameId = null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
private onContextRestored = () => {
|
|
64
|
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
65
|
+
this.startRenderLoop();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
private onResize = () => {
|
|
69
|
+
this.camera.aspect = window.innerWidth / window.innerHeight;
|
|
70
|
+
this.camera.updateProjectionMatrix();
|
|
71
|
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
public async loadAsset(url: string): Promise<THREE.Group> {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
this.gltfLoader.load(
|
|
77
|
+
url,
|
|
78
|
+
(gltf) => {
|
|
79
|
+
this.scene.add(gltf.scene);
|
|
80
|
+
resolve(gltf.scene);
|
|
81
|
+
},
|
|
82
|
+
undefined,
|
|
83
|
+
(error) => reject(error)
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public startRenderLoop() {
|
|
89
|
+
const render = () => {
|
|
90
|
+
this.renderer.render(this.scene, this.camera);
|
|
91
|
+
this.animationFrameId = requestAnimationFrame(render);
|
|
92
|
+
};
|
|
93
|
+
render();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public dispose() {
|
|
97
|
+
if (this.animationFrameId !== null) {
|
|
98
|
+
cancelAnimationFrame(this.animationFrameId);
|
|
99
|
+
}
|
|
100
|
+
window.removeEventListener('resize', this.onResize);
|
|
101
|
+
|
|
102
|
+
// Deep GPU disposal
|
|
103
|
+
this.scene.traverse((object) => {
|
|
104
|
+
if (object instanceof THREE.Mesh) {
|
|
105
|
+
object.geometry?.dispose();
|
|
106
|
+
if (Array.isArray(object.material)) {
|
|
107
|
+
object.material.forEach((m) => m.dispose());
|
|
108
|
+
} else {
|
|
109
|
+
object.material?.dispose();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
this.renderer.dispose();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# WebGPU & Three.js PBR Rendering Pipeline Specification (2026)
|
|
2
|
+
|
|
3
|
+
## 1. WebGPU / WebGL2 Dual Architecture
|
|
4
|
+
|
|
5
|
+
Modern browser 3D applications implement WebGPU as primary hardware abstraction with transparent WebGL2 fallback:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Device Initialization
|
|
9
|
+
│
|
|
10
|
+
┌───────────────┴───────────────┐
|
|
11
|
+
▼ ▼
|
|
12
|
+
navigator.gpu exists? Fall back to WebGL2
|
|
13
|
+
│ │
|
|
14
|
+
WebGPURenderer WebGLRenderer
|
|
15
|
+
(Compute shaders, BindGroups) (VAOs, Multi-Draw indirect)
|
|
16
|
+
│ │
|
|
17
|
+
└───────────────┬───────────────┘
|
|
18
|
+
▼
|
|
19
|
+
SRGBColorSpace + ACESFilmic
|
|
20
|
+
▼
|
|
21
|
+
DRACO / Meshopt + KTX2 VRAM
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 2. Asset Compression & VRAM Residency
|
|
25
|
+
|
|
26
|
+
1. **Geometry Compression**:
|
|
27
|
+
- Draco: High compression ratio for static environment meshes.
|
|
28
|
+
- Meshopt: Fast GPU-friendly decoding for dynamic, animated skeletal meshes.
|
|
29
|
+
2. **Texture Compression**:
|
|
30
|
+
- KTX2 / Basis Universal: Transcoded on Web Workers directly into GPU-native formats (ASTC, BC7, ETC2).
|
|
31
|
+
- Zero CPU decompression into uncompressed RGBA8 textures, slashing mobile VRAM usage by 75%.
|
|
32
|
+
3. **ORM Texture Packing**:
|
|
33
|
+
- Single texture combining Occlusion (R), Roughness (G), Metalness (B) channels to eliminate redundant samplers.
|
|
34
|
+
|
|
35
|
+
## 3. Draw Call Optimization & Instancing
|
|
36
|
+
|
|
37
|
+
- **`THREE.InstancedMesh`**: Mandated for repetitive dynamic entities (projectiles, enemies, coins).
|
|
38
|
+
- **`THREE.BatchedMesh`**: Merges dissimilar static geometries with identical materials into single MultiDrawIndirect submissions.
|
|
39
|
+
- **Frustum & Occlusion Culling**: Compute-based hierarchical Z-buffer occlusion culling for complex scenes.
|
|
40
|
+
|
|
41
|
+
## 4. Deterministic GPU Resource Lifecycle
|
|
42
|
+
|
|
43
|
+
JavaScript garbage collection does not clean GPU allocations. The unmount protocol requires:
|
|
44
|
+
```typescript
|
|
45
|
+
function disposeHierarchy(node: THREE.Object3D) {
|
|
46
|
+
if (node instanceof THREE.Mesh) {
|
|
47
|
+
node.geometry.dispose();
|
|
48
|
+
if (Array.isArray(node.material)) {
|
|
49
|
+
node.material.forEach((m) => disposeMaterial(m));
|
|
50
|
+
} else {
|
|
51
|
+
disposeMaterial(node.material);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
All texture maps, render targets, and compute pipelines must execute `.dispose()`.
|
|
@@ -132,3 +132,5 @@ Skip emission for single-campaign one-off queries that do not cross role boundar
|
|
|
132
132
|
|
|
133
133
|
- **setup-tracking-system**: Configure the S2S and postback tracking architecture analyzed by this skill.
|
|
134
134
|
- **analyze-data**: Perform exploratory statistical and cohort data analysis outside MMO performance contexts.
|
|
135
|
+
- Companion reference: `references/multi-touch-attribution-and-cpa-analytics.md`
|
|
136
|
+
- Companion example: `examples/campaign-roi-and-roas-dashboard.py`
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Campaign ROI and Blended ROAS Analytics Dashboard (2026).
|
|
3
|
+
|
|
4
|
+
Calculates True ROI incorporating operational overhead, proxy costs,
|
|
5
|
+
account die-rate attrition, and 90-day LTV cohort retention projections.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Dict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class CampaignFinancials:
|
|
14
|
+
ad_spend: float
|
|
15
|
+
direct_revenue: float
|
|
16
|
+
rebill_revenue: float
|
|
17
|
+
tier2_override_rate: float
|
|
18
|
+
milestone_bonus: float
|
|
19
|
+
proxy_cost: float
|
|
20
|
+
api_token_cost: float
|
|
21
|
+
active_accounts: int
|
|
22
|
+
account_die_rate: float
|
|
23
|
+
account_replace_cost: float
|
|
24
|
+
clawback_reserve_rate: float
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CampaignAnalyticsEngine:
|
|
28
|
+
def evaluate(self, fin: CampaignFinancials) -> Dict[str, float]:
|
|
29
|
+
# Revenue aggregation
|
|
30
|
+
tier2_revenue = fin.direct_revenue * fin.tier2_override_rate
|
|
31
|
+
gross_revenue = fin.direct_revenue + fin.rebill_revenue + tier2_revenue + fin.milestone_bonus
|
|
32
|
+
|
|
33
|
+
# Operational costs
|
|
34
|
+
replacement_costs = fin.active_accounts * fin.account_die_rate * fin.account_replace_cost
|
|
35
|
+
clawback_escrow = gross_revenue * fin.clawback_reserve_rate
|
|
36
|
+
|
|
37
|
+
total_operational_cost = (
|
|
38
|
+
fin.ad_spend + fin.proxy_cost + fin.api_token_cost + replacement_costs + clawback_escrow
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
true_net_profit = gross_revenue - total_operational_cost
|
|
42
|
+
true_roi = true_net_profit / total_operational_cost if total_operational_cost > 0 else 0.0
|
|
43
|
+
|
|
44
|
+
blended_roas = gross_revenue / fin.ad_spend if fin.ad_spend > 0 else 0.0
|
|
45
|
+
mer = gross_revenue / total_operational_cost if total_operational_cost > 0 else 0.0
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
"gross_revenue": gross_revenue,
|
|
49
|
+
"total_cost": total_operational_cost,
|
|
50
|
+
"true_net_profit": true_net_profit,
|
|
51
|
+
"true_roi": true_roi,
|
|
52
|
+
"blended_roas": blended_roas,
|
|
53
|
+
"mer": mer,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
engine = CampaignAnalyticsEngine()
|
|
59
|
+
sample_data = CampaignFinancials(
|
|
60
|
+
ad_spend=10000.0,
|
|
61
|
+
direct_revenue=22000.0,
|
|
62
|
+
rebill_revenue=7500.0,
|
|
63
|
+
tier2_override_rate=0.05,
|
|
64
|
+
milestone_bonus=1500.0,
|
|
65
|
+
proxy_cost=350.0,
|
|
66
|
+
api_token_cost=120.0,
|
|
67
|
+
active_accounts=20,
|
|
68
|
+
account_die_rate=0.10,
|
|
69
|
+
account_replace_cost=40.0,
|
|
70
|
+
clawback_reserve_rate=0.03,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
metrics = engine.evaluate(sample_data)
|
|
74
|
+
print("Campaign Financial Analysis:")
|
|
75
|
+
print(f" Gross Revenue: ${metrics['gross_revenue']:.2f}")
|
|
76
|
+
print(f" Total Cost: ${metrics['total_cost']:.2f}")
|
|
77
|
+
print(f" True Net Profit: ${metrics['true_net_profit']:.2f}")
|
|
78
|
+
print(f" True ROI: {metrics['true_roi']:.2%}")
|
|
79
|
+
print(f" Blended ROAS: {metrics['blended_roas']:.2f}x")
|
|
80
|
+
print(f" MER: {metrics['mer']:.2f}x")
|
package/core/skills/mmo/analyze-campaign-roi/references/multi-touch-attribution-and-cpa-analytics.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Multi-Touch Attribution & True ROI Analytics (2026)
|
|
2
|
+
|
|
3
|
+
## 1. True ROI Financial Modeling
|
|
4
|
+
|
|
5
|
+
In high-velocity performance marketing, raw advertising ROAS ($\text{Revenue} / \text{AdSpend}$) distorts financial health by ignoring operational friction. True ROI aggregates all cost vectors:
|
|
6
|
+
|
|
7
|
+
$$\text{True Cost} = \text{AdSpend} + \text{ProxyBandwidth} + \text{AI\_API\_Tokens} + (\text{AccountDieRate} \times \text{ReplaceCost}) + \text{ClawbackEscrow}$$
|
|
8
|
+
|
|
9
|
+
$$\text{True Net Profit} = \text{GrossRevenue} - \text{True Cost}$$
|
|
10
|
+
|
|
11
|
+
$$\text{True ROI} = \frac{\text{True Net Profit}}{\text{True Cost}}$$
|
|
12
|
+
|
|
13
|
+
## 2. LTV Cohort Retention Curves (Day 30/60/90)
|
|
14
|
+
|
|
15
|
+
For recurring subscription and trial offers, evaluating single-day CPA causes premature abandonment of profitable funnels:
|
|
16
|
+
- $\text{LTV}_{30} = \text{CPA}_0 + (r_1 \cdot V_{\text{rebill}})$
|
|
17
|
+
- $\text{LTV}_{60} = \text{LTV}_{30} + (r_2 \cdot V_{\text{rebill}})$
|
|
18
|
+
- $\text{LTV}_{90} = \text{LTV}_{60} + (r_3 \cdot V_{\text{rebill}})$
|
|
19
|
+
|
|
20
|
+
Where $r_i$ represents the retention probability of the cohort at month $i$, and $V_{\text{rebill}}$ is the subscription net payout.
|
|
21
|
+
|
|
22
|
+
## 3. Blended ROAS & Marketing Efficiency Ratio (MER)
|
|
23
|
+
|
|
24
|
+
- **Blended ROAS**: $\frac{\text{Total Net Revenue}}{\text{Total Ad Spend Across All Channels}}$
|
|
25
|
+
- **Marketing Efficiency Ratio (MER)**: $\frac{\text{Total Net Revenue}}{\text{Total Marketing \& Operational Expenses}}$
|
|
26
|
+
- Reconciles dark social conversions, iOS 18+ modeled attributions (AdAttributionKit), and delayed cross-device paths.
|
|
27
|
+
|
|
28
|
+
## 4. Multi-Tier Affiliate Economics & Clawback Reserves
|
|
29
|
+
|
|
30
|
+
- **Tier 1**: Direct payout per acquisition ($CPA$).
|
|
31
|
+
- **Tier 2**: Master affiliate override percentage ($3\% \text{--} 10\%$).
|
|
32
|
+
- **Volume Milestones**: Tiered bonuses paid when monthly conversion volume crosses contractual thresholds.
|
|
33
|
+
- **Clawback Escrow**: Maintain $3\% \text{--} 5\%$ reserve deduction against chargebacks and affiliate network refund audits.
|
|
@@ -137,3 +137,5 @@ Skip emission for local scratch testing of browser selectors.
|
|
|
137
137
|
|
|
138
138
|
- **deploy-mmo-infrastructure**: Provision and manage the Anti-Detect Browser profiles and proxy networks that scripts connect to.
|
|
139
139
|
- **turnstile-spin**: Handle Cloudflare Turnstile deployment and verification challenges in automation pipelines.
|
|
140
|
+
- Companion reference: `references/stealth-cdp-and-behavioral-mimicry.md`
|
|
141
|
+
- Companion example: `examples/stealth-browser-automation-flow.ts`
|