void Client_ReceiveBodiesPositions( RemoteEntityWorld sender, ReceiveDataReader reader ) { //clear snapshots cache if entity is not created if( !IsPostCreated ) client_receivePositionsSnapshots.Clear(); //check for invalid snapshot cache if( client_receivePositionsSnapshots.Count != 0 ) { Client_ReceivePositionsSnapshot lastSnapshot = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ]; if( lastSnapshot.bodies == null ) { //remove snapshot cache client_receivePositionsSnapshots.Clear(); } } int count = (int)reader.ReadVariableUInt32(); Client_ReceivePositionsSnapshot snapshot = new Client_ReceivePositionsSnapshot(); snapshot.networkTickNumber = EntitySystemWorld.Instance.NetworkTickCounter; snapshot.bodies = new Client_ReceivePositionsSnapshot.BodyItem[ count ]; //receive bodies positions and rotations for( int n = 0; n < count; n++ ) { Client_ReceivePositionsSnapshot.BodyItem bodyItem = new Client_ReceivePositionsSnapshot.BodyItem(); //read position if( reader.ReadBoolean() ) { bodyItem.position = reader.ReadVec3(); } else { //get position from previous snapshot if( client_receivePositionsSnapshots.Count != 0 ) { bodyItem.position = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ].bodies[ n ].position; } } //read rotation if( reader.ReadBoolean() ) { bodyItem.rotation = reader.ReadQuat( 16 ); } else { //get rotation from previous snapshot if( client_receivePositionsSnapshots.Count != 0 ) { bodyItem.rotation = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ].bodies[ n ].rotation; } } snapshot.bodies[ n ] = bodyItem; } if( !reader.Complete() ) return; client_receivePositionsSnapshots.Add( snapshot ); if( IsPostCreated ) Client_UpdatePositionsBySnapshots( false ); }
void Client_ReceivePositions( RemoteEntityWorld sender, ReceiveDataReader reader ) { //clear snanshots cache if entity is not created if( !IsPostCreated ) client_receivePositionsSnapshots.Clear(); //check for invalid snapshot cache if( client_receivePositionsSnapshots.Count != 0 ) { Client_ReceivePositionsSnapshot lastSnapshot = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ]; if( lastSnapshot.bodies != null ) { //remove snapshot cache client_receivePositionsSnapshots.Clear(); } } Client_ReceivePositionsSnapshot snapshot = new Client_ReceivePositionsSnapshot(); snapshot.networkTickNumber = EntitySystemWorld.Instance.NetworkTickCounter; //read position if( reader.ReadBoolean() ) { snapshot.position = reader.ReadVec3(); } else { //get position from previous snapshot if( client_receivePositionsSnapshots.Count != 0 ) { snapshot.position = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ].position; } } //read rotation if( reader.ReadBoolean() ) { snapshot.rotation = reader.ReadQuat( 16 ); } else { //get rotation from previous snapshot if( client_receivePositionsSnapshots.Count != 0 ) { snapshot.rotation = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ].rotation; } } //read scale if( reader.ReadBoolean() ) { snapshot.scale = reader.ReadVec3(); } else { //get position from previous snapshot if( client_receivePositionsSnapshots.Count != 0 ) { snapshot.scale = client_receivePositionsSnapshots[ client_receivePositionsSnapshots.Count - 1 ].scale; } } if( !reader.Complete() ) return; client_receivePositionsSnapshots.Add( snapshot ); Client_UpdatePositionsBySnapshots( false ); }
void Client_GetReceivePositionsSnapshots( int networkTickNumber, out Client_ReceivePositionsSnapshot snapshot1, out Client_ReceivePositionsSnapshot snapshot2) { for( int n = client_receivePositionsSnapshots.Count - 1; n >= 0; n-- ) { Client_ReceivePositionsSnapshot snapshot = client_receivePositionsSnapshots[ n ]; if( networkTickNumber >= snapshot.networkTickNumber ) { snapshot1 = snapshot; snapshot2 = null; if( n + 1 < client_receivePositionsSnapshots.Count ) { Client_ReceivePositionsSnapshot nextSnapshot = client_receivePositionsSnapshots[ n + 1 ]; if( networkTickNumber + 1 == nextSnapshot.networkTickNumber ) snapshot2 = nextSnapshot; } return; } } snapshot1 = client_receivePositionsSnapshots[ 0 ]; snapshot2 = null; }