1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-04-15 08:54:37 +00:00

Rest in peace, SwagCamera.

This commit is contained in:
EliteMasterEric 2024-02-13 01:38:11 -05:00
parent 0ff258ce75
commit f0b5ef4491
13 changed files with 49 additions and 125 deletions

View file

@ -11,7 +11,7 @@
"name": "flixel",
"type": "git",
"dir": null,
"ref": "07c6018008801972d12275690fc144fcc22e3de6",
"ref": "4d054bd10b05bb1309a0ba3427ffa5378e0b4b99",
"url": "https://github.com/FunkinCrew/flixel"
},
{

View file

@ -1,4 +1,4 @@
package funkin.graphics.framebuffer;
package funkin.graphics;
import flash.geom.ColorTransform;
import flixel.FlxCamera;
@ -8,6 +8,8 @@ import flixel.math.FlxMatrix;
import flixel.math.FlxRect;
import flixel.system.FlxAssets.FlxShader;
import funkin.graphics.shaders.RuntimeCustomBlendShader;
import funkin.graphics.framebuffer.BitmapDataUtil;
import funkin.graphics.framebuffer.FixedBitmapData;
import openfl.Lib;
import openfl.display.BitmapData;
import openfl.display.BlendMode;
@ -16,7 +18,11 @@ import openfl.filters.BitmapFilter;
import openfl.filters.ShaderFilter;
/**
* A camera, but grabbable. Also supports several additional blend modes.
* A FlxCamera with additional powerful features:
* - Grab the camera screen as a `BitmapData` and use it as a texture
* - Support `sprite.blend = DARKEN/HARDLIGHT/LIGHTEN/OVERLAY` to apply visual effects using certain sprites
* - NOTE: Several other blend modes work without FunkinCamera. Some still do not work.
* - NOTE: Framerate-independent camera tweening is fixed in Flixel 6.x. Rest in peace, SwagCamera.
*/
@:access(openfl.display.DisplayObject)
@:access(openfl.display.BitmapData)
@ -24,7 +30,7 @@ import openfl.filters.ShaderFilter;
@:access(openfl.display3D.textures.TextureBase)
@:access(flixel.graphics.FlxGraphic)
@:access(flixel.graphics.frames.FlxFrame)
class GrabbableCamera extends FlxCamera
class FunkinCamera extends FlxCamera
{
final grabbed:Array<BitmapData> = [];
final texturePool:Array<TextureBase> = [];
@ -39,6 +45,8 @@ class GrabbableCamera extends FlxCamera
var filtersApplied:Bool = false;
var bgItemCount:Int = 0;
public var shouldDraw:Bool = true;
public function new(x:Int = 0, y:Int = 0, width:Int = 0, height:Int = 0, zoom:Float = 0)
{
super(x, y, width, height, zoom);
@ -135,8 +143,8 @@ class GrabbableCamera extends FlxCamera
if (clearScreen)
{
// clear graphics data
// super.clearDrawStack();
// canvas.graphics.clear();
super.clearDrawStack();
canvas.graphics.clear();
}
// render the background bitmap
@ -169,6 +177,8 @@ class GrabbableCamera extends FlxCamera
override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false,
?shader:FlxShader):Void
{
if (!shouldDraw) return;
if ( switch blend
{
case DARKEN | HARDLIGHT | LIGHTEN | OVERLAY: true;

View file

@ -38,7 +38,8 @@ class PauseSubState extends MusicBeatSubState
var practiceText:FlxText;
var exitingToMenu:Bool = false;
public var exitingToMenu:Bool = false;
var bg:FlxSprite;
var metaDataGrp:FlxTypedGroup<FlxSprite>;

View file

@ -66,7 +66,7 @@ import funkin.ui.mainmenu.MainMenuState;
import funkin.ui.MusicBeatSubState;
import funkin.ui.options.PreferencesMenu;
import funkin.ui.story.StoryMenuState;
import funkin.ui.SwagCamera;
import funkin.graphics.FunkinCamera;
import funkin.ui.transition.LoadingState;
import funkin.util.SerializerUtil;
import haxe.Int64;
@ -420,7 +420,7 @@ class PlayState extends MusicBeatSubState
/**
* The camera which contains, and controls visibility of, the stage and characters.
*/
public var camGame:SwagCamera;
public var camGame:FlxCamera;
/**
* The camera which contains, and controls visibility of, a video cutscene.
@ -456,6 +456,17 @@ class PlayState extends MusicBeatSubState
return this.subState != null;
}
var isExitingViaPauseMenu(get, never):Bool;
function get_isExitingViaPauseMenu():Bool
{
if (this.subState == null) return false;
if (!Std.isOfType(this.subState, PauseSubState)) return false;
var pauseSubState:PauseSubState = cast this.subState;
return pauseSubState.exitingToMenu;
}
/**
* Data for the current difficulty for the current song.
* Includes chart data, scroll speed, and other information.
@ -1293,7 +1304,7 @@ class PlayState extends MusicBeatSubState
*/
function initCameras():Void
{
camGame = new SwagCamera();
camGame = new FlxCamera();
camGame.bgColor = BACKGROUND_COLOR; // Show a pink background behind the stage.
camHUD = new FlxCamera();
camHUD.bgColor.alpha = 0; // Show the game scene behind the camera.

View file

@ -352,11 +352,11 @@ class ResultState extends MusicBeatSubState
{
if (params.storyMode)
{
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.story.StoryMenuState(sticker)));
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new StoryMenuState(sticker)));
}
else
{
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.story.FreeplayState(null, sticker)));
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new FreeplayState(null, sticker)));
}
}

View file

@ -4,7 +4,7 @@ import openfl.display.BlendMode;
import funkin.graphics.framebuffer.FrameBufferManager;
import flixel.util.FlxColor;
import funkin.graphics.framebuffer.SpriteCopy;
import funkin.graphics.framebuffer.GrabbableCamera;
import funkin.graphics.FunkinCamera;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup;
@ -805,9 +805,9 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
*/
function grabScreen(applyFilters:Bool):BitmapData
{
if (Std.isOfType(FlxG.camera, GrabbableCamera))
if (Std.isOfType(FlxG.camera, FunkinCamera))
{
final cam:GrabbableCamera = cast FlxG.camera;
final cam:FunkinCamera = cast FlxG.camera;
return cam.grabScreen(applyFilters);
}
else

View file

@ -1,104 +0,0 @@
package funkin.ui;
import funkin.graphics.framebuffer.GrabbableCamera;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
import funkin.util.MathUtil;
class SwagCamera extends GrabbableCamera
{
/**
* properly follow framerate
* most of this just copied from FlxCamera,
* only lines 96 and 97 are changed
*/
override public function updateFollow():Void
{
// Either follow the object closely,
// or double check our deadzone and update accordingly.
if (deadzone == null)
{
target.getMidpoint(_point);
_point.addPoint(targetOffset);
focusOn(_point);
}
else
{
var edge:Float;
var targetX:Float = target.x + targetOffset.x;
var targetY:Float = target.y + targetOffset.y;
if (style == SCREEN_BY_SCREEN)
{
if (targetX >= (scroll.x + width))
{
_scrollTarget.x += width;
}
else if (targetX < scroll.x)
{
_scrollTarget.x -= width;
}
if (targetY >= (scroll.y + height))
{
_scrollTarget.y += height;
}
else if (targetY < scroll.y)
{
_scrollTarget.y -= height;
}
}
else
{
edge = targetX - deadzone.x;
if (_scrollTarget.x > edge)
{
_scrollTarget.x = edge;
}
edge = targetX + target.width - deadzone.x - deadzone.width;
if (_scrollTarget.x < edge)
{
_scrollTarget.x = edge;
}
edge = targetY - deadzone.y;
if (_scrollTarget.y > edge)
{
_scrollTarget.y = edge;
}
edge = targetY + target.height - deadzone.y - deadzone.height;
if (_scrollTarget.y < edge)
{
_scrollTarget.y = edge;
}
}
if ((target is FlxSprite))
{
if (_lastTargetPosition == null)
{
_lastTargetPosition = FlxPoint.get(target.x, target.y); // Creates this point.
}
_scrollTarget.x += (target.x - _lastTargetPosition.x) * followLead.x;
_scrollTarget.y += (target.y - _lastTargetPosition.y) * followLead.y;
_lastTargetPosition.x = target.x;
_lastTargetPosition.y = target.y;
}
if (followLerp >= 60 / FlxG.updateFramerate)
{
scroll.copyFrom(_scrollTarget); // no easing
}
else
{
// THIS THE PART THAT ACTUALLY MATTERS LOL
scroll.x = MathUtil.coolLerp(scroll.x, _scrollTarget.x, followLerp);
scroll.y = MathUtil.coolLerp(scroll.y, _scrollTarget.y, followLerp);
// scroll.x += (_scrollTarget.x - scroll.x) * MathUtil.cameraLerp(followLerp);
// scroll.y += (_scrollTarget.y - scroll.y) * MathUtil.cameraLerp(followLerp);
}
}
}
}

View file

@ -8,6 +8,7 @@ import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.graphics.FlxGraphic;
import flixel.group.FlxGroup.FlxTypedGroup;
import funkin.graphics.FunkinCamera;
import flixel.group.FlxSpriteGroup;
import flixel.input.keyboard.FlxKey;
import flixel.input.mouse.FlxMouseEvent;
@ -2071,7 +2072,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
loadPreferences();
uiCamera = new FlxCamera();
uiCamera = new FunkinCamera();
FlxG.cameras.reset(uiCamera);
buildDefaultSongData();
@ -5357,7 +5358,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// Kill and replace the UI camera so it doesn't get destroyed during the state transition.
uiCamera.kill();
FlxG.cameras.remove(uiCamera, false);
FlxG.cameras.reset(new FlxCamera());
FlxG.cameras.reset(new FunkinCamera());
this.persistentUpdate = false;
this.persistentDraw = false;

View file

@ -14,6 +14,7 @@ import flixel.group.FlxSpriteGroup;
import flixel.input.touch.FlxTouch;
import flixel.math.FlxAngle;
import flixel.math.FlxMath;
import funkin.graphics.FunkinCamera;
import flixel.math.FlxPoint;
import flixel.system.debug.watch.Tracker.TrackerProfile;
import flixel.text.FlxText;
@ -573,7 +574,7 @@ class FreeplayState extends MusicBeatSubState
var swag:Alphabet = new Alphabet(1, 0, "swag");
var funnyCam = new FlxCamera(0, 0, FlxG.width, FlxG.height);
var funnyCam = new FunkinCamera(0, 0, FlxG.width, FlxG.height);
funnyCam.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(funnyCam);

View file

@ -13,6 +13,7 @@ import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.input.touch.FlxTouch;
import flixel.text.FlxText;
import flixel.tweens.FlxEase;
import funkin.graphics.FunkinCamera;
import flixel.tweens.FlxTween;
import funkin.ui.MusicBeatState;
import flixel.util.FlxTimer;
@ -152,7 +153,7 @@ class MainMenuState extends MusicBeatState
function resetCamStuff()
{
FlxG.cameras.reset(new SwagCamera());
FlxG.cameras.reset(new FunkinCamera());
FlxG.camera.follow(camFollow, null, 0.06);
}

View file

@ -4,6 +4,7 @@ import funkin.util.InputUtil;
import flixel.FlxCamera;
import flixel.FlxObject;
import flixel.FlxSprite;
import funkin.graphics.FunkinCamera;
import flixel.group.FlxGroup;
import flixel.input.actions.FlxActionInput;
import flixel.input.gamepad.FlxGamepadInputID;
@ -47,7 +48,7 @@ class ControlsMenu extends funkin.ui.options.OptionsState.Page
{
super();
menuCamera = new FlxCamera();
menuCamera = new FunkinCamera();
FlxG.cameras.add(menuCamera, false);
menuCamera.bgColor = 0x0;
camera = menuCamera;

View file

@ -6,6 +6,7 @@ import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import funkin.ui.AtlasText.AtlasFont;
import funkin.ui.options.OptionsState.Page;
import funkin.graphics.FunkinCamera;
import funkin.ui.TextMenuList.TextMenuItem;
class PreferencesMenu extends Page
@ -20,7 +21,7 @@ class PreferencesMenu extends Page
{
super();
menuCamera = new SwagCamera();
menuCamera = new FunkinCamera();
FlxG.cameras.add(menuCamera, false);
menuCamera.bgColor = 0x0;
camera = menuCamera;

View file

@ -241,6 +241,7 @@ class StickerSubState extends MusicBeatSubState
if (ind == grpStickers.members.length - 1)
{
switchingState = true;
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;