Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PackOffset.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;
5 using System.Collections.Generic;
6 using System.Text.RegularExpressions;
7 
8 namespace SiliconStudio.Shaders.Ast.Hlsl
9 {
10  /// <summary>
11  /// Describes a packoffset(value).
12  /// </summary>
13  public class PackOffset : Qualifier
14  {
15  #region Constructors and Destructors
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref = "PackOffset" /> class.
19  /// </summary>
20  public PackOffset()
21  : base("packoffset")
22  {
23  IsPost = true;
24  }
25 
26  /// <summary>
27  /// Initializes a new instance of the <see cref="PackOffset"/> class.
28  /// </summary>
29  /// <param name="value">
30  /// The value.
31  /// </param>
32  public PackOffset(string value)
33  : base("packoffset")
34  {
35  var identifier = new IdentifierDot();
36  identifier.Identifiers.Add(new Identifier(value));
37  Value = identifier;
38  IsPost = true;
39  }
40 
41  #endregion
42 
43  #region Public Properties
44 
45  /// <summary>
46  /// Gets or sets the value.
47  /// </summary>
48  /// <value>
49  /// The value.
50  /// </value>
51  public Identifier Value { get; set; }
52 
53  #endregion
54 
55  #region Public Methods
56 
57 
58  private static readonly Regex matchComponent = new Regex(@"^c(\d+)(\.[xyzw])?$");
59 
60  /// <summary>
61  /// Converts this packoffset to a register index based on float size.
62  /// </summary>
63  /// <returns>An offset </returns>
64  public int ToFloat4SlotIndex()
65  {
66  var match = matchComponent.Match(Value.ToString());
67  if (!match.Success)
68  return -1;
69  var index = int.Parse(match.Groups[1].Value) * 16;
70  if (match.Groups[2].Success)
71  {
72  var subComponentChar = match.Groups[2].Value[1];
73  index += "xyzw".IndexOf(subComponentChar)* 4;
74  }
75  return index;
76  }
77 
78  /// <summary>
79  /// Determines whether the specified <see cref="PackOffset"/> is equal to this instance.
80  /// </summary>
81  /// <param name="other">
82  /// The <see cref="PackOffset"/> to compare with this instance.
83  /// </param>
84  /// <returns>
85  /// <c>true</c> if the specified <see cref="PackOffset"/> is equal to this instance; otherwise, <c>false</c>.
86  /// </returns>
87  public bool Equals(PackOffset other)
88  {
89  if (ReferenceEquals(null, other))
90  {
91  return false;
92  }
93 
94  if (ReferenceEquals(this, other))
95  {
96  return true;
97  }
98 
99  return base.Equals(other) && Equals(other.Value, Value);
100  }
101 
102  /// <inheritdoc />
103  public override bool Equals(object obj)
104  {
105  if (ReferenceEquals(null, obj))
106  {
107  return false;
108  }
109 
110  if (ReferenceEquals(this, obj))
111  {
112  return true;
113  }
114 
115  return Equals(obj as PackOffset);
116  }
117 
118  /// <inheritdoc />
119  public override IEnumerable<Node> Childrens()
120  {
121  ChildrenList.Clear();
122  ChildrenList.Add(Value);
123  return ChildrenList;
124  }
125 
126  /// <inheritdoc />
127  public override int GetHashCode()
128  {
129  unchecked
130  {
131  return (base.GetHashCode() * 397) ^ (Value != null ? Value.GetHashCode() : 0);
132  }
133  }
134 
135  /// <inheritdoc />
136  public override string DisplayName
137  {
138  get
139  {
140  return string.Format(": packoffset({0})", Value);
141  }
142  }
143 
144  #endregion
145 
146  #region Operators
147 
148  /// <summary>
149  /// Implements the operator ==.
150  /// </summary>
151  /// <param name = "left">The left.</param>
152  /// <param name = "right">The right.</param>
153  /// <returns>
154  /// The result of the operator.
155  /// </returns>
156  public static bool operator ==(PackOffset left, PackOffset right)
157  {
158  return Equals(left, right);
159  }
160 
161  /// <summary>
162  /// Implements the operator !=.
163  /// </summary>
164  /// <param name = "left">The left.</param>
165  /// <param name = "right">The right.</param>
166  /// <returns>
167  /// The result of the operator.
168  /// </returns>
169  public static bool operator !=(PackOffset left, PackOffset right)
170  {
171  return !Equals(left, right);
172  }
173 
174  #endregion
175  }
176 }
override bool Equals(object obj)
Definition: PackOffset.cs:103
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
Definition: PackOffset.cs:119
PackOffset()
Initializes a new instance of the PackOffset class.
Definition: PackOffset.cs:20
Describes a packoffset(value).
Definition: PackOffset.cs:13
bool Equals(PackOffset other)
Determines whether the specified PackOffset is equal to this instance.
Definition: PackOffset.cs:87
int ToFloat4SlotIndex()
Converts this packoffset to a register index based on float size.
Definition: PackOffset.cs:64
Identifier Value
Gets or sets the value.
Definition: PackOffset.cs:51
PackOffset(string value)
Initializes a new instance of the PackOffset class.
Definition: PackOffset.cs:32