Esempio n. 1
0
        public static byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            // Always output a result into the file
            string result;

            try
            {
                var parsingResult = ParadoxShaderParser.TryPreProcessAndParse(inputFileContent, inputFileName);

                if (parsingResult.HasErrors)
                {
                    result = "// Failed to parse the shader:\n" + parsingResult;
                }
                else
                {
                    // Try to generate a mixin code.
                    var shaderKeyGenerator = new ShaderMixinCodeGen(parsingResult.Shader, parsingResult);

                    shaderKeyGenerator.Run();
                    result = shaderKeyGenerator.Text ?? string.Empty;
                }
            }
            catch (Exception ex)
            {
                result = "// Unexpected exceptions occurred while generating the file\n" + ex;
            }

            // We force the UTF8 to include the BOM to match VS default
            var data = Encoding.UTF8.GetBytes(result);

            return(Encoding.UTF8.GetPreamble().Concat(data).ToArray());
        }
            protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext)
            {
                var logger = commandContext.Logger;

                var status = ResultStatus.Successful;

                try
                {
                    var parsingResults = ParadoxShaderParser.TryPreProcessAndParse(asset.Text, sourceLocationOnDisk);
                    if (parsingResults.HasErrors)
                    {
                        foreach (var message in parsingResults.Messages)
                        {
                            if (message.Level == ReportMessageLevel.Error)
                            {
                                logger.Error(message.ToString());
                            }
                        }
                        return(Task.FromResult(ResultStatus.Failed));
                    }

                    var shader       = parsingResults.Shader;
                    var loggerResult = new LoggerResult();

                    // Run shader codegen mixin in order to check that everything is well defined and compiled
                    var shaderMixinCodeGen = new ShaderMixinCodeGen(shader, loggerResult);
                    shaderMixinCodeGen.Run();
                }
                catch (Exception ex)
                {
                    commandContext.Logger.Error("Error while processing pdxfx [{0}]", ex, sourceLocationOnDisk);
                    status = ResultStatus.Failed;
                }

                return(Task.FromResult(status));
            }