mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-11-01 17:04:49 +00:00
input accuracy testing
This commit is contained in:
parent
5778e979d9
commit
f3e0b0ec5b
|
|
@ -5,9 +5,12 @@ import flixel.FlxSubState;
|
|||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
import flixel.group.FlxGroup;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.system.FlxSound;
|
||||
import flixel.system.debug.stats.StatsGraph;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.util.FlxColor;
|
||||
import funkin.audiovis.PolygonSpectogram;
|
||||
import funkin.ui.CoolStatsGraph;
|
||||
import haxe.Timer;
|
||||
import openfl.events.KeyboardEvent;
|
||||
|
||||
|
|
@ -26,16 +29,47 @@ class LatencyState extends MusicBeatSubstate
|
|||
var beatTrail:FlxSprite;
|
||||
var diffGrp:FlxTypedGroup<FlxText>;
|
||||
var offsetsPerBeat:Array<Int> = [];
|
||||
var swagSong:HomemadeMusic;
|
||||
|
||||
var funnyStatsGraph:CoolStatsGraph;
|
||||
var realStats:CoolStatsGraph;
|
||||
|
||||
override function create()
|
||||
{
|
||||
swagSong = new HomemadeMusic();
|
||||
swagSong.loadEmbedded(Paths.sound('soundTest'), true);
|
||||
|
||||
FlxG.sound.music = swagSong;
|
||||
FlxG.sound.music.play();
|
||||
|
||||
funnyStatsGraph = new CoolStatsGraph(0, Std.int(FlxG.height / 2), FlxG.width, Std.int(FlxG.height / 2), FlxColor.PINK, "time");
|
||||
FlxG.addChildBelowMouse(funnyStatsGraph);
|
||||
|
||||
realStats = new CoolStatsGraph(0, Std.int(FlxG.height / 2), FlxG.width, Std.int(FlxG.height / 2), FlxColor.YELLOW, "REAL");
|
||||
FlxG.addChildBelowMouse(realStats);
|
||||
|
||||
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, key ->
|
||||
{
|
||||
trace(key.charCode);
|
||||
|
||||
if (key.charCode == 120)
|
||||
generateBeatStuff();
|
||||
|
||||
trace("\tEVENT PRESS: \t" + FlxG.sound.music.time + " " + Timer.stamp());
|
||||
// trace(FlxG.sound.music.prevTimestamp);
|
||||
trace(FlxG.sound.music.time);
|
||||
trace("\tFR FR PRESS: \t" + swagSong.getTimeWithDiff());
|
||||
|
||||
// trace("\tREDDIT: \t" + swagSong.frfrTime + " " + Timer.stamp());
|
||||
@:privateAccess
|
||||
trace("\tREDDIT: \t" + FlxG.sound.music._channel.position + " " + Timer.stamp());
|
||||
// trace("EVENT LISTENER: " + key);
|
||||
});
|
||||
|
||||
FlxG.sound.playMusic(Paths.sound('soundTest'));
|
||||
// FlxG.sound.playMusic(Paths.sound('soundTest'));
|
||||
|
||||
// funnyStatsGraph.hi
|
||||
|
||||
Conductor.bpm = 60;
|
||||
|
||||
noteGrp = new FlxTypedGroup<Note>();
|
||||
|
|
@ -121,29 +155,19 @@ class LatencyState extends MusicBeatSubstate
|
|||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
/* trace("1: " + swagSong.frfrTime);
|
||||
@:privateAccess
|
||||
trace(FlxG.sound.music._channel.position);
|
||||
*/
|
||||
|
||||
funnyStatsGraph.update(FlxG.sound.music.time % 500);
|
||||
realStats.update(swagSong.getTimeWithDiff() % 500);
|
||||
|
||||
if (FlxG.keys.justPressed.S)
|
||||
{
|
||||
trace("\tUPDATE PRESS: \t" + FlxG.sound.music.time + " " + Timer.stamp());
|
||||
}
|
||||
|
||||
if (FlxG.keys.justPressed.X)
|
||||
{
|
||||
var closestBeat:Int = Math.round(Conductor.songPosition / Conductor.crochet) % diffGrp.members.length;
|
||||
var getDiff:Float = Conductor.songPosition - (closestBeat * Conductor.crochet);
|
||||
getDiff -= Conductor.visualOffset;
|
||||
|
||||
// lil fix for end of song
|
||||
if (closestBeat == 0 && getDiff >= Conductor.crochet * 2)
|
||||
getDiff -= FlxG.sound.music.length;
|
||||
|
||||
trace("\tDISTANCE TO CLOSEST BEAT: " + getDiff + "ms");
|
||||
trace("\tCLOSEST BEAT: " + closestBeat);
|
||||
beatTrail.x = songPosVis.x;
|
||||
|
||||
diffGrp.members[closestBeat].text = getDiff + "ms";
|
||||
offsetsPerBeat[closestBeat] = Std.int(getDiff);
|
||||
}
|
||||
|
||||
if (FlxG.keys.justPressed.SPACE)
|
||||
{
|
||||
if (FlxG.sound.music.playing)
|
||||
|
|
@ -155,7 +179,8 @@ class LatencyState extends MusicBeatSubstate
|
|||
if (FlxG.keys.pressed.D)
|
||||
FlxG.sound.music.time += 1000 * FlxG.elapsed;
|
||||
|
||||
Conductor.songPosition = FlxG.sound.music.time - Conductor.offset;
|
||||
Conductor.songPosition = swagSong.getTimeWithDiff() - Conductor.offset;
|
||||
// Conductor.songPosition += (Timer.stamp() * 1000) - FlxG.sound.music.prevTimestamp;
|
||||
|
||||
songPosVis.x = songPosToX(Conductor.songPosition);
|
||||
songVisFollowAudio.x = songPosToX(Conductor.songPosition - Conductor.audioOffset);
|
||||
|
|
@ -230,8 +255,56 @@ class LatencyState extends MusicBeatSubstate
|
|||
super.update(elapsed);
|
||||
}
|
||||
|
||||
function generateBeatStuff()
|
||||
{
|
||||
Conductor.songPosition = swagSong.getTimeWithDiff();
|
||||
|
||||
var closestBeat:Int = Math.round(Conductor.songPosition / Conductor.crochet) % diffGrp.members.length;
|
||||
var getDiff:Float = Conductor.songPosition - (closestBeat * Conductor.crochet);
|
||||
getDiff -= Conductor.visualOffset;
|
||||
|
||||
// lil fix for end of song
|
||||
if (closestBeat == 0 && getDiff >= Conductor.crochet * 2)
|
||||
getDiff -= FlxG.sound.music.length;
|
||||
|
||||
trace("\tDISTANCE TO CLOSEST BEAT: " + getDiff + "ms");
|
||||
trace("\tCLOSEST BEAT: " + closestBeat);
|
||||
beatTrail.x = songPosVis.x;
|
||||
|
||||
diffGrp.members[closestBeat].text = getDiff + "ms";
|
||||
offsetsPerBeat[closestBeat] = Std.int(getDiff);
|
||||
}
|
||||
|
||||
function songPosToX(pos:Float):Float
|
||||
{
|
||||
return FlxMath.remapToRange(pos, 0, FlxG.sound.music.length, 0, FlxG.width);
|
||||
}
|
||||
}
|
||||
|
||||
class HomemadeMusic extends FlxSound
|
||||
{
|
||||
public var prevTimestamp:Int = 0;
|
||||
public var timeWithDiff:Float = 0;
|
||||
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
var prevTime:Float = 0;
|
||||
|
||||
override function update(elapsed:Float)
|
||||
{
|
||||
super.update(elapsed);
|
||||
if (prevTime != time)
|
||||
{
|
||||
prevTime = time;
|
||||
prevTimestamp = Std.int(Timer.stamp() * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTimeWithDiff():Float
|
||||
{
|
||||
return time + (Std.int(Timer.stamp() * 1000) - prevTimestamp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
162
source/funkin/ui/CoolStatsGraph.hx
Normal file
162
source/funkin/ui/CoolStatsGraph.hx
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
package funkin.ui;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormatAlign;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.system.debug.DebuggerUtil;
|
||||
import flixel.system.debug.stats.Stats;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
|
||||
/**
|
||||
* This is a helper function for the stats window to draw a graph with given values.
|
||||
* SHAMELESSLY STOLEN FROM FLIXEL
|
||||
* https://github.com/HaxeFlixel/flixel/blob/master/flixel/system/debug/stats/StatsGraph.hx
|
||||
*/
|
||||
#if FLX_DEBUG
|
||||
class CoolStatsGraph extends Sprite
|
||||
{
|
||||
static inline var AXIS_COLOR:FlxColor = 0xffffff;
|
||||
static inline var AXIS_ALPHA:Float = 0.5;
|
||||
static inline var HISTORY_MAX:Int = 500;
|
||||
|
||||
public var minLabel:TextField;
|
||||
public var curLabel:TextField;
|
||||
public var maxLabel:TextField;
|
||||
public var avgLabel:TextField;
|
||||
|
||||
public var minValue:Float = FlxMath.MAX_VALUE_FLOAT;
|
||||
public var maxValue:Float = FlxMath.MIN_VALUE_FLOAT;
|
||||
|
||||
public var graphColor:FlxColor;
|
||||
|
||||
public var history:Array<Float> = [];
|
||||
|
||||
var _axis:Shape;
|
||||
var _width:Int;
|
||||
var _height:Int;
|
||||
var _unit:String;
|
||||
var _labelWidth:Int;
|
||||
var _label:String;
|
||||
|
||||
public function new(X:Int, Y:Int, Width:Int, Height:Int, GraphColor:FlxColor, Unit:String, LabelWidth:Int = 45, ?Label:String)
|
||||
{
|
||||
super();
|
||||
x = X;
|
||||
y = Y;
|
||||
_width = Width - LabelWidth;
|
||||
_height = Height;
|
||||
graphColor = GraphColor;
|
||||
_unit = Unit;
|
||||
_labelWidth = LabelWidth;
|
||||
_label = (Label == null) ? "" : Label;
|
||||
|
||||
_axis = new Shape();
|
||||
_axis.x = _labelWidth + 10;
|
||||
|
||||
maxLabel = DebuggerUtil.createTextField(0, 0, Stats.LABEL_COLOR, Stats.TEXT_SIZE);
|
||||
curLabel = DebuggerUtil.createTextField(0, (_height / 2) - (Stats.TEXT_SIZE / 2), graphColor, Stats.TEXT_SIZE);
|
||||
minLabel = DebuggerUtil.createTextField(0, _height - Stats.TEXT_SIZE, Stats.LABEL_COLOR, Stats.TEXT_SIZE);
|
||||
|
||||
avgLabel = DebuggerUtil.createTextField(_labelWidth + 20, (_height / 2) - (Stats.TEXT_SIZE / 2) - 10, Stats.LABEL_COLOR, Stats.TEXT_SIZE);
|
||||
avgLabel.width = _width;
|
||||
avgLabel.defaultTextFormat.align = TextFormatAlign.CENTER;
|
||||
avgLabel.alpha = 0.5;
|
||||
|
||||
addChild(_axis);
|
||||
addChild(maxLabel);
|
||||
addChild(curLabel);
|
||||
addChild(minLabel);
|
||||
addChild(avgLabel);
|
||||
|
||||
drawAxes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the axes of the graph.
|
||||
*/
|
||||
function drawAxes():Void
|
||||
{
|
||||
var gfx = _axis.graphics;
|
||||
gfx.clear();
|
||||
gfx.lineStyle(1, AXIS_COLOR, AXIS_ALPHA);
|
||||
|
||||
// y-Axis
|
||||
gfx.moveTo(0, 0);
|
||||
gfx.lineTo(0, _height);
|
||||
|
||||
// x-Axis
|
||||
gfx.moveTo(0, _height);
|
||||
gfx.lineTo(_width, _height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the graph based on the values stored in the history.
|
||||
*/
|
||||
function drawGraph():Void
|
||||
{
|
||||
var gfx:Graphics = graphics;
|
||||
gfx.clear();
|
||||
gfx.lineStyle(1, graphColor, 1);
|
||||
|
||||
var inc:Float = _width / (HISTORY_MAX - 1);
|
||||
var range:Float = Math.max(maxValue - minValue, maxValue * 0.1);
|
||||
var graphX = _axis.x + 1;
|
||||
|
||||
for (i in 0...history.length)
|
||||
{
|
||||
var value = (history[i] - minValue) / range;
|
||||
|
||||
var pointY = (-value * _height - 1) + _height;
|
||||
if (i == 0)
|
||||
gfx.moveTo(graphX, _axis.y + pointY);
|
||||
gfx.lineTo(graphX + (i * inc), pointY);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Value:Float):Void
|
||||
{
|
||||
history.unshift(Value);
|
||||
if (history.length > HISTORY_MAX)
|
||||
history.pop();
|
||||
|
||||
// Update range
|
||||
maxValue = Math.max(maxValue, Value);
|
||||
minValue = Math.min(minValue, Value);
|
||||
|
||||
minLabel.text = formatValue(minValue);
|
||||
curLabel.text = formatValue(Value);
|
||||
maxLabel.text = formatValue(maxValue);
|
||||
|
||||
avgLabel.text = _label + "\nAvg: " + formatValue(average());
|
||||
|
||||
drawGraph();
|
||||
}
|
||||
|
||||
function formatValue(value:Float):String
|
||||
{
|
||||
return FlxMath.roundDecimal(value, Stats.DECIMALS) + " " + _unit;
|
||||
}
|
||||
|
||||
public function average():Float
|
||||
{
|
||||
var sum:Float = 0;
|
||||
for (value in history)
|
||||
sum += value;
|
||||
return sum / history.length;
|
||||
}
|
||||
|
||||
public function destroy():Void
|
||||
{
|
||||
_axis = FlxDestroyUtil.removeChild(this, _axis);
|
||||
minLabel = FlxDestroyUtil.removeChild(this, minLabel);
|
||||
curLabel = FlxDestroyUtil.removeChild(this, curLabel);
|
||||
maxLabel = FlxDestroyUtil.removeChild(this, maxLabel);
|
||||
avgLabel = FlxDestroyUtil.removeChild(this, avgLabel);
|
||||
history = null;
|
||||
}
|
||||
}
|
||||
#end
|
||||
Loading…
Reference in a new issue