Procedural Game Engine

Started by
8 comments, last by nfries88 8 years, 1 month ago

i am doing a 3d game engine (c++ programming) based in a world of portals. Each one have different space concepts, for example, different gravity constant, material types, pressure constant.. And each one of those space concepts have different planets (Size, Format, Materials, Density, Orbit...) So i have to make a algorithm to generate different algorithms to finally generate each planet. I am beginner in this area and i don't know how it is done. Is it a random with a pattern algorithm used? Or just a mathematical form?

Advertisement
There are too many different methods, and most of them are still unknown smile.png

I like this book: Texturing & Modeling: A Procedural Approach
Easy to understand, covers a lot of basics (e.g. Perlin Noise) and i found many useful and controlable techniques there.

Here is a webpage covering any related stuff from fractals to cellular automata...:
https://softologyblog.wordpress.com/


for example, different gravity constant, material types, pressure constant.. And each one of those space concepts have different planets (Size, Format, Materials, Density, Orbit...)

for realistic results you'd do it the way it works in real life.

gravity is a function of mass

mass is function of how much material coalesced to form the planet, and its average density.

atmospheric composition is a function of the types of materials that formed the planet.

atmospheric pressure is a function of gravity and atmospheric composition (i think - been a while since chem class).

size is a function of amount of material, and its density. density and quantity determine mass, which determines gravity, combined with compressability of the materials gives you how small it shrinks due to its own gravity, and thus its size.

orbit is simply the distance the material that became the planet happened to be from the sun.

lookup how planets are formed for a better description of all of the above.

once you've figured out what conditions make what kind of planets, you can simply randomly generate particular types of planets that make sense, or you can generate the conditions and then determine what planets would form from them.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Work it down from high level to low level.

Stars explode sending new elements through space. Logically, the material needs to exist before the planet. We build a list of materials to use, with a set of unique properties. These elements clump together eventually and pull together.

Thus becoming planets. As the planets grow denser, their gravity linearly increases. As the planet grows larger, the gravity is inversely effected by the square of it's radius.

acceleration-due-to-gravity-formula.png

What effects the planet's mass is it's material. Material has a variety of weights, and to build an equation out of it to accurately model it, would be a nightmare... and would require a damn good computer. So instead we can approximate.

Generate the radius of the planet you want. The radius must be any r > 0.

with the radius, find the volume of a sphere using that exact radius.

0074.png

Now for all elements/materials that you have for your world, you want to generate a list of properties for them. The most specific one here would be density. Which is a function of mass divided by volume.

For each element that can be found on the planet, or what makes up the planet, choose some percentage of the planet's volume greater than zero, and assign it to that element.


Multiply that percentage of the planets volume by the density of the material. This will give you mass. Once all materials have been calculated, sum up the mass, and that will give you the planet's gravity.

On a side note... to look physically accurate. Larger planets will have stronger gravitational pulls than smaller planets logically. They have enough mass to hold themselves together. That will make sense to the players. buuut... mathematically, that's not true.

Thx for all those great answers. I am just in doubt about the generate which allow the objects to stay ever in the same place as the last generation without saving them on memory. I call it a "known random". But i have't any idea how it works.


I am just in doubt about the generate which allow the objects to stay ever in the same place as the last generation without saving them on memory.

you're in doubt about how to generate things so objects always stay in the same place every time, without having to save them in ram - correct?

possible approaches:

1. go ahead and save it in ram. odds are it will all fit ok.

2. use a known seed value for your random number generator, and known order for the variables generated. to generate a given object, call your rand function once for each variable of each object that gets generated before the one your interested in, then generate the object as usual. example: each object has say 5 random variables, and you want to generate object #4. seed your rand with your known value, call rand 3x5=15 times, then call it five times to get the five random variables for object #4.

3. use a known seed value to seed rand. call rand once for each object to generate a seed value for that object, store it with the object. when you want to generate an object, use its seed. then call rand to generate its variables.

note that only stars should be stationary. planets and moons should have orbit radii and orbit periods, which combined with the game clock will let you calculate their position at any given time.

.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

If you mean to not save it in ram... that's not possible.

If you mean to not save it to disk, then different story. The keyword is "Procedural" in procedural generation. As long as the initial seed was the same, then everything else will be the same.

The problem comes for when you want the world to be edited.

I i see!


srand (seed_number);
number = rand()%100;

That function can give always the same number order even if in different computers right? I thought it was relative to each computer state.

The problem comes for when you want the world to be edited.

I thought that situation too. I have to memorize those specific modifications. Like: (1 - generate all planet positions, 2 - Check on the "server buffer of modifications" which modifications match with the actual universe. 3 - Change their orbit equation.) Or can it be more complicated than that?

which combined with the game clock will let you calculate their position at any given time

I have an algorithm problem about that. How it will be a multiplayer engine i have to analyze the problem from another side.

I have some possibilities to make it:

I can pass the clock from the server to all the clients. (Good for velocity but it depends on a equation)

I can calculate all the planet positions on the server and pass them for the clients, but it's extremely heavy on server. (More dynamic without depending on a equation)

I can choose the host in each universe, what can make the "worker client" heavier and increase the lagg. (It's dynamic too but if the client fail hard, the universe can be bugged)

So i am stacked without any more ideas.

Thx.

you'll never have to draw more than say 4-5 stars/moons/planets around any given player. the distances between stuff are just to big to ever have more than a handful in "visual range". so you might be able to do it server side.

what to do on the server vs client is a whole different issue from how to generate the planet specs.on the fly as needed from a seed.

a good place to start is with a list of what the server need to know from the client and a list of what the client need to know from the server.

then you think of how that info could be transmitted in as few bytes as possible. often its possible to send just a little data and let the receiver calculate what they need from it. other times the calculations are too much (IE trying to do everything on the server, and its just too much).

a question posted in the networking forum should get you further along on that issue.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

I i see!

srand (seed_number);
number = rand()%100;

That function can give always the same number order even if in different computers right? I thought it was relative to each computer state.

Actually, no. Linux will give a different result than Windows, because they implement rand() differently. Best bet is to use a specific random number generator of your own choosing.
Also, since the output of a random number generator is usually a 32-bit integer, there are various ways to process it. Good random number generators are usually slow random number generators, so you want to minimize the number of times you call it. For example, you can split the 32-bit result into:
bit 0..1: number of stars (max 3)
bit 2..4: number of planets (max 8)
bit 5..7: which planet (ordered by distance from star) is most dense
bit 8: whether or not system has an astroid belt
etc.
You can keep using this technique right down to, say, generating rough information about alien races. smile.png


I can pass the clock from the server to all the clients. (Good for velocity but it depends on a equation)

I can calculate all the planet positions on the server and pass them for the clients, but it's extremely heavy on server. (More dynamic without depending on a equation)

I can choose the host in each universe, what can make the "worker client" heavier and increase the lagg. (It's dynamic too but if the client fail hard, the universe can be bugged)


1: Server should maintain the clock. Always a good idea.
2: Unless you're going to move the planets on an extremely accelerated rate (IE minutes are years) or make them very close together (compressing the system), planetary movement shouldn't be a major issue, even for several galaxies. Just move them in a straight line most of the time, updating each one's direction every 1/1000th of an orbit or so. If someone's patient enough to track them, it might look a little rough, but I highly doubt any normal player would notice.
3) If you do #2, it's also only necessary to send the players the position of the planet once, and then just tell them its new direction whenever it changes.

This topic is closed to new replies.

Advertisement