]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/game.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Life! game logic
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
8 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "game.h"
19 // for compilers that support precompilation, includes "wx/wx.h"
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers
31 // --------------------------------------------------------------------------
33 // --------------------------------------------------------------------------
35 // A Cell is just a struct which contains a pair of (i, j) coords.
36 // These structs are not used internally anywhere; they are just
37 // used to pass cell coordinates around.
45 // --------------------------------------------------------------------------
47 // --------------------------------------------------------------------------
49 // A class which holds a pattern
53 LifeShape(wxString name
,
74 // --------------------------------------------------------------------------
76 // --------------------------------------------------------------------------
88 inline wxUint32
GetNumCells() const { return m_numcells
; };
89 bool IsAlive (wxInt32 x
, wxInt32 y
);
90 void SetCell (wxInt32 x
, wxInt32 y
, bool alive
= TRUE
);
91 void SetShape (const LifeShape
&shape
);
104 // The following functions find cells within a given viewport; either
105 // all alive cells, or only those cells which have changed since last
106 // generation. You first call BeginFind() to specify the viewport,
107 // then keep calling FindMore() until it returns TRUE.
110 // Specify the viewport and whether to look for alive cells or for
111 // cells which have changed since the last generation and thus need
112 // to be repainted. In this latter case, there is no distinction
113 // between newborn or just-dead cells.
116 // Fills an array with cells that match the specification given with
117 // BeginFind(). The array itself belongs to the Life object and must
118 // not be modified or freed by the caller. If this function returns
119 // FALSE, then the operation is not complete: just process all cells
120 // and call FillMore() again.
122 void BeginFind(wxInt32 i0
, wxInt32 j0
,
123 wxInt32 i1
, wxInt32 j1
,
125 bool FindMore(Cell
*cells
[], size_t *ncells
);
129 CellBox
*CreateBox(wxInt32 x
, wxInt32 y
, wxUint32 hv
);
130 CellBox
*LinkBox(wxInt32 x
, wxInt32 y
, bool create
= TRUE
);
131 void KillBox(CellBox
*c
);
133 // helper for BeginFind & FindMore
134 void DoLine(wxInt32 i
, wxInt32 j
, wxUint32 alive
, wxUint32 old
= 0);
137 CellBox
*m_head
; // list of alive boxes
138 CellBox
*m_available
; // list of reusable dead boxes
139 CellBox
**m_boxes
; // hash table of alive boxes
140 wxUint32 m_numcells
; // population (number of alive cells)
141 Cell
*m_cells
; // cell array for FindMore()
142 size_t m_ncells
; // number of valid cells in cell array
143 wxInt32 m_i
, m_j
, // state vars for FindMore()
150 #endif // _LIFE_GAME_H_