Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ThumbnailListCompiler.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 
4 using System;
5 using System.Collections.Generic;
6 
7 using SiliconStudio.BuildEngine;
8 
9 namespace SiliconStudio.Assets.Compiler
10 {
11  /// <summary>
12  /// A thumbnail list compiler.
13  /// This compiler creates the list of build steps to perform to produce the thumbnails of an list of <see cref="AssetItem"/>.
14  /// </summary>
16  {
18 
19  private readonly ThumbnailCompilerContext context;
20 
21  private Func<AssetItem> getNextThumbnailToBuild;
22  private readonly object internObjectsLock = new object();
23 
24  private readonly AssetCompilerResult compilationResult = new AssetCompilerResult();
25 
26  /// <summary>
27  /// A list of queued build step already generated waiting to be executed.
28  /// </summary>
29  private readonly Queue<BuildStep> nextBuildSteps = new Queue<BuildStep>();
30 
31  /// <summary>
32  /// Creates an instance of <see cref="ThumbnailListCompiler"/>.
33  /// </summary>
36  {
37  if (context == null) throw new ArgumentNullException("context");
38 
39  this.context = context;
40  }
41 
42  /// <summary>
43  /// Gets or sets the handler providing the list of items to build to the compiler
44  /// </summary>
45  public Func<AssetItem> GetNextThumbnailToBuild
46  {
47  get { return getNextThumbnailToBuild; }
48  set
49  {
50  lock (internObjectsLock)
51  getNextThumbnailToBuild = value;
52  }
53  }
54 
55  /// <summary>
56  /// Get the next build step to execute to compile the thumbnail.
57  /// </summary>
58  /// <returns></returns>
60  {
61  // dequeue previously needed build steps
62  if (nextBuildSteps.Count > 0)
63  return nextBuildSteps.Dequeue();
64 
65  // get the next asset item to compile
66  AssetItem nextItem = null;
67  lock (internObjectsLock)
68  {
69  if (GetNextThumbnailToBuild != null)
70  nextItem = GetNextThumbnailToBuild();
71  }
72 
73  // add the compilation steps to the queue
74  if (nextItem != null)
75  {
76  // add the compilation of the thumbnail itself
77  nextBuildSteps.Enqueue(CompileItem(context, compilationResult, nextItem));
78  }
79 
80  // return the new first build step if any
81  if (nextBuildSteps.Count > 0)
82  return nextBuildSteps.Dequeue();
83 
84  return null; // no work to do for the moment
85  }
86 
87  /// <summary>
88  /// Register a default compiler to use when no compiler is explicitly associated to an asset type.
89  /// </summary>
90  /// <param name="compiler">The compiler to use as default compiler (can be null)</param>
91  public static void RegisterDefaultThumbnailCompiler(IAssetCompiler compiler)
92  {
93  ThumbnailCompilerRegistry.DefaultCompiler = compiler;
94  }
95  }
96 }
Result of a compilation of assets when using IAssetCompiler.Compile
A thumbnail list compiler. This compiler creates the list of build steps to perform to produce the th...
static void RegisterDefaultThumbnailCompiler(IAssetCompiler compiler)
Register a default compiler to use when no compiler is explicitly associated to an asset type...
ThumbnailListCompiler(ThumbnailCompilerContext context)
Creates an instance of ThumbnailListCompiler.
An asset item part of a Package accessible through SiliconStudio.Assets.Package.Assets.
Definition: AssetItem.cs:17
BuildStep GetNextBuildStep()
Get the next build step to execute to compile the thumbnail.
The base class to compile a series of AssetItems using associated IAssetCompilers. An item list compiler only creates the build steps required to creates some output items. The result of a compilation has then to be executed by the build engine to effectively create the outputs items.
A registry containing the thumbnail compilers of the assets.
Main interface for compiling an Asset.
This interface describes a class that is capable of providing build steps to a DynamicBuildStep.
The context used when building the thumbnail of an asset in a Package.