rbxts-transform-boost 1.0.0 → 1.1.1
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/README.md +22 -84
- package/dist/index.js +0 -2
- package/dist/passes/annotate.js +2 -6
- package/package.json +11 -5
- package/.github/workflows/publish.yml +0 -26
- package/bench/default.project.json +0 -20
- package/bench/out/include/Promise.lua +0 -2068
- package/bench/out/include/RuntimeLib.lua +0 -260
- package/bench/out/src/server/benchmark.server.luau +0 -122
- package/bench/out/src/shared/fns-bare.luau +0 -258
- package/bench/out/src/shared/fns.luau +0 -259
- package/bench/package-lock.json +0 -59
- package/bench/src/server/benchmark.server.ts +0 -57
- package/bench/src/shared/fns-bare.ts +0 -127
- package/bench/src/shared/fns.ts +0 -129
- package/bench/tsconfig.json +0 -32
- package/bench/tsconfig.notransform.json +0 -24
- package/rokit.toml +0 -3
- package/src/config.ts +0 -14
- package/src/index.ts +0 -25
- package/src/passes/annotate.ts +0 -400
- package/src/passes/cache.ts +0 -163
- package/src/passes/loops.ts +0 -80
- package/src/passes/native.ts +0 -34
- package/src/util.ts +0 -37
- package/tsconfig.json +0 -16
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
--!optimize 2
|
|
2
|
-
--!native
|
|
3
|
-
|
|
4
|
-
-- Compiled with rotor v2.2.0
|
|
5
|
-
|
|
6
|
-
-- Services
|
|
7
|
-
local _RunService = game:GetService("RunService")
|
|
8
|
-
local _Workspace = game:GetService("Workspace")
|
|
9
|
-
local _Players = game:GetService("Players")
|
|
10
|
-
|
|
11
|
-
local function integrate(pos: Vector3, vel: Vector3, acc: Vector3, dt: number)
|
|
12
|
-
local _vel = vel
|
|
13
|
-
local _acc = acc
|
|
14
|
-
local _dt = dt
|
|
15
|
-
const newVel = _vel + (_acc * _dt)
|
|
16
|
-
|
|
17
|
-
local _pos = pos
|
|
18
|
-
local _dt_1 = dt
|
|
19
|
-
local _arg0 = newVel * _dt_1
|
|
20
|
-
const newPos = _pos + _arg0
|
|
21
|
-
|
|
22
|
-
return { newPos, newVel }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
local function dot(a: Vector3, b: Vector3): number
|
|
26
|
-
return a.X * b.X + a.Y * b.Y + a.Z * b.Z
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
local function cross(a: Vector3, b: Vector3): Vector3
|
|
30
|
-
local _cache0 = a.Y
|
|
31
|
-
local _cache1 = b.Z
|
|
32
|
-
local _cache2 = a.Z
|
|
33
|
-
local _cache3 = b.Y
|
|
34
|
-
local _cache4 = b.X
|
|
35
|
-
local _cache5 = a.X
|
|
36
|
-
|
|
37
|
-
return Vector3.new(_cache0 * _cache1 - _cache2 * _cache3, _cache2 * _cache4 - _cache5 * _cache1, _cache5 * _cache3 - _cache0 * _cache4)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
local function lerpVec3(a: Vector3, b: Vector3, t: number): Vector3
|
|
41
|
-
local _cache0 = a.X
|
|
42
|
-
local _cache1 = a.Y
|
|
43
|
-
local _cache2 = a.Z
|
|
44
|
-
|
|
45
|
-
return Vector3.new(_cache0 + (b.X - _cache0) * t, _cache1 + (b.Y - _cache1) * t, _cache2 + (b.Z - _cache2) * t)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
-- ── Buffer / encoding ────────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
local function encodeFixed(buf: buffer, offset: number, value: number, scale: number): number
|
|
51
|
-
const fixed = math.floor(value * scale)
|
|
52
|
-
const clamped = math.clamp(fixed, -32768, 32767)
|
|
53
|
-
buffer.writei16(buf, offset, clamped)
|
|
54
|
-
|
|
55
|
-
return offset + 2
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
local function encodePacket(buf: buffer, x: number, y: number, z: number, scale: number)
|
|
59
|
-
local off = 0
|
|
60
|
-
off = encodeFixed(buf, off, x, scale)
|
|
61
|
-
off = encodeFixed(buf, off, y, scale)
|
|
62
|
-
encodeFixed(buf, off, z, scale)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
-- ── Math / arithmetic ────────────────────────────────────────────────────────
|
|
66
|
-
|
|
67
|
-
local function sumWeighted(values: {number}, weights: {number}): number
|
|
68
|
-
local total = 0
|
|
69
|
-
|
|
70
|
-
do
|
|
71
|
-
local _len_values = #values
|
|
72
|
-
|
|
73
|
-
do
|
|
74
|
-
local i = 0
|
|
75
|
-
local _shouldIncrement = false
|
|
76
|
-
|
|
77
|
-
while true do
|
|
78
|
-
if _shouldIncrement then
|
|
79
|
-
i += 1
|
|
80
|
-
else
|
|
81
|
-
_shouldIncrement = true
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
if not (i < _len_values) then
|
|
85
|
-
break
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
total += values[i + 1] * weights[i + 1]
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
return total
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
local function dotProduct(a: {number}, b: {number}): number
|
|
97
|
-
local sum = 0
|
|
98
|
-
|
|
99
|
-
do
|
|
100
|
-
local _len_a = #a
|
|
101
|
-
|
|
102
|
-
do
|
|
103
|
-
local i = 0
|
|
104
|
-
local _shouldIncrement = false
|
|
105
|
-
|
|
106
|
-
while true do
|
|
107
|
-
if _shouldIncrement then
|
|
108
|
-
i += 1
|
|
109
|
-
else
|
|
110
|
-
_shouldIncrement = true
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
if not (i < _len_a) then
|
|
114
|
-
break
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
sum += a[i + 1] * b[i + 1]
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
return sum
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
local function norm(values: {number}): number
|
|
126
|
-
local sq = 0
|
|
127
|
-
|
|
128
|
-
do
|
|
129
|
-
local _len_values = #values
|
|
130
|
-
|
|
131
|
-
do
|
|
132
|
-
local i = 0
|
|
133
|
-
local _shouldIncrement = false
|
|
134
|
-
|
|
135
|
-
while true do
|
|
136
|
-
if _shouldIncrement then
|
|
137
|
-
i += 1
|
|
138
|
-
else
|
|
139
|
-
_shouldIncrement = true
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
if not (i < _len_values) then
|
|
143
|
-
break
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
sq += values[i + 1] * values[i + 1]
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
return math.sqrt(sq)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
local function mathHeavy(x: number, y: number): number
|
|
155
|
-
return math.sin(x) * math.cos(y) + math.sqrt(x * x + y * y) + math.atan2(y, x)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
local function fib(n: number): number
|
|
159
|
-
|
|
160
|
-
if n <= 1 then
|
|
161
|
-
return n
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
local a = 0
|
|
165
|
-
local b = 1
|
|
166
|
-
|
|
167
|
-
do
|
|
168
|
-
local i = 2
|
|
169
|
-
local _shouldIncrement = false
|
|
170
|
-
|
|
171
|
-
while true do
|
|
172
|
-
if _shouldIncrement then
|
|
173
|
-
i += 1
|
|
174
|
-
else
|
|
175
|
-
_shouldIncrement = true
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
if not (i <= n) then
|
|
179
|
-
break
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
const tmp = a + b
|
|
183
|
-
a = b
|
|
184
|
-
b = tmp
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
return b
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
-- ── CFrame ───────────────────────────────────────────────────────────────────
|
|
192
|
-
|
|
193
|
-
local function cfLookAt(eye: Vector3, target: Vector3): CFrame
|
|
194
|
-
return CFrame.lookAt(eye, target)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
local function cfChain(cf: CFrame, dt: number): CFrame
|
|
198
|
-
local _cf = cf
|
|
199
|
-
local _arg0 = CFrame.Angles(0, dt, 0)
|
|
200
|
-
|
|
201
|
-
return _cf * _arg0
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
-- ── Services / instance ──────────────────────────────────────────────────────
|
|
205
|
-
|
|
206
|
-
local function serviceWork(): string
|
|
207
|
-
const count = #_Players:GetPlayers()
|
|
208
|
-
const running = _RunService:IsRunning()
|
|
209
|
-
|
|
210
|
-
return `{count}-{running}`
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
local function multiService(): boolean
|
|
214
|
-
const players = _Players
|
|
215
|
-
const rs = _RunService
|
|
216
|
-
const ws = _Workspace
|
|
217
|
-
|
|
218
|
-
return rs:IsRunning() and players.MaxPlayers > 0 and ws.Gravity > 0
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
local function cameraWork(camera: Camera): number
|
|
222
|
-
local _cache0 = camera.CFrame
|
|
223
|
-
const pos = _cache0.Position
|
|
224
|
-
const look = _cache0.LookVector
|
|
225
|
-
const fov = camera.FieldOfView
|
|
226
|
-
|
|
227
|
-
return pos.Magnitude + look.X + fov
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
-- ── String ───────────────────────────────────────────────────────────────────
|
|
231
|
-
|
|
232
|
-
local function formatStats(label: string, value: number, unit: string): string
|
|
233
|
-
return `{label}: {string.format("%.4f", value)} {unit}`
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
local function buildKey(prefix: string, id: number, suffix: string): string
|
|
237
|
-
return `{prefix}_{id}_{suffix}`
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
return {
|
|
241
|
-
integrate = integrate,
|
|
242
|
-
dot = dot,
|
|
243
|
-
cross = cross,
|
|
244
|
-
lerpVec3 = lerpVec3,
|
|
245
|
-
encodeFixed = encodeFixed,
|
|
246
|
-
encodePacket = encodePacket,
|
|
247
|
-
sumWeighted = sumWeighted,
|
|
248
|
-
dotProduct = dotProduct,
|
|
249
|
-
norm = norm,
|
|
250
|
-
mathHeavy = mathHeavy,
|
|
251
|
-
fib = fib,
|
|
252
|
-
cfLookAt = cfLookAt,
|
|
253
|
-
cfChain = cfChain,
|
|
254
|
-
serviceWork = serviceWork,
|
|
255
|
-
multiService = multiService,
|
|
256
|
-
cameraWork = cameraWork,
|
|
257
|
-
formatStats = formatStats,
|
|
258
|
-
buildKey = buildKey,
|
|
259
|
-
}
|
package/bench/package-lock.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rbxts-transform-perf-test",
|
|
3
|
-
"lockfileVersion": 3,
|
|
4
|
-
"requires": true,
|
|
5
|
-
"packages": {
|
|
6
|
-
"": {
|
|
7
|
-
"name": "rbxts-transform-perf-test",
|
|
8
|
-
"devDependencies": {
|
|
9
|
-
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
10
|
-
"@rbxts/types": "^1.0.908",
|
|
11
|
-
"rbxts-transform-boost": "file:../",
|
|
12
|
-
"typescript": "=5.5.3"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"..": {
|
|
16
|
-
"name": "rbxts-transform-boost",
|
|
17
|
-
"version": "0.1.0",
|
|
18
|
-
"dev": true,
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@types/node": "^26.0.0"
|
|
21
|
-
},
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"typescript": ">=5.0.0"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"node_modules/@rbxts/compiler-types": {
|
|
27
|
-
"version": "3.0.0-types.0",
|
|
28
|
-
"resolved": "https://registry.npmjs.org/@rbxts/compiler-types/-/compiler-types-3.0.0-types.0.tgz",
|
|
29
|
-
"integrity": "sha512-VGOHJPoL7+56NTatMGqQj3K7xWuzEV+aP4QD5vZiHu+bcff3kiTmtoadaF6NkJrmwfFAvbsd4Dg764ZjWNceag==",
|
|
30
|
-
"dev": true,
|
|
31
|
-
"license": "MIT"
|
|
32
|
-
},
|
|
33
|
-
"node_modules/@rbxts/types": {
|
|
34
|
-
"version": "1.0.928",
|
|
35
|
-
"resolved": "https://registry.npmjs.org/@rbxts/types/-/types-1.0.928.tgz",
|
|
36
|
-
"integrity": "sha512-GzmzBNn8fyn0ed9kVQkXUbBXpUg9Gfyf9AZJKT51VGqyrf4w6J0X72eSSGxt6YN2BMHNbqhzHCBn/fM8bdqMTg==",
|
|
37
|
-
"dev": true,
|
|
38
|
-
"license": "MIT"
|
|
39
|
-
},
|
|
40
|
-
"node_modules/rbxts-transform-boost": {
|
|
41
|
-
"resolved": "..",
|
|
42
|
-
"link": true
|
|
43
|
-
},
|
|
44
|
-
"node_modules/typescript": {
|
|
45
|
-
"version": "5.5.3",
|
|
46
|
-
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz",
|
|
47
|
-
"integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==",
|
|
48
|
-
"dev": true,
|
|
49
|
-
"license": "Apache-2.0",
|
|
50
|
-
"bin": {
|
|
51
|
-
"tsc": "bin/tsc",
|
|
52
|
-
"tsserver": "bin/tsserver"
|
|
53
|
-
},
|
|
54
|
-
"engines": {
|
|
55
|
-
"node": ">=14.17"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import * as base from "../shared/fns-bare";
|
|
2
|
-
import * as opt from "../shared/fns";
|
|
3
|
-
|
|
4
|
-
function bench(label: string, n: number, fn: () => void): void {
|
|
5
|
-
task.wait(0.05);
|
|
6
|
-
const t0 = os.clock();
|
|
7
|
-
for (let i = 0; i < n; i++) fn();
|
|
8
|
-
const elapsed = os.clock() - t0;
|
|
9
|
-
print(` ${label}: ${string.format("%.3f", (elapsed / n) * 1e6)} us/iter`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const N = 100000;
|
|
13
|
-
const NS = 10000;
|
|
14
|
-
|
|
15
|
-
const pos = new Vector3(1, 2, 3);
|
|
16
|
-
const vel = new Vector3(0, 1, 0);
|
|
17
|
-
const acc = new Vector3(0, -9.8, 0);
|
|
18
|
-
const vecA = new Vector3(1, 0, 0);
|
|
19
|
-
const vecB = new Vector3(0, 1, 0);
|
|
20
|
-
const eye = new Vector3(0, 5, 10);
|
|
21
|
-
const tgt = new Vector3(0, 0, 0);
|
|
22
|
-
const cf = CFrame.lookAt(eye, tgt);
|
|
23
|
-
const buf = buffer.create(256);
|
|
24
|
-
const vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
25
|
-
const wts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
|
|
26
|
-
const cam = game.GetService("Workspace").CurrentCamera!;
|
|
27
|
-
|
|
28
|
-
function runSuite(fns: typeof opt): void {
|
|
29
|
-
bench("integrate (verlet)", N, () => fns.integrate(pos, vel, acc, 1 / 60));
|
|
30
|
-
bench("dot (V3 manual)", N, () => fns.dot(vecA, vecB));
|
|
31
|
-
bench("cross (V3 manual)", N, () => fns.cross(vecA, vecB));
|
|
32
|
-
bench("lerpVec3 (V3 manual)", N, () => fns.lerpVec3(pos, eye, 0.5));
|
|
33
|
-
bench("encodeFixed (buf+math)", N, () => fns.encodeFixed(buf, 0, 3.14, 100));
|
|
34
|
-
bench("encodePacket(3x fixed)", N, () => fns.encodePacket(buf, 1.1, 2.2, 3.3, 100));
|
|
35
|
-
bench("sumWeighted (loop)", N, () => fns.sumWeighted(vals, wts));
|
|
36
|
-
bench("dotProduct (loop)", N, () => fns.dotProduct(vals, vals));
|
|
37
|
-
bench("norm (loop+sqrt)", N, () => fns.norm(vals));
|
|
38
|
-
bench("mathHeavy (trig+sqrt)", N, () => fns.mathHeavy(1.23, 4.56));
|
|
39
|
-
bench("fib(20) (iter)", N, () => fns.fib(20));
|
|
40
|
-
bench("cfLookAt (ctor)", NS, () => fns.cfLookAt(eye, tgt));
|
|
41
|
-
bench("cfChain (mul+angles)", N, () => fns.cfChain(cf, 0.016));
|
|
42
|
-
bench("serviceWork (GetService x2)", N, () => fns.serviceWork());
|
|
43
|
-
bench("multiSvc (GetService x3)", N, () => fns.multiService());
|
|
44
|
-
bench("cameraWork (prop chain)", N, () => fns.cameraWork(cam));
|
|
45
|
-
bench("formatStats (template)", N, () => fns.formatStats("speed", 9.81, "m/s"));
|
|
46
|
-
bench("buildKey (template)", N, () => fns.buildKey("player", 42, "data"));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
print("\n=== optimized (--!native + transformer) ===");
|
|
50
|
-
runSuite(opt);
|
|
51
|
-
print("===========================================\n");
|
|
52
|
-
|
|
53
|
-
task.wait(1);
|
|
54
|
-
|
|
55
|
-
print("\n=== baseline (plain rotor, no transformer) ===");
|
|
56
|
-
runSuite(base);
|
|
57
|
-
print("==============================================\n");
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// ── Vector3 / physics ────────────────────────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
export function integrate(pos: Vector3, vel: Vector3, acc: Vector3, dt: number): [Vector3, Vector3] {
|
|
4
|
-
const newVel = vel.add(acc.mul(dt));
|
|
5
|
-
const newPos = pos.add(newVel.mul(dt));
|
|
6
|
-
return [newPos, newVel];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function dot(a: Vector3, b: Vector3): number {
|
|
10
|
-
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function cross(a: Vector3, b: Vector3): Vector3 {
|
|
14
|
-
return new Vector3(
|
|
15
|
-
a.Y * b.Z - a.Z * b.Y,
|
|
16
|
-
a.Z * b.X - a.X * b.Z,
|
|
17
|
-
a.X * b.Y - a.Y * b.X,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function lerpVec3(a: Vector3, b: Vector3, t: number): Vector3 {
|
|
22
|
-
return new Vector3(
|
|
23
|
-
a.X + (b.X - a.X) * t,
|
|
24
|
-
a.Y + (b.Y - a.Y) * t,
|
|
25
|
-
a.Z + (b.Z - a.Z) * t,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// ── Buffer / encoding ────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
export function encodeFixed(buf: buffer, offset: number, value: number, scale: number): number {
|
|
32
|
-
const fixed = math.floor(value * scale);
|
|
33
|
-
const clamped = math.clamp(fixed, -32768, 32767);
|
|
34
|
-
buffer.writei16(buf, offset, clamped);
|
|
35
|
-
return offset + 2;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function encodePacket(buf: buffer, x: number, y: number, z: number, scale: number): void {
|
|
39
|
-
let off = 0;
|
|
40
|
-
off = encodeFixed(buf, off, x, scale);
|
|
41
|
-
off = encodeFixed(buf, off, y, scale);
|
|
42
|
-
encodeFixed(buf, off, z, scale);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ── Math / arithmetic ────────────────────────────────────────────────────────
|
|
46
|
-
|
|
47
|
-
export function sumWeighted(values: Array<number>, weights: Array<number>): number {
|
|
48
|
-
let total = 0;
|
|
49
|
-
for (let i = 0; i < values.size(); i++) {
|
|
50
|
-
total += values[i] * weights[i];
|
|
51
|
-
}
|
|
52
|
-
return total;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function dotProduct(a: Array<number>, b: Array<number>): number {
|
|
56
|
-
let sum = 0;
|
|
57
|
-
for (let i = 0; i < a.size(); i++) {
|
|
58
|
-
sum += a[i] * b[i];
|
|
59
|
-
}
|
|
60
|
-
return sum;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function norm(values: Array<number>): number {
|
|
64
|
-
let sq = 0;
|
|
65
|
-
for (let i = 0; i < values.size(); i++) {
|
|
66
|
-
sq += values[i] * values[i];
|
|
67
|
-
}
|
|
68
|
-
return math.sqrt(sq);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function mathHeavy(x: number, y: number): number {
|
|
72
|
-
return math.sin(x) * math.cos(y) + math.sqrt(x * x + y * y) + math.atan2(y, x);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function fib(n: number): number {
|
|
76
|
-
if (n <= 1) return n;
|
|
77
|
-
let a = 0;
|
|
78
|
-
let b = 1;
|
|
79
|
-
for (let i = 2; i <= n; i++) {
|
|
80
|
-
const tmp = a + b;
|
|
81
|
-
a = b;
|
|
82
|
-
b = tmp;
|
|
83
|
-
}
|
|
84
|
-
return b;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ── CFrame ───────────────────────────────────────────────────────────────────
|
|
88
|
-
|
|
89
|
-
export function cfLookAt(eye: Vector3, target: Vector3): CFrame {
|
|
90
|
-
return CFrame.lookAt(eye, target);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function cfChain(cf: CFrame, dt: number): CFrame {
|
|
94
|
-
return cf.mul(CFrame.Angles(0, dt, 0));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ── Services / instance ──────────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
export function serviceWork(): string {
|
|
100
|
-
const count = game.GetService("Players").GetPlayers().size();
|
|
101
|
-
const running = game.GetService("RunService").IsRunning();
|
|
102
|
-
return `${count}-${running}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function multiService(): boolean {
|
|
106
|
-
const players = game.GetService("Players");
|
|
107
|
-
const rs = game.GetService("RunService");
|
|
108
|
-
const ws = game.GetService("Workspace");
|
|
109
|
-
return rs.IsRunning() && players.MaxPlayers > 0 && ws.Gravity > 0;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function cameraWork(camera: Camera): number {
|
|
113
|
-
const pos = camera.CFrame.Position;
|
|
114
|
-
const look = camera.CFrame.LookVector;
|
|
115
|
-
const fov = camera.FieldOfView;
|
|
116
|
-
return pos.Magnitude + look.X + fov;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// ── String ───────────────────────────────────────────────────────────────────
|
|
120
|
-
|
|
121
|
-
export function formatStats(label: string, value: number, unit: string): string {
|
|
122
|
-
return `${label}: ${string.format("%.4f", value)} ${unit}`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function buildKey(prefix: string, id: number, suffix: string): string {
|
|
126
|
-
return `${prefix}_${id}_${suffix}`;
|
|
127
|
-
}
|
package/bench/src/shared/fns.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
//!native
|
|
2
|
-
|
|
3
|
-
// ── Vector3 / physics ────────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
export function integrate(pos: Vector3, vel: Vector3, acc: Vector3, dt: number): [Vector3, Vector3] {
|
|
6
|
-
const newVel = vel.add(acc.mul(dt));
|
|
7
|
-
const newPos = pos.add(newVel.mul(dt));
|
|
8
|
-
return [newPos, newVel];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function dot(a: Vector3, b: Vector3): number {
|
|
12
|
-
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function cross(a: Vector3, b: Vector3): Vector3 {
|
|
16
|
-
return new Vector3(
|
|
17
|
-
a.Y * b.Z - a.Z * b.Y,
|
|
18
|
-
a.Z * b.X - a.X * b.Z,
|
|
19
|
-
a.X * b.Y - a.Y * b.X,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function lerpVec3(a: Vector3, b: Vector3, t: number): Vector3 {
|
|
24
|
-
return new Vector3(
|
|
25
|
-
a.X + (b.X - a.X) * t,
|
|
26
|
-
a.Y + (b.Y - a.Y) * t,
|
|
27
|
-
a.Z + (b.Z - a.Z) * t,
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ── Buffer / encoding ────────────────────────────────────────────────────────
|
|
32
|
-
|
|
33
|
-
export function encodeFixed(buf: buffer, offset: number, value: number, scale: number): number {
|
|
34
|
-
const fixed = math.floor(value * scale);
|
|
35
|
-
const clamped = math.clamp(fixed, -32768, 32767);
|
|
36
|
-
buffer.writei16(buf, offset, clamped);
|
|
37
|
-
return offset + 2;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function encodePacket(buf: buffer, x: number, y: number, z: number, scale: number): void {
|
|
41
|
-
let off = 0;
|
|
42
|
-
off = encodeFixed(buf, off, x, scale);
|
|
43
|
-
off = encodeFixed(buf, off, y, scale);
|
|
44
|
-
encodeFixed(buf, off, z, scale);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ── Math / arithmetic ────────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
|
-
export function sumWeighted(values: Array<number>, weights: Array<number>): number {
|
|
50
|
-
let total = 0;
|
|
51
|
-
for (let i = 0; i < values.size(); i++) {
|
|
52
|
-
total += values[i] * weights[i];
|
|
53
|
-
}
|
|
54
|
-
return total;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function dotProduct(a: Array<number>, b: Array<number>): number {
|
|
58
|
-
let sum = 0;
|
|
59
|
-
for (let i = 0; i < a.size(); i++) {
|
|
60
|
-
sum += a[i] * b[i];
|
|
61
|
-
}
|
|
62
|
-
return sum;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function norm(values: Array<number>): number {
|
|
66
|
-
let sq = 0;
|
|
67
|
-
for (let i = 0; i < values.size(); i++) {
|
|
68
|
-
sq += values[i] * values[i];
|
|
69
|
-
}
|
|
70
|
-
return math.sqrt(sq);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function mathHeavy(x: number, y: number): number {
|
|
74
|
-
return math.sin(x) * math.cos(y) + math.sqrt(x * x + y * y) + math.atan2(y, x);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function fib(n: number): number {
|
|
78
|
-
if (n <= 1) return n;
|
|
79
|
-
let a = 0;
|
|
80
|
-
let b = 1;
|
|
81
|
-
for (let i = 2; i <= n; i++) {
|
|
82
|
-
const tmp = a + b;
|
|
83
|
-
a = b;
|
|
84
|
-
b = tmp;
|
|
85
|
-
}
|
|
86
|
-
return b;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ── CFrame ───────────────────────────────────────────────────────────────────
|
|
90
|
-
|
|
91
|
-
export function cfLookAt(eye: Vector3, target: Vector3): CFrame {
|
|
92
|
-
return CFrame.lookAt(eye, target);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function cfChain(cf: CFrame, dt: number): CFrame {
|
|
96
|
-
return cf.mul(CFrame.Angles(0, dt, 0));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ── Services / instance ──────────────────────────────────────────────────────
|
|
100
|
-
|
|
101
|
-
export function serviceWork(): string {
|
|
102
|
-
const count = game.GetService("Players").GetPlayers().size();
|
|
103
|
-
const running = game.GetService("RunService").IsRunning();
|
|
104
|
-
return `${count}-${running}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function multiService(): boolean {
|
|
108
|
-
const players = game.GetService("Players");
|
|
109
|
-
const rs = game.GetService("RunService");
|
|
110
|
-
const ws = game.GetService("Workspace");
|
|
111
|
-
return rs.IsRunning() && players.MaxPlayers > 0 && ws.Gravity > 0;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function cameraWork(camera: Camera): number {
|
|
115
|
-
const pos = camera.CFrame.Position;
|
|
116
|
-
const look = camera.CFrame.LookVector;
|
|
117
|
-
const fov = camera.FieldOfView;
|
|
118
|
-
return pos.Magnitude + look.X + fov;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ── String ───────────────────────────────────────────────────────────────────
|
|
122
|
-
|
|
123
|
-
export function formatStats(label: string, value: number, unit: string): string {
|
|
124
|
-
return `${label}: ${string.format("%.4f", value)} ${unit}`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function buildKey(prefix: string, id: number, suffix: string): string {
|
|
128
|
-
return `${prefix}_${id}_${suffix}`;
|
|
129
|
-
}
|
package/bench/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"moduleDetection": "force",
|
|
6
|
-
"moduleResolution": "Node",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noLib": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"rootDir": "./src",
|
|
13
|
-
"outDir": "./out/src",
|
|
14
|
-
"typeRoots": [
|
|
15
|
-
"./node_modules/@rbxts"
|
|
16
|
-
],
|
|
17
|
-
"plugins": [
|
|
18
|
-
{
|
|
19
|
-
"transform": "rbxts-transform-boost",
|
|
20
|
-
"optimize": true,
|
|
21
|
-
"hoist": true
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
"include": [
|
|
26
|
-
"./src/server",
|
|
27
|
-
"./src/shared/fns.ts"
|
|
28
|
-
],
|
|
29
|
-
"rbxts": {
|
|
30
|
-
"includePath": "out/include"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"moduleDetection": "force",
|
|
6
|
-
"moduleResolution": "Node",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noLib": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"rootDir": "./src",
|
|
13
|
-
"outDir": "./out/src",
|
|
14
|
-
"typeRoots": [
|
|
15
|
-
"./node_modules/@rbxts"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"./src/shared/fns-bare.ts"
|
|
20
|
-
],
|
|
21
|
-
"rbxts": {
|
|
22
|
-
"includePath": "out/include"
|
|
23
|
-
}
|
|
24
|
-
}
|
package/rokit.toml
DELETED