#include <zMonitor.h>
Public Member Functions | |
zMonitor (eGrid *_grid) | |
~zMonitor () | |
virtual void | RemoveFromGame () |
removes the object physically from the game | |
void | setName (string name) |
void | addRule (zMonitorRulePtr aRule) |
void | setInit (tPolynomial< nMessage > v) |
void | setDrift (tPolynomial< nMessage > d) |
void | setClampLow (REAL l) |
void | setClampHigh (REAL h) |
void | affectSlide (gCycle *user, tPolynomial< nMessage > triggererInfluenceSlide, Triad marked) |
Protected Member Functions | |
virtual bool | Timestep (REAL currentTime) |
simulates behaviour up to currentTime | |
Protected Attributes | |
tPolynomial< nMessage > | totalInfluence |
The sum of all the individual contributions in one, to be scaled in time. | |
triggerers | contributors |
All the players that contributed to the sliding (ie proportional to time). | |
zMonitorRulePtrs | rules |
tPolynomial< nMessage > | valueEq |
tPolynomial< nMessage > | drift |
REAL | minValue |
Low bound that value can take. | |
REAL | maxValue |
High bound that value can take. | |
string | name |
tPolynomial< nMessage > | previousValue |
tPolynomial< nMessage > | previousTotalInfluenceSlide |
Definition at line 27 of file zMonitor.h.
zMonitor::zMonitor | ( | eGrid * | _grid | ) | [inline] |
Definition at line 29 of file zMonitor.h.
References eGameObject::AddToList().
00029 : 00030 eReferencableGameObject( _grid, eCoord( 1,1 ), eCoord( 0,0 ), NULL, true ), 00031 totalInfluence(0), 00032 contributors(), 00033 rules(), 00034 valueEq(), 00035 drift(0), 00036 minValue(0.0), 00037 maxValue(1.0), 00038 previousTotalInfluenceSlide(0) 00039 { 00040 // add to game grid 00041 this->AddToList(); 00042 };
zMonitor::~zMonitor | ( | ) | [inline] |
virtual void zMonitor::RemoveFromGame | ( | void | ) | [inline, virtual] |
removes the object physically from the game
Reimplemented from eGameObject.
Definition at line 49 of file zMonitor.h.
References eGameObject::RemoveFromListsAll().
00049 { 00050 RemoveFromListsAll(); 00051 };
void zMonitor::setName | ( | string | name | ) | [inline] |
void zMonitor::addRule | ( | zMonitorRulePtr | aRule | ) |
Definition at line 90 of file zMonitor.cpp.
References rules.
00090 { 00091 /* 00092 * HACK 00093 * This only works for a single rule! fix this 00094 */ 00095 rules.push_back(aRule); 00096 }
void zMonitor::setInit | ( | tPolynomial< nMessage > | v | ) | [inline] |
void zMonitor::setDrift | ( | tPolynomial< nMessage > | d | ) | [inline] |
void zMonitor::setClampLow | ( | REAL | l | ) | [inline] |
void zMonitor::setClampHigh | ( | REAL | h | ) | [inline] |
void zMonitor::affectSlide | ( | gCycle * | user, | |
tPolynomial< nMessage > | triggererInfluenceSlide, | |||
Triad | marked | |||
) |
Definition at line 13 of file zMonitor.cpp.
References contributors, Triggerer::marked, totalInfluence, and Triggerer::who.
00013 { 00014 Triggerer triggerer; 00015 triggerer.who = user; 00016 // TODO: 00017 //triggerer.positive = triggererInfluence > 0.0 ? _true : _false; 00018 triggerer.marked = marked; 00019 00020 contributors.push_back(triggerer); 00021 totalInfluence += triggererInfluence; 00022 00023 }
bool zMonitor::Timestep | ( | REAL | time | ) | [protected, virtual] |
simulates behaviour up to currentTime
time | the current time |
Reimplemented from eGameObject.
Definition at line 36 of file zMonitor.cpp.
References tPolynomial< T >::changeRate(), tPolynomial< T >::clamp(), contributors, drift, tPolynomial< T >::evaluate(), eGameObject::lastTime, tPolynomial< T >::Len(), maxValue, minValue, previousTotalInfluenceSlide, rules, totalInfluence, and valueEq.
00037 { 00038 tPolynomial<nMessage> prevValueEq = valueEq; 00039 00040 if ( totalInfluence != previousTotalInfluenceSlide ) { 00041 00042 for (int i=1; i<totalInfluence.Len(); i++) { 00043 valueEq.changeRate(totalInfluence[i], i, time); 00044 } 00045 // Set to null any remainding elements not reassigned in the previous loop 00046 for (int i=totalInfluence.Len(); i<valueEq.Len(); i++) { 00047 valueEq.changeRate(0.0, i, time); 00048 } 00049 00050 previousTotalInfluenceSlide = totalInfluence; 00051 } 00052 00053 valueEq = valueEq.clamp(minValue, maxValue, time); 00054 00055 // Assemble all the contributors in a single list 00056 // Nota: this also protect the list for further modification 00057 // by recursives rules. Should all list be merged in a later version 00058 // still do make a copy at this step 00059 00060 00061 totalInfluence = drift; 00062 00063 // Only update if value has changed enough 00064 // TODO: 00065 // if( value < previousValue - EPS || previousValue + EPS < value) { 00066 // go through all the rules and find the ones to apply 00067 zMonitorRulePtrs::const_iterator iter; 00068 for (iter = rules.begin(); 00069 iter != rules.end(); 00070 ++iter) 00071 { 00072 // Go through all the rules of the monitor and see wich need to be activated 00073 if ((*iter)->isValid(valueEq.evaluate(time))) { 00074 (*iter)->applyRule(contributors, time, valueEq); 00075 } 00076 } 00077 // } 00078 00079 // Remove the information about who contributed in the last tic 00080 contributors.erase(contributors.begin(), contributors.end()); 00081 00082 // update time 00083 lastTime = time; 00084 00085 return false; 00086 }
tPolynomial<nMessage> zMonitor::totalInfluence [protected] |
The sum of all the individual contributions in one, to be scaled in time.
Definition at line 74 of file zMonitor.h.
Referenced by affectSlide(), and Timestep().
triggerers zMonitor::contributors [protected] |
All the players that contributed to the sliding (ie proportional to time).
Definition at line 78 of file zMonitor.h.
Referenced by affectSlide(), and Timestep().
zMonitorRulePtrs zMonitor::rules [protected] |
tPolynomial<nMessage> zMonitor::valueEq [protected] |
tPolynomial<nMessage> zMonitor::drift [protected] |
REAL zMonitor::minValue [protected] |
Low bound that value can take.
Definition at line 85 of file zMonitor.h.
Referenced by setClampLow(), and Timestep().
REAL zMonitor::maxValue [protected] |
High bound that value can take.
Definition at line 86 of file zMonitor.h.
Referenced by setClampHigh(), and Timestep().
string zMonitor::name [protected] |
Definition at line 88 of file zMonitor.h.
tPolynomial<nMessage> zMonitor::previousValue [protected] |
Definition at line 91 of file zMonitor.h.
tPolynomial<nMessage> zMonitor::previousTotalInfluenceSlide [protected] |