1
0
forked from 0ad/0ad

Remove the StateSet from FSM

The `StateSet` is only used to check if a state is valid. That's useless
since it wouldn't be found in the `TransitionMap` - With the same
outcome.

Accepted By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5236
This was SVN commit r28039.
This commit is contained in:
phosit 2024-02-25 14:05:23 +00:00
parent 04ce68f42e
commit 1eb11b39bf
3 changed files with 2 additions and 45 deletions

View File

@ -50,7 +50,6 @@ void CFsm::Setup()
void CFsm::Shutdown()
{
m_States.clear();
m_Transitions.clear();
m_Done = false;
@ -59,20 +58,9 @@ void CFsm::Shutdown()
m_NextState = FSM_INVALID_STATE;
}
void CFsm::AddState(unsigned int state)
{
m_States.insert(state);
}
void CFsm::AddTransition(unsigned int state, unsigned int eventType, unsigned int nextState,
Action* pAction /* = nullptr */, void* pContext /* = nullptr*/)
{
// Make sure we store the current state
AddState(state);
// Make sure we store the next state
AddState(nextState);
m_Transitions.insert({TransitionKey{state, eventType}, Transition{{pAction, pContext}, nextState}});
}
@ -96,9 +84,6 @@ bool CFsm::Update(unsigned int eventType, void* pEventParam)
if (IsFirstTime())
m_CurrState = m_FirstState;
if (!IsValidState(m_CurrState))
return false;
// Lookup transition
auto transitionIterator = m_Transitions.find({m_CurrState, eventType});
if (transitionIterator == m_Transitions.end())
@ -126,12 +111,3 @@ bool CFsm::IsDone() const
// By default the internal flag m_Done is tested
return m_Done;
}
bool CFsm::IsValidState(unsigned int state) const
{
StateSet::const_iterator it = m_States.find(state);
if (it == m_States.end())
return false;
return true;
}

View File

@ -19,7 +19,6 @@
#define FSM_H
#include <limits>
#include <set>
#include <unordered_map>
@ -41,8 +40,6 @@ struct CallbackFunction
}
};
using StateSet = std::set<unsigned int>;
/**
* Represents a signal in the state machine that a change has occurred.
* The CFsmEvent objects are under the control of CFsm so
@ -101,12 +98,6 @@ public:
*/
void Shutdown();
/**
* Adds the specified state to the internal list of states.
* @note If a state with the specified ID exists, the state is not added.
*/
void AddState(unsigned int state);
/**
* Adds a new transistion to the state machine.
*/
@ -137,22 +128,12 @@ public:
return m_NextState;
}
const StateSet& GetStates() const
{
return m_States;
}
/**
* Updates the FSM and retrieves next state.
* @return whether the state was changed.
*/
bool Update(unsigned int eventType, void* pEventData);
/**
* Verifies whether the specified state is managed by the FSM.
*/
bool IsValidState(unsigned int state) const;
/**
* Tests whether the state machine has finished its work.
* @note This is state machine specific.
@ -200,7 +181,6 @@ private:
unsigned int m_FirstState;
unsigned int m_CurrState;
unsigned int m_NextState;
StateSet m_States;
TransitionMap m_Transitions;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2024 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -48,6 +48,7 @@
#include <miniupnpc/upnperrors.h>
#endif
#include <set>
#include <string>
/**