Jump to content

window.setTimeout vs Frame Delay Ticking


MackeyK24
 Share

Recommended Posts

What is the IMPACT in babylonjs of using window.setTimeout and window.setInterval in your babylon js script code logic vs some kins of frame delay tracking flags and check that time has expired in the 'tick' function then execute action function.

Is it 'TABOO' to use browser based timeout and interval functions in your babylonjs game logic 

Is it preferred to use window.requestAnimationFrame game loop (TICKING) to execute DELAYED or INTERVALED functions ???

As Always... Thanks for any info :)

 

Link to comment
Share on other sites

I try to avoid setInterval, but it's more a personal preference than anything taboo.

setInterval doesn't report errors or guarantee execution (I didn't know it was CPU load, but thought it was duration of function).  setTimeout calling setTimeout (ie: tail recursion) is considered better by some.  Here is a setInterval npm using requestAnimationFrame:
https://github.com/nk-components/request-interval/blob/master/index.js

WHY you are using setInterval is also important.  If you are using it to trigger an action every x ms that seems OK.  I would say that if you are using setInterval only to check for a condition in a loop, progressing a game loop, or sequencing of events/actions that continuation passing style (CPS) or Promises may be better (like onComplete callback for animations) and will react faster.  For really convoluted chaining I may use something like redux-saga (great for game loops) with testable code from the generator functions, even if you skip the redux reducers.  Both CPS and generators can get hard to fathom, but we also have Promises or RxJS!  Probably more than you wanted to hear...
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...