PDA

View Full Version : Understanding window processing.



Damot
22-09-2004, 05:07 PM
I wasn?¢_Tt sure which group to post this in, but since I?¢_Tm still experimenting with DelphiX and you're all so clever and attractive... :-)

Bit of a newbie regarding windows processing..

Suppose I have a DXtimer running the game loop but I want another routine to calculate something (which might take a couple of seconds), but I still want my game to run as smoothly as possible while it?¢_Ts working.

At the moment everything freezes and waits for the procedure/s to return.

How should I approach this?

Useless Hacker
22-09-2004, 10:05 PM
You could put the procedure in a separate thread. The easiest way to implement threads in Delphi is to create a descendant of the TThread class and override its Execute method. When you create an instance of your TThread descendant, this method is executed in another thread, while your main program continues running.
However, this can cause a lot of other problems, since you have to ensure that two threads are not accessing the same variable at once. What does this routine do that takes so long anyway?

Damot
23-09-2004, 07:14 AM
What does this routine do that takes so long anyway?

Well I've been experimenting with a pathfinding routine found elsewhere on this site.

I have a complicated 100x100 level grid (walls/blank areas etc) and a monster that wishes to travel to several different locations.

Most of the time the calculation for the next path is quick, but occasionally it takes a second or two. so instead of everything freezing I wanted the monster to sit still while it calculates the path, leaving the player to move around.