Spell effects: (Damage-Over-Time) Threading?

Im designing the spells in my rpg… nukes are easy… heals are easy… but spells that change or affect the player over time are a different ball game.

My Question:

Should i make each buff that is in my buff list implement Runnable?when they run they proceed to affect the target over time.

I imagine this can be very taxing on the server. Is this a good way to handle it? or is there a better way?

kthnxbye

-Oryan

If I understand this correctly…
Why don’t you add some Vector() on your player object that will contain all active spells. Then, all spell knows when it is “triggered”. Every frame you just check “is it time for spell to affect player?”.
Yes —> affect, move trigger time to next trigger time
No —> go on…

I believe java is very optimised for multi-threading.

Why not create a thread specifically for spell effects that works globally?
It’s better if you’re trying to go for dual core efficiency optimisations.

IMO, threading in this situation would be a needless complication.

Disregarding the multiple processor case, threading should be used:

  • To keep GUIs responsive when doing processing in the background
  • When faced with blocking I/O operations

I say go with hvor2’s suggestion: Have a list of active spells for each player, and check them each frame.

I’d suggest processing delayed/repeating events in the same thread which processes game events.
But you still can use java.util.Timer (one timer per all delayed effects) if the game engine works fine with multiple threads. Why not ?

Thread scheduling is dependant on the underlying system, so what works on your development box may not work anywhere else. Also, bugs introduced by multithreading can be right bugger to find and fix, due to this inherent unpredictability.

IMO, threading should be avoided except where you absolutely have to use it, like in the cases above, or when you are completely sure about what you’re doing, and there is zero doubt of the benefits.

Never use threads for this kind of thing. You cannot predict how much time a thread will waste after each sleep or yield. If you want to change stuff in the game from the thread, those things must be synchronized or you will undoubtedly introduce subtle bugs that show randomly, ruining the game. You should either poll each time-dependent thing each frame, or implement a sort of queue which manages them by sorting them at insertion time, then polling the foremost entry for when it should be executed (this is more efficient if lots of stuff is going on).