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 2015-04-15 12:41:35

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

async await | Block placement and block check

How can i achieve this seamlessly? :3


Ug3JzgO.png

Offline

#2 2015-04-15 12:47:26

Hexagon
Member
Joined: 2015-04-22
Posts: 1,213

Re: async await | Block placement and block check

Do you want to await for a block to be written, and then execute another method (avoiding an opaque delay?) Processor has a nice solution which essentially reads incoming messages and if the current (bot) user id receives a block that they sent, it will send another block. I don't think this uses await though.

However, you might be able to increase the throughput by a factor of two because that method does not factor in round trip time. So, you could use his method but somehow determine the average time your message comes back, divide it by two then use an opaque delay to send blocks thereafter.

Offline

#3 2015-04-15 15:10:42

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: async await | Block placement and block check

As Hexagon pointed out, BotBits has an implementation that might fit your needs.

BotBits was made to be used with GUIs and contains a lot of features to make sure your GUI never freezes.

Here is a BotBits example.

Blocks
    .Of(bot)
    .Set(Foreground.Basic.Red) // Fill the world with red blocks

await PlaceSendMessage
    .Of(bot)
    .FinishQueueAsync(); // Wait until we've sent everything to the server

await BlockChecker
    .Of(bot)
    .FinishChecksAsync(); // Wait until everything is placed

I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

Wooted by:

#4 2015-04-15 15:20:00, last edited by DarkDragon4900 (2015-04-15 15:20:26)

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: async await | Block placement and block check

struct Block{public int Layer, X, Y, Id;}
List<Block> blocks = new List<Block>();
//...
// case b (after adding to (Dictionary<Block>)blocks)
while (blocks.Count > 0)
        Place(blocks);
//...
if (blocks.Contains(new Block{Layer = e.GetInt(0), X = e.GetInt(1), Y = e.GetInt(2), Id = e.GetInt(3)})
        {
                blocks.Remove(new Block{Layer = e.GetInt(0), X = e.GetInt(1), Y = e.GetInt(2), Id = e.GetInt(3)});
        }
//end of case b
//...
async void Place(List<Block> blocks, Connection con, int delay)
        {
            foreach (Block block in blocks)
            {
                con.Send(wKey, block.Layer, block.X, block.Y, block.Id);
                await Task.Delay(delay);
            }
        }

Adjust as needed.

[Edit] Could probably want to use BotBits, too.

Offline

#5 2015-04-15 15:41:18, last edited by TiKen (2015-04-15 17:10:12)

TiKen
Member
Joined: 2015-02-24
Posts: 298

Re: async await | Block placement and block check

Depending on you conditions you have two ways of doing that. Since the map are not so big, and computers now are powerful enough, I'll disregard the memory consumption as a condition.

1) You want to send a list of ordered block (you can only send a block if the previous is on the map): then you'll use the method described by hexagon: send nex block when you received the confirmation the first one was sent. If the block is none received after a short time, send it again and restart the timer.

2) You don't really care about the order: Send all your blocks with a fixed optimum delay between each and using an async. worker. Every time you received a confirmation a block as been place, tag a 2D boolean array. When the async. worker is done, check if there is some block missing (using that 2D Bool array) and send them again throught the async. worker. Etcaetera etcaetera until all the block have been sent.


Edit: I took to long to write this post XD

Offline

#6 2015-04-15 17:02:27, last edited by goeyfun (2015-04-15 17:03:00)

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

Re: async await | Block placement and block check

wow BotBit is lengendary, thanks so much for everyone's answer


Ug3JzgO.png

Offline

goeyfun1429113747495089

Board footer

Powered by FluxBB

[ Started around 1732812414.8021 - Generated in 0.085 seconds, 12 queries executed - Memory usage: 1.44 MiB (Peak: 1.55 MiB) ]