17 #define DBAR_VERSION 1
62 typedef typename CC::ATOM_TYPE T;
63 typedef typename CC::PARAM_CONFIG P;
64 enum { R = P::EVENT_WINDOW_RADIUS };
67 static u32 toSignMag(s32 value) {
68 const u32 SIGN_BIT = 1<<(TVBITS-1);
69 const u32 MAX = SIGN_BIT-1;
77 u32 val = (u32) value;
82 static u32 toMag(u32 value) {
83 const u32 MAX = (1<<TVBITS)-1;
85 FAIL(ILLEGAL_ARGUMENT);
94 static s32 fromSignMag(
const u32 value) {
95 const u32 SIGN_BIT = 1<<(TVBITS-1);
96 const u32 MASK = SIGN_BIT-1;
97 FXP16 val = value&MASK;
103 template <u32 TVBITS>
104 static u32 fromMag(
const u32 value) {
105 const u32 MASK = (1<<TVBITS)-1;
106 u32 val = value&MASK;
110 template <u32 TXBITS, u32 TYBITS>
111 static u32 toUTiny(
const UPoint & v) {
112 u32 x = toMag<TXBITS>(v.
GetX());
113 u32 y = toMag<TYBITS>(v.
GetY());
114 return (x<<TYBITS)|y;
117 template <u32 TXBITS, u32 TYBITS>
118 static UPoint toUPoint(
const u32 bits) {
120 u32 x = fromMag<TXBITS>(bits>>TYBITS);
121 u32 y = fromMag<TYBITS>(bits);
128 static const u32 TYPE() {
132 static const u32 TYPE_BITS = 15;
134 static bool IsOurType(u32 type) {
138 static const u32 BITS_WIDE = 5;
139 static const u32 BITS_HIGH = 7;
140 static const u32 BITS_SYMI = 3;
142 static const u32 BITS_BAR_COORD_LEN = BITS_WIDE + BITS_HIGH;
144 static const u32 STATE_SIZE_IDX = 0;
145 static const u32 STATE_SIZE_LEN = BITS_BAR_COORD_LEN;
146 static const u32 STATE_POS_IDX = STATE_SIZE_IDX + STATE_SIZE_LEN;
147 static const u32 STATE_POS_LEN = BITS_BAR_COORD_LEN;
148 static const u32 STATE_SYMI_IDX = STATE_POS_IDX + STATE_POS_LEN;
149 static const u32 STATE_SYMI_LEN = BITS_SYMI;
150 static const u32 STATE_BITS = STATE_SYMI_IDX + STATE_SYMI_LEN;
154 u32 GetSymI(
const T &atom)
const {
155 if (!IsOurType(atom.GetType()))
157 return atom.GetStateField(STATE_SYMI_IDX,STATE_SYMI_LEN);
160 SPoint GetMax(
const T &atom)
const {
161 if (!IsOurType(atom.GetType()))
163 return MakeSigned(toUPoint<BITS_WIDE,BITS_HIGH>(atom.GetStateField(STATE_SIZE_IDX,STATE_SIZE_LEN)));
166 SPoint GetPos(
const T &atom)
const {
167 if (!IsOurType(atom.GetType()))
169 return MakeSigned(toUPoint<BITS_WIDE,BITS_HIGH>(atom.GetStateField(STATE_POS_IDX,STATE_POS_LEN)));
172 bool FitsInRep(
const SPoint & v)
const {
176 void SetSize(T &atom,
const SPoint & v)
const {
177 if (!IsOurType(atom.GetType()))
180 FAIL(ILLEGAL_ARGUMENT);
181 atom.SetStateField(STATE_SIZE_IDX,STATE_SIZE_LEN,toUTiny<BITS_WIDE,BITS_HIGH>(MakeUnsigned(v)));
184 void SetPos(T &atom,
const SPoint v)
const {
185 if (!IsOurType(atom.GetType()))
188 FAIL(ILLEGAL_ARGUMENT);
189 atom.SetStateField(STATE_POS_IDX,STATE_POS_LEN,toUTiny<BITS_WIDE,BITS_HIGH>(MakeUnsigned(v)));
192 void SetSymI(T &atom,
const u32 sym)
const {
193 if (!IsOurType(atom.GetType()))
195 if (sym >= PSYM_SYMMETRY_COUNT)
196 FAIL(ILLEGAL_ARGUMENT);
197 atom.SetStateField(STATE_SYMI_IDX,STATE_SYMI_LEN, sym);
202 static T defaultAtom(TYPE(),0,0,STATE_BITS);
206 T GetAtom(
const SPoint & size,
const SPoint & pos)
const
234 SPoint barMax = GetMax(atom);
235 SPoint myPos = GetPos(atom);
236 return ColorMap_SEQ6_PuRd::THE_INSTANCE.
257 const u32 selfType =
self.GetType();
258 if (!IsOurType(selfType)) FAIL(ILLEGAL_STATE);
261 u32 symi = GetSymI(
self);
266 SPoint barMax = GetMax(
self);
267 SPoint myPos = GetPos(
self);
273 u32 inconsistentCount = 0;
276 u32 consistentCount = 0;
287 const SPoint sp = md.GetPoint(idx);
291 bool onGrid = (sp.
GetX()&1)==0 && (sp.
GetY()&1)==0;
296 const SPoint theirBarPos = sp+shearX+myPos;
303 const u32 otherType = other.GetType();
309 if (random.
OneIn(++makeCount)) {
312 SetPos(makeGuy,theirBarPos);
319 if (IsOurType(otherType)) {
323 SPoint otherBarMax = GetMax(other);
324 SPoint otherPos = GetPos(other);
326 SPoint otherPosMapped = otherPos-sp-shearX;
327 if (otherBarMax==barMax && otherPosMapped == myPos) {
329 }
else if (random.
OneIn(++inconsistentCount)) {
344 const u32 otherType = other.GetType();
349 if (random.
OneIn(++eatCount)) {
357 if (isEmpty) ++consistentCount;
359 bool iDBar = IsOurType(otherType);
361 if (random.
OneIn(++inconsistentCount)) {
374 if (inconsistentCount > 0) {
376 if (consistentCount > 3*inconsistentCount) {
379 }
else if (inconsistentCount > 3*consistentCount) {
385 if (makeCount > 0 && eatCount > 0) {
391 if (myPos == barMax-
SPoint(1,1)) {
395 const u32 offType = offEnd.GetType();
399 u32 symi = GetSymI(
self);
400 symi = (symi+6)%PSYM_SYMMETRY_COUNT;
417 Element_DBar<CC> Element_DBar<CC>::THE_INSTANCE;
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_DBar.h:253
u32 GetFirstIndex(const u32 radius) const
Definition: MDist.h:112
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_DBar.h:225
u32 GetType() const
Definition: Element.h:290
Definition: Element_DBar.h:20
Definition: Element_Empty.h:41
u32 GetLastIndex(const u32 radius) const
Definition: MDist.h:129
void SetSymmetry(const PointSymmetry psym)
Definition: EventWindow.h:110
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
u32 NoDiffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element.h:508
bool BoundedBy(const Point< T > &lowerBound, const Point< T > &upperBound) const
Definition: Point.tcc:223
virtual u32 DefaultLowlightColor() const
Definition: Element_DBar.h:220
Definition: Element_DBar.h:59
bool OneIn(u32 odds)
Definition: Random.h:96
T GetY() const
Definition: Point.tcc:40
Random & GetRandom()
Definition: EventWindow.h:122
const T & GetRelativeAtom(const SPoint &offset) const
Definition: EventWindow.tcc:26
virtual u32 Diffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element_DBar.h:249
const T & GetCenterAtom() const
Definition: EventWindow.h:209
virtual const T & GetDefaultAtom() const
Definition: Element.h:382
virtual const T & GetDefaultAtom() const
Definition: Element_DBar.h:200
virtual u32 LocalPhysicsColor(const T &atom, u32 selector) const
Definition: Element_DBar.h:230
virtual u32 DefaultPhysicsColor() const
Definition: Element_DBar.h:215
bool IsType(u32 type) const
Definition: Element.h:345
static MDist< R > & get()
Definition: MDist.tcc:193
Definition: Element_Res.h:48
Definition: ElementTable.h:43
virtual u32 PhysicsColor() const
Definition: Element.h:398
double GetEuclideanLength() const
Definition: Point.tcc:58
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
T GetX() const
Definition: Point.tcc:34