Real Software Forums
http://forums.realsoftware.com/

Timer Lag
http://forums.realsoftware.com/viewtopic.php?f=4&t=47794
Page 1 of 1

Author:  joe [ Sun May 05, 2013 1:11 am ]
Post subject:  Timer Lag

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! :)

Author:  ktekinay [ Sun May 05, 2013 1:51 am ]
Post subject:  Re: Timer Lag

Is the experience the same if you run the compiled version of your app?

Author:  joe [ Sun May 05, 2013 10:15 am ]
Post subject:  Re: Timer Lag

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

Author:  DaveS [ Sun May 05, 2013 10:39 am ]
Post subject:  Re: Timer Lag

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)

Author:  ktekinay [ Sun May 05, 2013 11:29 am ]
Post subject:  Re: Timer Lag

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?

Author:  joe [ Sun May 05, 2013 7:01 pm ]
Post subject:  Re: Timer Lag

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.

Author:  DaveS [ Sun May 05, 2013 7:11 pm ]
Post subject:  Re: Timer Lag

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....

Author:  joe [ Sun May 05, 2013 7:35 pm ]
Post subject:  Re: Timer Lag

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! :D

Thanks guys for giving your time to a noob :oops:

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/