Jump to content

Recommended Posts

Posted

In one of my projects, I have a simple procedurally generating dungeon algorithm which generates the mod's dungeons. I've recently decided to rewrite to be more complex and accommodate more features than before. Before I do this though, I wanted to generate it in a way that it won't cause cascading world generation, which the current algorithm doesn't prevent. Right now it works kind of like this: I'll generate a structure on the surface somewhere, which will spawn staircases underneath it. From there, rooms can branch off of these staircases, and each room can generate new rooms off of it and so on until it reaches the maximum amount of "tries". This is done through recursion which is simple enough to do.

 

So I've been trying to come up with a way to prevent the cascading generation from happening because it's not as simple as just adding an offset. I won't know how many chunks the dungeon will take up until after I generate it. I'm wondering about what the easiest solution to this would be. Could I generate all of the parts of the structure that are in loaded chunks only and then generate the others once those chunks have been loaded? I think that's the fundamental solution but how would you go about knowing/storing where a structure should be, and then generating that structure when the chunk is loaded? Maybe this isn't entirely right and there is another way around it, I'm not sure. Anyways, any help on solving this issue would be much appreciated.

Developer of Levels and Lost Eclipse

Posted

In theory, when an event is fired to which your generator is subscribed to, you should be able to get chunk's X an Y. Then while you generate the structure, you have to continuously check whether the next generated block will trigger generation of new chunk. If the blockpos is within current chunk, proceed generation; if not, then store this blockpos and maybe chunkpos in a map, perhaps. Then on next event you check whether the new chunkpos corresponds to any of the stored chunk positions and proceed generation if it does.

You can also find a way to track current chunkpos of player and based on it, pick chunks from the loaded ones and do your thing more safely - still, will have to start checking once the chunk positions are close to the border.

Posted (edited)
3 hours ago, Alexiy said:

In theory, when an event is fired to which your generator is subscribed to, you should be able to get chunk's X an Y. Then while you generate the structure, you have to continuously check whether the next generated block will trigger generation of new chunk.

Actually....

You want [inside the current chunk] + (8,8)

Due to the way Minecraft generates chunks, you want to always offset by 8 blocks in the positive X and positive Z directions. The next chunk in that direction are guaranteed to already exist. 

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I don't think that's the best solution, at least in terms of what I'm trying to do.

 

I've been digging around in vanilla world generation (Stronghold/Village generation) to figure out how they generate structures without causing runaway chunk generation. It looks like vanilla generation (say a Stronghold) will generate the positions of the Stronghold and store them somehow (MapGenStronghold#generatePositions looks like it does this, but I don't see how this works fully). Somehow the Stronghold's StructureStart gets a list of components to be generated and builds them out. Anyways, I think my conclusion is vanilla world generation is a mess and is hard to trace and track down how everything works.

 

As for how to fix this, I'm thinking the easiest thing is to generate a "virtual" dungeon through the algorithm, but not to build anything during this time and storing each structure in a map. Then I would generate it when chunks are loaded and everything is ok for it to generate. The problem is, how would I go about generating it this way? Is it even possible?

Developer of Levels and Lost Eclipse

Posted

Potential solution: When I go to generate the dungeon, instead of building each individual room during generation, I'm thinking I can just generate the positions of each individual structure and store the position and template into a map. If the bounding box of the structure intersects with the current chunk (which has an offset), generate the corresponding room. If it's outside of the currently generated chunks, it won't generate. As new chunks are generated through the WorldGenerator, I'm thinking about looping through all the pending structures, checking to see if the bounding box of the structure intersects with the current chunk and if it does, generate it and remove it from the map.

 

I'm not sure if this will work properly, so if anyone happens to find a flaw in it, I'd like to hear it before I try and implement it. If it sounds good, I'll work on implementing it.

Developer of Levels and Lost Eclipse

Posted

Have you looked at mineshaft code? Might give some hints, too.

It's kind of difficult to abstractly imagine how your algorithm would work, so just do it and we'll see how it goes.

Posted (edited)
7 hours ago, Alexiy said:

Have you looked at mineshaft code? Might give some hints, too.

It's kind of difficult to abstractly imagine how your algorithm would work, so just do it and we'll see how it goes.

Well it is pretty easy actually. You do everything the algorithm normally would but you don't place any blocks and you store the position and individual structure into a map or whatever. Whenever new chunks are generated, you check to see if your positions of the structures are in it and you generate if so.

 

Seems to make since to me, so I'll try and implement this soon.

 

I think Minecraft does this by checking if a given structure is inside of the bounding box of the chunk, and if so, it generates. So that's the kinda check you would need.

Edited by TheXFactor117

Developer of Levels and Lost Eclipse

Posted

If you don't mind having your world depend on the order of player exploration, then you could limit your code to generating only one complex at any given time (e.g. use a static field in one of your classes as a latch). Initialize it to "ready",  then check it before starting one of these structures. if "busy", then exit without starting a new complex. If "ready", then set it to "busy" and commence generation. Do the whole structure, loading as many chunks as it needs; any further would-be structures triggered would be suppressed by the field being set to "busy". When done, clear the field back to "ready".

 

Of course, if you're willing to do the work to map overlapping structures, then that's probably better (and repeatable).

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I think it would be easier to do what what I mentioned above, considering these structures should be fairly common. I'm going to try and implement it and see what kind of results I get. I need to finish re-writing portions of it first, however.

Developer of Levels and Lost Eclipse

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.