void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream) { Parent::unpackUpdate(con, stream); MatrixF mat; Point3F scale; mathRead( *stream, &mat ); mathRead( *stream, &scale ); setScale( scale); setTransform(mat); mShapeName = stream->readSTString(); if ( stream->readFlag() ) // UpdateCollisionMask { U32 collisionType = CollisionMesh; stream->read( &collisionType ); // Handle it if we have changed CollisionType's if ( (MeshType)collisionType != mCollisionType ) { mCollisionType = (MeshType)collisionType; if ( isProperlyAdded() && mShapeInstance ) prepCollision(); } } if (stream->readFlag()) // SkinMask { NetStringHandle skinDesiredNameHandle = con->unpackNetStringHandleU(stream);; if (mSkinNameHandle != skinDesiredNameHandle) { mSkinNameHandle = skinDesiredNameHandle; reSkin(); } } stream->read( (U32*)&mDecalType ); mAllowPlayerStep = stream->readFlag(); mMeshCulling = stream->readFlag(); mUseOriginSort = stream->readFlag(); stream->read( &mRenderNormalScalar ); stream->read( &mForceDetail ); mPlayAmbient = stream->readFlag(); if ( mLightPlugin ) { mLightPlugin->unpackUpdate(this, con, stream); } if ( isProperlyAdded() ) _updateShouldTick(); }
void CloudLayer::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); String oldTextureName = mTextureName; stream->read( &mTextureName ); for ( U32 i = 0; i < TEX_COUNT; i++ ) { stream->read( &mTexScale[i] ); stream->read( &mTexSpeed[i] ); mathRead( *stream, &mTexDirection[i] ); } stream->read( &mBaseColor ); F32 oldCoverage = mCoverage; stream->read( &mCoverage ); stream->read( &mExposure ); stream->read( &mWindSpeed ); F32 oldHeight = mHeight; stream->read( &mHeight ); if ( isProperlyAdded() ) { if ( ( oldTextureName != mTextureName ) || ( ( oldCoverage == 0.0f ) != ( mCoverage == 0.0f ) ) ) _initTexture(); if ( oldHeight != mHeight ) _initBuffers(); } }
void BasicClouds::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); for ( U32 i = 0; i < TEX_COUNT; i++ ) { mLayerEnabled[i] = stream->readFlag(); stream->read( &mTexName[i] ); stream->read( &mTexScale[i] ); mathRead( *stream, &mTexDirection[i] ); stream->read( &mTexSpeed[i] ); mathRead( *stream, &mTexOffset[i] ); stream->read( &mHeight[i] ); } if ( isProperlyAdded() ) { // We could check if the height or texture have actually changed. _initBuffers(); _initTexture(); } }
void GroundPlane::unpackUpdate( NetConnection* connection, BitStream* stream ) { Parent::unpackUpdate( connection, stream ); stream->read( &mSquareSize ); stream->read( &mScaleU ); stream->read( &mScaleV ); stream->read( &mMaterialName ); if( stream->readFlag() ) // UpdateMask { MatrixF mat; mathRead( *stream, &mat ); setTransform( mat ); } // If we're added then something possibly changed in // the editor... do an update of the material and the // geometry. if ( isProperlyAdded() ) { _updateMaterial(); mVertexBuffer = NULL; } }
//----------------------------------------------------------------------------- // unpackUpdate //----------------------------------------------------------------------------- void ParticleEmitterNode::unpackUpdate(NetConnection* con, BitStream* stream) { Parent::unpackUpdate(con, stream); if ( stream->readFlag() ) { MatrixF temp; Point3F tempScale; mathRead(*stream, &temp); mathRead(*stream, &tempScale); setScale(tempScale); setTransform(temp); } if ( stream->readFlag() ) { mEmitterDatablockId = stream->readFlag() ? stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast) : 0; ParticleEmitterData *emitterDB = NULL; Sim::findObject( mEmitterDatablockId, emitterDB ); if ( isProperlyAdded() ) setEmitterDataBlock( emitterDB ); } if ( stream->readFlag() ) { mActive = stream->readFlag(); stream->read( &mVelocity ); } }
void Material::inspectPostApply() { Parent::inspectPostApply(); // Reload the material instances which // use this material. if ( isProperlyAdded() ) reload(); }
void PxMaterial::onStaticModified( const char *slotName, const char *newValue ) { if ( isProperlyAdded() && mNxMat != NULL ) { mNxMat->setRestitution( restitution ); mNxMat->setStaticFriction( staticFriction ); mNxMat->setDynamicFriction( dynamicFriction ); } }
//---------------------------------------------------------------------------- bool GameBase::setDataBlock(GameBaseData* dptr) { if (isGhost() || isProperlyAdded()) { if (mDataBlock != dptr) return onNewDataBlock(dptr,false); } else mDataBlock = dptr; return true; }
void ConvexShape::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); if ( stream->readFlag() ) // TransformMask { mathRead(*stream, &mObjToWorld); mathRead(*stream, &mObjScale); setTransform( mObjToWorld ); setScale( mObjScale ); } if ( stream->readFlag() ) // UpdateMask { stream->read( &mMaterialName ); if ( isProperlyAdded() ) _updateMaterial(); mSurfaces.clear(); const U32 surfCount = stream->readInt( 32 ); for ( S32 i = 0; i < surfCount; i++ ) { mSurfaces.increment(); MatrixF &mat = mSurfaces.last(); QuatF quat; Point3F pos; mathRead( *stream, &quat ); mathRead( *stream, &pos ); quat.setMatrix( &mat ); mat.setPosition( pos ); } if ( isProperlyAdded() ) _updateGeometry( true ); } }
void ForestWindEmitter::unpackUpdate(NetConnection * con, BitStream * stream) { // Unpack Parent. Parent::unpackUpdate( con, stream ); MatrixF xfm; mathRead( *stream, &xfm ); Parent::setTransform( xfm ); U32 windMask = 0; if ( stream->readFlag() ) // EnabledMask mEnabled = stream->readFlag(); if ( stream->readFlag() ) // WindMask { stream->read( &mWindStrength ); stream->read( &mWindRadius ); mRadialEmitter = stream->readFlag(); stream->read( &mWindGustStrength ); stream->read( &mWindGustFrequency ); stream->read( &mWindGustYawAngle ); stream->read( &mWindGustYawFrequency ); stream->read( &mWindGustWobbleStrength ); stream->read( &mWindTurbulenceStrength ); stream->read( &mWindTurbulenceFrequency ); stream->readNormalVector( &mWindDirection, 8 ); windMask |= WindMask; mHasMount = stream->readFlag(); } // This does nothing if the masks are not set! if ( windMask != 0 && isProperlyAdded() ) { Point3F boxRad( 0, 0, 0 ); if ( !isRadialEmitter() ) boxRad.set( 10000.0f, 10000.0f, 10000.0f ); else boxRad.set( mWindRadius, mWindRadius, mWindRadius ); mObjBox.set( -boxRad, boxRad ); resetWorldBox(); _initWind( windMask ); } }
bool Item::onNewDataBlock( GameBaseData *dptr, bool reload ) { mDataBlock = dynamic_cast<ItemData*>(dptr); if (!mDataBlock || !Parent::onNewDataBlock(dptr,reload)) return false; if (!mSubclassItemHandlesScene) scriptOnNewDataBlock(); if ( isProperlyAdded() ) _updatePhysics(); return true; }
void SkyBox::_updateMaterial() { if ( mMatName.isEmpty() ) return; Material *pMat = NULL; if ( !Sim::findObject( mMatName, pMat ) ) Con::printf( "SkyBox::_updateMaterial, failed to find Material of name %s!", mMatName.c_str() ); else if ( isProperlyAdded() ) { mMaterial = pMat; _initMaterial(); } }
void WaterObject::_onDisableTrueRelfections() { // Same code as _setFullReflect if ( isProperlyAdded() && isClientObject() ) { bool isEnabled = mPlaneReflector.isEnabled(); bool enable = mFullReflect && !smDisableTrueReflections; if ( enable && !isEnabled ) mPlaneReflector.registerReflector( this, &mReflectorDesc ); else if ( !enable && isEnabled ) mPlaneReflector.unregisterReflector(); } }
void Sun::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); if ( stream->readFlag() ) // UpdateMask { stream->read( &mSunAzimuth ); stream->read( &mSunElevation ); stream->read( &mLightColor ); stream->read( &mLightAmbient ); stream->read( &mBrightness ); mCastShadows = stream->readFlag(); stream->read(&mStaticRefreshFreq); stream->read(&mDynamicRefreshFreq); stream->read( &mFlareScale ); if ( stream->readFlag() ) { SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); LightFlareData *datablock = NULL; if ( Sim::findObject( id, datablock ) ) mFlareData = datablock; else { conn->setLastError( "Sun::unpackUpdate() - invalid LightFlareData!" ); mFlareData = NULL; } } else mFlareData = NULL; mCoronaEnabled = stream->readFlag(); stream->read( &mCoronaMatName ); stream->read( &mCoronaScale ); stream->read( &mCoronaTint ); mCoronaUseLightColor = stream->readFlag(); mLight->unpackExtended( stream ); } if ( isProperlyAdded() ) { _initCorona(); _conformLights(); } }
void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream) { Parent::unpackUpdate(conn, stream); stream->read( &mNearClip ); stream->read( &mVisibleDistance ); stream->read( &mDecalBias ); stream->read( &mFogData.density ); stream->read( &mFogData.densityOffset ); stream->read( &mFogData.atmosphereHeight ); stream->read( &mFogData.color ); stream->read( &mCanvasClearColor ); stream->read( &mWorldSize ); mAdvancedLightmapSupport = stream->readFlag(); stream->read( &mAmbientLightBlendPhase ); mathRead( *stream, &mAmbientLightBlendCurve ); String errorStr; if( !sfxReadAndResolve( stream, &mSoundAmbience, errorStr ) ) Con::errorf( "%s", errorStr.c_str() ); mSoundDistanceModel = ( SFXDistanceModel ) stream->readInt( 1 ); if( isProperlyAdded() ) { _updateSceneGraph(); if( mSoundscape ) { if( mSoundAmbience ) mSoundscape->setAmbience( mSoundAmbience ); else mSoundscape->setAmbience( &sDefaultAmbience ); } SFX->setDistanceModel( mSoundDistanceModel ); } stream->read(&mAccuTextureName); setLevelAccuTexture(mAccuTextureName); }
void PopupMenu::onAttachToMenuBar(GuiCanvas *canvas, S32 pos, const char *title) { mCanvas = canvas; // Attached menus must be notified of menu events smPopupMenuEvent.notify(this, &PopupMenu::handleSelectEvent); // Pass on to sub menus for(SimSet::iterator i = mSubmenus->begin();i != mSubmenus->end();++i) { PopupMenu *mnu = dynamic_cast<PopupMenu *>(*i); if(mnu == NULL) continue; mnu->onAttachToMenuBar(canvas, pos, title); } // Call script if(isProperlyAdded()) Con::executef(this, "onAttachToMenuBar", Con::getIntArg(canvas ? canvas->getId() : 0), Con::getIntArg(pos), title); }
void RenderMeshExample::unpackUpdate(NetConnection *conn, BitStream *stream) { // Let the Parent read any info it sent Parent::unpackUpdate(conn, stream); if ( stream->readFlag() ) // TransformMask { mathRead(*stream, &mObjToWorld); mathRead(*stream, &mObjScale); setTransform( mObjToWorld ); } if ( stream->readFlag() ) // UpdateMask { stream->read( &mMaterialName ); if ( isProperlyAdded() ) updateMaterial(); } }
void PopupMenu::onRemoveFromMenuBar(GuiCanvas *canvas) { mCanvas = NULL; // We are no longer interested in select events, remove ourselves from the notification list in a safe way Sim::postCurrentEvent(this, new PopUpNotifyRemoveEvent()); // Pass on to sub menus for(SimSet::iterator i = mSubmenus->begin();i != mSubmenus->end();++i) { PopupMenu *mnu = dynamic_cast<PopupMenu *>(*i); if(mnu == NULL) continue; mnu->onRemoveFromMenuBar(canvas); } // Call script if(isProperlyAdded()) Con::executef(this, "onRemoveFromMenuBar", Con::getIntArg(canvas ? canvas->getId() : 0)); }
void DecalData::onStaticModified( const char *slotName, const char *newValue ) { Parent::onStaticModified( slotName, newValue ); if ( !isProperlyAdded() ) return; // To allow changing materials live. if ( dStricmp( slotName, "material" ) == 0 ) { materialName = newValue; _updateMaterial(); } // To allow changing name live. else if ( dStricmp( slotName, "name" ) == 0 ) { lookupName = getName(); } else if ( dStricmp( slotName, "renderPriority" ) == 0 ) { renderPriority = getMax( renderPriority, (U8)1 ); } }
void WaterObject::unpackUpdate( NetConnection * conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); // UpdateMask if ( stream->readFlag() ) { stream->read( &mDensity ); stream->read( &mViscosity ); stream->read( &mLiquidType ); if ( stream->readFlag() ) { mFullReflect = true; stream->read( &mReflectorDesc.priority ); mReflectorDesc.maxRateMs = stream->readInt( 32 ); //stream->read( &mReflectMaxDist ); //stream->read( &mReflectMinDist ); stream->read( &mReflectorDesc.detailAdjust ); mReflectNormalUp = stream->readFlag(); mReflectorDesc.useOcclusionQuery = stream->readFlag(); mReflectorDesc.texSize = stream->readInt( 32 ); if ( isProperlyAdded() && !mPlaneReflector.isEnabled() && !smDisableTrueReflections ) mPlaneReflector.registerReflector( this, &mReflectorDesc ); } else { mFullReflect = false; if ( isProperlyAdded() && mPlaneReflector.isEnabled() ) mPlaneReflector.unregisterReflector(); } stream->read( &mReflectivity ); stream->read( &mWaterFogData.density ); stream->read( &mWaterFogData.densityOffset ); stream->read( &mWaterFogData.wetDepth ); stream->read( &mWaterFogData.wetDarkening ); stream->read( &mDistortStartDist ); stream->read( &mDistortEndDist ); stream->read( &mDistortFullDepth ); stream->read( &mDepthGradientMax ); mEmissive = stream->readFlag(); stream->read( &mFoamMaxDepth ); stream->read( &mFoamAmbientLerp ); stream->read( &mFoamRippleInfluence ); stream->read( &mWaterFogData.color ); stream->read( &mFresnelBias ); stream->read( &mFresnelPower ); Point4F specularData; mathRead( *stream, &specularData ); mSpecularColor.set( specularData.x, specularData.y, specularData.z, 1.0f ); mSpecularPower = specularData.w; stream->read( &mClarity ); stream->read( &mUnderwaterColor ); stream->read( &mOverallRippleMagnitude ); stream->read( &mOverallWaveMagnitude ); stream->read( &mOverallFoamOpacity ); } // WaveMask if ( stream->readFlag() ) { for( U32 i=0; i<MAX_WAVES; i++ ) { stream->read( &mRippleSpeed[i] ); mathRead( *stream, &mRippleDir[i] ); mathRead( *stream, &mRippleTexScale[i] ); stream->read( &mRippleMagnitude[i] ); stream->read( &mWaveSpeed[i] ); mathRead( *stream, &mWaveDir[i] ); stream->read( &mWaveMagnitude[i] ); } for ( U32 i = 0; i < MAX_FOAM; i++ ) { stream->read( &mFoamSpeed[i] ); mathRead( *stream, &mFoamDir[i] ); mathRead( *stream, &mFoamTexScale[i] ); stream->read( &mFoamOpacity[i] ); } } // MaterialMask if ( stream->readFlag() ) { for ( U32 i = 0; i < NumMatTypes; i++ ) stream->read( &mSurfMatName[i] ); if ( isProperlyAdded() ) { // So they will be reloaded on next use. cleanupMaterials(); } } // TextureMask if ( stream->readFlag() ) { stream->read( &mRippleTexName ); stream->read( &mDepthGradientTexName ); stream->read( &mFoamTexName ); stream->read( &mCubemapName ); if ( isProperlyAdded() ) initTextures(); } // Sound environment. if( stream->readFlag() ) { String errorStr; if( !sfxReadAndResolve( stream, &mSoundAmbience, errorStr ) ) Con::errorf( "WaterObject::unpackUpdate - pad packet: %s", errorStr.c_str() ); if( isProperlyAdded() && gSFX3DWorld ) gSFX3DWorld->notifyChanged( this ); } }
void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream ) { // Unpack Parent. Parent::unpackUpdate( con, stream ); // DecalRoadMask if ( stream->readFlag() ) { String matName; stream->read( &matName ); if ( matName != mMaterialName ) { mMaterialName = matName; Material *pMat = NULL; if ( !Sim::findObject( mMaterialName, pMat ) ) { Con::printf( "DecalRoad::unpackUpdate, failed to find Material of name %s!", mMaterialName.c_str() ); } else { mMaterial = pMat; if ( isProperlyAdded() ) _initMaterial(); } } stream->read( &mBreakAngle ); stream->read( &mSegmentsPerBatch ); stream->read( &mTextureLength ); stream->read( &mRenderPriority ); } // NodeMask if ( stream->readFlag() ) { //U32 count = stream->readInt( 16 ); //mNodes.clear(); //Point3F pos; //F32 width; //for ( U32 i = 0; i < count; i++ ) //{ // mathRead( *stream, &pos ); // stream->read( &width ); // _addNode( pos, width ); //} if (stream->readFlag()) { // Nodes have been passed in this update U32 count = stream->readInt( 16 ); mNodes.clear(); Point3F pos; F32 width; for ( U32 i = 0; i < count; i++ ) { mathRead( *stream, &pos ); stream->read( &width ); _addNode( pos, width ); } } else { // Nodes will arrive as events U32 id; stream->read( &id ); // Check if the road's nodes made it here before we did. NodeListManager::NodeList* list = NULL; if ( gClientNodeListManager->findListById( id, &list, true) ) { // Work with the completed list DecalRoadNodeList* roadList = dynamic_cast<DecalRoadNodeList*>( list ); if (roadList) buildNodesFromList( roadList ); delete list; } else { // Nodes have not yet arrived, so register our interest in the list DecalRoadNodeListNotify* notify = new DecalRoadNodeListNotify( this, id ); gClientNodeListManager->registerNotification( notify ); } } } // GenEdgesMask if ( stream->readFlag() && isProperlyAdded() ) _generateEdges(); // ReClipMask if ( stream->readFlag() && isProperlyAdded() ) _captureVerts(); // TerrainChangedMask if ( stream->readFlag() ) { if ( isProperlyAdded() ) { if ( mTerrainUpdateRect.isOverlapped( getWorldBox() ) ) { _generateEdges(); _captureVerts(); // Clear out the mTerrainUpdateRect since we have updated its // region and we now need to store future terrain changes // in it. mTerrainUpdateRect = Box3F::Invalid; } } } }
void LightBase::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); mIsEnabled = stream->readFlag(); if ( stream->readFlag() ) // TransformMask stream->readAffineTransform( &mObjToWorld ); if ( stream->readFlag() ) // UpdateMask { stream->read( &mColor ); stream->read( &mBrightness ); mCastShadows = stream->readFlag(); stream->read( &mPriority ); mLight->unpackExtended( stream ); mAnimState.active = stream->readFlag(); stream->read( &mAnimState.animationPeriod ); stream->read( &mAnimState.animationPhase ); stream->read( &mFlareScale ); } if ( stream->readFlag() ) // DatablockMask { if ( stream->readFlag() ) { SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); LightAnimData *datablock = NULL; if ( Sim::findObject( id, datablock ) ) mAnimationData = datablock; else { conn->setLastError( "Light::unpackUpdate() - invalid LightAnimData!" ); mAnimationData = NULL; } } else mAnimationData = NULL; if ( stream->readFlag() ) { SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); LightFlareData *datablock = NULL; if ( Sim::findObject( id, datablock ) ) mFlareData = datablock; else { conn->setLastError( "Light::unpackUpdate() - invalid LightCoronaData!" ); mFlareData = NULL; } } else mFlareData = NULL; } if ( isProperlyAdded() ) _conformLights(); }
void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream) { Parent::unpackUpdate(con, stream); if ( stream->readFlag() ) // TimeMask { F32 temp = 0; stream->read( &temp ); setAzimuth( temp ); stream->read( &temp ); setElevation( temp ); } if ( stream->readFlag() ) // UpdateMask { stream->read( &mRayleighScattering ); stream->read( &mRayleighScattering4PI ); stream->read( &mMieScattering ); stream->read( &mMieScattering4PI ); stream->read( &mSunSize ); stream->read( &mSkyBrightness ); stream->read( &mMiePhaseAssymetry ); stream->read( &mSphereInnerRadius ); stream->read( &mSphereOuterRadius ); stream->read( &mScale ); ColorF tmpColor( 0, 0, 0 ); stream->read( &tmpColor ); stream->read( &mWavelength4[0] ); stream->read( &mWavelength4[1] ); stream->read( &mWavelength4[2] ); stream->read( &mRayleighScaleDepth ); stream->read( &mMieScaleDepth ); stream->read( &mNightColor ); stream->read( &mNightFogColor ); stream->read( &mAmbientScale ); stream->read( &mSunScale ); stream->read( &mFogScale ); F32 colorizeAmt; stream->read( &colorizeAmt ); if(mColorizeAmt != colorizeAmt) { mColorizeAmt = colorizeAmt; mShader = NULL; //forces shader refresh } stream->read( &mColorize ); if ( tmpColor != mWavelength ) { mWavelength = tmpColor; mWavelength4[0] = mPow(mWavelength[0], 4.0f); mWavelength4[1] = mPow(mWavelength[1], 4.0f); mWavelength4[2] = mPow(mWavelength[2], 4.0f); } stream->read( &mExposure ); stream->read( &mBrightness ); mCastShadows = stream->readFlag(); stream->read( &mFlareScale ); if ( stream->readFlag() ) { SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); LightFlareData *datablock = NULL; if ( Sim::findObject( id, datablock ) ) mFlareData = datablock; else { con->setLastError( "ScatterSky::unpackUpdate() - invalid LightFlareData!" ); mFlareData = NULL; } } else mFlareData = NULL; mMoonEnabled = stream->readFlag(); stream->read( &mMoonMatName ); stream->read( &mMoonScale ); stream->read( &mMoonTint ); mUseNightCubemap = stream->readFlag(); stream->read( &mNightCubemapName ); stream->read( &mMoonAzimuth ); stream->read( &mMoonElevation ); mLight->unpackExtended( stream ); if ( isProperlyAdded() ) { mDirty = true; _initMoon(); Sim::findObject( mNightCubemapName, mNightCubemap ); } } }
void Etherform::unpackUpdate(NetConnection *con, BitStream *bstream) { Parent::unpackUpdate(con,bstream); // controlled by the client? if(bstream->readFlag()) return; if (bstream->readFlag()) { Point3F pos,rot; bstream->read(&pos.x); bstream->read(&pos.y); bstream->read(&pos.z); bstream->read(&rot.x); bstream->read(&rot.z); F32 speed = mVelocity.len(); if(bstream->readFlag()) { bstream->readNormalVector(&mVelocity, 10); mVelocity *= bstream->readInt(13) / 32.0f; } else { mVelocity.set(0.0f, 0.0f, 0.0f); } delta.move.unpack(bstream); if(bstream->readFlag() && isProperlyAdded()) { // Determine number of ticks to warp based on the average // of the client and server velocities. delta.warpOffset = pos - delta.pos; F32 as = (speed + mVelocity.len()) * 0.5f * TickSec; F32 dt = (as > 0.00001f) ? delta.warpOffset.len() / as: sMaxWarpTicks; delta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f); if(delta.warpTicks) { // Setup the warp to start on the next tick. if(delta.warpTicks > sMaxWarpTicks) delta.warpTicks = sMaxWarpTicks; delta.warpOffset /= delta.warpTicks; delta.rotOffset = rot - delta.rot; delta.rotOffset /= delta.warpTicks; } else { // Going to skip the warp, server and client are real close. // Adjust the frame interpolation to move smoothly to the // new position within the current tick. if (delta.dt == 0.0f) { delta.posVec.set(0.0f, 0.0f, 0.0f); delta.rotVec.set(0.0f, 0.0f, 0.0f); } else { Point3F cp = delta.pos + delta.posVec * delta.dt; Point3F cr = delta.rot + delta.rotVec * delta.dt; F32 dti = 1.0f / delta.dt; delta.posVec = (cp - pos) * dti; delta.rotVec = (cr - rot) * dti; } delta.pos = pos; delta.rot = rot; this->setPosition(pos,rot); } } else { // Set the etherform to the server position delta.pos = pos; delta.rot = rot; delta.posVec.set(0.0f, 0.0f, 0.0f); delta.rotVec.set(0.0f, 0.0f, 0.0f); delta.warpTicks = 0; delta.dt = 0.0f; this->setPosition(pos, rot); } } }
void PxCloth::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); // TransformMask if ( stream->readFlag() ) { MatrixF mat; mathRead( *stream, &mat ); // start jc if(mCloth) { NxVec3 delta(mat.getPosition() - getTransform().getPosition()); if(mCloth->isSleeping()) mCloth->wakeUp(); if ( mAttachmentMask & BIT( 0 ) ) mCloth->attachVertexToGlobalPosition( 0, mCloth->getPosition( 0 ) + delta ); if ( mAttachmentMask & BIT( 1 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x-1, mCloth->getPosition( mPatchVerts.x-1 ) + delta ); if ( mAttachmentMask & BIT( 2 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x, mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x ) + delta ); if ( mAttachmentMask & BIT( 3 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - 1, mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - 1 ) + delta ); if ( mAttachmentMask & BIT( 4 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2), mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2) ) + delta ); if ( mAttachmentMask & BIT( 5 ) ) mCloth->attachVertexToGlobalPosition( (mPatchVerts.x/2), mCloth->getPosition( (mPatchVerts.x/2) ) + delta ); if ( mAttachmentMask & BIT( 6 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2), mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) ) + delta ); if ( mAttachmentMask & BIT( 7 ) ) mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1), mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1) ) + delta ); if ( mAttachmentMask & BIT( 8 ) ) for ( U32 i = mPatchVerts.x * mPatchVerts.y - mPatchVerts.x; i < mPatchVerts.x * mPatchVerts.y; i++ ) mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta ); if ( mAttachmentMask & BIT( 9 ) ) for ( U32 i = 0; i < mPatchVerts.x; i++ ) mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta ); if ( mAttachmentMask & BIT( 10 ) ) for ( U32 i = 0; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x ) mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta ); if ( mAttachmentMask & BIT( 11 ) ) for ( U32 i = mPatchVerts.x-1; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x ) mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta ); } // end jc setTransform( mat ); } // start jc // ScaleAttachmentPointsMask if ( stream->readFlag() ) { Point3F attachmentPointScale; mathRead( *stream, &attachmentPointScale ); if(mCloth) { Point3F scale(Point3F::One); scale.convolveInverse(mAttachmentPointScale); scale.convolve(attachmentPointScale); NxVec3 delta(scale); if(mCloth->isSleeping()) mCloth->wakeUp(); static NxVec3 delta2; if ( mAttachmentMask & BIT( 0 ) ) { delta2.arrayMultiply(mCloth->getPosition( 0 ),delta); mCloth->attachVertexToGlobalPosition( 0, delta2); } if ( mAttachmentMask & BIT( 1 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x-1 ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x-1, delta2); } if ( mAttachmentMask & BIT( 2 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x, delta2); } if ( mAttachmentMask & BIT( 3 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - 1 ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - 1, delta2); } if ( mAttachmentMask & BIT( 4 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2) ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2), delta2); } if ( mAttachmentMask & BIT( 5 ) ) { delta2.arrayMultiply(mCloth->getPosition( (mPatchVerts.x/2) ), delta); mCloth->attachVertexToGlobalPosition( (mPatchVerts.x/2), delta2); } if ( mAttachmentMask & BIT( 6 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2), delta2); } if ( mAttachmentMask & BIT( 7 ) ) { delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1) ), delta); mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1), delta2); } if ( mAttachmentMask & BIT( 8 ) ) for ( U32 i = mPatchVerts.x * mPatchVerts.y - mPatchVerts.x; i < mPatchVerts.x * mPatchVerts.y; i++ ) { delta2.arrayMultiply(mCloth->getPosition( i ), delta); mCloth->attachVertexToGlobalPosition( i, delta2); } if ( mAttachmentMask & BIT( 9 ) ) for ( U32 i = 0; i < mPatchVerts.x; i++ ) { delta2.arrayMultiply(mCloth->getPosition( i ), delta); mCloth->attachVertexToGlobalPosition( i, delta2); } if ( mAttachmentMask & BIT( 10 ) ) for ( U32 i = 0; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x ) { delta2.arrayMultiply(mCloth->getPosition( i ), delta); mCloth->attachVertexToGlobalPosition( i, delta2); } if ( mAttachmentMask & BIT( 11 ) ) for ( U32 i = mPatchVerts.x-1; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x ) { delta2.arrayMultiply(mCloth->getPosition( i ), delta); mCloth->attachVertexToGlobalPosition( i, delta2); } } mAttachmentPointScale = attachmentPointScale; } // end jc // MaterialMask if ( stream->readFlag() ) { stream->read( &mMaterialName ); SAFE_DELETE( mMatInst ); } // ClothMask if ( stream->readFlag() ) { Point2I patchVerts; Point2F patchSize; mathRead( *stream, &patchVerts ); mathRead( *stream, &patchSize ); if ( patchVerts != mPatchVerts || !patchSize.equal( mPatchSize ) ) { mPatchVerts = patchVerts; mPatchSize = patchSize; _releaseMesh(); } U32 attachMask; stream->read( &attachMask ); if ( attachMask != mAttachmentMask ) { mAttachmentMask = attachMask; _releaseCloth(); } mBendingEnabled = stream->readFlag(); mDampingEnabled = stream->readFlag(); mTriangleCollisionEnabled = stream->readFlag(); mSelfCollisionEnabled = stream->readFlag(); stream->read( &mThickness ); stream->read( &mFriction ); stream->read( &mBendingStiffness ); stream->read( &mDampingCoefficient ); F32 density; stream->read( &density ); if ( density != mDensity ) { mDensity = density; _releaseCloth(); } if ( isClientObject() && isProperlyAdded() && mWorld && !mCloth ) { _createClothPatch(); } _updateClothProperties(); } }
void PxCloth::unpackUpdate( NetConnection *conn, BitStream *stream ) { Parent::unpackUpdate( conn, stream ); // TransformMask if ( stream->readFlag() ) { MatrixF mat; mathRead( *stream, &mat ); setTransform( mat ); } // MaterialMask if ( stream->readFlag() ) { stream->read( &mMaterialName ); SAFE_DELETE( mMatInst ); } // ClothMask if ( stream->readFlag() ) { Point2I patchVerts; Point2F patchSize; mathRead( *stream, &patchVerts ); mathRead( *stream, &patchSize ); if ( patchVerts != mPatchVerts || !patchSize.equal( mPatchSize ) ) { mPatchVerts = patchVerts; mPatchSize = patchSize; _releaseMesh(); } U32 attachMask; stream->read( &attachMask ); if ( attachMask != mAttachmentMask ) { mAttachmentMask = attachMask; _releaseCloth(); } mBendingEnabled = stream->readFlag(); mDampingEnabled = stream->readFlag(); mTriangleCollisionEnabled = stream->readFlag(); mSelfCollisionEnabled = stream->readFlag(); stream->read( &mThickness ); stream->read( &mFriction ); stream->read( &mBendingStiffness ); stream->read( &mDampingCoefficient ); F32 density; stream->read( &density ); if ( density != mDensity ) { mDensity = density; _releaseCloth(); } if ( isClientObject() && isProperlyAdded() && mWorld && !mCloth ) { _createClothPatch(); } _updateClothProperties(); } }
void Item::unpackUpdate(NetConnection *connection, BitStream *stream) { Parent::unpackUpdate(connection,stream); // InitialUpdateMask if (stream->readFlag()) { mRotate = stream->readFlag(); mStatic = stream->readFlag(); if (stream->readFlag()) mathRead(*stream, &mObjScale); else mObjScale.set(1, 1, 1); } // ThrowSrcMask && mCollisionObject if (stream->readFlag()) { S32 gIndex = stream->readInt(NetConnection::GhostIdBitSize); setCollisionTimeout(static_cast<ShapeBase*>(connection->resolveGhost(gIndex))); } MatrixF mat = mObjToWorld; // RotationMask && !mRotate if (stream->readFlag()) { // Assumes rotation is about the Z axis AngAxisF aa; aa.axis.set(0.0f, 0.0f, stream->readFlag() ? -1.0f : 1.0f); stream->read(&aa.angle); aa.setMatrix(&mat); Point3F pos; mObjToWorld.getColumn(3,&pos); mat.setColumn(3,pos); } // PositionMask if (stream->readFlag()) { Point3F pos; mathRead(*stream, &pos); F32 speed = mVelocity.len(); if ((mAtRest = stream->readFlag()) == true) mVelocity.set(0.0f, 0.0f, 0.0f); else mathRead(*stream, &mVelocity); if (stream->readFlag() && isProperlyAdded()) { // Determin number of ticks to warp based on the average // of the client and server velocities. delta.warpOffset = pos - delta.pos; F32 as = (speed + mVelocity.len()) * 0.5f * TickSec; F32 dt = (as > 0.00001f) ? delta.warpOffset.len() / as: sMaxWarpTicks; delta.warpTicks = (S32)((dt > sMinWarpTicks)? getMax(mFloor(dt + 0.5f), 1.0f): 0.0f); if (delta.warpTicks) { // Setup the warp to start on the next tick, only the // object's position is warped. if (delta.warpTicks > sMaxWarpTicks) delta.warpTicks = sMaxWarpTicks; delta.warpOffset /= (F32)delta.warpTicks; } else { // Going to skip the warp, server and client are real close. // Adjust the frame interpolation to move smoothly to the // new position within the current tick. Point3F cp = delta.pos + delta.posVec * delta.dt; VectorF vec = delta.pos - cp; F32 vl = vec.len(); if (vl) { F32 s = delta.posVec.len() / vl; delta.posVec = (cp - pos) * s; } delta.pos = pos; mat.setColumn(3,pos); } } else { // Set the item to the server position delta.warpTicks = 0; delta.posVec.set(0,0,0); delta.pos = pos; delta.dt = 0; mat.setColumn(3,pos); } } Parent::setTransform(mat); }
void ConvexShape::onScaleChanged() { if ( isProperlyAdded() ) _updateCollision(); }
void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream ) { // Unpack Parent. Parent::unpackUpdate( con, stream ); // NodeMask if ( stream->readFlag() ) { U32 count = stream->readInt( 16 ); mNodes.clear(); Point3F pos; F32 width; for ( U32 i = 0; i < count; i++ ) { mathRead( *stream, &pos ); stream->read( &width ); _addNode( pos, width ); } } // DecalRoadMask if ( stream->readFlag() ) { String matName; stream->read( &matName ); if ( matName != mMaterialName ) { mMaterialName = matName; Material *pMat = NULL; if ( !Sim::findObject( mMaterialName, pMat ) ) { Con::printf( "DecalRoad::unpackUpdate, failed to find Material of name %s!", mMaterialName.c_str() ); } else { mMaterial = pMat; if ( isProperlyAdded() ) _initMaterial(); } } stream->read( &mBreakAngle ); stream->read( &mSegmentsPerBatch ); stream->read( &mTextureLength ); stream->read( &mRenderPriority ); } // GenEdgesMask if ( stream->readFlag() && isProperlyAdded() ) _generateEdges(); // ReClipMask if ( stream->readFlag() && isProperlyAdded() ) _captureVerts(); // TerrainChangedMask if ( stream->readFlag() ) { if ( isProperlyAdded() ) { if ( mTerrainUpdateRect.isOverlapped( getWorldBox() ) ) { _generateEdges(); _captureVerts(); // Clear out the mTerrainUpdateRect since we have updated its // region and we now need to store future terrain changes // in it. mTerrainUpdateRect = Box3F::Invalid; } } } }