I am not new to programming, I've been working with C++ and threading in the language for some time. But when I began to try out threading with Love, it just takes me out for a spin.
The general concept is to get a ton of entities to update on the screen all within a reasonable amount of time. I'd like to approach this via a job-based threading method. But the documentation isn't really providing much information on how to pass around data. Or any kind of semaphor for that matter (Waiting for all entities to finish updating before moving on).
Does anyone have any information on the matter? Also an example of a system in a game would be preferable.
Help with threading?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Help with threading?
Bartbes' async lib could be useful for that.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Help with threading?
This might come a little late, but the general Idea I use is the following (someone on this forum once gave me this hint):
In the main thread:
- Create two channels, channelIn and channelOut
- Create the thread
- Call thread:start and pass channelIn and channel Out to it: thread:start( channelIn, channelOut ). This makes sure that the first two agruments the thread receives are the communicating channels.
- Start sending stuff on channelIn and wait for responses on channelOut*
In the created thread:
-
- Start listening for commands on channelIn and send responses on channelOut.
The way I often send packets is to create a small table, with a "key" and a "value", where the key identifies what type of packet it is. For example, when I want to notify the main thread that something went wrong, I would do something like:
I use this method in trAInsported for connection handling, for example for the client. There are two (somewhat uncommented, sorry) scripts: connectionThreadClient.lua, which is the background thread handling connections (on the client) and the connectionClient.lua, the foreground thread which handles it.
*It's also very important to start listening to connectionThread:getError(), because otherwise you'll never get syntax errors etc. from your thread.
In the main thread:
- Create two channels, channelIn and channelOut
- Create the thread
- Call thread:start and pass channelIn and channel Out to it: thread:start( channelIn, channelOut ). This makes sure that the first two agruments the thread receives are the communicating channels.
- Start sending stuff on channelIn and wait for responses on channelOut*
In the created thread:
-
Code: Select all
local args = { ... }; local channelIn = args[1]; local channelOut = args[2]
The way I often send packets is to create a small table, with a "key" and a "value", where the key identifies what type of packet it is. For example, when I want to notify the main thread that something went wrong, I would do something like:
Code: Select all
channelOut:push( {key="error", value="Connection timed out"}).
*It's also very important to start listening to connectionThread:getError(), because otherwise you'll never get syntax errors etc. from your thread.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Help with threading?
Or without the table:Germanunkol wrote: In the created thread:
-Code: Select all
local args = { ... }; local channelIn = args[1]; local channelOut = args[2]
Code: Select all
local channelIn, channelOut = ...
Alternatively, use love.threaderror.Germanunkol wrote: *It's also very important to start listening to connectionThread:getError(), because otherwise you'll never get syntax errors etc. from your thread.
Who is online
Users browsing this forum: No registered users and 5 guests