Skip to content

Commit

Permalink
refactor: Context for state functions & conditions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Now pass context objects into state functions/conditions.
Makes it easier to change what we pass into them later on.
  • Loading branch information
christides11 committed Oct 1, 2023
1 parent 4cf9710 commit 0a4c956
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 336 deletions.
4 changes: 1 addition & 3 deletions Assets/HnSF/Combat/Boxes/Hurtbox/HurtboxGroup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine;

namespace HnSF.Combat
Expand Down
6 changes: 1 addition & 5 deletions Assets/HnSF/Combat/ForceType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HnSF.Combat
namespace HnSF.Combat
{
public enum ForceType
{
Expand Down
3 changes: 1 addition & 2 deletions Assets/HnSF/Combat/HitboxManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HnSF.Sample.TDAction
{
public class ADVManager : FighterManager
{
public override void Start()
{
base.Start();
StateManager.ChangeState((int)BaseStateEnum.IDLE);
StateManager.ChangeState((int)BaseStateEnum.FALL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,208 +19,7 @@ MonoBehaviour:
autoIncrement: 1
autoLoop: 1
autoLoopFrame: 1
data:
- rid: 1200828956845539343
- rid: 1200828957409673216
- rid: 1200828956845539345
- rid: 1200828956845539352
- rid: 1200828956845539353
- rid: 1200828956845539351
- rid: 1200828961006288896
- rid: 1200828961006288897
- rid: 1200828961006288898
- rid: 1200828961006288899
- rid: 1200828961006288901
- rid: 1200828961006288903
data: []
references:
version: 2
RefIds:
- rid: -2
type: {class: , ns: , asm: }
- rid: 1200828956845539343
type: {class: ChangeState, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 0
frameRanges: []
condition:
rid: -2
stateMovesetID: 0
stateID: 0
parent: -1
children: 0200000009000000
- rid: 1200828956845539345
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 2
frameRanges:
- {x: 2, y: 4}
condition:
rid: -2
value: 0
parent: 0
children:
- rid: 1200828956845539351
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 5
frameRanges:
- {x: 2, y: 4}
- {x: 8, y: 9}
condition:
rid: 1200828956845539355
value: 5
parent: 3
children:
- rid: 1200828956845539352
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 3
frameRanges:
- {x: 2, y: 4}
condition:
rid: -2
value: 0
parent: 1
children: 0400000005000000
- rid: 1200828956845539353
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 4
frameRanges:
- {x: 2, y: 4}
condition:
rid: -2
value: 0
parent: 3
children:
- rid: 1200828956845539355
type: {class: ConditionButton, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
button: 3
buttonState: 0
offset: 0
buffer: 322
- rid: 1200828957409673216
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 1
frameRanges:
- {x: 2, y: 4}
- {x: 8, y: 9}
condition:
rid: 1200828957409673217
value: 0
parent: -1
children: 0300000006000000
- rid: 1200828957409673217
type: {class: ConditionButton, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
button: 6
buttonState: 0
offset: 0
buffer: 0
- rid: 1200828961006288896
type: {class: VarApplyGravity, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 6
frameRanges: []
condition:
rid: -2
useMaxFallSpeedStat: 0
useGravityStat: 0
maxFallSpeed: 0
gravity: 0
parent: 1
children: 07000000
- rid: 1200828961006288897
type: {class: VarApplyTraction, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 7
frameRanges: []
condition:
rid: -2
useTractionStat: 0
aerialTraction: 0
traction: 0
parent: 6
children: 0a000000
- rid: 1200828961006288898
type: {class: ChangeState, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 8
frameRanges: []
condition:
rid: -2
stateMovesetID: 0
stateID: 0
parent: -1
children: 0b000000
- rid: 1200828961006288899
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 9
frameRanges:
- {x: 2, y: 4}
- {x: 8, y: 9}
condition:
rid: 1200828961006288900
value: 5
parent: 0
children:
- rid: 1200828961006288900
type: {class: ConditionButton, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
button: 3
buttonState: 0
offset: 0
buffer: 322
- rid: 1200828961006288901
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 10
frameRanges:
- {x: 2, y: 4}
- {x: 8, y: 9}
condition:
rid: 1200828961006288902
value: 5
parent: 7
children:
- rid: 1200828961006288902
type: {class: ConditionButton, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
button: 3
buttonState: 0
offset: 0
buffer: 322
- rid: 1200828961006288903
type: {class: VarSetFallSpeed, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
name:
id: 11
frameRanges:
- {x: 2, y: 4}
- {x: 8, y: 9}
condition:
rid: 1200828961006288904
value: 5
parent: 8
children:
- rid: 1200828961006288904
type: {class: ConditionButton, ns: HnSF.Sample.TDAction.State, asm: HnSF.TDAction}
data:
button: 3
buttonState: 0
offset: 0
buffer: 322
RefIds: []
46 changes: 23 additions & 23 deletions Assets/HnSF/Samples/TDAction/Rendering/TDAction URP Pipeline.asset
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,29 @@ MonoBehaviour:
m_Textures:
blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3}
bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3}
m_PrefilteringModeMainLightShadows: 1
m_PrefilteringModeMainLightShadows: 4
m_PrefilteringModeAdditionalLight: 4
m_PrefilteringModeAdditionalLightShadows: 1
m_PrefilterXRKeywords: 0
m_PrefilteringModeForwardPlus: 1
m_PrefilteringModeDeferredRendering: 1
m_PrefilteringModeScreenSpaceOcclusion: 1
m_PrefilterDebugKeywords: 0
m_PrefilterWriteRenderingLayers: 0
m_PrefilterHDROutput: 0
m_PrefilterSSAODepthNormals: 0
m_PrefilterSSAOSourceDepthLow: 0
m_PrefilterSSAOSourceDepthMedium: 0
m_PrefilterSSAOSourceDepthHigh: 0
m_PrefilterSSAOInterleaved: 0
m_PrefilterSSAOBlueNoise: 0
m_PrefilterSSAOSampleCountLow: 0
m_PrefilterSSAOSampleCountMedium: 0
m_PrefilterSSAOSampleCountHigh: 0
m_PrefilterDBufferMRT1: 0
m_PrefilterDBufferMRT2: 0
m_PrefilterDBufferMRT3: 0
m_PrefilterScreenCoord: 0
m_PrefilterNativeRenderPass: 0
m_PrefilteringModeAdditionalLightShadows: 0
m_PrefilterXRKeywords: 1
m_PrefilteringModeForwardPlus: 0
m_PrefilteringModeDeferredRendering: 0
m_PrefilteringModeScreenSpaceOcclusion: 0
m_PrefilterDebugKeywords: 1
m_PrefilterWriteRenderingLayers: 1
m_PrefilterHDROutput: 1
m_PrefilterSSAODepthNormals: 1
m_PrefilterSSAOSourceDepthLow: 1
m_PrefilterSSAOSourceDepthMedium: 1
m_PrefilterSSAOSourceDepthHigh: 1
m_PrefilterSSAOInterleaved: 1
m_PrefilterSSAOBlueNoise: 1
m_PrefilterSSAOSampleCountLow: 1
m_PrefilterSSAOSampleCountMedium: 1
m_PrefilterSSAOSampleCountHigh: 1
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 1
m_PrefilterScreenCoord: 1
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
m_ShadowCascades: 0
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using HnSF.Combat;
using HnSF.Fighters;
using HnSF.Sample.TDAction.State;
using UnityEngine;
using UnityEngine.Playables;

namespace HnSF.Sample.TDAction
{
Expand All @@ -31,6 +28,15 @@ public int MovesetCount
[NonSerialized] public StateFunctionMapper functionMapperBase = new StateFunctionMapper();
[NonSerialized] public StateConditionMapper conditionMapperBase = new StateConditionMapper();

private FighterStateMachineContext smContext = new FighterStateMachineContext();

private void Awake()
{
smContext.fighter = fighterManager;
functionMapperBase = new StateFunctionMapper();
conditionMapperBase = new StateConditionMapper();
}

public void Tick()
{
if (markedForStateChange)
Expand Down Expand Up @@ -85,9 +91,11 @@ private void ProcessStateVariables(StateTimeline timeline, IStateVariables d, in

if (!valid) return;
var varType = d.GetType();
if (!conditionMapperBase.TryCondition(varType, fighterManager, d.Condition, timeline, realFrame)) return;
functionMapperBase.functions[varType](fighterManager, d, timeline, realFrame, (float)(realFrame - frStart) / (float)(frEnd - frStart));
var sfContext = new StateFunctionContext() { currentFrame = realFrame, frameRangePercent = (float)(realFrame - frStart) / (float)(frEnd - frStart), };
if (d.Condition != null && !conditionMapperBase.TryCondition(d.Condition.GetType(), d.Condition, timeline, smContext, sfContext)) return;
functionMapperBase.functions[varType](d, timeline, smContext, sfContext);

if (d.Children is null) return;
foreach (var childID in d.Children)
{
ProcessStateVariables(timeline, timeline.data[timeline.stateVariablesIDMap[childID]], realFrame, totalFrames);
Expand Down
Loading

0 comments on commit 0a4c956

Please sign in to comment.