public static void SetPosition(this Biota biota, PositionType positionType, Position position) { var result = biota.BiotaPropertiesPosition.FirstOrDefault(x => x.PositionType == (uint)positionType); if (result != null) { result.ObjCellId = position.ObjCellID; result.OriginX = position.Pos.X; result.OriginY = position.Pos.Y; result.OriginZ = position.Pos.Z; result.AnglesW = position.Rotation.W; result.AnglesX = position.Rotation.X; result.AnglesY = position.Rotation.Y; result.AnglesZ = position.Rotation.Z; result.Instance = position.Instance; } else { var entity = new BiotaPropertiesPosition { ObjectId = biota.Id, PositionType = (ushort)positionType, ObjCellId = position.ObjCellID, OriginX = position.Pos.X, OriginY = position.Pos.Y, OriginZ = position.Pos.Z, AnglesW = position.Rotation.W, AnglesX = position.Rotation.X, AnglesY = position.Rotation.Y, AnglesZ = position.Rotation.Z, Instance = position.Instance, Object = biota }; biota.BiotaPropertiesPosition.Add(entity); } }
public static void SetPosition(this Biota biota, PositionType positionType, Position position, ReaderWriterLockSlim rwLock, out bool biotaChanged) { rwLock.EnterUpgradeableReadLock(); try { var result = biota.BiotaPropertiesPosition.FirstOrDefault(x => x.PositionType == (uint)positionType); if (result != null) { biotaChanged = true; // we just assume at least one of the values changed... result.ObjCellId = position.Cell; result.OriginX = position.PositionX; result.OriginY = position.PositionY; result.OriginZ = position.PositionZ; result.AnglesW = position.RotationW; result.AnglesX = position.RotationX; result.AnglesY = position.RotationY; result.AnglesZ = position.RotationZ; } else { rwLock.EnterWriteLock(); try { var entity = new BiotaPropertiesPosition { ObjectId = biota.Id, PositionType = (ushort)positionType, ObjCellId = position.Cell, OriginX = position.PositionX, OriginY = position.PositionY, OriginZ = position.PositionZ, AnglesW = position.RotationW, AnglesX = position.RotationX, AnglesY = position.RotationY, AnglesZ = position.RotationZ, Object = biota }; biota.BiotaPropertiesPosition.Add(entity); biotaChanged = true; } finally { rwLock.ExitWriteLock(); } } } finally { rwLock.ExitUpgradeableReadLock(); } }
public static bool TryRemovePosition(this Biota biota, PositionType positionType, out BiotaPropertiesPosition entity, ReaderWriterLockSlim rwLock) { rwLock.EnterUpgradeableReadLock(); try { entity = biota.BiotaPropertiesPosition.FirstOrDefault(x => x.PositionType == (uint)positionType); if (entity != null) { rwLock.EnterWriteLock(); try { biota.BiotaPropertiesPosition.Remove(entity); entity.Object = null; return(true); } finally { rwLock.ExitWriteLock(); } } return(false); } finally { rwLock.ExitUpgradeableReadLock(); } }
public static bool TryRemovePosition(this Biota biota, PositionType positionType, out BiotaPropertiesPosition entity) { entity = biota.BiotaPropertiesPosition.FirstOrDefault(x => x.PositionType == (uint)positionType); if (entity != null) { biota.BiotaPropertiesPosition.Remove(entity); entity.Object = null; return true; } return false; }