diff --git a/source/Main.hx b/source/Main.hx index 42867cfe..43f207de 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -51,7 +51,6 @@ class InitState extends FlxState { override function update(elapsed:Float) { super.update(elapsed); var accept = Controls.getKey('ACCEPT-P'); - var back = Controls.getKey('BACK-P'); if (accept || Controls.getKey('BACK-P') && !selected) { selected = true; diff --git a/source/funkin/graphics/FlxRepeatSprite.hx b/source/funkin/graphics/FlxRepeatSprite.hx index e9b41c7a..ab45afd1 100644 --- a/source/funkin/graphics/FlxRepeatSprite.hx +++ b/source/funkin/graphics/FlxRepeatSprite.hx @@ -79,13 +79,15 @@ class FlxRepeatSprite extends FlxSpriteExt { } override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect { - if (newRect == null) newRect = FlxRect.get(); + if (newRect == null) newRect = CoolUtil.rect; if (camera == null) camera = FlxG.camera; + newRect.setPosition(x, y); _scaledOrigin.set(origin.x * scale.x, origin.y * scale.y); newRect.x += -Std.int(camera.scroll.x * scrollFactor.x) - offset.x + origin.x - _scaledOrigin.x; newRect.y += -Std.int(camera.scroll.y * scrollFactor.y) - offset.y + origin.y - _scaledOrigin.y; - newRect.setSize(repeatWidth, repeatHeight); + newRect.setSize(repeatWidth, repeatHeight); + return newRect.getRotatedBounds(angle, _scaledOrigin, newRect); } @@ -202,10 +204,15 @@ class FlxRepeatSprite extends FlxSpriteExt { if (tileRect != null) tileFrame = tileFrame.clipTo(tileRect); var lastMatrix = __lastMatrix; - if (doDraw && (lastMatrix.x != _matrix.tx || lastMatrix.y != _matrix.ty)) { - lastMatrix.set(_matrix.tx, _matrix.ty); + var mTx = _matrix.tx; + var mTy = _matrix.ty; + + if (doDraw && (lastMatrix.x != mTx || lastMatrix.y != mTy)) { + lastMatrix.set(mTx, mTy); translateWithTrig(-tileOffset.x, -tileOffset.y); - if (!matrixOutOfBounds(_matrix, tileFrame.frame, __drawCam)) // dont draw stuff out of bounds + + var frame = tileFrame.frame; + if (rectInBounds(mTx, mTy, frame.width, frame.height, __drawCam)) // dont draw stuff out of bounds drawTileToCamera(tileFrame, bitmap, _matrix, __drawCam); translateWithTrig(tileOffset.x, tileOffset.y); @@ -217,14 +224,8 @@ class FlxRepeatSprite extends FlxSpriteExt { camera.drawPixels(tileFrame, bitmap, tileMatrix, colorTransform, blend, antialiasing, shader); } - public var boundsOffsetX:Float = 0.0; - public var boundsOffsetY:Float = 0.0; - - inline function matrixOutOfBounds(matrix:FlxMatrix, frame:FlxRect, cam:FlxCamera):Bool { - return ((_matrix.ty + (frame.height * scale.y) - boundsOffsetY) < cam.viewY) || - ((_matrix.ty - (frame.height * scale.y) + boundsOffsetY) > cam.viewHeight) || - ((_matrix.tx + (frame.width * scale.x) - boundsOffsetX) < cam.viewX) || - ((_matrix.tx - (frame.width * scale.x) + boundsOffsetX) > cam.viewWidth); + inline function rectInBounds(x:Float, y:Float, w:Float, h:Float, cam:FlxCamera):Bool { + return cam.containsRect(CoolUtil.rect.set(x, y, w * Math.abs(scale.x), h * Math.abs(scale.y))); } function handleClipRect(tileFrame:FlxFrame, baseFrame:FlxFrame, tilePos:FlxPoint) { diff --git a/source/funkin/graphics/FlxSpriteExt.hx b/source/funkin/graphics/FlxSpriteExt.hx index 55c46521..883dcfb5 100644 --- a/source/funkin/graphics/FlxSpriteExt.hx +++ b/source/funkin/graphics/FlxSpriteExt.hx @@ -240,11 +240,25 @@ class FlxSpriteExt extends FlxSkewedSprite { public override function getScreenBounds(?rect:FlxRect, ?cam:FlxCamera):FlxRect { if (flippedOffsets) { scale.x = -scale.x; - final bounds = super.getScreenBounds(rect, cam); + var bounds = __superGetScreenBounds(rect, cam); scale.x = -scale.x; return bounds; } - return super.getScreenBounds(rect, cam); + return __superGetScreenBounds(rect, cam); + } + + @:noCompletion + private inline function __superGetScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect { + if (newRect == null) newRect = CoolUtil.rect; + if (camera == null) camera = FlxG.camera; + + newRect.setPosition(x, y); + _scaledOrigin.set(origin.x * scale.x, origin.y * scale.y); + newRect.x += -Std.int(camera.scroll.x * scrollFactor.x) - offset.x + origin.x - _scaledOrigin.x; + newRect.y += -Std.int(camera.scroll.y * scrollFactor.y) - offset.y + origin.y - _scaledOrigin.y; + newRect.setSize(frameWidth * Math.abs(scale.x), frameHeight * Math.abs(scale.y)); + + return newRect.getRotatedBounds(angle, _scaledOrigin, newRect); } public function switchAnim(anim1:String, anim2:String):Void { diff --git a/source/funkin/states/editors/chart/ChartGridBase.hx b/source/funkin/states/editors/chart/ChartGridBase.hx index 49c22957..c1eef59f 100644 --- a/source/funkin/states/editors/chart/ChartGridBase.hx +++ b/source/funkin/states/editors/chart/ChartGridBase.hx @@ -248,7 +248,6 @@ class ChartSustain extends Sustain { angle = 0; flipX = false; active = false; - boundsOffsetY = -FlxG.height; } public var chartData:Null> = null; diff --git a/source/funkin/util/CoolUtil.hx b/source/funkin/util/CoolUtil.hx index 592b5c22..03627475 100644 --- a/source/funkin/util/CoolUtil.hx +++ b/source/funkin/util/CoolUtil.hx @@ -41,6 +41,7 @@ class CoolUtil { } public static var point:FlxPoint = FlxPoint.get(); // Global FlxPoint for quick calculations + public static var rect:FlxRect = FlxRect.get(); // Global FlxRect for quick calculations inline public static function openUrl(url:String) { #if linux