tried optimization thing but it didnt worked lol

This commit is contained in:
Yoshman29
2022-12-03 23:24:32 +01:00
parent 2255e251ac
commit e51b618baa
6 changed files with 71 additions and 5 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
export/
latest/windows/obj/
latest/windows/haxe/
.vscode/
.vscode/
**.png.bin
+1 -1
View File
@@ -1 +1 @@
1354
1369
+1 -1
View File
@@ -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;
+19 -2
View File
@@ -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;
}
}
+47
View File
@@ -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
}
}
+1
View File
@@ -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;
/**