Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

headless: inline Ebiten's clock package so I can run update in a way that is closer to headed builds #66

Open
silbinarywolf opened this issue Dec 24, 2018 · 0 comments

Comments

@silbinarywolf
Copy link
Owner

silbinarywolf commented Dec 24, 2018

Why?
The current headless update loop is run in a way that isn't identical to headed builds. I quickly threw this together and it seemed to update as often as the headed builds so things seem fine?

I can't remember what precisely makes me feel like this isn't good enough, but I noticed odd subtle behavior that might bite me later on. Even if I don't quite understand how Ebiten's clock works yet, I should probably fix this quirk sooner rather than later.

func Run(gameStartFunc func(), updateFunc func(), width, height float64, scale float64, title string) {
	gWindowSize = geom.Vec{
		X: width,
		Y: height,
	}
	gWindowScale = scale

	gMainFunctions.gameStart = gameStartFunc
	gMainFunctions.update = updateFunc
	gMainFunctions.gameStart()

	// Loop
	tick := time.Tick(16 * time.Millisecond)
	for {
		select {
		case <-tick:
			updateFunc()
			// todo(Jake): 2018-07-10
			//
			// Should improve this to be more robust!
			// - https://trello.com/c/1RUkMGOx/55-improve-clock-for-headless-mode
			//
			// However, I'm deferring this effort as the way Ebiten works might change
			// in the future:
			// - https://github.com/hajimehoshi/ebiten/issues/605
			//
			// time.Sleep(time.Second / 60)
		}
	}
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant