Skip to content

Commit 4828e4f

Browse files
Finally fix songs starting instantly with cutscenes
and yes, you can put music in your cutscene now!!
1 parent 54ae535 commit 4828e4f

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

source/PlayState.hx

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class PlayState extends MusicBeatState
126126
var strumsHit:Array<Bool> = [false, false, false, false, false, false, false, false];
127127
public var splashesPerFrame:Array<Int> = [0, 0, 0, 0];
128128

129+
public var inst:FlxSound;
129130
public var vocals:FlxSound;
130131
public var opponentVocals:FlxSound;
131132
var intro3:FlxSound;
@@ -452,6 +453,7 @@ class PlayState extends MusicBeatState
452453

453454
override public function create()
454455
{
456+
FlxG.mouse.visible = false;
455457
//Stops playing on a height that isn't divisible by 2
456458
if (ClientPrefs.ffmpegMode && ClientPrefs.resolution != null) {
457459
var resolutionValue = cast(ClientPrefs.resolution, String);
@@ -2492,7 +2494,7 @@ class PlayState extends MusicBeatState
24922494
if (ffmpegMode) vocals.volume = opponentVocals.volume = 0;
24932495
Conductor.songPosition = time;
24942496
songTime = time;
2495-
clearNotesBefore(time);
2497+
if (time > 0) clearNotesBefore(time);
24962498
}
24972499

24982500
public function startNextDialogue() {
@@ -2513,12 +2515,12 @@ class PlayState extends MusicBeatState
25132515
var diff:String = (SONG.specialAudioName.length > 1 ? SONG.specialAudioName : CoolUtil.difficultyString()).toLowerCase();
25142516
@:privateAccess
25152517
if (!ffmpegMode) {
2516-
FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song, diff), 1, false);
2518+
FlxG.sound.playMusic(inst._sound, 1, false);
25172519
FlxG.sound.music.onComplete = finishSong.bind();
25182520
vocals.play();
25192521
opponentVocals.play();
25202522
} else {
2521-
FlxG.sound.playMusic(Paths.inst(PlayState.SONG.song, diff), 0, false);
2523+
FlxG.sound.playMusic(inst._sound, 0, false);
25222524
vocals.play(); vocals.volume = 0;
25232525
opponentVocals.play(); opponentVocals.volume = 0;
25242526
}
@@ -2528,10 +2530,7 @@ class PlayState extends MusicBeatState
25282530
FlxG.sound.music.pitch = playbackRate;
25292531
vocals.pitch = opponentVocals.pitch = playbackRate;
25302532

2531-
if(startOnTime > 0)
2532-
{
2533-
setSongTime(startOnTime - 500);
2534-
}
2533+
setSongTime(Math.max(0, startOnTime - 500) + Conductor.offset);
25352534
startOnTime = 0;
25362535

25372536
if(paused) {
@@ -2658,7 +2657,13 @@ class PlayState extends MusicBeatState
26582657
vocals.pitch = opponentVocals.pitch = playbackRate;
26592658
FlxG.sound.list.add(vocals);
26602659
FlxG.sound.list.add(opponentVocals);
2661-
FlxG.sound.list.add(new FlxSound().loadEmbedded(Paths.inst(PlayState.SONG.song, diff)));
2660+
inst = new FlxSound();
2661+
try
2662+
{
2663+
inst.loadEmbedded(Paths.inst(SONG.song, diff));
2664+
}
2665+
catch (e:Dynamic) {}
2666+
FlxG.sound.list.add(inst);
26622667

26632668
final noteData:Array<SwagSection> = SONG.notes;
26642669

@@ -3340,37 +3345,37 @@ class PlayState extends MusicBeatState
33403345
}
33413346
if (ClientPrefs.showNPS && (notesHitDateArray.length > 0 || oppNotesHitDateArray.length > 0)) {
33423347
notesToRemoveCount = 0;
3348+
var i = 0;
33433349

3344-
for (i in 0...notesHitDateArray.length) {
3350+
while (i < notesHitDateArray.length) {
33453351
if (!Math.isNaN(notesHitDateArray[i]) && (notesHitDateArray[i] + 1000 * npsSpeedMult < Conductor.songPosition)) {
33463352
notesToRemoveCount++;
33473353
}
3354+
i++;
33483355
}
33493356

33503357
if (notesToRemoveCount > 0) {
33513358
notesHitDateArray.splice(0, notesToRemoveCount);
33523359
notesHitArray.splice(0, notesToRemoveCount);
3353-
if (ClientPrefs.ratingCounter && judgeCountUpdateFrame <= 4 && judgementCounter != null) updateRatingCounter();
3354-
if (scoreTxtUpdateFrame <= 4 && scoreTxt != null) updateScore();
33553360
}
33563361

33573362
nps = 0;
3358-
for (value in notesHitArray) {
3363+
for (value in notesHitArray)
33593364
nps += value;
3360-
}
33613365

33623366
oppNotesToRemoveCount = 0;
3367+
i = 0;
33633368

3364-
for (i in 0...oppNotesHitDateArray.length) {
3365-
if (!Math.isNaN(notesHitDateArray[i]) && (oppNotesHitDateArray[i] + 1000 * npsSpeedMult < Conductor.songPosition)) {
3369+
while (i < oppNotesHitDateArray.length) {
3370+
if (!Math.isNaN(oppNotesHitDateArray[i]) && (oppNotesHitDateArray[i] + 1000 * npsSpeedMult < Conductor.songPosition)) {
33663371
oppNotesToRemoveCount++;
33673372
}
3373+
i++;
33683374
}
33693375

33703376
if (oppNotesToRemoveCount > 0) {
33713377
oppNotesHitDateArray.splice(0, oppNotesToRemoveCount);
33723378
oppNotesHitArray.splice(0, oppNotesToRemoveCount);
3373-
if (ClientPrefs.ratingCounter && judgeCountUpdateFrame <= 4 && judgementCounter != null) updateRatingCounter();
33743379
}
33753380

33763381
oppNPS = 0;
@@ -3384,28 +3389,9 @@ class PlayState extends MusicBeatState
33843389
if (nps > maxNPS) {
33853390
maxNPS = nps;
33863391
}
3387-
if (nps > oldNPS)
3388-
npsIncreased = true;
33893392

3390-
if (nps < oldNPS)
3391-
npsDecreased = true;
3392-
3393-
if (oppNPS > oldOppNPS)
3394-
oppNpsIncreased = true;
3395-
3396-
if (oppNPS < oldOppNPS)
3397-
oppNpsDecreased = true;
3398-
3399-
if (npsIncreased || npsDecreased || oppNpsIncreased || oppNpsDecreased) {
3400-
if (ClientPrefs.ratingCounter && judgeCountUpdateFrame <= 8 && judgementCounter != null) updateRatingCounter();
3401-
if (scoreTxtUpdateFrame <= 8 && scoreTxt != null) updateScore();
3402-
if (npsIncreased) npsIncreased = false;
3403-
if (npsDecreased) npsDecreased = false;
3404-
if (oppNpsIncreased) oppNpsIncreased = false;
3405-
if (oppNpsDecreased) oppNpsDecreased = false;
3406-
oldNPS = nps;
3407-
oldOppNPS = oppNPS;
3408-
}
3393+
if (ClientPrefs.ratingCounter && judgeCountUpdateFrame <= 8 && judgementCounter != null) updateRatingCounter();
3394+
if (scoreTxtUpdateFrame <= 8 && scoreTxt != null) updateScore();
34093395
}
34103396

34113397
if (ClientPrefs.showcaseMode && !ClientPrefs.charsAndBG) {
@@ -3636,7 +3622,7 @@ class PlayState extends MusicBeatState
36363622
Conductor.songPosition += elapsed * 1000 * playbackRate;
36373623
if (!ffmpegMode)
36383624
{
3639-
if (FlxG.sound.music.time > Conductor.offset)
3625+
if (Conductor.songPosition > Conductor.offset)
36403626
{
36413627
Conductor.songPosition = FlxMath.lerp(FlxG.sound.music.time + Conductor.offset, Conductor.songPosition, Math.exp(-elapsed * 5));
36423628
var timeDiff:Float = Math.abs((FlxG.sound.music.time + Conductor.offset) - Conductor.songPosition);
@@ -6726,17 +6712,28 @@ class PlayState extends MusicBeatState
67266712

67276713
ffmpegExists = true;
67286714

6729-
process = new Process('ffmpeg', ['-v', 'quiet', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s', lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height, '-r', Std.string(targetFPS), '-i', '-', '-c:v', ClientPrefs.vidEncoder, '-b', Std.string(ClientPrefs.renderBitrate * 1000000), 'assets/gameRenders/' + Paths.formatToSongPath(SONG.song) + '.mp4']);
6715+
var fileName = 'assets/gameRenders/' + Paths.formatToSongPath(SONG.song);
6716+
if(FileSystem.exists(fileName + '.mp4')) {
6717+
trace ('Duplicate video found! Adding anti-dupe...');
6718+
var dateNow:String = Date.now().toString();
6719+
dateNow = dateNow.replace(" ", "_");
6720+
dateNow = dateNow.replace(":", "'");
6721+
fileName += '-' + dateNow;
6722+
}
6723+
6724+
process = new Process('ffmpeg', ['-v', 'quiet', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s', lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height, '-r', Std.string(targetFPS), '-i', '-', '-c:v', ClientPrefs.vidEncoder, '-b', Std.string(ClientPrefs.renderBitrate * 1000000), fileName + '.mp4']);
67306725
FlxG.autoPause = false;
67316726
}
67326727

6728+
var img = null;
6729+
var bytes = null;
67336730
private function pipeFrame():Void
67346731
{
67356732
if (!ffmpegExists || process == null)
67366733
return;
67376734

6738-
var img = lime.app.Application.current.window.readPixels(new lime.math.Rectangle(FlxG.scaleMode.offset.x, FlxG.scaleMode.offset.y, FlxG.scaleMode.gameSize.x, FlxG.scaleMode.gameSize.y));
6739-
var bytes = img.getPixels(new lime.math.Rectangle(0, 0, img.width, img.height));
6735+
img = lime.app.Application.current.window.readPixels(new lime.math.Rectangle(FlxG.scaleMode.offset.x, FlxG.scaleMode.offset.y, FlxG.scaleMode.gameSize.x, FlxG.scaleMode.gameSize.y));
6736+
bytes = img.getPixels(new lime.math.Rectangle(0, 0, img.width, img.height));
67406737
process.stdin.writeBytes(bytes, 0, bytes.length);
67416738
}
67426739

0 commit comments

Comments
 (0)