change operation order for input checks

This commit is contained in:
minenice55 2024-01-25 15:11:43 -05:00
parent 9f0a48e9ff
commit 9be16564a0
12 changed files with 81 additions and 149 deletions

View file

@ -46,7 +46,7 @@ namespace HeavenStudio
// Current time of the song
private double time;
double dspTime;
double absTime, absTimeAdjust, lastAbsTime;
double absTime, absTimeAdjust;
double dspSizeSeconds;
double dspMargin = 128 / 44100.0;
bool deferTimeKeeping = false;
@ -56,7 +56,7 @@ namespace HeavenStudio
private double dspStart;
private float dspStartTime => (float)dspStart;
public double dspStartTimeAsDouble => dspStart;
DateTime startTime, lastMixTime;
DateTime startTime;
//the beat we started at
private double startPos;
@ -88,7 +88,6 @@ namespace HeavenStudio
private float minigamePitch = 1f;
public float SongPitch { get => isPaused ? 0f : (timelinePitch * minigamePitch); }
public float TimelinePitch { get => timelinePitch; }
private float musicScheduledPitch = 1f;
private double musicScheduledTime = 0;
// volume modifier
@ -201,16 +200,15 @@ namespace HeavenStudio
double musicStartDelay = -offset - startPos;
if (musicStartDelay > 0)
{
musicScheduledTime = dspTime + (musicStartDelay / timelinePitch) + 2*dspSizeSeconds;
dspStart = dspTime + 2*dspSizeSeconds;
musicScheduledTime = dspTime + (musicStartDelay / timelinePitch) + 2 * dspSizeSeconds;
dspStart = dspTime + 2 * dspSizeSeconds;
}
else
{
musicScheduledTime = dspTime + 2*dspSizeSeconds;
dspStart = dspTime + 2*dspSizeSeconds;
musicScheduledTime = dspTime + 2 * dspSizeSeconds;
dspStart = dspTime + 2 * dspSizeSeconds;
}
musicSource.PlayScheduled(musicScheduledTime);
musicScheduledPitch = timelinePitch;
musicSource.pitch = timelinePitch;
Debug.Log($"playback scheduled for dsptime {dspStart}");
}
@ -221,7 +219,6 @@ namespace HeavenStudio
startTime = DateTime.Now;
absTimeAdjust = 0;
lastAbsTime = 0;
deferTimeKeeping = musicSource.clip != null;
isPlaying = true;
@ -242,7 +239,6 @@ namespace HeavenStudio
absTimeAdjust = 0;
dspStart = dsp;
}
lastMixTime = DateTime.Now;
}
public void Pause()

View file

@ -166,11 +166,11 @@ namespace HeavenStudio.Games
public override void OnBeatPulse(double beat)
{
if (!BeatIsInBopRegion(beat)) return;
if (student.isHolding)
if (student.isHolding && !student.swiping)
{
student.anim.DoScaledAnimationAsync("HoldBop", 0.5f);
}
else if (!student.swiping && student.anim.IsAnimationNotPlaying())
else if (student.anim.IsAnimationNotPlaying() && !student.swiping)
{
student.anim.DoScaledAnimationAsync("IdleBop", 0.5f);
}
@ -217,16 +217,19 @@ namespace HeavenStudio.Games
{
student.UnHold();
shouldBeHolding = false;
ScoreMiss();
}
else if(PlayerInput.GetIsAction(InputAction_FlickRelease) && !IsExpectingInputNow(InputAction_FlickRelease) && student.isHolding) //Flick during hold
{
student.OnFlickSwipe();
shouldBeHolding = false;
ScoreMiss();
}
else if (!GameManager.instance.autoplay && shouldBeHolding && !PlayerInput.GetIsAction(InputAction_BasicPressing) && !IsExpectingInputNow(InputAction_FlickRelease))
{
student.UnHold();
shouldBeHolding = false;
ScoreMiss();
}
}
@ -249,11 +252,11 @@ namespace HeavenStudio.Games
{
new BeatAction.Action(beat + i, delegate
{
if (student.isHolding)
if (student.isHolding && !student.swiping)
{
student.anim.DoScaledAnimationAsync("HoldBop", 0.5f);
}
else if (!student.swiping && student.anim.IsAnimationNotPlaying())
else if (student.anim.IsAnimationNotPlaying() && !student.swiping)
{
student.anim.DoScaledAnimationAsync("IdleBop", 0.5f);
}
@ -469,27 +472,13 @@ namespace HeavenStudio.Games
ScheduleInput(beat, timing, InputAction_FlickRelease, student.OnHitSwipe, student.OnMissSwipe, student.OnEmpty);
}
andStop = false;
}
//void SetupCue(float beat, bool swipe)
//{
// if (swipe)
// student.swipeBeat = beat;
// else
// student.holdBeat = beat;
// student.eligible = true;
// student.ResetState();
//}
public static void SoundFX(bool toggle)
{
Student.soundFX = toggle;
}
public static void VoiceLines(double beat, int type)
{
string[] sounds;

View file

@ -169,23 +169,21 @@ namespace HeavenStudio.Games.Scripts_DJSchool
public void OnHitSwipe(PlayerActionEvent caller, float beat)
{
game.shouldBeHolding = false;
isHolding = false;
swiping = true;
SoundByte.PlayOneShotGame("djSchool/recordSwipe");
anim.Play("Swipe", 0, 0);
if (beat >= 1f || beat <= -1f) missed = true;
if (!missed)
{
isHolding = false;
missed = false;
shouldBeHolding = false;
SoundByte.PlayOneShotGame("djSchool/recordSwipe");
FlashFX(false);
swiping = true;
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { anim.Play("Swipe", 0, 0); }),
new BeatAction.Action(beat + 4f, delegate { swiping = false; }),
});
//anim.Play("Swipe", 0, 0);
game.djYellowScript.ChangeHeadSprite(DJYellow.DJExpression.UpSecond);
game.djYellowScript.Reverse();
game.smileBeat = caller.timer + caller.startBeat + 1f;
@ -199,13 +197,10 @@ namespace HeavenStudio.Games.Scripts_DJSchool
else
{
OnMissSwipeForPlayerInput(caller.timer + caller.startBeat + 1);
SoundByte.PlayOneShotGame("djSchool/recordSwipe");
BeatAction.New(this, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { anim.Play("Swipe", 0, 0); }),
new BeatAction.Action(beat + 4f, delegate { swiping = false; }),
});
//anim.Play("Swipe", 0, 0);
tableAnim.speed = 1;
tableAnim.DoScaledAnimationAsync("Student_Turntable_Swipe", 0.5f);
@ -304,7 +299,6 @@ namespace HeavenStudio.Games.Scripts_DJSchool
}
}
//Not sure but will do?
private void OnDestroy()
{

View file

@ -39,7 +39,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
double lastChargeTime = double.MinValue;
double unPrepareTime = double.MinValue;
double noNuriJabTime = double.MinValue;
bool canEmote = false;
bool canEmote = false, justPunched = false;
public int wantFace = 0;
public bool inSpecial
@ -137,7 +137,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}
}
if (PlayerInput.GetIsAction(KarateMan.InputAction_Press) && !inSpecial)
if (PlayerInput.GetIsAction(KarateMan.InputAction_Press) && !(inSpecial || justPunched))
{
if (!KarateMan.instance.IsExpectingInputNow(KarateMan.InputAction_Press))
{
@ -204,7 +204,11 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}
}
}
}
void LateUpdate()
{
justPunched = false;
}
public void Bop()
@ -230,19 +234,6 @@ namespace HeavenStudio.Games.Scripts_KarateMan
switch (forceHand)
{
case 0:
if (cond.songPositionInBeatsAsDouble - lastPunchTime < 0.25f + (Minigame.JustLateTime() - 1f))
{
lastPunchTime = double.MinValue;
anim.DoScaledAnimationAsync("Straight", 0.5f);
straight = true;
}
else
{
lastPunchTime = cond.songPositionInBeatsAsDouble;
anim.DoScaledAnimationAsync("Jab", 0.5f);
}
break;
case 1:
anim.DoScaledAnimationAsync("Jab", 0.5f);
break;
@ -255,6 +246,19 @@ namespace HeavenStudio.Games.Scripts_KarateMan
anim.DoNormalizedAnimation("JabNoNuri");
noNuriJabTime = cond.songPositionInBeatsAsDouble;
break;
default:
if (cond.songPositionInBeatsAsDouble <= cond.GetBeatFromSongPos(lastPunchTime + Minigame.NgLateTime() - 1) + 0.25)
{
lastPunchTime = double.MinValue;
anim.DoScaledAnimationAsync("Straight", 0.5f);
straight = true;
}
else
{
lastPunchTime = cond.songPositionAsDouble;
anim.DoScaledAnimationAsync("Jab", 0.5f);
}
break;
}
if (touchCharge)
{
@ -265,6 +269,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
{
bop.startBeat = cond.songPositionInBeatsAsDouble + 0.5f;
}
justPunched = true;
return straight; //returns what hand was used to punch the object
}

View file

@ -190,6 +190,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
case ItemType.ComboPot1:
OnHit = KarateMan.instance.ScheduleInput(startBeat, 1f, KarateMan.InputAction_AltDown, ComboStartJustOrNg, ComboStartThrough, ComboStartOut, CanCombo);
OnHitWrongAction = KarateMan.instance.ScheduleUserInput(startBeat, 1f, KarateMan.InputAction_Press, ComboStartWrongAction, ComboStartOut, ComboStartOut, CanHitWrong);
OnHitWrongAction.weight = 0;
path = 1;
break;
case ItemType.ComboPot2:
@ -216,6 +217,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
case ItemType.KickBarrel:
OnHit = KarateMan.instance.ScheduleInput(startBeat, 1f, KarateMan.InputAction_Press, KickChargeJustOrNg, ItemThrough, ItemOut, CanCombo);
OnHitWrongAction = KarateMan.instance.ScheduleUserInput(startBeat, 1f, KarateMan.InputAction_AltDown, ItemWrongAction, ItemOut, ItemOut, CanComboWrong);
OnHitWrongAction.weight = 0;
path = 1;
comboId = -1;
break;
@ -243,12 +245,14 @@ namespace HeavenStudio.Games.Scripts_KarateMan
case ItemType.Bomb:
OnHit = KarateMan.instance.ScheduleInput(startBeat, 1f, KarateMan.InputAction_Press, ItemJustOrNg, ItemThrough, ItemOut, CanHit);
OnHitWrongAction = KarateMan.instance.ScheduleUserInput(startBeat, 1f, KarateMan.InputAction_AltDown, ItemWrongAction, ItemOut, ItemOut, CanHitWrong);
OnHitWrongAction.weight = 0;
path = 1;
comboId = -1;
break;
default:
OnHit = KarateMan.instance.ScheduleInput(startBeat, 1f, KarateMan.InputAction_Press, ItemJustOrNg, ItemThrough, ItemOut, CanHit);
OnHitWrongAction = KarateMan.instance.ScheduleUserInput(startBeat, 1f, KarateMan.InputAction_AltDown, ItemWrongAction, ItemOut, ItemOut, CanHitWrong);
OnHitWrongAction.weight = 0;
path = 1;
comboId = -1;
break;
@ -832,6 +836,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}),
});
KarateMan.instance.Nori.DoThrough();
KarateMan.instance.ScoreMiss();
}
public void ItemOut(PlayerActionEvent caller) { }
@ -937,6 +942,7 @@ namespace HeavenStudio.Games.Scripts_KarateMan
{
ItemHitEffect(straight);
}
KarateMan.instance.ScoreMiss();
KarateMan.instance.Nori.DoThrough();
}

View file

@ -198,42 +198,6 @@ namespace HeavenStudio.Games
scheduledInputs.Remove(evt);
}
//Get the scheduled input that should happen the **Soonest**
//Can return null if there's no scheduled inputs
// remark: need a check for specific button(s)
[Obsolete("Use GetClosestScheduledInput InputAction or InputAction category instead")]
public PlayerActionEvent GetClosestScheduledInput(InputType input = InputType.ANY)
{
PlayerActionEvent closest = null;
foreach (PlayerActionEvent toCompare in scheduledInputs)
{
// ignore inputs that are for sequencing in autoplay
if (toCompare.autoplayOnly) continue;
if (closest == null)
{
if (input == InputType.ANY || (toCompare.inputType & input) != 0)
closest = toCompare;
}
else
{
double t1 = closest.startBeat + closest.timer;
double t2 = toCompare.startBeat + toCompare.timer;
// Debug.Log("t1=" + t1 + " -- t2=" + t2);
if (t2 < t1)
{
if (input == InputType.ANY || (toCompare.inputType & input) != 0)
closest = toCompare;
}
}
}
return closest;
}
public PlayerActionEvent GetClosestScheduledInput(int[] actionCats)
{
int catIdx = (int)PlayerInput.CurrentControlStyle;
@ -267,22 +231,6 @@ namespace HeavenStudio.Games
return closest;
}
public PlayerActionEvent GetClosestScheduledInput(PlayerInput.InputAction action)
{
return GetClosestScheduledInput(action.inputLockCategory);
}
//Hasn't been tested yet. *Should* work.
//Can be used to detect if the user is expected to input something now or not
//Useful for strict call and responses games like Tambourine
[Obsolete("Use IsExpectingInputNow InputAction or InputAction category instead")]
public bool IsExpectingInputNow(InputType wantInput = InputType.ANY)
{
PlayerActionEvent input = GetClosestScheduledInput(wantInput);
if (input == null) return false;
return input.IsExpectingInputNow();
}
public bool IsExpectingInputNow(int[] wantActionCategory)
{
PlayerActionEvent input = GetClosestScheduledInput(wantActionCategory);
@ -299,43 +247,43 @@ namespace HeavenStudio.Games
public static double NgEarlyTime(float pitch = -1)
{
if (pitch < 0)
return 1f - ngEarlyTime;
return 1f - (ngEarlyTimeBase * pitch);
return 1 - ngEarlyTime;
return 1 - (ngEarlyTimeBase * pitch);
}
public static double JustEarlyTime(float pitch = -1)
{
if (pitch < 0)
return 1f - justEarlyTime;
return 1f - (justEarlyTimeBase * pitch);
return 1 - justEarlyTime;
return 1 - (justEarlyTimeBase * pitch);
}
public static double JustLateTime(float pitch = -1)
{
if (pitch < 0)
return 1f + justLateTime;
return 1f + (justLateTimeBase * pitch);
return 1 + justLateTime;
return 1 + (justLateTimeBase * pitch);
}
public static double NgLateTime(float pitch = -1)
{
if (pitch < 0)
return 1f + ngLateTime;
return 1f + (ngLateTimeBase * pitch);
return 1 + ngLateTime;
return 1 + (ngLateTimeBase * pitch);
}
public static double AceEarlyTime(float pitch = -1)
{
if (pitch < 0)
return 1f - aceEarlyTime;
return 1f - (aceEarlyTimeBase * pitch);
return 1 - aceEarlyTime;
return 1 - (aceEarlyTimeBase * pitch);
}
public static double AceLateTime(float pitch = -1)
{
if (pitch < 0)
return 1f + aceLateTime;
return 1f + (aceLateTimeBase * pitch);
return 1 + aceLateTime;
return 1 + (aceLateTimeBase * pitch);
}
public virtual void OnGameSwitch(double beat)

View file

@ -42,8 +42,6 @@ namespace HeavenStudio.Games
public bool noAutoplay = false; //Indicates if this PlayerActionEvent is recognized by the autoplay. /!\ Overrides autoPlayOnly /!\
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
@ -160,11 +158,6 @@ namespace HeavenStudio.Games
if (toCompare.InputAction != null
&& toCompare.InputAction.inputLockCategory[catIdx] != InputAction.inputLockCategory[catIdx]) continue;
}
else
{
if ((toCompare.inputType & this.inputType) == 0) continue;
if (!toCompare.IsExpectingInputNow()) continue;
}
double t1 = this.startBeat + this.timer;
double t2 = toCompare.startBeat + toCompare.timer;

View file

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 5
executionOrder: -30
icon: {instanceID: 0}
userData:
assetBundleName:

View file

@ -177,29 +177,23 @@ namespace HeavenStudio.Games
protected static bool IA_TouchNrm(out double dt)
{
return PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt)
&& (instance.currentReceiver is WhichTossKid.Akachan
|| (instance.lastReceiver is WhichTossKid.Akachan or WhichTossKid.None
&& instance.currentReceiver is WhichTossKid.None)
|| (instance.IsExpectingInputNow(InputAction_Aka)
&& !(instance.IsExpectingInputNow(InputAction_Ao) || instance.IsExpectingInputNow(InputAction_Kii))));
&& ((instance.currentReceiver is WhichTossKid.Akachan or WhichTossKid.None)
|| instance.IsExpectingInputNow(InputAction_Aka))
&& !(instance.IsExpectingInputNow(InputAction_Ao) || instance.IsExpectingInputNow(InputAction_Kii));
}
protected static bool IA_TouchDir(out double dt)
{
return PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt)
&& (instance.currentReceiver is WhichTossKid.Kiiyan
|| (instance.lastReceiver is WhichTossKid.Kiiyan
&& instance.currentReceiver is WhichTossKid.None)
|| (instance.IsExpectingInputNow(InputAction_Kii)
&& !(instance.IsExpectingInputNow(InputAction_Ao) || instance.IsExpectingInputNow(InputAction_Aka))));
&& ((instance.currentReceiver is WhichTossKid.Kiiyan)
|| instance.IsExpectingInputNow(InputAction_Kii))
&& !(instance.IsExpectingInputNow(InputAction_Ao) || instance.IsExpectingInputNow(InputAction_Aka));
}
protected static bool IA_TouchAlt(out double dt)
{
return PlayerInput.GetTouchDown(InputController.ActionsTouch.Tap, out dt)
&& (instance.currentReceiver is WhichTossKid.Aokun
|| (instance.lastReceiver is WhichTossKid.Aokun
&& instance.currentReceiver is WhichTossKid.None)
|| (instance.IsExpectingInputNow(InputAction_Ao)
&& !(instance.IsExpectingInputNow(InputAction_Aka) || instance.IsExpectingInputNow(InputAction_Kii))));
&& ((instance.currentReceiver is WhichTossKid.Aokun)
|| instance.IsExpectingInputNow(InputAction_Ao))
&& !(instance.IsExpectingInputNow(InputAction_Aka) || instance.IsExpectingInputNow(InputAction_Kii));
}
protected static bool IA_BatonNrm(out double dt)

View file

@ -58,15 +58,19 @@ namespace HeavenStudio.Util
if (behaviour == null || !(conductor.isPlaying || conductor.isPaused))
return;
try
while (conductor.songPositionInBeatsAsDouble >= actions[idx].beat)
{
actions[idx].function.Invoke();
try
{
actions[idx].function.Invoke();
}
catch (System.Exception e)
{
Debug.LogError($"Exception thrown while executing BeatAction: {e}");
}
idx++;
if (idx >= actions.Count) return;
}
catch (System.Exception e)
{
Debug.LogError($"Exception thrown while executing BeatAction: {e}");
}
idx++;
}
}
}

View file

@ -37,7 +37,7 @@ namespace HeavenStudio.Util
bool queued = false;
public bool available = true;
const double PREBAKE_TIME = 0.5;
const double PREBAKE_TIME = 0.25;
private void Start()
{

View file

@ -55,5 +55,8 @@ MonoBehaviour:
- Assets/Scripts/Games/TrickClass/TrickClass.cs
- Assets/Scripts/GameInitializer.cs
- Assets/Scripts/LevelEditor/Timeline/Timeline.cs
- Assets/Scripts/Games/PlayerActionEvent.cs
- Assets/Scripts/Games/KarateMan/KarateManPot.cs
- Assets/Scripts/Games/DJSchool/DJSchool.cs
PathsToSkipImportEvent: []
PathsToIgnoreOverwriteSettingOnAttribute: []