48     typedef typename CC::ATOM_TYPE T;
 
   49     typedef typename CC::PARAM_CONFIG P;
 
   50     enum { R = P::EVENT_WINDOW_RADIUS };
 
   53     static u32 toSignMag(s32 value) {
 
   54       const u32 SIGN_BIT = 1<<(TVBITS-1);
 
   55       const u32 MAX = SIGN_BIT-1;
 
   63       u32 val = (u32) value;
 
   68     static u32 toMag(u32 value) {
 
   69       const u32 MAX = (1<<TVBITS)-1;
 
   71         FAIL(ILLEGAL_ARGUMENT);
 
   80     static s32 fromSignMag(
const u32 value) {
 
   81       const u32 SIGN_BIT = 1<<(TVBITS-1);
 
   82       const u32 MASK = SIGN_BIT-1;
 
   83       FXP16 val = value&MASK;
 
   90     static u32 fromMag(
const u32 value) {
 
   91       const u32 MASK = (1<<TVBITS)-1;
 
   97     static u32 toSTiny(
const SPoint & v) {
 
   98       u32 x = toSignMag<TVBITS>(v.
GetX());
 
   99       u32 y = toSignMag<TVBITS>(v.
GetY());
 
  100       return (x<<TVBITS)|y;
 
  104     template <u32 TVBITS>
 
  105     static u32 toUTiny(
const UPoint & v) {
 
  106       u32 x = toMag<TVBITS>(v.
GetX());
 
  107       u32 y = toMag<TVBITS>(v.
GetY());
 
  108       return (x<<TVBITS)|y;
 
  111     template <u32 TVBITS>
 
  112     static SPoint toSPoint(
const u32 bits) {
 
  113       const u32 MASK = (1<<TVBITS)-1;
 
  115       s32 x = fromSignMag<TVBITS>((bits>>TVBITS)&MASK);
 
  116       s32 y = fromSignMag<TVBITS>(bits&MASK);
 
  120     template <u32 TVBITS>
 
  121     static UPoint toUPoint(
const u32 bits) {
 
  122       const u32 MASK = (1<<TVBITS)-1;
 
  124       u32 x = fromMag<TVBITS>((bits>>TVBITS)&MASK);
 
  125       u32 y = fromMag<TVBITS>(bits&MASK);
 
  130     const char* GetName()
 const { 
return "Bar"; }
 
  133     static const u32 TYPE() {
 
  137     static const u32 TYPE_BITS = 8;
 
  138     static const u32 TYPE_MASK = (1<<TYPE_BITS)-1;
 
  139     static bool IsBarType(u32 type) {
 
  143     static const u32 BITS_PER_DIM = 8;
 
  145     static const u32 STATE_SIZE_IDX = 0;
 
  146     static const u32 STATE_SIZE_LEN = 2 * BITS_PER_DIM;
 
  147     static const u32 STATE_POS_IDX = STATE_SIZE_IDX + STATE_SIZE_LEN;
 
  148     static const u32 STATE_POS_LEN = 2 * BITS_PER_DIM;
 
  149     static const u32 STATE_BITS = STATE_POS_IDX + STATE_POS_LEN;
 
  153     SPoint GetMax(
const T &atom)
 const {
 
  154       if (!IsBarType(atom.GetType()))
 
  156       return MakeSigned(toUPoint<BITS_PER_DIM>(atom.GetStateField(STATE_SIZE_IDX,STATE_SIZE_LEN)));
 
  159     SPoint GetPos(
const T &atom)
 const {
 
  160       if (!IsBarType(atom.GetType()))
 
  162       return MakeSigned(toUPoint<BITS_PER_DIM>(atom.GetStateField(STATE_POS_IDX,STATE_POS_LEN)));
 
  165     bool FitsInRep(
const SPoint & v)
 const {
 
  169     void SetSize(T &atom, 
const SPoint & v)
 const {
 
  170       if (!IsBarType(atom.GetType()))
 
  173         FAIL(ILLEGAL_ARGUMENT);
 
  174       atom.SetStateField(STATE_SIZE_IDX,STATE_SIZE_LEN,toUTiny<BITS_PER_DIM>(MakeUnsigned(v)));
 
  177     void SetPos(T &atom, 
const SPoint v)
 const {
 
  178       if (!IsBarType(atom.GetType()))
 
  181         FAIL(ILLEGAL_ARGUMENT);
 
  182       atom.SetStateField(STATE_POS_IDX,STATE_POS_LEN,toUTiny<BITS_PER_DIM>(MakeUnsigned(v)));
 
  187       static T defaultAtom(TYPE,0,0,STATE_BITS);
 
  191     T GetAtom(
const SPoint & size, 
const SPoint & pos)
 const 
  214         SPoint barMax = GetMax(atom);
 
  215         SPoint myPos = GetPos(atom);
 
  216         return ColorMap_SEQ6_PuRd::THE_INSTANCE.
 
  231       const u32 selfType = 
self.GetType();
 
  233       if (!IsBarType(selfType))
 
  236       SPoint barMax = GetMax(
self);
 
  238       SPoint myPos = GetPos(
self);
 
  244       u32 inconsistentCount = 0;
 
  247       u32 consistentCount = 0;
 
  258         const SPoint sp = md.GetPoint(idx);
 
  261         bool onGrid = (sp.
GetX()&1)==0 && (sp.
GetY()&1)==0;
 
  266           const SPoint theirBarPos = sp+myPos;
 
  273             const u32 otherType = other.GetType();
 
  279               if (random.
OneIn(++makeCount)) {
 
  282                 SetPos(makeGuy,theirBarPos);  
 
  289               if (IsBarType(otherType)) {
 
  293                 SPoint otherBarMax = GetMax(other);
 
  294                 SPoint otherPos = GetPos(other);
 
  296                 SPoint otherPosMapped = otherPos-sp;
 
  297                 if (otherBarMax==barMax && otherPosMapped == myPos) {
 
  299                 } 
else if (random.
OneIn(++inconsistentCount)) {
 
  314             const u32 otherType = other.GetType();
 
  319               if (random.
OneIn(++eatCount)) {
 
  327               if (isEmpty) ++consistentCount;
 
  331                   if (random.
OneIn(++inconsistentCount)) {
 
  344       if (inconsistentCount > 0) {
 
  346         if (consistentCount > 3*inconsistentCount) {
 
  349         } 
else if (inconsistentCount > 3*consistentCount) {
 
  355         if (makeCount > 0 && eatCount > 0) {
 
  366   Element_Bar<CC> Element_Bar<CC>::THE_INSTANCE;
 
u32 GetFirstIndex(const u32 radius) const 
Definition: MDist.h:112
 
u32 GetType() const 
Definition: Element.h:290
 
Definition: Element_Empty.h:41
 
u32 GetLastIndex(const u32 radius) const 
Definition: MDist.h:129
 
virtual const T & GetDefaultAtom() const 
Definition: Element_Bar.h:185
 
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
 
bool BoundedBy(const Point< T > &lowerBound, const Point< T > &upperBound) const 
Definition: Point.tcc:223
 
virtual u32 DefaultPhysicsColor() const 
Definition: Element_Bar.h:200
 
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
 
const T & GetCenterAtom() const 
Definition: EventWindow.h:209
 
virtual const T & GetDefaultAtom() const 
Definition: Element.h:382
 
static MDist< R > & get()
Definition: MDist.tcc:193
 
Definition: Element_Res.h:48
 
Definition: Element_Bar.h:45
 
Definition: ElementTable.h:43
 
virtual u32 LocalPhysicsColor(const T &atom, u32 selector) const 
Definition: Element_Bar.h:210
 
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
 
virtual u32 DefaultLowlightColor() const 
Definition: Element_Bar.h:205
 
virtual void Behavior(EventWindow< CC > &window) const 
Definition: Element_Bar.h:226
 
T GetX() const 
Definition: Point.tcc:34