Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PermutationGeneratorBuildStep.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 
5 using SiliconStudio.Assets.Compiler;
6 using SiliconStudio.BuildEngine;
7 using SiliconStudio.Paradox.Assets.Effect.Generators;
8 using SiliconStudio.Paradox.Effects;
9 using SiliconStudio.Paradox.Shaders.Compiler;
10 
11 namespace SiliconStudio.Paradox.Assets.Effect
12 {
14  {
15  protected readonly AssetCompilerContext Context;
16 
17  protected readonly List<ICompilerParametersGenerator> CompilerParametersGenerators;
18 
19  public PermutationGeneratorBuildStep(AssetCompilerContext context, List<ICompilerParametersGenerator> compilerParametersGenerators)
20  {
21  Context = context;
22  CompilerParametersGenerators = new List<ICompilerParametersGenerator> { new DefaultCompilerParametersGenerator() };
23  CompilerParametersGenerators.AddRange(compilerParametersGenerators);
24  }
25 
26  /// <inheritdoc/>
27  public override BuildStep Clone()
28  {
29  return new PermutationGeneratorBuildStep(Context, CompilerParametersGenerators);
30  }
31 
32  /// <inheritdoc/>
33  public override string ToString()
34  {
35  return "PermutationGeneratorBuildStep";
36  }
37 
38  protected IEnumerable<CompilerParameters> GenerateKeysPermutation(CompilerParameters parameters, IList<KeyValuePair<ParameterKey, List<object>>> parameterKeys, int keyIndex = 0)
39  {
40  if (keyIndex >= parameterKeys.Count)
41  {
42  yield return parameters.Clone();
43  }
44  else
45  {
46  var keyValues = parameterKeys[keyIndex];
47  // Create one CompilerParameter per keys
48  parameters = parameters.Clone();
49  foreach (var value in keyValues.Value)
50  {
51  parameters.SetObject(keyValues.Key, value);
52  foreach (var returnParameters in GenerateKeysPermutation(parameters, parameterKeys, keyIndex + 1))
53  {
54  yield return returnParameters;
55  }
56  }
57  }
58  }
59  }
60 }
Key of an effect parameter.
Definition: ParameterKey.cs:15
A BuildStep that can spawn multiple BuildStep. Input and output tracking and merging will be performe...
The context used when compiling an asset in a Package.
readonly List< ICompilerParametersGenerator > CompilerParametersGenerators
PermutationGeneratorBuildStep(AssetCompilerContext context, List< ICompilerParametersGenerator > compilerParametersGenerators)
IEnumerable< CompilerParameters > GenerateKeysPermutation(CompilerParameters parameters, IList< KeyValuePair< ParameterKey, List< object >>> parameterKeys, int keyIndex=0)
The default implementation for ICompilerParametersGenerator simply copy a clone version of the input ...