Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Multithreaded

Author
Message
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 23rd Jun 2009 09:22
Is it possible to say have the loading of an image be spawned off into a different thread so that the client would not hang up when loading a very large image or model?

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 23rd Jun 2009 11:42
Theoretically it is possible...

Personally I havent bothered threading any GDK apps, although I may look into doing something with multi-threading in the future.

I have read though, I cant remember where, but I think it was in these forums, that when Multi-Threading with GDK, you need to be very controlled, as calling any kind of drawing/screen updating fuction from more than one thread will cause an exception if GDK tried to process those threads at the same time...

But for instance, I assume, it would be safe to have one thread soley responsible for your rendering operations and another resposible for handling data loading....

If it ain't broke.... DONT FIX IT !!!
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 23rd Jun 2009 12:13 Edited at: 23rd Jun 2009 12:15
Is it a hard task to get things to run in different threads?

EDIT: tip, trying to move multiple models over 100k polys == no dice! xD

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Jun 2009 12:52
It's not considered safe, no.

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 23rd Jun 2009 13:44
DarkGDK itself isnt thread-safe.... which means that if you have 2 threads that are doing things with GDK memory addresses, there is a very high chance that it screw one or the other pieces of data up and crash on you...

That said, I think it would be safe to have all your GDK code and any data GDK can access in one thread, and do something completely unrelated in another, iterate through a very large array applying an algorithm to stored values, vertex calculations, data compression etc, while GDK keeps rendering or doing whatever it is doing in the other thread, the trick would be to keep them seperate and ensure that one thread isnt able to access any of the data in the other, until both have completed their operations and are locked.

Lastly, in my opinion, doing the above with a non-thread safe library, that is one which was not designed to run on multiple threads, is unsafe. plain and simple. You may get away with it and avoid crashing you app for now, but its not safe coding practice, and will eventually bite u in the butt with multiple hour long debug sessions lol(speaking from experience)

If it ain't broke.... DONT FIX IT !!!
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 23rd Jun 2009 15:10
In a sense one does already run multi-threaded under many conditions.

If you use DarkNet for networking, it runs in a separate thread to DarkGDK.
If you include a more advance external sound library like FMOD or errKlang, they both run within their own threads.

If you integrate almost any of the external physics libraries, they usually run in their own threads.

A safe way to run with 2 threads in DarkGDK, would be to run the game code in one thread, and do the rendering code in a second thread that is one frame behind the game code frame. All that is necessary is for one extra data structure that has positioning information in it being updated at the start of each frame. This can give (on a multicore CPU) a full game frame for rendering and also a full game frame for game logic.(can significantly increase FPS)

To actually multi-thread DarkGDK in the context where the game code is also fractured into threads, as Mista Wilson has said, is not a particular good idea for the reasons he has mentioned.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 23rd Jun 2009 23:11
Alright, sounds like too much trouble to deal with, not to mention I don't know how to get things to work on different threds anyways, i'll just forget about ever wanting to do it.

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 24th Jun 2009 04:10
Who knows what TGC will hit us with next... we might end up with a thread safe GDK that has inbuilt commands to allow us to run parts of it on differnt threads safelty.... One Day... Hint Hint.... TGC ...

If it ain't broke.... DONT FIX IT !!!
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 24th Jun 2009 10:17
Would'nt that be lovely!

Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 25th Jun 2009 14:10 Edited at: 25th Jun 2009 14:11
Yes, I agree it is a good suggestion (my project has terrible loading times).

Lately, I've seen a couple of commercial programs that allow to set multi-threaded loading on/off.
Loading without multi-thread is kind of eternal
AtomR
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Portugal
Posted: 26th Jun 2009 12:52
If multithreading is in the works (at all) i'd expect it to be a good selling feature for DBP X10 and don't expect it to be implemented in DBP. DX10 graphics + Multithreading alone would guarantee the comercial success of DBP X10.

Take care
AtomR

Login to post a reply

Server time is: 2024-11-25 08:33:59
Your offset time is: 2024-11-25 08:33:59