private static void ShowSolarSystem(UIVirtualStarmap starmap, int starIndex)
        {
            // start planet compute thread if not done already
            PlanetModelingManager.StartPlanetComputeThread();

            // add star
            StarData starData = starmap._galaxyData.StarById(starIndex + 1); // because StarById() decrements by 1

            AddStarToStarmap(starmap, starData);

            starmap.clickText = starData.id.ToString();
            Debug.Log("Setting it to " + starmap.clickText + " " + starData.id);

            for (int i = 0; i < starData.planetCount; i++)
            {
                // add planets
                PlanetData pData       = starData.planets[i];
                Color      color       = starmap.neutronStarColor;
                float      scaleFactor = 0.6f;
                bool       isMoon      = false;

                VectorLF3 pPos = GetRelativeRotatedPlanetPos(starData, pData, ref isMoon);

                // request generation of planet surface data to display its details when clicked and if not already loaded
                if (!pData.loaded)
                {
                    PlanetModelingManager.RequestLoadPlanet(pData);
                }

                // create fake StarData to pass _OnLateUpdate()
                StarData dummyStarData = new StarData
                {
                    position = pPos,
                    color    = starData.color,
                    id       = pData.id
                };

                Vector3 scale = (pData.realRadius / 100) * scaleFactor * Vector3.one;
                if (scale.x > 3 || scale.y > 3 || scale.z > 3)
                {
                    scale = new Vector3(3, 3, 3);
                }

                starmap.starPool[i + 1].active   = true;
                starmap.starPool[i + 1].starData = dummyStarData;
                starmap.starPool[i + 1].pointRenderer.material.SetColor("_TintColor", color);
                starmap.starPool[i + 1].pointRenderer.transform.localPosition = pPos;
                starmap.starPool[i + 1].pointRenderer.transform.localScale    = scale;
                starmap.starPool[i + 1].pointRenderer.gameObject.SetActive(true);
                starmap.starPool[i + 1].nameText.text  = pData.displayName + " (" + pData.typeString + ")";
                starmap.starPool[i + 1].nameText.color = Color.Lerp(color, Color.white, 0.5f);
                starmap.starPool[i + 1].nameText.rectTransform.sizeDelta        = new Vector2(starmap.starPool[i + 1].nameText.preferredWidth, starmap.starPool[i + 1].nameText.preferredHeight);
                starmap.starPool[i + 1].nameText.rectTransform.anchoredPosition = new Vector2(-2000f, -2000f);
                starmap.starPool[i + 1].textContent = pData.displayName + " (" + pData.typeString + ")";

                starmap.starPool[i + 1].nameText.gameObject.SetActive(true);

                // add orbit renderer
                starmap.connPool[i].active = true;
                starmap.connPool[i].lineRenderer.material.SetColor("_LineColorA", Color.Lerp(color, Color.white, 0.65f));

                if (starmap.connPool[i].lineRenderer.positionCount != 61)
                {
                    starmap.connPool[i].lineRenderer.positionCount = 61;
                }
                for (int j = 0; j < 61; j++)
                {
                    float   f    = (float)j * 0.017453292f * 6f; // ty dsp devs :D
                    Vector3 cPos = GetCenterOfOrbit(starData, pData, ref isMoon);
                    Vector3 position;
                    if (isMoon)
                    {
                        position = new Vector3(Mathf.Cos(f) * pData.orbitRadius * orbitScaler * 8 + (float)cPos.x, cPos.y, Mathf.Sin(f) * pData.orbitRadius * orbitScaler * 8 + (float)cPos.z);
                    }
                    else
                    {
                        position = new Vector3(Mathf.Cos(f) * pData.orbitRadius * orbitScaler + (float)cPos.x, cPos.y, Mathf.Sin(f) * pData.orbitRadius * orbitScaler + (float)cPos.z);
                    }

                    // rotate position around center by orbit angle
                    Quaternion quaternion = Quaternion.Euler(pData.orbitInclination, pData.orbitInclination, pData.orbitInclination);
                    Vector3    dir        = quaternion * (position - cPos);
                    position = dir + cPos;

                    starmap.connPool[i].lineRenderer.SetPosition(j, position);
                }
                starmap.connPool[i].lineRenderer.gameObject.SetActive(true);
            }
        }
Beispiel #2
0
        public static void GameMain_End_Prefix()
        {
            spreadsheetGenRequestFlag = false;
            planetResourceData.Clear();

            /******************************************************************/
            /* The code below fixes a bug in the original game which this mod */
            /* just makes appear more easily.  The original game doesn't      */
            /* properly handle PlanetModelingManager resetting when a game    */
            /* ends.  Such resetting is only needed when a planet/factory is  */
            /* being loaded, a rare occurance if it weren't for this mod.     */
            /******************************************************************/

            if (PlanetModelingManager.genPlanetReqList.Count == 0 &&
                PlanetModelingManager.fctPlanetReqList.Count == 0 &&
                PlanetModelingManager.modPlanetReqList.Count == 0)
            {
                Logger.LogInfo("Planet modeling reset is not needed.");
                return;
            }

            Logger.LogInfo("Stopping planet modeling thread.");
            PlanetModelingManager.EndPlanetComputeThread();
            Thread.Sleep(100);

            uint sleepIterationCount = 1;

            while (PlanetModelingManager.planetComputeThreadFlag == PlanetModelingManager.ThreadFlag.Ending &&
                   ++sleepIterationCount < 100) // Don't wait more than 10 seconds.  (It shouldn't even enter this loop.)
            {
                Thread.Sleep(100);
            }

            Logger.LogInfo("Clearing planet modeling queues.");
            PlanetModelingManager.genPlanetReqList.Clear();  // RequestLoadStar or RequestLoadPlanet -> PlanetComputeThreadMain
            PlanetModelingManager.fctPlanetReqList.Clear();  // RequestLoadPlanetFactory -> LoadingPlanetFactoryCoroutine
            PlanetModelingManager.modPlanetReqList.Clear();  // ModelingPlanetCoroutine -> ModelingPlanetMain

            if (PlanetModelingManager.currentModelingPlanet != null)
            {
                Logger.LogInfo("Cancelling planet modeling for " + PlanetModelingManager.currentModelingPlanet.name);
                PlanetModelingManager.currentModelingPlanet.Unload();
                PlanetModelingManager.currentModelingPlanet.factoryLoaded = false;
                PlanetModelingManager.currentModelingPlanet     = null;
                PlanetModelingManager.currentModelingStage      = 0;
                PlanetModelingManager.currentModelingSeamNormal = 0;
            }

            if (PlanetModelingManager.currentFactingPlanet != null)
            {
                Logger.LogInfo("Cancelling planet factory modeling for " + PlanetModelingManager.currentFactingPlanet.name);
                PlanetModelingManager.currentFactingPlanet.UnloadFactory();
                PlanetModelingManager.currentFactingPlanet.factoryLoaded = false;
                PlanetModelingManager.currentFactingPlanet = null;
                PlanetModelingManager.currentFactingStage  = 0;
            }

            Logger.LogInfo("Resetting planet modeling manager so we don't get a magenta planet when a new game begins.");
            for (int num57 = 0; num57 < PlanetModelingManager.tmpMeshList.Count; num57++)
            {
                UnityEngine.Object.Destroy(PlanetModelingManager.tmpMeshList[num57]);
            }
            UnityEngine.Object.Destroy(PlanetModelingManager.tmpPlanetGameObject);
            PlanetModelingManager.tmpPlanetGameObject       = null;
            PlanetModelingManager.tmpPlanetBodyGameObject   = null;
            PlanetModelingManager.tmpPlanetReformGameObject = null;
            PlanetModelingManager.tmpPlanetReformRenderer   = null;
            PlanetModelingManager.tmpMeshList.Clear();
            PlanetModelingManager.tmpTris.Clear();
            PlanetModelingManager.tmpVerts.Clear();
            PlanetModelingManager.tmpNorms.Clear();
            PlanetModelingManager.tmpTgnts.Clear();
            PlanetModelingManager.tmpUvs.Clear();
            PlanetModelingManager.tmpUv2s.Clear();
            PlanetModelingManager.currentModelingPlanet     = null;
            PlanetModelingManager.currentModelingStage      = 0;
            PlanetModelingManager.currentModelingSeamNormal = 0;

            Logger.LogInfo("Restarting planet modeling thread.");
            PlanetModelingManager.StartPlanetComputeThread();
        }