📄 fxshapereplicator.cc
字号:
// Set Parent.
Parent::inspectPostApply();
// Renew Shapes.
RenewShapes();
// Set Replication Mask.
setMaskBits(ReplicationMask);
}
//------------------------------------------------------------------------------
void fxShapeReplicator::onEditorEnable()
{
// Are we in the Scene?
if(!mAddedToScene)
{
// No, so add to scene.
addToScene();
mAddedToScene = true;
}
}
//------------------------------------------------------------------------------
void fxShapeReplicator::onEditorDisable()
{
// Are we in the Scene?
if(mAddedToScene)
{
// Yes, so remove from scene.
removeFromScene();
mAddedToScene = false;
}
}
//------------------------------------------------------------------------------
ConsoleFunction(StartClientReplication, void, 1, 1, "StartClientReplication()")
{
// Find the Replicator Set.
SimSet *fxReplicatorSet = dynamic_cast<SimSet*>(Sim::findObject("fxReplicatorSet"));
// Return if Error.
if (!fxReplicatorSet) return;
// StartUp Replication Object.
for (SimSetIterator itr(fxReplicatorSet); *itr; ++itr)
{
// Fetch the Replicator Object.
fxShapeReplicator* Replicator = static_cast<fxShapeReplicator*>(*itr);
// Start Client Objects Only.
if (Replicator->isClientObject()) Replicator->StartUp();
}
// Info ...
Con::printf("Client Replication Startup has Happened!");
}
//------------------------------------------------------------------------------
bool fxShapeReplicator::prepRenderImage(SceneState* state, const U32 stateKey, const U32 startZone,
const bool modifyBaseZoneState)
{
// Return if last state.
if (isLastState(state, stateKey)) return false;
// Set Last State.
setLastState(state, stateKey);
// Is Object Rendered?
if (state->isObjectRendered(this))
{
// Yes, so get a SceneRenderImage.
SceneRenderImage* image = new SceneRenderImage;
// Populate it.
image->obj = this;
image->sortType = SceneRenderImage::Normal;
// Insert it into the scene images.
state->insertRenderImage(image);
}
return false;
}
//------------------------------------------------------------------------------
void fxShapeReplicator::renderObject(SceneState* state, SceneRenderImage*)
{
// Return if placement area not needed.
if (!mFieldData.mShowPlacementArea) return;
// Check we are in Canonical State.
AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");
// Setup out the Projection Matrix/Viewport.
RectI viewport;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
dglGetViewport(&viewport);
state->setupBaseProjection();
// Setup our rendering state.
glPushMatrix();
dglMultMatrix(&getTransform());
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// Do we need to draw the Inner Radius?
if (mFieldData.mInnerRadiusX || mFieldData.mInnerRadiusY)
{
// Yes, so draw Inner Radius.
glBegin(GL_TRIANGLE_STRIP);
for (U32 Angle = mCreationAreaAngle; Angle < (mCreationAreaAngle+360); Angle++)
{
F32 XPos, YPos;
// Calculate Position.
XPos = mFieldData.mInnerRadiusX * mCos(mDegToRad(-(F32)Angle));
YPos = mFieldData.mInnerRadiusY * mSin(mDegToRad(-(F32)Angle));
// Set Colour.
glColor4f( mFieldData.mPlaceAreaColour.red,
mFieldData.mPlaceAreaColour.green,
mFieldData.mPlaceAreaColour.blue,
AREA_ANIMATION_ARC * (Angle-mCreationAreaAngle));
// Draw Arc Line.
glVertex3f( XPos, YPos, -(F32)mFieldData.mPlacementBandHeight/2.0f);
glVertex3f( XPos, YPos, +(F32)mFieldData.mPlacementBandHeight/2.0f);
}
glEnd();
}
// Do we need to draw the Outer Radius?
if (mFieldData.mOuterRadiusX || mFieldData.mOuterRadiusY)
{
// Yes, so draw Outer Radius.
glBegin(GL_TRIANGLE_STRIP);
for (U32 Angle = mCreationAreaAngle; Angle < (mCreationAreaAngle+360); Angle++)
{
F32 XPos, YPos;
// Calculate Position.
XPos = mFieldData.mOuterRadiusX * mCos(mDegToRad(-(F32)Angle));
YPos = mFieldData.mOuterRadiusY * mSin(mDegToRad(-(F32)Angle));
// Set Colour.
glColor4f( mFieldData.mPlaceAreaColour.red,
mFieldData.mPlaceAreaColour.green,
mFieldData.mPlaceAreaColour.blue,
AREA_ANIMATION_ARC * (Angle-mCreationAreaAngle));
// Draw Arc Line.
glVertex3f( XPos, YPos, -(F32)mFieldData.mPlacementBandHeight/2.0f);
glVertex3f( XPos, YPos, +(F32)mFieldData.mPlacementBandHeight/2.0f);
}
glEnd();
}
// Restore rendering state.
glDisable(GL_BLEND);
glPopMatrix();
// Animate Area Selection.
mCreationAreaAngle += 20;
mCreationAreaAngle = mCreationAreaAngle % 360;
// Restore out nice and friendly canonical state.
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
dglSetViewport(viewport);
// Check we have restored Canonical State.
AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on exit");
}
//------------------------------------------------------------------------------
U32 fxShapeReplicator::packUpdate(NetConnection * con, U32 mask, BitStream * stream)
{
// Pack Parent.
U32 retMask = Parent::packUpdate(con, mask, stream);
// Write Replication Flag.
if (stream->writeFlag(mask & ReplicationMask))
{
stream->writeAffineTransform(mObjToWorld); // Replicator Position.
stream->writeInt(mFieldData.mSeed, 32); // Replicator Seed.
stream->writeInt(mFieldData.mShapeCount, 32); // Shapes Count.
stream->writeInt(mFieldData.mShapeRetries, 32); // Shapes Retries.
stream->writeString(mFieldData.mShapeFile);
stream->writeInt(mFieldData.mInnerRadiusX, 32); // Shapes Inner Radius X.
stream->writeInt(mFieldData.mInnerRadiusY, 32); // Shapes Inner Radius Y.
stream->writeInt(mFieldData.mOuterRadiusX, 32); // Shapes Outer Radius X.
stream->writeInt(mFieldData.mOuterRadiusY, 32); // Shapes Outer Radius Y.
mathWrite(*stream, mFieldData.mShapeScaleMin); // Shapes Scale Min.
mathWrite(*stream, mFieldData.mShapeScaleMax); // Shapes Scale Max.
mathWrite(*stream, mFieldData.mShapeRotateMin); // Shapes Rotate Min.
mathWrite(*stream, mFieldData.mShapeRotateMax); // Shapes Rotate Max.
stream->writeSignedInt(mFieldData.mOffsetZ, 32); // Shapes Offset Z.
stream->writeFlag(mFieldData.mAllowOnTerrain); // Allow on Terrain.
stream->writeFlag(mFieldData.mAllowOnInteriors); // Allow on Interiors.
stream->writeFlag(mFieldData.mAllowStatics); // Allow on Statics.
stream->writeFlag(mFieldData.mAllowOnWater); // Allow on Water.
stream->writeFlag(mFieldData.mAllowWaterSurface); // Allow on Water Surface.
stream->writeSignedInt(mFieldData.mAllowedTerrainSlope, 32); // Shapes Offset Z.
stream->writeFlag(mFieldData.mAlignToTerrain); // Shapes AlignToTerrain.
mathWrite(*stream, mFieldData.mTerrainAlignment); // Write Terrain Alignment.
stream->writeFlag(mFieldData.mHideReplications); // Hide Replications.
stream->writeFlag(mFieldData.mInteractions); // Shape Interactions.
stream->writeFlag(mFieldData.mShowPlacementArea); // Show Placement Area Flag.
stream->writeInt(mFieldData.mPlacementBandHeight, 32); // Placement Area Height.
stream->write(mFieldData.mPlaceAreaColour);
}
// Were done ...
return(retMask);
}
//------------------------------------------------------------------------------
void fxShapeReplicator::unpackUpdate(NetConnection * con, BitStream * stream)
{
// Unpack Parent.
Parent::unpackUpdate(con, stream);
// Read Replication Details.
if(stream->readFlag())
{
MatrixF ReplicatorObjectMatrix;
stream->readAffineTransform(&ReplicatorObjectMatrix); // Replication Position.
mFieldData.mSeed = stream->readInt(32); // Replicator Seed.
mFieldData.mShapeCount = stream->readInt(32); // Shapes Count.
mFieldData.mShapeRetries = stream->readInt(32); // Shapes Retries.
mFieldData.mShapeFile = stream->readSTString(); // Shape File.
mFieldData.mInnerRadiusX = stream->readInt(32); // Shapes Inner Radius X.
mFieldData.mInnerRadiusY = stream->readInt(32); // Shapes Inner Radius Y.
mFieldData.mOuterRadiusX = stream->readInt(32); // Shapes Outer Radius X.
mFieldData.mOuterRadiusY = stream->readInt(32); // Shapes Outer Radius Y.
mathRead(*stream, &mFieldData.mShapeScaleMin); // Shapes Scale Min.
mathRead(*stream, &mFieldData.mShapeScaleMax); // Shapes Scale Max.
mathRead(*stream, &mFieldData.mShapeRotateMin); // Shapes Rotate Min.
mathRead(*stream, &mFieldData.mShapeRotateMax); // Shapes Rotate Max.
mFieldData.mOffsetZ = stream->readSignedInt(32); // Shapes Offset Z.
mFieldData.mAllowOnTerrain = stream->readFlag(); // Allow on Terrain.
mFieldData.mAllowOnInteriors = stream->readFlag(); // Allow on Interiors.
mFieldData.mAllowStatics = stream->readFlag(); // Allow on Statics.
mFieldData.mAllowOnWater = stream->readFlag(); // Allow on Water.
mFieldData.mAllowWaterSurface = stream->readFlag(); // Allow on Water Surface.
mFieldData.mAllowedTerrainSlope = stream->readSignedInt(32); // Allowed Terrain Slope.
mFieldData.mAlignToTerrain = stream->readFlag(); // Read AlignToTerrain.
mathRead(*stream, &mFieldData.mTerrainAlignment); // Read Terrain Alignment.
mFieldData.mHideReplications = stream->readFlag(); // Hide Replications.
mFieldData.mInteractions = stream->readFlag(); // Read Interactions.
mFieldData.mShowPlacementArea = stream->readFlag(); // Show Placement Area Flag.
mFieldData.mPlacementBandHeight = stream->readInt(32); // Placement Area Height.
stream->read(&mFieldData.mPlaceAreaColour);
// Set Transform.
setTransform(ReplicatorObjectMatrix);
// Renew Shapes (only if replication has started).
if (mClientReplicationStarted) RenewShapes();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -