add calculation for accuracy
This commit is contained in:
parent
4b13f559eb
commit
8b33e77791
|
@ -60,6 +60,7 @@ namespace HeavenStudio
|
|||
public static GameManager instance { get; private set; }
|
||||
private EventCaller eventCaller;
|
||||
|
||||
// average input accuracy (msec)
|
||||
List<int> inputOffsetSamples = new List<int>();
|
||||
float averageInputOffset = 0;
|
||||
public float AvgInputOffset
|
||||
|
@ -75,6 +76,18 @@ namespace HeavenStudio
|
|||
}
|
||||
}
|
||||
|
||||
// input accuracy (%)
|
||||
double totalInputs = 0;
|
||||
double totalPlayerAccuracy = 0;
|
||||
public double PlayerAccuracy
|
||||
{
|
||||
get
|
||||
{
|
||||
if (totalInputs == 0) return 0;
|
||||
return totalPlayerAccuracy / totalInputs;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// autoplay = true;
|
||||
|
@ -190,6 +203,11 @@ namespace HeavenStudio
|
|||
}
|
||||
}
|
||||
|
||||
public static void ScoreInputAccuracy(double accuracy, float weight = 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SeekAheadAndPreload(double start, float seekTime = 8f)
|
||||
{
|
||||
//seek ahead to preload games that have assetbundles
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace HeavenStudio.Games
|
|||
public class Minigame : MonoBehaviour
|
||||
{
|
||||
public static float earlyTime = 0.07f, perfectTime = 0.04f, aceEarlyTime = 0.01f, aceLateTime = 0.01f, lateTime = 0.04f, endTime = 0.07f;
|
||||
public static float rankHiThreshold = 0.8f, rankOkThreshold = 0.6f;
|
||||
[SerializeField] public SoundSequence.SequenceKeyValue[] SoundSequences;
|
||||
|
||||
public List<Minigame.Eligible> EligibleHits = new List<Minigame.Eligible>();
|
||||
|
@ -171,7 +172,7 @@ namespace HeavenStudio.Games
|
|||
|
||||
public static float AceStartTime()
|
||||
{
|
||||
return 1f + ScaleTimingMargin(aceEarlyTime);
|
||||
return 1f - ScaleTimingMargin(aceEarlyTime);
|
||||
}
|
||||
|
||||
public static float AceEndTime()
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace HeavenStudio.Games
|
|||
|
||||
public class PlayerActionEvent : PlayerActionObject
|
||||
{
|
||||
public static bool EnableAutoplayCheat = false;
|
||||
public delegate void ActionEventCallback(PlayerActionEvent caller);
|
||||
public delegate void ActionEventCallbackState(PlayerActionEvent caller, float state);
|
||||
|
||||
|
@ -33,6 +34,8 @@ namespace HeavenStudio.Games
|
|||
public InputType inputType; //The type of input. Check the InputType class to see a list of all of them
|
||||
|
||||
public bool perfectOnly = false; //Indicates that the input only recognize perfect inputs.
|
||||
|
||||
public bool countsForAccuracy = true; //Indicates if the input counts for the accuracy or not. If set to false, it'll not be counted in the accuracy calculation
|
||||
|
||||
public void setHitCallback(ActionEventCallbackState OnHit)
|
||||
{
|
||||
|
@ -60,31 +63,31 @@ namespace HeavenStudio.Games
|
|||
if (noAutoplay && autoplayOnly) autoplayOnly = false;
|
||||
if (noAutoplay && triggersAutoplay){ triggersAutoplay = false; }
|
||||
|
||||
float normalizedBeat = GetNormalizedTime();
|
||||
float stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2;
|
||||
StateCheck(normalizedBeat);
|
||||
double normalizedTime = GetNormalizedTime();
|
||||
double stateProg = ((normalizedTime - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2;
|
||||
StateCheck(normalizedTime);
|
||||
|
||||
//BUGFIX: ActionEvents destroyed too early
|
||||
if (normalizedBeat > Minigame.EndTime()) Miss();
|
||||
if (normalizedTime > Minigame.EndTime()) Miss();
|
||||
|
||||
|
||||
if (IsCorrectInput() && !autoplayOnly)
|
||||
{
|
||||
if (state.perfect)
|
||||
{
|
||||
Hit(stateProg);
|
||||
if (normalizedBeat >= Minigame.AceStartTime() && normalizedBeat <= Minigame.AceEndTime())
|
||||
Hit(stateProg, normalizedTime);
|
||||
if (normalizedTime >= Minigame.AceStartTime() && normalizedTime <= Minigame.AceEndTime())
|
||||
{
|
||||
// push an ace event
|
||||
}
|
||||
}
|
||||
else if (state.early && !perfectOnly)
|
||||
{
|
||||
Hit(-1f);
|
||||
Hit(-1f, normalizedTime);
|
||||
}
|
||||
else if (state.late && !perfectOnly)
|
||||
{
|
||||
Hit(1f);
|
||||
Hit(1f, normalizedTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -95,18 +98,18 @@ namespace HeavenStudio.Games
|
|||
|
||||
public bool IsExpectingInputNow()
|
||||
{
|
||||
float normalizedBeat = GetNormalizedTime();
|
||||
double normalizedBeat = GetNormalizedTime();
|
||||
return normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.EndTime();
|
||||
}
|
||||
|
||||
float GetNormalizedTime()
|
||||
double GetNormalizedTime()
|
||||
{
|
||||
var cond = Conductor.instance;
|
||||
double currTime = cond.GetSongPosFromBeat(cond.songPositionInBeatsAsDouble);
|
||||
double targetTime = cond.GetSongPosFromBeat(startBeat + timer);
|
||||
double min = targetTime - 1f;
|
||||
double max = targetTime + 1f;
|
||||
return 1f + (float)(((currTime - min) / (max - min))-0.5f)*2;
|
||||
return 1f + (((currTime - min) / (max - min))-0.5f)*2;
|
||||
}
|
||||
|
||||
public bool IsCorrectInput()
|
||||
|
@ -138,30 +141,88 @@ namespace HeavenStudio.Games
|
|||
//For the Autoplay
|
||||
public override void OnAce()
|
||||
{
|
||||
float normalizedBeat = Conductor.instance.GetPositionFromBeat(startBeat,timer);
|
||||
// allows ace detection with this new system
|
||||
float stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2;
|
||||
Hit(stateProg);
|
||||
if (EnableAutoplayCheat)
|
||||
{
|
||||
Hit(0f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
double normalizedBeat = GetNormalizedTime();
|
||||
double stateProg = ((normalizedBeat - Minigame.PerfectTime()) / (Minigame.LateTime() - Minigame.PerfectTime()) - 0.5f) * 2;
|
||||
Hit(stateProg, normalizedBeat);
|
||||
}
|
||||
}
|
||||
|
||||
//The state parameter is either -1 -> Early, 0 -> Perfect, 1 -> Late
|
||||
public void Hit(float state)
|
||||
public void Hit(double state, double time)
|
||||
{
|
||||
if (OnHit != null && enabled)
|
||||
{
|
||||
if(canHit)
|
||||
{
|
||||
float normalized = GetNormalizedTime() - 1f;
|
||||
double normalized = time - 1f;
|
||||
int offset = Mathf.CeilToInt((float)normalized * 1000);
|
||||
GameManager.instance.AvgInputOffset = offset;
|
||||
OnHit(this, state);
|
||||
OnHit(this, (float) state);
|
||||
|
||||
if (countsForAccuracy && !(noAutoplay || autoplayOnly))
|
||||
TimeToAccuracy(time);
|
||||
CleanUp();
|
||||
} else
|
||||
{
|
||||
Blank();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double TimeToAccuracy(double time)
|
||||
{
|
||||
if (time >= Minigame.AceStartTime() && time <= Minigame.AceEndTime())
|
||||
{
|
||||
// Ace
|
||||
Debug.Log("Accuracy (Ace): " + 1.0);
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
double state = 0;
|
||||
if (time >= Minigame.PerfectTime() && time <= Minigame.LateTime())
|
||||
{
|
||||
// Good Hit
|
||||
if (time > 1.0)
|
||||
{
|
||||
// late half of timing window
|
||||
state = 1.0 - ((time - Minigame.AceEndTime()) / (Minigame.LateTime() - Minigame.AceEndTime()));
|
||||
state *= 1.0 - Minigame.rankHiThreshold;
|
||||
state += Minigame.rankHiThreshold;
|
||||
Debug.Log("Accuracy (Late): " + state);
|
||||
}
|
||||
else
|
||||
{
|
||||
//early half of timing window
|
||||
state = ((time - Minigame.PerfectTime()) / (Minigame.AceStartTime() - Minigame.PerfectTime()));
|
||||
state *= 1.0 - Minigame.rankHiThreshold;
|
||||
state += Minigame.rankHiThreshold;
|
||||
Debug.Log("Accuracy (Early): " + state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (time > 1.0)
|
||||
{
|
||||
// late half of timing window
|
||||
state = 1.0 - ((time - Minigame.LateTime()) / (Minigame.EndTime() - Minigame.LateTime()));
|
||||
state *= Minigame.rankOkThreshold;
|
||||
Debug.Log("Accuracy (Late NG): " + state);
|
||||
}
|
||||
else
|
||||
{
|
||||
//early half of timing window
|
||||
state = ((time - Minigame.PerfectTime()) / (Minigame.AceStartTime() - Minigame.PerfectTime()));
|
||||
state *= Minigame.rankOkThreshold;
|
||||
Debug.Log("Accuracy (Early NG): " + state);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public void Miss()
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace HeavenStudio.Games
|
|||
autoPlayEnabledOnStart = GameManager.instance.autoplay;
|
||||
}
|
||||
|
||||
private void CheckForAce(float normalizedBeat, bool autoPlay = false)
|
||||
private void CheckForAce(double normalizedBeat, bool autoPlay = false)
|
||||
{
|
||||
if (aceTimes == 0)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace HeavenStudio.Games
|
|||
}
|
||||
|
||||
// could possibly add support for custom early, perfect, and end times if needed.
|
||||
public void StateCheck(float normalizedBeat, bool autoPlay = false)
|
||||
public void StateCheck(double normalizedBeat, bool autoPlay = false)
|
||||
{
|
||||
CheckForAce(normalizedBeat, autoPlay);
|
||||
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime())
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace HeavenStudio.Games.Scripts_RhythmTweezers
|
|||
|
||||
// Auto-release if holding at release time.
|
||||
if (normalizedBeat >= 1f)
|
||||
endEvent.Hit(0f);
|
||||
endEvent.Hit(0f, 1f);
|
||||
}
|
||||
|
||||
loop.transform.localScale = Vector2.one / holder.transform.localScale;
|
||||
|
|
Loading…
Reference in a new issue