views:

53

answers:

1

In my case I've got a game server, with the CLR threadpool handling the sockets, and a managed threadpool for the other stuff. I'm trying to figure out what the best way to handle events like, an npc casting a spell, or despawning after a set period is.

I could just write some sort of Timer wrapper that gets a new (managed)threadpool thread for each action I want to perform, like new TimedEvent(1500, npc.Cast(Spells.FireBall)); and have it check against the system time, but, I think, with multiple timers like that running, each individually checking the elapsed time is inefficient. Would some sort of dispatcher thread be better?

Thanks in advance.

A: 

Have a look at how UOX3 does that in case you don't know that server app. It's a .Net/C# Ultima Online server.

And to your concrete question. It depends on how many events you expect. If you expect thousands per second going the timer/thread way is likely to not really work well.

Foxfire
UOX3's core seems to be written in C++, so I'm guessing you meant RunUO :pAnyway, does checking a SortedList of events (sorted by due time/ticks) on region update sound better, than my initial proposal?
Fauxide
Uups sorry meant RunUO
Foxfire
If you have lots of events then the list approach sounds more feasable.
Foxfire