Arkanoid: "Sleep 10" to reduce CPU usage
This is about a post at http://community.thinbasic.com/index...13310#msg13310
_________________________________________________
Petr,
I'm not sure SLEEP 10 is the solution to reduce CPU usage especially on fast processors having multy core.
On those CPU SLEEP 10 add a visible stepping and does not reduce any CPU usage.
The method I think is best is to pass a time slice to Windows to manage events. And this is done using DOEVENTS or similar methods. But this is already done in thnBasic Core engine every time a WHILE keyword is encountered. To prove that, when you execute a UI script having a main WHILE/WEND loop, CPU is almost at zero even if thinBasic engine is parsing continuously message pump of the script.
I think you have to check inside TBGL module and see if after creating TBGL window you have a CALLBACK fucntion that handle the windows events. If you have, try to check if that callback is taking some time. If you have no CALLBACK for TBGL windo, create one that does not handle eny event but just pass them to the standard window function.
I will investigate more on this.
Ciao
Eros
Re: Arkanoid: "Sleep 10" to reduce CPU usage
Hi Eros,
the window is created old good Petzold way, so pure Win32 window with callback WndProc.
It is executed approximately various number of times in second on my PC, but it does almost nothing :)
Processed messages are:
%WM_CREATE
%WM_ERASEBKGND
%WM_MOUSEWHEEL
%WM_SIZE
%WM_MOVE
%WM_CLOSE
%WM_DESTROY
%WM_SYSCOMMAND
So as you see, many of them get processed just once.
The whole WndProc take almost unmeasurable time, and is executed approximately few times a second in ideal case.
Petr
P.S. Following script shows 99% CPU on AMD Sempron 3400+ 64bit
[code=thinbasic]
while 1
wend
[/code]
Re: Arkanoid: "Sleep 10" to reduce CPU usage
What value do you return in FUNCTION on %WM_ERASEBKGND notification message?
Re: Arkanoid: "Sleep 10" to reduce CPU usage
Hi Eros,
FUNCTION = %TRUE
Petr
Re: Arkanoid: "Sleep 10" to reduce CPU usage
OK thanks, Return code not zero means you handle the event so ok.
Quote:
Originally Posted by Psch
P.S. Following script shows 99% CPU on AMD Sempron 3400+ 64bit
[code=thinbasic]
while 1
wend
[/code]
That's because it is not using UI module.
I'm not on my computer so I cannot test right now but if it goes almost 100% CPU there must be something from my side.
Thanks I will check soon.
Re: Arkanoid: "Sleep 10" to reduce CPU usage
I tried to use UI:
Quote:
uses "UI"
while 1
wend
And this way I get from 45 to 55%
Thanks,
Petr
Re: Arkanoid: "Sleep 10" to reduce CPU usage
ATTENTION: use attached thinCore only for testing !!!!_________________________________________________
Petr,
please test attached thinCore.dll and see if it makes any difference.
Do not use any SLEEP or add any UI module in order not to influence your tests.
Thanks a lot
Eros
PS: File removed.
Re: Arkanoid: "Sleep 10" to reduce CPU usage
How did you do that ;D
Seems to work ok! In some TBGL scripts it seems the FPS is suddenly limited to very stable 64 FPS or so, but in others ( TopDown, tbglBenchmark ) I get the same as before, so up to 850 FPS. Seems quite ok!
But CPU hogging is at very low level, mostly reported as 0 :)
Thanks thanks!,
Petr
Re: Arkanoid: "Sleep 10" to reduce CPU usage
Re: Arkanoid: "Sleep 10" to reduce CPU usage
Mostly 0%,
so perfect!
The "worst" was about 2% :)
Petr