Example #1
0
/*
================
sdPhysics_Linear::WriteNetworkState
================
*/
void sdPhysics_Linear::WriteNetworkState( networkStateMode_t mode, const sdEntityStateNetworkData& baseState, sdEntityStateNetworkData& newState, idBitMsg& msg ) const {
	if ( mode == NSM_BROADCAST ) {
		NET_GET_STATES( sdPhysicsLinearBroadcastData );

		// update state
		newData.atRest				= current.atRest;
		newData.localOrigin			= current.localOrigin;
		newData.baseSpeed			= current.linearExtrapolation.GetBaseSpeed();
		newData.duration			= SEC2MS( current.linearExtrapolation.GetDuration() );
		newData.extrapolationType	= current.linearExtrapolation.GetExtrapolationType();
		newData.speed				= current.linearExtrapolation.GetSpeed();
		newData.startTime			= SEC2MS( current.linearExtrapolation.GetStartTime() );
		newData.startValue			= current.linearExtrapolation.GetStartValue();

		// write state
		msg.WriteDeltaLong( baseData.atRest, newData.atRest );
		msg.WriteDeltaVector( baseData.localOrigin, newData.localOrigin );
		msg.WriteDeltaVector( baseData.baseSpeed, newData.baseSpeed );
		msg.WriteDeltaLong( baseData.duration, newData.duration );
		msg.WriteDelta( baseData.extrapolationType, newData.extrapolationType, 8 );
		msg.WriteDeltaVector( baseData.speed, newData.speed );
		msg.WriteDeltaLong( baseData.startTime, newData.startTime );
		msg.WriteDeltaVector( baseData.startValue, newData.startValue );

		return;
	}
}
Example #2
0
/*
================
idScriptObject::WriteNetworkState
================
*/
void idScriptObject::WriteNetworkState( networkStateMode_t mode, const sdEntityStateNetworkData& baseState, sdEntityStateNetworkData& newState, idBitMsg& msg ) const {
	NET_GET_STATES( sdScriptObjectNetworkData );
	SetupStateData( mode, newData );

	baseData.Reset();
	newData.Reset();

	for ( int i = 0; i < networkFields[ mode ].fields.Num(); i++ ) {
		const networkFieldSync_t& value = networkFields[ mode ].fields[ i ];

		switch( value.type ) {
			case ev_object: {
				idScriptObject* object = gameLocal.program->GetScriptObject( *reinterpret_cast< int* >( value.data ) );
				int id = 0;
				if ( object ) {
					idEntity* ent = object->GetClass()->Cast< idEntity >();
					id = gameLocal.GetSpawnId( ent );
				}
				
				const int& oldBase = baseData.GetInt();
				int& newBase = newData.GetInt();

				newBase = id;

				msg.WriteDeltaLong( oldBase, newBase );

				break;
			}
			case ev_vector: {
				const idVec3& oldBase = baseData.GetVector();
				idVec3& newBase = newData.GetVector();

				newBase = *reinterpret_cast< idVec3* >( value.data );

				msg.WriteDeltaVector( oldBase, newBase );
				break;
			}
			case ev_float: {
				const float& oldBase = baseData.GetFloat();
				float& newBase = newData.GetFloat();

				newBase = *reinterpret_cast< float* >( value.data );

				msg.WriteDeltaFloat( oldBase, newBase );
				break;
			}
			case ev_boolean: {
				const int& oldBase = baseData.GetInt();
				int& newBase = newData.GetInt();

				newBase = *reinterpret_cast< int* >( value.data ) != 0;

				msg.WriteBits( newBase, 1 );
				break;
			}
		}
	}
}