![]() ![]() What platform are you running on? Does this ever happen other than on the first tick? Does it happen every time on the first tick? Some more information would be helpful.Īs an aside, you're overestimating your diffTime because you're setting lastUpdateTime before you do a whole bunch of things. I ran the same code and the numbers made sense. Regarding your times, you say that it happens "all the time" although from that output it looks like it happens only the first time. So if your loop does even 2 iterations its already more expensive than a modulus operator. Your loop will perform almost the same number of operations each iteration, since it has to perform the condition check, the subtraction, the assignment and a branch (which can itself be expensive). The modulus operator will perform a constant number of arithmetic operations, say 4 worst-case. I presume you're not an assembly programmer. You're reinventing the wheel which is both unnecessary and less reliable than the browser's implementation. It looks like you want to update every so often. The maths is simple: 0 <</a> updateTime - diffTime < updateTime.
Of course you're getting values that are <= updateTime = 1000/60 ~ 16, because you set the interval to be such: You loop until diffTime < updateTime and then execute the new timer for a delay of updateTime - diffTime. What is that while loop doing? Why not just have a modulus operator after rounding and do it in 1 step? Why are you subtracting this difference in such a strange manner? On what basis do you claim that the time hasn't passed? I see no checking of any value. If
I assign lastTimeUpdate because I want to find out how long it has taken to get to this frame and how long the frame has taken, so I can process it accordingly. I have submitted a bug report to mozilla. Oddly I tested it before hand and it didn't work correctly. I thought I would just recheck both browsers and I go the same result in Aurora, but Chrome worked as expected. Currently I am using Mozilla Aurora 6.0a and Google Chrome 14.0.803 dev. When I have tested it, it seems to work like setTimeout(func), so no millisecond elapse. Here is another log that does not do it only on the first tick. For example I have 15.666666666666668, but the difference in time after it is 12. Looking at the updateTime and the before diffTime, the timing doesn't make sense. The number always comes out less than updateTime given to setTimeout. The reason I know that the updateTime hasn't passed is that print out the diffTime before I manipulate it. The while reduces the diffTime into 1000 / 60 blocks of time, especially when it is greater than 16 ms. I don't use setInterval because it stacks the calls. Here, I have set it to be 1000 / 60 milliseconds, but I get numbers there are less than that, which doesn't make sense. ![]() When setTimeout is called, the time that has passed during the updateTime does not seem to of passed when diffTime is updated. I have a loop kind of like this var lastUpdateTime = (new Date()).getTime(),Ĭonsole.log(" - before diffTime:" + diffTIme) Ĭonsole.log(" - after diffTime:" + diffTime) Ĭonsole.log(" - updateTime:" + updateTime)
0 Comments
Leave a Reply. |