From 4efbec35878f21092bdca891cece12381073feff Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 11 Sep 2003 14:18:00 +0000 Subject: [PATCH] Applied patch [ 804322 ] Fixes for the "life" demo git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23510 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- demos/life/game.cpp | 19 +++++++++++++++++-- demos/life/life.cpp | 11 ++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/demos/life/game.cpp b/demos/life/game.cpp index a356f550a1..681e12449e 100644 --- a/demos/life/game.cpp +++ b/demos/life/game.cpp @@ -50,7 +50,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!) @@ -879,12 +879,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)); diff --git a/demos/life/life.cpp b/demos/life/life.cpp index b6d1a7ae58..eff085f3d4 100644 --- a/demos/life/life.cpp +++ b/demos/life/life.cpp @@ -355,16 +355,17 @@ void LifeFrame::UpdateUI() // start / stop GetToolBar()->EnableTool(ID_START, !m_running); GetToolBar()->EnableTool(ID_STOP, m_running); - GetMenuBar()->GetMenu(2)->Enable(ID_START, !m_running); - GetMenuBar()->GetMenu(2)->Enable(ID_STEP, !m_running); - GetMenuBar()->GetMenu(2)->Enable(ID_STOP, m_running); + GetMenuBar()->Enable(ID_START, !m_running); + GetMenuBar()->Enable(ID_STEP, !m_running); + GetMenuBar()->Enable(ID_STOP, m_running); + GetMenuBar()->Enable(ID_TOPSPEED, !m_topspeed); // zooming int cellsize = m_canvas->GetCellSize(); GetToolBar()->EnableTool(ID_ZOOMIN, cellsize < 32); GetToolBar()->EnableTool(ID_ZOOMOUT, cellsize > 1); - GetMenuBar()->GetMenu(1)->Enable(ID_ZOOMIN, cellsize < 32); - GetMenuBar()->GetMenu(1)->Enable(ID_ZOOMOUT, cellsize > 1); + GetMenuBar()->Enable(ID_ZOOMIN, cellsize < 32); + GetMenuBar()->Enable(ID_ZOOMOUT, cellsize > 1); } // Event handlers ----------------------------------------------------------- -- 2.47.2