Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → More rain...counting things in a sector
More rain...counting things in a sector
2005-07-26, 3:22 PM #1
Here's the pulse of my rain COG, the code that actually fires the rain templates. But it's acting a bit funny. It's supposed to scan the sector, count the number of raindrops, and if that number is fewer than the specified amount (based on a user specified density and area of the surface) it will create rain. If not, it won't. It's supposed to make it so rain is evenly distributed no matter what the size of the surface. If you have a rainDensity of 10, it shouldn't be dropping 10 drops at a time from a surface whose area is 0.2. It should only be dropping 2. But for some reason I'm getting as many as 9 or 10 drops from a small sky opening when, infact there should be no more than 2 in the sector at any given time. What's going on?

Oh, and don't worry about the code block after if(numDropsInSector < heapGet(numSkySurfaces + i)). That part works fine. I'm having trouble regulating the amount of rain however.

Code:
pulse:
	// Loop through all our stored sky surfaces using the loop index 'i' and
	// heapGet().	
	for(i = 0; i < numSkySurfaces; i = i + 1)
	{
		temp = firstThingInSector(getSurfaceSector(i));
		numDropsInSector = 0;
		
		// Add up all the things in the sector which are raindrops.
		for(j = 0; j < getSectorThingCount(getSurfaceSector(i)); j = j + 1)
		{
			if(getThingTemplate(temp + j) == raindropTpl)
				numDropsInSector = numDropsInSector + 1;
		}
		
		// Only create rain if the current number of raindrops in the sector
		// is less than the number it should have.
		if(numDropsInSector < heapGet(numSkySurfaces + i))
		{
			surface = heapGet(i);
			temp = heapGet(numSkySurfaces * 2 + i) * rand();
			
			testPoint = heapGet(numSkySurfaces * 4 +
								numMaxTestPoints * i + temp);
			testPoint = vectorSet(vectorX(testPoint),
								  vectorY(testPoint),
								  vectorZ(testPoint) - 0.05);
			
			ghostObj = createThingAtPos(ghostTpl, getSurfaceSector(surface),
										testPoint, '-90 0 0');
			proj = fireProjectile(ghostObj, raindropTpl, -1, -1, '0 0 0',
								  '0 0 0', 0, 0x0, 0, 0);
			destroyThing(ghostObj);
		}
	}
	return;
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2005-07-27, 12:20 AM #2
Zeq pointed out that I was using just i as the index instead of heapGet(i). However, it still doesn't work...
Code:
pulse:
	// Loop through all our stored sky surfaces using the loop index 'i' and
	// heapGet().	
	for(i = 0; i < numSkySurfaces; i = i + 1)
	{
		surface = heapGet(i);
		temp = firstThingInSector(getSurfaceSector(surface));
		numDropsInSector = 0;
		
		// Add up all the things in the sector which are raindrops.
		for(j = 0; j < getSectorThingCount(getSurfaceSector(surface)); j = j+1)
		{
			if(getThingTemplate(temp + j) == raindropTpl)
				numDropsInSector = numDropsInSector + 1;
		}
		
		// Only create rain if the current number of raindrops in the sector
		// is less than the number it should have.
		if(numDropsInSector < heapGet(numSkySurfaces + i))
		{
			temp = heapGet(numSkySurfaces * 2 + i) * rand();
			
			testPoint = heapGet(numSkySurfaces * 4 +
								numMaxTestPoints * i + temp);
			testPoint = vectorSet(vectorX(testPoint),
								  vectorY(testPoint),
								  vectorZ(testPoint) - 0.05);
			
			ghostObj = createThingAtPos(ghostTpl, getSurfaceSector(surface),
										testPoint, '-90 0 0');
			proj = fireProjectile(ghostObj, raindropTpl, -1, -1, '0 0 0',
								  '0 0 0', 0, 0x0, 0, 0);
			destroyThing(ghostObj);
		}
	}
	return;
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2005-07-27, 8:07 AM #3
Code:
if(getThingTemplate(temp + j) == raindropTpl)


I think that's a problem right there, though I'm not sure -- The things in a sector are not necessarily in a sequential order (e.g. 1st thing in sector is thing 12, 2nd thing in sector is 13...)

It should probably be

Code:
if(GetThingTemplate(temp) == raindropTpl)
{...}
temp = NextThingInSector();


or something like that, but again I'm not totally sure
May the mass times acceleration be with you.
2005-07-27, 10:53 AM #4
If you are just randomly placing them, it shouldn't matter. I guess the problem is that you just loop through surfaces, or randomly choose a surface. Something where you randomly choose a surface to add do, biased by its area, would take care of these problems and probably make your cog run a lot faster, since you don't have to do anything extra to determine where to add one at.
You could also bias it so that they appear closer to the player, since rain far away probably doesn't have as much use.
Air Master 3D (my iPhone game)
My Programming Website
2005-07-27, 1:46 PM #5
Turns out I went with a completely different method. That particular code was meant to make one raindrop per surface per iteration of the pulse, so that the delay of the pulse would break up the rainfall so it wouldn't come down in volleys. I switched back to my old method where I create all the raindrops for all the surfaces at once...except testPoint now looks like this:

Code:
testPoint = heapGet(numSkySurfaces * 3 +
								numMaxTestPoints * i + temp);
			temp = 1.0 * rand();
			testPoint = vectorSet(vectorX(testPoint),
								  vectorY(testPoint),
								  vectorZ(testPoint) + temp);

I just added a random flex to the Z axis of the vector, so raindrops are actually fired from outside the sector at different distances. Now it's totally broken up and looks like real rain. Well, sometimes the rain falls in volleys of 2-3 drops at a time, but I attribute that to JK's rand() function and there's not much I can do about that. Nor do you really notice.
Bassoon, n. A brazen instrument into which a fool blows out his brains.

↑ Up to the top!