func initFpsCounter(screen *window.Screen) func() int { const fpsBufferSize = 20 var fpsBuffer [fpsBufferSize]int fpsCounter := 0 currentFps := 0 return func() int { if fpsCounter > (fpsBufferSize - 1) { fpsCounter = 0 fpsSum := 0 for _, val := range fpsBuffer { fpsSum += val } currentFps = int(math.Ceil((float64(fpsSum) / float64(fpsBufferSize)))) if currentFps < 0 { currentFps = 0 } } fpsBuffer[fpsCounter] = int(1 / screen.GetTimeSinceLastFrame()) fpsCounter++ return currentFps } }