DeltaMonitor Class Reference

This class is used to gather and store all the DeltaAttribute attributes in the class it resides in. It provides functions to allow checking and updating of ALL the gathered attributes with a single call. There is a property drawer for this class that makes the OptioNames variable display as a mask field. Unity Programmers may use the DeltaMonitorUnity version of this class, to simplify usage.

Detailed Description

Class Usage Example

Class Usage Example

Class Usage Example
Class Usage Example

Class Usage Example

[System.Serializable]
public class Atmosphere
{
[Delta("Amto Height", SetID = 0)]
public float topOfAtmosphere = 20;
[Delta("Max Pressure", SetID = 0)]
public float seaLevelPressure = 10;
DeltaMonitor deltaMonitor; //The DeltaMonitor will keep a list of all members with the Delta attribute.
private float[] pressureGradient;
public Atmosphere()
{
deltaMonitor = new DeltaMonitor(this);// We pass "this" to the constructor, so the DeltaMointor will look through the "the newly instantiated atmosphere object", for DeltaAttributes (and record them).
deltaMonitor.ApplyMaxSet(0);
RecomputePressureGradient();
}
//This function is very expensive to compute.
private void RecomputePressureGradient()
{
pressureGradient = new float[1000];
for (int i = 0; i < 1000; i++)
{
float fraction = i / 1000;// (i * 1000) / topOfAtmosphere;
float pressure = 1 - Mathf.Log(fraction * fraction * fraction * 9 + 1);
pressure *= pressure;
pressure *= seaLevelPressure;
pressureGradient[i] = pressure;
}
}
//This function shows the ideal usage of DeltaDetector: we only detect changes when we need to read a value that is Dependant upon them.
public float GetAirPressureAtAltitude(float alt)
{
if (alt < 0) alt = 0;
if (deltaMonitor.DetectChanges()) // tells the DeltaMonitor to look through it's DeltaAttribute value cache, and see if any values therein do not match the current member values.
{
// Debug.Log("DeltaDetected In Atmosphere");
RecomputePressureGradient();
deltaMonitor.ResetValues(); //tells the DeltaMonitor to update it's DeltaAttribute value cache with current member values.
}
float fraction = alt / topOfAtmosphere;
int index = (int)(fraction * 1000.0f);
if (index < pressureGradient.Length)
return pressureGradient[index];
return 0;
}
}

Separate Example

Public Member Functions

 DeltaMonitor (object _objectToMonitor)
 Performs the same functions as Init(), once the object is instantiated. But, also, once initialized, sets all attributes to be "enabled".
 
void ApplyMaxSet (int newMaxSet)
 this function is used to specify a new MaxSet value. Only Delta attribute with an assigned set LOWER than or equal to the MaxSet, will be checked for changes.
 
void DeserializedDetectionEnabledList ()
 Reads from SelectOptions string array and for every DeltaAttribue named on the list, sets them to enabled. Existing DeltaAttribue that are NOT named by the list, are set to NOT enabled.
 
bool DetectChanges ()
 One of the primary functions for this class, it will check attributes to see if their value has changed.
 
bool DetectChangesInSet (int set)
 Will check all stored attributes to see if their value has changed. Only DeltaAttributes that have been assigned to the specified SetID will be checked.
 
DeltaAttribute GetDeltaAtrributeByAttributeName (string attributeConditionalName)
 Attempts to get the detltaAttribute in the same class as the called DeltaMonitor, using the name defined in the attribute, and returns it.
 
void Init (object _objectToMonitor)
 Given the objectToMonitor, which will be stored internally(but not serialized), Init() generates a list of all CheckForChangeAttribute attributes in that object's class, which will allow us access the attributed variable's value. This function will initialize the non-serialized variables of this class, and update the OptionNames's fullList It will also read the serialized OptionNames's "selected" List and enable/disable each attribute appropriately by calling ApplySerializedDetectionEnabledList();
 
void RenameConditionalOptionName (string OriginalConidtionName, string newConditionName)
 This function is used to change the display names of a given DeltaAttribute. This can be useful if one wants to change the displayed option name of derived class versions of a variable's delta detector. Assumes the Delta monitor has been initialized. If the originaConditionName is not found, does nothing.
 
void ResetValues ()
 One of the primary functions for this class, it will reset the values of all stored attributes.
This is done by overwriting the internal DeltaAttribute cache with the current variable value. This new value will thereafter be used for comparison during change detection.
 
void ResetValuesInSet (int set)
 Will reset the values of all stored attributes that have the provided SetID. This is done by overwriting the internal DeltaAttribute cache with the current variable value. This new value will thereafter be used for comparison during change detection.
 
void SerializeDetectionEnabledList ()
 Reads from run-time attributes array, and writes the name of all enabled attributes into the serialized, selectedOptions string array.
 

Public Attributes

bool changeResult
 Publicly over-writable. If set to true, will remain so until DetectChanges or DetectChangesInSet is called.
 
int CurrentMaxSet
 If this variable is not negative; it will be used to limit the DeltaAttributes checked to include only items in a set lower than or equal to this number.
 
OptionNames detectionEnabledList
 This is one of the only serialized field; The fullList member of the OptionNames will be overwritten upon Init(), with the current CheckForChangeAttribute names in the objectToMonitor's class Note: OptionNames class has it's own property drawer in EyE.UnityEditor
 
DeltaAttribute[] fieldsToCheckForChange
 These members are passed to or initialized inside the constructor or Init() function.
 
bool initialized
 Set to false when instantiated. Set to true during initialization. This distinction is important when DeltaMonitor is loaded from disk; it is instantiated, but not initialized.
 

Protected Attributes

object objectToMonitor
 This is the object that contains variables with CheckForChangeAttributes, and is assigned during construction. These attributes will be extracted and recorded during initialization, and at runt-time is internally used to check for changes in each.
 
+ Inheritance diagram for DeltaMonitor:
+ Collaboration diagram for DeltaMonitor:
EyE.Sys.DeltaDetector.DeltaMonitor.DeltaMonitor
DeltaMonitor(object _objectToMonitor)
Performs the same functions as Init(), once the object is instantiated. But, also,...
Definition: DeltaMonitor.cs:97