Skip to content

Commit c022acd

Browse files
Simulation runtime
1 parent 758c382 commit c022acd

69 files changed

Lines changed: 4896 additions & 874 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Extensions/3D/A_RuntimeObject3D.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ namespace gdjs {
44

55
type Object3DNetworkSyncDataType = {
66
// z is position on the Z axis, different from zo, which is Z order
7-
z: number;
8-
d: number;
9-
rx: number;
10-
ry: number;
7+
z?: number;
8+
9+
d?: number;
10+
depth?: number;
11+
12+
rx?: number;
13+
rotationX?: number;
14+
1115
// no need for rz, as it is the angle from gdjs.RuntimeObject
12-
flipX: boolean;
13-
flipY: boolean;
14-
flipZ: boolean;
16+
ry?: number;
17+
rotationY?: number;
18+
19+
flipX?: boolean;
20+
flipY?: boolean;
21+
flipZ?: boolean;
1522
};
1623

1724
/** @category Objects > 3D Objects */
@@ -123,12 +130,14 @@ namespace gdjs {
123130
getNetworkSyncData(
124131
syncOptions: GetNetworkSyncDataOptions
125132
): Object3DNetworkSyncData {
133+
const getKey = (abbrev: string, full: string) =>
134+
syncOptions.useFullNames ? full : abbrev;
126135
return {
127136
...super.getNetworkSyncData(syncOptions),
128137
z: this.getZ(),
129-
d: this.getDepth(),
130-
rx: this.getRotationX(),
131-
ry: this.getRotationY(),
138+
[getKey('d', 'depth')]: this.getDepth(),
139+
[getKey('rx', 'rotationX')]: this.getRotationX(),
140+
[getKey('ry', 'rotationY')]: this.getRotationY(),
132141
flipX: this.isFlippedX(),
133142
flipY: this.isFlippedY(),
134143
flipZ: this.isFlippedZ(),

Extensions/3D/AmbientLight.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace gdjs {
22
interface AmbientLightFilterNetworkSyncData {
3-
i: number;
4-
c: number;
3+
i?: number;
4+
intensity?: number;
5+
6+
c?: number;
7+
color?: number;
58
}
69
gdjs.PixiFiltersTools.registerFilterCreator(
710
'Scene3D::AmbientLight',
@@ -88,15 +91,19 @@ namespace gdjs {
8891
return 0;
8992
}
9093
updateBooleanParameter(parameterName: string, value: boolean): void {}
91-
getNetworkSyncData(): AmbientLightFilterNetworkSyncData {
94+
getNetworkSyncData(
95+
syncOptions: GetNetworkSyncDataOptions
96+
): AmbientLightFilterNetworkSyncData {
97+
const getKey = (abbrev: string, full: string) =>
98+
syncOptions.useFullNames ? full : abbrev;
9299
return {
93-
i: this.light.intensity,
94-
c: this.light.color.getHex(),
95-
};
100+
[getKey('i', 'intensity')]: this.light.intensity,
101+
[getKey('c', 'color')]: this.light.color.getHex(),
102+
} as AmbientLightFilterNetworkSyncData;
96103
}
97104
updateFromNetworkSyncData(data: AmbientLightFilterNetworkSyncData) {
98-
this.light.intensity = data.i;
99-
this.light.color.setHex(data.c);
105+
if (data.i !== undefined) this.light.intensity = data.i;
106+
if (data.c !== undefined) this.light.color.setHex(data.c);
100107
}
101108
})();
102109
}

Extensions/3D/BloomEffect.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
namespace gdjs {
22
interface BloomFilterNetworkSyncData {
3-
s: number;
4-
r: number;
5-
t: number;
3+
s?: number;
4+
strength?: number;
5+
6+
r?: number;
7+
radius?: number;
8+
9+
t?: number;
10+
threshold?: number;
611
}
712
gdjs.PixiFiltersTools.registerFilterCreator(
813
'Scene3D::Bloom',
@@ -87,17 +92,21 @@ namespace gdjs {
8792
return 0;
8893
}
8994
updateBooleanParameter(parameterName: string, value: boolean): void {}
90-
getNetworkSyncData(): BloomFilterNetworkSyncData {
95+
getNetworkSyncData(
96+
syncOptions: GetNetworkSyncDataOptions
97+
): BloomFilterNetworkSyncData {
98+
const getKey = (abbrev: string, full: string) =>
99+
syncOptions.useFullNames ? full : abbrev;
91100
return {
92-
s: this.shaderPass.strength,
93-
r: this.shaderPass.radius,
94-
t: this.shaderPass.threshold,
95-
};
101+
[getKey('s', 'strength')]: this.shaderPass.strength,
102+
[getKey('r', 'radius')]: this.shaderPass.radius,
103+
[getKey('t', 'threshold')]: this.shaderPass.threshold,
104+
} as BloomFilterNetworkSyncData;
96105
}
97106
updateFromNetworkSyncData(data: BloomFilterNetworkSyncData) {
98-
this.shaderPass.strength = data.s;
99-
this.shaderPass.radius = data.r;
100-
this.shaderPass.threshold = data.t;
107+
if (data.s !== undefined) this.shaderPass.strength = data.s;
108+
if (data.r !== undefined) this.shaderPass.radius = data.r;
109+
if (data.t !== undefined) this.shaderPass.threshold = data.t;
101110
}
102111
})();
103112
}

Extensions/3D/BrightnessAndContrastEffect.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace gdjs {
22
interface BrightnessAndContrastFilterNetworkSyncData {
3-
b: number;
4-
c: number;
3+
b?: number;
4+
brightness?: number;
5+
6+
c?: number;
7+
contrast?: number;
58
}
69
gdjs.PixiFiltersTools.registerFilterCreator(
710
'Scene3D::BrightnessAndContrast',
@@ -77,17 +80,25 @@ namespace gdjs {
7780
return 0;
7881
}
7982
updateBooleanParameter(parameterName: string, value: boolean): void {}
80-
getNetworkSyncData(): BrightnessAndContrastFilterNetworkSyncData {
83+
getNetworkSyncData(
84+
syncOptions: GetNetworkSyncDataOptions
85+
): BrightnessAndContrastFilterNetworkSyncData {
86+
const getKey = (abbrev: string, full: string) =>
87+
syncOptions.useFullNames ? full : abbrev;
8188
return {
82-
b: this.shaderPass.uniforms.brightness.value,
83-
c: this.shaderPass.uniforms.contrast.value,
84-
};
89+
[getKey('b', 'brightness')]:
90+
this.shaderPass.uniforms.brightness.value,
91+
[getKey('c', 'contrast')]:
92+
this.shaderPass.uniforms.contrast.value,
93+
} as BrightnessAndContrastFilterNetworkSyncData;
8594
}
8695
updateFromNetworkSyncData(
8796
data: BrightnessAndContrastFilterNetworkSyncData
8897
) {
89-
this.shaderPass.uniforms.brightness.value = data.b;
90-
this.shaderPass.uniforms.contrast.value = data.c;
98+
if (data.b !== undefined)
99+
this.shaderPass.uniforms.brightness.value = data.b;
100+
if (data.c !== undefined)
101+
this.shaderPass.uniforms.contrast.value = data.c;
91102
}
92103
})();
93104
}

Extensions/3D/Cube3DRuntimeObject.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,25 @@ namespace gdjs {
4444
};
4545

4646
type Cube3DObjectNetworkSyncDataType = {
47-
fo: 'Y' | 'Z';
48-
bfu: 'X' | 'Y';
49-
vfb: integer;
50-
trfb: integer;
51-
frn: [string, string, string, string, string, string];
52-
mt: number;
53-
tint: string;
47+
fo?: 'Y' | 'Z';
48+
facesOrientation?: 'Y' | 'Z';
49+
50+
bfu?: 'X' | 'Y';
51+
backFaceUpThroughWhichAxisRotation?: 'X' | 'Y';
52+
53+
vfb?: integer;
54+
visibleFacesBitmask?: integer;
55+
56+
trfb?: integer;
57+
textureRepeatFacesBitmask?: integer;
58+
59+
frn?: [string, string, string, string, string, string];
60+
faceResourceNames?: [string, string, string, string, string, string];
61+
62+
mt?: number;
63+
materialType?: number;
64+
65+
tint?: string;
5466
};
5567

5668
type Cube3DObjectNetworkSyncData = Object3DNetworkSyncData &
@@ -460,14 +472,18 @@ namespace gdjs {
460472
getNetworkSyncData(
461473
syncOptions: GetNetworkSyncDataOptions
462474
): Cube3DObjectNetworkSyncData {
475+
const getKey = (abbrev: string, full: string) =>
476+
syncOptions.useFullNames ? full : abbrev;
463477
return {
464478
...super.getNetworkSyncData(syncOptions),
465-
mt: this._materialType,
466-
fo: this._facesOrientation,
467-
bfu: this._backFaceUpThroughWhichAxisRotation,
468-
vfb: this._visibleFacesBitmask,
469-
trfb: this._textureRepeatFacesBitmask,
470-
frn: this._faceResourceNames,
479+
[getKey('mt', 'materialType')]: this._materialType,
480+
[getKey('fo', 'facesOrientation')]: this._facesOrientation,
481+
[getKey('bfu', 'backFaceUpThroughWhichAxisRotation')]:
482+
this._backFaceUpThroughWhichAxisRotation,
483+
[getKey('vfb', 'visibleFacesBitmask')]: this._visibleFacesBitmask,
484+
[getKey('trfb', 'textureRepeatFacesBitmask')]:
485+
this._textureRepeatFacesBitmask,
486+
[getKey('frn', 'faceResourceNames')]: this._faceResourceNames,
471487
tint: this._tint,
472488
};
473489
}
@@ -510,13 +526,12 @@ namespace gdjs {
510526
}
511527
}
512528
if (networkSyncData.frn !== undefined) {
529+
const frn = networkSyncData.frn;
513530
// If one element is different, update all the faces.
514531
if (
515-
!this._faceResourceNames.every(
516-
(value, index) => value === networkSyncData.frn[index]
517-
)
532+
!this._faceResourceNames.every((value, index) => value === frn[index])
518533
) {
519-
this._faceResourceNames = networkSyncData.frn;
534+
this._faceResourceNames = frn;
520535
// Update all faces. (Could optimize to only update the changed ones)
521536
for (let i = 0; i < this._faceResourceNames.length; i++) {
522537
this._renderer.updateFace(i);

Extensions/3D/CustomRuntimeObject3D.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
namespace gdjs {
22
type CustomObject3DNetworkSyncDataType = {
3-
z: float;
4-
d: float;
5-
rx: float;
6-
ry: float;
7-
ifz: boolean;
8-
ccz: float;
3+
z?: float;
4+
5+
d?: float;
6+
depth?: float;
7+
8+
rx?: float;
9+
rotationX?: float;
10+
11+
ry?: float;
12+
rotationY?: float;
13+
14+
ifz?: boolean;
15+
isFlippedZ?: boolean;
16+
17+
ccz?: float;
18+
customCenterZ?: float;
919
};
1020

1121
type CustomObject3DNetworkSyncData = CustomObjectNetworkSyncData &
@@ -88,14 +98,16 @@ namespace gdjs {
8898
getNetworkSyncData(
8999
syncOptions: GetNetworkSyncDataOptions
90100
): CustomObject3DNetworkSyncData {
101+
const getKey = (abbrev: string, full: string) =>
102+
syncOptions.useFullNames ? full : abbrev;
91103
return {
92104
...super.getNetworkSyncData(syncOptions),
93105
z: this.getZ(),
94-
d: this.getDepth(),
95-
rx: this.getRotationX(),
96-
ry: this.getRotationY(),
97-
ifz: this.isFlippedZ(),
98-
ccz: this._customCenterZ,
106+
[getKey('d', 'depth')]: this.getDepth(),
107+
[getKey('rx', 'rotationX')]: this.getRotationX(),
108+
[getKey('ry', 'rotationY')]: this.getRotationY(),
109+
[getKey('ifz', 'isFlippedZ')]: this.isFlippedZ(),
110+
[getKey('ccz', 'customCenterZ')]: this._customCenterZ,
99111
};
100112
}
101113

Extensions/3D/DirectionalLight.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
namespace gdjs {
22
interface DirectionalLightFilterNetworkSyncData {
3-
i: number;
4-
c: number;
5-
e: number;
6-
r: number;
7-
t: string;
3+
i?: number;
4+
intensity?: number;
5+
6+
c?: number;
7+
color?: number;
8+
9+
e?: number;
10+
elevation?: number;
11+
12+
r?: number;
13+
rotation?: number;
14+
15+
t?: string;
16+
top?: string;
817
}
918
const shadowHelper = false;
1019
gdjs.PixiFiltersTools.registerFilterCreator(
@@ -258,21 +267,27 @@ namespace gdjs {
258267
this._light.castShadow = value;
259268
}
260269
}
261-
getNetworkSyncData(): DirectionalLightFilterNetworkSyncData {
270+
getNetworkSyncData(
271+
syncOptions: GetNetworkSyncDataOptions
272+
): DirectionalLightFilterNetworkSyncData {
273+
const getKey = (abbrev: string, full: string) =>
274+
syncOptions.useFullNames ? full : abbrev;
262275
return {
263-
i: this._light.intensity,
264-
c: this._light.color.getHex(),
265-
e: this._elevation,
266-
r: this._rotation,
267-
t: this._top,
268-
};
276+
[getKey('i', 'intensity')]: this._light.intensity,
277+
[getKey('c', 'color')]: this._light.color.getHex(),
278+
[getKey('e', 'elevation')]: this._elevation,
279+
[getKey('r', 'rotation')]: this._rotation,
280+
[getKey('t', 'top')]: this._top,
281+
} as DirectionalLightFilterNetworkSyncData;
269282
}
270-
updateFromNetworkSyncData(syncData: any): void {
271-
this._light.intensity = syncData.i;
272-
this._light.color.setHex(syncData.c);
273-
this._elevation = syncData.e;
274-
this._rotation = syncData.r;
275-
this._top = syncData.t;
283+
updateFromNetworkSyncData(
284+
syncData: DirectionalLightFilterNetworkSyncData
285+
): void {
286+
if (syncData.i !== undefined) this._light.intensity = syncData.i;
287+
if (syncData.c !== undefined) this._light.color.setHex(syncData.c);
288+
if (syncData.e !== undefined) this._elevation = syncData.e;
289+
if (syncData.r !== undefined) this._rotation = syncData.r;
290+
if (syncData.t !== undefined) this._top = syncData.t;
276291
}
277292
})();
278293
}

0 commit comments

Comments
 (0)