New topic: 

Timer Lag

<http://forums.realsoftware.com/viewtopic.php?t=47794>

         Page 1 of 1
   [ 8 posts ]                 Previous topic | Next topic          Author  
Message        joe          Post subject: Timer LagPosted: Sun May 05, 2013 
1:11 am                         
Joined: Sun Apr 02, 2006 7:25 pm
Posts: 6                Hi guys, hope you're all well.

I'm a few hours into writing my first game and I've come across an issue that I 
can't figure out. It's a very simple game, the interface is comprised mostly of 
custom canvas progress bars - no open gl or anything like that. I'm using a 
timer set to 40ms that runs two methods, one to update the game, and one to 
update the interface. All was going well, until I tried watching a video whilst 
debugging and my performance went through the floor. The rest of my computer 
still runs fine, but bars that should take a second to fill (and do when no 
video is running) are taking as long as 4 seconds to fill instead.

I read that the timer steps are influenced by the stress on your computer, but 
it's so bad that I'm guessing I must be doing something wrong. I've tried 
adjusting the timer interval but it doesn't seem to make a difference... I'm 
stumped!

Any help would be greatly appreciated!    
                             Top                ktekinay          Post subject: 
Re: Timer LagPosted: Sun May 05, 2013 1:51 am                                 
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 582
Location: New York, NY                Is the experience the same if you run the 
compiled version of your app?      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                joe          Post subject: Re: 
Timer LagPosted: Sun May 05, 2013 10:15 am                         
Joined: Sun Apr 02, 2006 7:25 pm
Posts: 6                Thanks for your reply. Yes, it happens whether it's 
running from RS or as a compiled app...  

p.s. I'm using RBStudio 2012 on OSX 10.6.8   
                             Top                DaveS          Post subject: 
Re: Timer LagPosted: Sun May 05, 2013 10:39 am                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4845
Location: San Diego, CA                1) are you REFRESHING your canvas? or 
using INVALIDATE (prefered)

2) you said 40ms.... are you sure the work being intiated by the timer firing 
is complete by the time it fires again? As an experiment, increase the timer 
period, and see what the result it.

3) I found that using progressbars (the actual control), that they are 
"expensive" to update frequently (if you are going from say 0 to 10,000 .... 
DON'T refresh it every single interval... divide it into intervals where each 
interval is at least 2 pixels of the width of your progress bar  .. 
(personallly I just use 5% of the width.. ie. update it 20x max)      
_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                ktekinay          Post subject: 
Re: Timer LagPosted: Sun May 05, 2013 11:29 am                                 
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 582
Location: New York, NY                Where is the video playing, within the 
app or in another app?

I just don't feel like we have enough information to troubleshoot this yet. Is 
this code you can share?      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                joe          Post subject: Re: 
Timer LagPosted: Sun May 05, 2013 7:01 pm                         
Joined: Sun Apr 02, 2006 7:25 pm
Posts: 6                Thanks again for replying. Sorry I didn't realise how 
vague I was being!

The problem occurs when I watch an external video in my browser, although any 
kind of outside CPU usage seems to have a detrimental effect to the run speed. 
It's also quite inconsistent - when under stress, the update speeds surge and 
slow resulting in very jumpy animations.

I am using a custom progress bar class that uses a value between 0 and 100 for 
the drawing. When the timer fires, it calls the UpdateModel method which 
updates all the game values (about 40 lines of code) and then the 
UpdateInterface method which updates the values of all the progress bars and 
then calls refresh on each of them, not Invalidate (not heard of this before). 
The interface method is only 20 lines of code.

I considered that maybe I was asking too much in such a short time frame (40ms) 
but I figured this couldn't be the case as when the debug/app is the only thing 
running, I get good performance.

I hope this information is more helpful, if needed I can post some code and/or 
a video in the morning.   
                             Top                DaveS          Post subject: 
Re: Timer LagPosted: Sun May 05, 2013 7:11 pm                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4845
Location: San Diego, CA                REFRESH causes a control to redraw 
itself immediately... as in it interrupts the current flow to call its PAINT 
method (which may be internal, or maybe public [in the case of a Canvas])

INVALIDATE marks the control as NEEDING to be REFRESHED, and the system will do 
it as soon as it can, usually when the current loop or process completes.

For example.
for i=1 to 100
  <do some stuff>
  canvas1.refresh  ' FORCED REFRESH
next i


compared to 
for i=1 to 100
  <do some stuff>
  canvas1.invalidate
next i
...... <---- system will fire the paint event here automatically


For the users perspective both will VISUALLY be identical.... but the first 
will take longer to run, because it is redrawing the canvas 99 times that the 
user will never notice.


Obviously there are time where you need to use REFRESH to force an on going 
animation for example.... but 99% of the time INVALIDATE will make you code 
faster....      
_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                joe          Post subject: Re: 
Timer LagPosted: Sun May 05, 2013 7:35 pm                         
Joined: Sun Apr 02, 2006 7:25 pm
Posts: 6                Oh man....

I went into my UpdateInterface method, command-f to find 'refresh' and replace 
all with 'invalidate', clicked run and problem solved... this baby is running 
like a dream! Thanks Dave you've cracked it for me! I was starting to think 
maybe RB was a bad choice for my game (as basic as it is) but you've just blown 
this thing wide open! 

Thanks guys for giving your time to a noob   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 8 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to