From 392495a61eaa3350f74836313d1ca3dcab89aa26 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 6 Mar 2020 14:20:17 -0500 Subject: [PATCH] remove unneeded timeInState calc & redundant "string?" annotation --- Shared/FSM.cs | 10 ++++------ Shared/NPC.cs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Shared/FSM.cs b/Shared/FSM.cs index d313787..cda01a7 100644 --- a/Shared/FSM.cs +++ b/Shared/FSM.cs @@ -4,11 +4,12 @@ using System.Collections.Generic; namespace SemiColinGames { public interface IState { public void Enter(); - public string? Update(T obj, float modelTime, World world); + + // Returns the name of the new state, or null if we should stay in the same state. + public string Update(T obj, float modelTime, World world); } public class FSM { - float timeInState = 0f; Dictionary> states; IState state; @@ -21,16 +22,13 @@ namespace SemiColinGames { public string StateName { get; private set; } public void Update(T obj, float modelTime, World world) { - timeInState += modelTime; - string? newState = state.Update(obj, modelTime, world); + string newState = state.Update(obj, modelTime, world); if (newState != null) { Transition(newState); } } void Transition(string state) { - Debug.WriteLine("{0} -> {1} @ {2}", StateName, state, timeInState); - timeInState = 0f; StateName = state; IState newState = states[state]; this.state = newState; diff --git a/Shared/NPC.cs b/Shared/NPC.cs index d912ea9..dcd3de3 100644 --- a/Shared/NPC.cs +++ b/Shared/NPC.cs @@ -10,7 +10,7 @@ namespace SemiColinGames { timeInState = 0; } - public string? Update(NPC npc, float modelTime, World world) { + public string Update(NPC npc, float modelTime, World world) { timeInState += modelTime; if (timeInState > 1.0f) { npc.Facing *= -1; @@ -23,7 +23,7 @@ namespace SemiColinGames { class RunState : IState { public void Enter() {} - public string? Update(NPC npc, float modelTime, World world) { + public string Update(NPC npc, float modelTime, World world) { int moveSpeed = 120; int desiredX = npc.Position.X + (int) (moveSpeed * npc.Facing * modelTime); // TODO: define the box modularly & correctly.