Skip to content

Commit

Permalink
tired of this bullshit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyrid19 committed Sep 7, 2024
1 parent b73bd31 commit 9509ff2
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 82 deletions.
8 changes: 7 additions & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
THEN UHHH I USED THE NAME OF THE FONT WITH SETFORMAT() ON THE TEXT!!!
NOT USING A DIRECT THING TO THE ASSET!!!
-->
<assets path="assets/fonts" embed='true'/>
<assets path="assets/fonts" embed='false' />

<!-- _______________________________ Libraries ______________________________ -->

Expand All @@ -113,6 +113,12 @@
<!--FlxPartialSound-->
<haxelib name="flxpartialsound" />

<!--HXSDL-->
<haxelib name="hxsdl" />

<!--Outlined OpenFL Text Fields-->
<haxelib name="stroked-textfield" />

<!-- <haxelib name="hxCodec" if="desktop || mobile" /> -->

<section if="cpp">
Expand Down
Binary file added assets/fonts/nokia.ttf
Binary file not shown.
10 changes: 10 additions & 0 deletions cmd/data/haxelibs.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"version": "",
"git": ""
},
{
"name": "hxsdl",
"version": "",
"git": ""
},
{
"name": "sscript",
"version": "",
Expand All @@ -69,6 +74,11 @@
"name": "flxpartialsound",
"version": "",
"git": "https://github.com/FunkinCrew/FlxPartialSound"
},
{
"name": "stroked-textfield",
"version": "",
"git": "https://github.com/Fyrid19/StrokedTextField"
}
]
}
25 changes: 8 additions & 17 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import openfl.net.NetStream;
import backend.framerate.FullFPS;
import backend.focus.FocusLost;

class Main extends Sprite
{
class Main extends Sprite {
var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = InitialState; // The FlxState the game starts with.
Expand All @@ -24,27 +23,21 @@ class Main extends Sprite

// You can pretty much ignore everything from here on - your code should go in your states.

public static function main():Void
{
public static function main():Void {
Lib.current.addChild(new Main());
}

public function new()
{
public function new() {
super();

if (stage != null)
{
if (stage != null) {
init();
}
else
{
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
}
}

private function init(?E:Event):Void
{
private function init(?E:Event):Void {
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
Expand All @@ -61,13 +54,11 @@ class Main extends Sprite
public static var fpsCounter:FullFPS;
public static var lostFocus:FocusLost;

private function setupGame():Void
{
private function setupGame():Void {
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;

if (zoom == -1)
{
if (zoom == -1) {
var ratioX:Float = stageWidth / gameWidth;
var ratioY:Float = stageHeight / gameHeight;
zoom = Math.min(ratioX, ratioY);
Expand Down
33 changes: 19 additions & 14 deletions source/backend/assets/FunkinAssets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,56 @@ package backend.assets;
import openfl.utils.Assets;
import flixel.graphics.FlxGraphic;
import openfl.display.BitmapData;
import openfl.system.System;

/**
* Funkin asset library, used for caching, returning files, and more.
*/
@:access(openfl.display.BitmapData)
class FunkinAssets {
public static var cache:FunkinCache;
private static var _cache:FunkinCache;

public function new() {
cache = new FunkinCache();
/**
* Initializes the asset cache
*/
public static function init() {
_cache = new FunkinCache();
trace('FunkinAssets initialized');
}

/**
* Clears both the sound and graphic caches
*/
@:access(flixel.system.frontEnds.BitmapFrontEnd._cache)
public static function clearCaches() {
OpenFlAssets.cache.clear('assets/songs');
Assets.cache.clear('assets/songs');
for (key in FlxG.bitmap._cache.keys()) {
if (!assetCache.graphicCache.exists(key)) {
if (!_cache.graphicCache.exists(key)) {
if (FlxG.bitmap.get(key).bitmap.__texture != null)
FlxG.bitmap.get(key).bitmap.__texture.dispose();
FlxG.bitmap.remove(FlxG.bitmap.get(key));
}
}
FlxG.bitmap.dumpCache(); // i am desperate to clean memory
assetCache.clearCaches();
_cache.clearCaches();
System.gc();
}

/**
* Returns a graphic from the current cache, if no graphic is found it caches a new one.
* Returns a graphic from the current _cache, if no graphic is found it caches a new one.
* @param Key The key of the graphic to return
* @return The cached graphic
*/
public static function getCacheGraphic(Key:String)
return cache.getGraphic(Key);
return _cache.getGraphic(Key);

/**
* Returns a sound from the current cache, if no sound is found it caches a new one.
* Returns a sound from the current _cache, if no sound is found it caches a new one.
* @param Key The key of the sound to return
* @return The cached sound
*/
public static function getCacheSound(Key:String)
return cache.getSound(Key);
return _cache.getSound(Key);

/**
* Returns a blank graphic.
Expand All @@ -58,7 +63,7 @@ class FunkinAssets {
* @param Color Color of the graphic
* @return The blank graphic that got created
*/
public static function makeGraphic(Width:Float = 10, Height:Float = 10, Color:FlxColor = FlxColor.WHITE) {
public static function makeGraphic(Width:Int = 10, Height:Int = 10, Color:FlxColor = FlxColor.WHITE) {
var graphicKey:String = Width + 'x' + Height + ':' + Color;
var bitmap:BitmapData = new BitmapData(1, 1, false);
bitmap.lock();
Expand All @@ -67,16 +72,16 @@ class FunkinAssets {
bitmap.height = Height;
bitmap.unlock();

var graphic:FlxGraphic = cache.getGraphic(graphicKey);
graphic != null ? return graphic : continue;
var graphic:FlxGraphic = _cache.getGraphic(graphicKey);
if (graphic != null) return graphic;

var graphic:FlxGraphic;
try (graphic = FlxGraphic.fromBitmapData(bitmap))
catch (e) {
trace('Graphic failed to load');
return null;
}
cache.cacheGraphic(graphicKey, graphic);
_cache.cacheGraphic(graphicKey, graphic);
return graphic;
}

Expand Down
26 changes: 16 additions & 10 deletions source/backend/framerate/EngineWatermark.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ import openfl.text.TextField;
import openfl.text.TextFormat;

class EngineWatermark extends Sprite {
var watermarkTxt:TextField;
var commitTxt:TextField;
var watermarkTxt:StrokedTextField;
var commitTxt:StrokedTextField;
public function new() {
super();

watermarkTxt = new TextField();
commitTxt = new TextField();
watermarkTxt = new StrokedTextField(FullFPS.fpsFontBytes);
commitTxt = new StrokedTextField(FullFPS.fpsFontBytes);

for(text in [watermarkTxt, commitTxt]) {
text.text = "";
text.autoSize = LEFT;
text.multiline = false;
text.defaultTextFormat = new TextFormat(FullFPS.fpsFont, 14, 0xFFFFFF);
addChild(text);
var col:Array<UInt> = FullFPS.fpsColors;
var alp:Array<Float> = [1, 1];
var rat:Array<Int> = [255, 255];
var mtx:Matrix = new Matrix();
mtx.createGradientBox(400, 125, Math.PI / 2, 0, 0);

for(text in [watermarkTxt, commitTxt]) {
addChild(text);
text.lineStyle(4, 0x000000);
text.gradientFill(GradientType.LINEAR, col, alp, rat, mtx, SpreadMethod.PAD);
text.fontSize = 14;
// text.update();
}

watermarkTxt.text = 'Prototype Engine ' + EngineMain.engineVer;
Expand Down
30 changes: 20 additions & 10 deletions source/backend/framerate/FPSCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,38 @@ import backend.framerate.FullFPS;
import openfl.system.System;

class FPSCounter extends Sprite {
public var fpsCountTxt:TextField;
public var fpsLabelTxt:TextField;
public var fpsCountTxt:StrokedTextField;
public var fpsLabelTxt:StrokedTextField;

private var times:Array<Float>;

public function new() {
super();

fpsCountTxt = new TextField();
fpsLabelTxt = new TextField();
fpsCountTxt = new StrokedTextField(FullFPS.fpsFontBytes);
fpsLabelTxt = new StrokedTextField(FullFPS.fpsFontBytes);

var col:Array<UInt> = FullFPS.fpsColors;
var alp:Array<Float> = [1, 1];
var rat:Array<Int> = [255, 255];
var mtx:Matrix = new Matrix();
mtx.createGradientBox(400, 125, Math.PI / 2, 0, 0);

for(text in [fpsCountTxt, fpsLabelTxt]) {
text.text = "";
text.autoSize = LEFT;
text.multiline = false;
addChild(text);
addChild(text);
text.lineStyle(4, 0x000000);
text.gradientFill(GradientType.LINEAR, col, alp, rat, mtx, SpreadMethod.PAD);
text.fontSize = 14;
// text.update();
}

fpsCountTxt.defaultTextFormat = new TextFormat(FullFPS.fpsFont, 18, 0xFFFFFF);
fpsLabelTxt.defaultTextFormat = new TextFormat(FullFPS.fpsFont, 14, 0xFFFFFF);
fpsCountTxt.fontSize = 18;
fpsLabelTxt.fontSize = 14;
fpsLabelTxt.text = "FPS";

fpsCountTxt.update();
fpsLabelTxt.update();

times = [];
}

Expand Down
9 changes: 7 additions & 2 deletions source/backend/framerate/FullFPS.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package backend.framerate;

import openfl.Assets;
import openfl.display.Sprite;
import openfl.utils.ByteArray;
import backend.framerate.FPSCounter;
import backend.framerate.MemoryCounter;
import backend.framerate.EngineWatermark;

class FullFPS extends Sprite {
public static var fpsFont:String;
public static var fpsFontBytes:ByteArray;

public static var fpsColors:Array<UInt> = [0xFFFFFF, 0xFFFFFF];

public var fpsCount:FPSCounter;
public var memCount:MemoryCounter;
Expand All @@ -18,14 +22,15 @@ class FullFPS extends Sprite {
public function new() {
super();

fpsFont = Assets.getFont('assets/fonts/vcr.ttf').fontName;
fpsFont = Assets.getFont(Paths.font('nokia.ttf')).fontName;
fpsFontBytes = Assets.getBytes(Paths.font('nokia.ttf'));

fpsCount = new FPSCounter();
memCount = new MemoryCounter();
watermark = new EngineWatermark();

memCount.y = fpsCount.y + fpsCount.height + 2;
watermark.y = memCount.y + memCount.height + fpsCount.height - 2;
watermark.y = memCount.y + memCount.height + fpsCount.height - 3;

addChild(fpsCount);
addChild(memCount);
Expand Down
22 changes: 15 additions & 7 deletions source/backend/framerate/MemoryCounter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import openfl.text.TextFormat;
import openfl.system.System;

class MemoryCounter extends Sprite {
public var memText:TextField;
public var memText:StrokedTextField;
public function new() {
super();

memText = new TextField();
memText.text = "";
memText.autoSize = LEFT;
memText.multiline = false;
memText.defaultTextFormat = new TextFormat(FullFPS.fpsFont, 14, 0xFFFFFF);
addChild(memText);
memText = new StrokedTextField(FullFPS.fpsFontBytes);
addChild(memText);
memText.lineStyle(4, 0x000000);

var col:Array<UInt> = FullFPS.fpsColors;
var alp:Array<Float> = [1, 1];
var rat:Array<Int> = [255, 255];
var mtx:Matrix = new Matrix();
mtx.createGradientBox(400, 125, Math.PI / 2, 0, 0);

memText.gradientFill(GradientType.LINEAR, col, alp, rat, mtx, SpreadMethod.PAD);

memText.fontSize = 14;
memText.mode = "outline";
}

private var memPeak:Float = 0;
Expand Down
6 changes: 6 additions & 0 deletions source/backend/framerate/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package backend.framerate;

import openfl.utils.Assets;
import openfl.geom.Matrix;
import openfl.display.SpreadMethod;
import openfl.display.GradientType;
2 changes: 1 addition & 1 deletion source/funkin/objects/notes/NoteNew.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NoteNew extends FlxSprite implements NoteBasic {
public var strumLine:StrumLine; // The strum line the note is assigned to

public var hasSustain:Bool; // If the note has a sustain trail or not
public var sustinLength:Float = 0; // Length of the note sustain
public var sustainLength:Float = 0; // Length of the note sustain

public var scoreMulti:Float = 1; // Note score multiplier

Expand Down
Loading

0 comments on commit 9509ff2

Please sign in to comment.