X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..ab5c51e5b2e35bc3f0488996ee4b4665fdb68cf4:/demos/life/game.h diff --git a/demos/life/game.h b/demos/life/game.h index cca12fae4b..2b5b548f0e 100644 --- a/demos/life/game.h +++ b/demos/life/game.h @@ -12,22 +12,6 @@ #ifndef _LIFE_GAME_H_ #define _LIFE_GAME_H_ -#ifdef __GNUG__ - #pragma interface "game.h" -#endif - -// for compilers that support precompilation, includes "wx/wx.h" -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -// for all others, include the necessary headers -#ifndef WX_PRECOMP - #include "wx/wx.h" -#endif - // -------------------------------------------------------------------------- // LifePattern // -------------------------------------------------------------------------- @@ -47,8 +31,8 @@ public: m_rules = rules; m_shape = shape; }; - - // A more convenient ctor for the built-in samples + + // A more convenient ctor for the built-in samples LifePattern(wxString name, wxString description, int width, @@ -57,10 +41,24 @@ public: { m_name = name; m_description = description; - m_rules = _(""); - m_shape.Add( wxString::Format("%i %i", -width/2, -height/2) ); + m_rules = wxEmptyString; + // TODO: add the positions later, since the formatting command + // causes a crash due to conversion objects not being available + // during initialisation. +#ifndef __WXMAC__ + m_shape.Add( wxString::Format(_T("%i %i"), -width/2, -height/2) ); +#endif for(int j = 0; j < height; j++) - m_shape.Add( wxString(shape + (j * width), (size_t) width) ); + { + wxString tmp; + + for(int i = 0; i < width; i++) + { + tmp += wxChar(shape[j * width + i]); + } + + m_shape.Add( tmp ); + } }; wxString m_name; @@ -75,14 +73,14 @@ public: // -------------------------------------------------------------------------- // A struct used to pass cell coordinates around -struct Cell +struct LifeCell { wxInt32 i; wxInt32 j; -}; +}; // A private class that contains data about a block of cells -class CellBox; +class LifeCellBox; // A class that models a Life game instance class Life @@ -97,7 +95,7 @@ public: inline wxString GetRules() const { return m_rules; }; inline wxString GetDescription() const { return m_description; }; bool IsAlive(wxInt32 x, wxInt32 y); - void SetCell(wxInt32 x, wxInt32 y, bool alive = TRUE); + void SetCell(wxInt32 x, wxInt32 y, bool alive = true); void SetPattern(const LifePattern &pattern); // game control @@ -105,16 +103,16 @@ public: bool NextTic(); // navigation - Cell FindNorth(); - Cell FindSouth(); - Cell FindWest(); - Cell FindEast(); - Cell FindCenter(); + LifeCell FindNorth(); + LifeCell FindSouth(); + LifeCell FindWest(); + LifeCell FindEast(); + LifeCell FindCenter(); // The following functions find cells within a given viewport; either // all alive cells, or only those cells which have changed since last // generation. You first call BeginFind() to specify the viewport, - // then keep calling FindMore() until it returns TRUE. + // then keep calling FindMore() until it returns true. // // BeginFind: // Specify the viewport and whether to look for alive cells or for @@ -126,19 +124,19 @@ public: // Fills an array with cells that match the specification given with // BeginFind(). The array itself belongs to the Life object and must // not be modified or freed by the caller. If this function returns - // FALSE, then the operation is not complete: just process all cells + // false, then the operation is not complete: just process all cells // and call FillMore() again. // void BeginFind(wxInt32 x0, wxInt32 y0, wxInt32 x1, wxInt32 y1, bool changed); - bool FindMore(Cell *cells[], size_t *ncells); + bool FindMore(LifeCell *cells[], size_t *ncells); private: // cellbox-related - CellBox *CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv); - CellBox *LinkBox(wxInt32 x, wxInt32 y, bool create = TRUE); - void KillBox(CellBox *c); + LifeCellBox *CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv); + LifeCellBox *LinkBox(wxInt32 x, wxInt32 y, bool create = true); + void KillBox(LifeCellBox *c); // helper for BeginFind & FindMore void DoLine(wxInt32 x, wxInt32 y, wxUint32 alive, wxUint32 old = 0); @@ -150,13 +148,13 @@ private: wxString m_description; // description // pattern data - CellBox *m_head; // list of alive boxes - CellBox *m_available; // list of reusable dead boxes - CellBox **m_boxes; // hash table of alive boxes + LifeCellBox *m_head; // list of alive boxes + LifeCellBox *m_available; // list of reusable dead boxes + LifeCellBox **m_boxes; // hash table of alive boxes wxUint32 m_numcells; // population (number of alive cells) // state vars for BeginFind & FindMore - Cell *m_cells; // array of cells + LifeCell *m_cells; // array of cells size_t m_ncells; // number of valid entries in m_cells wxInt32 m_x, m_y, // counters and search mode m_x0, m_y0,