예제 #1
0
    public static void AddState(State state)
    {
        switch (state.Type)
        {
        case States.Idle:
            var idle = state as IdleState;
            IdleStates.Add(idle);
            break;

        case States.Build:
            var build = state as BuildState;
            BuildStates.Add(build);
            break;

        case States.Attack:
            var attack = state as AttackState;
            AttackStates.Add(attack);
            break;

        case States.Conquer:
            var conquer = state as ConquerState;
            ConquerStates.Add(conquer);
            break;

        case States.Move:
            var move = state as MoveState;
            MoveStates.Add(move);
            break;
        }
    }
예제 #2
0
        internal static VkPipeline CreatePipeline(PipelineDescription desc, Renderer renderer, uint subpass,
                                                  out BuildStates buildState)
        {
            // Validate
            var rlayout = (renderer.MSAA != MSAA.X1) ? renderer.MSAALayout ! : renderer.Layout;

            if (!desc.IsComplete)
            {
                throw new InvalidOperationException("Cannot create a pipeline from an incomplete description");
            }
            if (desc.Shader !.IsDisposed)
            {
                throw new ObjectDisposedException("desc.Shader", "Cannot build a pipeline with a disposed shader");
            }
            var cacnt = rlayout.Subpasses[subpass].ColorCount;

            if (desc.AllColorBlends !.Length != 1 && (cacnt != desc.AllColorBlends.Length))
            {
                throw new InvalidOperationException("Invalid color blend count for pipeline");
            }
            var hasds = rlayout.Subpasses[subpass].DepthOffset.HasValue;

            if (!hasds && (desc.DepthStencil !.Value.DepthMode != DepthMode.None))
            {
                throw new InvalidOperationException(
                          "Cannot perform depth/stencil operations on non-depth/stencil subpass");
            }
            if (desc.Shader !.CheckCompatiblity(desc, renderer, subpass) is string shaderErr)
            {
                throw new InvalidOperationException($"Invalid shader for pipeline - {shaderErr}");
            }

            // Describe the color blends
            var cblends = (desc.AllColorBlends.Length != 1)
                                ? desc.AllColorBlends !
                                : Enumerable.Repeat((ColorBlendState)desc.SharedColorBlend !, (int)cacnt).ToArray();

            // Vertex info
            CalculateVertexInfo(desc.VertexDescriptions !, out var vertexAttrs, out var vertexBinds);

            // Create the build states
            buildState = new(
                cblends,
                desc.BlendConstants,
                (DepthStencilState)desc.DepthStencil !,
                (VertexInput)desc.VertexInput !,
                vertexBinds,
                vertexAttrs,
                (RasterizerState)desc.Rasterizer !
                );

            // Create the initial pipeline
            return(CreatePipeline(buildState, renderer, subpass, desc.Shader !.Layout, desc.Shader.Program));
        }
예제 #3
0
    void OnMouseUp()
    {
        if (State == BuildStates.Draging)
        {
            State = BuildStates.Stay;
            GlobalEvents.Instance.OnEndBuildDraging();
            CameraRayCaster.Instance.transform.parent.GetComponent<FolowObject>().SetSpeed(3);
            CameraRayCaster.Instance.transform.parent.GetComponent<FolowObject>().SetTarget(PlayerControll.Instance.gameObject);

        }
    }
예제 #4
0
    static public void ClearBundleBuildStates(List <BundleDependsData> Data)
    {
        HashSet <string> set = new HashSet <string>();

        for (int i = 0; i < Data.Count; i++)
        {
            set.Add(Data[i].name);
        }

        for (int i = BuildStates.Count - 1; i >= 0; i--)
        {
            if (!set.Contains(Path.GetFileNameWithoutExtension(BuildStates[i].bundlePath)))
            {
                BuildStates.RemoveAt(i);
            }
        }

        SaveBundleBuildeStates();
    }
예제 #5
0
 void OnMouseDrag()
 {
     if (EditorMode && CameraRayCaster.Instance.enabled)
     {
         if (State == BuildStates.Stay)
         {
             GlobalEvents.Instance.OnBeginBuildDraging();
             CameraRayCaster.Instance.transform.parent.GetComponent<FolowObject>().SetSpeed(1);
             CameraRayCaster.Instance.transform.parent.GetComponent<FolowObject>().SetTarget(gameObject);
         }
         State = BuildStates.Draging;
         RaycastHit hit;
         Ray ray = CameraRayCaster.Instance.GameCamera.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 10))
         {
             SnappingGrid grid = hit.collider.GetComponent<SnappingGrid>();
             if(grid!=null)
                 Pivot.position = grid.GetNearestPosition(hit.point);
         }
     }
 }
예제 #6
0
    public static void RemoveState(State state)
    {
        switch (state.Type)
        {
        case States.Idle:
            if (IdleStates.Contains(state))
            {
                IdleStates.Remove(state);
            }
            break;

        case States.Build:
            if (BuildStates.Contains(state))
            {
                BuildStates.Remove(state);
            }
            break;

        case States.Attack:
            if (AttackStates.Contains(state))
            {
                AttackStates.Remove(state);
            }
            break;

        case States.Conquer:
            if (ConquerStates.Contains(state))
            {
                ConquerStates.Remove(state);
            }
            break;

        case States.Move:
            if (MoveStates.Contains(state))
            {
                MoveStates.Remove(state);
            }
            break;
        }
    }
예제 #7
0
        // Create a pipeline from a set of build states and a shader
        private static VkPipeline CreatePipeline(BuildStates states, Renderer renderer, uint subpass,
                                                 ShaderLayout shaderLayout, ShaderProgram shaderProgram)
        {
            var MAIN_STR = stackalloc byte[5] {
                (byte)'m', (byte)'a', (byte)'i', (byte)'n', (byte)'\0'
            };

            // Color blends
            var cblends = stackalloc VkPipelineColorBlendAttachmentState[states.ColorBlends.Length];

            for (int i = 0; i < states.ColorBlends.Length; ++i)
            {
                states.ColorBlends[i].ToVk(out cblends[i]);
            }
            VkPipelineColorBlendStateCreateInfo colorBlendCI = new(
                flags : VkPipelineColorBlendStateCreateFlags.NoFlags,
                logicOpEnable : false,                // TODO: Maybe enable this in the future
                logicOp : VkLogicOp.Clear,
                attachmentCount : (uint)states.ColorBlends.Length,
                attachments : cblends,
                blendConstants_0 : states.BlendConstants.R,
                blendConstants_1 : states.BlendConstants.G,
                blendConstants_2 : states.BlendConstants.B,
                blendConstants_3 : states.BlendConstants.A
                );

            // Inferred state objects
            VkPipelineMultisampleStateCreateInfo msaaCI = new(
                flags : VkPipelineMultisampleStateCreateFlags.NoFlags,
                rasterizationSamples : (VkSampleCountFlags)renderer.MSAA,
                sampleShadingEnable : false,                // TODO: Allow sample shading
                minSampleShading : 0,
                sampleMask : null,
                alphaToCoverageEnable : false,
                alphaToOneEnable : false
                );

            // Constant state objects
            var dynstates = stackalloc VkDynamicState[2] {
                VkDynamicState.Viewport, VkDynamicState.Scissor
            };
            VkViewport viewport = new();
            VkRect2D   scissor  = new();
            VkPipelineViewportStateCreateInfo viewportCI = new(             // Dummy value b/c dynamic state
                flags : VkPipelineViewportStateCreateFlags.NoFlags,
                viewportCount : 1,
                viewports : &viewport,
                scissorCount : 1,
                scissors : &scissor
                );
            VkPipelineDynamicStateCreateInfo dynamicCI = new(
                flags : VkPipelineDynamicStateCreateFlags.NoFlags,
                dynamicStateCount : 2,
                dynamicStates : dynstates
                );

            // Shader create info
            var stageCIs = shaderProgram.EnumerateModules().Select(mod => new VkPipelineShaderStageCreateInfo(
                                                                       flags: VkPipelineShaderStageCreateFlags.NoFlags,
                                                                       stage: (VkShaderStageFlags)mod.stage,
                                                                       module: mod.mod,
                                                                       name: MAIN_STR,
                                                                       specializationInfo: null // TODO: Public API for specialization
                                                                       )).ToArray();

            VkPipelineTessellationStateCreateInfo.New(out var tessCI);

            // State cached objects
            states.DepthStencil.ToVk(out var depthStencilCI);
            states.VertexInput.ToVk(out var vertexInputCI);
            states.RasterizerState.ToVk(out var rasterCI);

            // Create the pipeline
            fixed(VkPipelineShaderStageCreateInfo *stagePtr = stageCIs)
            fixed(VkVertexInputAttributeDescription * attributePtr = states.VertexAttributes)
            fixed(VkVertexInputBindingDescription * bindingPtr     = states.VertexBindings)
            {
                // Additional create objects
                VkPipelineVertexInputStateCreateInfo vertexCI = new(
                    flags : VkPipelineVertexInputStateCreateFlags.NoFlags,
                    vertexBindingDescriptionCount : (uint)states.VertexBindings.Length,
                    vertexBindingDescriptions : bindingPtr,
                    vertexAttributeDescriptionCount : (uint)states.VertexAttributes.Length,
                    vertexAttributeDescriptions : attributePtr
                    );

                // Create info
                VkGraphicsPipelineCreateInfo ci = new(
                    flags : VkPipelineCreateFlags.NoFlags,                    // TODO: see if we can utilize some of the flags
                    stageCount : (uint)stageCIs.Length,
                    stages : stagePtr,
                    vertexInputState : &vertexCI,
                    inputAssemblyState : &vertexInputCI,
                    tessellationState : &tessCI,
                    viewportState : &viewportCI,
                    rasterizationState : &rasterCI,
                    multisampleState : &msaaCI,
                    depthStencilState : &depthStencilCI,
                    colorBlendState : &colorBlendCI,
                    dynamicState : &dynamicCI,
                    layout : shaderLayout.PipelineLayout,
                    renderPass : renderer.RenderPass,
                    subpass : subpass,
                    basePipelineHandle : VulkanHandle <VkPipeline> .Null,
                    basePipelineIndex : 0
                    );
                VulkanHandle <VkPipeline> pipelineHandle;

                renderer.Graphics.Resources.PipelineCache.CreateGraphicsPipelines(1, &ci, null, &pipelineHandle)
                .Throw("Failed to recreate pipeline object");
                return(new(pipelineHandle, renderer.Graphics.VkDevice));
            }
        }