doing some tests
This commit is contained in:
parent
89b4901e06
commit
9c3e66e9cc
200
README.html
200
README.html
File diff suppressed because one or more lines are too long
189
README.md
189
README.md
@ -1,76 +1,45 @@
|
|||||||
# multi Version: 1.11.0 (Show me the love, love2d 11.1 support is here see changelog for details. Plus a new threaded object for testing!)
|
# multi Version: 2.0.0 (Introducing Network Threads look at the changelog for what was added)
|
||||||
|
|
||||||
**NOTE: I have been studying a lot about threading for the past few months and have some awesome additions in store! They will take a while to come out though. The goal of the library is still to provide a simple and efficient way to multi task in lua**
|
**NOTE: I have been studying a lot about threading for the past few months and have some awesome additions in store! They will take a while to come out though. The goal of the library is still to provide a simple and efficient way to multi task in lua**
|
||||||
|
|
||||||
In Changes you'll find documentation for(In Order):
|
My multitasking library for lua. It is a pure lua binding if you ignore the integrations and the love2d compat. If you find any bugs or have any issues, please let me know :). **If you don't see a table of contents try using the ReadMe.html file. It is easier to navigate the readme**</br>
|
||||||
- Sterilizing Objects
|
|
||||||
- System Threaded Job Queues
|
|
||||||
- New mainloop functions
|
|
||||||
- System Threaded Tables
|
|
||||||
- System Threaded Benchmark
|
|
||||||
- System Threaded Queues
|
|
||||||
- Threading related features
|
|
||||||
- And backwards compat stuff
|
|
||||||
|
|
||||||
My multitasking library for lua. It is a pure lua binding if you ingore the integrations and the love2d compat. If you find any bugs or have any issues please let me know :). **If you don't see a table of contents try using the ReadMe.html file. It is eaiser to navigate the readme**</br>
|
|
||||||
|
|
||||||
[TOC]
|
[TOC]
|
||||||
|
|
||||||
INSTALLING
|
INSTALLING
|
||||||
----------
|
----------
|
||||||
Note: The latest version of lualanes is required if you want to make use of system threads on lua 5.1+. I will update the dependencies for luarocks since this library should work fine on lua 5.1+
|
Note: The latest version of Lua lanes is required if you want to make use of system threads on lua 5.1+. I will update the dependencies for Lua rocks since this library should work fine on lua 5.1+
|
||||||
|
|
||||||
To install copy the multi folder into your enviroment and you are good to go</br>
|
To install copy the multi folder into your environment and you are good to go</br>
|
||||||
If you want to use the system threads then you'll need to install lanes!
|
If you want to use the system threads, then you'll need to install lanes!
|
||||||
**or** use luarocks
|
**or** use luarocks
|
||||||
|
|
||||||
```
|
```
|
||||||
luarocks install bin -- Inorder to use the new save state stuff
|
luarocks install bin -- To use the new save state stuff
|
||||||
luarocks install multi
|
luarocks install multi
|
||||||
```
|
```
|
||||||
Note: In the near future you may be able to run multitasking code on multiple machines, network paralisim. This however will have to wait until I hammer out some bugs within the core of system threading itself.
|
Note: Soon you may be able to run multitasking code on multiple machines, network parallelism. This however will have to wait until I hammer out some bugs within the core of system threading itself.
|
||||||
|
|
||||||
See the rambling section to get an idea of how this will work.
|
See the rambling section to get an idea of how this will work.
|
||||||
|
|
||||||
Discord
|
Discord
|
||||||
-------
|
-------
|
||||||
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries. Also you can request features and stuff there as well.</br>
|
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries. Also, you can request features and stuff there as well.</br>
|
||||||
https://discord.gg/U8UspuA</br>
|
https://discord.gg/U8UspuA</br>
|
||||||
|
|
||||||
**Upcoming Plans:** Adding network support for threading. Kinda like your own lua cloud. This will require the bin, net, and multi library. Once that happens I will include those libraries as a set. This also means that you can expect both a stand alone and joined versions of the libraries.
|
**Upcoming Plans:** Adding network support for threading. Kind of like your own lua cloud. This will require the bin, net, and multi library. Once that happens I will include those libraries as a set. This also means that you can expect both a standalone and joined versions of the libraries.
|
||||||
|
|
||||||
Planned features/TODO
|
Planned features/TODO
|
||||||
---------------------
|
---------------------
|
||||||
- [x] ~~Add system threads for love2d that works like the lanesManager (loveManager, slight differences).~~
|
|
||||||
- [x] ~~Improve performance of the library~~
|
|
||||||
- [x] ~~Improve coroutine based threading scheduling~~
|
|
||||||
- [ ] Improve love2d Idle thread cpu usage/Fix the performance when using system threads in love2d... Tricky Look at the rambling section for insight.
|
|
||||||
- [x] ~~Add more control to coroutine based threading~~
|
|
||||||
- [ ] Add more control to system based threading
|
|
||||||
- [ ] Make practical examples that show how you can solve real problems
|
- [ ] Make practical examples that show how you can solve real problems
|
||||||
- [x] ~~Add more features to support module creators~~
|
- [ ] Finish the wiki stuff. (11% done) -- It's been at 11% for so long. I really need to get on this!
|
||||||
- [x] ~~Make a framework for eaiser thread task distributing~~
|
- [ ] Test for unknown bugs -- This is always going on
|
||||||
- [x] ~~Fix Error handling on threaded multi objects~~ Non threaded multiobjs will crash your program if they error though! Use multi:newThread() of multi:newSystemThread() if your code can error! Unless you use multi:protect() this however lowers performance!
|
- [x] ~~Network Parallelism~~
|
||||||
- [x] ~~Add multi:OnError(function(obj,err))~~
|
|
||||||
- [ ] sThread.wrap(obj) **May or may not be completed** Theory: Allows interaction in one thread to affect it in another. The addition to threaded tables may make this possible!
|
|
||||||
- [ ] SystemThreaded Actors -- After some tests i figured out a way to make this work... It will work slightly different though. This is due to the actor needing to be splittable...
|
|
||||||
- [ ] LoadBalancing for system threads (Once SystemThreaded Actors are done)
|
|
||||||
- [x] ~~Add more integrations~~
|
|
||||||
- [ ] Fix SystemThreadedTables
|
|
||||||
- [ ] Finish the wiki stuff. (11% done)
|
|
||||||
- [ ] Test for unknown bugs
|
|
||||||
|
|
||||||
Known Bugs/Issues
|
Known Bugs/Issues
|
||||||
-----------------
|
-----------------
|
||||||
~~In regards to integrations, thread cancellation works slightly different for love2d and lanes. Within love2d I was unable to (To lazy to...) not use the multi library within the thread. A fix for this is to call `multi:Stop()` when you are done with your threaded code! This may change however if I find a way to work around this. In love2d in order to mimic the GLOBAL table I needed the library to constantly sync tha data... You can use the sThread.waitFor(varname), or sThread.hold(func) methods to sync the globals, to get the value instead of using GLOBAL and this could work. If you want to go this route I suggest setting multi.isRunning=true to prevent the auto runner from doing its thing! This will make the multi manager no longer function, but thats the point :P~~ THREAD.kill() should do the trick from within the thread. A listener could be made to detect when thread kill has been requested and sent to the running thread.
|
|
||||||
|
|
||||||
Another bug concerns the SystemThreadedJobQueue, Only 1 can be used for now. Going to change in a future update
|
A bug concerns the SystemThreadedJobQueue, only 1 can be used for now. Might change in a future update
|
||||||
|
|
||||||
~~And systemThreadedTables only supports 1 table between the main and worker thread! They do not work when shared between 2 or more threads. If you need that much flexiblity ust the GLOBAL table that all threads have.~~ **FIXED**
|
|
||||||
|
|
||||||
~~For module creators using this library. I suggest using SystemThreadedQueues for data transfer instead of SystemThreadedTables for rapid data transfer, If you plan on having Constants that will always be the same then a table is a good idea! They support up to **n** threads and can be messed with and abused as much as you want :D~~ FIXED Use what you want!
|
|
||||||
|
|
||||||
~~Love2D SystemThreadedTAbles do not send love2d userdata, use queues instead for that!~~ **FIXED**
|
|
||||||
|
|
||||||
Usage:</br>
|
Usage:</br>
|
||||||
-----
|
-----
|
||||||
@ -84,12 +53,12 @@ alarm:OnRing(function(a)
|
|||||||
end)
|
end)
|
||||||
multi:mainloop() -- the main loop of the program, multi:umanager() exists as well to allow integration in other loops Ex: love2d love.update function. More on this binding in the wiki!
|
multi:mainloop() -- the main loop of the program, multi:umanager() exists as well to allow integration in other loops Ex: love2d love.update function. More on this binding in the wiki!
|
||||||
```
|
```
|
||||||
The library is modular so you only need to require what you need to. Because of this, the global enviroment is altered</br>
|
The library is modular, so you only need to require what you need to. Because of this, the global environment is altered</br>
|
||||||
|
|
||||||
There are many useful objects that you can use</br>
|
There are many useful objects that you can use</br>
|
||||||
Check out the wiki for detailed usage, but here are the objects:</br>
|
Check out the wiki for detailed usage, but here are the objects:</br>
|
||||||
- Process#</br>
|
- Process#</br>
|
||||||
- QueueQueuer#</br>
|
- Queue#</br>
|
||||||
- Alarm</br>
|
- Alarm</br>
|
||||||
- Loop</br>
|
- Loop</br>
|
||||||
- Event</br>
|
- Event</br>
|
||||||
@ -107,15 +76,15 @@ Check out the wiki for detailed usage, but here are the objects:</br>
|
|||||||
- Job</br>
|
- Job</br>
|
||||||
- Function</br>
|
- Function</br>
|
||||||
- Watcher</br>
|
- Watcher</br>
|
||||||
Note: *Both a process and queue act like the multi namespace, but allows for some cool things. Because they use the other objects an example on them will be done last*</br>
|
Note: *Both a process and queue act like the multi namespace but allows for some cool things. Because they use the other objects an example on them will be done last*</br>
|
||||||
*Uses the built in coroutine features of lua, these have an interesting interaction with the other means of multi-tasking</br>
|
*Uses the built in coroutine features of lua, these have an interesting interaction with the other means of multi-tasking</br>
|
||||||
Triggers are kind of useless after the creation of the Connection</br>
|
Triggers are kind of useless after the creation of the Connection</br>
|
||||||
Watchers have no real purpose as well I made it just because.</br>
|
Watchers have no real purpose as well I made it just because.</br>
|
||||||
|
|
||||||
# Examples of each object being used</br>
|
# Examples of each object being used</br>
|
||||||
We already showed alarms in action so lets move on to a Loop object
|
We already showed alarms in action so let’s move on to a Loop object
|
||||||
|
|
||||||
Throughout these examples I am going to do some strange things in order to show other features of the library!
|
Throughout these examples I am going to do some strange things to show other features of the library!
|
||||||
|
|
||||||
LOOPS
|
LOOPS
|
||||||
-----
|
-----
|
||||||
@ -123,10 +92,10 @@ LOOPS
|
|||||||
-- Loops: Have been moved to the core of the library require("multi") would work as well
|
-- Loops: Have been moved to the core of the library require("multi") would work as well
|
||||||
require("multi") -- gets the entire library
|
require("multi") -- gets the entire library
|
||||||
count=0
|
count=0
|
||||||
loop=multi:newLoop(function(self,dt) -- dt is delta time and self is a reference to itself
|
loop=multi:newLoop(function(self,dt) -- dt is delta time and self are a reference to itself
|
||||||
count=count+1
|
count=count+1
|
||||||
if count > 10 then
|
if count > 10 then
|
||||||
self:Break() -- All methods on the multi objects are upper camel case, where as methods on the multi or process/queuer namespace are lower camel case
|
self:Break() -- All methods on the multi objects are upper camel case, whereas methods on the multi or process/queuer namespace are lower camel case
|
||||||
-- self:Break() will stop the loop and trigger the OnBreak(func) method
|
-- self:Break() will stop the loop and trigger the OnBreak(func) method
|
||||||
-- Stopping is the act of Pausing and deactivating the object! All objects can have the multiobj:Break() command on it!
|
-- Stopping is the act of Pausing and deactivating the object! All objects can have the multiobj:Break() command on it!
|
||||||
else
|
else
|
||||||
@ -154,16 +123,16 @@ You broke me :(</br>
|
|||||||
|
|
||||||
With loops out of the way lets go down the line
|
With loops out of the way lets go down the line
|
||||||
|
|
||||||
This library aims to be Async like. In reality everything is still on one thread *unless you are using the lanes integration module WIP* (More on that later)
|
This library aims to be Async like. Everything is still on one thread *unless you are using the lanes integration module WIP* (A stable WIP, more on that later)
|
||||||
|
|
||||||
EVENTS
|
EVENTS
|
||||||
------
|
------
|
||||||
```lua
|
```lua
|
||||||
-- Events, these were the first objects introduced into the library. I seldomly use them in their pure form though, but later on you'll see their advance uses!
|
-- Events, these were the first objects introduced into the library. I seldomly use them in their pure form though, but later you'll see their advance uses!
|
||||||
-- Events on there own don't really do much... We are going to need 2 objects at least to get something going
|
-- Events on their own don't really do much... We are going to need 2 objects at least to get something going
|
||||||
require("multi") -- gets the entire library
|
require("multi") -- gets the entire library
|
||||||
count=0
|
count=0
|
||||||
-- lets use the loop again to add to count!
|
-- let’s use the loop again to add to count!
|
||||||
loop=multi:newLoop(function(self,dt)
|
loop=multi:newLoop(function(self,dt)
|
||||||
count=count+1
|
count=count+1
|
||||||
end)
|
end)
|
||||||
@ -181,7 +150,7 @@ STEPS
|
|||||||
-----
|
-----
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
-- Steps, are like for loops but non blocking... You can run a loop to infintity and everything will still run I will combine Steps with Ranges in this example.
|
-- Steps, are like for loops but non-blocking... You can run a loop to infinity and everything will still run I will combine Steps with Ranges in this example.
|
||||||
step1=multi:newStep(1,10,1,0) -- Some explaining is due. Argument 1 is the Start # Argument 2 is the ResetAt # (inclusive) Argument 3 is the count # (in our case we are counting by +1, this can be -1 but you need to adjust your start and resetAt numbers)
|
step1=multi:newStep(1,10,1,0) -- Some explaining is due. Argument 1 is the Start # Argument 2 is the ResetAt # (inclusive) Argument 3 is the count # (in our case we are counting by +1, this can be -1 but you need to adjust your start and resetAt numbers)
|
||||||
-- The 4th Argument is for skipping. This is useful for timing and for basic priority management. A priority management system is included!
|
-- The 4th Argument is for skipping. This is useful for timing and for basic priority management. A priority management system is included!
|
||||||
step2=multi:newStep(10,1,-1,1) -- a second step, notice the slight changes!
|
step2=multi:newStep(10,1,-1,1) -- a second step, notice the slight changes!
|
||||||
@ -189,7 +158,7 @@ step1:OnStart(function(self)
|
|||||||
print("Step Started!")
|
print("Step Started!")
|
||||||
end)
|
end)
|
||||||
step1:OnStep(function(self,pos)
|
step1:OnStep(function(self,pos)
|
||||||
if pos<=10 then -- what what is this? the step only goes to 10!!!
|
if pos<=10 then -- The step only goes to 10
|
||||||
print("Stepping... "..pos)
|
print("Stepping... "..pos)
|
||||||
else
|
else
|
||||||
print("How did I get here?")
|
print("How did I get here?")
|
||||||
@ -197,27 +166,27 @@ step1:OnStep(function(self,pos)
|
|||||||
end)
|
end)
|
||||||
step1:OnEnd(function(self)
|
step1:OnEnd(function(self)
|
||||||
print("Done!")
|
print("Done!")
|
||||||
-- We finished here, but I feel like we could have reused this step in some way... Yeah I soule Reset() it, but what if i wanted to change it...
|
-- We finished here, but I feel like we could have reused this step in some way... I could use Reset() , but what if I wanted to change it...
|
||||||
if self.endAt==10 then -- lets only loop once
|
if self.endAt==10 then -- lets only loop once
|
||||||
self:Update(1,11,1,0) -- oh now we can reach that else condition!
|
self:Update(1,11,1,0) -- oh now we can reach that else condition!
|
||||||
end
|
end
|
||||||
-- Note Update() will restart the step!
|
-- Note Update() will restart the step!
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- step2 is bored lets give it some love :P
|
-- step2 is bored let’s give it some love :P
|
||||||
step2.range=step2:newRange() -- Set up a range object to have a nested step in a sense! Each nest requires a new range
|
step2.range=step2:newRange() -- Set up a range object to have a nested step in a sense! Each nest requires a new range
|
||||||
-- it is in your interest not to share ranges between objects! You can however do it if it suits your needs though
|
-- it is in your interest not to share ranges between objects! You can however do it if it suits your needs though
|
||||||
step2:OnStep(function(self,pos)
|
step2:OnStep(function(self,pos)
|
||||||
-- for 1=1,math.huge do
|
-- for 1=1,math.huge do
|
||||||
-- print("Haha I am holding the code up because I can!!!")
|
-- print("I am holding the code up because I can!")
|
||||||
--end
|
--end
|
||||||
-- We dont want to hold things up, but we want to nest.
|
-- We don’t want to hold things up, but we want to nest.
|
||||||
-- Note a range is not nessary if the nested for loop has a small range, if however the range is rather large you may want to allow other objects to do some work
|
-- Note a range is not necessary if the nested for loop has a small range, if however, the range is rather large you may want to allow other objects to do some work
|
||||||
for i in self.range(1,100) do
|
for i in self.range(1,100) do
|
||||||
print(pos,i) -- Now our nested for loop is using a range object which allows for other objects to get some cpu time while this one is running
|
print(pos,i) -- Now our nested for loop is using a range object which allows for other objects to get some CPU time while this one is running
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
-- TSteps are just like alarms and steps mixed together, the only difference in construction is the 4th Argument. On a TStep that argument controls time. The defualt is 1
|
-- TSteps are just like alarms and steps mixed together, the only difference in construction is the 4th Argument. On a TStep that argument controls time. The default is 1
|
||||||
-- The Reset(n) works just like you would figure!
|
-- The Reset(n) works just like you would figure!
|
||||||
step3=multi:newTStep(1,10,.5,2) -- lets go from 1 to 10 counting by .5 every 2 seconds
|
step3=multi:newTStep(1,10,.5,2) -- lets go from 1 to 10 counting by .5 every 2 seconds
|
||||||
step3:OnStep(function(self,pos)
|
step3:OnStep(function(self,pos)
|
||||||
@ -227,7 +196,7 @@ multi:mainloop()
|
|||||||
```
|
```
|
||||||
# Output
|
# Output
|
||||||
|
|
||||||
Note: the output on this one is huge!!! So I had to ... some parts! You need to run this for your self to see what is going on!</br>
|
Note: the output on this one is huge!!! So, I had to ... some parts! You need to run this for yourself to see what is going on!</br>
|
||||||
Step Started!</br>
|
Step Started!</br>
|
||||||
Stepping... 1</br>
|
Stepping... 1</br>
|
||||||
10 1</br>
|
10 1</br>
|
||||||
@ -246,7 +215,7 @@ require("multi")
|
|||||||
-- TLoops are loops that run ever n second. We will also look at condition objects as well
|
-- TLoops are loops that run ever n second. We will also look at condition objects as well
|
||||||
-- Here we are going to modify the old loop to be a little different
|
-- Here we are going to modify the old loop to be a little different
|
||||||
count=0
|
count=0
|
||||||
loop=multi:newTLoop(function(self) -- We are only going to coult with this loop, but doing so using a condition!
|
loop=multi:newTLoop(function(self) -- We are only going to count with this loop but doing so using a condition!
|
||||||
while self:condition(self.cond) do
|
while self:condition(self.cond) do
|
||||||
count=count+1
|
count=count+1
|
||||||
end
|
end
|
||||||
@ -254,7 +223,7 @@ loop=multi:newTLoop(function(self) -- We are only going to coult with this loop,
|
|||||||
self:Destroy() -- Lets destroy this object, casting it to the dark abyss MUHAHAHA!!!
|
self:Destroy() -- Lets destroy this object, casting it to the dark abyss MUHAHAHA!!!
|
||||||
-- the reference to this object will be a phantom object that does nothing!
|
-- the reference to this object will be a phantom object that does nothing!
|
||||||
end,1) -- Notice the ',1' after the function! This is where you put your time value!
|
end,1) -- Notice the ',1' after the function! This is where you put your time value!
|
||||||
loop.cond=multi:newCondition(function() return count<=100 end) -- conditions need a bit of work before i am happy with them
|
loop.cond=multi:newCondition(function() return count<=100 end) -- conditions need a bit of work before I am happy with them
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
```
|
```
|
||||||
# Output
|
# Output
|
||||||
@ -266,22 +235,22 @@ These are my favorite objects and you'll see why. They are very useful objects f
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
-- Lets create the events
|
-- Let’s create the events
|
||||||
yawn={} -- ill just leave that there
|
yawn={} -- ill just leave that there
|
||||||
OnCustomSafeEvent=multi:newConnection(true) -- lets pcall the calls incase something goes wrong defualt
|
OnCustomSafeEvent=multi:newConnection(true) -- lets pcall the calls in case something goes wrong default
|
||||||
OnCustomEvent=multi:newConnection(false) -- lets not pcall the calls and let errors happen... We are good at coding though so lets get a speed advantage by not pcalling. Pcalling is useful for plugins and stuff that may have been coded badly and you can ingore those connections if need be.
|
OnCustomEvent=multi:newConnection(false) -- let’s not pcall the calls and let errors happen... We are good at coding though so let’s get a speed advantage by not pcalling. Pcalling is useful for plugins and stuff that may have been coded badly and you can ignore those connections if need be.
|
||||||
OnCustomEvent:Bind(yawn) -- create the connection lookup data in yawn
|
OnCustomEvent:Bind(yawn) -- create the connection lookup data in yawn
|
||||||
|
|
||||||
-- Lets connect to them, a recent update adds a nice syntax to connect to these
|
-- Let’s connect to them, a recent update adds a nice syntax to connect to these
|
||||||
cd1=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
cd1=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
||||||
print("CSE1",arg1,arg2,...)
|
print("CSE1",arg1,arg2,...)
|
||||||
end,"bob") -- lets give this connection a name
|
end,"bob") -- let’s give this connection a name
|
||||||
cd2=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
cd2=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
||||||
print("CSE2",arg1,arg2,...)
|
print("CSE2",arg1,arg2,...)
|
||||||
end,"joe") -- lets give this connection a name
|
end,"joe") -- let’s give this connection a name
|
||||||
cd3=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
cd3=OnCustomSafeEvent:Connect(function(arg1,arg2,...)
|
||||||
print("CSE3",arg1,arg2,...)
|
print("CSE3",arg1,arg2,...)
|
||||||
end) -- lets not give this connection a name
|
end) -- let’s not give this connection a name
|
||||||
|
|
||||||
-- no need for connect, but I kept that function because of backwards compatibility.
|
-- no need for connect, but I kept that function because of backwards compatibility.
|
||||||
OnCustomEvent(function(arg1,arg2,...)
|
OnCustomEvent(function(arg1,arg2,...)
|
||||||
@ -289,7 +258,7 @@ OnCustomEvent(function(arg1,arg2,...)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Now within some loop/other object you trigger the connection like
|
-- Now within some loop/other object you trigger the connection like
|
||||||
OnCustomEvent:Fire(1,2,"Hello!!!") -- fire all conections
|
OnCustomEvent:Fire(1,2,"Hello!!!") -- fire all connections
|
||||||
|
|
||||||
-- You may have noticed that some events have names! See the following example!
|
-- You may have noticed that some events have names! See the following example!
|
||||||
OnCustomSafeEvent:getConnection("bob"):Fire(1,100,"Bye!") -- fire only bob!
|
OnCustomSafeEvent:getConnection("bob"):Fire(1,100,"Bye!") -- fire only bob!
|
||||||
@ -322,7 +291,7 @@ You may think timers should be bundled with alarms, but they are a bit different
|
|||||||
TIMERS
|
TIMERS
|
||||||
------
|
------
|
||||||
```lua
|
```lua
|
||||||
-- You see the thing is that all time based objects use timers eg. Alarms, TSteps, and Loops. Timers are more low level!
|
-- You see the thing is that all time-based objects use timers e.g. Alarms, TSteps, and Loops. Timers are more low level!
|
||||||
require("multi")
|
require("multi")
|
||||||
local clock = os.clock
|
local clock = os.clock
|
||||||
function sleep(n) -- seconds
|
function sleep(n) -- seconds
|
||||||
@ -332,7 +301,7 @@ end -- we will use this later!
|
|||||||
|
|
||||||
timer=multi:newTimer()
|
timer=multi:newTimer()
|
||||||
timer:Start()
|
timer:Start()
|
||||||
-- lets do a mock alarm
|
-- let’s do a mock alarm
|
||||||
set=3 -- 3 seconds
|
set=3 -- 3 seconds
|
||||||
a=0
|
a=0
|
||||||
while timer:Get()<=set do
|
while timer:Get()<=set do
|
||||||
@ -357,7 +326,7 @@ sleep(1)
|
|||||||
print(timer:Get()) -- should be really close to the value of set + 2
|
print(timer:Get()) -- should be really close to the value of set + 2
|
||||||
```
|
```
|
||||||
# Output
|
# Output
|
||||||
Note: This will make more sense when you run it for your self</br>
|
Note: This will make more sense when you run it for yourself</br>
|
||||||
3 second(s) have passed!</br>
|
3 second(s) have passed!</br>
|
||||||
3.001</br>
|
3.001</br>
|
||||||
3.001</br>
|
3.001</br>
|
||||||
@ -371,17 +340,17 @@ UPDATER
|
|||||||
```lua
|
```lua
|
||||||
-- Updaters: Have been moved to the core of the library require("multi") would work as well
|
-- Updaters: Have been moved to the core of the library require("multi") would work as well
|
||||||
require("multi")
|
require("multi")
|
||||||
updater=multi:newUpdater(5) -- really simple, think of a look with the skip feature of a step
|
updater=multi:newUpdater(5) -- simple, think of a look with the skip feature of a step
|
||||||
updater:OnUpdate(function(self)
|
updater:OnUpdate(function(self)
|
||||||
--print("updating...")
|
--print("updating...")
|
||||||
end)
|
end)
|
||||||
-- Here every 5 steps the updater will do stuff!
|
-- Here every 5 steps the updater will do stuff!
|
||||||
-- But I feel it is now time to touch into priority management, so lets get into basic priority stuff and get into a more advance version of it
|
-- But I feel it is now time to touch into priority management, so let’s get into basic priority stuff and get into a more advance version of it
|
||||||
--[[
|
--[[
|
||||||
multi.Priority_Core -- Highest form of priority
|
multi.Priority_Core -- Highest form of priority
|
||||||
multi.Priority_High
|
multi.Priority_High
|
||||||
multi.Priority_Above_Normal
|
multi.Priority_Above_Normal
|
||||||
multi.Priority_Normal -- The defualt form of priority
|
multi.Priority_Normal -- The default form of priority
|
||||||
multi.Priority_Below_Normal
|
multi.Priority_Below_Normal
|
||||||
multi.Priority_Low
|
multi.Priority_Low
|
||||||
multi.Priority_Idle -- Lowest form of priority
|
multi.Priority_Idle -- Lowest form of priority
|
||||||
@ -391,7 +360,7 @@ We aren't going to use regular objects to test priority, but rather benchmarks!
|
|||||||
to set priority on an object though you would do
|
to set priority on an object though you would do
|
||||||
multiobj:setPriority(one of the above)
|
multiobj:setPriority(one of the above)
|
||||||
]]
|
]]
|
||||||
-- lets bench for 3 seconds using the 3 forms of priority! First no Priority
|
-- let’s bench for 3 seconds using the 3 forms of priority! First no Priority
|
||||||
multi:benchMark(3,nil,"Regular Bench: "):OnBench(function() -- the onbench() allows us to do each bench after each other!
|
multi:benchMark(3,nil,"Regular Bench: "):OnBench(function() -- the onbench() allows us to do each bench after each other!
|
||||||
print("P1\n---------------")
|
print("P1\n---------------")
|
||||||
multi:enablePriority()
|
multi:enablePriority()
|
||||||
@ -403,7 +372,7 @@ multi:benchMark(3,nil,"Regular Bench: "):OnBench(function() -- the onbench() all
|
|||||||
multi:benchMark(3,multi.Priority_Low,"Low:")
|
multi:benchMark(3,multi.Priority_Low,"Low:")
|
||||||
multi:benchMark(3,multi.Priority_Idle,"Idle:"):OnBench(function()
|
multi:benchMark(3,multi.Priority_Idle,"Idle:"):OnBench(function()
|
||||||
print("P2\n---------------")
|
print("P2\n---------------")
|
||||||
-- Finally the 3rd form
|
-- Finally, the 3rd form
|
||||||
multi:enablePriority2()
|
multi:enablePriority2()
|
||||||
multi:benchMark(3,multi.Priority_Core,"Core:")
|
multi:benchMark(3,multi.Priority_Core,"Core:")
|
||||||
multi:benchMark(3,multi.Priority_High,"High:")
|
multi:benchMark(3,multi.Priority_High,"High:")
|
||||||
@ -417,7 +386,7 @@ end)
|
|||||||
multi:mainloop() -- Notice how the past few examples did not need this, well only actors need to be in a loop! More on this in the wiki.
|
multi:mainloop() -- Notice how the past few examples did not need this, well only actors need to be in a loop! More on this in the wiki.
|
||||||
```
|
```
|
||||||
# Output
|
# Output
|
||||||
Note: These numbers will vary drastically depending on your compiler and cpu power</br>
|
Note: These numbers will vary drastically depending on your compiler and CPU power</br>
|
||||||
Regular Bench: 2094137 Steps in 3 second(s)!</br>
|
Regular Bench: 2094137 Steps in 3 second(s)!</br>
|
||||||
P1</br>
|
P1</br>
|
||||||
Below_Normal: 236022 Steps in 3 second(s)!</br>
|
Below_Normal: 236022 Steps in 3 second(s)!</br>
|
||||||
@ -440,7 +409,7 @@ Notice: Even though I started each bench at the same time the order that they fi
|
|||||||
|
|
||||||
Processes
|
Processes
|
||||||
---------
|
---------
|
||||||
A process allows you to group the Actor objects within a controlable interface
|
A process allows you to group the Actor objects within a controllable interface
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
proc=multi:newProcess() -- takes an optional file as an argument, but for this example we aren't going to use that
|
proc=multi:newProcess() -- takes an optional file as an argument, but for this example we aren't going to use that
|
||||||
@ -448,7 +417,7 @@ proc=multi:newProcess() -- takes an optional file as an argument, but for this e
|
|||||||
b=0
|
b=0
|
||||||
loop=proc:newTLoop(function(self)
|
loop=proc:newTLoop(function(self)
|
||||||
a=a+1
|
a=a+1
|
||||||
proc:Pause() -- pauses the cpu cycler for this processor! Individual objects are not paused, however because they aren't getting cpu time they act as if they were paused
|
proc:Pause() -- pauses the CPU cycler for this processor! Individual objects are not paused, however because they aren't getting CPU time they act as if they were paused
|
||||||
end,.1)
|
end,.1)
|
||||||
updater=proc:newUpdater(multi.Priority_Idle) -- priority can be used in skip arguments as well to manage priority without enabling it!
|
updater=proc:newUpdater(multi.Priority_Idle) -- priority can be used in skip arguments as well to manage priority without enabling it!
|
||||||
updater:OnUpdate(function(self)
|
updater:OnUpdate(function(self)
|
||||||
@ -456,14 +425,14 @@ updater:OnUpdate(function(self)
|
|||||||
end)
|
end)
|
||||||
a=0 -- a counter
|
a=0 -- a counter
|
||||||
loop2=proc:newLoop(function(self,dt)
|
loop2=proc:newLoop(function(self,dt)
|
||||||
print("Lets Go!")
|
print("Let’s Go!")
|
||||||
self:hold(3) -- this will keep this object from doing anything! Note: You can only have one hold active at a time! Multiple are possible, but results may not be as they seem see * for how hold works
|
self:hold(3) -- this will keep this object from doing anything! Note: You can only have one hold active at a time! Multiple are possible, but results may not be as they seem see * for how hold works
|
||||||
-- Within a process using hold will keep it alive until the hold is satisified!
|
-- Within a process using hold will keep it alive until the hold is satisfied!
|
||||||
print("Done being held for 1 second")
|
print("Done being held for 1 second")
|
||||||
self:hold(function() return a>10 end)
|
self:hold(function() return a>10 end)
|
||||||
print("A is now: "..a.." b is also: "..b)
|
print("A is now: "..a.." b is also: "..b)
|
||||||
self:Destroy()
|
self:Destroy()
|
||||||
self.Parent:Pause() -- lets say you don't have the reference to the process!
|
self.Parent:Pause() -- let’s say you don't have the reference to the process!
|
||||||
os.exit()
|
os.exit()
|
||||||
end)
|
end)
|
||||||
-- Notice this is now being created on the multi namespace
|
-- Notice this is now being created on the multi namespace
|
||||||
@ -476,7 +445,7 @@ proc:Start()
|
|||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
```
|
```
|
||||||
# Output
|
# Output
|
||||||
Lets Go!</br>
|
Let’s Go!</br>
|
||||||
Done being held for 1 second</br>
|
Done being held for 1 second</br>
|
||||||
A is now: 29 b is also: 479</br>
|
A is now: 29 b is also: 479</br>
|
||||||
|
|
||||||
@ -488,7 +457,7 @@ function multi:hold(task)
|
|||||||
if type(task)=='number' then -- a sleep cmd
|
if type(task)=='number' then -- a sleep cmd
|
||||||
local timer=multi:newTimer()
|
local timer=multi:newTimer()
|
||||||
timer:Start()
|
timer:Start()
|
||||||
while timer:Get()<task do -- This while loop is what makes using multiple holds tricky... If the outer while is good before the nested one then the outter one will have to wait! There is a way around this though!
|
while timer:Get()<task do -- This while loop is what makes using multiple holds tricky... If the outer while is good before the nested one then the outer one will have to wait! There is a way around this though!
|
||||||
if love then
|
if love then
|
||||||
self.Parent:lManager()
|
self.Parent:lManager()
|
||||||
else
|
else
|
||||||
@ -567,7 +536,7 @@ Ring ring!!!</br>
|
|||||||
|
|
||||||
Threads
|
Threads
|
||||||
-------
|
-------
|
||||||
These fix the hold problem that you get with regular objects, and they work exactly the same! They even have some extra features that make them really useful.</br>
|
These fix the hold problem that you get with regular objects, and they work the same! They even have some extra features that make them really useful.</br>
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
test=multi:newThreadedProcess("main") -- you can thread processors and all Actors see note for a list of actors you can thread!
|
test=multi:newThreadedProcess("main") -- you can thread processors and all Actors see note for a list of actors you can thread!
|
||||||
@ -633,7 +602,7 @@ Threadable Actors
|
|||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
If you ever wanted to pause a function then great now you can
|
If you ever wanted to pause a function then great now you can
|
||||||
The uses of the Function object allows one to have a method that can run free in a sense
|
The use of the Function object allows one to have a method that can run free in a sense
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
func=multi:newFunction(function(self,arg1,arg2,...)
|
func=multi:newFunction(function(self,arg1,arg2,...)
|
||||||
@ -687,7 +656,7 @@ trig:Fire(1,2,3,"Hello",true)
|
|||||||
|
|
||||||
Tasks
|
Tasks
|
||||||
-----
|
-----
|
||||||
Tasks allow you to run a block of code before the multi mainloops does it thing. Tasks still have a use, but depending on how you program they aren't needed.</br>
|
Tasks allow you to run a block of code before the multi mainloop does it thing. Tasks still have a use but depending on how you program they aren't needed.</br>
|
||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
multi:newTask(function()
|
multi:newTask(function()
|
||||||
@ -711,7 +680,7 @@ As seen in the example above the tasks were done before anything else in the mai
|
|||||||
|
|
||||||
Jobs
|
Jobs
|
||||||
----
|
----
|
||||||
Jobs were a strange feature that was created for throttling connections! When I was building a irc bot around this library I couldn't have messages posting too fast due to restrictions. Jobs allowed functions to be added to a queue that were executed after a certain amount of time has passed
|
Jobs were a strange feature that was created for throttling connections! When I was building an IRC bot around this library I couldn't have messages posting too fast due to restrictions. Jobs allowed functions to be added to a queue that were executed after a certain amount of time has passed
|
||||||
```lua
|
```lua
|
||||||
require("multi") -- jobs use alarms I am pondering if alarms should be added to the core or if jobs should use timers instead...
|
require("multi") -- jobs use alarms I am pondering if alarms should be added to the core or if jobs should use timers instead...
|
||||||
-- jobs are built into the core of the library so no need to require them
|
-- jobs are built into the core of the library so no need to require them
|
||||||
@ -750,7 +719,7 @@ Watchers allow you to monitor a variable and trigger an event when the variable
|
|||||||
```lua
|
```lua
|
||||||
require("multi")
|
require("multi")
|
||||||
a=0
|
a=0
|
||||||
watcher=multi:newWatcher(_G,"a") -- watch a in the global enviroment
|
watcher=multi:newWatcher(_G,"a") -- watch a in the global environment
|
||||||
watcher:OnValueChanged(function(self,old,new)
|
watcher:OnValueChanged(function(self,old,new)
|
||||||
print(old,new)
|
print(old,new)
|
||||||
end)
|
end)
|
||||||
@ -769,7 +738,7 @@ multi:mainloop()
|
|||||||
Timeout management
|
Timeout management
|
||||||
------------------
|
------------------
|
||||||
```lua
|
```lua
|
||||||
-- Note: I used a tloop so I could control the output of the program a bit.
|
-- Note: I used a tloop, so I could control the output of the program a bit.
|
||||||
require("multi")
|
require("multi")
|
||||||
a=0
|
a=0
|
||||||
inc=1 -- change to 0 to see it not met at all, 1 if you want to see the first condition not met but the second and 2 if you want to see it meet the condition on the first go.
|
inc=1 -- change to 0 to see it not met at all, 1 if you want to see the first condition not met but the second and 2 if you want to see it meet the condition on the first go.
|
||||||
@ -818,7 +787,7 @@ We did it! 1 2 3</br>
|
|||||||
Rambling
|
Rambling
|
||||||
--------
|
--------
|
||||||
5/23/18:
|
5/23/18:
|
||||||
When it comes to running code across different systems we run into a problem. It takes time to send objects from one maching to another. In the beginning only local networks will be supported. I may add support to send commands to another network to do computing. Like having your own lus cloud. userdata will never be allowed to run on other machines. It is not possible unless the library you are using allows userdata to be turned into a string and back into an object. With this feature you want to send a command that will take time or needs tons of them done millions+, reason being networks are not that "fast" and only simple objects can be sent. If you mirror your enviroment then you can do some cool things.
|
When it comes to running code across different systems we run into a problem. It takes time to send objects from one matching to another. In the beginning only, local networks will be supported. I may add support to send commands to another network to do computing. Like having your own lua cloud. userdata will never be allowed to run on other machines. It is not possible unless the library you are using allows userdata to be turned into a string and back into an object. With this feature you want to send a command that will take time or needs tons of them done millions+, reason being networks are not that "fast" and only simple objects can be sent. If you mirror your environment then you can do some cool things.
|
||||||
|
|
||||||
The planned structure will be something like this:
|
The planned structure will be something like this:
|
||||||
multi-Single Threaded Multitasking
|
multi-Single Threaded Multitasking
|
||||||
@ -845,7 +814,7 @@ multi:mainloop()
|
|||||||
```lua
|
```lua
|
||||||
GLOBAL,sThread=require("multi.integration.networkManager").init() -- This will determine if one is using lanes,love2d, or luvit
|
GLOBAL,sThread=require("multi.integration.networkManager").init() -- This will determine if one is using lanes,love2d, or luvit
|
||||||
node = multi:newNode("NodeName","MainSystem") -- Search the network for the host, connect to it and be ready for requests!
|
node = multi:newNode("NodeName","MainSystem") -- Search the network for the host, connect to it and be ready for requests!
|
||||||
-- On the main thread, a simple multi:newNetworkThread thread and also non system threads, you can access global data without an issue. When dealing with system threads is when you have a problem.
|
-- On the main thread, a simple multi:newNetworkThread thread and non-system threads, you can access global data without an issue. When dealing with system threads is when you have a problem.
|
||||||
node:setLog{
|
node:setLog{
|
||||||
maxLines = 10000,
|
maxLines = 10000,
|
||||||
cleanOnInterval = true,
|
cleanOnInterval = true,
|
||||||
@ -853,30 +822,28 @@ node:setLog{
|
|||||||
noLog = false -- default is false, make true if you do not need a log
|
noLog = false -- default is false, make true if you do not need a log
|
||||||
}
|
}
|
||||||
node:settings{
|
node:settings{
|
||||||
maxJobs = 100, -- Job queues will respect this as well as the host when it is figuting out which node is under the least load. Default: 0 or infinite
|
maxJobs = 100, -- Job queues will respect this as well as the host when it is figuring out which node is under the least load. Default: 0 or infinite
|
||||||
sendLoadInterval = 60 -- every 60 seconds update the host of the nodes load
|
sendLoadInterval = 60 -- every 60 seconds update the host of the nodes load
|
||||||
sendLoad = true -- default is true, tells the server how stressed the system is
|
sendLoad = true -- default is true, tells the server how stressed the system is
|
||||||
}
|
}
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
-- Note: the node will contain a log of all the commands that it gets. A file called "NodeName.log" will contain the info. You can set the limit by lines or file size. Also you can set it to clear the log every interval of time if an error does not exist. All errors are both logged and sent to the host as well. You can have more than one host and more than one node(duh :P).
|
-- Note: the node will contain a log of all the commands that it gets. A file called "NodeName.log" will contain the info. You can set the limit by lines or file size. Also, you can set it to clear the log every interval of time if an error does not exist. All errors are both logged and sent to the host as well. You can have more than one host and more than one node(duh :P).
|
||||||
```
|
```
|
||||||
The goal of the node is to set up a simple and easy way to run commands on a remote machine.
|
The goal of the node is to set up a simple and easy way to run commands on a remote machine.
|
||||||
|
|
||||||
There are 2 main ways you can use this feature. 1. One node per machine with system threads being able to use the full processing power of the machine. 2. Multiple nodes on one machine where each node is acting like its own thread. And of course a mix of the two is indeed possible.
|
There are 2 main ways you can use this feature. 1. One node per machine with system threads being able to use the full processing power of the machine. 2. Multiple nodes on one machine where each node is acting like its own thread. And of course, a mix of the two is indeed possible.
|
||||||
|
|
||||||
|
|
||||||
Love2d Sleeping reduces the cpu time making my load detection think the system is under more load, thus preventing it from sleeping... I will look into other means. As of right now it will not eat all of your cpu if threads are active. For now I suggest killing threads that aren't needed anymore. On lanes threads at idle use 0% cpu and it is amazing. A state machine may solve what I need though. One state being idle state that sleeps and only goes into the active state if a job request or data is sent to it... after some time of not being under load it wil switch back into the idle state... We'll see what happens.
|
Love2d Sleeping reduces the CPU time making my load detection think the system is under more load, thus preventing it from sleeping... I will investigate other means. As of right now it will not eat all your CPU if threads are active. For now, I suggest killing threads that aren't needed anymore. On lanes threads at idle use 0% CPU and it is amazing. A state machine may solve what I need though. One state being idle state that sleeps and only goes into the active state if a job request or data is sent to it... after some time of not being under load it will switch back into the idle state... We'll see what happens.
|
||||||
|
|
||||||
Love2d doesn't like to send functions through channels. By defualt it does not support this. I achieve this by dumping the function and loadstring it on the thread. This however is slow. For the System Threaded Job Queue I had to change my original idea of sending functions as jobs. The current way you do it now is register a job functions once and then call that job across the thread through a queue. Each worker thread pops from the queue and returns the job. The Job ID is automatically updated and allows you to keep track of the order that the data comes in. A table with # indexes can be used to originze the data...
|
Love2d doesn't like to send functions through channels. By default, it does not support this. I achieve this by dumping the function and loadstring it on the thread. This however is slow. For the System Threaded Job Queue, I had to change my original idea of sending functions as jobs. The current way you do it now is register a job functions once and then call that job across the thread through a queue. Each worker thread pops from the queue and returns the job. The Job ID is automatically updated and allows you to keep track of the order that the data comes in. A table with # indexes can be used to organize the data...
|
||||||
|
|
||||||
In regards to benchmarking. If you see my bench marks and are wondering they are 10x better its because I am using luajit for my tests. I highly recommend using luajit for my library, but lua 5.1 will work just as well, but not as fast.
|
Regarding benchmarking. If you see my bench marks and are wondering they are 10x better it’s because I am using luajit for my tests. I highly recommend using luajit for my library, but lua 5.1 will work just as well, but not as fast.
|
||||||
|
|
||||||
So while working on the jobQueue:doToAll() method I figured out why love2d's threaded tables were acting up when more than 1 thread was sharing the table. It turns out 1 thread was eating all of the pops from the queue and starved all of the other queues... Ill need to use the same trick I did with GLOBAL to fix the problem... However at the rate I am going threading in love will become way slower. I might use the regualr GLOBAL to manage data internally for threadedtables...
|
So, while working on the jobQueue:doToAll() method I figured out why love2d's threaded tables were acting up when more than 1 thread was sharing the table. It turns out 1 thread was eating all the pops from the queue and starved all the other queues... I’ll need to use the same trick I did with GLOBAL to fix the problem... However, at the rate I am going threading in love will become way slower. I might use the regular GLOBAL to manage data internally for threadedtables...
|
||||||
|
|
||||||
It has been awhile since I had to bring out the Multi Functions... Syncing within threads are a pain! I had no idea what a task it would be to get something as simple as syncing data was going to be... I will probably add a SystemThreadedSyncer in the future because it will make life eaiser for you guys as well. SystemThreadedTables are still not going to work on love2d, but will work fine on lanes... I have a solution and it is being worked on... Depending on when I pust the next update to this library the second half of this ramble won't apply anymore
|
I have been using this (EventManager --> MultiManager --> now multi) for my own purposes and started making this when I first started learning lua. You can see how the code changed and evolved throughout the years. I tried to include all the versions that still existed on my HDD.
|
||||||
|
|
||||||
I have been using this (EventManager --> MultiManager --> now multi) for my own purposes and started making this when I first started learning lua. You are able to see how the code changed and evolved throughout the years. I tried to include all the versions that still existed on my HDD.
|
I added my old versions to this library... It started out as the EventManager and was kind of crappy, but it was the start to this library. It kept getting better and better until it became what it is today. There are some features that no longer exist in the latest version, but they were remove because they were useless... I added these files to the GitHub so for those interested can see into my mind in a sense and see how I developed the library before I used GitHub.
|
||||||
|
|
||||||
I added my old versions to this library... It started out as the EventManager and was kinda crappy but it was the start to this library. It kept getting better and better until it became what it is today. There are some features that nolonger exist in the latest version, but they were remove because they were useless... I added these files to the github so for those interested can see into my mind in a sense and see how I developed the library before I used github.
|
The first version of the EventManager was function based not object based and benched at about 2000 steps per second... Yeah that was bad... I used loadstring and it was a mess... Look and see how it grew throughout the years I think it may interest some of you guys!
|
||||||
|
|
||||||
The first version of the EventManager was function based not object based and benched at about 2000 steps per second... Yeah that was bad... I used loadstring and it was a mess... Take a look and see how it grew throughout the years I think it may intrest some of you guys!
|
|
||||||
|
|||||||
104
changes.html
104
changes.html
File diff suppressed because one or more lines are too long
195
changes.md
195
changes.md
@ -1,9 +1,102 @@
|
|||||||
Changes
|
#Changes
|
||||||
-------
|
[TOC]
|
||||||
|
Update: 2.0.0 Big update
|
||||||
|
------------------------
|
||||||
|
**Note:** After doing some testing, I have noticed that using multi-objects are slightly, quite a bit, faster than using (coroutines)multi:newthread(). Only create a thread if there is no other possibility! System threads are different and will improve performance if you know what you are doing. Using a (coroutine)thread as a loop with a timer is slower than using a TLoop! If you do not need the holding features I strongly recommend that you use the multi-objects. This could be due to the scheduler that I am using, and I am looking into improving the performance of the scheduler for (coroutine)threads. This is still a work in progress so expect things to only get better as time passes!
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
- multi:mainloop(settings) -- now takes a table of settings
|
||||||
|
- multi:uManager(settings) -- now takes a table of settings
|
||||||
|
- connections:holdUT(n) can take a number now. Where they will not continue until it gets triggered **n** times Added 3 updated ago, forgot to list it as a new feature
|
||||||
|
- The way you require the library has changed a bit! This will change how you start your code, but it isn't a big change.
|
||||||
|
- These changes have led to significant performance improvements
|
||||||
|
|
||||||
|
Modifying the global stack is not the best way to manage or load in the library.
|
||||||
|
```lua
|
||||||
|
-- Base Library
|
||||||
|
multi = require("multi")
|
||||||
|
-- In Lanes
|
||||||
|
multi = require("multi")
|
||||||
|
local GLOBAL, THREAD = require("multi.integration.lanesManager").init()
|
||||||
|
-- In Love2d
|
||||||
|
multi = require("multi")
|
||||||
|
GLOBAL, THREAD = require("multi.integration.loveManager").init()
|
||||||
|
-- In Luvit
|
||||||
|
local timer = require("timer")
|
||||||
|
local thread = require("thread")
|
||||||
|
multi = require("multi")
|
||||||
|
require("multi.integration.luvitManager").init(thread,timer) -- Luvit does not cuttently have support for the global table or threads.
|
||||||
|
```
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
- Updated the ThreadedConsole, now 100x faster!
|
||||||
|
- Updated the ThreadedConections, .5x faster!
|
||||||
|
- Both multi:uManager(settings) and multi:mainloop(settings) provide about the same performance! Though uManager is slightly slower due to function overhead, but still really close.
|
||||||
|
- Revamped pausing mulit-objects they now take up less memory when being used
|
||||||
|
|
||||||
|
Removed:
|
||||||
|
- require("multi.all") -- We are going into a new version of the library so this is nolonger needed
|
||||||
|
- require("multi.compat.backwards[1,5,0]") -- This is really old and is no longer supported going forward
|
||||||
|
- multi:Do_Order()
|
||||||
|
- multi:enablePriority()
|
||||||
|
- multi:enablePriority2()
|
||||||
|
- multi:protect()
|
||||||
|
- multi:unProtect()
|
||||||
|
- multi:protectedMainloop()
|
||||||
|
- multi:unprotectedMainloop()
|
||||||
|
- multi:prioritizedMainloop1()
|
||||||
|
- multi:prioritizedMainloop2()
|
||||||
|
- Removed Tasks
|
||||||
|
- multi:oneTime(func,...) -- never seen use of this, plus multi-functions can do this by pausing the function after the first use, and is much faster anyway
|
||||||
|
- multi:reboot() -- removed due to having no real use
|
||||||
|
- multi:hold() -- removed due to threads being able to do the same thing and way better too
|
||||||
|
- multi:waitFor() -- the thread variant does something completely different
|
||||||
|
- multi.resurrect() -- removed due to being useless
|
||||||
|
|
||||||
|
The new settings table makes all of these possible and removes a lot of function overhead that was going on before.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
multi:mainloop{
|
||||||
|
priority = 1, -- 1 or 2
|
||||||
|
protect = true, -- Should I use pcall to ignore errors?
|
||||||
|
preLoop = function(self) -- a function that is called before the mainloop does its thing
|
||||||
|
multi:newTLoop(function()
|
||||||
|
print("Hello whats up!")
|
||||||
|
error(":P")
|
||||||
|
end,1)
|
||||||
|
multi.OnError(function(obj,err)
|
||||||
|
print(err)
|
||||||
|
obj:Destroy()
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Update: 1.11.1
|
||||||
|
--------------
|
||||||
|
Love2d change:
|
||||||
|
I didn't make a mistake but didn't fully understand how the new love.run function worked.
|
||||||
|
So, it works by returning a function that allows for running the mainloop. So, this means that we can do something like this:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
multi:newLoop(love.run()) -- Run the mainloop here, cannot use thread.* when using this object
|
||||||
|
|
||||||
|
-- or
|
||||||
|
|
||||||
|
multi:newThread("MainLoop",love.run()) -- allows you to use the thread.*
|
||||||
|
|
||||||
|
--And you'll need to throw this in at the end
|
||||||
|
multi:mainloop()
|
||||||
|
```
|
||||||
|
|
||||||
|
For the long-time users of this library you know of the amazing multitasking features that the library has. Used correctly you can have insane power. The priority management system should be quite useful with this change.
|
||||||
|
NOTE: **multiobj:hold() will be removed in the next version!** This is something I feel should be changed, since threads(coroutines) do the job great, and way better than my holding method that I throw together 5 years ago. I doubt this is being used by many anyway. Version 1.11.2 or version 2.0.0 will have this change. The next update may be either, bug fixes if any or network parallelism.
|
||||||
|
|
||||||
|
TODO: Add auto priority adjustments when working with priority and stuff... If the system is under heavy load it will dial some things deemed as less important down and raise the core processes.
|
||||||
|
|
||||||
Update: 1.11.0
|
Update: 1.11.0
|
||||||
--------------
|
--------------
|
||||||
Added:
|
Added:
|
||||||
- SystemThreadedConsole(name) -- Allsow each thread to print without the sync issues that make prints merge and hard to read.
|
- SystemThreadedConsole(name) -- Allow each thread to print without the sync issues that make prints merge and hard to read.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- MainThread:
|
-- MainThread:
|
||||||
@ -13,7 +106,7 @@ console = THREAD.waitFor("console"):init()
|
|||||||
|
|
||||||
-- using the console
|
-- using the console
|
||||||
console:print(...)
|
console:print(...)
|
||||||
console:write(...) -- kinda useless for formatting code though. other threads can eaisly mess this up.
|
console:write(...) -- kind of useless for formatting code though. other threads can eaisly mess this up.
|
||||||
```
|
```
|
||||||
|
|
||||||
Fixed/Updated:
|
Fixed/Updated:
|
||||||
@ -34,8 +127,7 @@ Update: 1.10.0
|
|||||||
**Note:** The library is now considered to be stable!
|
**Note:** The library is now considered to be stable!
|
||||||
**Upcoming:** Network parallelism is on the way. It is in the works and should be released soon
|
**Upcoming:** Network parallelism is on the way. It is in the works and should be released soon
|
||||||
|
|
||||||
Added:
|
#Added:
|
||||||
------
|
|
||||||
- isMainThread true/nil
|
- isMainThread true/nil
|
||||||
- multi:newSystemThreadedConnection(name,protect) -- Works like normal connections, but are able to trigger events across threads
|
- multi:newSystemThreadedConnection(name,protect) -- Works like normal connections, but are able to trigger events across threads
|
||||||
|
|
||||||
@ -68,8 +160,7 @@ multi:newTLoop(function()
|
|||||||
end,1)
|
end,1)
|
||||||
```
|
```
|
||||||
|
|
||||||
Fixed:
|
#Fixed:
|
||||||
------
|
|
||||||
**loveManager** and **shared threading objects**
|
**loveManager** and **shared threading objects**
|
||||||
- sThread.waitFor()
|
- sThread.waitFor()
|
||||||
- sThread.hold()
|
- sThread.hold()
|
||||||
@ -115,8 +206,8 @@ Update: 1.9.2
|
|||||||
-------------
|
-------------
|
||||||
Added:
|
Added:
|
||||||
- (THREAD).kill() kills a thread. Note: THREAD is based on what you name it
|
- (THREAD).kill() kills a thread. Note: THREAD is based on what you name it
|
||||||
- newTimeStamper() Part of the persistant systems... Useful for when you are running this library for a massive amount of time... like years stright!
|
- newTimeStamper() Part of the persistent systems... Useful for when you are running this library for a long amount of time... like months and years! Though daily, hourly, minute events do also exist.
|
||||||
Allows one to hook to timed events such as whenever the clock strikes midnight or when the day turns to monday. The event is only done once though. so as soon as monday is set it would trigger then not trigger again until next monday
|
Allows one to hook to timed events such as whenever the clock strikes midnight or when the day turns to Monday. The event is only done once though. so as soon as Monday is set it would trigger then not trigger again until next Monday
|
||||||
works for seconds, minutes, days, months, year.
|
works for seconds, minutes, days, months, year.
|
||||||
```lua
|
```lua
|
||||||
stamper = multi:newTimeStamper()
|
stamper = multi:newTimeStamper()
|
||||||
@ -129,16 +220,16 @@ stamper:OnMonth(int month,func)
|
|||||||
stamper:OnYear(int year,func)
|
stamper:OnYear(int year,func)
|
||||||
```
|
```
|
||||||
Updated:
|
Updated:
|
||||||
- LoadBalancing, well bettwr load balancing than existed before. This one allowd for multiple processes to have their own load reading. Calling this on the multi object will return the total load for the entire multi enviroment... loads of other processes are indeed affected by what other processes are doing. However if you combine prorioty to the mix of things then you will get differing results... these results however will most likely be higher than normal... different pirorities will have different default thresholds of performence.
|
- LoadBalancing, well better load balancing than existed before. This one allowed for multiple processes to have their own load reading. Calling this on the multi object will return the total load for the entire multi environment... loads of other processes are indeed affected by what other processes are doing. However, if you combine propriety to the mix of things then you will get differing results... these results however will most likely be higher than normal... different priorities will have different default thresholds of performance.
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
- Thread.getName() should now work on lanes and love2d, haven't tested ut nuch with the luvit side of things...
|
- Thread.getName() should now work on lanes and love2d, haven't tested it much with the luvit side of things...
|
||||||
- A bug with the lovemanager table.remove arguments were backwards haha
|
- A bug with the lovemanager table.remove arguments were backwards
|
||||||
- The queue object in the love2d threading has been fixed! It now supports sending all objects (even functions as long as no upvalues are present!)
|
- The queue object in the love2d threading has been fixed! It now supports sending all objects (even functions if no upvalues are present!)
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
- SystemThreadedJobQueues now have built in load management so they are not constantly at 100% cpu usage.
|
- SystemThreadedJobQueues now have built in load management so they are not constantly at 100% CPU usage.
|
||||||
- SystemThreadedJobQueues pushJob now retunts an id of that job which will match the same one that OnJobCompleted returns
|
- SystemThreadedJobQueues pushJob now returns an id of that job which will match the same one that OnJobCompleted returns
|
||||||
|
|
||||||
|
|
||||||
Update: 1.9.1
|
Update: 1.9.1
|
||||||
@ -146,17 +237,17 @@ Update: 1.9.1
|
|||||||
Added:
|
Added:
|
||||||
- Integration "multi.integration.luvitManager"
|
- Integration "multi.integration.luvitManager"
|
||||||
- Limited... Only the basic multi:newSystemThread(...) will work
|
- Limited... Only the basic multi:newSystemThread(...) will work
|
||||||
- Not even data passing will work other than arguments... If using the bin library you can pass tables and function... Even full objects as long as inner recursion is not preasent.
|
- Not even data passing will work other than arguments... If using the bin library, you can pass tables and function... Even full objects if inner recursion is not present.
|
||||||
|
|
||||||
Updated:
|
Updated:
|
||||||
- multi:newSystemThread(name,func,...)
|
- multi:newSystemThread(name,func,...)
|
||||||
- It will not pass the ... to the func(). Do not know why this wasn't done in the first place :P
|
- It will not pass the ... to the func(). Do not know why this wasn't done in the first place
|
||||||
- Also multi:getPlatform(will now return "luvit" if using luvit... Though Idk if module creators would use the multi library when inside the luvit enviroment
|
- Also multi:getPlatform(will now return "luvit" if using luvit... Though Idk if module creators would use the multi library when inside the luvit environment
|
||||||
|
|
||||||
Update: 1.9.0
|
Update: 1.9.0
|
||||||
-------------
|
-------------
|
||||||
Added:
|
Added:
|
||||||
- multiobj:ToString() -- returns a string repersenting the object
|
- multiobj:ToString() -- returns a string representing the object
|
||||||
- multi:newFromString(str) -- creates an object from a string
|
- multi:newFromString(str) -- creates an object from a string
|
||||||
|
|
||||||
Works on threads and regular objects. Requires the latest bin library to work!
|
Works on threads and regular objects. Requires the latest bin library to work!
|
||||||
@ -257,17 +348,17 @@ Added:
|
|||||||
- multi:newSystemThreadedJobQueue()
|
- multi:newSystemThreadedJobQueue()
|
||||||
- Improved stability of the library
|
- Improved stability of the library
|
||||||
- Fixed a bug that made the benchmark and getload commands non-thread(coroutine) safe
|
- Fixed a bug that made the benchmark and getload commands non-thread(coroutine) safe
|
||||||
- Tweaked the loveManager to help improve idle cpu usage
|
- Tweaked the loveManager to help improve idle CPU usage
|
||||||
- Minor tweaks to the coroutine scheduling
|
- Minor tweaks to the coroutine scheduling
|
||||||
|
|
||||||
# Using multi:newSystemThreadedJobQueue()
|
# Using multi:newSystemThreadedJobQueue()
|
||||||
First you need to create the object
|
First you need to create the object
|
||||||
This works the same way as love2d as it does with lanes... It is getting increasing harder to make both work the same way with speed in mind... Anyway...
|
This works the same way as love2d as it does with lanes... It is getting harder to make both work the same way with speed in mind... Anyway...
|
||||||
```lua
|
```lua
|
||||||
-- Creating the object using lanes manager to show case this. Examples has the file for love2d
|
-- Creating the object using lanes manager to show case this. Examples has the file for love2d
|
||||||
local GLOBAL,sThread=require("multi.integration.lanesManager").init()
|
local GLOBAL,sThread=require("multi.integration.lanesManager").init()
|
||||||
jQueue=multi:newSystemThreadedJobQueue(n) -- this internally creates System threads. By defualt it will use the # of processors on your system You can set this number though.
|
jQueue=multi:newSystemThreadedJobQueue(n) -- this internally creates System threads. By default it will use the # of processors on your system You can set this number though.
|
||||||
-- Only create 1 jobqueue! For now making more than 1 is buggy. You only really need one though. Just register new functions if you want 1 queue to do more. The one reason though is keeping track of jobIDs. I have an idea that I will roll out in the next update.
|
-- Only create 1 jobqueue! For now, making more than 1 is not supported. You only really need one though. Just register new functions if you want 1 queue to do more. The one reason though is keeping track of jobIDs. I have an idea that I will roll out in the ~~next update~~ eventually.
|
||||||
jQueue:registerJob("TEST_JOB",function(a,s)
|
jQueue:registerJob("TEST_JOB",function(a,s)
|
||||||
math.randomseed(s)
|
math.randomseed(s)
|
||||||
-- We will push a random #
|
-- We will push a random #
|
||||||
@ -278,9 +369,9 @@ jQueue:registerJob("TEST_JOB2",function()
|
|||||||
print("Test Works!") -- this is called from the job since it is registered on the same queue
|
print("Test Works!") -- this is called from the job since it is registered on the same queue
|
||||||
end)
|
end)
|
||||||
tableOfOrder={} -- This is how we will keep order of our completed jobs. There is no guarantee that the order will be correct
|
tableOfOrder={} -- This is how we will keep order of our completed jobs. There is no guarantee that the order will be correct
|
||||||
jQueue.OnJobCompleted(function(JOBID,n) -- whenever a job is completed you hook to the event that is called. This passes the JOBID folled by the returns of the job
|
jQueue.OnJobCompleted(function(JOBID,n) -- whenever a job is completed you hook to the event that is called. This passes the JOBID filled by the returns of the job
|
||||||
-- JOBID is the completed job, starts at 1 and counts up by 1.
|
-- JOBID is the completed job, starts at 1 and counts up by 1.
|
||||||
-- Threads finish at different times so jobids may be passed out of order! Be sure to have a way to order them
|
-- Threads finish at different times so jobIDs may be passed out of order! Be sure to have a way to order them
|
||||||
tableOfOrder[JOBID]=n -- we order ours by putting them into a table
|
tableOfOrder[JOBID]=n -- we order ours by putting them into a table
|
||||||
if #tableOfOrder==10 then
|
if #tableOfOrder==10 then
|
||||||
print("We got all of the pieces!")
|
print("We got all of the pieces!")
|
||||||
@ -294,12 +385,12 @@ print("I pushed all of the jobs :)")
|
|||||||
multi:mainloop() -- Start the main loop :D
|
multi:mainloop() -- Start the main loop :D
|
||||||
```
|
```
|
||||||
|
|
||||||
Thats it from this version!
|
That’s it from this version!
|
||||||
|
|
||||||
Update: 1.8.3
|
Update: 1.8.3
|
||||||
-------------
|
-------------
|
||||||
Added:</br>
|
Added:</br>
|
||||||
**New Mainloop functions** Below you can see the slight differences... Function overhead is not too bad in lua, but has a real difference. multi:mainloop() and multi:unprotectedMainloop() use the same algorithm yet the dedicated unprotected one is slightly faster due to having less function overhead.
|
**New Mainloop functions** Below you can see the slight differences... Function overhead is not too bad in lua but has a real difference. multi:mainloop() and multi:unprotectedMainloop() use the same algorithm yet the dedicated unprotected one is slightly faster due to having less function overhead.
|
||||||
- multi:mainloop()\* -- Bench: 16830003 Steps in 3 second(s)!
|
- multi:mainloop()\* -- Bench: 16830003 Steps in 3 second(s)!
|
||||||
- multi:protectedMainloop() -- Bench: 16699308 Steps in 3 second(s)!
|
- multi:protectedMainloop() -- Bench: 16699308 Steps in 3 second(s)!
|
||||||
- multi:unprotectedMainloop() -- Bench: 16976627 Steps in 3 second(s)!
|
- multi:unprotectedMainloop() -- Bench: 16976627 Steps in 3 second(s)!
|
||||||
@ -308,25 +399,25 @@ Added:</br>
|
|||||||
|
|
||||||
\* The OG mainloop function remains the same and old methods to achieve what we have with the new ones still exist
|
\* The OG mainloop function remains the same and old methods to achieve what we have with the new ones still exist
|
||||||
|
|
||||||
These new methods help by removing function overhead that is caused through the original mainloop function. The one downside is that you no longer have the flexiblity to change the processing during runtime.
|
These new methods help by removing function overhead that is caused through the original mainloop function. The one downside is that you no longer have the flexibility to change the processing during runtime.
|
||||||
|
|
||||||
However there is a work around! You can use processes to run multiobjs as well and use the other methods on them.
|
However there is a work around! You can use processes to run multiobjs as well and use the other methods on them.
|
||||||
|
|
||||||
I may make a full comparison between each method and which is faster, but for now trust that the dedicated ones with less function overhead are infact faster. Not by much but still faster. :D
|
I may make a full comparison between each method and which is faster, but for now trust that the dedicated ones with less function overhead are infect faster. Not by much but still faster.
|
||||||
|
|
||||||
Update: 1.8.2
|
Update: 1.8.2
|
||||||
-------------
|
-------------
|
||||||
Added:</br>
|
Added:</br>
|
||||||
- multi:newsystemThreadedTable(name) NOTE: Metatables are not supported in transfers. However there is a work around obj:init() that you see does this. Take a look in the multi/integration/shared/shared.lua files to see how I did it!
|
- multi:newsystemThreadedTable(name) NOTE: Metatables are not supported in transfers. However there is a work around obj:init() does this. Look in the multi/integration/shared/shared.lua files to see how I did it!
|
||||||
- Modified the GLOBAL metatable to sync before doing its tests
|
- Modified the GLOBAL metatable to sync before doing its tests
|
||||||
- multi._VERSION was multi.Version, felt it would be more consistant this way... I left the old way of getting the version just incase someone has used that way. It will eventually be gone. Also multi:getVersion() will do the job just as well and keep your code nice and update related bug free!
|
- multi._VERSION was multi.Version, felt it would be more consistent this way... I left the old way of getting the version just in case someone has used that way. It will eventually be gone. Also multi:getVersion() will do the job just as well and keep your code nice and update related bug free!
|
||||||
- Also everything that is included in the: multi/integration/shared/shared.lua (Which is loaded automatically) works in both lanes and love2d enviroments!
|
- Also everything that is included in the: multi/integration/shared/shared.lua (Which is loaded automatically) works in both lanes and love2d environments!
|
||||||
|
|
||||||
The threaded table is setup just like the threaded queue.</br>
|
The threaded table is setup just like the threaded queue.</br>
|
||||||
It provids GLOBAL like features without having to write to GLOBAL!</br>
|
It provids GLOBAL like features without having to write to GLOBAL!</br>
|
||||||
This is useful for module creators who want to keep their data private, but also use GLOBAL like coding.</br>
|
This is useful for module creators who want to keep their data private, but also use GLOBAL like coding.</br>
|
||||||
It has a few features that makes it a bit better than plain ol GLOBAL (For now...)
|
It has a few features that makes it a bit better than plain ol GLOBAL (For now...)
|
||||||
(ThreadedTable - TT for short)
|
(ThreadedTable - TT for short) This was modified by a recent version that removed the need for a sync command
|
||||||
- TT:waitFor(name)
|
- TT:waitFor(name)
|
||||||
- TT:sync()
|
- TT:sync()
|
||||||
- TT["var"]=value
|
- TT["var"]=value
|
||||||
@ -334,7 +425,7 @@ It has a few features that makes it a bit better than plain ol GLOBAL (For now..
|
|||||||
|
|
||||||
we also have the "sync" method, this one was made for love2d because we do a syncing trick to get data in a table format. The lanes side has a sync method as well so no worries. Using indexing calls sync once and may grab your variable. This allows you to have the lanes indexing 'like' syntax when doing regular indexing in love2d side of the module. As of right now both sides work flawlessly! And this effect is now the GLOBAL as well</br>
|
we also have the "sync" method, this one was made for love2d because we do a syncing trick to get data in a table format. The lanes side has a sync method as well so no worries. Using indexing calls sync once and may grab your variable. This allows you to have the lanes indexing 'like' syntax when doing regular indexing in love2d side of the module. As of right now both sides work flawlessly! And this effect is now the GLOBAL as well</br>
|
||||||
|
|
||||||
On GLOBALS sync is a internal method for keeping the GLOBAL table in order. You can still use sThread.waitFor(name) to wait for variables that may of may not yet exist!
|
On GLOBALS sync is a internal method for keeping the GLOBAL table in order. You can still use sThread.waitFor(name) to wait for variables that may or may not yet exist!
|
||||||
|
|
||||||
Time for some examples:
|
Time for some examples:
|
||||||
# Using multi:newSystemThreadedTable(name)
|
# Using multi:newSystemThreadedTable(name)
|
||||||
@ -356,7 +447,7 @@ multi:mainloop()
|
|||||||
```
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- love2d gaming lua! NOTE: this is in main4.lua in the love2d examples
|
-- love2d lua! NOTE: this is in main4.lua in the love2d examples
|
||||||
require("core.Library")
|
require("core.Library")
|
||||||
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
|
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
|
||||||
require("core.GuiManager")
|
require("core.GuiManager")
|
||||||
@ -373,7 +464,7 @@ multi:newThread("test2",function()
|
|||||||
print(test:waitFor("test2"))
|
print(test:waitFor("test2"))
|
||||||
t.text="DONE!"
|
t.text="DONE!"
|
||||||
end)
|
end)
|
||||||
t=gui:newTextLabel("no done yet!",0,0,300,100)
|
t=gui:newTextLabel("not done yet!",0,0,300,100)
|
||||||
t:centerX()
|
t:centerX()
|
||||||
t:centerY()
|
t:centerY()
|
||||||
```
|
```
|
||||||
@ -383,9 +474,9 @@ Update: 1.8.1
|
|||||||
No real change!</br>
|
No real change!</br>
|
||||||
Changed the structure of the library. Combined the coroutine based threads into the core!</br>
|
Changed the structure of the library. Combined the coroutine based threads into the core!</br>
|
||||||
Only compat and integrations are not part of the core and never will be by nature.</br>
|
Only compat and integrations are not part of the core and never will be by nature.</br>
|
||||||
This should make the library more convient to use.</br>
|
This should make the library more convent to use.</br>
|
||||||
I left multi/all.lua file so if anyone had libraries/projects that used that it will still work!</br>
|
I left multi/all.lua file so if anyone had libraries/projects that used that it will still work!</br>
|
||||||
Updated from 1.7.6 to 1.8.0</br> (How much thread could a thread thread if a thread could thread thread?)
|
Updated from 1.7.6 to 1.8.0</br> (How much thread could a thread htread if a thread could thread thread?)
|
||||||
Added:</br>
|
Added:</br>
|
||||||
- multi:newSystemThreadedQueue()
|
- multi:newSystemThreadedQueue()
|
||||||
- multi:systemThreadedBenchmark()
|
- multi:systemThreadedBenchmark()
|
||||||
@ -405,7 +496,7 @@ multi:mainloop()
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Using multi:newSystemThreadedQueue()
|
# Using multi:newSystemThreadedQueue()
|
||||||
Quick Note: queues shared across multiple objects will be pulling from the same "queue" keep this in mind when coding! ~~Also the queue respects direction a push on the thread side cannot be popped on the thread side... Same goes for the mainthread!</br>~~ Turns out i was wrong about this...
|
Quick Note: queues shared across multiple objects will be pulling from the same "queue" keep this in mind when coding! ~~Also the queue respects direction a push on the thread side cannot be popped on the thread side... Same goes for the mainthread!</br>~~ Turns out I was wrong about this...
|
||||||
```lua
|
```lua
|
||||||
-- in love2d, this file will be in the same example folder as before, but is named main2.lua
|
-- in love2d, this file will be in the same example folder as before, but is named main2.lua
|
||||||
require("core.Library")
|
require("core.Library")
|
||||||
@ -414,7 +505,7 @@ GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2
|
|||||||
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
||||||
-- If these are local the functions will have the upvalues put into them that do not exist on the threaded side
|
-- If these are local the functions will have the upvalues put into them that do not exist on the threaded side
|
||||||
-- You will need to ensure that the function does not refer to any upvalues in its code. It will print an error if it does though
|
-- You will need to ensure that the function does not refer to any upvalues in its code. It will print an error if it does though
|
||||||
-- Also each thread has a .1 second delay! This is used to generate a random values for each thread!
|
-- Also, each thread has a .1 second delay! This is used to generate a random value for each thread!
|
||||||
require("core.GuiManager")
|
require("core.GuiManager")
|
||||||
gui.ff.Color=Color.Black
|
gui.ff.Color=Color.Black
|
||||||
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
||||||
@ -514,7 +605,7 @@ Added:</br>
|
|||||||
multi:getPlatform() -- returns "love2d" if using the love2d platform or returns "lanes" if using lanes for threading</br>
|
multi:getPlatform() -- returns "love2d" if using the love2d platform or returns "lanes" if using lanes for threading</br>
|
||||||
examples files</br>
|
examples files</br>
|
||||||
In Events added method setTask(func)</br>
|
In Events added method setTask(func)</br>
|
||||||
The old way still works and is more convient to be honest, but I felt a method to do this was ok.</br>
|
The old way still works and is more convent to be honest, but I felt a method to do this was needed for completeness.</br>
|
||||||
|
|
||||||
Updated:
|
Updated:
|
||||||
some example files to reflect changes to the core. Changes allow for less typing</br>
|
some example files to reflect changes to the core. Changes allow for less typing</br>
|
||||||
@ -532,12 +623,12 @@ I'll show case some old versions of the multitasking library eventually so you c
|
|||||||
Update: 1.7.4
|
Update: 1.7.4
|
||||||
-------------
|
-------------
|
||||||
Added: the example folder which will be populated with more examples in the near future!</br>
|
Added: the example folder which will be populated with more examples in the near future!</br>
|
||||||
The loveManager integration that mimics the lanesManager integration almost exactly to keep coding in both enviroments as close to possible. This is done mostly for library creation support!</br>
|
The loveManager integration that mimics the lanesManager integration almost exactly to keep coding in both environments as close to possible. This is done mostly for library creation support!</br>
|
||||||
An example of the loveManager in action using almost the same code as the lanesintergreationtest2.lua</br>
|
An example of the loveManager in action using almost the same code as the lanesintergreationtest2.lua</br>
|
||||||
NOTE: This code has only been tested to work on love2d version 1.10.2 thoough it should work version 0.9.0
|
NOTE: This code has only been tested to work on love2d version 1.10.2 though it should work version 0.9.0
|
||||||
```lua
|
```lua
|
||||||
require("core.Library") -- Didn't add this to a repo yet! Will do eventually... Allows for injections and other cool things
|
require("core.Library") -- Didn't add this to a repo yet! Will do eventually... Allows for injections and other cool things
|
||||||
require("multi.compat.love2d") -- allows for multitasking and binds my libraies to the love2d engine that i am using
|
require("multi.compat.love2d") -- allows for multitasking and binds my libraries to the love2d engine that i am using
|
||||||
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager
|
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager
|
||||||
--IMPORTANT
|
--IMPORTANT
|
||||||
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
||||||
@ -594,9 +685,9 @@ multi:newThread("test0",function()
|
|||||||
-- when the main thread is holding there is a chance that error handling on the system threads may not work!
|
-- when the main thread is holding there is a chance that error handling on the system threads may not work!
|
||||||
-- instead we can do this
|
-- instead we can do this
|
||||||
while true do
|
while true do
|
||||||
thread.skip(1) -- allow error handling to take place... Otherwise lets keep the main thread running on the low
|
thread.skip(1) -- allow error handling to take place... Otherwise let’s keep the main thread running on the low
|
||||||
-- Before we held just because we could... But this is a game and we need to have logic continue
|
-- Before we held just because we could... But this is a game and we need to have logic continue
|
||||||
--sThreadM.sleep(.001) -- Sleeping for .001 is a greeat way to keep cpu usage down. Make sure if you aren't doing work to rest. Abuse the hell out of GLOBAL if you need to :P
|
--sThreadM.sleep(.001) -- Sleeping for .001 is a great way to keep cpu usage down. Make sure if you aren't doing work to rest. Abuse the hell out of GLOBAL if you need to :P
|
||||||
if GLOBAL["DONE"] then
|
if GLOBAL["DONE"] then
|
||||||
t.text="Bench: "..GLOBAL["DONE"]
|
t.text="Bench: "..GLOBAL["DONE"]
|
||||||
end
|
end
|
||||||
@ -634,9 +725,9 @@ Update: 1.7.1 Bug Fixes Only
|
|||||||
Update: 1.7.0
|
Update: 1.7.0
|
||||||
-------------
|
-------------
|
||||||
Modified: multi.integration.lanesManager.lua
|
Modified: multi.integration.lanesManager.lua
|
||||||
It is now in a stable and simple state Works with the latest lanes version! Tested with version 3.11 I cannot promise that everything will work with eariler versions. Future versions are good though.</br>
|
It is now in a stable and simple state Works with the latest lanes version! Tested with version 3.11 I cannot promise that everything will work with earlier versions. Future versions are good though.</br>
|
||||||
Example Usage:</br>
|
Example Usage:</br>
|
||||||
sThread is a handle to a global interface for system threads to interact with themself</br>
|
sThread is a handle to a global interface for system threads to interact with themselves</br>
|
||||||
thread is the interface for multithreads as seen in the threading section</br>
|
thread is the interface for multithreads as seen in the threading section</br>
|
||||||
|
|
||||||
GLOBAL a table that can be used throughout each and every thread
|
GLOBAL a table that can be used throughout each and every thread
|
||||||
@ -697,14 +788,14 @@ multi:newLoop(function(dt,self)
|
|||||||
print(dt)
|
print(dt)
|
||||||
end)
|
end)
|
||||||
-- Is now
|
-- Is now
|
||||||
step:OnStep(function(self,pos) -- same goes for tsteps as well
|
step:OnStep(function(self,pos) -- same goes for tsteps as wellc
|
||||||
print(pos)
|
print(pos)
|
||||||
end)
|
end)
|
||||||
multi:newLoop(function(self,dt)
|
multi:newLoop(function(self,dt)
|
||||||
print(dt)
|
print(dt)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
Reasoning I wanted to keep objects consistant, but a lot of my older libraries use the old way of doing things. Therefore I added a backwards module
|
Reasoning I wanted to keep objects consistent, but a lot of my older libraries use the old way of doing things. Therefore, I added a backwards module
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi.all")
|
||||||
require("multi.compat.backwards[1,5,0]") -- allows for the use of features that were scrapped/changed in 1.6.0+
|
require("multi.compat.backwards[1,5,0]") -- allows for the use of features that were scrapped/changed in 1.6.0+
|
||||||
@ -719,4 +810,4 @@ Update: 1.4.1 - First Public release of the library
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
**IMPORTANT:**
|
**IMPORTANT:**
|
||||||
Every update I make aims to make things simpler more efficent and just better, but a lot of old code, which can be really big, uses a lot of older features. I know the pain of having to rewrite everything. My promise to my library users is that I will always have backwards support for older features! New ways may exist that are quicker and eaiser, but the old features/methods will be supported.</br>
|
Every update I make aims to make things simpler more efficient and just better, but a lot of old code, which can be really big, uses a lot of older features. I know the pain of having to rewrite everything. My promise to my library users is that I will always have backwards support for older features! New ways may exist that are quicker and easier, but the old features/methods will be supported.</br>**Note:** Version 2.x.x sort of breaks this promise. Sorry about that, but a new major version means changes that had to be made. Not too much has changed though and base code is 100% compatiable. What changed was how you init the library and some files that were removed due to not really being used by what i have seen. The older backwards compat file was for an older version of the library that was changed before the public release had any traction. The goal is still to provide a easy way to multitask in lua. I'll try my best however to ensure that not much changes and that changes are easy to make if they are introduced.
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
require("multi")
|
|
||||||
@ -1,305 +0,0 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
]]
|
|
||||||
multi.OnObjectCreated(function(obj)
|
|
||||||
if obj.Type=="loop" then
|
|
||||||
function obj:Act()
|
|
||||||
for i=1,#self.func do
|
|
||||||
self.func[i](self.Parent.clock()-self.Start,self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif obj.Type=="step" then
|
|
||||||
function obj:Act()
|
|
||||||
if self~=nil then
|
|
||||||
if self.spos==0 then
|
|
||||||
if self.pos==self.start then
|
|
||||||
for fe=1,#self.funcS do
|
|
||||||
self.funcS[fe](self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#self.func do
|
|
||||||
self.func[i](self.pos,self)
|
|
||||||
end
|
|
||||||
self.pos=self.pos+self.count
|
|
||||||
if self.pos-self.count==self.endAt then
|
|
||||||
self:Pause()
|
|
||||||
for fe=1,#self.funcE do
|
|
||||||
self.funcE[fe](self)
|
|
||||||
end
|
|
||||||
self.pos=self.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.spos=self.spos+1
|
|
||||||
if self.spos>=self.skip then
|
|
||||||
self.spos=0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif obj.Type=="tstep" then
|
|
||||||
function c:Act()
|
|
||||||
if self.clock()-self.timer>=self.set then
|
|
||||||
self:Reset()
|
|
||||||
if self.pos==self.start then
|
|
||||||
for fe=1,#self.funcS do
|
|
||||||
self.funcS[fe](self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#self.func do
|
|
||||||
self.func[i](self.pos,self)
|
|
||||||
end
|
|
||||||
self.pos=self.pos+self.count
|
|
||||||
if self.pos-self.count==self.endAt then
|
|
||||||
self:Pause()
|
|
||||||
for fe=1,#self.funcE do
|
|
||||||
self.funcE[fe](self)
|
|
||||||
end
|
|
||||||
self.pos=self.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
if thread then
|
|
||||||
function multi:newThreadedLoop(name,func)
|
|
||||||
local c=self:newTBase()
|
|
||||||
c.Type='loopThread'
|
|
||||||
c.Start=os.clock()
|
|
||||||
if func then
|
|
||||||
c.func={func}
|
|
||||||
end
|
|
||||||
function c:tofile(path)
|
|
||||||
local m=bin.new()
|
|
||||||
m:addBlock(self.Type)
|
|
||||||
m:addBlock(self.func)
|
|
||||||
m:addBlock(self.Active)
|
|
||||||
m:tofile(path)
|
|
||||||
end
|
|
||||||
function c:Resume()
|
|
||||||
self.rest=false
|
|
||||||
end
|
|
||||||
function c:Pause()
|
|
||||||
self.rest=true
|
|
||||||
end
|
|
||||||
function c:OnLoop(func)
|
|
||||||
table.insert(self.func,func)
|
|
||||||
end
|
|
||||||
c.rest=false
|
|
||||||
c.updaterate=0
|
|
||||||
c.restRate=.75
|
|
||||||
multi:newThread(name,function(ref)
|
|
||||||
while true do
|
|
||||||
if c.rest then
|
|
||||||
thread.sleep(c.restRate)
|
|
||||||
else
|
|
||||||
for i=1,#c.func do
|
|
||||||
c.func[i](os.clock()-self.Start,c)
|
|
||||||
end
|
|
||||||
thread.sleep(c.updaterate)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
self:create(c)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
function multi:newThreadedStep(name,start,reset,count,skip)
|
|
||||||
local c=self:newTBase()
|
|
||||||
local think=1
|
|
||||||
c.Type='stepThread'
|
|
||||||
c.pos=start or 1
|
|
||||||
c.endAt=reset or math.huge
|
|
||||||
c.skip=skip or 0
|
|
||||||
c.spos=0
|
|
||||||
c.count=count or 1*think
|
|
||||||
c.funcE={}
|
|
||||||
c.funcS={}
|
|
||||||
c.start=start or 1
|
|
||||||
if start~=nil and reset~=nil then
|
|
||||||
if start>reset then
|
|
||||||
think=-1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function c:tofile(path)
|
|
||||||
local m=bin.new()
|
|
||||||
m:addBlock(self.Type)
|
|
||||||
m:addBlock(self.func)
|
|
||||||
m:addBlock(self.funcE)
|
|
||||||
m:addBlock(self.funcS)
|
|
||||||
m:addBlock({pos=self.pos,endAt=self.endAt,skip=self.skip,spos=self.spos,count=self.count,start=self.start})
|
|
||||||
m:addBlock(self.Active)
|
|
||||||
m:tofile(path)
|
|
||||||
end
|
|
||||||
function c:Resume()
|
|
||||||
self.rest=false
|
|
||||||
end
|
|
||||||
function c:Pause()
|
|
||||||
self.rest=true
|
|
||||||
end
|
|
||||||
c.Reset=c.Resume
|
|
||||||
function c:OnStart(func)
|
|
||||||
table.insert(self.funcS,func)
|
|
||||||
end
|
|
||||||
function c:OnStep(func)
|
|
||||||
table.insert(self.func,1,func)
|
|
||||||
end
|
|
||||||
function c:OnEnd(func)
|
|
||||||
table.insert(self.funcE,func)
|
|
||||||
end
|
|
||||||
function c:Break()
|
|
||||||
self.rest=true
|
|
||||||
end
|
|
||||||
function c:Update(start,reset,count,skip)
|
|
||||||
self.start=start or self.start
|
|
||||||
self.endAt=reset or self.endAt
|
|
||||||
self.skip=skip or self.skip
|
|
||||||
self.count=count or self.count
|
|
||||||
self:Resume()
|
|
||||||
end
|
|
||||||
c.updaterate=0
|
|
||||||
c.restRate=.1
|
|
||||||
multi:newThread(name,function(ref)
|
|
||||||
while true do
|
|
||||||
if c.rest then
|
|
||||||
ref:sleep(c.restRate)
|
|
||||||
else
|
|
||||||
if c~=nil then
|
|
||||||
if c.spos==0 then
|
|
||||||
if c.pos==c.start then
|
|
||||||
for fe=1,#c.funcS do
|
|
||||||
c.funcS[fe](c)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#c.func do
|
|
||||||
c.func[i](c.pos,c)
|
|
||||||
end
|
|
||||||
c.pos=c.pos+c.count
|
|
||||||
if c.pos-c.count==c.endAt then
|
|
||||||
c:Pause()
|
|
||||||
for fe=1,#c.funcE do
|
|
||||||
c.funcE[fe](c)
|
|
||||||
end
|
|
||||||
c.pos=c.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
c.spos=c.spos+1
|
|
||||||
if c.spos>=c.skip then
|
|
||||||
c.spos=0
|
|
||||||
end
|
|
||||||
ref:sleep(c.updaterate)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
self:create(c)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
function multi:newThreadedTStep(name,start,reset,count,set)
|
|
||||||
local c=self:newTBase()
|
|
||||||
local think=1
|
|
||||||
c.Type='tstepThread'
|
|
||||||
c.Priority=self.Priority_Low
|
|
||||||
c.start=start or 1
|
|
||||||
local reset = reset or math.huge
|
|
||||||
c.endAt=reset
|
|
||||||
c.pos=start or 1
|
|
||||||
c.skip=skip or 0
|
|
||||||
c.count=count or 1*think
|
|
||||||
c.funcE={}
|
|
||||||
c.timer=os.clock()
|
|
||||||
c.set=set or 1
|
|
||||||
c.funcS={}
|
|
||||||
function c:Update(start,reset,count,set)
|
|
||||||
self.start=start or self.start
|
|
||||||
self.pos=self.start
|
|
||||||
self.endAt=reset or self.endAt
|
|
||||||
self.set=set or self.set
|
|
||||||
self.count=count or self.count or 1
|
|
||||||
self.timer=os.clock()
|
|
||||||
self:Resume()
|
|
||||||
end
|
|
||||||
function c:tofile(path)
|
|
||||||
local m=bin.new()
|
|
||||||
m:addBlock(self.Type)
|
|
||||||
m:addBlock(self.func)
|
|
||||||
m:addBlock(self.funcE)
|
|
||||||
m:addBlock(self.funcS)
|
|
||||||
m:addBlock({pos=self.pos,endAt=self.endAt,skip=self.skip,timer=self.timer,count=self.count,start=self.start,set=self.set})
|
|
||||||
m:addBlock(self.Active)
|
|
||||||
m:tofile(path)
|
|
||||||
end
|
|
||||||
function c:Resume()
|
|
||||||
self.rest=false
|
|
||||||
end
|
|
||||||
function c:Pause()
|
|
||||||
self.rest=true
|
|
||||||
end
|
|
||||||
function c:OnStart(func)
|
|
||||||
table.insert(self.funcS,func)
|
|
||||||
end
|
|
||||||
function c:OnStep(func)
|
|
||||||
table.insert(self.func,func)
|
|
||||||
end
|
|
||||||
function c:OnEnd(func)
|
|
||||||
table.insert(self.funcE,func)
|
|
||||||
end
|
|
||||||
function c:Break()
|
|
||||||
self.Active=nil
|
|
||||||
end
|
|
||||||
function c:Reset(n)
|
|
||||||
if n then self.set=n end
|
|
||||||
self.timer=os.clock()
|
|
||||||
self:Resume()
|
|
||||||
end
|
|
||||||
c.updaterate=0
|
|
||||||
c.restRate=0
|
|
||||||
multi:newThread(name,function(ref)
|
|
||||||
while true do
|
|
||||||
if c.rest then
|
|
||||||
thread.sleep(c.restRate)
|
|
||||||
else
|
|
||||||
if os.clock()-c.timer>=c.set then
|
|
||||||
c:Reset()
|
|
||||||
if c.pos==c.start then
|
|
||||||
for fe=1,#c.funcS do
|
|
||||||
c.funcS[fe](c)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#c.func do
|
|
||||||
c.func[i](c.pos,c)
|
|
||||||
end
|
|
||||||
c.pos=c.pos+c.count
|
|
||||||
if c.pos-c.count==c.endAt then
|
|
||||||
c:Pause()
|
|
||||||
for fe=1,#c.funcE do
|
|
||||||
c.funcE[fe](c)
|
|
||||||
end
|
|
||||||
c.pos=c.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
thread.skip(c.updaterate)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
self:create(c)
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
]]
|
]]
|
||||||
require("multi")
|
local multi = require("multi")
|
||||||
os.sleep=love.timer.sleep
|
os.sleep=love.timer.sleep
|
||||||
multi.drawF={}
|
multi.drawF={}
|
||||||
function multi.dManager()
|
function multi.dManager()
|
||||||
@ -34,3 +34,4 @@ function multi:onDraw(func,i)
|
|||||||
i=i or 1
|
i=i or 1
|
||||||
table.insert(self.drawF,i,func)
|
table.insert(self.drawF,i,func)
|
||||||
end
|
end
|
||||||
|
return multi
|
||||||
533
multi/init.lua
533
multi/init.lua
@ -22,41 +22,38 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
]]
|
]]
|
||||||
require("bin")
|
require("bin")
|
||||||
multi = {}
|
local multi = {}
|
||||||
multi.Version = "1.11.0"
|
multi.Version = "2.0.0"
|
||||||
multi._VERSION = "1.11.0"
|
multi._VERSION = "2.0.0"
|
||||||
multi.stage = "stable"
|
multi.stage = "stable"
|
||||||
multi.__index = multi
|
multi.__index = multi
|
||||||
multi.Mainloop = {}
|
multi.Mainloop = {}
|
||||||
multi.Tasks = {}
|
multi.Garbage = {}
|
||||||
multi.Tasks2 = {}
|
multi.ender = {}
|
||||||
multi.Garbage = {}
|
multi.Children = {}
|
||||||
multi.ender = {}
|
multi.Active = true
|
||||||
multi.Children = {}
|
multi.fps = 60
|
||||||
multi.Paused = {}
|
multi.Id = -1
|
||||||
multi.Active = true
|
multi.Type = "mainprocess"
|
||||||
multi.fps = 60
|
multi.Rest = 0
|
||||||
multi.Id = -1
|
multi._type = type
|
||||||
multi.Type = "mainprocess"
|
multi.Jobs = {}
|
||||||
multi.Rest = 0
|
multi.queue = {}
|
||||||
multi._type = type
|
multi.jobUS = 2
|
||||||
multi.Jobs = {}
|
multi.clock = os.clock
|
||||||
multi.queue = {}
|
multi.time = os.time
|
||||||
multi.jobUS = 2
|
multi.LinkedPath = multi
|
||||||
multi.clock = os.clock
|
multi.isRunning = false
|
||||||
multi.time = os.time
|
|
||||||
multi.LinkedPath = multi
|
|
||||||
multi.isRunning = false
|
|
||||||
--Do not change these ever...Any other number will not work (Unless you are using enablePriority2())
|
--Do not change these ever...Any other number will not work (Unless you are using enablePriority2())
|
||||||
multi.Priority_Core = 1
|
multi.Priority_Core = 1
|
||||||
multi.Priority_High = 4
|
multi.Priority_High = 4
|
||||||
multi.Priority_Above_Normal = 16
|
multi.Priority_Above_Normal = 16
|
||||||
multi.Priority_Normal = 64
|
multi.Priority_Normal = 64
|
||||||
multi.Priority_Below_Normal = 256
|
multi.Priority_Below_Normal = 256
|
||||||
multi.Priority_Low = 1024
|
multi.Priority_Low = 1024
|
||||||
multi.Priority_Idle = 4096
|
multi.Priority_Idle = 4096
|
||||||
multi.PStep = 1
|
multi.PStep = 1
|
||||||
multi.PList={multi.Priority_Core,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Idle}
|
multi.PList = {multi.Priority_Core,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Idle}
|
||||||
--^^^^
|
--^^^^
|
||||||
multi.PriorityTick=1 -- Between 1, 2 and 4
|
multi.PriorityTick=1 -- Between 1, 2 and 4
|
||||||
multi.Priority=multi.Priority_Core
|
multi.Priority=multi.Priority_Core
|
||||||
@ -204,65 +201,6 @@ function multi.executeFunction(name,...)
|
|||||||
print('Error: Not a function')
|
print('Error: Not a function')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:waitFor(obj)
|
|
||||||
local value=false
|
|
||||||
self.__waiting=function()
|
|
||||||
value=true
|
|
||||||
end
|
|
||||||
obj:connectFinal(self.__waiting)
|
|
||||||
self:hold(function() return value end)
|
|
||||||
end
|
|
||||||
multi.WaitFor=multi.waitFor
|
|
||||||
function multi:reboot(r)
|
|
||||||
local before=collectgarbage('count')
|
|
||||||
multi.Mainloop={}
|
|
||||||
multi.Tasks={}
|
|
||||||
multi.Tasks2={}
|
|
||||||
multi.Garbage={}
|
|
||||||
multi.ender={}
|
|
||||||
multi.Children={}
|
|
||||||
multi.Paused={}
|
|
||||||
multi.Active=true
|
|
||||||
multi.fps=60
|
|
||||||
multi.Id=-1
|
|
||||||
multi.Type='mainprocess'
|
|
||||||
multi.Rest=0
|
|
||||||
multi._type=type
|
|
||||||
multi.Jobs={}
|
|
||||||
multi.queue={}
|
|
||||||
multi.jobUS=2
|
|
||||||
multi.clock=os.clock
|
|
||||||
multi.time=os.time
|
|
||||||
multi.LinkedPath=multi
|
|
||||||
multi.isRunning=false
|
|
||||||
multi.Priority_Core=1
|
|
||||||
multi.Priority_High=4
|
|
||||||
multi.Priority_Above_Normal=16
|
|
||||||
multi.Priority_Normal=64
|
|
||||||
multi.Priority_Below_Normal=256
|
|
||||||
multi.Priority_Low=1024
|
|
||||||
multi.Priority_Idle=4096
|
|
||||||
multi.PList={multi.Priority_Core,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Idle}
|
|
||||||
multi.PStep=1
|
|
||||||
multi.PriorityTick=1
|
|
||||||
multi.Priority=multi.Priority_Core
|
|
||||||
multi.threshold=256
|
|
||||||
multi.threstimed=.001
|
|
||||||
if r then
|
|
||||||
for i,v in pairs(_G) do
|
|
||||||
if type(i)=='table' then
|
|
||||||
if i.Parent and i.Id and i.Act then
|
|
||||||
_G[i]={}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
collectgarbage()
|
|
||||||
local after=collectgarbage('count')
|
|
||||||
print([[Before rebooting total Ram used was ]]..before..[[Kb
|
|
||||||
After rebooting total Ram used is ]]..after..[[ Kb
|
|
||||||
A total of ]]..(before-after)..[[Kb was cleaned up]])
|
|
||||||
end
|
|
||||||
function multi:getChildren()
|
function multi:getChildren()
|
||||||
return self.Mainloop
|
return self.Mainloop
|
||||||
end
|
end
|
||||||
@ -287,62 +225,6 @@ function multi:getError()
|
|||||||
return self.error
|
return self.error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:Do_Order()
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
_G.ID=0
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
if Loop[_D] then
|
|
||||||
if Loop[_D].Active then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
Loop[_D]:Act()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:enablePriority()
|
|
||||||
function self:Do_Order()
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
_G.ID=0
|
|
||||||
local PS=self
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
for P=1,7 do
|
|
||||||
if Loop[_D] then
|
|
||||||
if (PS.PList[P])%Loop[_D].Priority==0 then
|
|
||||||
if Loop[_D].Active then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
Loop[_D]:Act()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:enablePriority2()
|
|
||||||
function self:Do_Order()
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
_G.ID=0
|
|
||||||
local PS=self
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
if Loop[_D] then
|
|
||||||
if (PS.PStep)%Loop[_D].Priority==0 then
|
|
||||||
if Loop[_D].Active then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
Loop[_D]:Act()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
PS.PStep=PS.PStep+1
|
|
||||||
if PS.PStep>self.Priority_Idle then
|
|
||||||
PS.PStep=1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
multi.disablePriority=multi.unProtect
|
|
||||||
function multi:benchMark(sec,p,pt)
|
function multi:benchMark(sec,p,pt)
|
||||||
local temp=self:newLoop(function(self,t)
|
local temp=self:newLoop(function(self,t)
|
||||||
if self.clock()-self.init>self.sec then
|
if self.clock()-self.init>self.sec then
|
||||||
@ -390,35 +272,6 @@ end
|
|||||||
function multi:OnMainConnect(func)
|
function multi:OnMainConnect(func)
|
||||||
table.insert(self.func,func)
|
table.insert(self.func,func)
|
||||||
end
|
end
|
||||||
function multi:protect()
|
|
||||||
function self:Do_Order()
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
if Loop[_D]~=nil then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
|
||||||
if err and not(Loop[_D].error) then
|
|
||||||
Loop[_D].error=err
|
|
||||||
self.OnError:Fire(Loop[_D],err)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:unProtect()
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
_G.ID=0
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
if Loop[_D] then
|
|
||||||
if Loop[_D].Active then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
Loop[_D]:Act()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:reallocate(o,n)
|
function multi:reallocate(o,n)
|
||||||
n=n or #o.Mainloop+1
|
n=n or #o.Mainloop+1
|
||||||
local int=self.Parent
|
local int=self.Parent
|
||||||
@ -484,10 +337,6 @@ function multi:getType()
|
|||||||
return self.Type
|
return self.Type
|
||||||
end
|
end
|
||||||
multi.GetType=multi.getType
|
multi.GetType=multi.getType
|
||||||
function multi:Sleep(n)
|
|
||||||
self:hold(n)
|
|
||||||
end
|
|
||||||
multi.sleep=multi.Sleep
|
|
||||||
-- Advance Timer stuff
|
-- Advance Timer stuff
|
||||||
function multi:SetTime(n)
|
function multi:SetTime(n)
|
||||||
if not n then n=3 end
|
if not n then n=3 end
|
||||||
@ -531,8 +380,6 @@ function multi:Pause()
|
|||||||
self.Active=false
|
self.Active=false
|
||||||
if self.Parent.Mainloop[self.Id]~=nil then
|
if self.Parent.Mainloop[self.Id]~=nil then
|
||||||
table.remove(self.Parent.Mainloop,self.Id)
|
table.remove(self.Parent.Mainloop,self.Id)
|
||||||
table.insert(self.Parent.Paused,self)
|
|
||||||
self.PId=#self.Parent.Paused
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -545,18 +392,12 @@ function multi:Resume()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self:isPaused() then
|
if self:isPaused() then
|
||||||
table.remove(self.Parent.Paused,self.PId)
|
|
||||||
table.insert(self.Parent.Mainloop,self)
|
table.insert(self.Parent.Mainloop,self)
|
||||||
self.Id=#self.Parent.Mainloop
|
self.Id=#self.Parent.Mainloop
|
||||||
self.Active=true
|
self.Active=true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:resurrect()
|
|
||||||
table.insert(self.Parent.Mainloop,self)
|
|
||||||
self.Active=true
|
|
||||||
end
|
|
||||||
multi.Resurrect=multi.resurrect
|
|
||||||
function multi:Destroy()
|
function multi:Destroy()
|
||||||
if self.Type=='process' or self.Type=='mainprocess' then
|
if self.Type=='process' or self.Type=='mainprocess' then
|
||||||
local c=self:getChildren()
|
local c=self:getChildren()
|
||||||
@ -575,69 +416,6 @@ function multi:Destroy()
|
|||||||
self.Active=false
|
self.Active=false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:hold(task)
|
|
||||||
self:Pause()
|
|
||||||
self.held=true
|
|
||||||
if type(task)=='number' then
|
|
||||||
local timer=multi:newTimer()
|
|
||||||
timer:Start()
|
|
||||||
while timer:Get()<task do
|
|
||||||
if love then
|
|
||||||
if love.thread then
|
|
||||||
self.Parent:Do_Order()
|
|
||||||
else
|
|
||||||
self.Parent:lManager()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.Parent:Do_Order()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:Resume()
|
|
||||||
self.held=false
|
|
||||||
elseif type(task)=='function' then
|
|
||||||
local env=self.Parent:newEvent(task)
|
|
||||||
env:OnEvent(function(envt) envt:Pause() envt.Active=false end)
|
|
||||||
while env.Active do
|
|
||||||
if love then
|
|
||||||
if love.graphics then
|
|
||||||
self.Parent:lManager()
|
|
||||||
else
|
|
||||||
self.Parent:Do_Order()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.Parent:Do_Order()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
env:Destroy()
|
|
||||||
self:Resume()
|
|
||||||
self.held=false
|
|
||||||
else
|
|
||||||
print('Error Data Type!!!')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
multi.Hold=multi.hold
|
|
||||||
function multi:oneTime(func,...)
|
|
||||||
if not(self.Type=='mainprocess' or self.Type=='process') then
|
|
||||||
for _k=1,#self.Parent.Tasks2 do
|
|
||||||
if self.Parent.Tasks2[_k]==func then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.insert(self.Parent.Tasks2,func)
|
|
||||||
func(...)
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
for _k=1,#self.Tasks2 do
|
|
||||||
if self.Tasks2[_k]==func then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.insert(self.Tasks2,func)
|
|
||||||
func(...)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:Reset(n)
|
function multi:Reset(n)
|
||||||
self:Resume()
|
self:Resume()
|
||||||
end
|
end
|
||||||
@ -664,7 +442,6 @@ function multi:newBase(ins)
|
|||||||
c.ender={}
|
c.ender={}
|
||||||
c.important={}
|
c.important={}
|
||||||
c.Id=0
|
c.Id=0
|
||||||
c.PId=0
|
|
||||||
c.Act=function() end
|
c.Act=function() end
|
||||||
c.Parent=self
|
c.Parent=self
|
||||||
c.held=false
|
c.held=false
|
||||||
@ -682,21 +459,17 @@ function multi:newProcess(file)
|
|||||||
c.Parent=self
|
c.Parent=self
|
||||||
c.Active=true
|
c.Active=true
|
||||||
c.func={}
|
c.func={}
|
||||||
c.Id=0
|
|
||||||
c.Type='process'
|
c.Type='process'
|
||||||
c.Mainloop={}
|
c.Mainloop={}
|
||||||
c.Tasks={}
|
|
||||||
c.Tasks2={}
|
|
||||||
c.Garbage={}
|
c.Garbage={}
|
||||||
c.Children={}
|
c.Children={}
|
||||||
c.Paused={}
|
|
||||||
c.Active=true
|
c.Active=true
|
||||||
c.Id=-1
|
c.Id=-1
|
||||||
c.Rest=0
|
c.Rest=0
|
||||||
c.Jobs={}
|
c.Jobs={}
|
||||||
c.queue={}
|
c.queue={}
|
||||||
c.jobUS=2
|
c.jobUS=2
|
||||||
c.l=self:newLoop(function(self,dt) c:uManager(dt) end)
|
c.l=self:newLoop(function(self,dt) c:uManager() end)
|
||||||
c.l:Pause()
|
c.l:Pause()
|
||||||
function c:getController()
|
function c:getController()
|
||||||
return c.l
|
return c.l
|
||||||
@ -926,7 +699,6 @@ function multi:newJob(func,name)
|
|||||||
c.Active=true
|
c.Active=true
|
||||||
c.func={}
|
c.func={}
|
||||||
c.Id=0
|
c.Id=0
|
||||||
c.PId=0
|
|
||||||
c.Parent=self
|
c.Parent=self
|
||||||
c.Type='job'
|
c.Type='job'
|
||||||
c.trigfunc=func or function() end
|
c.trigfunc=func or function() end
|
||||||
@ -974,111 +746,142 @@ function multi:newCondition(func)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
multi.NewCondition=multi.newCondition
|
multi.NewCondition=multi.newCondition
|
||||||
function multi:mainloop()
|
function multi:mainloop(settings)
|
||||||
if not multi.isRunning then
|
if not multi.isRunning then
|
||||||
multi.isRunning=true
|
local protect = false
|
||||||
for i=1,#self.Tasks do
|
local priority = false
|
||||||
self.Tasks[i](self)
|
if settings then
|
||||||
|
if settings.preLoop then
|
||||||
|
settings.preLoop(self)
|
||||||
|
end
|
||||||
|
protect = settings.protect
|
||||||
|
priority = settings.priority
|
||||||
end
|
end
|
||||||
|
multi.isRunning=true
|
||||||
rawset(self,'Start',self.clock())
|
rawset(self,'Start',self.clock())
|
||||||
while self.Active do
|
while self.Active do
|
||||||
self:Do_Order()
|
if priority==1 then
|
||||||
end
|
local Loop=self.Mainloop
|
||||||
else
|
local PS=self
|
||||||
return "Already Running!"
|
for _D=#Loop,1,-1 do
|
||||||
end
|
for P=1,7 do
|
||||||
end
|
if Loop[_D] then
|
||||||
function multi:protectedMainloop()
|
if (PS.PList[P])%Loop[_D].Priority==0 then
|
||||||
multi:protect()
|
if Loop[_D].Active then
|
||||||
if not multi.isRunning then
|
self.CID=_D
|
||||||
multi.isRunning=true
|
if not protect then
|
||||||
for i=1,#self.Tasks do
|
Loop[_D]:Act()
|
||||||
self.Tasks[i](self)
|
else
|
||||||
end
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
rawset(self,'Start',self.clock())
|
if err then
|
||||||
while self.Active do
|
Loop[_D].error=err
|
||||||
self:Do_Order()
|
self.OnError:Fire(Loop[_D],err)
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
return "Already Running!"
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:unprotectedMainloop()
|
|
||||||
multi:unProtect()
|
|
||||||
if not multi.isRunning then
|
|
||||||
multi.isRunning=true
|
|
||||||
for i=1,#self.Tasks do
|
|
||||||
self.Tasks[i](self)
|
|
||||||
end
|
|
||||||
rawset(self,'Start',self.clock())
|
|
||||||
while self.Active do
|
|
||||||
local Loop=self.Mainloop
|
|
||||||
_G.ID=0
|
|
||||||
for _D=#Loop,1,-1 do
|
|
||||||
if Loop[_D] then
|
|
||||||
if Loop[_D].Active then
|
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
|
||||||
Loop[_D]:Act()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
elseif priority==2 then
|
||||||
end
|
local Loop=self.Mainloop
|
||||||
else
|
local PS=self
|
||||||
return "Already Running!"
|
for _D=#Loop,1,-1 do
|
||||||
end
|
if Loop[_D] then
|
||||||
end
|
if (PS.PStep)%Loop[_D].Priority==0 then
|
||||||
function multi:prioritizedMainloop1()
|
if Loop[_D].Active then
|
||||||
multi:enablePriority()
|
self.CID=_D
|
||||||
if not multi.isRunning then
|
if not protect then
|
||||||
multi.isRunning=true
|
Loop[_D]:Act()
|
||||||
for i=1,#self.Tasks do
|
else
|
||||||
self.Tasks[i](self)
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
end
|
if err then
|
||||||
rawset(self,'Start',self.clock())
|
Loop[_D].error=err
|
||||||
while self.Active do
|
self.OnError:Fire(Loop[_D],err)
|
||||||
local Loop=self.Mainloop
|
end
|
||||||
_G.ID=0
|
end
|
||||||
local PS=self
|
end
|
||||||
for _D=#Loop,1,-1 do
|
end
|
||||||
if Loop[_D] then
|
end
|
||||||
if (PS.PList[PS.PStep])%Loop[_D].Priority==0 then
|
end
|
||||||
|
PS.PStep=PS.PStep+1
|
||||||
|
if PS.PStep>self.Priority_Idle then
|
||||||
|
PS.PStep=1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local Loop=self.Mainloop
|
||||||
|
for _D=#Loop,1,-1 do
|
||||||
|
if Loop[_D] then
|
||||||
if Loop[_D].Active then
|
if Loop[_D].Active then
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
self.CID=_D
|
||||||
Loop[_D]:Act()
|
if not protect then
|
||||||
|
Loop[_D]:Act()
|
||||||
|
else
|
||||||
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
|
if err then
|
||||||
|
Loop[_D].error=err
|
||||||
|
self.OnError:Fire(Loop[_D],err)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
PS.PStep=PS.PStep+1
|
|
||||||
if PS.PStep>7 then
|
|
||||||
PS.PStep=1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return "Already Running!"
|
return "Already Running!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:prioritizedMainloop2()
|
function multi:uManager(settings)
|
||||||
multi:enablePriority2()
|
if settings then
|
||||||
if not multi.isRunning then
|
if settings.preLoop then
|
||||||
multi.isRunning=true
|
settings.preLoop(self)
|
||||||
for i=1,#self.Tasks do
|
|
||||||
self.Tasks[i](self)
|
|
||||||
end
|
end
|
||||||
rawset(self,'Start',self.clock())
|
end
|
||||||
while self.Active do
|
self.uManager=self.uManagerRef
|
||||||
|
end
|
||||||
|
function multi:uManagerRef(settings)
|
||||||
|
if self.Active then
|
||||||
|
if settings.priority==1 then
|
||||||
|
local Loop=self.Mainloop
|
||||||
|
local PS=self
|
||||||
|
for _D=#Loop,1,-1 do
|
||||||
|
for P=1,7 do
|
||||||
|
if Loop[_D] then
|
||||||
|
if (PS.PList[P])%Loop[_D].Priority==0 then
|
||||||
|
if Loop[_D].Active then
|
||||||
|
self.CID=_D
|
||||||
|
if not settings.protect then
|
||||||
|
Loop[_D]:Act()
|
||||||
|
else
|
||||||
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
|
if err then
|
||||||
|
Loop[_D].error=err
|
||||||
|
self.OnError:Fire(Loop[_D],err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif settings.priority==2 then
|
||||||
local Loop=self.Mainloop
|
local Loop=self.Mainloop
|
||||||
_G.ID=0
|
|
||||||
local PS=self
|
local PS=self
|
||||||
for _D=#Loop,1,-1 do
|
for _D=#Loop,1,-1 do
|
||||||
if Loop[_D] then
|
if Loop[_D] then
|
||||||
if (PS.PStep)%Loop[_D].Priority==0 then
|
if (PS.PStep)%Loop[_D].Priority==0 then
|
||||||
if Loop[_D].Active then
|
if Loop[_D].Active then
|
||||||
Loop[_D].Id=_D
|
|
||||||
self.CID=_D
|
self.CID=_D
|
||||||
Loop[_D]:Act()
|
if not settings.protect then
|
||||||
|
Loop[_D]:Act()
|
||||||
|
else
|
||||||
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
|
if err then
|
||||||
|
Loop[_D].error=err
|
||||||
|
self.OnError:Fire(Loop[_D],err)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1087,28 +890,25 @@ function multi:prioritizedMainloop2()
|
|||||||
if PS.PStep>self.Priority_Idle then
|
if PS.PStep>self.Priority_Idle then
|
||||||
PS.PStep=1
|
PS.PStep=1
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local Loop=self.Mainloop
|
||||||
|
for _D=#Loop,1,-1 do
|
||||||
|
if Loop[_D] then
|
||||||
|
if Loop[_D].Active then
|
||||||
|
self.CID=_D
|
||||||
|
if not settings.protect then
|
||||||
|
Loop[_D]:Act()
|
||||||
|
else
|
||||||
|
local status, err=pcall(Loop[_D].Act,Loop[_D])
|
||||||
|
if err then
|
||||||
|
Loop[_D].error=err
|
||||||
|
self.OnError:Fire(Loop[_D],err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
return "Already Running!"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi._tFunc(self,dt)
|
|
||||||
for i=1,#self.Tasks do
|
|
||||||
self.Tasks[i](self)
|
|
||||||
end
|
|
||||||
if dt then
|
|
||||||
self.pump=true
|
|
||||||
end
|
|
||||||
self.pumpvar=dt
|
|
||||||
rawset(self,'Start',self.clock())
|
|
||||||
end
|
|
||||||
function multi:uManager(dt)
|
|
||||||
if self.Active then
|
|
||||||
self:oneTime(self._tFunc,self,dt)
|
|
||||||
function self:uManager(dt)
|
|
||||||
self:Do_Order()
|
|
||||||
end
|
|
||||||
self:Do_Order()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Core Actors
|
--Core Actors
|
||||||
@ -1311,9 +1111,6 @@ function multi:newStep(start,reset,count,skip)
|
|||||||
self:create(c)
|
self:create(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
function multi:newTask(func)
|
|
||||||
table.insert(self.Tasks,func)
|
|
||||||
end
|
|
||||||
function multi:newTLoop(func,set)
|
function multi:newTLoop(func,set)
|
||||||
local c=self:newBase()
|
local c=self:newBase()
|
||||||
c.Type='tloop'
|
c.Type='tloop'
|
||||||
@ -1608,7 +1405,6 @@ function multi:newTBase(name)
|
|||||||
c.func={}
|
c.func={}
|
||||||
c.ender={}
|
c.ender={}
|
||||||
c.Id=0
|
c.Id=0
|
||||||
c.PId=0
|
|
||||||
c.Parent=self
|
c.Parent=self
|
||||||
c.important={}
|
c.important={}
|
||||||
c.held=false
|
c.held=false
|
||||||
@ -2003,7 +1799,6 @@ function multi:newThreadedProcess(name)
|
|||||||
ct.func={}
|
ct.func={}
|
||||||
ct.ender={}
|
ct.ender={}
|
||||||
ct.Id=0
|
ct.Id=0
|
||||||
ct.PId=0
|
|
||||||
ct.Act=function() end
|
ct.Act=function() end
|
||||||
ct.Parent=self
|
ct.Parent=self
|
||||||
ct.held=false
|
ct.held=false
|
||||||
@ -2017,11 +1812,8 @@ function multi:newThreadedProcess(name)
|
|||||||
c.Id=0
|
c.Id=0
|
||||||
c.Type='process'
|
c.Type='process'
|
||||||
c.Mainloop={}
|
c.Mainloop={}
|
||||||
c.Tasks={}
|
|
||||||
c.Tasks2={}
|
|
||||||
c.Garbage={}
|
c.Garbage={}
|
||||||
c.Children={}
|
c.Children={}
|
||||||
c.Paused={}
|
|
||||||
c.Active=true
|
c.Active=true
|
||||||
c.Id=-1
|
c.Id=-1
|
||||||
c.Rest=0
|
c.Rest=0
|
||||||
@ -2166,7 +1958,6 @@ function multi:ToString()
|
|||||||
ender=self.ender,
|
ender=self.ender,
|
||||||
-- IDK if these need to be present...
|
-- IDK if these need to be present...
|
||||||
-- Id=self.Id,
|
-- Id=self.Id,
|
||||||
-- PId=self.PId,
|
|
||||||
held=self.held,
|
held=self.held,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2179,7 +1970,6 @@ function multi:ToString()
|
|||||||
ender=self.ender,
|
ender=self.ender,
|
||||||
-- IDK if these need to be present...
|
-- IDK if these need to be present...
|
||||||
-- Id=self.Id,
|
-- Id=self.Id,
|
||||||
-- PId=self.PId,
|
|
||||||
held=self.held,
|
held=self.held,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -2399,3 +2189,4 @@ multi.load_updater:OnUpdate(function(self)
|
|||||||
self.Parent.dStepB = os.clock()
|
self.Parent.dStepB = os.clock()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
return multi
|
||||||
@ -32,7 +32,7 @@ end
|
|||||||
-- Step 1 get lanes
|
-- Step 1 get lanes
|
||||||
lanes=require("lanes").configure()
|
lanes=require("lanes").configure()
|
||||||
--~ package.path="lua/?/init.lua;lua/?.lua;"..package.path
|
--~ package.path="lua/?/init.lua;lua/?.lua;"..package.path
|
||||||
require("multi") -- get it all and have it on all lanes
|
local multi = require("multi") -- get it all and have it on all lanes
|
||||||
isMainThread=true
|
isMainThread=true
|
||||||
function multi:canSystemThread()
|
function multi:canSystemThread()
|
||||||
return true
|
return true
|
||||||
@ -40,7 +40,6 @@ end
|
|||||||
function multi:getPlatform()
|
function multi:getPlatform()
|
||||||
return "lanes"
|
return "lanes"
|
||||||
end
|
end
|
||||||
local multi=multi
|
|
||||||
-- Step 2 set up the linda objects
|
-- Step 2 set up the linda objects
|
||||||
local __GlobalLinda = lanes.linda() -- handles global stuff
|
local __GlobalLinda = lanes.linda() -- handles global stuff
|
||||||
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
||||||
@ -143,4 +142,4 @@ multi.integration={} -- for module creators
|
|||||||
multi.integration.GLOBAL=GLOBAL
|
multi.integration.GLOBAL=GLOBAL
|
||||||
multi.integration.THREAD=THREAD
|
multi.integration.THREAD=THREAD
|
||||||
require("multi.integration.shared")
|
require("multi.integration.shared")
|
||||||
return {init=function() return GLOBAL,THREAD end}
|
return {init=function() return GLOBAL, THREAD end}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
require("multi.compat.love2d")
|
local multi = require("multi.compat.love2d")
|
||||||
function multi:canSystemThread()
|
function multi:canSystemThread()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -35,7 +35,7 @@ local function _INIT(luvitThread,timer)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Step 1 get setup threads on luvit... Sigh how do i even...
|
-- Step 1 get setup threads on luvit... Sigh how do i even...
|
||||||
require("multi")
|
local multi = require("multi")
|
||||||
isMainThread=true
|
isMainThread=true
|
||||||
function multi:canSystemThread()
|
function multi:canSystemThread()
|
||||||
return true
|
return true
|
||||||
@ -123,5 +123,6 @@ local function _INIT(luvitThread,timer)
|
|||||||
local interval = timer.setInterval(1, function ()
|
local interval = timer.setInterval(1, function ()
|
||||||
multi:uManager()
|
multi:uManager()
|
||||||
end)
|
end)
|
||||||
|
return multi
|
||||||
end
|
end
|
||||||
return {init=function(threadHandle,timerHandle) _INIT(threadHandle,timerHandle) return GLOBAL,THREAD end}
|
return {init=function(threadHandle,timerHandle) local multi = _INIT(threadHandle,timerHandle) return GLOBAL, THREAD end}
|
||||||
|
|||||||
39
multi/integration/networkManager.lua
Normal file
39
multi/integration/networkManager.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
local multi = require("multi")
|
||||||
|
local net = require("net")
|
||||||
|
local nGLOBAL = {}
|
||||||
|
local nTHREAD = {}
|
||||||
|
-- This integration is a bit different than the others! Nodes should include both the system threading integration and the network integration. This is because each node has a "main thread" as well. The examples will make this clear!
|
||||||
|
multi.defaultNetworkPort = 30341 -- This port has a meaning to it... convert to base 36 and see what you get.
|
||||||
|
function multi:setdefaultNetworkPort(port)
|
||||||
|
multi.defaultNetworkPort = port
|
||||||
|
end
|
||||||
|
function multi:newNode(name,settings)
|
||||||
|
-- Here we have to use the net library to broadcast our node across the network
|
||||||
|
local port = multi.defaultNetworkPort
|
||||||
|
math.randomseed(os.time())
|
||||||
|
local name = name or multi.randomString(8)
|
||||||
|
if settings then
|
||||||
|
port = settings.port or port
|
||||||
|
-- When I think of more they will be added here
|
||||||
|
end
|
||||||
|
local node = {}
|
||||||
|
node.server = net:newServer(port) -- hosts the node using the default port
|
||||||
|
node.port = multi.defaultNetworkPort
|
||||||
|
-- Lets tell the network we are alive!
|
||||||
|
node.server:broadcast("NODE_"..name)
|
||||||
|
end
|
||||||
|
function multi:newMaster(name,settings) -- You will be able to have more than one master connecting to a node if that is what you want to do. I want you to be able to have the freedom to code any way that you want to code.
|
||||||
|
local master = {}
|
||||||
|
master.clients = net.ClientCache -- Link to the client cache that is created on the net interface
|
||||||
|
net.OnCastedClientInfo(function(client,name,ip,port)
|
||||||
|
print("Found a new node!")
|
||||||
|
-- Do the handshake and start up stuff here
|
||||||
|
end)
|
||||||
|
net:newCastedClients("NODE_(.+)") -- Searches for nodes and connects to them, the master.clients table will contain them by name
|
||||||
|
end
|
||||||
|
-- For the same reasons that the other integrations have this
|
||||||
|
multi.integration.nGLOBAL=nGLOBAL
|
||||||
|
multi.integration.nTHREAD=nTHREAD
|
||||||
|
return {init=function()
|
||||||
|
return nGLOBAL, nTHREAD
|
||||||
|
end}
|
||||||
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
multi = require("multi")
|
||||||
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
||||||
local c={} -- where we will store our object
|
local c={} -- where we will store our object
|
||||||
c.name=name -- set the name this is important for the love2d side
|
c.name=name -- set the name this is important for the love2d side
|
||||||
@ -182,8 +183,9 @@ function multi:newSystemThreadedConnection(name,protect)
|
|||||||
table.remove(data,1)-- Remove the first 3 elements
|
table.remove(data,1)-- Remove the first 3 elements
|
||||||
table.remove(data,1)-- Remove the first 3 elements
|
table.remove(data,1)-- Remove the first 3 elements
|
||||||
con.obj:Fire(unpack(data))
|
con.obj:Fire(unpack(data))
|
||||||
multi:newThread("Clean_UP",function()
|
local alarm = multi:newAlarm(con.cleanup)
|
||||||
thread.sleep(con.cleanup)
|
alarm:OnRing(function()
|
||||||
|
alarm:Destroy()
|
||||||
local dat = con.queueCall:peek()
|
local dat = con.queueCall:peek()
|
||||||
if not dat then return end
|
if not dat then return end
|
||||||
table.remove(data,1)-- Remove the first 3 elements
|
table.remove(data,1)-- Remove the first 3 elements
|
||||||
@ -218,7 +220,7 @@ function multi:systemThreadedBenchmark(n,p)
|
|||||||
if multi:getPlatform()=="love2d" then
|
if multi:getPlatform()=="love2d" then
|
||||||
GLOBAL=_G.GLOBAL
|
GLOBAL=_G.GLOBAL
|
||||||
sThread=_G.sThread
|
sThread=_G.sThread
|
||||||
end -- we cannot have upvalues... in love2d globals not locals must be used
|
end -- we cannot have upvalues... in love2d globals, not locals must be used
|
||||||
queue=sThread.waitFor("QUEUE"):init() -- always wait for when looking for a variable at the start of the thread!
|
queue=sThread.waitFor("QUEUE"):init() -- always wait for when looking for a variable at the start of the thread!
|
||||||
multi:benchMark(sThread.waitFor("__SYSTEMBENCHMARK__")):OnBench(function(self,count)
|
multi:benchMark(sThread.waitFor("__SYSTEMBENCHMARK__")):OnBench(function(self,count)
|
||||||
queue:push(count)
|
queue:push(count)
|
||||||
@ -266,17 +268,14 @@ function multi:newSystemThreadedConsole(name)
|
|||||||
cc.stream = sThread.waitFor("__SYSTEM_CONSLOE__"):init()
|
cc.stream = sThread.waitFor("__SYSTEM_CONSLOE__"):init()
|
||||||
else
|
else
|
||||||
cc.stream = multi:newSystemThreadedQueue("__SYSTEM_CONSLOE__"):init()
|
cc.stream = multi:newSystemThreadedQueue("__SYSTEM_CONSLOE__"):init()
|
||||||
multi:newThread("Threaded_Console",function()
|
multi:newLoop(function()
|
||||||
while true do
|
local data = cc.stream:pop()
|
||||||
thread.sleep(.001)
|
if data then
|
||||||
local data = cc.stream:pop()
|
local dat = table.remove(data,1)
|
||||||
if data then
|
if dat=="w" then
|
||||||
local dat = table.remove(data,1)
|
io.write(unpack(data))
|
||||||
if dat=="w" then
|
elseif dat=="p" then
|
||||||
io.write(unpack(data))
|
print(unpack(data))
|
||||||
elseif dat=="p" then
|
|
||||||
print(unpack(data))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user