forked from ricardojmendez/LibNoise.Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleBase.cs
executable file
·187 lines (160 loc) · 5.08 KB
/
ModuleBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Xml.Serialization;
using UnityEngine;
using Debug = System.Diagnostics.Debug;
namespace LibNoise
{
#region Enumerations
/// <summary>
/// Defines a collection of quality modes.
/// </summary>
public enum QualityMode
{
Low,
Medium,
High,
}
#endregion
/// <summary>
/// Base class for noise modules.
/// </summary>
public abstract class ModuleBase : IDisposable
{
#region Fields
private ModuleBase[] _modules;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of Helpers.
/// </summary>
/// <param name="count">The number of source modules.</param>
protected ModuleBase(int count)
{
if (count > 0)
{
_modules = new ModuleBase[count];
}
}
#endregion
#region Indexers
/// <summary>
/// Gets or sets a source module by index.
/// </summary>
/// <param name="index">The index of the source module to aquire.</param>
/// <returns>The requested source module.</returns>
public virtual ModuleBase this[int index]
{
get
{
Debug.Assert(_modules != null);
Debug.Assert(_modules.Length > 0);
if (index < 0 || index >= _modules.Length)
{
throw new ArgumentOutOfRangeException("Index out of valid module range");
}
if (_modules[index] == null)
{
throw new ArgumentNullException("Desired element is null");
}
return _modules[index];
}
set
{
Debug.Assert(_modules.Length > 0);
if (index < 0 || index >= _modules.Length)
{
throw new ArgumentOutOfRangeException("Index out of valid module range");
}
if (value == null)
{
throw new ArgumentNullException("Value should not be null");
}
_modules[index] = value;
}
}
#endregion
#region Properties
protected ModuleBase[] Modules
{
get { return _modules; }
}
/// <summary>
/// Gets the number of source modules required by this noise module.
/// </summary>
public int SourceModuleCount
{
get { return (_modules == null) ? 0 : _modules.Length; }
}
#endregion
#region Methods
/// <summary>
/// Returns the output value for the given input coordinates.
/// </summary>
/// <param name="x">The input coordinate on the x-axis.</param>
/// <param name="y">The input coordinate on the y-axis.</param>
/// <param name="z">The input coordinate on the z-axis.</param>
/// <returns>The resulting output value.</returns>
public abstract double GetValue(double x, double y, double z);
/// <summary>
/// Returns the output value for the given input coordinates.
/// </summary>
/// <param name="coordinate">The input coordinate.</param>
/// <returns>The resulting output value.</returns>
public double GetValue(Vector3 coordinate)
{
return GetValue(coordinate.x, coordinate.y, coordinate.z);
}
/// <summary>
/// Returns the output value for the given input coordinates.
/// </summary>
/// <param name="coordinate">The input coordinate.</param>
/// <returns>The resulting output value.</returns>
public double GetValue(ref Vector3 coordinate)
{
return GetValue(coordinate.x, coordinate.y, coordinate.z);
}
#endregion
#region IDisposable Members
[XmlIgnore]
#if !XBOX360 && !ZUNE
[NonSerialized]
#endif
private bool _disposed;
/// <summary>
/// Gets a value whether the object is disposed.
/// </summary>
public bool IsDisposed
{
get { return _disposed; }
}
/// <summary>
/// Immediately releases the unmanaged resources used by this object.
/// </summary>
public void Dispose()
{
if (!_disposed)
{
_disposed = Disposing();
}
GC.SuppressFinalize(this);
}
/// <summary>
/// Immediately releases the unmanaged resources used by this object.
/// </summary>
/// <returns>True if the object is completely disposed.</returns>
protected virtual bool Disposing()
{
if (_modules != null)
{
for (var i = 0; i < _modules.Length; i++)
{
_modules[i].Dispose();
_modules[i] = null;
}
_modules = null;
}
return true;
}
#endregion
}
}