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.

Program Announcements / Plugin Release: Multi-Threading with Resource Query

Author
Message
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 1st Oct 2012 22:37 Edited at: 7th Oct 2012 03:45
Multi-Threading


Multi-Threading plugin is a plugin that is close to the performance plugin. It can create new threads which are just like functions but looped that are performance driven. Meaning it uses the same code that my Game Performance plugin uses. You can run your threads at a rate called Loops Per Second or LPS for short. I also added a resource query which is basically a list of resources to be loaded but on a new thread. You can only have one resource query thread to load objects. Having multiple resource queries or loading a resource at the same time the query is running will cause the game to crash.

However there are a few rules to running things threads: (To avoid crashes)
- Do not load resources while a query is loading resources
You must not try accessing the same variable from two separate threads at the same time without the use of a mutex. (MatrixUtils have mutexes)
- You may not load a resource within a new thread at the same time a main thread or another thread is loading resources.

Dark Basic Pro is natively not thread safe. This means that there is no guarantee that Dark Basic Pro commands will work successfully in a thread.

What Multi-Threading is useful for:
- Math calculations
- Loading Resources using my resource query while the main loop is running
- Physics
- For loops that are heavy in work or very long for loops that will hinder with the game play
- Input: I created a plugin to handle multiple keys at once.
And many more!

Commands


MT Start

This command will setup the multi-threading so you can use the commands

Index = MT Create Task(FunctionName$, LPSCap)

This command will create a new multi-theaded task. You provide a Function Name that will be called. The LPS cap is the rate in Loops Per Second.

Type$ = MT Get Task Type()
Time: Will run the task for a certain amount of time
Loop: Will loop indefinitely
Count: Will run the task for a certain amount of iterations
MT End Task

MT Set Task To Time Index, Duration#

This command will run a task for a certain amount of time. (Duration#) The Index is the Index of the already created Task.

MT Set Task To Count Index, Count

This command will run a task for a certain amount of iterations. (Count) The Index is the Index of the already created Task.

MT Set Task To Loop Index

This command will run a task indefinitely. The Index is the Index of the already created Task.

MT Pause Task Index

This command will pause the task.

MT Resume Task Index

This command will resume the pause tasked.

MT Stop Task Index

This command will stop the task.

index = MT Task Count()

This command will return the amount of tasks that exists.

index = MT Task Ended()

This command will return a 1 if the task has ended and a 0 if it hasn't.

MT Remove Task Index

This command will remove a task at Index.

MT Query Object ObjectIndex, Path$, PositionVector, RotateVector, Exclude Flag

This command will add an object to the query. You provide a Path$ and an Object Index. The Position and Rotate Vectors are DBP vectors with the position and rotations set. The Exclude flag set to 1 will exclude the object as soon as it is loaded and a 0 won't exclude it.

MT Query Image Index, Path$

This command will add a image to the query. You provide a Path$ and an Object Index.

MT Query Sound Index, Path$

This command will add a sound to the query. You provide a Path$ and an Object Index.

MT Query Music Index, Path$

This command will add music to the query. You provide a Path$ and an Object Index.

ThreadIndex = MT Load Resources()

This command will create a new thread where it will go through the queried resources and load them one at a time.

Copyright:

MCN:CX0NK-ZKKJS-AH8P9


Cost: $1.99!

Demo Plugin + Examples!: http://www.mediafire.com/?l220h1y2q8ecl9e

DigitalFury

Booma
15
Years of Service
User Offline
Joined: 29th Mar 2009
Location:
Posted: 2nd Oct 2012 09:35
I will wait the demo
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 2nd Oct 2012 17:59
Demo Posted!

Enjoy,

DigitalFury

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 7th Oct 2012 03:50
Updates


If you want a command added that will fit this plugin let me know. Test it out and let me know if you like it. I can add more features/improvement to the plugin.

I did add performance based multi-threading to the final release. It uses a really cleaver system of function calls within the performance driven thread. Overall this is a solid addition to the performance plugin.

I will be having a sale as soon as I release my Input plugin. I just have to kill a couple of bugs then I will release it and the Game Template Pre-Order.

I updated the price to reflect how many commands are included.

Any questions, comments, suggestions, criticisms, or ideas let me know.

Thanks,

DigitalFury

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 8th Oct 2012 01:29 Edited at: 8th Oct 2012 01:30
Check out an article I posted on performance. Multi-Threading is a good performance booster.

Checkout the post for yourself!: http://forum.thegamecreators.com/?m=forum_view&t=198638&b=5&p=1

DigitalFury

Login to post a reply

Server time is: 2024-11-21 10:34:55
Your offset time is: 2024-11-21 10:34:55