Latest wind related commit

Latest wind related commit

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Latest wind related commit

Post by Rafal99 »

This is about commit https://github.com/spring/spring/commit ... 1a7e4a6e7a

I may have misunderstood the code but it seems to me that the new way of generating wind direction and power is very strange or even simply wrong and changes dramatically how wind works ingame.

With the old formula the wind power generated was uniformly distributed between minWind nad maxWind.

Now with the new formula I see a few issues:

Code: Select all

do {
 newWind.x -= (gs->randFloat() - 0.5f) * maxWind;
 newWind.z -= (gs->randFloat() - 0.5f) * maxWind;
  len = newWind.Length();
} while (len == 0.f);
So newWind.x and .z are in range [-0.5*maxWind, 0.5*maxWind].
There seems to be "*2" missing in the formula.

Now the length generated is NOT in range of [minWind, maxWind] which I assume it should be, but instead it is in range [0, maxWind*sqrt(2)].

Now look at the code below:

Code: Select all

len = Clamp(len, minWind, maxWind);
The length which was in range [0, maxWind*sqrt(2)] is clamped to [minWind, maxWind] which means a lot of the values will land on the bounds and the wind power will be either min or max most of the time.

This all seems quite wrong to me and I figured that is probably unintented so I decided to post this.
This is quite a huge issue since it may affect balance of mods with wind focused economy quite a lot.
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Latest wind related commit

Post by SirMaverick »

Rafal99 wrote:

Code: Select all

do {
 newWind.x -= (gs->randFloat() - 0.5f) * maxWind;
 newWind.z -= (gs->randFloat() - 0.5f) * maxWind;
  len = newWind.Length();
} while (len == 0.f);
So newWind.x and .z are in range [-0.5*maxWind, 0.5*maxWind].
No, the wind change is in that range. It's added to the old value.
Now look at the code below:

Code: Select all

len = Clamp(len, minWind, maxWind);
The length which was in range [0, maxWind*sqrt(2)] is clamped to [minWind, maxWind] which means a lot of the values will land on the bounds and the wind power will be either min or max most of the time.
It's more probable to be at the edges. But not most of the time.
e.g. upper bound: If you get out of bound in one step you get clamped to maxWind. Next time it's 50% chance you either stay there or wind gets lower.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Latest wind related commit

Post by hoijui »

so what does this change really do?
is it:?
So far, a new wind was a random value between min and max. Since that change, it is a slight change from the old value, so wind is gradually changing, instead of jumping around?
User avatar
Rafal99
Posts: 162
Joined: 14 Jan 2006, 04:09

Re: Latest wind related commit

Post by Rafal99 »

Heh, I looked at the code so many times but didn't notice there are -= there not = ...

So the code seems quite correct. Still at the case when difference between minWind and maxWind is relatively small it will stay at the edges mostly.
But in such case the difference is small as mentioned so it won't be noticable much anyway.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Latest wind related commit

Post by jK »

hoijui wrote:So far, a new wind was a random value between min and max. Since that change, it is a slight change from the old value, so wind is gradually changing, instead of jumping around?
Yeah, it now changes less rapidly.
I also increased the update rate from each 30sec to 15sec.
Also the interpolation between old and new wind is now done on the vector and not independtly between angel & strength. So it can now be in illegal ranges (<minWind), making it look much more natural when changing between two extremes.

SirMaverick wrote:It's more probable to be at the edges. But not most of the time.
e.g. upper bound: If you get out of bound in one step you get clamped to maxWind. Next time it's 50% chance you either stay there or wind gets lower.
Also true. It got now a marginal higher chance to be in the upper range bounds, but not that it would have any real influence AFAIK.
Post Reply

Return to “Engine”