Sign in to follow this  
fguihen

to use threads, or are there alternatives?

Recommended Posts

im making a simulation or a crowd of people evacuating a builidng. i know its not a game but a lot of the ideas would be the same id imagine. since each person has to assess their suituation individually( i.e, how close they are to sorounding people, how much dnger they are in etc) do i need a seperate thread for each person? if not , what other ways are there for allowing each person to act of their own accord?

Share this post


Link to post
Share on other sites
I you want to simulate group or crowd behaviour I suggest you take a close look at the 'Boids ' simulation by Craig Reynolds. http://www.red3d.com/cwr/boids/.

Hope it helps.

[Edited by - Crazy Chicken on October 15, 2004 3:28:46 PM]

Share this post


Link to post
Share on other sites
In theory, multiple threads are beautiful. Each object in your simulation that maintains a state should run in its own thread.

In practice, multiple threads are a major source of problems because the complexity of interdependencies is magnified tremendously.

Share this post


Link to post
Share on other sites
Although a thread per entity makes the code elegant, it's far from ideal in terms of performance.

A rule of thumb I work to is: aim to have no more than one running thread per CPU (it's ok to have more than one blocked/waiting thread per CPU).

You may want to look at "micro threads" for this kind of thing. You keep the code elegant without the peformance hit of abusing the system thread scheduler (exactly how much depends on OS).

Share this post


Link to post
Share on other sites
No, you won't want to use threads.

Instead you just give each person a turn to do a small amount of logic and then do the others.

In practice, because it's easier, in games we normally do all the "thinking" more or less instantly, then have the objects blindly follow the path they've figured out previously until they reach the end or something else crops up, then do another bit of "thinking".

This is because it makes for much easier coding than doing a little bit of "thinking" each time.

You could use lightweight threads or some kind of cooperative multitasking, but in practice that's not really necessary.

Just move each person a small amount each turn, and carry out "thinking" steps as necessary (not usually each timestep though).

Different people will have different reaction times, so you could simulate that by having a random delay before they carry out "thinking" steps.

Mark

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this