X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4efbec35878f21092bdca891cece12381073feff..d9307d006e88025e28457290c9997f7c0f7c4fdc:/demos/life/game.cpp diff --git a/demos/life/game.cpp b/demos/life/game.cpp index 681e12449e..eefae2c2de 100644 --- a/demos/life/game.cpp +++ b/demos/life/game.cpp @@ -9,18 +9,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __WIN16__ -#error "Sorry, Life! will not work in 16-bit Windows" -#endif - // ========================================================================== // headers, declarations, constants // ========================================================================== -#ifdef __GNUG__ - #pragma implementation "game.h" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -39,7 +31,7 @@ #include // for memset -#define ARRAYSIZE 1024 // static array for BeginFind & co. +#define CELLSARRAYSIZE 1024 // static array for BeginFind & co. #define ALLOCBOXES 16 // number of cellboxes to alloc at once #define MAXDEAD 8 // tics before removing cellbox from list @@ -79,14 +71,14 @@ public: bool LifeCellBox::IsAlive(int dx, int dy) const { if (dy > 3) - return (m_live2 & 1 << ((dy - 4) * 8 + dx)); + return (m_live2 & 1 << ((dy - 4) * 8 + dx)) ? true : false ; else - return (m_live1 & 1 << ((dy) * 8 + dx)); + return (m_live1 & 1 << ((dy) * 8 + dx)) ? true : false ; } // SetCell: -// Sets cell dx, dy in this box to 'alive', returns TRUE if -// the previous value was different, FALSE if it was the same. +// Sets cell dx, dy in this box to 'alive', returns true if +// the previous value was different, false if it was the same. // bool LifeCellBox::SetCell(int dx, int dy, bool alive) { @@ -100,10 +92,10 @@ bool LifeCellBox::SetCell(int dx, int dy, bool alive) // reset this here to avoid updating problems m_dead = 0; - return TRUE; + return true; } else - return FALSE; + return false; } @@ -118,9 +110,9 @@ bool LifeCellBox::SetCell(int dx, int dy, bool alive) Life::Life() { // pattern description - m_name = _(""); - m_rules = _(""); - m_description = _(""); + m_name = wxEmptyString; + m_rules = wxEmptyString; + m_description = wxEmptyString; // pattern data m_numcells = 0; @@ -131,10 +123,10 @@ Life::Life() m_boxes[i] = NULL; // state vars for BeginFind & FindMore - m_cells = new LifeCell[ARRAYSIZE]; + m_cells = new LifeCell[CELLSARRAYSIZE]; m_ncells = 0; - m_findmore = FALSE; - m_changed = FALSE; + m_findmore = false; + m_changed = false; } Life::~Life() @@ -177,9 +169,9 @@ void Life::Clear() m_available = NULL; // reset state - m_name = _(""); - m_rules = _(""); - m_description = _(""); + m_name = wxEmptyString; + m_rules = wxEmptyString; + m_description = wxEmptyString; m_numcells = 0; } @@ -192,7 +184,7 @@ void Life::Clear() // bool Life::IsAlive(wxInt32 x, wxInt32 y) { - LifeCellBox *c = LinkBox(x, y, FALSE); + LifeCellBox *c = LinkBox(x, y, false); return (c && c->IsAlive( x - c->m_x, y - c->m_y )); } @@ -324,7 +316,7 @@ LifeCellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create) for (c = m_boxes[hv]; c; c = c->m_hnext) if ((c->m_x == x) && (c->m_y == y)) return c; - // if not found, and (create == TRUE), create a new one + // if not found, and (create == true), create a new one return create? CreateBox(x, y, hv) : (LifeCellBox*) NULL; } @@ -397,7 +389,7 @@ LifeCell Life::FindCenter() LifeCell Life::FindNorth() { wxInt32 x = 0, y = 0; - bool first = TRUE; + bool first = true; LifeCellBox *c; for (c = m_head; c; c = c->m_next) @@ -405,9 +397,9 @@ LifeCell Life::FindNorth() { x = c->m_x; y = c->m_y; - first = FALSE; + first = false; } - + LifeCell cell; cell.i = first? 0 : x + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2; @@ -417,7 +409,7 @@ LifeCell Life::FindNorth() LifeCell Life::FindSouth() { wxInt32 x = 0, y = 0; - bool first = TRUE; + bool first = true; LifeCellBox *c; for (c = m_head; c; c = c->m_next) @@ -425,9 +417,9 @@ LifeCell Life::FindSouth() { x = c->m_x; y = c->m_y; - first = FALSE; + first = false; } - + LifeCell cell; cell.i = first? 0 : x + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2; @@ -437,7 +429,7 @@ LifeCell Life::FindSouth() LifeCell Life::FindWest() { wxInt32 x = 0, y = 0; - bool first = TRUE; + bool first = true; LifeCellBox *c; for (c = m_head; c; c = c->m_next) @@ -445,9 +437,9 @@ LifeCell Life::FindWest() { x = c->m_x; y = c->m_y; - first = FALSE; + first = false; } - + LifeCell cell; cell.i = first? 0 : x + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2; @@ -457,7 +449,7 @@ LifeCell Life::FindWest() LifeCell Life::FindEast() { wxInt32 x = 0, y = 0; - bool first = TRUE; + bool first = true; LifeCellBox *c; for (c = m_head; c; c = c->m_next) @@ -465,9 +457,9 @@ LifeCell Life::FindEast() { x = c->m_x; y = c->m_y; - first = FALSE; + first = false; } - + LifeCell cell; cell.i = first? 0 : x + CELLBOX / 2; cell.j = first? 0 : y + CELLBOX / 2; @@ -513,7 +505,7 @@ void Life::BeginFind(wxInt32 x0, wxInt32 y0, wxInt32 x1, wxInt32 y1, bool change m_x1 = (x1 + 7) & 0xfffffff8; m_y1 = (y1 + 7) & 0xfffffff8; - m_findmore = TRUE; + m_findmore = true; m_changed = changed; } @@ -528,14 +520,14 @@ bool Life::FindMore(LifeCell *cells[], size_t *ncells) for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0) for ( ; m_x <= m_x1; m_x += 8) { - if ((c = LinkBox(m_x, m_y, FALSE)) == NULL) + if ((c = LinkBox(m_x, m_y, false)) == NULL) continue; // check whether there is enough space left in the array - if (m_ncells > (ARRAYSIZE - 64)) + if (m_ncells > (CELLSARRAYSIZE - 64)) { *ncells = m_ncells; - return FALSE; + return false; } DoLine(m_x, m_y , c->m_live1, c->m_old1 ); @@ -553,14 +545,14 @@ bool Life::FindMore(LifeCell *cells[], size_t *ncells) for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0) for ( ; m_x <= m_x1; m_x += 8) { - if ((c = LinkBox(m_x, m_y, FALSE)) == NULL) + if ((c = LinkBox(m_x, m_y, false)) == NULL) continue; // check whether there is enough space left in the array - if (m_ncells > (ARRAYSIZE - 64)) + if (m_ncells > (CELLSARRAYSIZE - 64)) { *ncells = m_ncells; - return FALSE; + return false; } DoLine(m_x, m_y , c->m_live1 ); @@ -575,8 +567,8 @@ bool Life::FindMore(LifeCell *cells[], size_t *ncells) } *ncells = m_ncells; - m_findmore = FALSE; - return TRUE; + m_findmore = false; + return true; } // -------------------------------------------------------------------------- @@ -594,7 +586,7 @@ bool Life::NextTic() { LifeCellBox *c, *up, *dn, *lf, *rt; wxUint32 t1, t2, t3, t4; - bool changed = FALSE; + bool changed = false; m_numcells = 0; @@ -874,7 +866,7 @@ bool Life::NextTic() t2 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 24) & 0xf) ] << 24; t2 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 28) & 0xf) ] << 28; - c->m_on[0] = c->m_on[1] = c->m_on[2] = c->m_on[3] = + c->m_on[0] = c->m_on[1] = c->m_on[2] = c->m_on[3] = c->m_on[4] = c->m_on[5] = c->m_on[6] = c->m_on[7] = 0; c->m_live1 = t1; c->m_live2 = t2; @@ -946,7 +938,7 @@ bool LifeModule::OnInit() // see below g_tab = new unsigned char [0xfffff]; - if (!g_tab) return FALSE; + if (!g_tab) return false; for (wxUint32 i = 0; i < 0xfffff; i++) { @@ -968,7 +960,7 @@ bool LifeModule::OnInit() g_tab[i] = (unsigned char) live; } - return TRUE; + return true; } void LifeModule::OnExit() @@ -1140,7 +1132,7 @@ int g_tab1[]= 0x11112110, 0x11112121, 0x11112221, - 0x11112232, + 0x11112232, 0x11122100, 0x11122111, 0x11122211,