/// <summary>
 /// Finds a path using waypoints. Use whenever the direct path is blocked.
 /// </summary>
 /// <param name="from">First endpoint of the path. Will be duplicated in the returned path.</param>
 /// <param name="to">First endpoint of the path. Will be duplicated in the returned path.</param>
 /// <param name="pathFoundHandler">To be called after the pathfinder is finished. Will receive the found path, or null when there's none.</param>
 /// <param name="userData">An object that will be passed to pathFoundHandler. Can be used to identify the query.</param>
 /// <param name="useRaycasts">Whether the bot should use raycasts.</param>
 public static void FindPathInBackground(Vector3 from, Vector3 to, PathFoundHandler pathFoundHandler, object userData, bool useRaycasts)
 {
     MyCommonDebugUtils.AssertDebug(from != null && to != null && pathFoundHandler != null);
     m_queue.Enqueue(new PathToBeFound(from, to, pathFoundHandler, userData, useRaycasts));
     //m_event.Set();
     m_findPathTask = Parallel.Start(m_pathfindingHelper);
 }
Example #2
0
 public void ScheduleRefresh()
 {
     lock (this)
     {
         if (_task.IsComplete)
         {
             _task = ParallelTasks.Parallel.Start(this);
         }
     }
 }
 void OnDetails(MyGuiControlButton button)
 {
     if (m_selectedItem == null)
     {
         if (m_activeDetail)
         {
             MyScreenManager.RemoveScreen(m_detailScreen);
         }
         return;
     }
     else if(m_activeDetail)
     {
         MyScreenManager.RemoveScreen(m_detailScreen);
     }
     else if (!m_activeDetail)
     {
         MyBlueprintItemInfo blueprintInfo = (m_selectedItem.UserData as MyBlueprintItemInfo);
         if (blueprintInfo.Type == MyBlueprintTypeEnum.LOCAL)
         {
             var path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen = new MyGuiDetailScreenLocal(
                     callBack: delegate(MyGuiControlListbox.Item item)
                     {
                         if (item == null)
                         {
                             m_screenshotButton.Enabled = false;
                             m_detailsButton.Enabled = false;
                             m_replaceButton.Enabled = false;
                             m_deleteButton.Enabled = false;
                         }
                         m_selectedItem = item;
                         m_activeDetail = false;
                         m_detailScreen = null;
                         if (Task.IsComplete)
                         {
                             RefreshBlueprintList();
                         }
                     },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             buttonType: MyMessageBoxButtonsType.OK,
                             styleEnum: MyMessageBoxStyleEnum.Error,
                             messageCaption: new StringBuilder("Error"),
                             messageText: new StringBuilder("Cannot find the blueprint file.")
                             ));
             }
         }
         else if (blueprintInfo.Type == MyBlueprintTypeEnum.DEFAULT)
         {
             var path = Path.Combine(m_defaultBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen = new MyGuiDetailScreenDefault(
                     callBack: delegate(MyGuiControlListbox.Item item)
                     {
                         if (item == null)
                         {
                             m_screenshotButton.Enabled = false;
                             m_detailsButton.Enabled = false;
                             m_replaceButton.Enabled = false;
                             m_deleteButton.Enabled = false;
                         }
                         m_selectedItem = item;
                         m_activeDetail = false;
                         m_detailScreen = null;
                         if (Task.IsComplete)
                         {
                             RefreshBlueprintList();
                         }
                     },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                             buttonType: MyMessageBoxButtonsType.OK,
                             styleEnum: MyMessageBoxStyleEnum.Error,
                             messageCaption: new StringBuilder("Error"),
                             messageText: new StringBuilder("Cannot find the blueprint file.")
                             ));
             }
         }
         else if (blueprintInfo.Type == MyBlueprintTypeEnum.STEAM)
         {
             MySteamWorkshop.SubscribedItem workshopData = blueprintInfo.Item;
             Task = Parallel.Start(() => {
                 if (MySteamWorkshop.IsBlueprintUpToDate(workshopData) == false) 
                 { 
                     DownloadBlueprintFromSteam(workshopData);
                 } 
             }, () => { OnBlueprintDownloadedDetails(workshopData); });               
         }
     }
 }
        void Ok()
        {
            if (m_selectedItem == null)
            {
                CloseScreen();
                return;
            }

            var itemInfo = m_selectedItem.UserData as MyBlueprintItemInfo;
            if (itemInfo.Type == MyBlueprintTypeEnum.SHARED)
            {
                OpenSharedBlueprint(itemInfo);
            }
            else
            {
                if (MySession.Static.SurvivalMode && MySession.Static.IsAdminModeEnabled == false && m_clipboard == Sandbox.Game.Entities.MyCubeBuilder.Static.Clipboard)
                {
                    CloseScreen();
                }
                else
                {
                    if (itemInfo.Type == MyBlueprintTypeEnum.STEAM)
                    {
                        Task = Parallel.Start(() =>
                        {
                            if (MySteamWorkshop.IsBlueprintUpToDate(itemInfo.Item) == false)
                            {
                                DownloadBlueprintFromSteam(itemInfo.Item);
                            }
                        }, () => { CopyBlueprintAndClose(); });
                    }
                    else
                    {
                        CopyBlueprintAndClose();
                    }
                }
            }
        }
        void GetWorkshopBlueprints()
        {
            if (MyFakes.XB1_PREVIEW)
                return;

            Task = Parallel.Start(DownloadBlueprints);
        }
        public static void Update()
        {
            if (App.MyMinerGame.IsPaused())
                return;
            MyPerformanceCounter.PerCameraDraw.ParticleEffectsTotal = 0;
            MyPerformanceCounter.PerCameraDraw.ParticleEffectsDrawn = 0;

            if (MultithreadedUpdater)
            {
                WaitUntilUpdateCompleted();

                m_updaterTask = Parallel.Start(m_updateEffectsWork, null);
            }
            else
            {
                UpdateEffects();
            }
        }
Example #7
0
 public void StartBackground(byte[] keyFrame = null)
 {
     lastKeyframe = keyFrame;
     task         = MyAPIGateway.Parallel.StartBackground(DoWork);
 }
Example #8
0
        /// <summary>
        /// Finds nearby enemy ship
        /// </summary>
        /// <returns></returns>
        private void DetectEnemies()
        {
            const int DETECT_TIME_MS = 1000;

            if (!m_detectingEnemies && MyMinerGame.TotalGamePlayTimeInMilliseconds > (m_lastDetect + DETECT_TIME_MS))
            {
                m_detectEnemiesJob.Start(this);
                m_detectEnemiesTask = Parallel.Start(m_detectEnemiesJob);
                m_detectingEnemies = true;
            }
            else if (m_detectEnemiesTask.IsComplete && m_detectingEnemies)
            {
                // To prevent same detection time for bots spawned in one moment
                m_lastDetect = MyMinerGame.TotalGamePlayTimeInMilliseconds + MyMwcUtils.GetRandomInt(DETECT_TIME_MS / 3);
                m_detectingEnemies = false;

                // Detected entity
                if (m_detectEnemiesJob.ClosestEnemy != null)
                {
                    AddSeenEnemy(m_detectEnemiesJob.ClosestEnemy);
                    m_detectEnemiesJob.ClosestEnemy = null;
                }

                // Visualy detected entity
                if (m_detectEnemiesJob.ClosestVisual != null)
                {
                    AddCuriousLocation(m_detectEnemiesJob.ClosestVisual.GetPosition(), m_detectEnemiesJob.ClosestVisual);
                    m_detectEnemiesJob.ClosestVisual = null;
                }
                m_detectEnemiesJob.Finish();
            }
        }
 void GetWorkshopBlueprints()
 {
     Task = Parallel.Start(DownloadBlueprints);
 }
        public void UpdateBeforeSimulation()
        {
            if (MyFakes.BACKGROUND_OXYGEN && m_bgTaskRunning)
                return;//wait

            if (m_pressurizationPending && !m_doPostProcess)
            {
                ProfilerShort.Begin("Oxygen Initialize");
                if (ShouldPressurize())
                {
                    if (MyFakes.BACKGROUND_OXYGEN)
                    {
                        m_doPostProcess = false;
                        PressurizeInitialize();
                    }
                    else
                        PressurizeInternal();
                }
                m_pressurizationPending = false;
                ProfilerShort.End();
            }
            if (m_isPressurizing)
            {
                ProfilerShort.Begin("Oxygen Pressurize");
                if (m_doPostProcess)
                {
                    PressurizePostProcess();
                    m_doPostProcess = false;
                }
                else if (!m_bgTaskRunning)
                {
                    m_backgroundTask = Parallel.Start(BackgroundPressurizeStart, BackgroundPressurizeFinished);
                    m_bgTaskRunning = true;
                }
                ProfilerShort.End();
            }
            if (!m_isPressurizing && m_deletedBlocks.Count > 0)
            {
                ProfilerShort.Begin("Removing blocks");
                foreach (var deletedBlock in m_deletedBlocks)
                {
                    RemoveBlock(deletedBlock);
                }
                ApplyDepressurizationForces();
                m_deletedBlocks.Clear();
                ProfilerShort.End();
            }
        }
        void Ok()
        {
            if (m_selectedItem == null)
            {
                CloseScreen();
                return;
            }

            var itemInfo = m_selectedItem.UserData as MyBlueprintItemInfo;

            bool devTagMismatch = itemInfo.Item != null && itemInfo.Item.Tags != null && itemInfo.Item.Tags.Contains(MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG) && MyFinalBuildConstants.IS_STABLE;

            if (devTagMismatch)
            {
               MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                buttonType: MyMessageBoxButtonsType.OK,
                styleEnum: MyMessageBoxStyleEnum.Info,
                messageCaption: MyTexts.Get(MySpaceTexts.BlueprintScreen_DevMismatchCaption),
               messageText: MyTexts.Get(MySpaceTexts.BlueprintScreen_DevMismatchMessage)));

            }
  
            if (itemInfo.Type == MyBlueprintTypeEnum.SHARED)
            {
                OpenSharedBlueprint(itemInfo);
            }
            else
            {
                if (itemInfo.Type == MyBlueprintTypeEnum.STEAM)
                {
                    Task = Parallel.Start(() =>
                    {
                        if (MySteamWorkshop.IsBlueprintUpToDate(itemInfo.Item) == false)
                        {
                            DownloadBlueprintFromSteam(itemInfo.Item);
                        }
                    }, () => { CopyBlueprintAndClose(); });
                }
                else
                {
                    CopyBlueprintAndClose();
                }
            }
        }
        void GetWorkshopScripts()
        {
            if (MyFakes.XB1_PREVIEW)
                return;

            m_task = Parallel.Start(GetScriptsInfo);
        }
Example #13
0
        public override void Update()
        {
            if (m_on)
            {
                if (!m_running)
                {
                    if (m_currentIndex >= m_raysStartPositions.Count)
                    {
                        m_currentIndex = 0;
                    }
                    Matrix world = WorldMatrix;
                    Vector3 rayPosition = m_raysStartPositions[m_currentIndex];
                    Vector3 rayStart = Vector3.Transform(rayPosition, world);
                    Vector3 rayEnd = rayStart + world.Right * Size.X;
                    MyLine rayLine = new MyLine(rayStart, rayEnd, true);
                    m_work.Init(rayLine);
                    m_task = Parallel.Start(m_work);
                    m_running = true;
                    m_currentIndex++;
                }

                if (m_running && m_task.IsComplete)
                {
                    MyEntity scannedEntity = m_work.GetScannedEntity();
                    if (scannedEntity != null && MyPrefabScanner.CanBeScannedCriterium(scannedEntity, this))
                    {
                        m_scanner.NotifyEntityScanned(scannedEntity);
                    }
                    m_running = false;
                }
            }
        }
Example #14
0
        private static void ComputeGPSPath()
        {
            if (!m_computingGPS)
            {
                m_gpsStarted_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                m_GPSPathDirty = false;
                m_GPSPath = new List<Vector3>();

                // move startPos a little bit below and to the front so that it's visible from the cockpit
                var startEntity = MyGuiScreenGamePlay.Static.ControlledEntity;
                Vector3 playerPos = startEntity.GetPosition();
                Vector3 startPos = playerPos + MyHudConstants.GPS_START_POSITION_FRONT * startEntity.GetWorldRotation().Forward + MyHudConstants.GPS_START_POSITION_UP * startEntity.GetWorldRotation().Up;

                // if startPos is blocked by some object, move it into a visible position
                var line = new MyLine(playerPos, playerPos + 2 * (startPos - playerPos), true);
                var intersection = MyEntities.GetIntersectionWithLine(ref line, startEntity, MySession.PlayerShip, true, true);
                if (intersection != null)
                    startPos = (playerPos + intersection.Value.IntersectionPointInWorldSpace) * 0.5f;  // halfway between the player and the intersection

                // find the goal position
                var goalEntity = GetGPSGoalEntity(startPos);

                Vector3? goalPos = goalEntity != null ? goalEntity.WorldAABB.GetCenter() : (Vector3?)null;

                if (goalPos == null)
                {
                    m_GPSMessage = MyTextsWrapper.Get(MyTextsWrapperEnum.GPSNoObjectives);
                    return;  // nothing found
                }
                
                m_computeGPSJob.Start(startPos, goalPos.Value, goalEntity);
                m_computeGPSTask = Parallel.Start(m_computeGPSJob);
                m_computingGPS = true;
            }
            else if (m_computeGPSTask.IsComplete)
            {
                m_computingGPS = false;
                LastGPS = MyMinerGame.TotalGamePlayTimeInMilliseconds;

                m_GPSPath = m_computeGPSJob.Path;
                m_GPSMessage = m_computeGPSJob.Message;
            }
            else
            {
                // commented because it was evil
                /*
                if (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_gpsStarted_ms > 1000)
                {
                    // one sec was enough, do it NOW
                    m_computeGPSJob.DoWork();
                    m_computingGPS = false;
                    LastGPS = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_GPSPath = m_computeGPSJob.Path;
                    m_GPSMessage = m_computeGPSJob.Message;
                }
                */
            }
        }
 void PrepareForDraw()
 {
     if (MultiThreaded)
     {
         if (m_prepareForDrawTask.IsComplete)
         {
             m_prepareForDrawTask = ParallelTasks.Parallel.Start(this);
         }
     }
 }
 public static void AdvanceRoutefinding()
 {
     if (m_queue.Count > 0)
         //   m_event.Set();
         m_advanceRouteTask = Parallel.Start(m_routefindingHelper);
 }
 private void DownloadNews()
 {
     m_downloadNewsTask = Parallel.Start(DownloadNewsAsync);
 }
 void GetWorkshopScripts()
 {
     m_task = Parallel.Start(GetScriptsInfo);
 }
Example #19
0
        public bool TryTestPosition(Vector3 position, Vector3 targetPosition)
        {
            if (m_testPositionTask.IsComplete)
            {
                m_testingPosition = false;
            }

            if (!m_testingPosition)
	        {
                m_testPositionJob.Start(this, position, targetPosition);
                m_testPositionTask = Parallel.Start(m_testPositionJob);
                m_testingPosition = true;

                return true;
	        }
            
            return false;
        }
 void OpenSharedScript(MyScriptItemInfo itemInfo)
 {
     m_scriptList.Enabled = false;
     m_task = Parallel.Start(DownloadScriptFromSteam, OnScriptDownloaded);
 }
 public LoadWorkshopResult()
 {
     Task = Parallel.Start(() =>
     {
         SubscribedScenarios = new List<MySteamWorkshop.SubscribedItem>();
         if (!MySteam.IsOnline)
             return;
         if (!MySteamWorkshop.GetSubscribedScenariosBlocking(SubscribedScenarios))
             return;
     });
 }
        public override void UpdateBeforeSimulation()
        {
            //if (MySandboxGame.IsPaused)
            //  return;

            MyPerformanceCounter.PerCameraDrawWrite.ParticleEffectsTotal = 0;
            MyPerformanceCounter.PerCameraDrawWrite.ParticleEffectsDrawn = 0;

            if (MultithreadedUpdater)
            {
                WaitUntilUpdateCompleted();

                m_updaterTask = Parallel.Start(m_updateEffectsWork, null);
            }
            else
            {
                UpdateEffects();
            }
        }
Example #23
0
            public LoadListResult(HashSet<ulong> ids)
            {
                Task = Parallel.Start(() =>
                {
                    SubscribedMods = new List<MySteamWorkshop.SubscribedItem>(ids.Count);
                    WorldMods = new List<MySteamWorkshop.SubscribedItem>();

                    if (!MySteam.IsOnline)
                        return;

                    if (!MySteamWorkshop.GetSubscribedModsBlocking(SubscribedMods))
                        return;

                    var toGet = new HashSet<ulong>(ids);

                    foreach (var mod in SubscribedMods)
                        toGet.Remove(mod.PublishedFileId);
                    if (toGet.Count > 0)
                        MySteamWorkshop.GetItemsBlocking(WorldMods, toGet);
                });
            }
        void OnMouseOverItem(MyGuiControlListbox listBox)
        {
            var item = listBox.MouseOverItem;
            var path = "";
            if (item != null)
            {
                MyBlueprintItemInfo blueprintInfo = (item.UserData as MyBlueprintItemInfo);
                if (blueprintInfo.Type == MyBlueprintTypeEnum.LOCAL)
                {
                    path = Path.Combine(m_localBlueprintFolder, item.Text.ToString(), "thumb.png");               
                }
                else if (blueprintInfo.Type == MyBlueprintTypeEnum.STEAM)
                {
                    var id = blueprintInfo.PublishedItemId;
                    if (id != null)
                    {
                        path = Path.Combine(TEMP_PATH, id.ToString(), "thumb.png");
                        if (blueprintInfo.Item != null)
                        {
                            bool isQueued = m_downloadQueued.Contains(blueprintInfo.Item.PublishedFileId);
                            bool isDownloaded = m_downloadFinished.Contains(blueprintInfo.Item.PublishedFileId);
                            MySteamWorkshop.SubscribedItem worshopData = blueprintInfo.Item;
                            if (isDownloaded && IsExtracted(worshopData) == false)
                            {
                                m_blueprintList.Enabled = false;
                                m_okButton.Enabled = false;
                                ExtractWorkshopItem(worshopData);
                                m_blueprintList.Enabled = true;
                                m_okButton.Enabled = true;
                            }
                            if (isQueued == false && isDownloaded == false)
                            {
                                m_blueprintList.Enabled = false;
                                m_okButton.Enabled = false;
                                m_downloadQueued.Add(blueprintInfo.Item.PublishedFileId);

                                Task = Parallel.Start(() =>
                                {
                                    DownloadBlueprintFromSteam(worshopData);
                                }, () => { OnBlueprintDownloadedThumbnail(worshopData); });
                            }
                        }
                    }
                }
                else if (blueprintInfo.Type == MyBlueprintTypeEnum.DEFAULT)
                {
                    path = Path.Combine(m_defaultBlueprintFolder, item.Text.ToString(), "thumb.png");
                }

                if (File.Exists(path))
                {
                    m_thumbnailImage.SetTexture(path);
                    if (!m_activeDetail)
                    {
                        if (m_thumbnailImage.BackgroundTexture != null)
                        {
                            m_thumbnailImage.Visible = true;
                        }
                    }
                }
                else
                {
                    m_thumbnailImage.Visible = false;
                    m_thumbnailImage.BackgroundTexture = null;
                }
            }
            else
            {
                m_thumbnailImage.Visible = false;
            }
        }
        public static void PrepareForDraw()
        {
            m_effectsForCustomDraw.Clear();

            if (MultithreadedPrepareForDraw)
            {
                m_prepareForDrawTask = Parallel.Start(m_prepareEffectsWork);

                //m_prepareForDrawCompleted = false;
                //m_prepareForDrawEvent.Set();
            }
            else
            {
                PrepareEffectsForDraw();
            }
        }
        bool CopySelectedItemToClipboard()
        {
            if (!ValidateSelecteditem())
                return false;

            var path = "";
            MyObjectBuilder_Definitions prefab = null;
            MyBlueprintItemInfo blueprintInfo = (m_selectedItem.UserData as MyBlueprintItemInfo);
            if (blueprintInfo.Type == MyBlueprintTypeEnum.LOCAL)
            {
                path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
                if (File.Exists(path))
                {
                    m_LoadPrefabData = new LoadPrefabData(prefab, path, this);
                    Task = Parallel.Start(m_LoadPrefabData.CallLoadPrefab, null, m_LoadPrefabData);
                }
            }
#if !XB1 // XB1_NOWORKSHOP
            else if (blueprintInfo.Type == MyBlueprintTypeEnum.STEAM)
            {
                var id = (m_selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId;
                path = Path.Combine(m_workshopBlueprintFolder, id.ToString() + m_workshopBlueprintSuffix);
                if (File.Exists(path))
                {
                    m_LoadPrefabData = new LoadPrefabData(prefab, path, this, id);
                    Task = Parallel.Start(m_LoadPrefabData.CallLoadWorkshopPrefab, null, m_LoadPrefabData);
                }

            }
#endif // !XB1
            else if (blueprintInfo.Type == MyBlueprintTypeEnum.SHARED)
            {
                return false;
            }
            else if (blueprintInfo.Type == MyBlueprintTypeEnum.DEFAULT)
            {
                path = Path.Combine(m_defaultBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
                if (File.Exists(path))
                {
                    m_LoadPrefabData = new LoadPrefabData(prefab, path, this);
                    Task = Parallel.Start(m_LoadPrefabData.CallLoadPrefab, null, m_LoadPrefabData);
                }
            }
            return false;
            
        }