public void Init(ShipyardType yardType) { if (YardType == yardType) { return; } Logging.Instance.WriteDebug("YardItem.Init: " + yardType); YardType = yardType; foreach (IMyCubeGrid grid in ContainsGrids) { ((MyCubeGrid)grid).OnGridSplit += OnGridSplit; } YardGrids = ContainsGrids.Where(x => !x.Closed && !x.MarkedForClose).ToList(); ContainsGrids.Clear(); IntersectsGrids.Clear(); Utilities.Invoke(() => { foreach (IMyCubeBlock tool in Tools) { var myFunctionalBlock = tool as IMyFunctionalBlock; if (myFunctionalBlock != null) { myFunctionalBlock.Enabled = true; //.RequestEnable(true); } } }); Communication.SendYardState(this); }
// Update the state machine, try changing state. public void Update() { if (CurrentNode == null) { m_enqueuedActions.Clear(); return; } int maxPassThrough = 100; MyStateMachineNode nextNode; do { nextNode = null; int transitionId = -1; // enqueued transitions (actions) first if (m_enqueuedActions.Count > 0) { int bestPriority = int.MaxValue; foreach (var transition in CurrentNode.Transitions) { int transitionPriority = transition.Priority ?? int.MaxValue; if (transitionPriority <= bestPriority && m_enqueuedActions.Contains(transition.Name) && (transition.Conditions.Count == 0 || transition.Evaluate())) { transitionId = transition.Id; nextNode = transition.TargetNode; bestPriority = transitionPriority; } } } // transitions checking conditions if (nextNode == null) { nextNode = CurrentNode.QueryNewState(false, out transitionId); } // now try to transfer from one state to another if (nextNode != null) { //var fromNode = CurrentNode; var transitionWithStart = m_transitions[transitionId]; CurrentNode = nextNode; NotifyStateChanged(transitionWithStart); } } while (nextNode != null && // we changed state CurrentNode.PassThrough && // we want to pass through maxPassThrough-- > 0); // safety, prevent infinite loop caused by wrong data m_enqueuedActions.Clear(); if (CurrentNode != null) { CurrentNode.OnUpdate(this); } }
/// <summary> /// Update the state machine. Transition to new states. /// </summary> public virtual void Update() { m_activeCursors.ApplyChanges(); if (m_activeCursorsById.Count == 0) { m_enqueuedActions.Clear(); return; } foreach (var cursor in m_activeCursors) { cursor.Node.Expand(cursor, m_enqueuedActions); cursor.Node.OnUpdate(this); } m_enqueuedActions.Clear(); }
public override void Update() { m_activeCursors.ApplyChanges(); // Lazy Deserialize of the scripts. // Mandatory because at this point we know that the SM structure is valid. foreach (var cursor in m_cursorsToDeserialize) { var vsNode = cursor.Node as MyVSStateMachineNode; if (vsNode != null) { vsNode.ActivateScript(true); } } m_cursorsToDeserialize.Clear(); // Lazy init of the scripts foreach (var cursor in m_cursorsToInit) { var vsNode = cursor.Node as MyVSStateMachineNode; if (vsNode != null) { vsNode.ActivateScript(); } } m_cursorsToInit.Clear(); foreach (var action in m_cachedActions) { m_enqueuedActions.Add(action); } m_cachedActions.Clear(); base.Update(); }
static public void RevealAll( ) { _checkReveal = true; HashSet <MyEntity> entities = new HashSet <MyEntity>(); Wrapper.GameAction(() => entities = MyEntities.GetEntities()); foreach (var entity in entities.ToArray()) { var grid = entity as MyCubeGrid; if (grid == null) { continue; } if (PluginSettings.Instance.DynamicShowMessages && RemovedGrids.Contains(entity.EntityId)) { Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ((MyCubeGrid)entity).BigOwners.FirstOrDefault(), PlayerMap.Instance.GetPlayerNameFromPlayerId(((MyCubeGrid)entity).BigOwners.FirstOrDefault()), "Force reveal"); } Wrapper.GameAction(() => ReregisterHierarchy(entity.GetTopMostParent( ))); } RemovedGrids.Clear(); _checkReveal = false; }
public override void Update() { foreach (var action in m_cachedActions) { m_enqueuedActions.Add(action); } m_cachedActions.Clear(); base.Update(); }
public void Dispose() { m_availableVoices.Clear(); m_fadingOutVoices.Clear(); m_currentCount = 0; m_audioEngine = null; m_owner = null; foreach (var v in m_allVoices) { v.Cleanup(); m_voiceBuffer.Add(v); } m_allVoices.Clear(); }
public void Clear() { _hashSet.Clear(); _queue.Clear(); }
public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); if (!Sync.IsServer || !IsWorking) { return; } if (!ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId)) { if (ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, BlockDefinition.RequiredPowerInput)) { float origInput = ResourceSink.RequiredInputByType(MyResourceDistributorComponent.ElectricityId); ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, 0); ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, origInput); } else { return; } } var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up); var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field"); if (m_recreateField) { m_recreateField = false; m_fieldShape.RemoveReference(); m_fieldShape = GetHkShape(); ResourceSink.Update(); } VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).TransformFast(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition()); m_potentialPenetrations.Clear(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations); m_potentialVoxelPenetrations.Clear(); MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics"); LastDetectedEntity = null; bool empty = true; m_detectedEntities.Clear(); //foreach (var entity in m_potentialPenetrations) Parallel.ForEach(m_potentialPenetrations, entity => { if (entity is MyVoxelBase) { //voxels are handled in different loop (becaose of planets) return; } if (ShouldDetect(entity)) { Quaternion rotation2; Vector3 posDiff; HkShape?shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { if (LastDetectedEntity == null) { LastDetectedEntity = entity; } empty = false; //entities.Add(entity); var inf = MyDetectedEntityInfoHelper.Create(entity, this.OwnerId); m_detectedEntities.Add(inf); } } } }); if (DetectAsteroids) { //foreach (var entity in m_potentialVoxelPenetrations) Parallel.ForEach(m_potentialVoxelPenetrations, entity => { var voxel = entity as MyVoxelPhysics; if (voxel != null) { Vector3D localPositionMin, localPositionMax; MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin); MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax); var aabb = new BoundingBox(localPositionMin, localPositionMax); aabb.Translate(voxel.StorageMin); if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint) { if (LastDetectedEntity == null) { LastDetectedEntity = entity; } empty = false; //entities.Add(entity); var inf = MyDetectedEntityInfoHelper.Create(entity, this.OwnerId); m_detectedEntities.Add(inf); } } else { Quaternion rotation2; Vector3 posDiff; HkShape?shape2; if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2)) { if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2)) { if (LastDetectedEntity == null) { LastDetectedEntity = entity; } empty = false; //entities.Add(entity); var inf = MyDetectedEntityInfoHelper.Create(entity, this.OwnerId); m_detectedEntities.Add(inf); } } } }); } IsActive = !empty; m_potentialPenetrations.Clear(); m_potentialVoxelPenetrations.Clear(); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); }