Large processing of blocks

Discussion in 'Plugin Development' started by NoLiver92, Jun 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    NoLiver92

    I am trying to make a plugin which places blocks in certain ways (cant go into specifics) the way im doing this is having a block list and using a runnable to place these blocks, synchronous repeating task, I have 2 issues here, firstly what im currently doing gives the client a black screen when they trigger the event. the second issue i have is i can only run one of these runnables at a time.

    the runnables are in a separate class and are called when certain events are fired but if more then one event is triggered only one happens at a time. i want to get it so 2 or more are running at the same time.

    Is someone able to help me with this? i can provide more info as needed.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    NoLiver92

    ok i think i understand that but is the synchronous task right or is asynchronous better?

    also what about the client crashes?
     
  4. Offline

    timtower Administrator Administrator Moderator

    I am not sure about that, and how many blocks do you change? There is an possibility that the server stop sending things by the amount of blocks that are changed
     
  5. Offline

    skore87


    The world isn't thread safe. That means async isn't an option for your scenario. Your best bet to prevent people from crashing is to split up the work into multiple pieces and have a delay between them.

    One such way would be to have an entire array of the changes you want to make and send it into a delayed task. That task would then process X amount of it and then schedule a new copy of itself with a subarray starting at X after a determined period of acceptable delay.

    The idea behind that is to buffer your changes so that the server doesn't get stressed to the point that clients disconnect.
     
  6. Offline

    NoLiver92

    skore87
    ok thanks, at the moment i have a list of blocks to change and i change one every second. I like your idea but will this allow simultaneous placing of blocks in different locations?

    The plugin works a bit like this: a player clicks the ground with an item and from that the blocks spawn to make a tower (stalagmite) of blocks depending on where they are in the world depends on what blocks these towers are made of. I dont want the players to have to wait 10 seconds for it to be built, i want to make it so it places 10 blocks a second so it simulates it shooting out of the ground like a spear. The players rank will determine how big the tower is so the number of blocks changes.

    this is what im having trouble with when 2 players do it at the same time one has to wait until the other is finished which gives a delay. i need to do it as and when it was fired..

    timtower that all depends on where the player is in the world, it could be from 10 to 100 odd. im not sure about the server stops sending as only some of the people connected crash and some dont.
     
  7. Offline

    timtower Administrator Administrator Moderator

    Those numbers are not big enough to cause an crash...
     
  8. Offline

    NoLiver92

    well something to do with the runnable is causing a crash in the client, i know the numbers are small but something is still causing it.

    without the runnable and this code, there are no crashes
     
  9. Offline

    timtower Administrator Administrator Moderator

    Try using to run the runnable the other way, maybe it will fix the issue
     
  10. Offline

    skore87

    Yeah you can do several thousand blocks per second before you experience any slows. Check to make sure you're not trying to modify the world on an async task. Otherwise you'll need to take a closer look at the exceptions being thrown.
     
  11. Offline

    NoLiver92

    what other way?

    I believe the runnable works fine but the code for placing blocks in the runnable is causing the problem as i havd just tested the runnable code on another project im doing and there are no problems

    Ok thanks, its is sync, i think it is something to do with my code with the blocks and the way i execute it. that can be the only explanation as i use the same runnable code in a different project with a different use and it works.

    can sync taks run at the same time or do you have to do something fancy?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  12. Offline

    skore87

    You can run as many as you want synchronous as they are executed in order on the main thread. Without knowing the error we can't really give much else for advice.
     
  13. Offline

    NoLiver92

    are you saying i can only do one sync task at any one time? so if 2 events fired, then the first is executed then the second?
     
  14. Offline

    skore87

    It's impossible for two SYNCHRONOUS tasks to execute at the same time. Take a moment to learn the difference between synchronous and asynchronous threads. :eek:

    When you schedule more than one sync task they just get executed in the order received.
     
  15. Offline

    frymaster


    The whole point of a sync task is it's run on the main simulation thread. There's only one of that, so only one thing happens at a time. You can have two tasks set to execute in the same tick, and they'll both happen before the next tick (so from a simulation perspective I suppose you could say they happen "at the same time"), but one will be executed and complete before the second one gets called.
     
  16. Offline

    NoLiver92

    ok, so i am going to have to do something fancy, thanks
     
  17. Offline

    skore87


    No, lol... We're saying that you can call as many sync tasks as you like and they will appear to be "at the same time" of each other. Can you at least tell us what the exception is or are you content with your broken, secretive, plugin?
     
  18. Offline

    NoLiver92

    there is no exception it runs but crashes the client. with this i am wanting to do two things the towers mentioned earlier and the other is getting all the blocks above an explosion and turning them into fallingblocks (thus making everything like sand so there cant be any overhangs)

    so when 2 explosions happen just after each other it turns the blocks to falling blocks where the 1st explosion happens and when thats finished the 2nd explosion falling block effect starts.

    this was doing the method you suggested calling them when the event fires and hold them in a list
     
  19. Offline

    skore87

    I have a hunch that the crash (and yes even the client will give the exception) is due to it not rendering the falling block. I had this happen to me recently because I decided to toy with some numbers on my plugin that uses FallingBlock. Just out of curiousity, how many of these entities are you creating?

    Oh and just holding it in a list isn't enough. I mentioned an array so that you only process a portion of the whole task at a time to alleviate issues like this one.
     
  20. Offline

    LucasEmanuel

    You can use dhtutils to set a large amount of blocks at a very high rate.
     
  21. Offline

    NoLiver92

    ahhh it was doing 10 a second so that is probably the reason why. is there any way to prevent this and still keep it working at the same speed?

    ok and how do i use it? is there a tutorial?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  22. Offline

    skore87


    There is no way that 10 block/s is going to cause a crash. That is a tiny amount of blocks to change so something else is going on here that you're not telling us. I still think you're using asynchronous repeating/delayed tasks.
     
  23. Offline

    NoLiver92

    i said from 10 to hundreds, when i tested it i had 150 blocks in the array in the runnable. and i am using sync
     
Thread Status:
Not open for further replies.

Share This Page