28 #ifndef ELEMENT_SORTER_H
29 #define ELEMENT_SORTER_H
44 #define SORTER_VERSION 1
50 typedef typename CC::ATOM_TYPE T;
51 typedef typename CC::PARAM_CONFIG P;
52 enum { R = P::EVENT_WINDOW_RADIUS };
56 static const u32 TYPE()
61 static const u32 STATE_THRESHOLD_IDX = 0;
62 static const u32 STATE_THRESHOLD_LEN = 32;
63 static const u32 STATE_BITS = STATE_THRESHOLD_LEN;
65 static const SPoint m_southeastSubWindow[4];
66 static const SPoint m_northeastSubWindow[4];
67 static const SPoint m_southwestSubWindow[4];
68 static const SPoint m_northwestSubWindow[4];
70 inline u32 GetDataType()
const
75 inline u32 GetEmptyType()
const
87 u32 GetThreshold(
const T &atom, u32 badType)
const
93 return atom.GetStateField(STATE_THRESHOLD_IDX,STATE_THRESHOLD_LEN);
96 bool SetThreshold(T &atom, u32 value)
const
102 atom.SetStateField(STATE_THRESHOLD_IDX,STATE_THRESHOLD_LEN,value);
108 static T defaultAtom(TYPE(),0,0,STATE_BITS);
113 const T& me,
const SPoint& offset)
const
130 return "A sorting \"demon\", which sorts DATA atoms based on their values and "
131 "a value held within this Sorter as well. See the \"Demon Hoard Sort\" "
132 "algorithm for details.";
137 u32 threshold = GetThreshold(*atom, 0);
141 desc.Printf(
"Threshold: %d", threshold);
145 desc.Printf(
"Threshold: INVALID");
154 return ColorMap_CubeHelixRev::THE_INSTANCE.
155 GetInterpolatedColor(GetThreshold(atom,0),DATA_MINVAL,DATA_MAXVAL,0xffff0000);
179 for(s32 i = 0; i < 2; i++)
184 if(scanner.FindRandomAtomsInSubWindows(2,
185 &src, GetDataType(), m_southeastSubWindow, 4,
186 &dst, GetEmptyType(), m_northwestSubWindow, 4))
193 if(scanner.FindRandomAtomsInSubWindows(2,
194 &src, GetDataType(), m_northeastSubWindow, 4,
195 &dst, GetEmptyType(), m_southwestSubWindow, 4))
205 bool cmp = (movingUp && (datum < threshold)) || (!movingUp && (datum > threshold));
209 SetThreshold(
self, datum);
216 movingUp = !movingUp;
224 Element_Sorter<CC> Element_Sorter<CC>::THE_INSTANCE;
227 const SPoint Element_Sorter<CC>::m_southeastSubWindow[4] =
229 SPoint(1,1),SPoint(1,2),SPoint(2,1),SPoint(2,2)
233 const SPoint Element_Sorter<CC>::m_northeastSubWindow[4] =
235 SPoint(1,-1),SPoint(1,-2),SPoint(2,-1),SPoint(2,-2)
239 const SPoint Element_Sorter<CC>::m_northwestSubWindow[4] =
241 SPoint(-1,-1),SPoint(-1,-2),SPoint(-2,-1),SPoint(-2,-2)
245 const SPoint Element_Sorter<CC>::m_southwestSubWindow[4] =
247 SPoint(-1,1),SPoint(-1,2),SPoint(-2,1),SPoint(-2,2)
void Diffuse(EventWindow< CC > &window) const
Definition: Element.tcc:73
u32 GetType() const
Definition: Element.h:290
Definition: Element_Empty.h:41
Definition: Element_Data.h:47
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Sorter.h:162
virtual u32 DefaultLowlightColor() const
Definition: Element_Sorter.h:123
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
virtual u32 LocalPhysicsColor(const T &atom, u32 selector) const
Definition: Element_Sorter.h:149
virtual const char * GetDescription() const
Definition: Element_Sorter.h:128
Random & GetRandom()
Definition: EventWindow.h:122
const T & GetRelativeAtom(const SPoint &offset) const
Definition: EventWindow.tcc:26
const T & GetCenterAtom() const
Definition: EventWindow.h:209
virtual const T & GetDefaultAtom() const
Definition: Element_Sorter.h:106
virtual u32 DefaultPhysicsColor() const
Definition: Element_Sorter.h:118
u32 FindRandomInVonNeumann(const u32 type, SPoint &outPoint) const
Definition: WindowScanner.tcc:294
Definition: Element_Sorter.h:47
Definition: Element_Res.h:48
Definition: ElementTable.h:43
virtual u32 PhysicsColor() const
Definition: Element.h:398
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Sorter.h:112
Definition: WindowScanner.h:40
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
virtual void AppendDescription(const T *atom, OString64 &desc) const
Definition: Element_Sorter.h:135
bool CreateBool()
Definition: Random.h:86
void SwapAtoms(const SPoint &locA, const SPoint &locB)
Definition: EventWindow.tcc:40