using System;
using System.Xml.Serialization;
using UnityEngine;
using Debug = System.Diagnostics.Debug;
namespace LibNoise
{
#region Enumerations
///
/// Defines a collection of quality modes.
///
public enum QualityMode
{
Low,
Medium,
High,
}
#endregion
///
/// Base class for noise modules.
///
public abstract class ModuleBase : IDisposable
{
#region Fields
private ModuleBase[] _modules;
#endregion
#region Constructors
///
/// Initializes a new instance of Helpers.
///
/// The number of source modules.
protected ModuleBase(int count)
{
if (count > 0)
{
_modules = new ModuleBase[count];
}
}
#endregion
#region Indexers
///
/// Gets or sets a source module by index.
///
/// The index of the source module to aquire.
/// The requested source module.
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; }
}
///
/// Gets the number of source modules required by this noise module.
///
public int SourceModuleCount
{
get { return (_modules == null) ? 0 : _modules.Length; }
}
#endregion
#region Methods
///
/// Returns the output value for the given input coordinates.
///
/// The input coordinate on the x-axis.
/// The input coordinate on the y-axis.
/// The input coordinate on the z-axis.
/// The resulting output value.
public abstract double GetValue(double x, double y, double z);
///
/// Returns the output value for the given input coordinates.
///
/// The input coordinate.
/// The resulting output value.
public double GetValue(Vector3 coordinate)
{
return GetValue(coordinate.x, coordinate.y, coordinate.z);
}
///
/// Returns the output value for the given input coordinates.
///
/// The input coordinate.
/// The resulting output value.
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;
///
/// Gets a value whether the object is disposed.
///
public bool IsDisposed
{
get { return _disposed; }
}
///
/// Immediately releases the unmanaged resources used by this object.
///
public void Dispose()
{
if (!_disposed)
{
_disposed = Disposing();
}
GC.SuppressFinalize(this);
}
///
/// Immediately releases the unmanaged resources used by this object.
///
/// True if the object is completely disposed.
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
}
}