Infinite level generation?

So I’m thinking of creating infinite map generation in my game.
The problem is, I cannot solve some problems :smiley:

Ok first of all I’m able to generate 2d array of tiles to my liking, and I could do that infinitely, probably. What I don’t know how to do is generate objects on the map based on the seed. I can just use Random or something to randomly generate objects, but that isn’t what I want. I want generated map to always be the same when same seed is specified.

Let me explain why I want this.
Here is how I’m thinking of doing infinite terrain.

  • Generate infinite terrain for the first time. Keep track of the seed used to generate the terrain.
  • Player changes certain tiles/entities in the world. Keep track of what the player has done.
  • When saving, only save what the player changed in the world.
  • After loading, generate terrain from same seed again, and apply changes that player previously made.

So this is really a “big” question, but the first thing I need to figure out is how to generate object/entities based on specific seed. I probably should use some kind of PRNG like XorShirt or something like that.

PS

Anybody knows how Minecraft stores/loads terrain?

If you use the same seed you will get the same terrain. Why is this not working for you? Make sure to create and use a separate and specific Random object for terrain creation.

The map data should hold entity spawn points too - not only terrain data.

PS
In chunks.

Ok look here for a moment. Lets say I have this PRNG.


private static class xor {

		private long last;

		public xor(long seed) {
			last = seed;
		}
		
		public xor() {
			this(System.currentTimeMillis());
		}

		public int nextInt(int max) {
			long rand = last;

			rand ^= (rand << 21);
			rand ^= (rand >>> 35);
			rand ^= (rand << 4);

			last = rand;

			rand = (rand < 0 ? -rand : rand) % max;
			return (int) rand;
		}
		
		public int nextInt(int max, long seed) {
			long rand = seed;

			rand ^= (rand << 21);
			rand ^= (rand >>> 35);
			rand ^= (rand << 4);

			last = rand;

			rand = (rand < 0 ? -rand : rand) % max;
			return (int) rand;
		}
		

	}

Basically returns a value based on seed and caps it to “max”.

Lets say I have tile “x = 241, y = 65”
How would I calculate seed value based on level seed(base seed which never changes) and x,y values?

I really suck at such math :smiley: Almost first time using it.

EDIT---------

Ow I think I know how.
Need to do this:

long seed = 107759511739861197l ^ ((x<<5)+(y<<3) + 1);

that long is basically level seed or something that never changes.

… what!?

PS @Riven: is the “quoting” over 90% of the posts really a relevant issue?

Filler image:
http://192.227.234.154:40000/.ico

I hate the 90% thingy too…
I solved my problem already… under EDIT----

Well, good for you. Still makes no sense, though.

This is exactly like noise. Choose some size, take a predefined coordinate of that square (say lower-left), create a hashing value from the coordinate and that’s your seed.

Just to make this clear to anyone, the java.util.Random object has a constructer that accepts a seed and will produce the same values every time when using the same seed. It is exactly what you want and 100% reproduceable when running exactly the same procedure.

In cases where you have for some reason no reproduceable random generator, you might consider to genereate 100 or more random values and store them. Running through the same list of values over and over may be random enough for many cases and all you need to store is 100 or 200 or somewhat integers.

But generally, stick with the Random class and give it a seed.

-JAW

(sorry for off-topic)

Where the heck did you get those awesome sprites? Can I have the icon set? Could you share it? Can I use it for non-commercial stuff? Is it even yours?

Can I rip them myself? ;D

I have no idea. It’s been on my HD for almost 2 years. They’re not mine. It’s a huge icon set called “bigset.png”. Most likely ripped from multiple games.

~5MB in size - one huge sprite sheet [384x15096]
[link1] http://www28.speedyshare.com/32XEu/download/bigset.png
[link2] http://www.sendspace.com/file/i7doy2

WHAAAT
THEEE

… thank you :slight_smile:

90% quote stuff … :confused:

Filler image:
http://192.227.234.154:40000/.ico

EDIT: Couldn’t recognize everything but I saw some Guild Wars Skill images on the bottom. Seems like it might not be too safe to use it :confused: thanks anyways. Might be helpful for prototyping! :slight_smile:

Thanks for these, thats alot of assets!
Definetly cool for placeholders, or whatever.