Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModelNodeLinkProcessor.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;
4 using System.Collections.Generic;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Extensions;
7 using SiliconStudio.Paradox.Effects;
8 using SiliconStudio.Paradox.EntityModel;
9 using SiliconStudio.Paradox.Games;
10 
11 namespace SiliconStudio.Paradox.Engine
12 {
13  public class ModelNodeLinkProcessor : EntityProcessor<ModelNodeLinkComponent>
14  {
15  internal HashSet<ModelNodeLinkComponent> DirtyLinks = new HashSet<ModelNodeLinkComponent>();
16  internal MeshProcessor meshProcessor;
17 
19  : base(new PropertyKey[] { TransformationComponent.Key, ModelNodeLinkComponent.Key })
20  {
21  }
22 
24  {
25  return entity.Get(ModelNodeLinkComponent.Key);
26  }
27 
28  protected override void OnEntityAdding(Entity entity, ModelNodeLinkComponent modelNodeLinkComponent)
29  {
30  entity.Transformation.UseTRS = false;
31  entity.Transformation.isSpecialRoot = true;
32 
33  modelNodeLinkComponent.Processor = this;
34 
35  if (meshProcessor == null)
36  meshProcessor = EntitySystem.GetProcessor<MeshProcessor>();
37 
38  lock (DirtyLinks)
39  {
40  DirtyLinks.Add(modelNodeLinkComponent);
41 
42  // Mark it as invalid
43  modelNodeLinkComponent.EntityLink.NodeIndex = -1;
44  }
45  }
46 
47  protected override void OnEntityRemoved(Entity entity, ModelNodeLinkComponent modelNodeLinkComponent)
48  {
49  if (meshProcessor == null)
50  meshProcessor = EntitySystem.GetProcessor<MeshProcessor>();
51 
52  meshProcessor.UnlinkEntity(modelNodeLinkComponent.EntityLink);
53 
54  modelNodeLinkComponent.Processor = null;
55  }
56 
57  public override void Draw(GameTime time)
58  {
59  lock (DirtyLinks)
60  {
61  if (DirtyLinks.Count == 0)
62  return;
63 
64  if (meshProcessor == null)
65  meshProcessor = EntitySystem.GetProcessor<MeshProcessor>();
66 
67  foreach (var transformationLinkComponent in DirtyLinks)
68  {
69  // ModelNodeLinkComponent has been changed, regenerate link
70  meshProcessor.UnlinkEntity(transformationLinkComponent.EntityLink);
71  meshProcessor.LinkEntity(transformationLinkComponent.Entity, transformationLinkComponent.Target, transformationLinkComponent.NodeName);
72  }
73 
74  DirtyLinks.Clear();
75  }
76  }
77  }
78 }
Game entity. It usually aggregates multiple EntityComponent
Definition: Entity.cs:28
Entity processor, triggered on various EntitySystem events such as Entity and Component additions and...
Current timing used for variable-step (real time) or fixed-step (game time) games.
Definition: GameTime.cs:31
A class that represents a tag propety.
Definition: PropertyKey.cs:17