Beispiel #1
0
        private void Render()
        {
            Vector2I vector2I  = default(Vector2I);
            Vector2I vector2I2 = default(Vector2I);

            if (GameUtil.IsCapturingTimeLapse())
            {
                vector2I  = new Vector2I(0, 0);
                vector2I2 = new Vector2I(Grid.WidthInCells / 16, Grid.HeightInCells / 16);
            }
            else
            {
                GridArea visibleArea = GridVisibleArea.GetVisibleArea();
                Vector2I min         = visibleArea.Min;
                int      a           = min.x / 16;
                Vector2I min2        = visibleArea.Min;
                vector2I = new Vector2I(a, min2.y / 16);
                Vector2I max  = visibleArea.Max;
                int      a2   = (max.x + 16 - 1) / 16;
                Vector2I max2 = visibleArea.Max;
                vector2I2 = new Vector2I(a2, (max2.y + 16 - 1) / 16);
            }
            foreach (KeyValuePair <KeyValuePair <BuildingDef, RenderInfoLayer>, RenderInfo> item in renderInfo)
            {
                RenderInfo value = item.Value;
                for (int i = vector2I.y; i < vector2I2.y; i++)
                {
                    for (int j = vector2I.x; j < vector2I2.x; j++)
                    {
                        value.Rebuild(this, j, i, MeshUtil.vertices, MeshUtil.uvs, MeshUtil.indices, MeshUtil.colours);
                        value.Render(j, i);
                    }
                }
            }
        }
    private void TriggerAudio(int old_value)
    {
        SpeedControlScreen instance = SpeedControlScreen.Instance;

        if (old_value != outputValue && (Object)instance != (Object)null && !instance.IsPaused)
        {
            GridArea         visibleArea = GridVisibleArea.GetVisibleArea();
            List <LogicWire> list        = new List <LogicWire>();
            for (int i = 0; i < wires.Count; i++)
            {
                if (visibleArea.Min <= (Vector2)wires[i].transform.GetPosition() && (Vector2)wires[i].transform.GetPosition() <= visibleArea.Max)
                {
                    list.Add(wires[i]);
                }
            }
            if (list.Count > 0)
            {
                int index = Mathf.CeilToInt((float)(list.Count / 2));
                if ((Object)list[index] != (Object)null)
                {
                    Vector3       position  = list[index].transform.GetPosition();
                    EventInstance instance2 = KFMOD.BeginOneShot(GlobalAssets.GetSound("Logic_Circuit_Toggle", false), position);
                    instance2.setParameterValue("wireCount", (float)(wires.Count % 24));
                    instance2.setParameterValue("enabled", (float)outputValue);
                    KFMOD.EndOneShot(instance2);
                }
            }
        }
    }
    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();
        }
    }
    private void LateUpdate()
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();
        Vector2I min         = visibleArea.Min;
        Vector2I max         = visibleArea.Max;
        Vector2I vector2I    = min + (max - min) / 2;
        Camera   main        = Camera.main;
        Vector3  position    = Camera.main.transform.GetPosition();
        Vector3  a           = main.ViewportToWorldPoint(new Vector3(1f, 1f, position.z));
        Camera   main2       = Camera.main;
        Vector3  position2   = Camera.main.transform.GetPosition();
        Vector3  vector      = main2.ViewportToWorldPoint(new Vector3(0f, 0f, position2.z));
        Vector3  a2          = vector + (a - vector) / 2f;
        Vector3  a3          = a - vector;

        if (a3.x > a3.y)
        {
            a3.y = a3.x;
        }
        else
        {
            a3.x = a3.y;
        }
        a      = a2 + a3 / 2f;
        vector = a2 - a3 / 2f;
        Vector3 a4      = a3 / 2f;
        Vector3 vector2 = a4 / 2f;

        quadrants[0].Update(new Vector2I(min.x, min.y), new Vector2I(vector2I.x, vector2I.y), new Vector3(vector.x + vector2.x, vector.y + vector2.y, emitterZPosition));
        quadrants[1].Update(new Vector2I(vector2I.x, min.y), new Vector2I(max.x, vector2I.y), new Vector3(a2.x + vector2.x, vector.y + vector2.y, emitterZPosition));
        quadrants[2].Update(new Vector2I(min.x, vector2I.y), new Vector2I(vector2I.x, max.y), new Vector3(vector.x + vector2.x, a2.y + vector2.y, emitterZPosition));
        quadrants[3].Update(new Vector2I(vector2I.x, vector2I.y), new Vector2I(max.x, max.y), new Vector3(a2.x + vector2.x, a2.y + vector2.y, emitterZPosition));
        float num  = 0f;
        float num2 = 0f;
        float num3 = 0f;

        for (int i = 0; i < quadrants.Length; i++)
        {
            num  += (float)quadrants[i].spaceLayer.tileCount;
            num2 += (float)quadrants[i].facilityLayer.tileCount;
            num3 += (float)quadrants[i].totalTileCount;
        }
        AudioMixer.instance.UpdateSpaceVisibleSnapshot(num / num3);
        AudioMixer.instance.UpdateFacilityVisibleSnapshot(num2 / num3);
    }
    public void UpdateTemperature()
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();

        for (int i = 0; i < data.Count; i++)
        {
            InfraredVisualizerData infraredVisualizerData = data[i];
            KAnimControllerBase    controller             = infraredVisualizerData.controller;
            if ((Object)controller != (Object)null)
            {
                Vector3 position = controller.transform.GetPosition();
                if (visibleArea.Min <= (Vector2)position && (Vector2)position <= visibleArea.Max)
                {
                    data[i].Update();
                }
            }
        }
    }
Beispiel #6
0
    public bool IsVisiblePos(Vector3 pos)
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();

        return(visibleArea.Min <= (Vector2)pos && (Vector2)pos <= visibleArea.Max);
    }
Beispiel #7
0
    public void UpdateOverlayColours()
    {
        GridArea visibleArea = GridVisibleArea.GetVisibleArea();
        Diseases diseases    = Db.Get().Diseases;
        Color32  color       = new Color32(0, 0, 0, byte.MaxValue);

        for (int i = 0; i < headers.Count; i++)
        {
            DiseaseContainer       payload    = payloads[i];
            DiseaseHeader          header     = headers[i];
            KBatchedAnimController controller = payload.controller;
            if ((UnityEngine.Object)controller != (UnityEngine.Object)null)
            {
                Color32 c        = color;
                Vector3 position = controller.transform.GetPosition();
                if (visibleArea.Min <= (Vector2)position && (Vector2)position <= visibleArea.Max)
                {
                    int num           = 0;
                    int disease_idx   = 255;
                    int disease_count = 0;
                    GetVisualDiseaseIdxAndCount(header, ref payload, out disease_idx, out disease_count);
                    if (disease_idx != 255)
                    {
                        c   = diseases[disease_idx].overlayColour;
                        num = disease_count;
                    }
                    if (payload.isContainer)
                    {
                        Storage           component = header.primaryElement.GetComponent <Storage>();
                        List <GameObject> items     = component.items;
                        for (int j = 0; j < items.Count; j++)
                        {
                            GameObject gameObject = items[j];
                            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
                            {
                                HandleVector <int> .Handle handle = GetHandle(gameObject);
                                if (handle.IsValid())
                                {
                                    DiseaseHeader header2 = GetHeader(handle);
                                    if (header2.diseaseCount > num && header2.diseaseIdx != 255)
                                    {
                                        num = header2.diseaseCount;
                                        c   = diseases[header2.diseaseIdx].overlayColour;
                                    }
                                }
                            }
                        }
                    }
                    c.a = SimUtil.DiseaseCountToAlpha254(num);
                    if (payload.conduitType != 0)
                    {
                        ConduitFlow flowManager = Conduit.GetFlowManager(payload.conduitType);
                        int         cell        = Grid.PosToCell(position);
                        ConduitFlow.ConduitContents contents = flowManager.GetContents(cell);
                        if (contents.diseaseIdx != 255 && contents.diseaseCount > num)
                        {
                            num = contents.diseaseCount;
                            c   = diseases[contents.diseaseIdx].overlayColour;
                            c.a = byte.MaxValue;
                        }
                    }
                }
                controller.OverlayColour = c;
            }
        }
    }