diff --git a/.gitignore b/.gitignore index 8f54cb6b..b77db02a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ export/ latest/windows/obj/ latest/windows/haxe/ -.vscode/ \ No newline at end of file +.vscode/ +**.png.bin \ No newline at end of file diff --git a/buildnumber.txt b/buildnumber.txt index 8fad7c29..c197cc7a 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1354 \ No newline at end of file +1369 \ No newline at end of file diff --git a/source/funkin/editors/CharacterEditor.hx b/source/funkin/editors/CharacterEditor.hx index faa5d8d2..87c5655a 100644 --- a/source/funkin/editors/CharacterEditor.hx +++ b/source/funkin/editors/CharacterEditor.hx @@ -20,7 +20,7 @@ class CharacterEditor extends MusicBeatState { public override function create() { super.create(); - add(new Stage("default")); + add(new Stage("stage")); character = new Character(770, 100, characterName, true); characterName = character.curCharacter; diff --git a/source/funkin/mods/ModsFolderLibrary.hx b/source/funkin/mods/ModsFolderLibrary.hx index d483d01d..dfe89cd2 100644 --- a/source/funkin/mods/ModsFolderLibrary.hx +++ b/source/funkin/mods/ModsFolderLibrary.hx @@ -1,5 +1,7 @@ package funkin.mods; +import funkin.options.Options; +import lime.graphics.ImageBuffer; import lime.utils.Log; import lime.utils.AssetLibrary; import lime.utils.Assets as LimeAssets; @@ -96,8 +98,23 @@ class ModsFolderLibrary extends AssetLibrary implements ModsAssetLibrary { var path = getAssetPath(); editedTimes[id] = FileSystem.stat(path).mtime.getTime(); - var e = Image.fromFile(path); - return e; + var buffer:ImageBuffer = null; + var image:Image; + if (Options.enablePngBins) { + if (PngBinHandler.exists(path)) { + buffer = PngBinHandler.loadBinPng(path); + @:privateAccess + image = new Image(buffer); + } else { + @:privateAccess + image = Image.fromFile(path); + PngBinHandler.saveBinPng(image.buffer, path); + } + } else { + @:privateAccess + image = Image.fromFile(path); + } + return image; } } diff --git a/source/funkin/mods/PngBinHandler.hx b/source/funkin/mods/PngBinHandler.hx new file mode 100644 index 00000000..257f1fcc --- /dev/null +++ b/source/funkin/mods/PngBinHandler.hx @@ -0,0 +1,47 @@ +package funkin.mods; + +import sys.FileSystem; +import lime.utils.UInt8Array; +import lime.graphics.ImageBuffer; +import openfl.utils.ByteArray; +import openfl.utils.Assets; +import sys.io.File; + +class PngBinHandler { + public static function loadBinPng(path:String) { + #if sys + var bytes = File.getBytes('$path.bin'); + + var width:Int = bytes.getInt32(0); + var height:Int = bytes.getInt32(4); + var bitsPerPixel:Int = bytes.getUInt16(8); + var pixelFormat:Int = bytes.getUInt16(10); + + var imageBuffer = new ImageBuffer(UInt8Array.fromBytes(bytes, 12), width, height, bitsPerPixel, pixelFormat); + + return imageBuffer; + #else + return null; + #end + } + + public static function saveBinPng(buffer:ImageBuffer, path:String) { + #if sys + var array = new ByteArrayData(buffer.data.length + 12); + array.writeInt(buffer.width); + array.writeInt(buffer.height); + array.writeShort(buffer.bitsPerPixel); + array.writeShort(buffer.format); + array.writeBytes(buffer.data.toBytes()); + File.saveBytes('$path.bin', array); + #end + } + + public static function exists(path:String) { + #if sys + return FileSystem.exists('$path.bin'); + #else + return false; + #end + } +} \ No newline at end of file diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index f67f479a..856fbe1d 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -21,6 +21,7 @@ class Options public static var fpsCounter:Bool = true; public static var autoPause:Bool = true; public static var antialiasing:Bool = true; + public static var enablePngBins:Bool = true; // optimization feature kinda which takes space on your computer! public static var volume:Float = 1; /**