public override void ProcessPacket(PlanetDataRequest packet, NebulaConnection conn) { if (IsClient) { return; } Dictionary <int, byte[]> planetDataToReturn = new Dictionary <int, byte[]>(); foreach (int planetId in packet.PlanetIDs) { PlanetData planet = GameMain.galaxy.PlanetById(planetId); Log.Info($"Returning terrain for {planet.name}"); // NOTE: The following has been picked-n-mixed from "PlanetModelingManager.PlanetComputeThreadMain()" // This method is **costly** - do not run it more than is required! // It generates the planet on the host and then sends it to the client PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet); if (planet.data == null) { planet.data = new PlanetRawData(planet.precision); planet.modData = planet.data.InitModData(planet.modData); planet.data.CalcVerts(); planet.aux = new PlanetAuxData(planet); planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y); planetAlgorithm.CalcWaterPercent(); //Load planet meshes and register callback to unload unneccessary stuff planet.wanted = true; planet.onLoaded += OnActivePlanetLoaded; PlanetModelingManager.modPlanetReqList.Enqueue(planet); if (planet.type != EPlanetType.Gas) { planetAlgorithm.GenerateVegetables(); planetAlgorithm.GenerateVeins(false); } } using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) { planet.ExportRuntime(writer.BinaryWriter); planetDataToReturn.Add(planetId, writer.CloseAndGetBytes()); } } conn.SendPacket(new PlanetDataResponse(planetDataToReturn)); }
private static byte[] PlanetCompute(int planetId) { PlanetData planet = GameMain.galaxy.PlanetById(planetId); HighStopwatch highStopwatch = new HighStopwatch(); highStopwatch.Begin(); // NOTE: The following has been picked-n-mixed from "PlanetModelingManager.PlanetComputeThreadMain()" // This method is **costly** - do not run it more than is required! // It generates the planet on the host and then sends it to the client PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet); if (planet.data == null) { planet.data = new PlanetRawData(planet.precision); planet.modData = planet.data.InitModData(planet.modData); planet.data.CalcVerts(); planet.aux = new PlanetAuxData(planet); planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y); planetAlgorithm.CalcWaterPercent(); //Load planet meshes and register callback to unload unneccessary stuff planet.wanted = true; planet.onLoaded += OnActivePlanetLoaded; PlanetModelingManager.modPlanetReqList.Enqueue(planet); if (planet.type != EPlanetType.Gas) { planetAlgorithm.GenerateVegetables(); planetAlgorithm.GenerateVeins(false); } } byte[] data; using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) { planet.ExportRuntime(writer.BinaryWriter); data = writer.CloseAndGetBytes(); } Log.Info($"Returning terrain for {planet.name} (id:{planet.id} time:{highStopwatch.duration:F4}s)"); return data; }
private static bool OnPlanetDataSet(ref UIPlanetDetail __instance, ref UIResAmountEntry ___tipEntry, ref Text ___nameText, ref Text ___typeText, ref Text ___orbitRadiusValueText, ref Text ___orbitRadiusValueTextEx, ref Text ___orbitPeriodValueText, ref Text ___rotationPeriodValueText, ref Text ___inclinationValueText, ref Text ___obliquityValueText, ref Sprite ___unknownResIcon, ref Sprite ___sprite6, ref Sprite ___sprite8, ref Sprite ___sprite9) { var getEntry = Traverse.Create(__instance).Method("GetEntry"); getEntry.GetValue <UIResAmountEntry>(); for (var index = 0; index < __instance.entries.Count; ++index) { var entry = __instance.entries[index]; entry.SetEmpty(); __instance.pool.Add(entry); } __instance.entries.Clear(); ___tipEntry = null; if (__instance.planet == null) { return(false); } var _observed = GameMain.history.universeObserveLevel >= (__instance.planet != GameMain.localPlanet ? 2 : 1); ___nameText.text = __instance.planet.displayName; var empty = string.Empty; ___typeText.text = string.Format("{0} {1}", __instance.planet.typeString, "<color=\"#FD965EC0\">" + __instance.planet.singularityString + "</color>"); ___orbitRadiusValueText.text = __instance.planet.orbitRadius.ToString("0.00#") + " AU"; ___orbitRadiusValueTextEx.text = __instance.planet.name; ___orbitPeriodValueText.text = __instance.planet.orbitalPeriod.ToString("#,##0") + "空格秒".Translate(); ___rotationPeriodValueText.text = __instance.planet.rotationPeriod.ToString("#,##0") + "空格秒".Translate(); var num1 = Mathf.Abs(__instance.planet.orbitInclination); var num2 = (int)num1; var num3 = (int)((num1 - (double)num2) * 60.0); if (__instance.planet.orbitInclination < 0.0) { num2 = -num2; } var num4 = Mathf.Abs(__instance.planet.obliquity); var num5 = (int)num4; var num6 = (int)((num4 - (double)num5) * 60.0); if (__instance.planet.obliquity < 0.0) { num5 = -num5; } ___inclinationValueText.text = string.Format("{0}° {1}′", num2, num3); ___obliquityValueText.text = string.Format("{0}° {1}′", num5, num6); var num7 = 0; if (__instance.planet.type != EPlanetType.Gas) { for (var index = 0; index < 6; ++index) { var id = index + 1; var veinProto = LDB.veins.Select(id); var itemProto = LDB.items.Select(veinProto.MiningItem); if (veinProto != null && itemProto != null) { var entry = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry); entry.SetInfo(num7, itemProto.name, veinProto.iconSprite, veinProto.description, false, false, " "); entry.refId = id; ++num7; } } var waterItemId = __instance.planet.waterItemId; Sprite icon = null; var str = "无".Translate(); if (waterItemId < 0) { str = waterItemId != -1 ? "未知".Translate() : "熔岩".Translate(); } var itemProto1 = LDB.items.Select(waterItemId); if (itemProto1 != null) { icon = itemProto1.iconSprite; str = itemProto1.name; } var entry1 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry1); entry1.SetInfo(num7, "海洋类型".Translate(), icon, itemProto1 == null ? string.Empty : itemProto1.description, false, itemProto1 != null && waterItemId != 1000, string.Empty); entry1.valueString = str; var index1 = num7 + 1; var entry2 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry2); entry2.SetInfo(index1, "适建区域".Translate(), ___sprite6, string.Empty, false, false, " %"); if (__instance.planet.landPercentDirty) { PlanetAlgorithm.CalcLandPercent(__instance.planet); __instance.planet.landPercentDirty = false; } StringBuilderUtility.WritePositiveFloat(entry2.sb, 0, 5, __instance.planet.landPercent * 100f, 1); entry2.DisplayStringBuilder(); var index2 = index1 + 1; var entry3 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry3); entry3.SetInfo(index2, "风能利用率".Translate(), ___sprite8, string.Empty, false, __instance.planet.windStrength > 1.49899995326996, " %"); StringBuilderUtility.WriteUInt(entry3.sb, 0, 3, (uint)(__instance.planet.windStrength * 100.0 + 0.499900013208389)); entry3.DisplayStringBuilder(); var index3 = index2 + 1; var entry4 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry4); entry4.SetInfo(index3, "光能利用率".Translate(), ___sprite9, string.Empty, false, __instance.planet.luminosity > 1.49899995326996, " %"); StringBuilderUtility.WriteUInt(entry4.sb, 0, 3, (uint)(__instance.planet.luminosity * 100.0 + 0.499900013208389)); entry4.DisplayStringBuilder(); num7 = index3 + 1; for (var index4 = 7; index4 < 15; ++index4) { var id = index4; var veinProto = LDB.veins.Select(id); var itemProto2 = LDB.items.Select(veinProto.MiningItem); if (veinProto != null && itemProto2 != null && __instance.planet.veinAmounts[id] > 0L) { var entry5 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry5); entry5.SetInfo(num7, itemProto2.name, veinProto.iconSprite, veinProto.description, true, false, index4 != 7 ? " " : " /s"); entry5.refId = id; ++num7; } } if (!_observed) { var entry5 = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry5); entry5.SetInfo(num7, string.Empty, null, string.Empty, false, false, string.Empty); ___tipEntry = entry5; ++num7; } } else { for (var index = 0; index < __instance.planet.gasItems.Length; ++index) { var itemProto = LDB.items.Select(__instance.planet.gasItems[index]); if (itemProto != null) { var entry = getEntry.GetValue <UIResAmountEntry>(); ; __instance.entries.Add(entry); if (_observed) { entry.SetInfo(num7, "可采集".Translate() + itemProto.name, itemProto.iconSprite, "环绕行星手动采集".Translate(), false, false, " /s"); StringBuilderUtility.WritePositiveFloat(entry.sb, 0, 7, __instance.planet.gasSpeeds[index]); entry.DisplayStringBuilder(); } else { entry.SetInfo(num7, "未知".Translate(), ___unknownResIcon, "环绕行星手动采集".Translate(), false, false, " /s"); entry.valueString = "未知".Translate(); } entry.SetObserved(_observed); ++num7; } } } __instance.SetResCount(num7); __instance.RefreshDynamicProperties(); return(false); }
private static void exportStar(PlanetData planet) { UnityEngine.Debug.Log("-- planet: " + planet.id); PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet); planet.data = new PlanetRawData(planet.precision); planet.modData = planet.data.InitModData(planet.modData); planet.data.CalcVerts(); planet.aux = new PlanetAuxData(planet); planetAlgorithm.GenerateTerrain(planet.mod_x, planet.mod_y); planetAlgorithm.CalcWaterPercent(); if (planet.type != EPlanetType.Gas) { planetAlgorithm.GenerateVegetables(); } if (planet.type != EPlanetType.Gas) { planetAlgorithm.GenerateVeins(false); } Monitor.Enter(streamWriter); try { if (!firstPlanet) { streamWriter.Write(","); } else { firstPlanet = false; } streamWriter.Write("\"" + planet.name + "\":{" + "\"seed\":" + planet.seed + ",\"index\":" + planet.index + ",\"id\":" + planet.id + ",\"orbitAround\":" + planet.orbitAround + ",\"number\":" + planet.number + ",\"orbitIndex\":" + planet.orbitIndex + ",\"name\":\"" + planet.name + "\"" + ",\"orbitRadius\":" + planet.orbitRadius + ",\"orbitInclination\":" + planet.orbitInclination + ",\"orbitLongitude\":" + planet.orbitLongitude + ",\"orbitalPeriod\":" + planet.orbitalPeriod + ",\"orbitPhase\":" + planet.orbitPhase + ",\"obliquity\":" + planet.obliquity + ",\"rotationPeriod\":" + planet.rotationPeriod + ",\"rotationPhase\":" + planet.rotationPhase + ",\"radius\":" + planet.radius + ",\"scale\":" + planet.scale + ",\"sunDistance\":" + planet.sunDistance + ",\"habitableBias\":" + planet.habitableBias + ",\"temperatureBias\":" + planet.temperatureBias + ",\"ionHeight\":" + planet.ionHeight + ",\"windStrength\":" + planet.windStrength + ",\"luminosity\":" + planet.luminosity + ",\"landPercent\":" + planet.landPercent + ",\"mod_x\":" + planet.mod_x + ",\"mod_y\":" + planet.mod_y + ",\"type\":" + (int)planet.type + ",\"singularity\":" + (int)planet.singularity + ",\"theme\":" + planet.theme + ",\"algoId\":" + planet.algoId + ",\"waterHeight\":" + planet.waterHeight); if (planet.waterItemId > 0) { ItemProto water = LDB.items.Select(planet.waterItemId); streamWriter.Write( ",\"waterItem\":\"" + water.name + "\"" ); } if (planet.type == EPlanetType.Gas) { streamWriter.Write(",\"gasTotalHeat\":" + planet.gasTotalHeat); streamWriter.Write(",\"gas\":{"); // open gas[] bool firstvein = true; for (int k = 0; k < planet.gasItems.Length; k++) { ItemProto gas = LDB.items.Select(planet.gasItems[k]); if (firstvein == false) { streamWriter.Write(","); } else { firstvein = false; } streamWriter.Write("\"" + gas.name + "\":{" + "\"gasName\":\"" + gas.name + "\"" + ",\"gasItem\":" + planet.gasItems[k] + ",\"gasSpeed\":\"" + planet.gasSpeeds[k] + "\"" + ",\"gasHeatValue\":\"" + planet.gasHeatValues[k] + "\"}"); } streamWriter.Write("}"); // close gas[] } else { streamWriter.Write(",\"vein\":{"); // open vein[] bool firstvein = true; for (int k = 0; k < planet.veinAmounts.Length; k++) { if (planet.veinAmounts[k] == 0) { continue; } if (firstvein == false) { streamWriter.Write(","); } else { firstvein = false; } streamWriter.Write("\"" + (EVeinType)k + "\":" + planet.veinAmounts[k]); } streamWriter.Write("}"); // close vein[] } streamWriter.Write(",\"uPosition\":{\"x\":" + planet.uPosition.x + ",\"y\":" + planet.uPosition.y + ",\"z\":" + planet.uPosition.z + "}}"); // close planet } finally { Monitor.Exit(streamWriter); } planet.Unload(); }
public static GalaxyData CreateGalaxy(GameDesc gameDesc) { int galaxyAlgo = gameDesc.galaxyAlgo; int galaxySeed = gameDesc.galaxySeed; int num = gameDesc.starCount; if (galaxyAlgo < 20200101 || galaxyAlgo > 20591231) { throw new Exception("Wrong version of unigen algorithm!"); } System.Random random = new System.Random(galaxySeed); int seed = random.Next(); num = Traverse.Create(typeof(UniverseGen)).Method("GenerateTempPoses", seed, num, 4, 2.0, 2.3, 3.5, 0.18).GetValue <int>(); GalaxyData galaxyData = new GalaxyData(); galaxyData.seed = galaxySeed; galaxyData.starCount = num; galaxyData.stars = new StarData[num]; Assert.Positive(num); if (num <= 0) { return(galaxyData); } float num2 = (float)random.NextDouble(); float num3 = (float)random.NextDouble(); float num4 = (float)random.NextDouble(); float num5 = (float)random.NextDouble(); int num6 = Mathf.CeilToInt(0.01f * (float)num + num2 * 0.3f); int num7 = Mathf.CeilToInt(0.01f * (float)num + num3 * 0.3f); int num8 = Mathf.CeilToInt(0.016f * (float)num + num4 * 0.4f); int num9 = Mathf.CeilToInt(0.013f * (float)num + num5 * 1.4f); int num10 = num - num6; int num11 = num10 - num7; int num12 = num11 - num8; int num13 = (num12 - 1) / num9; int num14 = num13 / 2; for (int i = 0; i < num; i++) { int seed2 = random.Next(); ESpectrType needSpectr = ESpectrType.X; if (i == 3) { needSpectr = ESpectrType.M; } else if (i == num12 - 1) { needSpectr = ESpectrType.O; } EStarType needtype = EStarType.MainSeqStar; if (i % num13 == num14) { needtype = EStarType.GiantStar; } if (i >= num10) { needtype = EStarType.BlackHole; } else if (i >= num11) { needtype = EStarType.NeutronStar; } else if (i >= num12) { needtype = EStarType.WhiteDwarf; } galaxyData.stars[i] = StarGen.CreateStar(galaxyData, Traverse.Create(typeof(UniverseGen)).Field("tmp_poses").GetValue <List <VectorLF3> >()[i], i + 1, seed2, needtype, needSpectr); } AstroPose[] astroPoses = galaxyData.astroPoses; StarData[] stars = galaxyData.stars; for (int j = 0; j < galaxyData.astroPoses.Length; j++) { astroPoses[j].uRot.w = 1f; astroPoses[j].uRotNext.w = 1f; } for (int k = 0; k < num; k++) { StarGen.CreateStarPlanets(galaxyData, stars[k], gameDesc); astroPoses[stars[k].id * 100].uPos = (astroPoses[stars[k].id * 100].uPosNext = stars[k].uPosition); astroPoses[stars[k].id * 100].uRot = (astroPoses[stars[k].id * 100].uRotNext = Quaternion.identity); astroPoses[stars[k].id * 100].uRadius = stars[k].physicsRadius; } galaxyData.UpdatePoses(0.0); galaxyData.birthPlanetId = 0; if (num > 0) { StarData starData = stars[0]; for (int l = 0; l < starData.planetCount; l++) { PlanetData planetData = starData.planets[l]; ThemeProto themeProto = LDB.themes.Select(planetData.theme); if (themeProto != null && themeProto.Distribute == EThemeDistribute.Birth) { galaxyData.birthPlanetId = planetData.id; galaxyData.birthStarId = starData.id; CustomBirthPlanet(planetData); break; } } } Assert.Positive(galaxyData.birthPlanetId); for (int m = 0; m < num; m++) { StarData starData2 = galaxyData.stars[m]; for (int n = 0; n < starData2.planetCount; n++) { PlanetData planet = starData2.planets[n]; PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet); planetAlgorithm.GenerateVeins(true); } } UniverseGen.CreateGalaxyStarGraph(galaxyData); return(galaxyData); }