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 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); }