Skip to content

Commit 0b97a43

Browse files
committed
Merge branch 'main' into internal-merge
# Conflicts: # building/libs.xml # source/funkin/backend/FunkinText.hx
2 parents 21f57b3 + 6253269 commit 0b97a43

3 files changed

Lines changed: 100 additions & 177 deletions

File tree

source/funkin/backend/FunkinSprite.hx

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class FunkinSprite extends FlxAnimate implements IBeatReceiver implements IOffse
7878

7979
public var animateSettings:FlxAnimateSettings = {};
8080

81+
// originally used for zoom factor, now unused
8182
var _rect2:FlxRect;
8283

8384
public function new(?X:Float = 0, ?Y:Float = 0, ?SimpleGraphic:FlxGraphicAsset)
@@ -190,7 +191,6 @@ class FunkinSprite extends FlxAnimate implements IBeatReceiver implements IOffse
190191

191192
// ANIMATE ATLAS DRAWING
192193
#if REGION
193-
194194
public override function destroy()
195195
{
196196
if (animOffsets != null) {
@@ -208,48 +208,6 @@ class FunkinSprite extends FlxAnimate implements IBeatReceiver implements IOffse
208208
}
209209
#end
210210

211-
// ZOOM FACTOR
212-
private inline function __shouldDoZoomFactor()
213-
return zoomFactorEnabled && zoomFactor != 1;
214-
215-
private inline function __prepareZoomFactor(?rect:FlxRect, camera:FlxCamera):FlxRect {
216-
if (Flags.USE_LEGACY_ZOOM_FACTOR)
217-
return (rect ?? FlxRect.get()).set(
218-
camera.width * 0.5,
219-
camera.height * 0.5,
220-
(camera.scaleX > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleX, 1, zoomFactor)),
221-
(camera.scaleY > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleY, 1, zoomFactor))
222-
);
223-
else
224-
return (rect ?? FlxRect.get()).set(
225-
camera.width * 0.5 + camera.scroll.x * scrollFactor.x,
226-
camera.height * 0.5 + camera.scroll.y * scrollFactor.y,
227-
(camera.scaleX > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleX, 1, zoomFactor)),
228-
(camera.scaleY > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleY, 1, zoomFactor))
229-
);
230-
}
231-
232-
override public function isOnScreen(?camera:FlxCamera):Bool
233-
{
234-
if (forceIsOnScreen)
235-
return true;
236-
237-
if (camera == null)
238-
camera = FlxG.camera;
239-
240-
var bounds = getScreenBounds(_rect, camera);
241-
if (bounds.width == 0 && bounds.height == 0)
242-
return false;
243-
return camera.containsRect(bounds);
244-
}
245-
246-
private inline function __shouldDoAngleFactor()
247-
return angleFactorEnabled && angleFactor != 1;
248-
249-
private inline function __prepareAngleFactor(camera:FlxCamera):Float {
250-
return FlxMath.lerp(-camera.angle, 0, angleFactor);
251-
}
252-
253211
// OFFSETTING
254212
#if REGION
255213
public var animOffsets:Map<String, FlxPoint> = new Map<String, FlxPoint>();
@@ -379,22 +337,23 @@ class FunkinSprite extends FlxAnimate implements IBeatReceiver implements IOffse
379337
override function prepareDrawMatrix(matrix:FlxMatrix, camera:FlxCamera):Void {
380338
super.prepareDrawMatrix(matrix, camera);
381339

382-
if (__shouldDoZoomFactor() || __shouldDoAngleFactor()) {
383-
__prepareZoomFactor(_rect2, camera);
340+
final ox = camera.width * 0.5, oy = camera.height * 0.5;
341+
final sx = (camera.scaleX > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleX + zoomFactor);
342+
final sy = (camera.scaleY > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleY + zoomFactor);
384343

385-
if (__shouldDoZoomFactor()) {
386-
matrix.setTo(
387-
matrix.a * _rect2.width, matrix.b * _rect2.height,
388-
matrix.c * _rect2.width, matrix.d * _rect2.height,
389-
(matrix.tx - _rect2.x) * _rect2.width + _rect2.x,
390-
(matrix.ty - _rect2.y) * _rect2.height + _rect2.y
391-
);
392-
}
393-
if (__shouldDoAngleFactor()) {
394-
matrix.translate(-_rect2.x, -_rect2.y);
395-
matrix.rotate(FlxAngle.asRadians(__prepareAngleFactor(camera)));
396-
matrix.translate(_rect2.x, _rect2.y);
397-
}
344+
if (zoomFactorEnabled && zoomFactor != 1) {
345+
matrix.setTo(
346+
matrix.a * sx, matrix.b * sy,
347+
matrix.c * sx, matrix.d * sy,
348+
(matrix.tx - ox) * sx + ox,
349+
(matrix.ty - oy) * sy + oy
350+
);
351+
}
352+
353+
if (angleFactorEnabled && angleFactor != 1) {
354+
matrix.translate(-ox, -oy);
355+
matrix.rotate(-camera.angle * FlxAngle.TO_RAD * (1.0 - angleFactor));
356+
matrix.translate(ox, oy);
398357
}
399358
}
400359

Lines changed: 83 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package funkin.backend;
22

3+
import animate.FlxAnimate;
34
import flixel.FlxCamera;
45
import flixel.FlxG;
56
import flixel.math.FlxMath;
@@ -10,14 +11,17 @@ import flixel.math.FlxRect;
1011
import flixel.text.FlxText;
1112
import flixel.util.FlxColor;
1213
import flixel.graphics.frames.FlxFrame;
14+
1315
import funkin.backend.system.Flags;
1416

17+
@:access(animate.FlxAnimate)
1518
class FunkinText extends FlxText
1619
{
17-
public var zoomFactor:Float = 1;
18-
public var zoomFactorEnabled:Bool = true;
19-
public var angleFactor:Float = 1;
20-
public var angleFactorEnabled:Bool = true;
20+
public var zoomFactor:Float = 1;
21+
public var zoomFactorEnabled:Bool = true;
22+
23+
public var angleFactor:Float = 1;
24+
public var angleFactorEnabled:Bool = true;
2125

2226
/**
2327
* Change the skew of your sprite's graphic.
@@ -34,91 +38,45 @@ class FunkinText extends FlxText
3438
*/
3539
public var matrixExposed:Bool = false;
3640

37-
public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, ?Size:Int, Border:Bool = true)
38-
{
39-
if (Size == null)
40-
Size = Flags.DEFAULT_FONT_SIZE;
41-
42-
super(X, Y, FieldWidth, Text, Size);
41+
public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, ?Size:Int, Border:Bool = true)
42+
{
43+
if (Size == null) Size = Flags.DEFAULT_FONT_SIZE;
4344

44-
setFormat(Paths.font(Flags.DEFAULT_FONT), Size, FlxColor.WHITE);
45+
super(X, Y, FieldWidth, Text, Size);
4546

46-
if (Border)
47-
{
48-
borderStyle = OUTLINE;
49-
borderSize = 1;
50-
borderColor = 0xFF000000;
51-
}
52-
}
47+
setFormat(Paths.font(Flags.DEFAULT_FONT), Size, FlxColor.WHITE);
5348

54-
var _rect2:FlxRect;
49+
if (Border)
50+
{
51+
borderStyle = OUTLINE;
52+
borderSize = 1;
53+
borderColor = 0xFF000000;
54+
}
55+
}
5556

56-
override function initVars() {
57+
override function initVars()
58+
{
5759
super.initVars();
5860
skew = new FlxPoint();
5961
transformMatrix = new FlxMatrix();
60-
_rect2 = FlxRect.get();
6162
}
6263

63-
private inline function __shouldDoZoomFactor():Bool
64-
{
65-
return zoomFactorEnabled && zoomFactor != 1;
66-
}
67-
68-
private inline function __prepareZoomFactor(rect:FlxRect, camera:FlxCamera):FlxRect {
69-
if (Flags.USE_LEGACY_ZOOM_FACTOR)
70-
return rect.set(
71-
camera.width * 0.5,
72-
camera.height * 0.5,
73-
(camera.scaleX > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleX, 1, zoomFactor)),
74-
(camera.scaleY > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleY, 1, zoomFactor))
75-
);
76-
else
77-
return rect.set(
78-
camera.width * 0.5 + camera.scroll.x * scrollFactor.x,
79-
camera.height * 0.5 + camera.scroll.y * scrollFactor.y,
80-
(camera.scaleX > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleX, 1, zoomFactor)),
81-
(camera.scaleY > 0 ? Math.max : Math.min)(0, FlxMath.lerp(1 / camera.scaleY, 1, zoomFactor))
82-
);
64+
override function destroy()
65+
{
66+
super.destroy();
67+
skew = FlxDestroyUtil.put(skew);
68+
transformMatrix = null;
8369
}
8470

85-
private inline function __shouldDoAngleFactor():Bool
86-
{
87-
return angleFactorEnabled && angleFactor != 1;
88-
}
89-
90-
private inline function __prepareAngleFactor(camera:FlxCamera):Float
91-
{
92-
return FlxMath.lerp(-camera.angle, 0, angleFactor);
93-
}
94-
95-
// EVERYTHING AFTER THIS COMMENT IS STOLen from flixel animate ok sorry
96-
public override function drawComplex(camera:FlxCamera):Void
71+
override function drawComplex(camera:FlxCamera):Void
9772
{
98-
if (!__shouldDoZoomFactor() && !__shouldDoAngleFactor() && (skew.x == 0) && (skew.y == 0)) {
99-
return super.drawComplex(camera);
100-
}
101-
102-
final frame = this._frame;
103-
final matrix = this._matrix; // TODO: Just use local?
104-
105-
frame.prepareMatrix(matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY());
106-
prepareDrawMatrix(matrix, camera);
73+
_frame.prepareMatrix(_matrix, ANGLE_0, checkFlipX(), checkFlipY());
74+
_matrix.translate(-origin.x - _graphicOffset.x, -origin.y - _graphicOffset.y);
10775

108-
if (layer != null)
109-
layer.drawPixels(this, camera, frame, framePixels, matrix, colorTransform, blend, antialiasing, shaderEnabled ? shader : null,
110-
wrapMode);
111-
else
112-
camera.drawPixels(frame, framePixels, matrix, colorTransform, blend, antialiasing, shaderEnabled ? shader : null, wrapMode);
113-
}
114-
115-
function prepareDrawMatrix(matrix:FlxMatrix, camera:FlxCamera):Void {
116-
matrix.translate(-origin.x, -origin.y);
11776
if (frameOffsetAngle != null && frameOffsetAngle != angle)
11877
{
11978
var angleOff = (frameOffsetAngle - angle) * FlxAngle.TO_RAD;
120-
var cos = Math.cos(angleOff);
121-
var sin = Math.sin(angleOff);
79+
var cos = Math.cos(angleOff), sin = Math.sin(angleOff);
12280
// cos doesnt need to be negated
12381
_matrix.rotateWithTrig(cos, -sin);
12482
_matrix.translate(-frameOffset.x, -frameOffset.y);
@@ -127,66 +85,75 @@ class FunkinText extends FlxText
12785
else
12886
_matrix.translate(-frameOffset.x, -frameOffset.y);
12987

130-
matrix.scale(scale.x, scale.y);
88+
_matrix.scale(scale.x, scale.y);
13189

132-
if (matrixExposed) matrix.concat(transformMatrix);
90+
if (matrixExposed) _matrix.concat(transformMatrix);
13391
else {
13492
if (angle != 0)
13593
{
13694
updateTrig();
137-
matrix.rotateWithTrig(_cosAngle, _sinAngle);
95+
_matrix.rotateWithTrig(_cosAngle, _sinAngle);
13896
}
13997
if (skew.x != 0 || skew.y != 0)
14098
{
141-
updateSkew();
142-
matrix.concat(_skewMatrix);
99+
FlxAnimate._skewMatrix.setTo(1, Math.tan(skew.y * FlxAngle.TO_RAD), Math.tan(skew.x * FlxAngle.TO_RAD), 1, 0, 0);
100+
_matrix.concat(FlxAnimate._skewMatrix);
143101
}
144102
}
145103

146-
getScreenPosition(_point, camera).subtractPoint(offset).add(origin.x, origin.y);
147-
matrix.translate(_point.x, _point.y);
104+
getScreenPosition(_point, camera).subtractPoint(offset).addPoint(origin);
105+
_matrix.translate(_point.x, _point.y);
148106

149107
if (isPixelPerfectRender(camera))
150-
preparePixelPerfectMatrix(matrix);
151-
152-
if (__shouldDoZoomFactor() || __shouldDoAngleFactor()) {
153-
__prepareZoomFactor(_rect2, camera);
154-
155-
if (__shouldDoZoomFactor()) {
156-
matrix.setTo(
157-
matrix.a * _rect2.width, matrix.b * _rect2.height,
158-
matrix.c * _rect2.width, matrix.d * _rect2.height,
159-
(matrix.tx - _rect2.x) * _rect2.width + _rect2.x,
160-
(matrix.ty - _rect2.y) * _rect2.height + _rect2.y
161-
);
162-
}
163-
if (__shouldDoAngleFactor()) {
164-
matrix.translate(-_rect2.x, -_rect2.y);
165-
matrix.rotate(FlxAngle.asRadians(__prepareAngleFactor(camera)));
166-
matrix.translate(_rect2.x, _rect2.y);
167-
}
108+
{
109+
_matrix.tx = Math.floor(_matrix.tx);
110+
_matrix.ty = Math.floor(_matrix.ty);
168111
}
169-
}
170112

171-
function preparePixelPerfectMatrix(matrix:FlxMatrix):Void
172-
{
173-
matrix.tx = Math.floor(matrix.tx);
174-
matrix.ty = Math.floor(matrix.ty);
175-
}
176-
177-
// semi stolen from FlxSkewedSprite
178-
static var _skewMatrix:FlxMatrix = new FlxMatrix();
113+
// Copied from FunkinSprite
114+
final ox = camera.width * 0.5, oy = camera.height * 0.5;
115+
final sx = (camera.scaleX > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleX + zoomFactor);
116+
final sy = (camera.scaleY > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleY + zoomFactor);
117+
118+
if (zoomFactorEnabled && zoomFactor != 1) {
119+
matrix.setTo(
120+
matrix.a * sx, matrix.b * sy,
121+
matrix.c * sx, matrix.d * sy,
122+
(matrix.tx - ox) * sx + ox,
123+
(matrix.ty - oy) * sy + oy
124+
);
125+
}
179126

180-
private inline function updateSkew():Void
181-
{
182-
_skewMatrix.setTo(1, Math.tan(skew.y * FlxAngle.TO_RAD), Math.tan(skew.x * FlxAngle.TO_RAD), 1, 0, 0);
127+
if (angleFactorEnabled && angleFactor != 1) {
128+
matrix.translate(-ox, -oy);
129+
matrix.rotate(-camera.angle * FlxAngle.TO_RAD * (1.0 - angleFactor));
130+
matrix.translate(ox, oy);
131+
}
132+
133+
if (layer != null)
134+
layer.drawPixels(this, camera, _frame, framePixels, _matrix, colorTransform, blend, antialiasing, shaderEnabled ? shader : null);
135+
else
136+
camera.drawPixels(_frame, framePixels, _matrix, colorTransform, blend, antialiasing, shaderEnabled ? shader : null);
183137
}
184138

185-
public override function destroy()
139+
override function getScreenBounds(?rect:FlxRect, ?camera:FlxCamera):FlxRect
186140
{
187-
super.destroy();
188-
_rect2 = FlxDestroyUtil.put(_rect2);
189-
skew = FlxDestroyUtil.put(skew);
190-
transformMatrix = null;
141+
if (camera == null) camera = getDefaultCamera();
142+
rect = super.getScreenBounds(rect, camera);
143+
144+
if (zoomFactorEnabled && zoomFactor != 1) {
145+
final ox = camera.width * 0.5, oy = camera.height * 0.5;
146+
final sx = (camera.scaleX > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleX + zoomFactor);
147+
final sy = (camera.scaleY > 0.0 ? Math.max : Math.min)(0.0, (1.0 - zoomFactor) / camera.scaleY + zoomFactor);
148+
149+
rect.set(
150+
(rect.x - ox) * sx + ox,
151+
(rect.y - oy) * sy + oy,
152+
rect.width * sx,
153+
rect.height * sy
154+
);
155+
}
156+
157+
return rect;
191158
}
192-
}
159+
}

source/funkin/backend/system/Flags.hx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class Flags {
168168
public static var DEFAULT_CAM_ZOOM_LERP:Float = 0.05;
169169
public static var DEFAULT_HUD_ZOOM_LERP:Float = 0.05;
170170

171-
public static var USE_LEGACY_ZOOM_FACTOR:Null<Bool> = null;
172-
173171
// Font configuration
174172
public static var DEFAULT_FONT:String = "vcr.ttf";
175173
public static var DEFAULT_FONT_SIZE:Int = 16;
@@ -322,7 +320,6 @@ class Flags {
322320
if (MOD_API_VERSION == null) MOD_API_VERSION = CURRENT_API_VERSION;
323321
if (WINDOW_TITLE_USE_MOD_NAME == null) WINDOW_TITLE_USE_MOD_NAME = !overridenFlags.exists('TITLE') && overridenFlags.exists('MOD_NAME');
324322
if (USE_LEGACY_TIMING == null) USE_LEGACY_TIMING = MOD_API_VERSION < 2;
325-
if (USE_LEGACY_ZOOM_FACTOR == null) USE_LEGACY_ZOOM_FACTOR = MOD_API_VERSION < 2;
326323
if (SUSTAINS_AS_ONE_NOTE == null) SUSTAINS_AS_ONE_NOTE = MOD_API_VERSION >= 2;
327324
if (DEFAULT_GLSL_VERSION == null) {
328325
if (MOD_API_VERSION < 2) {

0 commit comments

Comments
 (0)