Skip to content

Commit 7e64955

Browse files
author
Your Name
committed
added rng support
1 parent d6afe66 commit 7e64955

File tree

6 files changed

+108
-71
lines changed

6 files changed

+108
-71
lines changed

Math/rng.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export function sfc32(a: number, b: number, c: number, d: number) {
2+
return function() {
3+
a |= 0; b |= 0; c |= 0; d |= 0;
4+
let t = (a + b | 0) + d | 0;
5+
d = d + 1 | 0;
6+
a = b ^ b >>> 9;
7+
b = c + (c << 3) | 0;
8+
c = (c << 21 | c >>> 11);
9+
c = c + t | 0;
10+
return (t >>> 0) / 4294967296;
11+
}
12+
}
13+
14+
15+
export function cyrb128(str: string) {
16+
let h1 = 1779033703, h2 = 3144134277,
17+
h3 = 1013904242, h4 = 2773480762;
18+
for (let i = 0, k; i < str.length; i++) {
19+
k = str.charCodeAt(i);
20+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
21+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
22+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
23+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
24+
}
25+
h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);
26+
h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);
27+
h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);
28+
h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
29+
h1 ^= (h2 ^ h3 ^ h4), h2 ^= h1, h3 ^= h1, h4 ^= h1;
30+
return [h1>>>0, h2>>>0, h3>>>0, h4>>>0];
31+
}

Parts/Children/Collider.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,6 @@ export abstract class Collider extends Part {
225225
}
226226

227227
this.hoverbug = `${this.colliding ? "🟥" : "🟩"} - ${Array.from(this.collidingWith).map(o => o.name).join(", ")} objects`;
228-
229-
// Debugging manually
230-
231-
const fill = this.active;
232-
233-
const ctx = this.top instanceof Game ? this.top.context : null;
234-
if (ctx) {
235-
ctx.beginPath();
236-
ctx.strokeStyle = `rgb(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]})`;
237-
ctx.fillStyle = fill ? `rgba(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]}, 0.5)` : "transparent";
238-
239-
ctx.moveTo(this.worldVertices[0].x, this.worldVertices[0].y);
240-
for (const vertex of this.worldVertices) {
241-
ctx.lineTo(vertex.x, vertex.y);
242-
}
243-
ctx.closePath();
244-
ctx.stroke();
245-
ctx.fill();
246-
}
247-
248228
if (this.top instanceof Game && this.top.devmode) {
249229
const ctx = this.top.context;
250230
if (ctx) {

engine/bundle.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12154,24 +12154,10 @@ class Collider extends Part {
1215412154
}
1215512155
}
1215612156
this.hoverbug = `${this.colliding ? "\uD83D\uDFE5" : "\uD83D\uDFE9"} - ${Array.from(this.collidingWith).map((o) => o.name).join(", ")} objects`;
12157-
const fill = this.active;
12158-
const ctx = this.top instanceof Game ? this.top.context : null;
12159-
if (ctx) {
12160-
ctx.beginPath();
12161-
ctx.strokeStyle = `rgb(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]})`;
12162-
ctx.fillStyle = fill ? `rgba(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]}, 0.5)` : "transparent";
12163-
ctx.moveTo(this.worldVertices[0].x, this.worldVertices[0].y);
12164-
for (const vertex of this.worldVertices) {
12165-
ctx.lineTo(vertex.x, vertex.y);
12166-
}
12167-
ctx.closePath();
12168-
ctx.stroke();
12169-
ctx.fill();
12170-
}
1217112157
if (this.top instanceof Game && this.top.devmode) {
12172-
const ctx2 = this.top.context;
12173-
if (ctx2) {
12174-
this.drawDebug(ctx2);
12158+
const ctx = this.top.context;
12159+
if (ctx) {
12160+
this.drawDebug(ctx);
1217512161
}
1217612162
}
1217712163
}
@@ -14432,6 +14418,38 @@ class GravityCharacterMovement extends Part {
1443214418
transform.position.addInPlace(this.velocity.multiply(delta));
1443314419
}
1443414420
}
14421+
// Math/rng.ts
14422+
function sfc32(a, b, c, d) {
14423+
return function() {
14424+
a |= 0;
14425+
b |= 0;
14426+
c |= 0;
14427+
d |= 0;
14428+
let t = (a + b | 0) + d | 0;
14429+
d = d + 1 | 0;
14430+
a = b ^ b >>> 9;
14431+
b = c + (c << 3) | 0;
14432+
c = c << 21 | c >>> 11;
14433+
c = c + t | 0;
14434+
return (t >>> 0) / 4294967296;
14435+
};
14436+
}
14437+
function cyrb128(str) {
14438+
let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;
14439+
for (let i = 0, k;i < str.length; i++) {
14440+
k = str.charCodeAt(i);
14441+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
14442+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
14443+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
14444+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
14445+
}
14446+
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
14447+
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
14448+
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
14449+
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
14450+
h1 ^= h2 ^ h3 ^ h4, h2 ^= h1, h3 ^= h1, h4 ^= h1;
14451+
return [h1 >>> 0, h2 >>> 0, h3 >>> 0, h4 >>> 0];
14452+
}
1443514453
// node_modules/terser/lib/utils/index.js
1443614454
function characters(str) {
1443714455
return str.split("");
@@ -44391,6 +44409,7 @@ async function infer_options(options) {
4439144409
}
4439244410
export {
4439344411
vecEq,
44412+
sfc32,
4439444413
resetCamera,
4439544414
pointInPoly,
4439644415
minify_sync,
@@ -44400,6 +44419,7 @@ export {
4440044419
getDebugInfo,
4440144420
generateUID,
4440244421
drawBox,
44422+
cyrb128,
4440344423
convertTexturePackerToSpriteSheetData,
4440444424
applyCamera,
4440544425
run_cli as _run_cli,

engine/editor.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,6 +4352,7 @@ var require_showdown = __commonJS((exports, module) => {
43524352
var exports_bundle = {};
43534353
__export(exports_bundle, {
43544354
vecEq: () => vecEq,
4355+
sfc32: () => sfc32,
43554356
resetCamera: () => resetCamera,
43564357
pointInPoly: () => pointInPoly,
43574358
minify_sync: () => minify_sync,
@@ -4361,6 +4362,7 @@ __export(exports_bundle, {
43614362
getDebugInfo: () => getDebugInfo,
43624363
generateUID: () => generateUID,
43634364
drawBox: () => drawBox,
4365+
cyrb128: () => cyrb128,
43644366
convertTexturePackerToSpriteSheetData: () => convertTexturePackerToSpriteSheetData,
43654367
applyCamera: () => applyCamera,
43664368
_run_cli: () => run_cli,
@@ -5191,6 +5193,37 @@ class Vector {
51915193
}
51925194
}
51935195
}
5196+
function sfc32(a, b, c, d) {
5197+
return function() {
5198+
a |= 0;
5199+
b |= 0;
5200+
c |= 0;
5201+
d |= 0;
5202+
let t = (a + b | 0) + d | 0;
5203+
d = d + 1 | 0;
5204+
a = b ^ b >>> 9;
5205+
b = c + (c << 3) | 0;
5206+
c = c << 21 | c >>> 11;
5207+
c = c + t | 0;
5208+
return (t >>> 0) / 4294967296;
5209+
};
5210+
}
5211+
function cyrb128(str) {
5212+
let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;
5213+
for (let i = 0, k;i < str.length; i++) {
5214+
k = str.charCodeAt(i);
5215+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
5216+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
5217+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
5218+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
5219+
}
5220+
h1 = Math.imul(h3 ^ h1 >>> 18, 597399067);
5221+
h2 = Math.imul(h4 ^ h2 >>> 22, 2869860233);
5222+
h3 = Math.imul(h1 ^ h3 >>> 17, 951274213);
5223+
h4 = Math.imul(h2 ^ h4 >>> 19, 2716044179);
5224+
h1 ^= h2 ^ h3 ^ h4, h2 ^= h1, h3 ^= h1, h4 ^= h1;
5225+
return [h1 >>> 0, h2 >>> 0, h3 >>> 0, h4 >>> 0];
5226+
}
51945227
function characters(str) {
51955228
return str.split("");
51965229
}
@@ -25085,24 +25118,10 @@ Defaulting to 2020, but this will stop working in the future.`);
2508525118
}
2508625119
}
2508725120
this.hoverbug = `${this.colliding ? "\uD83D\uDFE5" : "\uD83D\uDFE9"} - ${Array.from(this.collidingWith).map((o) => o.name).join(", ")} objects`;
25088-
const fill = this.active;
25089-
const ctx = this.top instanceof Game ? this.top.context : null;
25090-
if (ctx) {
25091-
ctx.beginPath();
25092-
ctx.strokeStyle = `rgb(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]})`;
25093-
ctx.fillStyle = fill ? `rgba(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]}, 0.5)` : "transparent";
25094-
ctx.moveTo(this.worldVertices[0].x, this.worldVertices[0].y);
25095-
for (const vertex of this.worldVertices) {
25096-
ctx.lineTo(vertex.x, vertex.y);
25097-
}
25098-
ctx.closePath();
25099-
ctx.stroke();
25100-
ctx.fill();
25101-
}
2510225121
if (this.top instanceof Game && this.top.devmode) {
25103-
const ctx2 = this.top.context;
25104-
if (ctx2) {
25105-
this.drawDebug(ctx2);
25122+
const ctx = this.top.context;
25123+
if (ctx) {
25124+
this.drawDebug(ctx);
2510625125
}
2510725126
}
2510825127
}

engine/engine-core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export * from '../Parts/HealthBar';
3434
export * from '../Parts/PhysicsBody';
3535
export * from '../Parts/GravityCharacterMovement';
3636
export * from '../Math/Vector';
37+
export * from '../Math/rng';
3738
export * from '../helpers';
3839
export * from '../types';
3940
export * from 'terser';

testDist/TestColliderMerge.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6784,24 +6784,10 @@ class Collider extends Part {
67846784
}
67856785
}
67866786
this.hoverbug = `${this.colliding ? "\uD83D\uDFE5" : "\uD83D\uDFE9"} - ${Array.from(this.collidingWith).map((o) => o.name).join(", ")} objects`;
6787-
const fill = this.active;
6788-
const ctx = this.top instanceof Game ? this.top.context : null;
6789-
if (ctx) {
6790-
ctx.beginPath();
6791-
ctx.strokeStyle = `rgb(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]})`;
6792-
ctx.fillStyle = fill ? `rgba(${this.randomTestingColors[0]}, ${this.randomTestingColors[1]}, ${this.randomTestingColors[2]}, 0.5)` : "transparent";
6793-
ctx.moveTo(this.worldVertices[0].x, this.worldVertices[0].y);
6794-
for (const vertex of this.worldVertices) {
6795-
ctx.lineTo(vertex.x, vertex.y);
6796-
}
6797-
ctx.closePath();
6798-
ctx.stroke();
6799-
ctx.fill();
6800-
}
68016787
if (this.top instanceof Game && this.top.devmode) {
6802-
const ctx2 = this.top.context;
6803-
if (ctx2) {
6804-
this.drawDebug(ctx2);
6788+
const ctx = this.top.context;
6789+
if (ctx) {
6790+
this.drawDebug(ctx);
68056791
}
68066792
}
68076793
}

0 commit comments

Comments
 (0)