//------------------------------------------------------------------------ bool CProjectile::NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int pflags) { if(aspect == eEA_Physics) { pe_type type = PE_NONE; switch(profile) { case ePT_Rigid: type = PE_RIGID; break; case ePT_Particle: type = PE_PARTICLE; break; case ePT_None: return true; case ePT_Static: { Vec3 pos = GetEntity()->GetWorldPos(); Quat ori = GetEntity()->GetWorldRotation(); ser.Value("pos", pos, 'wrld'); ser.Value("ori", ori, 'ori1'); if(ser.IsReading()) GetEntity()->SetWorldTM(Matrix34::Create(Vec3(1,1,1), ori, pos)); } return true; default: return false; } IEntityPhysicalProxy *pEPP = (IEntityPhysicalProxy *) GetEntity()->GetProxy(ENTITY_PROXY_PHYSICS); if(ser.IsWriting()) { if(!pEPP || !pEPP->GetPhysicalEntity() || pEPP->GetPhysicalEntity()->GetType() != type) { gEnv->pPhysicalWorld->SerializeGarbageTypedSnapshot(ser, type, 0); return true; } } else if(!pEPP) { return false; } pEPP->SerializeTyped(ser, type, pflags); } return true; }
//----------------------------------------------------------------------------- bool CNetworkedPhysicsEntity::NetSerialize( TSerialize ser, EEntityAspects aspect, uint8 profile, int flags ) { NET_PROFILE_SCOPE("NetworkedPhysicsEntity", ser.IsReading()); if (aspect == eEA_Physics) { pe_type type = PE_NONE; switch (profile) { case ePhys_PhysicalizedRigid: { type = PE_RIGID; break; } case ePhys_PhysicalizedStatic: { type = PE_STATIC; // Serialise the position ourselves - physics system won't do it for static entities const Matrix34 &worldTM = GetEntity()->GetWorldTM(); Vec3 worldPos = worldTM.GetTranslation(); ser.Value("worldPos", worldPos, 'wrld'); if (ser.IsReading()) { Matrix34 newTM = worldTM; newTM.SetTranslation(worldPos); GetEntity()->SetWorldTM(newTM); } break; } } if (type == PE_NONE) return true; IEntityPhysicalProxy * pEPP = (IEntityPhysicalProxy *) GetEntity()->GetProxy(ENTITY_PROXY_PHYSICS); if (ser.IsWriting()) { if (!pEPP || !pEPP->GetPhysicalEntity() || pEPP->GetPhysicalEntity()->GetType() != type) { gEnv->pPhysicalWorld->SerializeGarbageTypedSnapshot( ser, type, 0 ); return true; } } else if (!pEPP) { return false; } pEPP->SerializeTyped( ser, type, flags ); } return true; }
bool CMonoActor::NetSerialize( TSerialize ser, EEntityAspects aspect, uint8 profile, int pflags ) { if (aspect == eEA_Physics) { pe_type type = PE_NONE; switch (profile) { case eAP_NotPhysicalized: type = PE_NONE; break; case eAP_Spectator: type = PE_LIVING; break; case eAP_Alive: type = PE_LIVING; break; case eAP_Sleep: type = PE_ARTICULATED; break; case eAP_Frozen: type = PE_RIGID; break; case eAP_Ragdoll: type = PE_ARTICULATED; break; case eAP_Linked: //if actor is attached to a vehicle - don't serialize actor physics additionally return true; break; default: return false; } // TODO: remove this when craig fixes it in the network system if (profile==eAP_Spectator) { int x=0; ser.Value("unused", x, 'skip'); } else if (profile==eAP_Sleep) { int x=0; ser.Value("unused1", x, 'skip'); ser.Value("unused2", x, 'skip'); } if (type == PE_NONE) return true; IEntityPhysicalProxy * pEPP = (IEntityPhysicalProxy *) GetEntity()->GetProxy(ENTITY_PROXY_PHYSICS); if (ser.IsWriting()) { if (!pEPP || !pEPP->GetPhysicalEntity() || pEPP->GetPhysicalEntity()->GetType() != type) { gEnv->pPhysicalWorld->SerializeGarbageTypedSnapshot( ser, type, 0 ); return true; } } else if (!pEPP) { return false; } // PLAYERPREDICTION if(type!=PE_LIVING) { pEPP->SerializeTyped( ser, type, pflags ); } // ~PLAYERPREDICTION } ser.BeginGroup("ManagedActor"); IMonoArray *pArgs = CreateMonoArray(4); pArgs->InsertNativePointer(&ser); pArgs->Insert(aspect); pArgs->Insert(profile); pArgs->Insert(pflags); m_pScript->GetClass()->InvokeArray(m_pScript, "InternalNetSerialize", pArgs); ser.EndGroup(); return true; }