X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/764835a5d5b72c635527bfbb350d190c89381b44..c829d62b6945c74edaf25210720129b8b749639d:/demos/life/game.cpp diff --git a/demos/life/game.cpp b/demos/life/game.cpp index a356f550a1..5b7e6ce79a 100644 --- a/demos/life/game.cpp +++ b/demos/life/game.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __WIN16__ -#error "Sorry, Life! will not work in 16-bit Windows" -#endif - // ========================================================================== // headers, declarations, constants // ========================================================================== @@ -50,7 +46,7 @@ #define HASH(x, y) (((x >> 3) & 0x7f) << 7) + ((y >> 3) & 0x7f) -#define HASHSIZE 32768 // hash table size (do not change!) +#define HASHSIZE 16384 // hash table size (do not change!) #define CELLBOX 8 // cells in a cellbox (do not change!) @@ -79,9 +75,9 @@ public: bool LifeCellBox::IsAlive(int dx, int dy) const { if (dy > 3) - return (m_live2 & 1 << ((dy - 4) * 8 + dx)); + return (bool)(m_live2 & 1 << ((dy - 4) * 8 + dx)); else - return (m_live1 & 1 << ((dy) * 8 + dx)); + return (bool)(m_live1 & 1 << ((dy) * 8 + dx)); } // SetCell: @@ -879,12 +875,27 @@ bool Life::NextTic() c->m_live1 = t1; c->m_live2 = t2; - // count alive cells (TODO: find a better way to do this) + // count alive cells +#if 1 + wxUint32 t1_, t2_; + + t1_ = (t1 & 0x55555555) + (t1 >> 1 & 0x55555555); + t1_ = (t1_ & 0x33333333) + (t1_ >> 2 & 0x33333333); + + t2_ = (t2 & 0x55555555) + (t2 >> 1 & 0x55555555); + t2_ = (t2_ & 0x33333333) + (t2_ >> 2 & 0x33333333) + t1_; + t2_ = (t2_ & 0x0F0F0F0F) + (t2_ >> 4 & 0x0F0F0F0F); + t2_ = (t2_ & 0x00FF00FF) + (t2_ >> 8 & 0x00FF00FF); + + m_numcells += (t2_ & 0xFF) + (t2_ >> 16 & 0xFF); +#else + // Original, slower code for (int i = 0; i < 32; i++) { if (t1 & (1 << i)) m_numcells++; if (t2 & (1 << i)) m_numcells++; } +#endif changed |= ((t1 ^ c->m_old1) || (t2 ^ c->m_old2));