Skip to content

Commit ef0f139

Browse files
committed
Conductor fixes, cache update, PerformanceStats has outline
1 parent b7f3e47 commit ef0f139

5 files changed

Lines changed: 101 additions & 13 deletions

File tree

src/Main.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Main extends Sprite
4242
!flxGameData.showSplash, flxGameData.startFullscreen);
4343
addChild(flxGame);
4444

45-
performanceStats = new PerformanceStats(5, 5, 0xFFFFFF);
45+
performanceStats = new PerformanceStats(5, 5);
4646
addChild(performanceStats);
4747

4848
Assets.cache.enabled = false;

src/funkin/Conductor.hx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ class Conductor implements IFlxDestroyable
151151
recalculateBPMChangeCache();
152152
}
153153

154+
/**
155+
* Fully resets BPM Changes.
156+
*/
157+
public function resetBPMChanges():Void
158+
{
159+
var currentBPM:Float = bpmChangesLeft[0].bpm;
160+
var currentTimeSignature:{numerator:Float, denominator:Float} = bpmChangesLeft[0].timeSignature;
161+
setupBPMChanges([
162+
{
163+
bpm: currentBPM,
164+
time: 0,
165+
timeSignature: currentTimeSignature
166+
}
167+
]);
168+
}
169+
154170
/**
155171
* Updates the current conductor time.
156172
* @param songTime The time to set it to. If not specified the FlxG.sound.music time will be used instead.

src/funkin/objects/ui/PerformanceStats.hx

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package funkin.objects.ui;
22

33
import flixel.util.FlxStringUtil;
4+
import openfl.display.Sprite;
45
import openfl.text.TextField;
56
import openfl.text.TextFormat;
67

78
/**
89
* The performance stats TextField keeps track of FPS and Memory in-game.
910
*/
10-
class PerformanceStats extends TextField
11+
class PerformanceStats extends Sprite
1112
{
1213
/**
1314
* How many frames have passed since the last second.
@@ -19,23 +20,67 @@ class PerformanceStats extends TextField
1920
*/
2021
public var randomAccessMemory(get, null):Null<Float>;
2122

23+
/**
24+
* The main text that shows FPS and RAM Usage.
25+
*/
26+
public var mainText:TextField;
27+
28+
/**
29+
* The outline text group.
30+
*/
31+
public var outlineTextGrp:Sprite;
32+
2233
var cacheCount:Int;
2334
var currentTime:Float;
2435
var times:Array<Float>;
2536

26-
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
37+
public function new(x:Float = 10, y:Float = 10)
2738
{
2839
super();
40+
visible = true;
41+
42+
outlineTextGrp = new Sprite();
43+
addChild(outlineTextGrp);
44+
45+
mainText = new TextField();
46+
mainText.x = x;
47+
mainText.y = y;
48+
addChild(mainText);
49+
50+
var outlinePosArray:Array<Array<Int>> = [];
2951

30-
this.x = x;
31-
this.y = y;
52+
// stolen from FlxText
53+
outlinePosArray.push([-1, -1]); // upper-left
54+
outlinePosArray.push([1, 0]); // upper-middle
55+
outlinePosArray.push([1, 0]); // upper-right
56+
outlinePosArray.push([0, 1]); // middle-right
57+
outlinePosArray.push([0, 1]); // lower-right
58+
outlinePosArray.push([-1, 0]); // lower-middle
59+
outlinePosArray.push([-1, 0]); // lower-left
60+
outlinePosArray.push([0, -1]); // lower-left
61+
62+
for (pos in outlinePosArray)
63+
{
64+
var outlineText:TextField = new TextField();
65+
outlineText.x = x + pos[0];
66+
outlineText.y = y + pos[1];
67+
outlineTextGrp.addChild(outlineText);
68+
}
3269

3370
framesPerSecond = 0;
3471

35-
selectable = false;
72+
mainText.selectable = false;
3673
mouseEnabled = false;
37-
defaultTextFormat = new TextFormat(Paths.location.get('ui/fonts/vcr.ttf'), 12, color);
38-
text = '';
74+
mainText.defaultTextFormat = new TextFormat(Paths.location.get('ui/fonts/vcr.ttf'), 12, 0xFFFFFF);
75+
mainText.text = '';
76+
77+
for (i in 0...outlineTextGrp.numChildren)
78+
{
79+
var outlineText:TextField = cast outlineTextGrp.getChildAt(i);
80+
outlineText.selectable = false;
81+
outlineText.defaultTextFormat = new TextFormat(Paths.location.get('ui/fonts/vcr.ttf'), 12, 0x000000);
82+
outlineText.text = '';
83+
}
3984

4085
cacheCount = 0;
4186
currentTime = 0;
@@ -57,10 +102,18 @@ class PerformanceStats extends TextField
57102

58103
if (currentCount != cacheCount)
59104
{
60-
text = getFramesPerSecond() + getRandomAccessMemory();
105+
mainText.text = getFramesPerSecond() + getRandomAccessMemory();
106+
107+
for (i in 0...outlineTextGrp.numChildren)
108+
{
109+
var outlineText:TextField = cast outlineTextGrp.getChildAt(i);
110+
outlineText.text = getFramesPerSecond() + getRandomAccessMemory();
111+
}
61112
}
62113

63114
cacheCount = currentCount;
115+
116+
super.__enterFrame(cast deltaTime);
64117
}
65118

66119
function getFramesPerSecond():String

src/funkin/states/ui/FreeplayState.hx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ class FreeplayState extends FunkinState
318318

319319
if (curSelected == 0)
320320
{
321-
conductor.changeBPM(145, false);
321+
conductor.changeBPM(145);
322+
conductor.resetBPMChanges();
322323
var songPosToSetTo:Float = lastSongPos;
323324
lastSongPos = FlxG.sound.music.time;
324325
FlxG.sound.playMusic(Paths.content.audio('ui/freeplay/freeplayRandom'));
@@ -328,7 +329,8 @@ class FreeplayState extends FunkinState
328329
}
329330
else if (isRandomPlaying)
330331
{
331-
conductor.changeBPM(102, false);
332+
conductor.changeBPM(102);
333+
conductor.resetBPMChanges();
332334
var songPosToSetTo:Float = lastSongPos;
333335
lastSongPos = FlxG.sound.music?.time;
334336
FlxG.sound.playMusic(Paths.content.audio('ui/menu/freakyMenu'));
@@ -422,7 +424,8 @@ class FreeplayState extends FunkinState
422424
{
423425
if (isRandomPlaying)
424426
{
425-
conductor.changeBPM(102, false);
427+
conductor.changeBPM(102);
428+
conductor.resetBPMChanges();
426429
var songPosToSetTo:Float = lastSongPos;
427430
lastSongPos = FlxG.sound.music?.time;
428431
FlxG.sound.playMusic(Paths.content.audio('ui/menu/freakyMenu'));

src/funkin/util/paths/PathsCache.hx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class PathsCache
1818
{
1919
/**
2020
* The content that doesn't get wiped from a cache clean.
21+
* These can also be Flixel cache IDs!
2122
*
2223
* You should only put something here if you use it on a daily basis.
2324
*/
@@ -207,7 +208,22 @@ class PathsCache
207208
removeImage(image, bypassExcludeKeys);
208209
}
209210

210-
FlxG.bitmap.reset(); // Flixel likes to cache all texts and transitions, nothing wrong with it but this is a graphic clear.
211+
// Flixel likes to cache all texts and transitions, nothing wrong with it but this is a graphic clear.
212+
@:privateAccess
213+
if (FlxG.bitmap._cache != null)
214+
{
215+
for (key in FlxG.bitmap._cache.keys())
216+
{
217+
if (removeExcludeKeys.contains(key) && !bypassExcludeKeys)
218+
continue;
219+
220+
var obj:FlxGraphic = FlxG.bitmap.get(key);
221+
FlxG.bitmap.removeKey(key);
222+
223+
if (obj != null)
224+
obj.destroy();
225+
}
226+
}
211227

212228
if (runGarbageCollector)
213229
System.gc();

0 commit comments

Comments
 (0)