MCPcopy
hub / github.com/EngoEngine/engo / rafPolyfill

Function rafPolyfill

engo_js.go:262–295  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

260}
261
262func rafPolyfill() {
263 vendors := []string{"ms", "moz", "webkit", "o"}
264 if window.Get("requestAnimationFrame").Type() == js.TypeUndefined {
265 for i := 0; i < len(vendors) && window.Get("requestAnimationFrame").Type() == js.TypeUndefined; i++ {
266 vendor := vendors[i]
267 window.Set("requestAnimationFrame", window.Get(vendor+"RequestAnimationFrame"))
268 window.Set("cancelAnimationFrame", window.Get(vendor+"CancelAnimationFrame"))
269 if window.Get("cancelAnimationFrame").Type() == js.TypeUndefined {
270 window.Set("cancelAnimationFrame", window.Get(vendor+"CancelRequestAnimationFrame"))
271 }
272 }
273 }
274
275 lastTime := 0.0
276 if window.Get("requestAnimationFrame").Type() == js.TypeUndefined {
277 window.Set("requestAnimationFrame", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
278 currTime := js.Global().Get("Date").New().Call("getTime").Float()
279 timeToCall := math.Max(0, 16-(currTime-lastTime))
280 window.Call("setTimeout", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
281 args[0].Invoke(currTime + timeToCall)
282 return nil
283 }), timeToCall)
284 lastTime = currTime + timeToCall
285 return nil
286 }))
287 }
288
289 if window.Get("cancelAnimationFrame").Type() == js.TypeUndefined {
290 window.Set("cancelAnimationFrame", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
291 js.Global().Get("clearTimeout").Invoke(args[0])
292 return nil
293 }))
294 }
295}
296
297// RunIteration runs one iteration per frame
298func RunIteration() {

Callers 1

CreateWindowFunction · 0.85

Calls 4

GetMethod · 0.80
TypeMethod · 0.65
SetMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected