]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/game.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Life! game logic, version 2
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.
44 // --------------------------------------------------------------------------
46 // --------------------------------------------------------------------------
48 // A class which holds a pattern
52 LifeShape::LifeShape(wxString name
,
73 // --------------------------------------------------------------------------
75 // --------------------------------------------------------------------------
87 inline wxUint32
GetNumCells() const { return m_numcells
; };
88 bool IsAlive (wxInt32 x
, wxInt32 y
);
89 void SetCell (wxInt32 x
, wxInt32 y
, bool alive
= TRUE
);
90 void SetShape(const LifeShape
&shape
);
96 // The following functions find cells within a given viewport; either
97 // all alive cells, or only those cells which have changed since last
98 // generation. You first call BeginFind() to specify the viewport,
99 // then keep calling FindMore() until it returns TRUE.
102 // Specify the viewport and whether to look for alive cells or for
103 // cells which have changed since the last generation and thus need
104 // to be repainted. In this latter case, there is no distinction
105 // between newborn or just-dead cells.
108 // Fills an array with cells that match the specification given with
109 // BeginFind(). The array itself belongs to the Life object and must
110 // not be modified or freed by the caller. If this function returns
111 // FALSE, then the operation is not complete: just process all cells
112 // and call FillMore() again.
114 void BeginFind(wxInt32 i0
, wxInt32 j0
,
115 wxInt32 i1
, wxInt32 j1
,
117 bool FindMore(Cell
*cells
[], size_t *ncells
);
121 CellBox
*CreateBox(wxInt32 x
, wxInt32 y
, wxUint32 hv
);
122 CellBox
*LinkBox(wxInt32 x
, wxInt32 y
, bool create
= TRUE
);
123 void KillBox(CellBox
*c
);
125 // helpers for FindMore & co.
126 void DoLine(wxInt32 i
, wxInt32 j
, wxUint32 alive
, wxUint32 old
);
127 void DoLine(wxInt32 i
, wxInt32 j
, wxUint32 alive
);
130 CellBox
*m_head
; // list of alive boxes
131 CellBox
*m_available
; // list of reusable dead boxes
132 CellBox
**m_boxes
; // hash table of alive boxes
133 wxUint32 m_numcells
; // population (number of alive cells)
134 Cell
*m_cells
; // cell array for FindMore()
135 size_t m_ncells
; // number of valid cells in cell array
136 wxInt32 m_i
, m_j
, // state vars for FindMore()
143 #endif // _LIFE_GAME_H_