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
This commit is contained in:
Julian Smart
2003-09-11 14:18:00 +00:00
parent 256b8649ff
commit 4efbec3587
2 changed files with 23 additions and 7 deletions

View File

@@ -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));

View File

@@ -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 -----------------------------------------------------------