add quit channel to clean up after self

This commit is contained in:
2025-01-18 22:27:22 +01:00
parent fb018e2a7d
commit d86cbe15a3
3 changed files with 80 additions and 65 deletions

View File

@ -17,6 +17,7 @@ type Game struct {
Music rl.Music
Chat *Chat
MenuOpen bool
QuitChan chan struct{} // Channel to signal shutdown
}
func New() *Game {
@ -37,7 +38,8 @@ func New() *Game {
Fovy: 45.0,
Projection: rl.CameraPerspective,
},
Chat: NewChat(),
Chat: NewChat(),
QuitChan: make(chan struct{}),
}
game.Player.UserData = game
game.Chat.userData = game
@ -259,6 +261,7 @@ func (g *Game) DrawMenu() {
case "Settings":
// TODO: Implement settings
case "Exit Game":
close(g.QuitChan) // Signal all goroutines to shut down
rl.CloseWindow()
}
}