PlayBasic Threading Test
This example is an experiment that I've had on my mind for some time now. The objective is to try threading some of the rendering from within a PlayBasic program. The purpose of this, is to split the work load on machines with multi core cpu's. While it works without multi core, the benefit (if any) will be lost. Since the same cpu is running both threads.
So ideally the second cpu could be used to asynchronously render in the background while the main cpu runs the program code (in this case the game logic). In this example, only the back drop fill (shadebox) in bring executed as a thread. While this occurs, the demo moves some ship objects from left to the right. The ships (the circle things) rendered once the thread closes. Which should be obvious, If you think about it.
So the drawing loop looks a bit like this.
lockbuffer
Call ShadeBox
For each Ship()
move this ship
next
repeat
until ShadeBoxThreadComplete=true
For each Ship()
draw each ship
next
unlockbuffer
Sync
While the example is written in the stock standard version of 1.63w, it's about as user friendly as a hole in the head. Much like the JIT test a few months ago. So this is just test, nothing more ATM. The main problem with doing this from 1.63 is that only a few tid bits can be threaded safely. The key being safely here, as if you don't know what your doing or how PB works, then this is not for you.
Ultimately i'd like to integrate some level of threaded functionality right across the engine. While this is not possible in 1.63w, who knows in the future.
Keys
Esc = Quit
Space = Change from single <> threaded. (defaults to single.. no threading)
Left / Right Arrows = Thread Priority. (when in threaded mode)
Download
Get Thread Test Demo
Note:
This is actually an older tech demo from our private developer forums. What i'm really interested in with this pubic test, is if SINGLE CORE CPU's with HYPER THREADING get any signification gain.