Jump to content

Recommended Posts

Posted

I have a structure generator that is invoked when a tile entity reaches a certain state. This structure generator simply reads a text file and places blocks accordingly. But as mentioned in another thread on the topic, I'm generating this very high up (in the clouds) and it turns out that the lighting updated during the setBlock make a high structure much slower to generate than a lower structure. Anyway, the point is that it takes about 20 seconds to generate the structure.

 

The thing that puzzles me though is that it doesn't create any lag in the actual game. The structure takes 20 seconds to appear, but there is no lag (other gameplay is smooth) while it is generating. But this seems odd because I'm doing the structure generation from the update method of a tile entity, and the structure gen is just a big nested loop, so I would think that whatever thread called the tile entity update method would get held up until it completed the generation.

 

So I'm wondering whether the server is actually hung up during the generation and the client is continuing to make the game play seem to work, or is the server sufficiently threaded that the call to the tile entity is isolated from the other code the server is executing?

 

Basically it just seems odd to me that putting code that takes 20 seconds to loop through isn't causing the server to have trouble doing the rest of what it needs to do.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

You said it reads a text file to place the blocks, maybe the way you read the file is slower thus causing it to take longer to generate?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I don't know, but one way to find out would be to print to your logger during the world tick event - you will see how many server vs. client ticks appear while generating your structure, and then you will know if the client is continuing along on its dandy way whilst the server is entangled in your structure gen's for loops.

Posted
  On 4/30/2015 at 4:09 AM, coolAlias said:

I don't know, but one way to find out would be to print to your logger during the world tick event - you will see how many server vs. client ticks appear while generating your structure, and then you will know if the client is continuing along on its dandy way whilst the server is entangled in your structure gen's for loops.

 

Okay, yeah I did that and it definitely seems that the server is held up while the client is continuing. Here's the log starting a few ticks before the generation starts:

 

  Reveal hidden contents

 

 

You can see that at the beginning on average it is doing same number client and server ticks. Then you can see the generation starts and then there are only client ticks. I then stopped the game and then a whole bunch of server messages came through.

 

So yep, just like I thought, I'm hanging the server.

 

I had previously broken up the structure to just do a few blocks per tick, so I'll try to go back to that.

 

Ultimately, I've really got to figure out a way to create an alternative setBlock() that doesn't regenerate lighting after every placement. I almost got it working by trying to edit the chunk storage directly and it was literally 100 times faster...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 4/30/2015 at 4:04 AM, HappyKiller1O1 said:

You said it reads a text file to place the blocks, maybe the way you read the file is slower thus causing it to take longer to generate?

 

Thanks for the suggestion. I actually read the file into an array in advance during the mod loading, so I'm not reading from the file during the generation.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Okay -- I created my own version of set block that doesn't do the lighting updates. Basically just copied the World#setBlock() code along with the Chunk function it calls and commented out the things that recalculated lighting.

 

The time to generate went down from 22 seconds to 74 milliseconds!!! Pretty much instantaneous.

 

If you're interested, here is the code (1.7.10 version) as I currently have it. I renamed a few parameters to make it more readable, and will probably go through and rename some more, but it seems to work and you can see what I commented out:

 

 

  Reveal hidden contents

 

 

Note it does have some lighting artifacts -- some areas are darker than they should be, but they fill in over time or as you move around, and it doesn't look that bad and frankly Minecraft has a lot of such visual/loading artifacts. I will still look at how i can get the lighting update after the blocks are placed...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

and here is 1.8 version of the code for those who might want to use it:

 

 

  Reveal hidden contents

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.