Game Development Community

dev|Pro Game Development Curriculum

fxShapereplicator Polysoup for TGEA 1.7.x

by James Laker (BurNinG) · 06/18/2008 (8:10 am) · 7 comments

I'm a little bored and waiting for time to pass, so I thought I would quickly submit my code to get polysoup working for fxShapereplicators. This was a key feature needed for me in Solar Battles to have ships fly through asteroid fields with proper collision.

Lets get right to it and open up fxShapereplicator.h. Search for where all the variables are being declared under:

class tagFieldData
   {
      public:

and add:
//JLAKER - Polysoup
         bool mUsePolysoup;
         //JLAKER - Polysoup

Down a little is where we give it a default value so just add the following:
mAllowedTerrainSlope= 90;
         mAlignToTerrain     = false;
         mInteractions       = true;
         //JLAKER - Polysoup         
         mUsePolysoup = false;
         //JLAKER - Polysoup

That's it for the Header file; Open up fxShapereplicator.cpp and add the following at the bottom of void fxShapeReplicator::initPersistFields():

//JLAKER - Polysoup
	addGroup( "Collision" );
	addField( "usePolysoup",		TypeBool,		Offset( mFieldData.mUsePolysoup,			fxShapeReplicator ) );
	endGroup( "Collision" );	// MM: Added Group Footer.
//JLAKER - Polysoup

The above code will make sure you can change it in the Mission Editor to use Polysoup or not - It's that simple ;)

In the next method (void fxShapeReplicator::CreateShapes(void)) we find where we create each individual shape and change it to look like this:
.
...
.....
		// Create our static shape.
		fxStatic = new fxShapeReplicatedStatic();

		// Set the 'shapeName' field.
		fxStatic->setField("shapeName", mFieldData.mShapeFile);

		//JLAKER - Polysoup
		if (mFieldData.mUsePolysoup)
			fxStatic->setField("usePolysoup", "true");
		else
			fxStatic->setField("usePolysoup", "false");
		//JLAKER - Polysoup

		// Is this Replicator on the Server?
		if (isServerObject())
.....
...
.

Just make sure we send the variable over to wire by changing the following int U32 fxShapeReplicator::packUpdate to:
stream->write(mFieldData.mPlaceAreaColour);

		//JLAKER - Polysoup
		stream->writeFlag(mFieldData.mUsePolysoup);		// Polysoup.
		//JLAKER - Polysoup

	} //JLaker -> Dont miss this!

And of course also update the unpack (void fxShapeReplicator::unpackUpdate) make the following changes:

stream->read(&mFieldData.mPlaceAreaColour);

		//JLAKER - Polysoup
		mFieldData.mUsePolysoup		= stream->readFlag(); //Polysoup... Tastes like chicken		//JLAKER - Polysoup

		// Set Transform.
		setTransform(ReplicatorObjectMatrix);

Recompile and Pow - It's that simple :)

#1
06/18/2008 (9:44 am)
Sweet! Thanks for posting this. Now my replicated shapes have shadows. =D
#2
06/18/2008 (5:06 pm)
Thanks for posting this resource.

But i have some problem.

i add your code and compiled.

add fxshapereplicator in my test mission.

but not add shapes.

this is my console message.

TSStatic::onAdd: unable to load shape: true
[asdferdf] - Could not load shape file 'scriptsAndAssets/data/shapes/trees/oak1.dts'!
TSStatic::onAdd: unable to load shape: true
[(null)] - Could not load shape file 'scriptsAndAssets/data/shapes/trees/oak1.dts'!

and i remove this code
if (mFieldData.mUsePolysoup)			
			fxStatic->setField("shapeName", "true");		
		else			
			fxStatic->setField("shapeName", "false");

Then possible add fxshapereplicator in mission.
but not apply polysoup.

i need some help.
#3
06/18/2008 (11:47 pm)
Just a thought, but shouldn't it be:

fxStatic->setField("usePolysoup", "false/true");

instead of

fxStatic->setField("shapeName", "false/true");
#4
06/19/2008 (1:19 am)
Thanx Taylor... Stupid Typo from my side.

@Mquaker: Updated the resource, just make the small change Taylor gave.
#5
06/19/2008 (2:21 am)
No problem James.
#6
06/19/2008 (7:06 pm)
Thanks Taylor & James. :)
#7
08/07/2008 (5:12 am)
Nice... thats how it should be.