コード例 #1
0
    private void OnHighlighted(object data)
    {
        int highlightedCell = (!(bool)data) ? (-1) : Grid.PosToCell(base.transform.GetPosition());
        ConduitFlowVisualizer flowVisualizer = GetFlowVisualizer();

        flowVisualizer.SetHighlightedCell(highlightedCell);
    }
    private void RenderMesh(float z, int render_layer, float lerp_percent, bool trigger_audio)
    {
        GridArea          visibleArea = GridVisibleArea.GetVisibleArea();
        Vector2I          min         = visibleArea.Min;
        int               a           = Mathf.Max(0, min.x - 1);
        Vector2I          min2        = visibleArea.Min;
        Vector2I          min3        = new Vector2I(a, Mathf.Max(0, min2.y - 1));
        int               a2          = Grid.WidthInCells - 1;
        Vector2I          max         = visibleArea.Max;
        int               a3          = Mathf.Min(a2, max.x + 1);
        int               a4          = Grid.HeightInCells - 1;
        Vector2I          max2        = visibleArea.Max;
        Vector2I          max3        = new Vector2I(a3, Mathf.Min(a4, max2.y + 1));
        RenderMeshContext shared_data = new RenderMeshContext(this, lerp_percent, min3, max3);

        if (shared_data.visible_conduits.Count == 0)
        {
            shared_data.Finish();
        }
        else
        {
            render_mesh_job.Reset(shared_data);
            int num  = Mathf.Max(1, (int)((float)(shared_data.visible_conduits.Count / CPUBudget.coreCount) / 1.5f));
            int num2 = Mathf.Max(1, shared_data.visible_conduits.Count / num);
            for (int i = 0; i != num2; i++)
            {
                int num3 = i * num;
                int end  = (i != num2 - 1) ? (num3 + num) : shared_data.visible_conduits.Count;
                render_mesh_job.Add(new RenderMeshTask(num3, end));
            }
            GlobalJobManager.Run(render_mesh_job);
            float z2 = 0f;
            if (showContents)
            {
                z2 = 1f;
            }
            int   num4 = (int)(animTime / (1.0 / (double)tuning.framesPerSecond)) % (int)tuning.spriteCount;
            float w    = (float)num4 * (1f / tuning.spriteCount);
            movingBallMesh.Begin();
            movingBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture);
            movingBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture);
            movingBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, w));
            movingBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f));
            staticBallMesh.Begin();
            staticBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture);
            staticBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture);
            staticBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, 0f));
            staticBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f));
            Vector3 position = CameraController.Instance.transform.GetPosition();
            ConduitFlowVisualizer visualizer = (!trigger_audio) ? null : this;
            for (int j = 0; j != render_mesh_job.Count; j++)
            {
                render_mesh_job.GetWorkItem(j).Finish(movingBallMesh, staticBallMesh, position, visualizer);
            }
            movingBallMesh.End(z, layer);
            staticBallMesh.End(z, layer);
            shared_data.Finish();
        }
    }
コード例 #3
0
            internal static void Postfix(ConduitFlowVisualizer __instance, int cell, ConduitFlow ___flowManager, bool ___showContents, ref Color32 __result)
            {
                Pressurized pressure = Integration.GetPressurizedAt(cell, (ConduitType)conduitType.GetValue(___flowManager));

                if (!Pressurized.IsDefault(pressure))
                {
                    __result = ___showContents ? pressure.Info.FlowOverlayTint : pressure.Info.FlowTint;
                }
            }
コード例 #4
0
            internal static void Prefix(ConduitFlowVisualizer __instance, int cell, ref float conductivity, ConduitFlow ___flowManager)
            {
                Pressurized pressure = Integration.GetPressurizedAt(cell, (ConduitType)conduitType.GetValue(___flowManager));

                if (!Pressurized.IsDefault(pressure))
                {
                    conductivity = 1f;
                }
            }
コード例 #5
0
 /// <summary>
 /// Forces a conduit update to run next time.
 /// </summary>
 /// <param name="instance">The conduit flow visualizer to invalidate, or null to
 /// invalidate all.</param>
 internal static void ForceUpdate(ConduitFlowVisualizer instance)
 {
     if (instance == null)
     {
         NEXT_UPDATE.Clear();
     }
     else if (NEXT_UPDATE.Count > 0)
     {
         NEXT_UPDATE.Remove(instance);
     }
 }
コード例 #6
0
    private void OnStructureTemperatureRegistered(object data)
    {
        int cell = Grid.PosToCell(this);

        GetNetworkManager().AddToNetworks(cell, this, false);
        Connect();
        GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, Db.Get().BuildingStatusItems.Pipe, this);
        BuildingDef def = GetComponent <Building>().Def;

        if ((UnityEngine.Object)def != (UnityEngine.Object)null && def.ThermalConductivity != 1f)
        {
            ConduitFlowVisualizer flowVisualizer = GetFlowVisualizer();
            flowVisualizer.AddThermalConductivity(Grid.PosToCell(base.transform.GetPosition()), def.ThermalConductivity);
        }
    }
        public RenderMeshContext(ConduitFlowVisualizer outer, float lerp_percent, Vector2I min, Vector2I max)
        {
            this.outer        = outer;
            this.lerp_percent = lerp_percent;
            visible_conduits  = ListPool <int, ConduitFlowVisualizer> .Allocate();

            visible_conduits.Capacity = outer.flowManager.soaInfo.NumEntries;
            for (int i = 0; i != outer.flowManager.soaInfo.NumEntries; i++)
            {
                Vector2I vector2I = Grid.CellToXY(outer.flowManager.soaInfo.GetCell(i));
                if (min <= vector2I && vector2I <= max)
                {
                    visible_conduits.Add(i);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Applied before Render runs.
        /// </summary>
        internal static bool Prefix(ConduitFlowVisualizer __instance, float z)
        {
            double now = Time.unscaledTime, calcUpdateRate = updateRate;
            var    cc     = CameraController.Instance;
            bool   update = true;

            // Calculate update rate otherwise
            if (__instance != null && updateRate > 0.0 && cc != null)
            {
                // Set updates to 1 Hz if zoomed way way out
                var area = cc.VisibleArea.CurrentArea;
                var max  = area.Max;
                var min  = area.Min;
                if (max.x - min.x > MAX_ZOOM || max.y - min.y > MAX_ZOOM)
                {
                    calcUpdateRate = UPDATE_RATE_ZOOMED;
                }
                if (NEXT_UPDATE.TryGetValue(__instance, out double nextConduitUpdate))
                {
                    update = now > nextConduitUpdate;
                }
                if (update)
                {
                    NEXT_UPDATE[__instance] = now + calcUpdateRate;
                }
            }
            update |= __instance.showContents;
            // If not updating, render the last mesh
            if (!update)
            {
                __instance.animTime += Time.deltaTime;
                if (!USE_MESH)
                {
                    int layer = __instance.layer;
                    DrawMesh(__instance.movingBallMesh, z, layer);
                    DrawMesh(__instance.staticBallMesh, z, layer);
                }
            }
            return(update);
        }
コード例 #9
0
    protected override void OnCleanUp()
    {
        Unsubscribe(774203113, OnBuildingBrokenDelegate, false);
        Unsubscribe(-1735440190, OnBuildingFullyRepairedDelegate, false);
        BuildingDef def = GetComponent <Building>().Def;

        if ((UnityEngine.Object)def != (UnityEngine.Object)null && def.ThermalConductivity != 1f)
        {
            ConduitFlowVisualizer flowVisualizer = GetFlowVisualizer();
            flowVisualizer.RemoveThermalConductivity(Grid.PosToCell(base.transform.GetPosition()), def.ThermalConductivity);
        }
        int cell = Grid.PosToCell(base.transform.GetPosition());

        GetNetworkManager().RemoveFromNetworks(cell, this, false);
        BuildingComplete component = GetComponent <BuildingComplete>();

        if (component.Def.ReplacementLayer == ObjectLayer.NumLayers || (UnityEngine.Object)Grid.Objects[cell, (int)component.Def.ReplacementLayer] == (UnityEngine.Object)null)
        {
            GetNetworkManager().RemoveFromNetworks(cell, this, false);
            GetFlowManager().EmptyConduit(Grid.PosToCell(base.transform.GetPosition()));
        }
        base.OnCleanUp();
    }
 public void Finish(ConduitFlowMesh moving_ball_mesh, ConduitFlowMesh static_ball_mesh, Vector3 camera_pos, ConduitFlowVisualizer visualizer)
 {
     for (int i = 0; i != moving_balls.Count; i++)
     {
         moving_balls[i].Consume(moving_ball_mesh);
     }
     moving_balls.Recycle();
     for (int j = 0; j != static_balls.Count; j++)
     {
         static_balls[j].Consume(static_ball_mesh);
     }
     static_balls.Recycle();
     if (visualizer != null)
     {
         foreach (ConduitFlow.Conduit moving_conduit in moving_conduits)
         {
             visualizer.AddAudioSource(moving_conduit, camera_pos);
         }
     }
     moving_conduits.Recycle();
 }