Page 6 of 14

Posted: Tue Apr 13, 2010 3:00 pm
by Commander McLane
Looking at the code again I notice that it defines the situations in which no Superhub shall be added. Which already means that it uses the opposite end of the pseudo-random spectrum, so the Superhubs are created in the systems with 0.5 < pseudoRandomNumber < 1 instead of the systems with pseudoRandomNumber < 0.5.

What I often do is to set an arbitrary range between 0 and 1, and if I want to add different kinds of things I set different arbitrary sets. For instance:

Code: Select all

if(system.pseudoRandomNumber >= 0.1 && system.pseudoRandomNumber < 0.6)
{
	add one kind of thing
}
if(system.pseudoRandomNumber >= 0.4 && system.pseudoRandomNumber < 0.9)
{
	add another kind of thing
}
Both kinds of things are added with a 0.5-probability, but there is only a 0.2-probability that they both will appear independently in the same system. Obviously by changing the arbitrary values you can make that more or less likely.

If you have lower probabilities for each object you can put a lot of variants in the scale between 0 and 1, and it is your choice whether two objects have a chance to appear in the same system or not.

Posted: Tue Apr 13, 2010 3:12 pm
by JensAyton
I was right – my solution was indeed broken.

Here’s a simpler solution than PhantorGoth’s (which has been properly tested and everything). It scrambles the pseudoRandomNumber by using it and an arbitrary “salt” value as the seed of a simple psuedo-random number generator. Each salt gives a different per-system random value in the same range as pseudoRandomNumber.

Code: Select all

this.scrambledPseudoRandom = function(salt)
{
    // Convert from float in [0..1) with 24 bits of precision to integer.
    var n = Math.floor(system.pseudoRandomNumber * 16777216.0);
    
    // Add salt to enable generation of different sequences.
    n += salt;
    
    // Scramble with basic LCG psuedo-random number generator.
    n = (214013 * n + 2531011) & 0xFFFFFFFF;
    n = (214013 * n + 2531011) & 0xFFFFFFFF;
    n = (214013 * n + 2531011) & 0xFFFFFFFF;
    
    // Convert from (effectively) 32-bit signed integer to float in [0..1).
    return n / 4294967296.0 + 0.5;
}
Usage:

Code: Select all

if (this.scrambledPseudoRandom(344336) < 0.5…
Obviously 344336 should be replaced with a different randomly-selected value in each context this is used.

Posted: Tue Apr 13, 2010 4:39 pm
by Thargoid
Somehow I think I'll just stick to things like system.ID for mine. This is getting a little Heath-Robinson.

Posted: Tue Apr 13, 2010 6:15 pm
by Commander McLane
Thargoid wrote:
Somehow I think I'll just stick to things like system.ID for mine. This is getting a little Heath-Robinson.
But will lead to the mentioned problems. If everybody adds their stuff in systems with system.ID < n, then all system below n will look the same and have all the stuff in them, and all systems above n will look the same and have no stuff at all in them.

Posted: Tue Apr 13, 2010 6:16 pm
by JensAyton
I strongly suggest not using system.ID or any other stable property, for the reasons already mentioned. While it took a while to get there, my last approach is tested, correct, easy to use and solves the problem.

Posted: Thu Apr 29, 2010 11:32 pm
by JazHaz
Have created a wiki page for this OXP:

http://wiki.alioth.net/index.php/Superhub

Posted: Fri Apr 30, 2010 12:00 am
by JensAyton
It’s a bad idea to put documentation inside an OXP. Mac users will not see it, and other users are likely not to look.

Posted: Fri Apr 30, 2010 7:11 pm
by pagroove
Ahruman wrote:
It’s a bad idea to put documentation inside an OXP. Mac users will not see it, and other users are likely not to look.
For all my next versions of OXP's I will put the documentation in the main .zip file. to make it also user-friendly for Apple etc.

Re: Superhub V1.2. slight update

Posted: Thu Mar 10, 2011 8:49 am
by Commander McLane
There is a small oversight in the Superhub spawning script: it doesn't check for system.isInterstellarSpace, therefore it throws an error on misjumps, because it can't find the main planet or its station.

Fix: add

Code: Select all

|| system.isInterstellarSpace
to the first if-statement.

Re: Superhub V1.2. slight update

Posted: Thu Mar 10, 2011 2:48 pm
by pagroove
Thanx,

Noted for the next update! :mrgreen:

Re: Superhub V1.2. slight update

Posted: Thu Feb 09, 2012 9:24 pm
by Switeck
Any chance Superhub can be redesigned to use smaller than the 4096x4096 texture file it currently uses?

Most of the texture appears to be black "dead space", so if it was all crammed together it looks like it'd fit in 2048x2048.

I had one Oolite crash that said it couldn't allocate 64 MB of memory for that texture alone. I attribute Superhub to be the largest contributor of the huge memory spikes I'm seeing from rapid wormhole-jumping. During rapid wormhole-jumping, the game seems to allocate memory for Superhub's massive texture file a few times over until garbage collection can "catch up".
Were the texture reduced to 2048x2048, it might fit within 16 MB of memory.

As for when to spawn Superhubs, I use this code:

Code: Select all

	if(system.techLevel > 10 && system.economy < 4 && system.government > 4 && system.countShipsWithRole("pagroove_superhub") < 1) {
		this.xOffset = (Math.random() * 10000) + 10000; // x offset between 10 and 20km
		this.yOffset = (Math.random() * 10000) + 10000; // y offset between 10 and 20km
		if(Math.random() > 0.5) this.xOffset = -this.xOffset; // 50:50 chance of offsetting in the other direction
		if(Math.random() > 0.5) this.yOffset = -this.yOffset; // 50:50 chance of offsetting in the other direction
		system.addShips("pagroove_superhub", 1, system.mainStation.position.add(Vector3D(this.xOffset, this.yOffset, 0).fromCoordinateSystem("abs")));
		return;
	}
I figure Communist systems would not allow such a capitalist-style station in their systems. Their Gulags and Factories are good enough for them. :mrgreen:

Re: Superhub V1.2. slight update

Posted: Sat Feb 18, 2012 8:16 pm
by pagroove
I think that is a good idea to resize the texture indeed and repackage the OXP. :D

Re: Superhub V1.2. slight update

Posted: Sat Feb 18, 2012 8:19 pm
by pagroove
Switeck wrote:
figure Communist systems would not allow such a capitalist-style station in their systems. Their Gulags and Factories are good enough for them. :mrgreen:
Unless it's a 'Chinastyle' communist system.

Re: Superhub V1.2. slight update

Posted: Sat Feb 18, 2012 8:25 pm
by pagroove
@Switeck. BTW in the Superhub v1.2 there is already a smaller texture included. It resides in the texture directory in the sub dir 'smaller version'. You have to get this texture and copy it over the texture in the texture folder.

Re: Superhub V1.2. slight update

Posted: Sun Feb 19, 2012 10:50 am
by pagroove
mm :( last night I came across a Superhub and I can confirm that the rescaled texture is not good (buggy). I believe a few pages back Commander McLane posted a link to a correct version of the texture.