From 8475a7d9f1bb058eefe6a0a163db8b8502bf538a Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Fri, 11 Aug 2023 13:48:36 +0200 Subject: [PATCH] Fixed bugs with cameras --- assets/shaders/engine/editorBlurFast.frag | 13 ++++++---- .../backend/system/framerate/ConductorInfo.hx | 4 +-- source/funkin/editors/EditorPicker.hx | 26 ++++++++++--------- .../editors/charter/CharterEventScreen.hx | 2 +- source/funkin/editors/ui/UIButtonList.hx | 9 +++++++ source/funkin/editors/ui/UIWarningSubstate.hx | 4 +-- source/funkin/menus/PauseSubState.hx | 1 - 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/assets/shaders/engine/editorBlurFast.frag b/assets/shaders/engine/editorBlurFast.frag index 6f497644..8abad7aa 100644 --- a/assets/shaders/engine/editorBlurFast.frag +++ b/assets/shaders/engine/editorBlurFast.frag @@ -10,11 +10,14 @@ float uBlur = 0.015; float uBrightness = 0.6; vec4 getColor(vec2 pos) { - if (pos.x < 0) pos.x = 0; - else if (pos.x > 1.0 - (1.0 / iResolution.x)) pos.x = 1.0 - (1.0 / iResolution.x); - if (pos.y < 0) pos.y = 0; - else if (pos.y > 1.0 - (1.0 / iResolution.y)) pos.y = 1.0 - (1.0 / iResolution.y); - return getTexture(bitmap, pos); + vec2 ps = camToOg(pos); + if (ps.x < 0) ps.x = 0; + //else if (ps.x > 1.0 - (1.0 / iResolution.x)) ps.x = 1.0 - (1.0 / iResolution.x); + else if (ps.x > 1.0) return vec4(0.0); + if (ps.y < 0) ps.y = 0; + //else if (ps.y > 1.0 - (1.0 / iResolution.y)) return ps.y = 1.0 - (1.0 / iResolution.y); + else if (ps.y > 1.0) return vec4(0.0); + return flixel_texture2D(bitmap, (ps)); } diff --git a/source/funkin/backend/system/framerate/ConductorInfo.hx b/source/funkin/backend/system/framerate/ConductorInfo.hx index eaec638f..cfe55664 100644 --- a/source/funkin/backend/system/framerate/ConductorInfo.hx +++ b/source/funkin/backend/system/framerate/ConductorInfo.hx @@ -8,13 +8,13 @@ class ConductorInfo extends FramerateCategory { public override function __enterFrame(t:Int) { if (alpha <= 0.05) return; - _text = 'Current Song Position: ${Conductor.songPosition}'; + _text = 'Current Song Position: ${Math.floor(Conductor.songPosition * 1000) / 1000}'; _text += '\n - ${Conductor.curBeat} beats'; _text += '\n - ${Conductor.curStep} steps'; _text += '\n - ${Conductor.curMeasure} measures'; _text += '\nCurrent BPM: ${Conductor.bpm}'; _text += '\nTime Signature: ${Conductor.beatsPerMesure}/${Conductor.stepsPerBeat}'; - + this.text.text = _text; super.__enterFrame(t); } diff --git a/source/funkin/editors/EditorPicker.hx b/source/funkin/editors/EditorPicker.hx index 52c74ae9..2ddd9435 100644 --- a/source/funkin/editors/EditorPicker.hx +++ b/source/funkin/editors/EditorPicker.hx @@ -39,7 +39,7 @@ class EditorPicker extends MusicBeatSubstate { public var curSelected:Int = 0; - + public var subCam:FlxCamera; public var oldMousePos:FlxPoint = FlxPoint.get(); public var curMousePos:FlxPoint = FlxPoint.get(); @@ -52,9 +52,9 @@ class EditorPicker extends MusicBeatSubstate { public override function create() { super.create(); - camera = new FlxCamera(); - camera.bgColor = 0; - FlxG.cameras.add(camera, false); + camera = subCam = new FlxCamera(); + subCam.bgColor = 0; + FlxG.cameras.add(subCam, false); bg = new FlxSprite().makeGraphic(1, 1, 0xFF000000); bg.scrollFactor.set(); @@ -72,7 +72,7 @@ class EditorPicker extends MusicBeatSubstate { } sprites[0].selected = true; - FlxG.mouse.getScreenPosition(camera, oldMousePos); + FlxG.mouse.getScreenPosition(subCam, oldMousePos); } public override function update(elapsed:Float) { @@ -82,12 +82,12 @@ class EditorPicker extends MusicBeatSubstate { if (selected) { camVelocity += FlxG.width * elapsed * 2; - camera.scroll.x += camVelocity * elapsed; + subCam.scroll.x += camVelocity * elapsed; return; } changeSelection(-FlxG.mouse.wheel + (controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); - FlxG.mouse.getScreenPosition(camera, curMousePos); + FlxG.mouse.getScreenPosition(subCam, curMousePos); if (curMousePos.x != oldMousePos.x || curMousePos.y != oldMousePos.y) { oldMousePos.set(curMousePos.x, curMousePos.y); curSelected = -1; @@ -102,13 +102,13 @@ class EditorPicker extends MusicBeatSubstate { MusicBeatState.skipTransIn = true; MusicBeatState.skipTransOut = true; - FlxG.sound.music.fadeOut(0.7, 0, function(n) { - FlxG.sound.music.stop(); - }); + if (FlxG.sound.music != null) + FlxG.sound.music.fadeOut(0.7, 0, function(n) { + FlxG.sound.music.stop(); + }); sprites[curSelected].flicker(function() { - if (FlxG.sound.music != null) - camera.fade(0xFF000000, 0.25, false, function() { + subCam.fade(0xFF000000, 0.25, false, function() { FlxG.switchState(Type.createInstance(options[curSelected].state, [])); }); }); @@ -126,6 +126,8 @@ class EditorPicker extends MusicBeatSubstate { oldMousePos.put(); curMousePos.put(); + + FlxG.cameras.remove(subCam); } public function changeSelection(change:Int) { diff --git a/source/funkin/editors/charter/CharterEventScreen.hx b/source/funkin/editors/charter/CharterEventScreen.hx index 3a6d0405..31b6e581 100644 --- a/source/funkin/editors/charter/CharterEventScreen.hx +++ b/source/funkin/editors/charter/CharterEventScreen.hx @@ -9,7 +9,7 @@ import flixel.util.FlxColor; using StringTools; class CharterEventScreen extends UISubstateWindow { - public var cam:FlxCamera; + //public var cam:FlxCamera; public var chartEvent:CharterEvent; public var step:Float = 0; diff --git a/source/funkin/editors/ui/UIButtonList.hx b/source/funkin/editors/ui/UIButtonList.hx index 4bfa7059..5e861eec 100644 --- a/source/funkin/editors/ui/UIButtonList.hx +++ b/source/funkin/editors/ui/UIButtonList.hx @@ -126,4 +126,13 @@ class UIButtonList extends UIWindow { buttonCameras.zoom = __lastDrawCameras[0].zoom; } } + + override function destroy() { + super.destroy(); + + if(buttonCameras != null) { + FlxG.cameras.remove(buttonCameras); + buttonCameras = null; + } + } } \ No newline at end of file diff --git a/source/funkin/editors/ui/UIWarningSubstate.hx b/source/funkin/editors/ui/UIWarningSubstate.hx index 4c02617a..b20e78f0 100644 --- a/source/funkin/editors/ui/UIWarningSubstate.hx +++ b/source/funkin/editors/ui/UIWarningSubstate.hx @@ -96,9 +96,7 @@ class UIWarningSubstate extends MusicBeatSubstate { this.buttons = buttons; } } -typedef WarningCamShader = { - var cam:FlxCamera; -} + typedef WarningButton = { var label:String; var onClick:UIWarningSubstate->Void; diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index 4de31238..e495269d 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -155,7 +155,6 @@ class PauseSubState extends MusicBeatSubstate } override function destroy() { - if(FlxG.cameras.list.contains(camera)) FlxG.cameras.remove(camera, true); pauseScript.call("onDestroy");