@uptimizr/unreal 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions for
125
+ use, reproduction, or distribution of Your modifications, or for any
126
+ such Derivative Works as a whole, provided Your use, reproduction,
127
+ and distribution of the Work otherwise complies with the conditions
128
+ stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Uptimizr Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @uptimizr/unreal
2
+
3
+ The **Unreal Engine (web export)** connector for Uptimizr (ADR 0045). Unreal renders
4
+ into a `<canvas>` via WebAssembly, so there is no live JS scene to read — this
5
+ connector is built on [`@uptimizr/web-export`](../web-export) and works in **two
6
+ tiers**:
7
+
8
+ | Tier | Engine code? | Captures |
9
+ | ----------- | ----------------------------------------------- | --------------------------------------------------------------- |
10
+ | **JS-only** | none | pointer move/click heatmaps, FPS / long frames, JS errors |
11
+ | **Bridged** | a thin copy-in shim (see [`bridge/`](./bridge)) | camera pose → view-direction heatmap, world-space picks, replay |
12
+
13
+ > **Best-effort.** Unreal's first-party web export is community-maintained, so the
14
+ > bridged tier is best-effort by design (ADR 0045). The JS-only tier always works.
15
+
16
+ Unreal's native world frame is **left-handed, z-up, centimeters**, so the connector
17
+ rebases **z-up → y-up**, converts **cm → m**, and reaches the canonical wire frame
18
+ (left-handed, y-up, unit scale 1 — ADR 0018). The engine-side shim does **no**
19
+ coordinate math — it pushes raw Unreal values.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @uptimizr/unreal
25
+ ```
26
+
27
+ The engine-side bridge is a **copy-in asset** (Emscripten `EM_JS` glue), not an npm
28
+ dependency — see [`bridge/`](./bridge).
29
+
30
+ ## Usage
31
+
32
+ ```ts
33
+ import { trackUnreal } from "@uptimizr/unreal";
34
+
35
+ const { client, bridge } = trackUnreal({
36
+ projectId: "your-project",
37
+ endpoint: "https://collect.example.com",
38
+ canvas: () => document.querySelector("#unreal-canvas"),
39
+ });
40
+
41
+ // ... later, on teardown
42
+ await client.stop("manual");
43
+ ```
44
+
45
+ `trackUnreal` creates the client, registers the JS-only tier collector, exposes the
46
+ engine `bridge` (default `window.__uptimizr_unreal__`), and starts the session with
47
+ Unreal's connector provenance. The JS-only tier captures immediately; wire the
48
+ engine-side shim to `bridge` to add camera pose, picks, and replay.
49
+
50
+ ### Advanced: wire it up yourself
51
+
52
+ ```ts
53
+ import { UptimizrClient } from "@uptimizr/sdk-core";
54
+ import { unrealCollector, UNREAL_FRAME } from "@uptimizr/unreal";
55
+
56
+ const client = new UptimizrClient({ projectId: "your-project", endpoint: "..." });
57
+ client.use(unrealCollector({ canvas: () => document.querySelector("#unreal-canvas") }));
58
+ client.start();
59
+ ```
60
+
61
+ ## Engine-side bridge
62
+
63
+ The bridged tier needs a thin copy-in shim that pushes world-space pose / picks / FPS
64
+ across Unreal's Emscripten glue. The contract and an `EM_JS` sketch live in
65
+ [`bridge/README.md`](./bridge/README.md). The full shim is authored in the Unreal
66
+ web-export sub-issue (umbrella #111).
67
+
68
+ ## Privacy
69
+
70
+ No client-side persistent IDs and no PII by default (ADR 0003). `client.stop()` tears
71
+ down every listener, timer, and animation-frame callback.
72
+
73
+ ## License
74
+
75
+ Apache-2.0.
@@ -0,0 +1,106 @@
1
+ # Unreal engine-side bridge (copy-in asset)
2
+
3
+ > **Status: shim provided, best-effort.** This folder ships the actual Emscripten
4
+ > shim — [`Uptimizr.h`](./Uptimizr.h) + [`Uptimizr.cpp`](./Uptimizr.cpp) — that
5
+ > pushes camera pose / world-space picks / FPS over the versioned bridge. The
6
+ > **JS-only tier** (pointer heatmaps + FPS + errors) already works with **no** engine
7
+ > code; this shim adds the 3D-native (bridged) tier.
8
+
9
+ ## What the shim is
10
+
11
+ A small, dumb shim that ships as a **copy-in asset** (not an npm package) and pushes
12
+ per-sample telemetry from an Unreal web export across the JS interop boundary to the
13
+ browser-side `@uptimizr/unreal` connector. It carries **no** analytics logic, IDs, or
14
+ schema knowledge (ADR 0045). It performs **no** coordinate math — it pushes Unreal's
15
+ RAW world-space values and the connector owns the single normalization path.
16
+
17
+ ## Feasibility — which web targets this works on (issue #112)
18
+
19
+ Epic has **no official UE5 HTML5/WASM target** (it was deprecated after UE 4.24), and
20
+ Pixel Streaming is **server-side** rendering (no client WASM scene to read), so neither
21
+ fits this model. The shim instead targets the real, **Emscripten-based, client-side**
22
+ web exports that render into a `<canvas>` and expose the `EM_JS` / `cwrap` interop seam:
23
+
24
+ | Target | UE versions | Renderer | Status |
25
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------------- | -------------------- |
26
+ | Community HTML5 forks ([ufna/UE-HTML5](https://github.com/ufna/UE-HTML5), [SpeculativeCoder/UnrealEngine-HTML5-ES3](https://github.com/SpeculativeCoder/UnrealEngine-HTML5-ES3)) | 4.24–4.27 | WebGL2 | community-maintained |
27
+ | [Wonder Interactive / SimplyStream](https://wonderinteractive.com/) | 5.1–5.4 | WASM + WebGPU | experimental |
28
+
29
+ Both are Emscripten, so the `EM_JS` / `cwrap` glue below is available by construction.
30
+ Because every viable target is experimental or community-maintained, the **bridged tier
31
+ is best-effort by design** (ADR 0045); the JS-only tier always works. Outside Emscripten
32
+ (e.g. the desktop editor) every entry point compiles to a no-op, so the shim is safe to
33
+ leave wired in across all your build targets.
34
+
35
+ ## The JS API the shim calls
36
+
37
+ The connector exposes an `EngineBridge` on `window.__uptimizr_unreal__` (configurable via
38
+ the `bridgeGlobal` option). **All values are world-space in Unreal's native frame**
39
+ (left-handed, **z-up**, **centimeters**); the connector rebases z-up → y-up, converts
40
+ cm → m, and reaches the canonical wire frame, then emits the schema events — the shim does
41
+ **no** coordinate math.
42
+
43
+ ```ts
44
+ interface EngineBridge {
45
+ readonly protocolVersion: number; // assert against UPTIMIZR_BRIDGE_PROTOCOL_VERSION (1)
46
+ pushPose(position: [x, y, z], forward: [x, y, z], up: [x, y, z], fov?: number): void;
47
+ pushPick(objectName: string, hitPoint: [x, y, z]): void;
48
+ pushPerf(fps: number, longFrames?: number): void;
49
+ setSceneProxy(nodes: { name: string; aabb: [minX, minY, minZ, maxX, maxY, maxZ] }[]): void;
50
+ dispose(): void;
51
+ }
52
+ ```
53
+
54
+ ## Wiring it in
55
+
56
+ 1. Copy `Uptimizr.h` + `Uptimizr.cpp` into your project's `Source/<Module>/` (or a
57
+ plugin), so they build with your **web** target.
58
+ 2. Load `@uptimizr/unreal` in the export's host page and call `trackUnreal({...})` (or
59
+ register `unrealCollector()`), which attaches the bridge to `window.__uptimizr_unreal__`.
60
+ 3. Once both are up, initialize the sampler. `Initialize()` reads the live bridge's
61
+ `protocolVersion` and **asserts it equals `UPTIMIZR_BRIDGE_PROTOCOL_VERSION` (1)** —
62
+ it stays disabled on a mismatch rather than push against an incompatible API. Drive it
63
+ from C++:
64
+
65
+ ```cpp
66
+ #include "Uptimizr.h"
67
+
68
+ // once, after the page + connector are ready:
69
+ UptimizrTelemetry().Initialize();
70
+
71
+ // every frame (e.g. from an AActor::Tick or a UActorComponent::TickComponent):
72
+ UptimizrTelemetry().Tick(GetWorld(), DeltaSeconds);
73
+
74
+ // from your own click/interaction handler (or let it line-trace for you):
75
+ UptimizrTelemetry().TraceAndReportPick(GetWorld());
76
+ ```
77
+
78
+ …or drive `Init` / `Shutdown` from JS by symbol via `cwrap`
79
+ (`Module.cwrap('UptimizrBridge_Init', 'number', [])`).
80
+
81
+ `Tick` reads the active `APlayerCameraManager` pose and accumulates FPS, pushing a pose
82
+ every frame and a perf sample about once per second — all as **raw centimeters, z-up,
83
+ left-handed** values.
84
+
85
+ ### `EM_JS` sketch (the shim implements the full version)
86
+
87
+ ```cpp
88
+ EM_JS(void, UptimizrPushPoseJS, (double px, double py, double pz,
89
+ double fx, double fy, double fz,
90
+ double ux, double uy, double uz, double fov), {
91
+ var b = window.__uptimizr_unreal__;
92
+ if (b) b.pushPose([px, py, pz], [fx, fy, fz], [ux, uy, uz], fov);
93
+ });
94
+
95
+ // Each frame: read APlayerCameraManager location/rotation (cm, z-up) and call
96
+ // UptimizrPushPoseJS(loc.X, loc.Y, loc.Z, fwd.X, fwd.Y, fwd.Z, up.X, up.Y, up.Z, fovRad);
97
+ ```
98
+
99
+ > Pass raw Unreal values — **centimeters, z-up, left-handed**. Do **not** pre-convert;
100
+ > the connector owns the single normalization path so every engine stays consistent.
101
+
102
+ ## Privacy (ADR 0003)
103
+
104
+ The shim transmits only low-cardinality, non-PII telemetry: poses, FPS, and
105
+ developer-assigned **named** objects (the picked actor's `GetName()`). It MUST NOT invent
106
+ identifiers or forward raw input text.
@@ -0,0 +1,204 @@
1
+ // Uptimizr — Unreal Engine (web export) telemetry bridge shim implementation.
2
+ // See Uptimizr.h for the contract, feasibility notes, and privacy rules (ADR 0045 / 0003).
3
+
4
+ #include "Uptimizr.h"
5
+
6
+ #include "Camera/PlayerCameraManager.h"
7
+ #include "Engine/World.h"
8
+ #include "GameFramework/Actor.h"
9
+ #include "GameFramework/PlayerController.h"
10
+
11
+ #if defined(__EMSCRIPTEN__)
12
+ #include <emscripten/emscripten.h>
13
+
14
+ // --- C++ -> JS glue (EM_JS) -------------------------------------------------------------
15
+ //
16
+ // Each macro embeds a tiny JS body that forwards to the connector's EngineBridge on
17
+ // `window.__uptimizr_unreal__`. All numeric args are RAW Unreal world-space values; the JS
18
+ // connector does the z-up -> y-up rebase and cm -> m scale. The bridge is looked up fresh on
19
+ // every call so teardown (`dispose()` removing the global) cleanly turns pushes into no-ops.
20
+
21
+ // Returns the live bridge's protocol version, or -1 when no bridge is attached yet.
22
+ EM_JS(int, UptimizrBridgeProtocolVersionJS, (), {
23
+ var b = (typeof window !== 'undefined') ? window['__uptimizr_unreal__'] : undefined;
24
+ return (b && typeof b.protocolVersion === 'number') ? b.protocolVersion : -1;
25
+ });
26
+
27
+ EM_JS(void, UptimizrPushPoseJS,
28
+ (double px, double py, double pz,
29
+ double fx, double fy, double fz,
30
+ double ux, double uy, double uz, double fov), {
31
+ var b = (typeof window !== 'undefined') ? window['__uptimizr_unreal__'] : undefined;
32
+ if (b) b.pushPose([px, py, pz], [fx, fy, fz], [ux, uy, uz], fov);
33
+ });
34
+
35
+ EM_JS(void, UptimizrPushPickJS, (const char* name, double hx, double hy, double hz), {
36
+ var b = (typeof window !== 'undefined') ? window['__uptimizr_unreal__'] : undefined;
37
+ if (b) b.pushPick(UTF8ToString(name), [hx, hy, hz]);
38
+ });
39
+
40
+ EM_JS(void, UptimizrPushPerfJS, (double fps, int longFrames), {
41
+ var b = (typeof window !== 'undefined') ? window['__uptimizr_unreal__'] : undefined;
42
+ if (b) b.pushPerf(fps, longFrames);
43
+ });
44
+
45
+ #else // !__EMSCRIPTEN__ — non-web builds (e.g. desktop editor): compile to no-ops.
46
+
47
+ static int UptimizrBridgeProtocolVersionJS()
48
+ {
49
+ return -1;
50
+ }
51
+ static void UptimizrPushPoseJS(double, double, double, double, double, double, double, double,
52
+ double, double)
53
+ {
54
+ }
55
+ static void UptimizrPushPickJS(const char*, double, double, double) {}
56
+ static void UptimizrPushPerfJS(double, int) {}
57
+
58
+ #endif // __EMSCRIPTEN__
59
+
60
+ namespace
61
+ {
62
+ // Emit a perf sample roughly this often.
63
+ constexpr float UPTIMIZR_PERF_WINDOW_SECONDS = 1.0f;
64
+ // A frame slower than this (ms) counts as a long frame (matches the JS-only tier default).
65
+ constexpr float UPTIMIZR_JANK_FRAME_MS = 50.0f;
66
+
67
+ APlayerCameraManager* ResolveCameraManager(UWorld* World)
68
+ {
69
+ if (!World)
70
+ {
71
+ return nullptr;
72
+ }
73
+ APlayerController* PC = World->GetFirstPlayerController();
74
+ return PC ? PC->PlayerCameraManager : nullptr;
75
+ }
76
+ }
77
+
78
+ bool FUptimizrTelemetry::Initialize()
79
+ {
80
+ const int Reported = UptimizrBridgeProtocolVersionJS();
81
+ if (Reported != UPTIMIZR_BRIDGE_PROTOCOL_VERSION)
82
+ {
83
+ // No bridge yet, or a version this shim was not authored against — stay disabled
84
+ // rather than push against an incompatible API.
85
+ UE_LOG(LogTemp, Warning,
86
+ TEXT("[Uptimizr] bridge protocol mismatch: shim=%d live=%d — telemetry disabled."),
87
+ UPTIMIZR_BRIDGE_PROTOCOL_VERSION, Reported);
88
+ bInitialized = false;
89
+ return false;
90
+ }
91
+
92
+ bInitialized = true;
93
+ PerfWindowSeconds = 0.0f;
94
+ PerfWindowFrames = 0;
95
+ PerfWindowLongFrames = 0;
96
+ return true;
97
+ }
98
+
99
+ void FUptimizrTelemetry::Tick(UWorld* World, float DeltaSeconds)
100
+ {
101
+ if (!bInitialized)
102
+ {
103
+ return;
104
+ }
105
+
106
+ if (APlayerCameraManager* Cam = ResolveCameraManager(World))
107
+ {
108
+ // RAW Unreal world-space: centimeters, z-up, left-handed. Pushed unconverted.
109
+ const FVector Loc = Cam->GetCameraLocation();
110
+ const FRotator Rot = Cam->GetCameraRotation();
111
+ const FVector Fwd = Rot.Vector();
112
+ const FVector Up = FRotationMatrix(Rot).GetUnitAxis(EAxis::Z);
113
+ // UE exposes horizontal FOV in degrees; the bridge wants radians. (Vertical vs
114
+ // horizontal is best-effort — the connector only uses it as a coarse frustum hint.)
115
+ const double FovRad = FMath::DegreesToRadians(Cam->GetFOVAngle());
116
+
117
+ UptimizrPushPoseJS(Loc.X, Loc.Y, Loc.Z, Fwd.X, Fwd.Y, Fwd.Z, Up.X, Up.Y, Up.Z, FovRad);
118
+ }
119
+
120
+ // Accumulate FPS over a ~1s window so we push a stable rate, not per-frame noise.
121
+ PerfWindowSeconds += DeltaSeconds;
122
+ PerfWindowFrames += 1;
123
+ if (DeltaSeconds * 1000.0f > UPTIMIZR_JANK_FRAME_MS)
124
+ {
125
+ PerfWindowLongFrames += 1;
126
+ }
127
+
128
+ if (PerfWindowSeconds >= UPTIMIZR_PERF_WINDOW_SECONDS && PerfWindowFrames > 0)
129
+ {
130
+ const double Fps = static_cast<double>(PerfWindowFrames) / PerfWindowSeconds;
131
+ UptimizrPushPerfJS(Fps, PerfWindowLongFrames);
132
+ PerfWindowSeconds = 0.0f;
133
+ PerfWindowFrames = 0;
134
+ PerfWindowLongFrames = 0;
135
+ }
136
+ }
137
+
138
+ void FUptimizrTelemetry::ReportPick(const FString& ObjectName, const FVector& WorldHitPoint)
139
+ {
140
+ if (!bInitialized || ObjectName.IsEmpty())
141
+ {
142
+ return;
143
+ }
144
+ // RAW world-space hit point (cm, z-up, left-handed).
145
+ UptimizrPushPickJS(TCHAR_TO_UTF8(*ObjectName), WorldHitPoint.X, WorldHitPoint.Y,
146
+ WorldHitPoint.Z);
147
+ }
148
+
149
+ bool FUptimizrTelemetry::TraceAndReportPick(UWorld* World, float MaxDistanceCm)
150
+ {
151
+ if (!bInitialized)
152
+ {
153
+ return false;
154
+ }
155
+ APlayerCameraManager* Cam = ResolveCameraManager(World);
156
+ if (!Cam)
157
+ {
158
+ return false;
159
+ }
160
+
161
+ const FVector Start = Cam->GetCameraLocation();
162
+ const FVector End = Start + Cam->GetCameraRotation().Vector() * MaxDistanceCm;
163
+
164
+ FHitResult Hit;
165
+ FCollisionQueryParams Params(SCENE_QUERY_STAT(UptimizrPick), /*bTraceComplex=*/false);
166
+ if (!World->LineTraceSingleByChannel(Hit, Start, End, ECC_Visibility, Params))
167
+ {
168
+ return false;
169
+ }
170
+
171
+ // Only the developer-assigned object name crosses the bridge (ADR 0003) — never input
172
+ // text or invented identifiers.
173
+ const AActor* HitActor = Hit.GetActor();
174
+ if (!HitActor)
175
+ {
176
+ return false;
177
+ }
178
+ ReportPick(HitActor->GetName(), Hit.ImpactPoint);
179
+ return true;
180
+ }
181
+
182
+ void FUptimizrTelemetry::Shutdown()
183
+ {
184
+ bInitialized = false;
185
+ }
186
+
187
+ FUptimizrTelemetry& UptimizrTelemetry()
188
+ {
189
+ static FUptimizrTelemetry Instance;
190
+ return Instance;
191
+ }
192
+
193
+ extern "C"
194
+ {
195
+ int UptimizrBridge_Init()
196
+ {
197
+ return UptimizrTelemetry().Initialize() ? 1 : 0;
198
+ }
199
+
200
+ void UptimizrBridge_Shutdown()
201
+ {
202
+ UptimizrTelemetry().Shutdown();
203
+ }
204
+ }