Skip to content

Commit

Permalink
Add experimental support for multiplayer games ("GDevelop Multiplayer…
Browse files Browse the repository at this point in the history
…") (#6613)
  • Loading branch information
ClementPasteau authored Jun 7, 2024
1 parent 7f2806b commit 3c5fee0
Show file tree
Hide file tree
Showing 108 changed files with 10,591 additions and 275 deletions.
14 changes: 14 additions & 0 deletions Extensions/3D/AmbientLight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace gdjs {
interface AmbientLightFilterNetworkSyncData {
i: number;
c: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::AmbientLight',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -86,6 +90,16 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): AmbientLightFilterNetworkSyncData {
return {
i: this.light.intensity,
c: this.light.color.getHex(),
};
}
updateFromNetworkSyncData(data: AmbientLightFilterNetworkSyncData) {
this.light.intensity = data.i;
this.light.color.setHex(data.c);
}
})();
}
})()
Expand Down
17 changes: 17 additions & 0 deletions Extensions/3D/BloomEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace gdjs {
interface BloomFilterNetworkSyncData {
s: number;
r: number;
t: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::Bloom',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -82,6 +87,18 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): BloomFilterNetworkSyncData {
return {
s: this.shaderPass.strength,
r: this.shaderPass.radius,
t: this.shaderPass.threshold,
};
}
updateFromNetworkSyncData(data: BloomFilterNetworkSyncData) {
this.shaderPass.strength = data.s;
this.shaderPass.radius = data.r;
this.shaderPass.threshold = data.t;
}
})();
}
})()
Expand Down
16 changes: 16 additions & 0 deletions Extensions/3D/BrightnessAndContrastEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace gdjs {
interface BrightnessAndContrastFilterNetworkSyncData {
b: number;
c: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::BrightnessAndContrast',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -73,6 +77,18 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): BrightnessAndContrastFilterNetworkSyncData {
return {
b: this.shaderPass.uniforms.brightness.value,
c: this.shaderPass.uniforms.contrast.value,
};
}
updateFromNetworkSyncData(
data: BrightnessAndContrastFilterNetworkSyncData
) {
this.shaderPass.uniforms.brightness.value = data.b;
this.shaderPass.uniforms.contrast.value = data.c;
}
})();
}
})()
Expand Down
106 changes: 106 additions & 0 deletions Extensions/3D/Cube3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ namespace gdjs {
bottom: 5,
};

type Cube3DObjectNetworkSyncDataType = {
w: number;
h: number;
d: number;
rx: number;
ry: number;
rz: number;
fo: 'Y' | 'Z';
bfu: 'X' | 'Y';
vfb: integer;
trfb: integer;
frn: [string, string, string, string, string, string];
mt: number;
};

type Cube3DObjectNetworkSyncData = ObjectNetworkSyncData &
Cube3DObjectNetworkSyncDataType;

/**
* Shows a 3D box object.
*/
Expand Down Expand Up @@ -402,6 +420,94 @@ namespace gdjs {
return true;
}

getObjectNetworkSyncData(): Cube3DObjectNetworkSyncData {
return {
...super.getObjectNetworkSyncData(),
w: this.getWidth(),
h: this.getHeight(),
d: this.getDepth(),
rx: this.getRotationX(),
ry: this.getRotationY(),
rz: this.getAngle(),
mt: this._materialType,
fo: this._facesOrientation,
bfu: this._backFaceUpThroughWhichAxisRotation,
vfb: this._visibleFacesBitmask,
trfb: this._textureRepeatFacesBitmask,
frn: this._faceResourceNames,
};
}

updateFromObjectNetworkSyncData(
networkSyncData: Cube3DObjectNetworkSyncData
): void {
super.updateFromObjectNetworkSyncData(networkSyncData);

if (networkSyncData.w !== undefined) {
this.setWidth(networkSyncData.w);
}
if (networkSyncData.h !== undefined) {
this.setHeight(networkSyncData.h);
}
if (networkSyncData.d !== undefined) {
this.setDepth(networkSyncData.d);
}
if (networkSyncData.rx !== undefined) {
this.setRotationX(networkSyncData.rx);
}
if (networkSyncData.ry !== undefined) {
this.setRotationY(networkSyncData.ry);
}
if (networkSyncData.rz !== undefined) {
this.setAngle(networkSyncData.rz);
}
if (networkSyncData.mt !== undefined) {
this._materialType = networkSyncData.mt;
}
if (networkSyncData.fo !== undefined) {
if (this._facesOrientation !== networkSyncData.fo) {
this.setFacesOrientation(networkSyncData.fo);
}
}
if (networkSyncData.bfu !== undefined) {
if (this._backFaceUpThroughWhichAxisRotation !== networkSyncData.bfu) {
this.setBackFaceUpThroughWhichAxisRotation(networkSyncData.bfu);
}
}
if (networkSyncData.vfb !== undefined) {
// If it is different, update all the faces.
if (this._visibleFacesBitmask !== networkSyncData.vfb) {
this._visibleFacesBitmask = networkSyncData.vfb;
for (let i = 0; i < this._faceResourceNames.length; i++) {
this._renderer.updateFace(i);
}
}
}
if (networkSyncData.trfb !== undefined) {
// If it is different, update all the faces.
if (this._textureRepeatFacesBitmask !== networkSyncData.trfb) {
this._textureRepeatFacesBitmask = networkSyncData.trfb;
for (let i = 0; i < this._faceResourceNames.length; i++) {
this._renderer.updateFace(i);
}
}
}
if (networkSyncData.frn !== undefined) {
// If one element is different, update all the faces.
if (
!this._faceResourceNames.every(
(value, index) => value === networkSyncData.frn[index]
)
) {
this._faceResourceNames = networkSyncData.frn;
// Update all faces. (Could optimize to only update the changed ones)
for (let i = 0; i < this._faceResourceNames.length; i++) {
this._renderer.updateFace(i);
}
}
}
}

/**
* Return true if the texture transparency should be enabled.
*/
Expand Down
24 changes: 24 additions & 0 deletions Extensions/3D/DirectionalLight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace gdjs {
interface DirectionalLightFilterNetworkSyncData {
i: number;
c: number;
e: number;
r: number;
t: string;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::DirectionalLight',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -118,6 +125,23 @@ namespace gdjs {
this.rotationObject.rotation.z = -gdjs.toRad(this.elevation);
}
}
getNetworkSyncData(): DirectionalLightFilterNetworkSyncData {
return {
i: this.light.intensity,
c: this.light.color.getHex(),
e: this.elevation,
r: this.rotation,
t: this.top,
};
}
updateFromNetworkSyncData(syncData: any): void {
this.light.intensity = syncData.i;
this.light.color.setHex(syncData.c);
this.elevation = syncData.e;
this.rotation = syncData.r;
this.top = syncData.t;
this.updateRotation();
}
})();
}
})()
Expand Down
16 changes: 16 additions & 0 deletions Extensions/3D/ExponentialFog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace gdjs {
interface ExponentialFogFilterNetworkSyncData {
d: number;
c: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::ExponentialFog',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -83,6 +87,18 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): ExponentialFogFilterNetworkSyncData {
return {
d: this.fog.density,
c: this.fog.color.getHex(),
};
}
updateFromNetworkSyncData(
syncData: ExponentialFogFilterNetworkSyncData
): void {
this.fog.density = syncData.d;
this.fog.color.setHex(syncData.c);
}
})();
}
})()
Expand Down
11 changes: 11 additions & 0 deletions Extensions/3D/ExposureEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace gdjs {
interface ExposureFilterNetworkSyncData {
e: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::Exposure',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -67,6 +70,14 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): ExposureFilterNetworkSyncData {
return { e: this.shaderPass.uniforms.exposure.value };
}
updateFromNetworkSyncData(
syncData: ExposureFilterNetworkSyncData
): void {
this.shaderPass.uniforms.exposure.value = syncData.e;
}
})();
}
})()
Expand Down
29 changes: 29 additions & 0 deletions Extensions/3D/HemisphereLight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace gdjs {
interface HemisphereLightFilterNetworkSyncData {
i: number;
sc: number;
gc: number;
e: number;
r: number;
t: string;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::HemisphereLight',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -129,6 +137,27 @@ namespace gdjs {
this.rotationObject.rotation.z = -gdjs.toRad(this.elevation);
}
}
getNetworkSyncData(): HemisphereLightFilterNetworkSyncData {
return {
i: this.light.intensity,
sc: this.light.color.getHex(),
gc: this.light.groundColor.getHex(),
e: this.elevation,
r: this.rotation,
t: this.top,
};
}
updateFromNetworkSyncData(
syncData: HemisphereLightFilterNetworkSyncData
): void {
this.light.intensity = syncData.i;
this.light.color.setHex(syncData.sc);
this.light.groundColor.setHex(syncData.gc);
this.elevation = syncData.e;
this.rotation = syncData.r;
this.top = syncData.t;
this.updateRotation();
}
})();
}
})()
Expand Down
16 changes: 16 additions & 0 deletions Extensions/3D/HueAndSaturationEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace gdjs {
interface HueAndSaturationFilterExtra {
h: number;
s: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::HueAndSaturation',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -73,6 +77,18 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): HueAndSaturationFilterExtra {
return {
h: this.shaderPass.uniforms.hue.value,
s: this.shaderPass.uniforms.saturation.value,
};
}
updateFromNetworkSyncData(
syncData: HueAndSaturationFilterExtra
): void {
this.shaderPass.uniforms.hue.value = syncData.h;
this.shaderPass.uniforms.saturation.value = syncData.s;
}
})();
}
})()
Expand Down
19 changes: 19 additions & 0 deletions Extensions/3D/LinearFog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace gdjs {
interface LinearFogFilterNetworkSyncData {
n: number;
f: number;
c: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Scene3D::LinearFog',
new (class implements gdjs.PixiFiltersTools.FilterCreator {
Expand Down Expand Up @@ -87,6 +92,20 @@ namespace gdjs {
return 0;
}
updateBooleanParameter(parameterName: string, value: boolean): void {}
getNetworkSyncData(): LinearFogFilterNetworkSyncData {
return {
n: this.fog.near,
f: this.fog.far,
c: this.fog.color.getHex(),
};
}
updateFromNetworkSyncData(
data: LinearFogFilterNetworkSyncData
): void {
this.fog.near = data.n;
this.fog.far = data.f;
this.fog.color.setHex(data.c);
}
})();
}
})()
Expand Down
Loading

0 comments on commit 3c5fee0

Please sign in to comment.