cool stuff

This commit is contained in:
Yoshman29
2022-10-15 15:26:29 +02:00
parent 235b8c6838
commit ac243fec52
8 changed files with 167 additions and 49 deletions
+1 -1
View File
@@ -1 +1 @@
478 495
-1
View File
@@ -98,7 +98,6 @@ class MainMenuState extends MusicBeatState
FlxG.camera.follow(camFollow, null, 0.06); FlxG.camera.follow(camFollow, null, 0.06);
trace(funkin.macros.BuildCounterMacro.getBuildNumber());
var versionShit:FlxText = new FlxText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\nPre-Alpha: Build ${funkin.macros.BuildCounterMacro.getBuildNumber()}\n', 12); var versionShit:FlxText = new FlxText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\nPre-Alpha: Build ${funkin.macros.BuildCounterMacro.getBuildNumber()}\n', 12);
versionShit.scrollFactor.set(); versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
+2 -1
View File
@@ -48,6 +48,8 @@ class TitleState extends MusicBeatState
{ {
curWacky = FlxG.random.getObject(getIntroTextShit()); curWacky = FlxG.random.getObject(getIntroTextShit());
FlxTransitionableState.skipNextTransIn = true;
super.create(); super.create();
startIntro(); startIntro();
@@ -73,7 +75,6 @@ class TitleState extends MusicBeatState
FlxG.sound.playMusic(Paths.music('freakyMenu'), 0); FlxG.sound.playMusic(Paths.music('freakyMenu'), 0);
FlxG.sound.music.fadeIn(4, 0, 0.7); FlxG.sound.music.fadeIn(4, 0, 0.7);
} }
FlxTransitionableState.skipNextTransIn = true;
Conductor.changeBPM(102); Conductor.changeBPM(102);
persistentUpdate = true; persistentUpdate = true;
+69
View File
@@ -0,0 +1,69 @@
package funkin.system;
import lime.media.AudioManager;
import flixel.system.FlxSound;
import flixel.FlxState;
import funkin.windows.WindowsAPI;
import flixel.FlxG;
/**
* if youre stealing this keep this comment at least please lol
*
* hi gray itsa me yoshicrafter29 i fixed it hehe
*/
@:dox(hide)
class AudioSwitchFix {
@:noCompletion
private static function onStateSwitch(state:FlxState):Void {
#if windows
if (Main.audioDisconnected) {
var playingList:Array<PlayingSound> = [];
for(e in FlxG.sound.list) {
if (e.playing) {
playingList.push({
sound: e,
time: e.time
});
e.stop();
}
}
if (FlxG.sound.music != null)
FlxG.sound.music.stop();
AudioManager.shutdown();
AudioManager.init();
// #if !lime_doc_gen
// if (AudioManager.context.type == OPENAL)
// {
// var alc = AudioManager.context.openal;
// var device = alc.openDevice();
// var ctx = alc.createContext(device);
// alc.makeContextCurrent(ctx);
// alc.processContext(ctx);
// }
// #end
Main.changeID++;
for(e in playingList) {
e.sound.play(e.time);
}
Main.audioDisconnected = false;
}
#end
}
public static function init() {
#if windows
WindowsAPI.registerAudio();
FlxG.signals.preStateCreate.add(onStateSwitch);
#end
}
}
typedef PlayingSound = {
var sound:FlxSound;
var time:Float;
}
+11
View File
@@ -23,6 +23,17 @@ class CoolUtil
return v == null ? defaultValue : v; return v == null ? defaultValue : v;
} }
public static function getSizeString(size:UInt):String {
var labels = ["B", "KB", "MB", "GB", "TB"];
var rSize:Float = size;
var label:Int = 0;
while(rSize > 1024 && label < labels.length-1) {
label++;
rSize /= 1024;
}
return '${FlxMath.roundDecimal(rSize, 2)}${labels[label]}';
}
public static function fpsLerp(v1:Float, v2:Float, ratio:Float):Float { public static function fpsLerp(v1:Float, v2:Float, ratio:Float):Float {
return FlxMath.lerp(v1, v2, getFPSRatio(ratio)); return FlxMath.lerp(v1, v2, getFPSRatio(ratio));
} }
+79
View File
@@ -0,0 +1,79 @@
package funkin.system;
import lime.ui.KeyCode;
import openfl.ui.Keyboard;
import openfl.events.KeyboardEvent;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.system.System;
import openfl.display.Application;
import flixel.math.FlxMath;
import flixel.FlxG;
class FramerateField extends TextField {
public var showFPS:Bool = true;
public var showMemory:Bool = true;
public var showMemoryPeak:Bool = true;
/**
* Press F3 to enable
*/
public var debugMode:Bool = false;
public var peak:UInt = 0;
public var lastFPS:Float = 0;
public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
{
super();
this.x = x;
this.y = y;
selectable = false;
mouseEnabled = false;
defaultTextFormat = new TextFormat("_sans", 12, color);
autoSize = LEFT;
#if flash
addEventListener(Event.ENTER_FRAME, function(e)
{
var time = Lib.getTimer();
__enterFrame(time - currentTime);
});
#end
FlxG.stage.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent) {
switch(e.keyCode) {
case 114: // F3
debugMode = !debugMode;
}
});
}
public override function __enterFrame(t:Float) {
var text = [];
if (showFPS || debugMode) {
lastFPS = CoolUtil.fpsLerp(lastFPS, FlxG.elapsed == 0 ? 0 : (1 / FlxG.elapsed), 0.25);
text.push('FPS: ${Std.int(lastFPS)}');
}
if (showMemory || debugMode) {
text.push('RAM: ${CoolUtil.getSizeString(System.totalMemory)}');
}
if (showMemoryPeak || debugMode) {
if (peak < System.totalMemory)
peak = System.totalMemory;
text.push('RAM PEAK: (${CoolUtil.getSizeString(peak)})');
}
#if !release
text.push('CODENAME ENGINE ALPHA - BUILD ${funkin.macros.BuildCounterMacro.getBuildNumber()}');
#end
if (debugMode) {
text.push('System: ${lime.system.System.platformLabel} ${lime.system.System.platformVersion}');
text.push('Objs in state: ${FlxG.state.members.length}');
text.push('Nb cameras: ${FlxG.cameras.list.length}');
text.push('Current state: ${Type.getClassName(Type.getClass(FlxG.state))}');
}
this.text = text.join("\n");
}
}
+4 -45
View File
@@ -90,7 +90,7 @@ class Main extends Sprite
loadGameSettings(); loadGameSettings();
#if !mobile #if !mobile
addChild(new FPS(10, 3, 0xFFFFFF)); addChild(new FramerateField(10, 3, 0xFFFFFF));
#end #end
} }
@@ -98,47 +98,7 @@ class Main extends Sprite
public static var audioDisconnected:Bool = false; public static var audioDisconnected:Bool = false;
public static var changeID:Int = 0; public static var changeID:Int = 0;
@:dox(hide)
@:noCompletion
private function onStateSwitch(state:FlxState):Void {
#if windows
if (audioDisconnected) {
// for(e in lime.media.openal.AL.buffers) {
// lime.media.openal.AL.deleteBuffer(e);
// }
// lime.media.openal.AL.buffers = [];
// var buffers = [for(e in lime._internal.backend.native.NativeAudioSource.initBuffers) e];
// trace(buffers.length);
for(e in FlxG.sound.list) {
e.stop();
}
if (FlxG.sound.music != null)
FlxG.sound.music.stop();
#if !lime_doc_gen
if (lime.media.AudioManager.context.type == OPENAL)
{
var alc = lime.media.AudioManager.context.openal;
var device = alc.openDevice();
var ctx = alc.createContext(device);
alc.makeContextCurrent(ctx);
alc.processContext(ctx);
}
#end
changeID++;
// for(e in buffers) {
// @:privateAccess
// e.init();
// }
// lime._internal.backend.native.NativeAudioSource.initBuffers = [];
audioDisconnected = false;
}
#end
}
public function loadGameSettings() { public function loadGameSettings() {
funkin.options.PlayerSettings.init(); funkin.options.PlayerSettings.init();
@@ -165,11 +125,10 @@ class Main extends Sprite
FlxG.fixedTimestep = false; FlxG.fixedTimestep = false;
FlxG.autoPause = false; FlxG.autoPause = false;
FlxG.signals.preStateCreate.add(onStateSwitch);
Options.load(); Options.load();
WindowsAPI.registerAudio(); AudioSwitchFix.init();
// WindowsAPI.setAudioChangeCallback(function() { // WindowsAPI.setAudioChangeCallback(function() {
// trace("test"); // trace("test");
// }); // });
+1 -1
View File
@@ -114,7 +114,7 @@ class WinAPI {
if (!curAudioFix) curAudioFix = new AudioFixClient(); if (!curAudioFix) curAudioFix = new AudioFixClient();
') ')
public static function registerAudio() { public static function registerAudio() {
funkin.system.Main.audioDisconnected = true; funkin.system.Main.audioDisconnected = false;
} }
} }
#end #end