The way my asset loading works is it queues them all up in a queue table with info about each "asset load request" then when a function is called it loads them all at once while displaying a loading screen. There are 2 problems:
1. You can't use love.graphics in threads, even to load images.
2. You can't send non-flat tables.
Besides the first one, I don't even know how I can do it. I would have to loop and send each single queued asset, then in the thread do some more stuff after I pop it all, then give back the loaded resources one at a time so they can be put into their respective asset tables, all the while rendering the animated loader in the main thread... why is it so hard? Is there a simpler and actually possible way?
Multithreaded Loading Screen... problems
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Multithreaded Loading Screen... problems
while true do end;
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Multithreaded Loading Screen... problems
You can do what kikito's solution does and load the assets as data. Like image data and etc. Then you can send them to the main thread. On the main thread there will be a scheduler/manager that will turn the image data to an image and put it in a table for you to use.
Re: Multithreaded Loading Screen... problems
Code: Select all
while true do
task = tasks:demand()
local ret = {name=task.name}
if task.type == "image" then
ret.data = love.image.newImageData(task.image)
else if task.type == .....
end
results:push(ret)
end
Code: Select all
values = {}
function love.load()
tasks:push{type="image", image="logo.png"}
...
end
function love.update()
res = results:pop()
while res do
values[res.name] = res.data
res = results.pop()
end
end
- slime
- Solid Snayke
- Posts: 3136
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Multithreaded Loading Screen... problems
Check out kikito's love-loader library (which is what BobbyJones mentioned).
Re: Multithreaded Loading Screen... problems
Works for images, but what about fonts? Can't find a way to load fonts without love.graphics.S0lll0s wrote:Code: Select all
while true do task = tasks:demand() local ret = {name=task.name} if task.type == "image" then ret.data = love.image.newImageData(task.image) else if task.type == ..... end results:push(ret) end
Untested and with a few parts missing, but you get the idea.Code: Select all
values = {} function love.load() tasks:push{type="image", image="logo.png"} ... end function love.update() res = results:pop() while res do values[res.name] = res.data res = results.pop() end end
while true do end;
Who is online
Users browsing this forum: Google [Bot] and 6 guests