Decompose daemons.go; daemon dispatch becomes a table (step 7)
runDaemon's switch becomes gameData.daemonHandlers (the C d_func function pointers restored as method expressions); stomach splits into stomachFaint/stomachDigest; visuals gains visualMonsters. daemons.go is complexity-clean. Behavior and RNG call order unchanged.
This commit is contained in:
@@ -151,6 +151,10 @@ type gameData struct {
|
||||
// trapHandlers dispatches each sprung trap to its effect method:
|
||||
// the cases of the move.c be_trapped switch.
|
||||
trapHandlers [NumTrapTypes]func(g *RogueGame, tc Coord)
|
||||
|
||||
// daemonHandlers dispatches DaemonIDs to their callbacks: the C
|
||||
// d_func function pointers (daemons.c / daemon.c).
|
||||
daemonHandlers [DTurnSee + 1]func(g *RogueGame, arg int)
|
||||
}
|
||||
|
||||
// ripWall is the repeated blank wall line of the tombstone art.
|
||||
@@ -826,6 +830,24 @@ func newGameData() *gameData {
|
||||
TrapRust: (*RogueGame).trapRust,
|
||||
TrapMystery: (*RogueGame).trapMystery,
|
||||
},
|
||||
|
||||
daemonHandlers: [DTurnSee + 1]func(*RogueGame, int){
|
||||
DRollwand: (*RogueGame).rollwand,
|
||||
DDoctor: (*RogueGame).doctor,
|
||||
DStomach: (*RogueGame).stomach,
|
||||
DRunners: (*RogueGame).runners,
|
||||
DSwander: (*RogueGame).swander,
|
||||
DNohaste: (*RogueGame).nohaste,
|
||||
DUnconfuse: (*RogueGame).unconfuse,
|
||||
DUnsee: (*RogueGame).unsee,
|
||||
DSight: (*RogueGame).sight,
|
||||
DVisuals: (*RogueGame).visuals,
|
||||
DComeDown: (*RogueGame).comeDown,
|
||||
DLand: (*RogueGame).land,
|
||||
DTurnSee: func(g *RogueGame, arg int) {
|
||||
g.turnSee(arg != 0)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user