Xojo Conferences
XDCMay2019MiamiUSA

[RB List] Getting the Timer to work (Real Studio getting started Mailinglist archive)

Back to the thread list
Previous thread: launch a program daily
Next thread: Windows thinks I have a demo version of RealBasic


RE: [RB List] MouseRightButton ?   -   RBNUBE
  [RB List] Getting the Timer to work   -   Eirik Karlsen
    Re: [RB List] Getting the Timer to work   -   Joseph J. Strout
    Re: [RB List] Getting the Timer to work   -   Phil M
    Re: [RB List] Getting the Timer to work   -   Will Brokenbourgh
    Re: [RB List] Getting the Timer to work   -   Andrew Keller
    Re: [RB List] Getting the Timer to work   -   Eirik Karlsen
    Re: [RB List] Getting the Timer to work   -   Phil M
    Re: [RB List] Getting the Timer to work   -   Eirik Karlsen

[RB List] Getting the Timer to work
Date: 01.02.05 21:24 (Tue, 01 Feb 2005 21:24:20 +0100)
From: Eirik Karlsen
I'm about to start on speed optimizing subs and code. For this purpose I want
to run code segments in a loop and have the timer interrupt after 1sec.
This way one can easily identify slow code, and watch progress as
modifications are made.

But could I get the timer to work?? Nope!

Should be a very simple task, and if I'm not too mistaken I've done a very
simple error...
Can you spot it?
Testcode here:
<http://home.online.no/~eikarlse/temp/>

Re: [RB List] Getting the Timer to work
Date: 01.02.05 21:33 (Tue, 1 Feb 2005 14:33:21 -0600)
From: Joseph J. Strout
At 9:24 PM +0100 2/1/05, Eirik Karlsen wrote:

>I'm about to start on speed optimizing subs and code. For this purpose I want
>to run code segments in a loop and have the timer interrupt after 1sec.

Timers can't interrupt code. To do that sort of sampling, you need
to use a real profiler. If you're running on a Mac, try Shark, part
of the free CHUD tools from Apple.

Best,
- Joe

Re: [RB List] Getting the Timer to work
Date: 01.02.05 21:33 (Tue, 1 Feb 2005 12:33:32 -0800)
From: Phil M
On Feb 1, 2005, at 12:24 PM, Eirik Karlsen wrote:

> I'm about to start on speed optimizing subs and code. For this purpose
> I want to run code segments in a loop and have the timer interrupt
> after 1sec. This way one can easily identify slow code, and watch
> progress as modifications are made.
>
> But could I get the timer to work?? Nope!
>
> Should be a very simple task, and if I'm not too mistaken I've done a
> very simple error... Can you spot it?

Haven't looked at the code, but...

Timers are passive and will only fire when there are no other processes
going on. Since the loop is running full speed, the Timer does not get
an opportunity to trigger.

Instead, you can hold a target time in Microseconds and compare the
current time versus the end time within the loop.

Dim endTime As Double
endTime = Microseconds + 1000000 // 1 million microseconds for
each second

Do Until (Microseconds > endTime)
// intensive code here
Loop

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: [RB List] Getting the Timer to work
Date: 01.02.05 21:52 (Tue, 1 Feb 2005 12:52:42 -0800)
From: Will Brokenbourgh
You may want to try executing the test code in a Thread class. I added your test code into the Run method of a Thread class and the timer worked.

I'm relatively new to RB, so this may not be the best solution. Sorry, I can't post my updated code at the moment.

Will
----- Original Message -----
From: Eirik Karlsen
To: Getting Started
Sent: Tuesday, February 01, 2005 12:24 PM
Subject: [RB List] Getting the Timer to work

I'm about to start on speed optimizing subs and code. For this purpose I want
to run code segments in a loop and have the timer interrupt after 1sec.
This way one can easily identify slow code, and watch progress as
modifications are made.

But could I get the timer to work?? Nope!

Should be a very simple task, and if I'm not too mistaken I've done a very
simple error...
Can you spot it?
Testcode here:
<http://home.online.no/~eikarlse/temp/>

--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Regards
Eirik Karlsen

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: [RB List] Getting the Timer to work
Date: 01.02.05 22:03 (Tue, 1 Feb 2005 16:03:47 -0500)
From: Andrew Keller
> Should be a very simple task, and if I'm not too mistaken I've done a
> very
> simple error...

The concept sure is easy, but the error isn't as much. The reason that
the timer isn't working is that your busy code (the code that sucks all
the processor time) won't let anything else happen until it's done.

I would put that code in a thread, and not in the window. It's very
simple. Create a new class, and set it's super to a Thread, and call
it something meaningful. Then, in the Open event of your window, run
the thread, like this:

Sub Open()
Dim t As MyThread
t = New MyThread
t.Run
End Sub

That code will simply run the thread and forget about it. Since you
want to be able to access the tread later, in the timer, you will want
to make that variable a property on the window and not a variable in
the event. The rest of the sample code is the same. It's very simple.

In the timer's Action event, just call it like any other class.

MyThread.WhateverPropertyOrMethod

In order to access variables in the thread, you may want to make the
variables properties in the thread and not variables in the Run Event.

HTH!

Andrew Keller

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: [RB List] Getting the Timer to work
Date: 02.02.05 00:28 (Wed, 02 Feb 2005 00:28:53 +0100)
From: Eirik Karlsen
I'll keep that thread stuff in mind...I'm convinced it will be needed a
little later in the project.

In the meantime I got the work done using Phil's suggestion.
Were now able to point out the exact hotspots in the code.
The basic problem is very simple...we're back to (slow) picture drawing
again!
RB is one of the 2-3 fastest BASICs around, and its picture drawing isn't
really slow,
its jut that I do so much of it, and at such short intervals.

I've had some great help from this list regarding speed before, very simple
and very effective code.

However I'm a bit more worried about this latest speed problem...I see no
way out of it, and if this
turns out to be the case I'm afraid the whole project will probably have to
ba abandoned ...
and after working on this for 200 hours I'd really hate that.

Once again the code is simple, and reming out just two lines makes it run
40 times faster.

I've posted the culprit code here:
<http://home.online.no/~eikarlse/temp/>

Concentrate on the DataRPMgauge method...thats where the problem is.
Description / explanations are included there.







Andrew Keller wrote:

> > Should be a very simple task, and if I'm not too mistaken I've done a
> > very
> > simple error...
>
> The concept sure is easy, but the error isn't as much. The reason that
> the timer isn't working is that your busy code (the code that sucks all
> the processor time) won't let anything else happen until it's done.
>
> I would put that code in a thread, and not in the window. It's very
> simple. Create a new class, and set it's super to a Thread, and call
> it something meaningful. Then, in the Open event of your window, run
> the thread, like this:
>
> Sub Open()
> Dim t As MyThread
> t = New MyThread
> t.Run
> End Sub
>
> That code will simply run the thread and forget about it. Since you
> want to be able to access the tread later, in the timer, you will want
> to make that variable a property on the window and not a variable in
> the event. The rest of the sample code is the same. It's very simple.
>
> In the timer's Action event, just call it like any other class.
>
> MyThread.WhateverPropertyOrMethod
>
> In order to access variables in the thread, you may want to make the
> variables properties in the thread and not variables in the Run Event.
>
> HTH!
>
> Andrew Keller
>
> __

Re: [RB List] Getting the Timer to work
Date: 02.02.05 18:39 (Wed, 2 Feb 2005 09:39:45 -0800)
From: Phil M
On Feb 1, 2005, at 3:28 PM, Eirik Karlsen wrote:

> Were now able to point out the exact hotspots in the code. The basic
> problem is very simple...we're back to (slow) picture drawing again!
> RB is one of the 2-3 fastest BASICs around, and its picture drawing
> isn't really slow, its jut that I do so much of it, and at such short
> intervals.

I am getting 38-40 draws per second on a Powerbook 500 mhz. Personally
I see this as acceptable even for games, but I do not know how complex
of a graphic system you are developing.

> However I'm a bit more worried about this latest speed problem...I see
> no way out of it, and if this turns out to be the case I'm afraid the
> whole project will probably have to ba abandoned ... and after working
> on this for 200 hours I'd really hate that.

There might be another option, which is to use either the built-in RB3D
control or work directly in OpenGL via declares. Asher Dunn has a
OpenGL declare library which might be of use to you:

http://www.fireyesoftware.com/code/opengldeclares/

If you are interested in seeing what the RB3D control can do, there is
the Renegades game engine (beta) and the Armageddon game. Both are
available with source code, but I do not have the links off-hand; but
you can search the Games archive for this.

Even if you are not developing a game, it seems that you graphic
requirements are similar to a game. I recommend that you get on the
"RB Games" list since most of the image gurus which would be able to
answer your questions frequent that list.

> Once again the code is simple, and reming out just two lines makes it
> run 40 times faster.

Comment out which lines?

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: [RB List] Getting the Timer to work
Date: 02.02.05 21:08 (Wed, 02 Feb 2005 21:08:32 +0100)
From: Eirik Karlsen
I'm getting what appears to be about 200 frames/sec for each of the 4
canvases (when run separately).
That gives a total of 50 frames/sec for all. This should be adequate in
itself, but I suspect my canvas
code runs 'head to tail', leaving no time for other tasks. I'll have a
closer look at that scenario. I'll
also check out the RB3D...have never used 3D or sprites before.

The two lines clearly marked out in the DataRPMgauge method in this source:
<http://home.online.no/~eikarlse/temp/>

Phil M wrote:

> .......
>
> Comment out which lines?
>