views:

49

answers:

2

Hello,

I'm creating a game in WPF and I'm wondering if it is a wise decision to divide game logic and graphics to different threads.

My game logic works in steps (one step takes about 30 ms).

I'm quite afraid that locks will decrease the performance.

What do you think? Does anyone have an experience with that?

Thank you!

A: 

It really depends how much you do. Liocks are not an issue if you are not stupid programming your update logic.

Normally you would go client/server internally. The UI has it's own model it "renders", the logic has it's own non-visual model.

You can work with 2 queues (to model, to visual) where status updates are inserted (operations to logic, ui updates to visual model).

Then the WPF - timing or triggered wise - pulls updates from the queue and updates the model, making the visual changes as it is going.

Works pretty nice depending on the "game" you do. My "game" is a financial trading application working pretty exactly like that (albeit I have X visual queues, as multiple screens have all their own UI thread).

TomTom
Do you have any third-party plugins in your system?
MartyIX
Hm ;) no ;) Yes ;) the whole application is very slim unless plugins are loaded - it is highly modular. So, yes, no third party at the moment, though, unless you cound some major financial institutiopns as such that I integrate.
TomTom
+1  A: 

The cons regarding this far outweight the pros (i.e., manual message passing, synchronisation issues). Don't forget that the back-end presentation logic may already be executing in a separate thread. Most likely, the functions are already queuing up operations on a message bus and return instantly.

Chris Dennett
Well now when a plugin in my game freezes then the whole app will froze. But otherwise you are right I've already tried to use two threads a few times before and I couldn't make it work really well.
MartyIX