• Print

Author Topic: ON TIMER, STOP - remembered events [fixed* (refer to final replies)]  (Read 516 times)

OlDosLover

  • Hero Member
  • *****
  • Posts: 3972
  • OlDosLover
    • Email
Re: ON TIMER, STOP - remembered events
« Reply #15 on: March 18, 2013, 12:25:46 PM »
Hi all,
    Sorry. See http://www.qb64.net/forum/index.php?topic=10834.msg90753#msg90753
Perhaps we can rewrite your program to avoid this?
OlDosLover.

RhoSigma

  • Jr. Member
  • **
  • Posts: 75
  • 4 * 1.0079 = 4.0026
    • Email
Re: ON TIMER, STOP - remembered events
« Reply #16 on: March 18, 2013, 12:36:21 PM »
Hi MajorApollo,

finally I've to beg your pardon for screwing up your thread with my off topic concerns about the whole timer thing. So, here is my try to show the functionality you're looking for, but unfortunately it seems that the described behaviour in the wiki is not implemented correctly either.

I've tried this example program in the old QBasic 1.1 too, and it doesn't work with it eiter, so Galleon may call this behaviour of QB64 (SDL) a compatiblity issue and not going to correct it anyway (at least for QB64 GL), which would mean that ON TIMER is useless and will probably remain useless.

Also I've found, that you even must re-type the ON TIMER(X) GOSUB label line to actually resume the the timer in QB64 SDL, a simple TIMER ON doesn't work. QBasic 1.1 does not need the re-typed line.

To bring it up to the point, the whole TIMER thing is only usable as long you never use any delaying instructions anywhere in your program and you don't need the TIMER STOP thing remembering the missed events.

Regards, RhoSigma

Code: [Select]
'======================================
'=== TIMER STOP - remembered events ===
'======================================
'=== This example intentionally doesn't use any SLEEP, _DELAY or _LIMIT
'=== instructions to avoid the TIMER failure discussed in this thread.
'===
'=== Unfortunately it seems that there is more weired behaviour regarding
'=== the use of ON TIMER and the rememberance of events during paused
'=== periods. So finally I've to say it again, it's useless.
'===
'=== I've intentionally used the standard TIMER (without a number), so
'=== the program can also run in QBasic 1.1, but it works not there
'=== nor in QB64 SDL, I don't use the GL version, so somebody else must
'=== test it in QB64 GL.
'===
'=== As you can see, not just one event is remembered, the counter just
'=== moves on from where it was paused, or maybe the events are remembered,
'=== but none of it is triggered/processed after TIMER ON is resumed.

c% = 0
ON TIMER(1) GOSUB Counter 'one second counting period
TIMER ON

PRINT "press (p) for pause, (r) to resume, (q) to quit..."

s$ = "ON  "
i$ = ""
sc& = 0
WHILE i$ <> "q"
    LOCATE 3, 1
    PRINT "            Current Timer State: "; s$
    IF sc& > 0 THEN
        '--- this prints only if STOP ---
        LOCATE 4, 1
        PRINT "Event counter while Timer is ON:"; c%; "("; c% + (INT(TIMER) - sc&); ")"
        LOCATE 5, 1
        PRINT "  Expected events while stopped:"; INT(TIMER) - sc&
    ELSE
        '--- this prints only if ON ---
        LOCATE 4, 1
        PRINT "Event counter while Timer is ON:"; c%
        LOCATE 5, 1
        PRINT "  Expected events while stopped:"; sc&
    END IF
    i$ = INKEY$
    IF i$ = "p" AND s$ = "ON  " THEN 'only allow pause, if currently ON
        TIMER STOP
        s$ = "STOP"
        sc& = INT(TIMER)
    ELSEIF i$ = "r" AND s$ = "STOP" THEN 'only allow resume, if currently STOP
        ON TIMER(1) GOSUB Counter 'without this the timer never resumes in QB64 SDL (Bug?)
        TIMER ON
        s$ = "ON  "
        sc& = 0
    END IF
WEND

TIMER OFF
PRINT
PRINT "I'm sorry, just as I say - useless at all (at least in QB64-SDL)..."
END

Counter:
c% = c% + 1
RETURN

Download archives of my QB64 stuff:
Polygon functions: http://rhosigma-cw.net/down/GfxDemos.zip
Screen savers: http://rhosigma-cw.net/down/ScrSavers.zip
Libraries collection: http://rhosigma-cw.net/down/QB64Library.zip (extract into the QB64 folder, a new sub-folder "QB64Library" is created)

MajorApollo

  • Newbie
  • *
  • Posts: 10
Re: ON TIMER, STOP - remembered events
« Reply #17 on: March 18, 2013, 06:00:58 PM »
Quote from: RhoSigma on March 18, 2013, 12:36:21 PM
Hi MajorApollo,

finally I've to beg your pardon for screwing up your thread with my off topic concerns about the whole timer thing. So, here is my try to show the functionality you're looking for, but unfortunately it seems that the described behaviour in the wiki is not implemented correctly either.

I've tried this example program in the old QBasic 1.1 too, and it doesn't work with it eiter, so Galleon may call this behaviour of QB64 (SDL) a compatiblity issue and not going to correct it anyway (at least for QB64 GL), which would mean that ON TIMER is useless and will probably remain useless.

I've also discovered using the original GOTO statement when resuming the timer does indeed process the last, and only the last, call/gosub. The way my 500+ timers work are dependant on a combinations of variables used in the CALL statement so I cannot resume the timer with the original CALL thus the variables change - so while that does work and only finishes 1 event it still doesn't do the trick. I do use _DELAY to some extent, the greatest being .008 and no _delay statements, if skipped once would impact the functionality of my program as I have implemented my own delay'ing system based on system time so I can delay some parts while others still run. I might as well rewrite those few thousands lines of counter code to my own new system that looks like I'll have to develop. Sigh :/

OlDosLover

  • Hero Member
  • *****
  • Posts: 3972
  • OlDosLover
    • Email
Re: ON TIMER, STOP - remembered events
« Reply #18 on: March 19, 2013, 12:29:14 AM »
Hi all
   
Quote
The way my 500+ timers work are dependant on a combinations of variables used in the CALL statement so I cannot resume the timer with the original CALL thus the variables change - so while that does work and only finishes 1 event it still doesn't do the trick.
    Wow thats a lot of timers! Perhaps if you posted your code here the community may be able to help you out. Good luck which ever way you choose.
OlDosLover.

MajorApollo

  • Newbie
  • *
  • Posts: 10
Re: ON TIMER, STOP - remembered events
« Reply #19 on: March 19, 2013, 05:36:33 PM »
Quote from: OlDosLover on March 19, 2013, 12:29:14 AM
Hi all
   
Quote
The way my 500+ timers work are dependant on a combinations of variables used in the CALL statement so I cannot resume the timer with the original CALL thus the variables change - so while that does work and only finishes 1 event it still doesn't do the trick.
    Wow thats a lot of timers! Perhaps if you posted your code here the community may be able to help you out. Good luck which ever way you choose.
OlDosLover.

Yeah it is. You should see the spreadsheet I spent days making before implementing each ones duty. Since the ON TIMER system itself is pretty simplistic and I've already got a precision timer routine that starts when the program does I'm pretty sure I can create my own replacement; it's just a bummer I have to now.

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4691
  • QB Forever
    • Email
Re: ON TIMER, STOP - remembered events
« Reply #20 on: April 03, 2013, 10:10:27 PM »
QB64-GL already interrupts _DELAY and _LIMIT commands to call TIMER events (and screen updates). I will alter SLEEP to do the same.

ON TIMER events are not multi-threaded events, nor were they multi-threaded in QBASIC, and for good reason.
Something old... Something new... Something borrowed... Something blue...

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4691
  • QB Forever
    • Email
Re: ON TIMER, STOP - remembered events
« Reply #21 on: April 04, 2013, 05:14:34 AM »
I've updated SLEEP to make events break a SLEEP or timed SLEEP so it will not work like QBASIC.

Note: TIMER events do not accumulate in multiple when timer(s) are stopped.

PS. Also revised the code of _LIMIT and _DELAY for more accurate timing whilst maintaining events.

PPS: QB64 will only allow up to 100 interruptions of a _DELAY/_LIMIT wait per second. So if an ON TIMER event is set to fire faster than 100 times per second it will slow to 100 times per second when _DELAY/_LIMIT are active. This is so CPU usage does not go through the roof. Setting a higher _LIMIT, such as _LIMIT 1000 would permit a greater amount of ON TIMER events to fire if so desired.
« Last Edit: April 04, 2013, 05:32:52 AM by Galleon »
Something old... Something new... Something borrowed... Something blue...

  • Print