Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DelegateHolder.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 
5 namespace SiliconStudio.Paradox
6 {
7  /// <summary>
8  /// Delegate for a RenderPass action used by <see cref="Effects.RenderPass.StartPass"/> and <see cref="Effects.RenderPass.EndPass"/>.
9  /// </summary>
10  /// <param name="param">The param.</param>
11  public struct DelegateHolder<T1>
12  {
13  public DelegateHolder(DelegateType delegateValue)
14  {
15  currentDelegate = delegateValue;
16  }
17 
18  public static DelegateHolder<T1> operator +(DelegateHolder<T1> delegateHolder, DelegateType delegateValue)
19  {
20  if (delegateHolder.currentDelegate == null)
21  return new DelegateHolder<T1>(delegateValue);
22  return new DelegateHolder<T1>(delegateHolder.currentDelegate + delegateValue);
23  }
24 
25  public static DelegateHolder<T1> operator -(DelegateHolder<T1> delegateHolder, DelegateType delegateValue)
26  {
27  if (delegateHolder.currentDelegate == null)
28  return delegateHolder;
29 
30  return new DelegateHolder<T1>((DelegateType)Delegate.Remove(delegateHolder.currentDelegate, delegateValue));
31  }
32 
33  /// <summary>
34  /// Delegate for a RenderPass action used by <see cref="Effects.RenderPass.StartPass"/> and <see cref="Effects.RenderPass.EndPass"/>.
35  /// </summary>
36  /// <param name="param">The param.</param>
37  public delegate void DelegateType(T1 param);
38 
39  private DelegateType currentDelegate;
40 
41  public void Invoke(T1 param)
42  {
43  if (currentDelegate != null)
44  currentDelegate(param);
45  }
46 
47  /// <summary>
48  /// Set delegate action.
49  /// </summary>
50  /// <value>
51  /// The action to set.
52  /// </value>
53  public DelegateType Set
54  {
55  set
56  {
57  currentDelegate = value;
58  }
59  }
60 
61  /// <summary>
62  /// Adds an action at the end of the invocation list.
63  /// </summary>
64  /// <value>
65  /// The action to add.
66  /// </value>
67  public DelegateType AddLast
68  {
69  set
70  {
71  if (currentDelegate == null)
72  currentDelegate = value;
73  else
74  currentDelegate += value;
75  }
76  }
77 
78  /// <summary>
79  /// Adds an action at the beginning of the invocation list.
80  /// </summary>
81  /// <value>
82  /// The action to add.
83  /// </value>
84  public DelegateType AddFirst
85  {
86  set
87  {
88  if (currentDelegate == null)
89  currentDelegate = value;
90  else
91  currentDelegate = (DelegateType)Delegate.Combine(value, currentDelegate);
92  }
93  }
94  }
95 }
DelegateHolder(DelegateType delegateValue)
Delegate for a RenderPass action used by Effects.RenderPass.StartPass and Effects.RenderPass.EndPass.