Thread: Multithreading

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972

    Multithreading

    Does anyone know of a tutorial that covers multithreading in DirectX? I've read a few tutorials in DirectX and never learned much so now I've decided to try to make some kind of game so I will actually learn something...I think multithreading will be important, at least if I add sound, since I think someone had an issue with their sounds interfering with display...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    JaWiB - I don't know how to answer your question, but if you haven't learned much reading DirectX tutorials, read these. Looks like they just added a vertex fog tutorial - I'm off to read that.
    Away.

  3. #3
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    About those tutorials, the way they are designed (OOP) used an application class to contain everything and create the window etc, so that WinMain only includes the message loop.

    Is this the way professional games/3D apps are set out?
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Hm thanks for that link...rethinking my post it may have been a bit premature and I wanted to stick with 2d game programming for a little while before I try anything 3d...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    No no, he was specifficaly speaking of the tutorials themselves.


    Multithreading can be very useful and it can - well not be. It depends on how (well) you implement it. The pretense is that with multi-threading you can run two "threads" at the same time. In reality this isnt true. Instead your telling your computer to devote time to two tasks alternatly - rather then starting one - finishing and starting the other. In a math metaphor let say - I want you to divide 2930/3.79 and 9/2.1304820 at the same time. So you work on the first problem for 2 seconds, second problem for 2 seconds and alternate until you are finished.

    If done improperly this can slow down your rendering times as youll be branching off to spend time on another thread in the middle of a render process. There are ways to give certain processes more weight (more time).

    An example of a way to use multithreads is for loading resources and displaying realtime progress of the loading.

    Another use is for loading resources "On the Fly" something that Shadow Bane likes to do (uber UBER LAG) - is when you enter new areas with new resources instead of a loading screen you give a small amount of time to loading process during the render time. Say about 95% importantness to the Render process and a 5% weight to the loading process - so every render you hop into the loading thread for 5 milliseconds - then back out and continue loading - when the resources are finaly loaded you can add them to the render process.

    Like I said - if not handled appropriately the attempt can be very disasterous.

    For your 2d applicatiosn like rpg - if you break down your maps into "zones" with certain resources only in certain zones - as your character approaches the zones start multithreading the loading process. This way you can have a gigantic map with "no load times"



    There are many other things to considere with multithreading - but this is a pretty good tutorial to get you started.

    http://www.flipcode.com/tutorials/tut_mthreading.shtml
    and part 2
    http://www.flipcode.com/tutorials/tut_mthreading2.shtml

    When I did the tutorial I stripped the code from the class he gives and did some simple tests with the consle input and printing at the same time. I'll think about cleaning it up and posting - maybe it can help.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Thanks! Haven't looked at those tutorials yet, but it sounds like something that could be fun to play around with a little . I've been looking at the sunlightd tutorials on direct draw, and they have been very simple and straightforward so far...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    The sunlight tutorials are also a bit old... but if that doesn't bother you and you like them, go for it.
    Away.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Well it does bother me a little bit, but they are written very clearly and don't have about 500 lines of code in the first tutorial...at least I can use it to start with and later I'll either look at some other tutorials or get myself a book.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. multithreading in C++
    By manzoor in forum C++ Programming
    Replies: 19
    Last Post: 11-28-2008, 12:20 PM
  3. Question on Multithreading
    By ronan_40060 in forum C Programming
    Replies: 1
    Last Post: 08-23-2006, 07:58 AM
  4. Client/Server and Multithreading
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 03:53 AM
  5. Multithreading
    By -KEN- in forum C# Programming
    Replies: 4
    Last Post: 06-13-2003, 10:11 PM