IsmAvatar
|
|
Reply #15 Posted on: September 14, 2009, 02:24:49 am |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
The problems with threading is that if you wish to draw, they *must* be synchronized in order to avoid two problems: 1) frame lag - e.g. one second into the game, thread1.object is on frame 30 and draws such, while thread2.object is on frame 20 - a 10-frame difference) 2) tearing - a fractional-frame difference between the threads. If your frames are drawn 30 times a second, and there is a 0.900 frame lag between two threads, then you will get one thread's image drawn, and then the other's image drawn only 1/300th of a second before the screen gets flushed, causing the image to flash or not appear at all.
Thread issues are almost always solved with synchronization, which means waiting for one of the threads to catch up (or reach a certain synchronization point, such as the begin of the Draw phase - in which case you don't care if there's a 10-frame difference between the threads, as long as it's not a fractional difference like 10.001 or 0.900).
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #16 Posted on: September 14, 2009, 06:58:57 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
And waiting for the threads to catch up would often be disadvantageous. It would be a pain in the ass to synchronize the threads in the first place, but then you have the fact that people might not want it done so.
That being the case, I think the best way is to let the user do it with my surface method (Possibly double buffering them, as well. I could implement a specific function set for doing so.)
In fact... I could probably fully implement an automatic system that worked off of that surface idea. The draw event of threaded instances would be called while the target is set to a specific buffer for thread two.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #18 Posted on: September 14, 2009, 08:51:03 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Objects can potentially be moved to a separate thread by threading the instance handling code and treating it as a set of separate lists. Scripts can be threaded by turning them over to the kernel to run until they complete. It will be impossible to obtain a return value from a threaded script. (It would have to set a global variable when it is done.)
Functions would look like this: script_start_thread(script) thread_create() instance_set_thread(inst,thread) thread_destroy(thread) instance_exists_thread(object,thread) instance_exists_allthreads(object)
The last function probably raised some O_o. It exists for efficiency, so that instance_exists won't waste time iterating an unused feature. Because of this, threaded instances would be essentially nonexistent. At best, they would exist when the function is called on their own thread. This function would deliberately iterate all threads.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|
|
Game_boy
|
|
Reply #23 Posted on: September 16, 2009, 11:41:30 am |
|
|
Joined: Apr 2008
Posts: 228
|
And chances are you'll never use more than 4 cores.
That's why it's a server chip; they can usually scale to any number of threads. But we'll never use more than 640k of memory... -- @Retro Where did you hear that? Cray uses tens of thousands of x86 cores in its more recent supercomputers.
|
|
|
Logged
|
|
|
|
|
|
|
luiscubal
|
|
Reply #27 Posted on: September 17, 2009, 08:33:31 am |
|
|
Joined: Jun 2009
Posts: 452
|
It seems pointless because programmers aren't used to threads yet. Honestly, you DO have many things to do at once. Synchronization issues aside, think about this: A single game could have:
1. A thread to do the drawing 2. A thread to handle the input 3. A thread to perform AI 4. A thread to handle the audio 5. A thread to handle collisions 6. A thread to handle GC(since it was in its own thread, GC would no longer be bad for game speed)
So a single game could use 6 threads, so 6 cores would be used. Now, onto more futuristic situations - you could have the OS use a different core, leading us to 7 cores being used. Then, antiviruses(assuming you use Windows and not Linux) could use a different core, so they wouldn't affect the game speed. We're now reaching the 8 cores.
Of course, you could merge this things into a single core, but this way would allow multiple cores to be used.
And, yes, I know 8 cores != 48 cores, but then again, why have only *one* thread to handle drawing? And why just *one* to handle AI? Done efficiently, a really big number of cores/threads could mean a really good speed.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #28 Posted on: September 17, 2009, 09:13:31 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
1. A thread to do the drawing Why bother 2. A thread to handle the input Mark does that, you end up getting the mouse in eight different positions during a lagtastic step 3. A thread to perform AI Can't think of an instance that'd be useful, but that wouldn't be part of ENIGMA 4. A thread to handle the audio That's necessary, everyone does that 5. A thread to handle collisions That would be awful. Unless you had them split up across multiple cores, there'd be more harm than good to come from doing that. (Taking sync on all this into account) 6. A thread to handle GC(since it was in its own thread, GC would no longer be bad for game speed) GC? Garbage collection? This is C++. The only garbage collection I do is leftovers from instance_destroy(), and that causes next to no lag. But yeah, it wouldn't hurt, and that's probably the best use for threads here.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|