WaitWindowsEvent Loop
Posted: Wed Jul 21, 2010 9:05 am
Hi all,
Used PB for a while but mainly for internal programs at work. Now I'm using it for an 'entertainment' reason and I'm seeing a problem.
To give a brief run down I'm writing a simulation of a fictional space ship. I'm not interested at this stage with graphics or anything, I just want to simulate the actual systems of the ship itself (power, life support etc). So, I'm just using basic windows gadgets for controls and readouts.
The algorithims for how the the systems work are held in their own Procedures which I'm calling from the main WaitWindowsEvent Repeat:Until loop. The problem is that this loop only loops on a windows event.
So, for example, my Reactor get switched on. The core temperature then rises. The algorithim for the temp rising and how much is contained in in the ReactorSystems procedure and updates a progress bar on the Windows form.
What I want to happen is when I press the ReactorStart button the core temperature slowly and evenly rises. What actually happens is that the temperature only rises when I move the mouse (eg a Windows Event). If I don't move the mouse the temperature doesn't rise.
I tried using Threads, I assume I did it correctly as it didn't error, I've never used Threads before but it didn't help. (Please ignore the simple temperature rising algorithim, I kept it simple until I could get these basics working).
How should I be coding this to get what I need?
Cheers
Mark
Used PB for a while but mainly for internal programs at work. Now I'm using it for an 'entertainment' reason and I'm seeing a problem.
To give a brief run down I'm writing a simulation of a fictional space ship. I'm not interested at this stage with graphics or anything, I just want to simulate the actual systems of the ship itself (power, life support etc). So, I'm just using basic windows gadgets for controls and readouts.
The algorithims for how the the systems work are held in their own Procedures which I'm calling from the main WaitWindowsEvent Repeat:Until loop. The problem is that this loop only loops on a windows event.
So, for example, my Reactor get switched on. The core temperature then rises. The algorithim for the temp rising and how much is contained in in the ReactorSystems procedure and updates a progress bar on the Windows form.
Code: Select all
;Engineering
Procedure ReactorSystem()
If ReactorOn
If temp < 100
temp = temp + 1
EndIf
Else
If temp > 0
temp = temp - 1
EndIf
EndIf
SetGadgetState (#prgCoreTemp, temp)
EndProcedure
CreateThread(@ReactorSystem(),0)
;Main Loop
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #cmdReactorStart
ReactorOn = 1
Case #cmdRecactorStop
ReactorOn = 0
EndSelect
EndSelect
ReactorSystem()
Until Event = #PB_Event_CloseWindow
I tried using Threads, I assume I did it correctly as it didn't error, I've never used Threads before but it didn't help. (Please ignore the simple temperature rising algorithim, I kept it simple until I could get these basics working).
How should I be coding this to get what I need?
Cheers
Mark