public static void Postfix(PlanetSimulator __instance) { foreach (Renderer renderer in __instance.surfaceRenderer) { renderer.shadowCastingMode = (!PlanetSimulator.sOptionCastShadow) ? ShadowCastingMode.Off : ShadowCastingMode.On; } }
public DebugGUI(PlanetSimulator pSim) { this.pSim = pSim; mainWindowID = Guid.NewGuid().GetHashCode(); basicWindowID = Guid.NewGuid().GetHashCode(); bMap = new BoundsMap(x => 1, pSim.level); }
public SimulatorDisplay(PlanetSimulator pSim, DisplayMapType dMapType) { this.pSim = pSim; this.mapType = dMapType; InitTexture(); InitObject(); foreach (Cell cell in Cell.AtLevel(3)) { testShits.Add(new WindTestShit(pSim, cell.Position)); } //testShits.Add(new WindTestShit(pSim, Vector3.one.normalized)); }
public void SolvePart1() { string[] input = System.IO.File.ReadAllLines("../../../input/day_12.txt"); Planet[] planets = input .Select(x => x.Substring(1, x.Length - 2)) .Select(x => PlanetParser.ParsePlanet(x)) .ToArray(); var sim = new PlanetSimulator(planets); sim.Run(1000); Assert.Equal(5350, sim.TotalSystemEnergy); }
public static bool SetPlanetData(ref PlanetSimulator __instance, ref Transform ___lookCamera, ref UniverseSimulator ___universe, ref StarSimulator ___star, PlanetData planet) { __instance.planetData = planet; if (__instance.planetData.atmosMaterial != null) { __instance.atmoTrans0 = new GameObject("Atmosphere") { layer = 31 }.transform; __instance.atmoTrans0.parent = __instance.transform; __instance.atmoTrans0.localPosition = Vector3.zero; if (planet.GetScaleFactored() >= 1) { __instance.atmoTrans0.localScale *= planet.GetScaleFactored(); } else { __instance.atmoTrans0.localScale /= planet.GetScaleFactored(); } var primitive = GameObject.CreatePrimitive(PrimitiveType.Quad); primitive.layer = 31; __instance.atmoTrans1 = primitive.transform; __instance.atmoTrans1.parent = __instance.atmoTrans0; __instance.atmoTrans1.localPosition = Vector3.zero; Object.Destroy(primitive.GetComponent <Collider>()); var component = primitive.GetComponent <Renderer>(); var atmosMaterial = __instance.planetData.atmosMaterial; component.sharedMaterial = atmosMaterial; __instance.atmoMat = atmosMaterial; component.shadowCastingMode = ShadowCastingMode.Off; component.receiveShadows = false; component.lightProbeUsage = LightProbeUsage.Off; component.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion; __instance.atmoTrans1.localScale = Vector3.one * (planet.realRadius * 5f * planet.GetScaleFactored()); __instance.atmoMatRadiusParam = __instance.atmoMat.GetVector("_PlanetRadius"); } ___lookCamera = Camera.main.transform; ___universe = GameMain.universeSimulator; ___star = ___universe.FindStarSimulator(planet.star); return(false); }
public CloudSystem(PlanetSimulator pSim) { this.pSim = pSim; urf = GameObject.Find("Earth"); pEmitter = (ParticleEmitter)urf.AddComponent("MeshParticleEmitter"); pRenderer = urf.AddComponent <ParticleRenderer>(); pAnimator = urf.AddComponent <ParticleAnimator>(); pEmitter.useWorldSpace = false; pEmitter.maxEmission = 5000f; particles = new Particle[Cell.CountAtLevel(pSim.level)]; //pEmitter.particles = particles; initParticleMap(); }
public WindTestShit(PlanetSimulator pSim, Vector3 startPos) { currentPos = startPos; this.pSim = pSim; //GameObject returnObject = new GameObject(); GameObject go = new GameObject(); lineRend = go.AddComponent <LineRenderer>(); lineRend.material = new Material(Shader.Find("Unlit/Texture")); Texture2D newTex = new Texture2D(1, 1, TextureFormat.ARGB32, false); newTex.SetPixel(0, 0, Color.white); newTex.Apply(); lineRend.material.mainTexture = newTex; lineRend.SetWidth(0.01f, 0.01f); lineRend.SetVertexCount(2); lineRend.SetPosition(0, new Vector3(0, 0, 0)); SetPosition(currentPos); }
public void Part1() { string[] input = { "<x=-1, y=0, z=2>", "<x=2, y=-10, z=-7>", "<x=4, y=-8, z=8>", "<x=3, y=5, z=-1>", }; Planet[] planets = input .Select(x => x.Substring(1, x.Length - 2)) .Select(x => PlanetParser.ParsePlanet(x)) .ToArray(); var sim = new PlanetSimulator(planets); sim.Run(10); Assert.Equal(179, sim.TotalSystemEnergy); }
void FixedUpdate() { if (hasGenerated == false) { GenerateNewGrids(); } second += 0.02f; if (second >= (WeatherTickRate * 0.02) && (WeatherTickRate * 0.02) != 0) { if (FlightGlobals.currentMainBody != null && PlanetMap.ContainsKey(FlightGlobals.currentMainBody)) { //Debug.Log("Weather Tick!"); //Debug.Log(body.name + " has: " + PlanetMap[body].Count + " layers."); if (hasGenerated == true) { PlanetSimulator pSim = PlanetMap[FlightGlobals.currentMainBody]; pSim.UpdateNCells(KWSSettings.CellsPerUpdate); } //Debug.Log(PlanetMap[body].Count); } second = 0f; } }
void GenerateNewGrids() { hasGenerated = true; PlanetMap = new Dictionary <CelestialBody, PlanetSimulator>(); int i = 0; foreach (CelestialBody body in FlightGlobals.Bodies) { i++; if (body.atmosphere) { //Debug.Log(body.name + " has atmosphere!"); KSPWeatherCallbacks kspwcb = new KSPWeatherCallbacks(body); //Debug.Log("1"); PlanetSimulator pSim = new PlanetSimulator(KWSSettings.gridLevel, KWSSettings.Layers - 1, kspwcb.SunDirection, kspwcb.SunlightAngle); //Debug.Log("2"); PlanetMap.Add(body, pSim); //Debug.Log("3"); pSim.bufferFlip += BufferFlip; Debug.Log("Map added to: " + body.name); } } setInitVars(); }
void WeatherDataUI(int windowID) { CelestialBody body = FlightGlobals.currentMainBody; PlanetSimulator pSim = KWSKSPButtToucher.KSPHeadMaster.PlanetMap[body]; Cell cell = KSPWeatherFunctions.getCellAtLocation(body, FlightGlobals.ActiveVessel.GetWorldPos3D()); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Body Up")) { if (i < KWSKSPButtToucher.KSPHeadMaster.PlanetMap.Keys.Count - 1) { i++; } } ; if (GUILayout.Button("Body Down")) { if (i > 0) { i--; } } ; GUILayout.EndHorizontal(); CelestialBody testBody = KWSKSPButtToucher.KSPHeadMaster.PlanetMap.ElementAt(i).Key; GUILayout.BeginHorizontal(); if (GUILayout.Button("Layer Up")) { if (AltLayer < KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap.Count - 1) { AltLayer++; } } if (GUILayout.Button("Layer Down")) { if (AltLayer > 0) { AltLayer--; } } GUILayout.EndHorizontal(); //Debug.Log("1"); //GUILayout.Label("CellID: " + CellIDLabel); CellIDLabel = GUILayout.TextField(CellIDLabel, 10); CellIDInt = int.Parse(CellIDLabel); GUILayout.Label("Body: " + testBody.name); GUILayout.Label("Layer: " + AltLayer); GUILayout.Label("Current location: " + FlightGlobals.ActiveVessel.GetWorldPos3D().ToString()); //GUILayout.Label("Temperature: " + WeatherFunctions.getCellTemperature(FlightGlobals.currentMainBody, WeatherFunctions.getCellAtLocation(FlightGlobals.currentMainBody, FlightGlobals.ActiveVessel.GetWorldPos3D()))); GUILayout.Label("Temperature: " + ((KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Temperature - 273.15)).ToString("0.0000")); GUILayout.Label("Pressure: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Pressure.ToString("0.000000000")); GUILayout.Label("Density: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Density); //Debug.Log("2"); GUILayout.Label("Cell Latitude: " + WeatherFunctions.getLatitude(cell)); GUILayout.Label("Cell Longitude: " + WeatherFunctions.getLongitude(cell)); GUILayout.Label("Cell Altitude: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Altitude); GUILayout.Label("isOcean?: " + KSPWeatherFunctions.isOcean(testBody, cell)); GUILayout.Label("Albedo: " + KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].Albedo); GUILayout.Label("Daytime?: " + Heating.isSunlight(KSPHeadMaster.PlanetMap[testBody], AltLayer, cell) + " " + Heating.getSunlightAngle(KSPHeadMaster.PlanetMap[testBody], AltLayer, cell)); GUILayout.Label("Shortwave Abs: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].SWAbsorbed); GUILayout.Label("Shortwave Out: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].SWTransmitted); GUILayout.Label("Longwave In: " + KWSKSPButtToucher.KSPHeadMaster.PlanetMap[testBody].LiveMap[AltLayer][cell].LWIn); //Debug.Log("3"); //GUILayout.Label("Cell Pos: " + Cell.KWSBODY[FlightGlobals.currentMainBody][CellIDInt].CellPosition); GUILayout.EndVertical(); GUI.DragWindow(); }
public static bool UpdateUniversalPosition(ref PlanetSimulator __instance, ref StarSimulator ___star, ref bool ___isLocal, ref Transform ___lookCamera, Vector3 playerLPos, VectorLF3 playerUPos, Vector3 cameraPos) { if (__instance.planetData == null || __instance.planetData.loading || __instance.planetData.factoryLoading) { return(false); } __instance.SetLayers(); var localPlanet = GameMain.localPlanet; var flag1 = ___isLocal != (localPlanet == __instance.planetData); ___isLocal = localPlanet == __instance.planetData; var flag2 = PlanetSimulator.sOptionCastShadow != __instance.optionCastShadow; if (flag1 || flag2) { foreach (var renderer in __instance.surfaceRenderer) { renderer.receiveShadows = ___isLocal; renderer.shadowCastingMode = !___isLocal || !PlanetSimulator.sOptionCastShadow ? ShadowCastingMode.Off : ShadowCastingMode.On; } __instance.optionCastShadow = PlanetSimulator.sOptionCastShadow; } __instance.reformRenderer.receiveShadows = ___isLocal; var flag3 = ___isLocal && __instance.planetData.type != EPlanetType.Gas; if (__instance.sphereCollider.enabled == flag3) { foreach (var collider in __instance.surfaceCollider) { collider.enabled = flag3; } if (__instance.oceanCollider != null) { __instance.oceanCollider.enabled = flag3; } __instance.sphereCollider.enabled = !flag3; } var uPosition = __instance.planetData.uPosition; var quaternion = Quaternion.identity; VectorLF3 vectorLf3; if (localPlanet != null) { quaternion = localPlanet.runtimeRotation; if (localPlanet == __instance.planetData) { vectorLf3 = VectorLF3.zero; } else { var v = uPosition - localPlanet.uPosition; vectorLf3 = Maths.QInvRotateLF(quaternion, v); } } else { vectorLf3 = uPosition - playerUPos; } var vscale = 1f; Vector3 vpos; UniverseSimulator.VirtualMapping(vectorLf3.x, vectorLf3.y, vectorLf3.z, cameraPos, out vpos, out vscale); var vector3_1 = Vector3.one * vscale; if (__instance.transform.localPosition != vpos) { __instance.transform.localPosition = vpos; } if (__instance.planetData == localPlanet) { if (__instance.transform.localPosition.sqrMagnitude > 0.0) { __instance.transform.localPosition = Vector3.zero; } if (__instance.transform.localRotation != Quaternion.identity) { __instance.transform.localRotation = Quaternion.identity; } } else { __instance.transform.localRotation = Quaternion.Inverse(quaternion) * __instance.planetData.runtimeRotation; } if (__instance.transform.localScale != vector3_1) { __instance.transform.localScale = vector3_1; } var vector3_2 = Quaternion.Inverse(quaternion) * (__instance.planetData.star.uPosition - __instance.planetData.uPosition).normalized; var lhs = ___lookCamera.localPosition - __instance.transform.localPosition; var magnitude = lhs.magnitude; var localRotation = __instance.transform.localRotation; var vector4_1 = new Vector4(localRotation.x, localRotation.y, localRotation.z, localRotation.w); if (__instance.surfaceRenderer != null && __instance.surfaceRenderer.Length > 0) { var sharedMaterial = __instance.surfaceRenderer[0].sharedMaterial; sharedMaterial.SetVector("_SunDir", vector3_2); sharedMaterial.SetVector("_Rotation", new Vector4(localRotation.x, localRotation.y, localRotation.z, localRotation.w)); sharedMaterial.SetFloat("_Distance", magnitude); } if (__instance.reformRenderer != null && __instance.reformMat != null && __instance.planetData.factory != null) { var platformSystem = __instance.planetData.factory.platformSystem; var reformOffsetsBuffer = platformSystem.reformOffsetsBuffer; var reformDataBuffer = platformSystem.reformDataBuffer; __instance.reformMat.SetFloat("_LatitudeCount", platformSystem.latitudeCount); __instance.reformMat.SetVector("_SunDir", vector3_2); __instance.reformMat.SetFloat("_Distance", magnitude); __instance.reformMat.SetVector("_Rotation", vector4_1); if (platformSystem.reformData != null && reformDataBuffer != null) { reformOffsetsBuffer.SetData(platformSystem.reformOffsets); reformDataBuffer.SetData(platformSystem.reformData); __instance.reformMat.SetBuffer("_OffsetsBuffer", reformOffsetsBuffer); __instance.reformMat.SetBuffer("_DataBuffer", reformDataBuffer); } } if (!(__instance.atmoTrans0 != null)) { return(false); } __instance.atmoTrans0.rotation = ___lookCamera.localRotation; Vector4 vector4_2 = !(GameCamera.generalTarget == null) ? GameCamera.generalTarget.position : Vector3.zero; // ********************************* Fix Here for release :) var positionOffset = 0; if (localPlanet != null) { if (localPlanet.type != EPlanetType.Gas) { positionOffset = Mathf.RoundToInt(Mathf.Abs(localPlanet.radius - 200) / 2); } } Patch.Debug("positionOffset " + positionOffset, LogLevel.Debug, Patch.DebugAtmoBlur); __instance.atmoTrans1.localPosition = new Vector3(0, 0, Mathf.Clamp(Vector3.Dot(lhs, ___lookCamera.forward) + 10f / __instance.planetData.GetScaleFactored(), 0.0f, Math.Max(320f, 320f * __instance.planetData.GetScaleFactored()))); var num1 = Mathf.Clamp01(8000f * __instance.planetData.GetScaleFactored() / magnitude); var num2 = Mathf.Clamp01(4000f * __instance.planetData.GetScaleFactored() / magnitude); var atmoMatRadiusParam = __instance.atmoMatRadiusParam; atmoMatRadiusParam.z = atmoMatRadiusParam.x + (float)((__instance.atmoMatRadiusParam.z - (double)__instance.atmoMatRadiusParam.x) * (2.70000004768372 - num2 * 1.70000004768372)); Patch.Debug("__instance.atmoTrans1 " + __instance.atmoTrans1.localScale, LogLevel.Debug, Patch.DebugAtmoBlur); var vector4_3 = atmoMatRadiusParam * vscale * __instance.planetData.GetScaleFactored(); Patch.Debug("vector4_3 " + __instance.planetData.name + vector4_3, LogLevel.Debug, Patch.DebugAtmoBlur); __instance.atmoMat.SetVector("_PlanetPos", __instance.transform.localPosition); __instance.atmoMat.SetVector("_SunDir", vector3_2); __instance.atmoMat.SetVector("_PlanetRadius", vector4_3); __instance.atmoMat.SetColor("_Color4", ___star.sunAtmosColor); __instance.atmoMat.SetColor("_Sky4", ___star.sunriseAtmosColor); __instance.atmoMat.SetVector("_LocalPos", vector4_2); __instance.atmoMat.SetFloat("_SunRiseScatterPower", Mathf.Max(60f * __instance.planetData.GetScaleFactored(), (float)((magnitude - __instance.planetData.realRadius * 2.0) * 0.180000007152557))); __instance.atmoMat.SetFloat("_IntensityControl", num1); __instance.atmoMat.renderQueue = __instance.planetData != localPlanet ? 2989 : 2991; return(false); }