WaitEvent() in Blitz3D with userlibs
Blitz3D Forums/Blitz3D Userlibs/WaitEvent() in Blitz3D with userlibs
| ||
I'm trying to recreate the effect of WaitEvent() in Blitz3D. I don't really care about the possible events, I just want my program to be idle and not use my processor's power if I don't do anything. I tried it using WaitForInputIdle from user32.dll, but that doesn't seem to work. Any suggestions? Think it can be done? |
| ||
if it's really only the blitz app that you want to watch for events, you could do it with some kind of screensaver mode. example: ... old_mx=mx old_my=my mx=mousex() my=mousey() k=0 for i=1 to 255 if keydown(i) then k=1 exit next if (k<>0) or (mx<>old_mx) or (my<>old_my) lastuseraction=millisecs() endif if millisecs()>(lastuseraction-1000) then delay 100 endif ... It will not be completely idle, but it will kind of slumber as soon as the user doesn't interact for a second. I guess the CPU usage will drop to about 5%. If you want to use real WaitEvent System Calls, take a look at the BlitzWin3D Include Files. |
| ||
Thanks jfk, your screensaver idea is an interesting tip, even though it's not really what I need for my current project. I checked out BlitzWin3D, but the WaitEvent() function only returns an event. It doesn't wait in idle mode, so CPU usage is still high. EDIT: I just put your screensaver method in my program, and it works better than I thought. The switching between "screensaver" mode (10 fps) and normal mode (50 fps) goes very fast and smooth. Excellent alternative for idle mode! |
| ||
BTW you may also use a special loop for the "slumber mode", that only checks for user action and won't update the screen, this way you'll reduce the cpu usage even more. |
| ||
Oh man! That's kind of daft, that I didn't think of that myself. This is basicly what I had: *Check for input* If MilliSecs() - lastInteraction > 2000 Then Delay 100 EndIf *Draw stuff* And I didn't even think of adding a simple 'Else': *Check for input* If MilliSecs() - lastInteraction > 2000 Then Delay 100 Else *Draw stuff* EndIf Hehe, oh well, thanks again jfk. Task Manager now says my program takes 0% CPU power. :D EDIT: As a matter of fact, if I remove the 'Delay 100' it still runs at 0% CPU. So I'm going to just let my program check for input at 50 fps and only draw when the user does something. Seems kind of obvious now. |