![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
On Jan 31, 5:17 pm, Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> wrote: Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> writes: And that's disregarding the fact that you're displaying *each frame* for *every* call to run() Never mind, I misread your code. It still doesn't make any sense, though. Joost. Are you saying time-based animation doesn't make sense? There are a LOT of videogames out there that work that way. |
#12
| |||
| |||
|
|
On Feb 1, 1:07 pm, timothytoe <timothy... (AT) gmail (DOT) com> wrote: On Jan 31, 5:17 pm, Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> wrote: Joost Diepenmaat <jo... (AT) zeekat (DOT) nl> writes: And that's disregarding the fact that you're displaying *each frame* for *every* call to run() Never mind, I misread your code. It still doesn't make any sense, though. Comments added. |
|
Joost. Are you saying time-based animation doesn't make sense? There are a LOT of videogames out there that work that way. No, he's not. But setting two setIntervals in motion that both call the same function may well have unexpected results. Contrary to the "two thread" inference, the two will never call the function at the same time - javascript is single threaded. About half the time, the one set for a 20ms interval will call the function twice between calls from the one set for a 30ms interval. Other times it will call once. The delay between calls will, in theory, be one of 20ms, 10ms or 0ms. The delay in practice might be much longer and more unevenly spaced depending on a variety of factors beyond the script programmer's control or knowledge. Issues resulting from that may or may not be significant. That's the problem. It's a crapshoot. It's mostly Firefox is so |
|
-- Rob |
#13
| |||||
| |||||
|
|
On Jan 31, 7:28 pm, RobG <rg... (AT) iinet (DOT) net.au> wrote: On Feb 1, 1:07 pm, timothytoe <timothy... (AT) gmail (DOT) com> wrote: No, he's not. But setting two setIntervals in motion that both call the same function may well have unexpected results. Contrary to the "two thread" inference, the two will never call the function at the same time - javascript is single threaded. About half the time, the one set for a 20ms interval will call the function twice between calls from the one set for a 30ms interval. Other times it will call once. The delay between calls will, in theory, be one of 20ms, 10ms or 0ms. The delay in practice might be much longer and more unevenly spaced depending on a variety of factors beyond the script programmer's control or knowledge. Issues resulting from that may or may not be significant. |
|
That's the problem. It's a crapshoot. |
|
It's mostly Firefox is so choppy. |
|
But there's no "available cpus" or yeild() or thread.priority or anything. |
|
Should I double thread (double setTimeout), or not? |
#14
| |||||
| |||||
|
|
On Jan 31, 1:27 pm, VK <schools_r... (AT) yahoo (DOT) com> wrote: On Feb 1, 12:14 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de Also, what about double threading for animations? Is it too much of a CPU hog to start setInterval twice for one run() method? Probably not. What is important is that the intervals do not get too short and that they do not overlap for changing the same property. Which is why window.setTimeout() should be used in favor of window.setInterval() in animations. I'm using time-based animation. |
|
Distance is calculated on a rationalValue (or floating point position [0-1]). The "property" is always a number from [0-1]. In a 2 sec animation, if 1 sec had elapsed, then the position would be 0.5. |
|
window.setInterval(run, 20); if(this.isDoubleThreaded) this.intervalId2 = window.setInterval(run, 30); } |
|
----+----+----+----+----+----+----+----+----+----+----+----+---- 0 10 20 30 40 50 60 70 80 90 100 110 120 ms |
|
----+----+----+----+----+----+----+----+----+----+----+----+---- 0 10 20 30 40 50 60 70 80 90 100 110 120 ms |
#15
| ||||
| ||||
|
|
dhtml wrote: On Jan 31, 1:27 pm, VK <schools_r... (AT) yahoo (DOT) com> wrote: On Feb 1, 12:14 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de Also, what about double threading for animations? Is it too much of a CPU hog to start setInterval twice for one run() method? Probably not. What is important is that the intervals do not get too short and that they do not overlap for changing the same property. Which is why window.setTimeout() should be used in favor of window.setInterval() in animations. I'm using time-based animation. Pardon? Is there any other sort of animation? The other kind is frame-based. |
|
Distance is calculated on a rationalValue (or floating point position [0-1]). The "property" is always a number from [0-1]. In a 2 sec animation, if 1 sec had elapsed, then the position would be 0.5. It matters not how far the object is moved but how many steps the motion takes. The more steps, the shorter each interval, the more calls are to be performed, the greater is the CPU load, and the more likely is that your animation does not run smoothly because either your timers accumulate or the layout engine cannot handle it anymore. Accumulation is more likely when you use window.setInterval() instead of window.setTimeout(). I have explained why a few months ago; search the newsgroup. |
|
window.setInterval(run, 20); if(this.isDoubleThreaded) this.intervalId2 = window.setInterval(run, 30); } This is not going to work properly. Consider the timeline here (`*' denotes a call): intv1 * * * * * * intv2 | * | * | * | * steps | | | | | | | | |----+----+----+----+----+----+----+----+----+----+----+----+---- 0 10 20 30 40 50 60 70 80 90 100 110 120 ms Meaning that every 60 ms (60 is the LCM of 20 and 30) the scheduler will have to handle two calls. Since that is not going to happen as the implementation is single-threaded indeed, the second call will be slightly delayed. Nevertheless, at almost the same time you do the animation, moving the object virtually twice per each step. Also note that the second window.setInterval() call happens shortly after the first one, and not simultaneously, and that 10 ms is the minimum timeout that Mozilla on x86 will handle. So the delay that can be expected on interval is increased by at least that time span (consider external interference). A "jumping" animation in place of a smooth one becomes more and more likely: intv1 * * * * * * intv2 | * | | * | * | | * steps | | | | | | | | | | |----+----+----+----+----+----+----+----+----+----+----+----+---- 0 10 20 30 40 50 60 70 80 90 100 110 120 ms The jumping I get i caused by mozilla being a CPU hog for whatever |
|
HTH PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee |
#16
| |||||||||
| |||||||||
|
|
On Feb 1, 11:18 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de> wrote: dhtml wrote: On Jan 31, 1:27 pm, VK <schools_r... (AT) yahoo (DOT) com> wrote: On Feb 1, 12:14 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de Also, what about double threading for animations? Is it too much of a CPU hog to start setInterval twice for one run() method? Probably not. What is important is that the intervals do not get too short and that they do not overlap for changing the same property. Which is why window.setTimeout() should be used in favor of window.setInterval() in animations. I'm using time-based animation. Pardon? Is there any other sort of animation? The other kind is frame-based. you have distance and time and number of frames. |
|
setInterval(f, 20) the function f doesn't fire every 20 ms. It depends how long f takes, among other things, before f can fire again. |
|
If distance-per-frame is a constant, then total time will increase, making the animation time vary greatly between browsers. |
|
This is frame-based animation. |
|
I check the time in each call to _playFrame(). Distance is calculated as a result of elapsed/total. distance = [0-1]. |
|
[...] Accumulation is more likely when you use window.setInterval() instead of window.setTimeout(). I have explained why a few months ago; search the newsgroup. The search feature on Google Groups does not work at all in any browser for any Google username on this computer; I think it has to do with a language preference cookie somewhere. Even when I click "without the language restriction" link, it returns 0 results. |
|
The jumping I get i caused by mozilla being a CPU hog for whatever else it's doing. Adding more timers hogs more CPUs, which contributes to jumpiness in a different way. |
|
If I change the second timer so they're both 20ms. I don't know if that means the other time will have to "yeild" less or not. It could be that the timers have to compete instead of weave and that's not determinable. Even if the LCM was high (lets say I picked 45 for the second setInterval, LCM would be 180); well, I still get jerky behavior. |
|
Even with only 1 timer. It's mozilla. |
#17
| ||||
| ||||
|
|
dhtml wrote: On Feb 1, 11:18 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de> wrote: dhtml wrote: On Jan 31, 1:27 pm, VK <schools_r... (AT) yahoo (DOT) com> wrote: On Feb 1, 12:14 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de Also, what about double threading for animations? Is it too much of a CPU hog to start setInterval twice for one run() method? Probably not. What is important is that the intervals do not get too short and that they do not overlap for changing the same property. Which is why window.setTimeout() should be used in favor of window.setInterval() in animations. I'm using time-based animation. Pardon? Is there any other sort of animation? The other kind is frame-based. you have distance and time and number of frames. I see. The time reference confused me because timing is involved in any animation (delta(x) := t / frames). Time-based animation, as you call it, is the only sensible thing to do on the Web as you can't do moves shorter than 1px. setInterval(f, 20) the function f doesn't fire every 20 ms. It depends how long f takes, among other things, before f can fire again. Yes, I have said that. If distance-per-frame is a constant, then total time will increase, making the animation time vary greatly between browsers. And operating systems. And platforms. It is mostly the system timer tick interval that determines the minimum time resolution that can be achieved in a scripted animation. This is frame-based animation. ISTM you are applying terms on this situation that don't fit. I check the time in each call to _playFrame(). Distance is calculated as a result of elapsed/total. distance = [0-1]. Since you can't measure the elapsed time exactly, that approach is doomed to fail. [...] Accumulation is more likely when you use window.setInterval() instead of window.setTimeout(). I have explained why a few months ago; search the newsgroup. The search feature on Google Groups does not work at all in any browser for any Google username on this computer; I think it has to do with a language preference cookie somewhere. Even when I click "without the language restriction" link, it returns 0 results. I doubt that. Try this: http://groups.google.com/groups?q=se...3APointedEars%... Groups search does not work on Google Wifi. I have narrowed it down to |
|
Nevertheless, Google Groups is flawed enough not to find my article directly (Message-ID: <46EF029E.6050... (AT) PointedEars (DOT) de>, Date: 2007-09-18T00:41:34+02:00, Subject "Re: Need help with textboxes") via a regular search. The following, found with a subject-only search, should work: http://groups.google.com/group/comp..../491749a08ef7c... That's actually good info. |
|
It is your concept that is erroneous. Use window.setTimeout() instead. |
|
PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee |
![]() |
| Thread Tools | |
| Display Modes | |
| |