package gamestate

import (
	"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
	"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
)

type GameState struct {
	Mainfunc     chan func()
	Exit         chan struct{}
	Input        chan string
	RawInput     chan int
	FovRecompute chan struct{}
	Redraw       chan struct{}
	Player       ecs.Entity
	Level        *gamemap.Level
	Controller   *ecs.Controller
}

// do runs f on the main thread.
func (g *GameState) Do(f func()) {
	done := make(chan struct{}, 1)
	g.Mainfunc <- func() {
		f()
		f = nil //zero pointer for closure function
		done <- struct{}{}
	}
	<-done
}