Reversing a procedural generation

Started by
30 comments, last by Aardvajk 10 years, 1 month ago
You can also use a more straight-forward compression library, without the hack of going through an image. Start with something like zlib.
Advertisement

You certainly can store your data in an image format, and may see some benefit from that format's compression -- because image formats are designed with images in mind, your non-image data may not get an optimal benefit from that compression -- you could get better compression with something designed specifically for the type of data you're storing.

- Jason Astle-Adams

Voxel world chunks do tend to end up very image-like, though, enough so that schemes such as RLE can achieve pretty significant compression. The caveat, of course, is that the more types of blocks you include, and the more widespread and scattered the types are throughout the world, the less effective RLE will be. You wouldn't want to actually use an image compression library (they're optimized for the 2D case, usually) but you can look to them for ideas.

Álvaro, the zlib link takes me to the first post in this thread biggrin.png

Álvaro, the zlib link takes me to the first post in this thread biggrin.png

Just google zlib. It's pretty well-known.

This is a SUPER SIMPLE random number generator:


int RNSeed=12345;
int randomnum(void){
	RNSeed=abs(RNSeed*8786545643)%987654321;
	return RNSeed;
}

With this initial seed, the first time it's called it results in 770159010, and the second time it results in 808599291.

This will happen EVERY time I start with 12345. The problem with reversing the calculation is the modulus of 987654321. Any seed value greater than that number will be some value that can't be found and therefore the previous seed us unknown. The solution would involve a random number generator that can be reversed-- I don't know how to make that (or if it can be made at all).

All of you are either think I don't know how random generators work or you are missing my point entirely.

The modulus IS the problem with the whole thing... It means that you have lost some piece of the information. You can go one way, you can even go back, BUT which of the UNLIMITED number of combinations is the right one? Oh shoot! You can't go back anyway...

You will need a change patch log system to record all the subsequent changes for the direct and indirect object your procedural system will initially create. The changes get added ontop of the procedurally generated initial data set whenever the area is rebuilt.

Some changes will be trivial and not need to be added to the patch log. (like bullet hole decals that the elves come and cleanup while player isnt watching)

Some changes may themselves be a 'procedural' generation (ie- a pattern a fire event spreads) and alot of 'sub' detail might be expressed in only a small amount of patch data.

Some changes may 'heal' over time (possibly since some player last saw it) and be able to eventually be removed from the patch log (reverting the change back to the initial generation state)

Some dynamic changes created 'on the fly' to match a game situation may be regrouped/nullified and regenerated newly when the area is rebuilt (matching a newer game situation).

Sometimes its possible (depending on game mechanics) to have catastrophic events periodicly overwhelm a location and wipe clean/consume more than a few accumulated changes.

Many times a procedural generation cycle is based on more than just a random number and additional information used in activating its 'subprocedures' will also have to be saved.

Sometimes there are 'in the area' significant objects whichhave been custom built (with too many variable attributes and states) and they have to be preserved with much greater detail saved.

Some world systems mutate (faction entities with spheres of influence move around, or seasonal variations) and areas can rebuild somewhat differently and any change log data may have to be checked/arbitrated if their are dependencies that cause them to mutate (or become irrelevant)

--------------------------------------------[size="1"]Ratings are Opinion, not Fact

This is a SUPER SIMPLE random number generator:
//...snip...

With this initial seed, the first time it's called it results in 770159010, and the second time it results in 808599291.
This will happen EVERY time I start with 12345. The problem with reversing the calculation is the modulus of 987654321. Any seed value greater than that number will be some value that can't be found and therefore the previous seed us unknown. The solution would involve a random number generator that can be reversed-- I don't know how to make that (or if it can be made at all).


Maybe I'm misunderstanding your original question, but I thought you were wanting to reverse player actions, and the effects of a complex system being fed with input data that comes from player actions.

Players aren't random number generators. You can't reverse player actions backwards, because you can't predict player actions forward. Instead, you save the result of those actions (the current game state) or save the actions themselves (like undo/redo frameworks), and re-apply them later.

"This process could be very useful in games that have a huge amount of "object states". Like a planet with mineral deposits. If the player collects a certain amount of them, it would be silly for the player to be able to come back to the planet and get those deposits again. And saving the state of each mineral deposit on every planet in every solar system would be crazy!"

Every object state is either generated solely by the simulation (procedural generation, later simulations that aren't affected by the game world, ...), prefabricated by the developer (manually made maps and game events, even some of the pre-written code and scripts), resulting from direct player actions (my character has blue eyes, I choose to mine this ore deposit), or affected by the complex simulation that is fed input from player actions, the passage of time, and other inputs (Enemy223 lobs a grenade in direction XYZ at Ally17 because the player told Ally17 to guard the mobile Entity452 which wandered in that direction because it needs sunlight for power and the weather simulation was cloudy at that point in time).

The isolated simulations (procedural generation, and self-contained non-influenced simulations like weather systems) can be re-simulated.
The prefabricated data must be reloaded, and cannot be generated (though theoretically you could use really good compression and pattern-matching to semi-generate parts of it, or maybe even to lossy-generate the whole imperfectly).
The player actions must be saved and re-applied or else the result of those actions (just the states you care about).
The complex whole simulation cannot be re-ran, unless the above three areas are also precisely reran (with recorded player actions, not just recorded results).

The main reason I started this post was to flesh out an idea to limit save game data for a huge scale game. I think I would like to have a "player profile" instead of a save game. I would create a seperate file for each solar system (or something like that) and save it with some standard convention within the player profile folder.....

I think this might actually be possible without having to save a bunch of states for the window. What you need is some kind of "random.previous" function (as opposed to the traditional "random.next" function found in most languages). However as far as I know no programming language supports this. I would recommend programming your own PRNG from scratch for this task. Assign each window it's own random class and once it needs to be put back together just throw the PRNG in reverse.

This topic is closed to new replies.

Advertisement