Hierarchical State Machine 涉及的原理是什么,如何实现基本模型?
What are the principles involved for an Hierarchical State Machine, and how to implement a basic model?
所以我正在尝试使用 C++ 制作游戏,并且我阅读了大量关于 Finite State Machines (FSM), and Hierarchical State Machines (HSM). However I will admit most of the stuff I've read is a bit dense and hard to understand, so I was hoping someone can simplify it for me. Is this answer an FSM or an HSM?
的文章
我想澄清的是:
How is an HSM different from a normal FSM, and why is it better for games?
Regarding C++, How do you implement a basic HSM following the state pattern? (I might be incorrect on this/using the wrong words.)
How exactly do you handle transitions? What is the on_exit and on_enter method I keep hearing a lot about?
Do I need one HSM for my entire game? (e.g. Handling all enemies, player actions, game menus) or do I use multiple HSMs?
When implementing player entities, would they all be a subset of an Entity state?
Lastly if someone could give some pseudo-code to help visualize these questions, I would appreciate it.
这只是关于嵌套。 HSM 基本上是一个 FSM,但每个状态又可以是一个单独的 FSM。
举个游戏中的例子,考虑一个 NPC。它有多个状态:
- 走到A点
- 等一下
- 走到B点
- 等一下
- 从 1 继续
- 与PC战斗
这个FSM很简单,但是当NPC被PC攻击时,所有状态都需要转换到状态6(Fighting with PC)。这使得 FSM 有点难看。因此,让 this 更简单 FSM:
- 四处走动
- 与PC战斗
这个FSM很简单,只有两个转换,很容易理解。状态 1 的主要部分是辅助 FSM:
- 走到A点
- 等一下
- 走到B点
- 等一下
如果有一个事件与次级 FSM 转换不匹配,例如 PC 攻击,您将升级到顶级 FSM 以匹配该事件并找到合适的转换。
你可以在某种程度上将其视为堆栈,较高级别的每个状态都可以推送一个新的较低级别的 FSM。如果有一个事件与任何可能的转换都不匹配,则弹出堆栈并返回上一级。继续,直到出现匹配的过渡。
简而言之,这是一种简化 FSM 的方法。
所以我正在尝试使用 C++ 制作游戏,并且我阅读了大量关于 Finite State Machines (FSM), and Hierarchical State Machines (HSM). However I will admit most of the stuff I've read is a bit dense and hard to understand, so I was hoping someone can simplify it for me. Is this answer an FSM or an HSM?
的文章我想澄清的是:
How is an HSM different from a normal FSM, and why is it better for games?
Regarding C++, How do you implement a basic HSM following the state pattern? (I might be incorrect on this/using the wrong words.)
How exactly do you handle transitions? What is the on_exit and on_enter method I keep hearing a lot about?
Do I need one HSM for my entire game? (e.g. Handling all enemies, player actions, game menus) or do I use multiple HSMs?
When implementing player entities, would they all be a subset of an Entity state?
Lastly if someone could give some pseudo-code to help visualize these questions, I would appreciate it.
这只是关于嵌套。 HSM 基本上是一个 FSM,但每个状态又可以是一个单独的 FSM。
举个游戏中的例子,考虑一个 NPC。它有多个状态:
- 走到A点
- 等一下
- 走到B点
- 等一下
- 从 1 继续
- 与PC战斗
这个FSM很简单,但是当NPC被PC攻击时,所有状态都需要转换到状态6(Fighting with PC)。这使得 FSM 有点难看。因此,让 this 更简单 FSM:
- 四处走动
- 与PC战斗
这个FSM很简单,只有两个转换,很容易理解。状态 1 的主要部分是辅助 FSM:
- 走到A点
- 等一下
- 走到B点
- 等一下
如果有一个事件与次级 FSM 转换不匹配,例如 PC 攻击,您将升级到顶级 FSM 以匹配该事件并找到合适的转换。
你可以在某种程度上将其视为堆栈,较高级别的每个状态都可以推送一个新的较低级别的 FSM。如果有一个事件与任何可能的转换都不匹配,则弹出堆栈并返回上一级。继续,直到出现匹配的过渡。
简而言之,这是一种简化 FSM 的方法。