Skip to content

Commit

Permalink
feat: State frame range % for functions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Added frame range percentage for functions.
  • Loading branch information
christides11 committed Feb 23, 2023
1 parent f29f55e commit ffd4229
Show file tree
Hide file tree
Showing 11 changed files with 2,993 additions and 2,872 deletions.
1,464 changes: 741 additions & 723 deletions Assembly-CSharp.csproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public void Tick()

private void ProcessState(StateTimeline state, bool onInterrupt = false, bool autoIncrement = false, bool autoLoop = false)
{
var topState = state;
while (true)
{
int realFrame = onInterrupt ? state.totalFrames+1 : Mathf.Clamp(CurrentStateFrame, 0, state.totalFrames);
foreach (var d in state.data)
{
ProcessStateVariables(state, d, realFrame);
ProcessStateVariables(state, d, realFrame, topState.totalFrames);
}

if (!state.useBaseState) break;
Expand All @@ -64,34 +65,48 @@ private void ProcessState(StateTimeline state, bool onInterrupt = false, bool au
}
}

private void ProcessStateVariables(StateTimeline timeline, IStateVariables d, int realFrame)
private void ProcessStateVariables(StateTimeline timeline, IStateVariables d, int realFrame, int totalFrames)
{
var valid = true;
var valid = d.FrameRanges.Length == 0 ? true : false;
int frameRange = 0;
int frStart = 0;
int frEnd = 0;
for (int j = 0; j < d.FrameRanges.Length; j++)
{
if (!(realFrame < d.FrameRanges[j].x) &&
!(realFrame > d.FrameRanges[j].y)) continue;
valid = false;
break;
frStart = ConvertFrameRangeNumber((int)d.FrameRanges[j].x, totalFrames);
frEnd = ConvertFrameRangeNumber((int)d.FrameRanges[j].y, totalFrames);
if (realFrame >= frStart && realFrame <= frEnd)
{
frameRange = j;
valid = true;
break;
}
}

if (!valid) return;
var varType = d.GetType();
if (!conditionMapperBase.TryCondition(varType, fighterManager, d.Condition, timeline, realFrame)) return;
functionMapperBase.functions[varType](fighterManager, d, timeline, realFrame);
functionMapperBase.functions[varType](fighterManager, d, timeline, realFrame, (float)(realFrame - frStart) / (float)(frEnd - frStart));

foreach (var childID in d.Children)
{
ProcessStateVariables(timeline, timeline.data[timeline.stateVariablesIDMap[childID]], realFrame);
ProcessStateVariables(timeline, timeline.data[timeline.stateVariablesIDMap[childID]], realFrame, totalFrames);
}
}

private int ConvertFrameRangeNumber(int number, int totalFrames)
{
if (number == -1) return totalFrames;
if (number == -2) return totalFrames + 1;
return number;
}

public void MarkForStateChange(int nextState, int moveset = -1, int frame = 0, bool force = false)
{
markedForStateChange = true;
this.nextMoveset = moveset == -1 ? CurrentStateMoveset : moveset;
this.nextState = nextState;
this.nextFrame = nextFrame;
this.nextFrame = frame;
}

public IMovesetDefinition GetMoveset(int index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ namespace HnSF.Sample.TDAction
{
public static class BaseStateFunctions
{
public static void ChangeState(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int arg4)
public static void ChangeState(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int currentFrame, float frameRangePercent)
{
State.ChangeState vars = (State.ChangeState)variables;
fighter.StateManager.MarkForStateChange(vars.stateID, vars.stateMovesetID);
}

public static void ApplyGravity(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int arg4)
public static void ApplyGravity(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int currentFrame, float frameRangePercent)
{
State.VarApplyGravity vars = (State.VarApplyGravity)variables;
FighterManager fm = (FighterManager)fighter;
fm.physicsManager.ApplyGravity(vars.useMaxFallSpeedStat ? fm.statManager.maxFallSpeed : vars.maxFallSpeed,
vars.useGravityStat ? fm.statManager.gravity : vars.gravity);
}

public static void ApplyTraction(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int arg4)
public static void ApplyTraction(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int currentFrame, float frameRangePercent)
{
State.VarApplyTraction vars = (State.VarApplyTraction)variables;
FighterManager fm = (FighterManager)fighter;
Expand All @@ -35,7 +35,7 @@ public static void ApplyTraction(IFighterBase fighter, IStateVariables variables
}
}

public static void SetFallSpeed(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int arg4)
public static void SetFallSpeed(IFighterBase fighter, IStateVariables variables, HnSF.StateTimeline arg3, int currentFrame, float frameRangePercent)
{
State.VarSetFallSpeed vars = (State.VarSetFallSpeed)variables;
FighterManager fm = (FighterManager)fighter;
Expand Down
13 changes: 8 additions & 5 deletions Assets/HnSF/State/StateFunctionMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ namespace HnSF
[System.Serializable]
public class StateFunctionMapperBase
{
public Dictionary<Type, Action<IFighterBase, IStateVariables, StateTimeline, int>> functions =
new Dictionary<Type, Action<IFighterBase, IStateVariables, StateTimeline, int>>();
/// <summary>
/// IFighterBase, IStateVariables, StateTimeline, Current Frame, Frame Range %
/// </summary>
public Dictionary<Type, Action<IFighterBase, IStateVariables, StateTimeline, int, float>> functions =
new Dictionary<Type, Action<IFighterBase, IStateVariables, StateTimeline, int, float>>();

public virtual bool TryRegisterFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int> function)
public virtual bool TryRegisterFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int, float> function)
{
if (functions.ContainsKey(id)) return false;
functions.Add(id, function);
return true;
}

public virtual void RegisterFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int> function)
public virtual void RegisterFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int, float> function)
{
functions.Add(id, function);
}

public virtual bool OverrideFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int> function)
public virtual bool OverrideFunction(Type id, Action<IFighterBase, IStateVariables, StateTimeline, int, float> function)
{
functions[id] = function;
return true;
Expand Down
Loading

0 comments on commit ffd4229

Please sign in to comment.