waitevent
BlitzMax Forums/BlitzMax Programming/waitevent
| ||
Waitevent seems to make my while statement crawl ( I guess because events arent being generated)....However if I move my mouse, the graphics that are supposed to be doing something move quickly..... How can I get around this? |
| ||
Can you post some code? |
| ||
You need to create a timer for screen updating and simply call flip if a EVENT_TIMERTICK was raised by your update timer. When doing event based you can't use regular coding styles anymore (ok you can but you will have to face many problems) |
| ||
thanks Dreamora, I'll have a look at it tonight, that makes sense. :) |
| ||
Been starting to learn bmax and maxgui recently and came across waitevent and thought eewww. Did a forum search and came across this post about using timers for a game loop etc and thought i would post this bit of code here as it might help a few people. If you dont want your game loop to process every timer tick but process as fast as possible when its got nothing else to do try this Global GAME_WIDTH=320 Global GAME_HEIGHT=240 ' create a centered window with client size GAME_WIDTH,GAME_HEIGHT Local wx=(GadgetWidth(Desktop())-GAME_WIDTH)/2 Local wy=(GadgetHeight(Desktop())-GAME_HEIGHT)/2 Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,0,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS) ' create a canvas for our game Local canvas:TGadget=CreateCanvas(0,0,320,240,window) ' create an update timer CreateTimer 60 While True If PeekEvent() PollEvent() Select EventID() Case EVENT_TIMERTICK RedrawGadget canvas Case EVENT_GADGETPAINT Local g=CanvasGraphics(canvas) SetGraphics g SetOrigin 160,120 SetLineWidth 5 Cls Local t=MilliSecs() DrawLine 0,0,120*Cos(t),120*Sin(t) DrawLine 0,0,80*Cos(t/60),80*Sin(t/60) Flip Case EVENT_WINDOWCLOSE FreeGadget canvas End Case EVENT_APPTERMINATE End End Select EndIf 'Do other stuff in your loop here when no events in queue Wend This way you can keep redrawing at 60fps but dont have to wait around for that timer tick to process your game code(eg scripts/ai etc) If im wrong, please shoot me down as im just starting to learn this stuff :) |
| ||
I'd drop any polling.. You don't need to rely on just one timer. You can do: AItimer=CreateTimer(30) Drawtimer=CreateTimer(60) And then: WaitEvent() If EventID()=EVENT_TIMERTICK If EventSource()=AItimer doAI() Endif If EventSource()=Drawtimer update() Endif Endif Advantage of events with games is that you could create a map-editor (events/GUI) in the future with integrated testplaying (e.g walking around on the map-editor form). In this case you'd have to have the game running in an event-interface anyway. |
| ||
The problem with WaitEvent I think is the waiting, waiting is unused processing time you could be using elsewhere. |
| ||
Use for what? I'd prefer constant gametiming without cpu drops.. with timers you have a guaranteerd framerate. |
| ||
you might want to consider dropping a pollsystem in there somewhere too, under certain circumstances the windows gui can become unresponsive (usually when you've borked somthing!) so it can be useful for testing |