Game Development Community

dev|Pro Game Development Curriculum

2 Bugfixes for fxShapeReplicator

by Michael-Paul Jakovlevski · 01/25/2005 (10:42 pm) · 8 comments

Download Code File

This resource contains a fix for the bug describe here. it also contains a solution for another bug that occurs when interactions are turned off that causes the player to "lag" when walking through a shape that has a Collision mesh. This bug is caused by the fact that the client detects a collision and the server does not.

The fix was made against TGE 3.1 but it may work with lower versions.

Instructions:

1. Make backups of FxShapeReplicator.h and FxShapeReplicator.cc (located in the subdirectory Torque/engine/game/fx)

2. extract fxShapeReplicator.* into the same directory.

3. Rebuild solution.

4. Open up your favorite torque script editor and load the script file common/server/missionLoad.cs.

5. goto the function loadMissionStage2 add this after the line echo("*** Mission loaded"):
//Replicate shapes on server
   StartServerReplication();

and that's it.

About the author

Recent Blogs


#1
01/06/2005 (6:39 am)
Says zip file is missing?

Can't wait for it to work.
#2
01/07/2005 (1:06 am)
No file yet !?
#3
01/08/2005 (2:18 am)
Hey, can you re-upload the file? I would really like to take a look asap.
#4
01/08/2005 (7:12 am)
I can't do anything about it. Resources files have approved by someone at Garage Games before they can be downloaded. I guess it's to prevent people from putting up malicous code.
#5
01/22/2005 (12:22 pm)
This was a big help with my Tree placement. I did find another sneaky little bug though. Here is what happens. When the Server creates the SimSet it does so in order 1 2 3 4 5, unfortunatly, the client created the same set in order 5 4 3 2 1. SO if you have 2 fxShapeReplicators on top of each other as I do. When there is a RayCast to a bad point, the server and the client will be placing objects to different places. So here is my rather hacky solution, but it will hopefully save others from tossing and turning at night trying to figure out whats up.

in this file: fxShapeReplicator.cc
in this function: ConsoleFunction(StartServerReplication, void, 1, 1, "StartServerReplication()")


change:
for (SimSetIterator itr(fxReplicatorSet); *itr; ++itr)

to:
if ( fxReplicatorSet->size() <= 0 )
{
return;
}
for (SimSet::iterator itr = fxReplicatorSet->end() - 1; itr >= fxReplicatorSet->begin(); itr--)


What this snippet of code does is make the server see things in the same order as the client. No more insivible walls.
#6
11/21/2006 (3:51 pm)
Any idea if this has been fixed in 1.5? I am still crashing with invisible trees, so I dont think it has been fixed.
#7
10/04/2007 (5:51 am)
Seams to work well with 1.5 :)

I also added ReceiveSunLight because on dark maps it looks better.

Add the bold in fxShapeReplicator.h at about line 176:

mShapeRotateMax        .set(0, 0, 0);
         mTerrainAlignment      .set(1, 1, 1);

	 [b]mReceiveSunLight    = true;[/b]
      }

   } mFieldData;

and the bold in fxShapeReplicator.cc


At void fxShapeReplicator::initPersistFields():
addField( "OffsetZ",            TypeS32,        Offset( mFieldData.mOffsetZ,                fxShapeReplicator ) );
    endGroup( "Object Transforms" ); 
[b]
   //XXTH 
   addGroup("Lighting");
   addField("receiveSunLight", TypeBool, Offset(mFieldData.mReceiveSunLight, fxShapeReplicator));
   endGroup("Lighting");
[/b]
}

void fxShapeReplicator::CreateShapes(void):
// Lock it.
        fxStatic->setLocked(true);

	[b]fxStatic->receiveSunLight=mFieldData.mReceiveSunLight;[/b]
        // Store Shape in Replicated Shapes Vector.
        mReplicatedShapes[mCurrentShapeCount++] = fxStatic;

U32 fxShapeReplicator::packUpdate(NetConnection * con, U32 mask, BitStream * stream):
stream->write(mFieldData.mPlaceAreaColour);
		//MPJ Fix Begin
		stream->writeFlag(mFieldData.mFixShapeAspect);
		//MPJ Fix End
		//XXTH 
		[b]stream->writeFlag(mFieldData.mReceiveSunLight);[/b]
    }

void fxShapeReplicator::unpackUpdate(NetConnection * con, BitStream * stream):
mFieldData.mFixShapeAspect = stream->readFlag();
      //MPJ Fix End
      [b]mFieldData.mReceiveSunLight = stream->readFlag();[/b]

        // Set Transform.
        setTransform(ReplicatorObjectMatrix);
#8
04/02/2009 (6:09 am)
This still isn't fixing the collision problem for me. (TGE 1.5.2) It is better, only half of the replicated shapes have the same problem. I have a modded version with twSurface, AlphaLOD, animation and clustering in it, so one of these things may be effecting it.

In your editor, once you click on the fxShapeReplicator in the guiTreeView, doesn't that inact inspectPostApply(); I assume... and all the collisions work fine after that. So I tried to setup the applyPostInspect to be called after the replication is complete and after your unpack, but it doesn't make a difference either way. So can I make a call to update the replicator, say in onMissionLoaded in game.cs? or something like that?
EDIT:
I think I found the fix, I had Interactions switched off. But that still doesn't make sense, why when you click on the fxShapeReplicator in the editor it fixes your collision problem...bug bug bug