File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ package SM
2+
3+ import "log"
4+
5+ // 有限状态机
6+ type FSM struct {
7+ CurrentState int // 当前状态数组的索引数值
8+ State []int // 自定义状态
9+ // CallBcaks Callbacks // 回调函数
10+ }
11+
12+ type Callback func ()
13+
14+ type Callbacks map [string ]Callback
15+
16+ func NewFSM (data []int ) * FSM {
17+ if len (data ) == 0 {
18+ log .Println ("create new FSM is fail" )
19+ return nil
20+ }
21+ return & FSM {
22+ CurrentState : 0 ,
23+ State :data ,
24+ }
25+ }
26+
27+ func (this * FSM )NextTurn () {
28+ if this != nil {
29+ if this .CurrentState < len (this .State )+ 1 {
30+ this .CurrentState ++
31+ }else {
32+ this .CurrentState = 0
33+ }
34+ }else {
35+ log .Println ("FSM is nil" )
36+ }
37+ }
38+
39+ func (this * FSM )GetFSMState () int {
40+ return this .State [this .CurrentState ]
41+ }
42+
43+ func (this * FSM )InitFSM () {
44+ this = NewFSM (this .State )
45+ }
Original file line number Diff line number Diff line change 77 TCP = "tcp"
88 UDP = "udp"
99 KCP = "kcp"
10+ NCN = "ncn"
1011)
1112
1213func InitNet ( netty string ) interface {} {
@@ -17,6 +18,7 @@ func InitNet( netty string ) interface{} {
1718 case KCP :
1819 case TCP :
1920 case UDP :
21+ case NCN :
2022 default :
2123 }
2224 return nil
You can’t perform that action at this time.
0 commit comments