Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2017-10-01 10:37:08

Anatoly
Guest

Parallel running fucntions

Basically:

Like in ShiftBot, how to isolate blocks buildings from the commands, so once you build a map, you can still use commands.

#2 2017-10-01 10:45:06, last edited by LukeM (2017-10-01 10:46:49)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Parallel running fucntions

Use multiple threads and locks

I usually have a Queue<object[]> where object is the b messages being sent, and Place and BlockPlaceTick functions using locks to add and remove blocks from the queue
BlockPlaceTick is usually then called by a timer, and has a while(curTick < curTime) so it can place blocks faster than the max timer speed

Edit: Locks basically make it so two threads wait for each other to finish using data before they try to access it, as if they both used it at the same time, bad things could happen

Offline

#3 2017-10-01 11:25:51

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

Re: Parallel running fucntions

Or, if you're not worried about potential thread issues,

new Thread(() =>
{
    //send blocks

}).Start();

One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

Wooted by:

#4 2017-10-01 11:39:52

Anatoly
Guest

Re: Parallel running fucntions

What is more suggested? That Queue stuff or Threads?

Wooted by:

#5 2017-10-01 11:44:27

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Parallel running fucntions

AnatolyEE wrote:

What is more suggested? That Queue stuff or Threads?

Depends what youre using it for, some things wouldnt cause any threading problems, so you could just use Tomahawks, but other things might need the locks and queues to prevent errors

Offline

#6 2017-10-01 12:13:54

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: Parallel running fucntions

Screams Async in the background


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

Wooted by: (3)

#7 2017-10-01 12:55:52

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Parallel running fucntions

I personally have my main thread (duh), a thread for my message handler (so I don't have to worry about delays in messages) and a thread for my block handler. All I then just do is call a function and the block handler will do the rest.

Offline

#8 2017-10-01 13:06:06, last edited by LukeM (2017-10-01 13:06:37)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Parallel running fucntions

Vinyl Melody wrote:

Screams Async in the background

It really depends what youre using it for, if it was a shift like world, you should probably use async as youd want to have a callback once it had finished placing, and wouldnt need mutliple things being placed at once, but if it was something where, for example commands could place structures, that wouldnt work very well, as you could have multiple placement loops at the same time, which would lead to an inconsistant placement speed, plus iirc async is for things that would need a callback, which it wouldnt

Offline

#9 2017-10-01 22:29:31

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Parallel running fucntions

destroyer123 wrote:

you should probably use async as youd want to have a callback once it had finished placing

I personally provide an optional "onComplete" Action parameter to my block handler. Just push in a method or an () => { anonymous.Method(); } and you got your callback.

Offline

#10 2017-10-01 23:31:03

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Parallel running fucntions

den3107 wrote:
destroyer123 wrote:

you should probably use async as youd want to have a callback once it had finished placing

I personally provide an optional "onComplete" Action parameter to my block handler. Just push in a method or an () => { anonymous.Method(); } and you got your callback.

You definately can do it that way, but IMO its neater to use async / await, as then all your code is all at one 'level', and is run from top to bottom

Offline

LukeM1506897063679098

Board footer

Powered by FluxBB

[ Started around 1732694369.6135 - Generated in 0.231 seconds, 12 queries executed - Memory usage: 1.51 MiB (Peak: 1.66 MiB) ]