Added some new methods (1.7.6)
More examples small tweaks added/modified examples typos as always minor bug fixes some new features, read readme for them
This commit is contained in:
parent
1635a1633c
commit
38f8234d20
48
README.md
48
README.md
@ -1,5 +1,6 @@
|
|||||||
# multi Version: 1.7.5 (Typos and improved module creation supprt, examples to come soon)
|
# multi Version: 1.7.6 (Examples and more module creation support, small tweaks to cut down the amount of code needed to get things to work)
|
||||||
View Changes: https://github.com/rayaman/multi#changes
|
View Changes: https://github.com/rayaman/multi#changes
|
||||||
|
**Note: The changes section has information on how to use the new features as they come out. Why put the infomation twice on the readme?**</br>
|
||||||
|
|
||||||
My multitasking library for lua</br>
|
My multitasking library for lua</br>
|
||||||
To install copy the multi folder into your enviroment and you are good to go</br>
|
To install copy the multi folder into your enviroment and you are good to go</br>
|
||||||
@ -14,14 +15,22 @@ Also I will eventually add an example folder with a lot of examples for how you
|
|||||||
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries</br>
|
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries</br>
|
||||||
https://discord.gg/U8UspuA</br>
|
https://discord.gg/U8UspuA</br>
|
||||||
|
|
||||||
# Planned feature
|
# Planned features/TODO
|
||||||
- [x] Add system threads for love2d that work like the lanesManager (loveManager).
|
- [x] Add system threads for love2d that works like the lanesManager (loveManager, slight differences).
|
||||||
- [ ] Improve performance of the library
|
- [ ] Improve performance of the library
|
||||||
- [ ] Add more features to support module creators
|
- [ ] Add more features to support module creators
|
||||||
|
- [ ] Make a framework for eaiser thread task distributing
|
||||||
|
- [ ] Fix Error handling on multi objects
|
||||||
|
- [ ] Add Remote Proxies **May or may not be completed**
|
||||||
|
- [ ] sThread.wrapper(obj) **May or may not be completed**
|
||||||
|
- [ ] SystemThreaded Actors
|
||||||
|
- [ ] LoadBalancing for system threads (Once SystemThreaded Actors are done)
|
||||||
|
- [ ] Add more intergrations
|
||||||
|
- [ ] Finish the wiki stuff. (11% done)</br>
|
||||||
|
- [ ] Test for unknown bugs</br>
|
||||||
Usage:</br>
|
Usage:</br>
|
||||||
```lua
|
```lua
|
||||||
--Basic usage Alarms: Have been moved to the core of the library require("multi") would work as well
|
-- Basic usage Alarms: 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
|
||||||
alarm=multi:newAlarm(3) -- in seconds can go to .001 uses the built in os.clock()
|
alarm=multi:newAlarm(3) -- in seconds can go to .001 uses the built in os.clock()
|
||||||
alarm:OnRing(function(a)
|
alarm:OnRing(function(a)
|
||||||
@ -753,13 +762,25 @@ Looping...</br>
|
|||||||
We did it! 1 2 3</br>
|
We did it! 1 2 3</br>
|
||||||
|
|
||||||
# Changes
|
# Changes
|
||||||
Updated from 1.7.4 to 1.7.5</br>
|
Updated from 1.7.5 to 1.7.6</br>
|
||||||
Fixed some typos in the readme... (I am sure there are more there are always more)
|
Fixed:
|
||||||
Added more features for module support
|
Typos like always
|
||||||
TODO:
|
Added:</br>
|
||||||
Work on performance of the library... I see 3 places where I can make this thing run quicker
|
multi:getPlatform() -- returns "love2d" if using the love2d platform or returns "lanes" if using lanes for threading</br>
|
||||||
|
examples files</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>
|
||||||
|
|
||||||
I'll show case some old versions of the multitasking library eventually so you can see its changes in days past!
|
Updated:
|
||||||
|
some example files to reflect changes to the core. Changes allow for less typing</br>
|
||||||
|
loveManager to require the compat if used so you don't need 2 require line to retrieve the library</br>
|
||||||
|
Updated from 1.7.4 to 1.7.5</br>
|
||||||
|
Fixed some typos in the readme... (I am sure there are more there are always more)</br>
|
||||||
|
Added more features for module support</br>
|
||||||
|
TODO:</br>
|
||||||
|
Work on performance of the library... I see 3 places where I can make this thing run quicker</br>
|
||||||
|
|
||||||
|
I'll show case some old versions of the multitasking library eventually so you can see its changes in days past!</br>
|
||||||
|
|
||||||
Updated from 1.7.3 to 1.7.4</br>
|
Updated from 1.7.3 to 1.7.4</br>
|
||||||
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>
|
||||||
@ -943,7 +964,4 @@ Added:
|
|||||||
1.4.1 - First Public release of the library
|
1.4.1 - First Public release of the library
|
||||||
|
|
||||||
IMPORTANT:</br>
|
IMPORTANT:</br>
|
||||||
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 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>
|
||||||
# TODO (In order of importance)
|
|
||||||
- [ ] Finish the wiki stuff. (10% done)</br>
|
|
||||||
- [ ] Test for unknown bugs</br>
|
|
||||||
BIN
examples/lanes resource loading/proAudioRt.dll
Normal file
BIN
examples/lanes resource loading/proAudioRt.dll
Normal file
Binary file not shown.
BIN
examples/lanes resource loading/proAudioRt.so
Normal file
BIN
examples/lanes resource loading/proAudioRt.so
Normal file
Binary file not shown.
32
examples/lanes resource loading/resourceloading.lua
Normal file
32
examples/lanes resource loading/resourceloading.lua
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
require("proAudioRt") -- an audio library
|
||||||
|
-- The hosting site with precompiled binaries is down, but here is a link to a archive
|
||||||
|
-- https://web.archive.org/web/20160907180559/http://viremo.eludi.net:80/proteaAudio/proteaaudiolua.html documentation and downloads are availiable... I also have saved copies just in case :D
|
||||||
|
-- Music by: myuuji
|
||||||
|
-- His youtube channel can be found here: https://www.youtube.com/channel/UCiSKnkKCKAQVxMUWpZQobuQ
|
||||||
|
proAudio.create()
|
||||||
|
multi:newThread("test",function()
|
||||||
|
-- simple playlist
|
||||||
|
sThread.waitFor("song")
|
||||||
|
print("Playing song 1!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song"])
|
||||||
|
sThread.waitFor("song2")
|
||||||
|
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
|
||||||
|
print("Playing song 2!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song2"])
|
||||||
|
sThread.waitFor("song3")
|
||||||
|
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
|
||||||
|
print("Playing song 3!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song3"])
|
||||||
|
end)
|
||||||
|
-- loading the audio in another thread is way faster! So lets do that
|
||||||
|
multi:newSystemThread("test1",function() -- spawns a thread in another lua process
|
||||||
|
require("proAudioRt")
|
||||||
|
GLOBAL["song"]=proAudio.sampleFromFile("test.ogg",1,1)
|
||||||
|
print("Loaded song 1!")
|
||||||
|
GLOBAL["song2"]=proAudio.sampleFromFile("test2.ogg",1,1)
|
||||||
|
print("Loaded song 2!")
|
||||||
|
GLOBAL["song3"]=proAudio.sampleFromFile("test3.ogg",1,1)
|
||||||
|
print("Loaded song 3!")
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
BIN
examples/lanes resource loading/test.ogg
Normal file
BIN
examples/lanes resource loading/test.ogg
Normal file
Binary file not shown.
BIN
examples/lanes resource loading/test2.ogg
Normal file
BIN
examples/lanes resource loading/test2.ogg
Normal file
Binary file not shown.
BIN
examples/lanes resource loading/test3.ogg
Normal file
BIN
examples/lanes resource loading/test3.ogg
Normal file
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
package.path="?/init.lua;?.lua;"..package.path
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
require("multi.threading")
|
|
||||||
multi:newAlarm(2):OnRing(function(self)
|
multi:newAlarm(2):OnRing(function(self)
|
||||||
GLOBAL["NumOfCores"]=sThread.getCores()
|
GLOBAL["NumOfCores"]=sThread.getCores()
|
||||||
end)
|
end)
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package.path="?/init.lua;?.lua;"..package.path
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
|
||||||
require("multi.threading") -- obvious copy/paste below with no attempt to clean it up :P
|
|
||||||
local function comma_value(amount)
|
local function comma_value(amount)
|
||||||
local formatted = amount
|
local formatted = amount
|
||||||
while true do
|
while true do
|
||||||
@ -40,8 +39,6 @@ multi:newSystemThread("test6",function() -- spawns a thread in another lua proce
|
|||||||
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
end)
|
|
||||||
multi:newSystemThread("Combiner",function() -- spawns a thread in another lua process
|
|
||||||
print("Bench: ",comma_value(tostring(sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6"))))
|
print("Bench: ",comma_value(tostring(sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6"))))
|
||||||
GLOBAL["DONE"]=true
|
GLOBAL["DONE"]=true
|
||||||
end)
|
end)
|
||||||
@ -58,5 +55,5 @@ multi:newThread("test0",function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
GLOBAL["Bench"]=10
|
GLOBAL["Bench"]=60
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
|
|||||||
48
examples/lanesintergratetest3.lua
Normal file
48
examples/lanesintergratetest3.lua
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package.path="?/init.lua;?.lua;"..package.path -- Spawing threads using 1 method and the sThread.getCores() function!
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
|
||||||
|
local function comma_value(amount)
|
||||||
|
local formatted = amount
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if (k==0) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
GLOBAL["BENCHCOUNT"],GLOBAL["CNUM"],GLOBAL["DONE"]=0,0,0
|
||||||
|
cores=sThread.getCores()
|
||||||
|
function benchmark() -- our single function that will be used across a bunch of threads
|
||||||
|
require("multi.all") -- get the library
|
||||||
|
local n=GLOBAL["CNUM"]; GLOBAL["CNUM"]=n+1 -- do some math so we can identify which thread is which
|
||||||
|
multi:benchMark(sThread.waitFor("BENCH"),nil,"Thread "..n+1):OnBench(function(self,c) GLOBAL["BENCHCOUNT"]=GLOBAL["BENCHCOUNT"]+c; GLOBAL["DONE"]=GLOBAL["DONE"]+1; multi:Stop() end)
|
||||||
|
-- ^ do the bench mark and add to the BENCHCOUNT GLOBAL value, then increment the DONE Value
|
||||||
|
multi:mainloop()
|
||||||
|
end
|
||||||
|
for i=1,cores do -- loop based on the number of cores you have
|
||||||
|
multi:newSystemThread("test"..i,benchmark) -- create a system thread based on the benchmark
|
||||||
|
end
|
||||||
|
multi:newThread("test0",function()
|
||||||
|
while true do
|
||||||
|
thread.skip(1)
|
||||||
|
sThread.sleep(.001)
|
||||||
|
if GLOBAL["DONE"]==cores then
|
||||||
|
print(comma_value(tostring(GLOBAL["BENCHCOUNT"])))
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
GLOBAL["BENCH"]=10
|
||||||
|
print("Platform is: ",multi:getPlatform()) -- returns love2d or lanes depending on which platform you are using... If I add more intergrations then this method will be updated! corona sdk may see this library in the future...
|
||||||
|
multi:mainloop()
|
||||||
|
--[[ Output on my machine! I am using luajit and have 6 cores on my computer. Your numbers will vary, but it should look something like this
|
||||||
|
Intergrated Lanes!
|
||||||
|
Platform is: lanes
|
||||||
|
Thread 1 62442125 Steps in 10 second(s)!
|
||||||
|
Thread 2 61379095 Steps in 10 second(s)!
|
||||||
|
Thread 3 62772502 Steps in 10 second(s)!
|
||||||
|
Thread 4 62740684 Steps in 10 second(s)!
|
||||||
|
Thread 5 60926715 Steps in 10 second(s)!
|
||||||
|
Thread 6 61793175 Steps in 10 second(s)!
|
||||||
|
372,054,296
|
||||||
|
]]
|
||||||
@ -1,6 +1,5 @@
|
|||||||
require("core.Library")
|
require("core.Library")
|
||||||
require("multi.compat.love2d") -- allows for multitasking and binds my libraies to the love2d engine that i am using
|
GLOBAL,sThread=require("multi.intergration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
|
||||||
GLOBAL,sThread=require("multi.intergration.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
|
||||||
-- 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
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function print(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
multi = {}
|
multi = {}
|
||||||
multi.Version={1,7,5}
|
multi.Version={1,7,6}
|
||||||
multi.stage='stable'
|
multi.stage='stable'
|
||||||
multi.__index = multi
|
multi.__index = multi
|
||||||
multi.Mainloop={}
|
multi.Mainloop={}
|
||||||
@ -67,7 +67,7 @@ multi.jobUS=2
|
|||||||
multi.clock=os.clock
|
multi.clock=os.clock
|
||||||
multi.time=os.time
|
multi.time=os.time
|
||||||
multi.LinkedPath=multi
|
multi.LinkedPath=multi
|
||||||
mulit.isRunning=false
|
multi.isRunning=false
|
||||||
multi.queuefinal=function(self)
|
multi.queuefinal=function(self)
|
||||||
self:Destroy()
|
self:Destroy()
|
||||||
if self.Parent.Mainloop[#self.Parent.Mainloop] then
|
if self.Parent.Mainloop[#self.Parent.Mainloop] then
|
||||||
@ -239,6 +239,15 @@ end
|
|||||||
function multi:getVersion()
|
function multi:getVersion()
|
||||||
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
|
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
|
||||||
end
|
end
|
||||||
|
function multi:getPlatform()
|
||||||
|
if love then
|
||||||
|
if love.thread then
|
||||||
|
return "love2d"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return "lanes"
|
||||||
|
end
|
||||||
|
end
|
||||||
--Processor
|
--Processor
|
||||||
function multi:getError()
|
function multi:getError()
|
||||||
if self.error then
|
if self.error then
|
||||||
@ -953,8 +962,8 @@ function multi:newCondition(func)
|
|||||||
end
|
end
|
||||||
multi.NewCondition=multi.newCondition
|
multi.NewCondition=multi.newCondition
|
||||||
function multi:mainloop()
|
function multi:mainloop()
|
||||||
if not mulit.isRunning then
|
if not multi.isRunning then
|
||||||
mulit.isRunning=true
|
multi.isRunning=true
|
||||||
for i=1,#self.Tasks do
|
for i=1,#self.Tasks do
|
||||||
self.Tasks[i](self)
|
self.Tasks[i](self)
|
||||||
end
|
end
|
||||||
@ -1020,6 +1029,9 @@ function multi:newEvent(task)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function c:SetTask(func)
|
||||||
|
self.Task=func
|
||||||
|
end
|
||||||
function c:OnEvent(func)
|
function c:OnEvent(func)
|
||||||
table.insert(self.func,func)
|
table.insert(self.func,func)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,7 +31,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.updater") -- get it all and have it on all lanes
|
require("multi.all") -- get it all and have it on all lanes
|
||||||
local multi=multi
|
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
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
require("multi.compat.love2d")
|
||||||
multi.intergration={}
|
multi.intergration={}
|
||||||
multi.intergration.love2d={}
|
multi.intergration.love2d={}
|
||||||
multi.intergration.love2d.ThreadBase=[[
|
multi.intergration.love2d.ThreadBase=[[
|
||||||
@ -326,6 +327,7 @@ updater:OnUpdate(function(self)
|
|||||||
data=multi.intergration.love2d.mainChannel:pop()
|
data=multi.intergration.love2d.mainChannel:pop()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
print("Intergrated Love2d!")
|
||||||
return {
|
return {
|
||||||
init=function(t)
|
init=function(t)
|
||||||
if t then
|
if t then
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function print(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
multi = {}
|
multi = {}
|
||||||
multi.Version={1,7,5}
|
multi.Version={1,7,6}
|
||||||
multi.stage='stable'
|
multi.stage='stable'
|
||||||
multi.__index = multi
|
multi.__index = multi
|
||||||
multi.Mainloop={}
|
multi.Mainloop={}
|
||||||
@ -239,6 +239,15 @@ end
|
|||||||
function multi:getVersion()
|
function multi:getVersion()
|
||||||
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
|
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
|
||||||
end
|
end
|
||||||
|
function multi:getPlatform()
|
||||||
|
if love then
|
||||||
|
if love.thread then
|
||||||
|
return "love2d"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return "lanes"
|
||||||
|
end
|
||||||
|
end
|
||||||
--Processor
|
--Processor
|
||||||
function multi:getError()
|
function multi:getError()
|
||||||
if self.error then
|
if self.error then
|
||||||
@ -1020,6 +1029,9 @@ function multi:newEvent(task)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function c:SetTask(func)
|
||||||
|
self.Task=func
|
||||||
|
end
|
||||||
function c:OnEvent(func)
|
function c:OnEvent(func)
|
||||||
table.insert(self.func,func)
|
table.insert(self.func,func)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
require("multi.compat.love2d")
|
||||||
multi.intergration={}
|
multi.intergration={}
|
||||||
multi.intergration.love2d={}
|
multi.intergration.love2d={}
|
||||||
multi.intergration.love2d.ThreadBase=[[
|
multi.intergration.love2d.ThreadBase=[[
|
||||||
@ -326,6 +327,7 @@ updater:OnUpdate(function(self)
|
|||||||
data=multi.intergration.love2d.mainChannel:pop()
|
data=multi.intergration.love2d.mainChannel:pop()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
print("Intergrated Love2d!")
|
||||||
return {
|
return {
|
||||||
init=function(t)
|
init=function(t)
|
||||||
if t then
|
if t then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user