Multithreaded Loading Screen... problems

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

Multithreaded Loading Screen... problems

Post by RonanZero »

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? :death:
while true do end;
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Multithreaded Loading Screen... problems

Post by bobbyjones »

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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Multithreaded Loading Screen... problems

Post by s-ol »

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
Untested and with a few parts missing, but you get the idea.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
slime
Solid Snayke
Posts: 3136
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Multithreaded Loading Screen... problems

Post by slime »

Check out kikito's love-loader library (which is what BobbyJones mentioned).
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

Re: Multithreaded Loading Screen... problems

Post by RonanZero »

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

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
Untested and with a few parts missing, but you get the idea.
Works for images, but what about fonts? Can't find a way to load fonts without love.graphics.
while true do end;
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests