Skip to content

Commit

Permalink
Make objects effects updated just before the rendering (like layers)
Browse files Browse the repository at this point in the history
* Update method names to make this very obvious
* Also fix wrong parameters
  • Loading branch information
4ian committed Aug 20, 2021
1 parent 4a98a4a commit 0572a4e
Show file tree
Hide file tree
Showing 40 changed files with 89 additions and 71 deletions.
6 changes: 3 additions & 3 deletions Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
_("Change the value of a parameter of an effect.") + "\n" +
_("You can find the parameter names (and change the effect "
"names) in the effects window."),
_("Set _PARAM2_ to _PARAM3_ for effect _PARAM3_ of _PARAM0_"),
_("Set _PARAM2_ to _PARAM3_ for effect _PARAM1_ of _PARAM0_"),
_("Effects"),
"res/actions/effect24.png",
"res/actions/effect.png")
Expand All @@ -1104,7 +1104,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
_("Change the value (string) of a parameter of an effect.") + "\n" +
_("You can find the parameter names (and change the effect "
"names) in the effects window."),
_("Set _PARAM2_ to _PARAM3_ for effect _PARAM3_ of _PARAM0_"),
_("Set _PARAM2_ to _PARAM3_ for effect _PARAM1_ of _PARAM0_"),
_("Effects"),
"res/actions/effect24.png",
"res/actions/effect.png")
Expand Down Expand Up @@ -1132,7 +1132,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
obj.AddCondition("IsEffectEnabled",
_("Effect is enabled"),
_("Check if the effect on an object is enabled."),
_("Effect _PARAM2_ on _PARAM1_ is enabled"),
_("Effect _PARAM1_ of _PARAM0_ is enabled"),
_("Effects"),
"res/actions/effect24.png",
"res/actions/effect.png")
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/adjustment-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const adjustmentFilter = new PIXI.filters.AdjustmentFilter();
return adjustmentFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const adjustmentFilter = (filter as unknown) as PIXI.filters.AdjustmentFilter;
if (parameterName === 'gamma') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/advanced-bloom-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const advancedBloomFilter = new PIXI.filters.AdvancedBloomFilter();
return advancedBloomFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const advancedBloomFilter = (filter as unknown) as PIXI.filters.AdvancedBloomFilter;
if (parameterName === 'threshold') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/ascii-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const asciiFilter = new PIXI.filters.AsciiFilter();
return asciiFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const asciiFilter = (filter as unknown) as PIXI.filters.AsciiFilter;
if (parameterName === 'size') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/bevel-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const bevelFilter = new PIXI.filters.BevelFilter();
return bevelFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const bevelFilter = (filter as unknown) as PIXI.filters.BevelFilter;
if (parameterName === 'rotation') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/black-and-white-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
colorMatrix.blackAndWhite(false);
return colorMatrix;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const colorMatrix = (filter as unknown) as PIXI.filters.ColorMatrixFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/blending-mode-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace gdjs {
const blendingModeFilter = new PIXI.filters.AlphaFilter();
return blendingModeFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const blendingModeFilter = (filter as unknown) as PIXI.filters.AlphaFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/blur-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace gdjs {
const blur = new PIXI.filters.BlurFilter();
return blur;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
if (
parameterName !== 'blur' &&
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/brightness-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
brightness.brightness(1, false);
return brightness;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const brightnessFilter = (filter as unknown) as PIXI.filters.ColorMatrixFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/bulge-pinch-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const bulgePinchFilter = new PIXI.filters.BulgePinchFilter();
return bulgePinchFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const bulgePinchFilter = (filter as unknown) as PIXI.filters.BulgePinchFilter;
if (parameterName === 'centerX') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/color-map-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace gdjs {
);
return colorMapFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const colorMapFilter = (filter as unknown) as PIXI.filters.ColorMapFilter;
if (parameterName === 'mix') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/color-replace-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const colorReplaceFilter = new PIXI.filters.ColorReplaceFilter();
return colorReplaceFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const colorReplaceFilter = (filter as unknown) as PIXI.filters.ColorReplaceFilter;
if (parameterName === 'epsilon') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/crt-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace gdjs {
crtFilter._animationTimer = 0;
return crtFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
if (filter.animationSpeed !== 0) {
// Multiply by 10 so that the default value is a sensible speed
filter.time +=
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/displacement-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace gdjs {
);
return displacementFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const displacementFilter = (filter as unknown) as PIXI.filters.DisplacementFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/dot-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const dotFilter = new PIXI.filters.DotFilter();
return dotFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const dotFilter = (filter as unknown) as PIXI.filters.DotFilter;
if (parameterName === 'scale') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/drop-shadow-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const dropShadowFilter = new PIXI.filters.DropShadowFilter();
return dropShadowFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'blur') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/glitch-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace gdjs {
glitchFilter._animationTimer = 0;
return glitchFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
if (filter.animationFrequency !== 0) {
filter._animationTimer += target.getElapsedTime() / 1000;
if (filter._animationTimer >= 1 / filter.animationFrequency) {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/glow-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const glowFilter = new PIXI.filters.GlowFilter();
return glowFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const glowFilter = (filter as unknown) as PIXI.filters.GlowFilter;
if (parameterName === 'innerStrength') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/godray-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
const godrayFilter = new PIXI.filters.GodrayFilter();
return godrayFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
if (filter.animationSpeed !== 0) {
filter.time += (target.getElapsedTime() / 1000) * filter.animationSpeed;
}
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/kawase-blur-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const kawaseBlurFilter = new PIXI.filters.KawaseBlurFilter();
return kawaseBlurFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const kawaseBlurFilter = (filter as unknown) as PIXI.filters.KawaseBlurFilter;
if (parameterName === 'pixelizeX') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/light-night-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace gdjs {
const filter = new gdjs.LightNightPixiFilter();
return filter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
if (parameterName !== 'opacity') {
return;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/night-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace gdjs {
const filter = new gdjs.NightPixiFilter();
return filter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
if (parameterName !== 'intensity' && parameterName !== 'opacity') {
return;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/noise-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace gdjs {
const noiseFilter = new PIXI.filters.NoiseFilter();
return noiseFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const noiseFilter = (filter as unknown) as PIXI.filters.NoiseFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/old-film-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace gdjs {
oldFilmFilter._animationTimer = 0;
return oldFilmFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
if (filter.animationFrequency !== 0) {
filter._animationTimer += target.getElapsedTime() / 1000;
if (filter._animationTimer >= 1 / filter.animationFrequency) {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/outline-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const outlineFilter = new PIXI.filters.OutlineFilter();
return outlineFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const outlineFilter = (filter as unknown) as PIXI.filters.OutlineFilter;
if (parameterName === 'thickness') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/pixelate-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
);
return pixelateFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const pixelateFilter = (filter as unknown) as PIXI.filters.PixelateFilter;
if (parameterName === 'size') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/radial-blur-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const radialBlurFilter = new PIXI.filters.RadialBlurFilter();
return radialBlurFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
const radialBlurFilter = (filter as unknown) as PIXI.filters.RadialBlurFilter;
radialBlurFilter.center[0] = Math.round(
// @ts-ignore - extra properties are stored on the filter.
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/reflection-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace gdjs {
);
return reflectionFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
if (filter.animationSpeed !== 0) {
filter.time += (target.getElapsedTime() / 1000) * filter.animationSpeed;
}
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/rgb-split-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const rgbSplitFilter = new PIXI.filters.RGBSplitFilter();
return rgbSplitFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const rgbSplitFilter = (filter as unknown) as PIXI.filters.RGBSplitFilter;
if (parameterName === 'redX') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/sepia-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
colorMatrixFilter.sepia(false);
return colorMatrixFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
// @ts-ignore - unsure why PIXI.filters is not recognised.
const colorMatrixFilter = (filter as unknown) as PIXI.filters.ColorMatrixFilter;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/tilt-shift-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const tiltShiftFilter = new PIXI.filters.TiltShiftFilter();
return tiltShiftFilter;
},
update: function (filter, target) {},
updatePreRender: function (filter, target) {},
updateDoubleParameter: function (filter, parameterName, value) {
const tiltShiftFilter = (filter as unknown) as PIXI.filters.TiltShiftFilter;
if (parameterName === 'blur') {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/twist-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace gdjs {
twistFilter.offset = new PIXI_.Point(0, 0);
return twistFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
const twistFilter = (filter as unknown) as PIXI.filters.TwistFilter;
twistFilter.offset.x = Math.round(
// @ts-ignore - extra properties are stored on the filter.
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Effects/zoom-blur-pixi-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace gdjs {
const zoomBlurFilter = new PIXI.filters.ZoomBlurFilter();
return zoomBlurFilter;
},
update: function (filter, target) {
updatePreRender: function (filter, target) {
const zoomBlurFilter = (filter as unknown) as PIXI.filters.ZoomBlurFilter;
zoomBlurFilter.center[0] = Math.round(
// @ts-ignore - extra properties are stored on the filter.
Expand Down
11 changes: 6 additions & 5 deletions Extensions/ExampleJsExtension/dummyeffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ namespace gdjs {
);
return filter;
},
// Function called at every frame rendered
update: function (filter, layer) {},
// If your filter depends on the time, you can get the elapsed time
// with `layer.getElapsedTime()`.
// You can update the uniforms or other state of the filter.
// Function called at every frame, after events and before the frame is rendered.
updatePreRender: function (filter, layer) {
// If your filter depends on the time, you can get the elapsed time
// with `layer.getElapsedTime()`.
// You can update the uniforms or other state of the filter.
},
// Function that will be called to update a (number) parameter of the PIXI filter with a new value
updateDoubleParameter: function (filter, parameterName, value) {
if (parameterName === 'opacity') {
Expand Down
2 changes: 1 addition & 1 deletion GDJS/Runtime/cocos-renderers/layer-cocos-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace gdjs {
this._cocosLayer.setVisible(visible);
}

update(): void {}
updatePreRender(): void {}

// Unimplemented
updateClearColor(): void {}
Expand Down
7 changes: 3 additions & 4 deletions GDJS/Runtime/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@ namespace gdjs {

/**
* Called at each frame, after events are run and before rendering.
* @param [runtimeScene] The scene the layer belongs to.
*/
update(runtimeScene?: gdjs.RuntimeScene): void {
updatePreRender(runtimeScene?: gdjs.RuntimeScene): void {
if (this._followBaseLayerCamera) {
this.followBaseLayer();
}
this._renderer.update();
this._effectsManager.update(this._rendererEffects, this);
this._renderer.updatePreRender();
this._effectsManager.updatePreRender(this._rendererEffects, this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace gdjs {
this._pixiContainer.visible = !!visible;
}

update(): void {
updatePreRender(): void {
if (this._renderTexture) {
this._updateRenderTexture();
}
Expand Down
13 changes: 8 additions & 5 deletions GDJS/Runtime/pixi-renderers/pixi-effects-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace gdjs {
updateDoubleParameter: filterCreator.updateDoubleParameter,
updateStringParameter: filterCreator.updateStringParameter,
updateBooleanParameter: filterCreator.updateBooleanParameter,
update: filterCreator.update,
updatePreRender: filterCreator.updatePreRender,
};

if (target.isLightingLayer && target.isLightingLayer()) {
Expand Down Expand Up @@ -81,13 +81,16 @@ namespace gdjs {

/**
* Update the filters applied on a PixiJS DisplayObject.
* @param runtimeObject
* @param target
* This must be called after the events and before the rendering.
*
* This allows effects to be sure that they are up to date and ready
* to render. This is not called on objects that are not rendered on screen
* ("culling"). This is always called on layers.
*/
update(rendererEffects: RendererEffects, target: EffectsTarget) {
updatePreRender(rendererEffects: RendererEffects, target: EffectsTarget) {
for (const filterName in rendererEffects) {
const filter = rendererEffects[filterName];
filter.update(filter.pixiFilter, target);
filter.updatePreRender(filter.pixiFilter, target);
}
}

Expand Down
Loading

0 comments on commit 0572a4e

Please sign in to comment.