28 #ifndef ELEMENT_CONSUMER_H
29 #define ELEMENT_CONSUMER_H
48 typedef typename CC::ATOM_TYPE T;
49 typedef typename CC::PARAM_CONFIG P;
50 enum { R = P::EVENT_WINDOW_RADIUS };
51 enum { W = P::TILE_WIDTH };
57 TOTAL_BUCKET_ERROR_SLOT,
65 this->SetGap(defaultAtom,1);
76 u64 GetAndResetDatumsConsumed(Tile<CC> & t)
const
78 ElementTable<CC> & et = t.GetElementTable();
79 u64 * datap = et.GetDataIfRegistered(this->
GetType(), DATA_SLOT_COUNT);
83 u64 ret = datap[DATUMS_CONSUMED_SLOT];
84 datap[DATUMS_CONSUMED_SLOT] = 0;
88 u64 GetAndResetBucketError(Tile<CC> & t)
const
90 ElementTable<CC> & et = t.GetElementTable();
91 u64 * datap = et.GetDataIfRegistered(this->
GetType(), DATA_SLOT_COUNT);
95 u64 ret = datap[TOTAL_BUCKET_ERROR_SLOT];
96 datap[TOTAL_BUCKET_ERROR_SLOT] = 0;
101 const T& me,
const SPoint& offset)
const
118 return "This vertically-reproducing Element consumes DATA atoms and holds "
119 "information on its position and the DATA consumed.";
125 this->ReproduceVertically(window);
130 for (u32 i = 1; i < R; ++i)
141 u32 above = this->GetAbove(
self,0);
142 u32 below = this->GetBelow(
self,0);
143 u32 range = above + below + 1;
144 const u32 bucketSize = DATA_MAXVAL / range;
148 u32 minBucketVal = bucketSize * above;
149 u32 maxBucketVal = bucketSize * (above + 1);
150 u32 midpoint = (maxBucketVal+minBucketVal)/2;
153 if (val < midpoint) diff = midpoint - val;
154 else diff = val - midpoint;
156 u32 bucketsOff = diff / bucketSize;
161 u64 * datap = et.GetDataAndRegister(this->
GetType(), DATA_SLOT_COUNT);
162 ++datap[DATUMS_CONSUMED_SLOT];
163 datap[TOTAL_BUCKET_ERROR_SLOT] += bucketsOff;
186 Element_Consumer<CC> Element_Consumer<CC>::THE_INSTANCE;
u32 GetType() const
Definition: Element.h:290
Definition: Element_Empty.h:41
Definition: Element_Data.h:47
virtual u32 DefaultPhysicsColor() const
Definition: Element_Consumer.h:106
virtual u32 DefaultLowlightColor() const
Definition: Element_Consumer.h:111
Tile< CC > & GetTile()
Definition: EventWindow.h:132
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
const T & GetRelativeAtom(const SPoint &offset) const
Definition: EventWindow.tcc:26
Definition: Element_Consumer.h:45
const T & GetCenterAtom() const
Definition: EventWindow.h:209
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Consumer.h:122
virtual const T & GetDefaultAtom() const
Definition: Element.h:382
Definition: AbstractElement_Reprovert.h:42
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Consumer.h:100
virtual T BuildDefaultAtom() const
Definition: Element_Consumer.h:63
virtual const char * GetDescription() const
Definition: Element_Consumer.h:116
Definition: EventWindow.h:41
Definition: ElementTable.h:46
ElementTable< CC > & GetElementTable()
Definition: Tile.h:599
Definition: ElementTable.h:43
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15