This commit was manufactured by cvs2svn to create tag 'WX_2_2_9'.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/WX_2_2_9@13364 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2002-01-04 16:15:08 +00:00
parent dc3d889d0b
commit f7f6abe24d
2324 changed files with 375095 additions and 121526 deletions

235
demos/life/LifeVC.dsp Normal file
View File

@@ -0,0 +1,235 @@
# Microsoft Developer Studio Project File - Name="LifeVC" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=LifeVC - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "LifeVC.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "LifeVC.mak" CFG="LifeVC - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "LifeVC - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "LifeVC - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE "LifeVC - Win32 Debug DLL" (based on "Win32 (x86) Application")
!MESSAGE "LifeVC - Win32 Release DLL" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "LifeVC - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O1 /Ob2 /I "../../include" /I "../../contrib/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib wx.lib xpm.lib png.lib zlib.lib jpeg.lib tiff.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libci.lib" /nodefaultlib:"msvcrtd.lib" /out:"Release/life.exe" /libpath:"../../lib" /libpath:"../../contrib/lib"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /I "../../contrib/include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D DEBUG=1 /D "__WXDEBUG__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /Yu"wx/wxprec.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib wxd.lib xpmd.lib pngd.lib zlibd.lib jpegd.lib tiffd.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrt.lib" /out:"Debug/life.exe" /pdbtype:sept /libpath:"../../lib" /libpath:"../../contrib/lib"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "DebugDLL"
# PROP BASE Intermediate_Dir "DebugDLL"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "DebugDLL"
# PROP Intermediate_Dir "DebugDLL"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /I "../../contrib/include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D DEBUG=1 /D "__WXDEBUG__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D WXUSINGDLL=1 /Yu"wx/wxprec.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib wx22_9d.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /out:"DebugDLL/life.exe" /pdbtype:sept /libpath:"../../lib" /libpath:"../../contrib/lib"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Release DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "ReleaseDLL"
# PROP BASE Intermediate_Dir "ReleaseDLL"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "ReleaseDLL"
# PROP Intermediate_Dir "ReleaseDLL"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O1 /Ob2 /I "../../include" /I "../../contrib/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D WXUSINGDLL=1 /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib wx22_9.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libci.lib" /out:"ReleaseDLL/life.exe" /libpath:"../../lib" /libpath:"../../contrib/lib"
!ENDIF
# Begin Target
# Name "LifeVC - Win32 Release"
# Name "LifeVC - Win32 Debug"
# Name "LifeVC - Win32 Debug DLL"
# Name "LifeVC - Win32 Release DLL"
# Begin Source File
SOURCE=.\dialogs.cpp
!IF "$(CFG)" == "LifeVC - Win32 Release"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug"
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug DLL"
# SUBTRACT BASE CPP /YX /Yc /Yu
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Release DLL"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\dialogs.h
# End Source File
# Begin Source File
SOURCE=.\game.cpp
!IF "$(CFG)" == "LifeVC - Win32 Release"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug"
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug DLL"
# SUBTRACT BASE CPP /YX /Yc /Yu
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Release DLL"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\game.h
# End Source File
# Begin Source File
SOURCE=.\life.cpp
!IF "$(CFG)" == "LifeVC - Win32 Release"
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug"
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Debug DLL"
# SUBTRACT BASE CPP /YX /Yc /Yu
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "LifeVC - Win32 Release DLL"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\life.h
# End Source File
# Begin Source File
SOURCE=.\life.rc
# ADD BASE RSC /l 0x809
# ADD RSC /l 0x809 /i "../../include" /i "../../contrib/include"
# End Source File
# Begin Source File
SOURCE=.\reader.cpp
# End Source File
# Begin Source File
SOURCE=.\reader.h
# End Source File
# End Target
# End Project

29
demos/life/LifeVC.dsw Normal file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "LifeVC"=.\LifeVC.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -13,11 +13,11 @@ top_srcdir = @top_srcdir@/..
top_builddir = ../..
program_dir = demos/life
DATAFILES = samples.inc
DATAFILES = samples.inc breeder.lif
PROGRAM=life
OBJECTS=$(PROGRAM).o dialogs.o game.o
OBJECTS=$(PROGRAM).o dialogs.o game.o reader.o
include ../../src/makeprog.env

BIN
demos/life/bitmaps/info.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

View File

@@ -0,0 +1,24 @@
/* XPM */
static char *info_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
" c None",
". c Blue",
/* pixels */
" ",
" .... ",
" ...... ",
" ...... ",
" .... ",
" ",
" ",
" ....... ",
" ..... ",
" ..... ",
" ..... ",
" ..... ",
" ..... ",
" ..... ",
" ..... ",
" ......... "
};

BIN
demos/life/bitmaps/open.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

View File

@@ -0,0 +1,26 @@
/* XPM */
static char *open_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 15 5 1",
" c None",
". c Black",
"X c Yellow",
"o c Gray100",
"O c #bfbf00",
/* pixels */
" ",
" ... ",
" . . .",
" ..",
" ... ...",
" .XoX....... ",
" .oXoXoXoXo. ",
" .XoXoXoXoX. ",
" .oXoX..........",
" .XoX.OOOOOOOOO.",
" .oo.OOOOOOOOO. ",
" .X.OOOOOOOOO. ",
" ..OOOOOOOOO. ",
" ........... ",
" "
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

After

Width:  |  Height:  |  Size: 238 B

View File

@@ -1,24 +1,24 @@
/* XPM */
static char *reset_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
"16 15 3 1",
" c None",
". c Black",
"X c Gray100",
/* pixels */
" ",
" ",
" ",
" .. .. ",
" ... ... ",
" ... ... ",
" ...... ",
" .... ",
" .... ",
" ...... ",
" ... ... ",
" ... ... ",
" .. .. ",
" ",
" ",
" ........ ",
" .XXXXXX.. ",
" .XXXXXX.X. ",
" .XXXXXX.... ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" .XXXXXXXXX. ",
" ........... ",
" "
};

2523
demos/life/breeder.lif Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -93,16 +93,16 @@ LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
0, NULL,
wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
for (unsigned i = 0; i < (sizeof(g_shapes) / sizeof(LifeShape)); i++)
m_list->Append(g_shapes[i].m_name);
for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
m_list->Append(g_patterns[i].m_name);
// descriptions
wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description"));
m_life = new Life();
m_life->SetShape(g_shapes[0]);
m_life->SetPattern(g_patterns[0]);
m_canvas = new LifeCanvas( this, m_life, FALSE );
m_text = new wxTextCtrl( this, -1,
g_shapes[0].m_desc,
g_patterns[0].m_description,
wxDefaultPosition,
wxSize(300, 60),
wxTE_MULTILINE | wxTE_READONLY);
@@ -136,9 +136,9 @@ LifeSamplesDialog::~LifeSamplesDialog()
m_canvas->Destroy();
}
const LifeShape& LifeSamplesDialog::GetShape()
const LifePattern& LifeSamplesDialog::GetPattern()
{
return g_shapes[m_value];
return g_patterns[m_value];
}
void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
@@ -148,15 +148,14 @@ void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
if (sel != -1)
{
m_value = m_list->GetSelection();
m_text->SetValue(g_shapes[ sel ].m_desc);
m_life->SetShape(g_shapes[ sel ]);
m_text->SetValue(g_patterns[ sel ].m_description);
m_life->SetPattern(g_patterns[ sel ]);
// quick and dirty :-)
if ((g_shapes[ sel ].m_width > 36) ||
(g_shapes[ sel ].m_height > 22))
m_canvas->SetCellSize(2);
else
// these values shouldn't be hardcoded...
if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
m_canvas->SetCellSize(8);
else
m_canvas->SetCellSize(2);
}
}
@@ -182,7 +181,7 @@ LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
sizer->Add( CreateTextSizer(_("Life! version 2.1 for wxWindows\n\n"
sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWindows\n\n"
"(c) 2000 Guillermo Rodriguez Garcia\n\n"
"<guille@iies.es>\n\n"
"Portions of the code are based in XLife;\n"

View File

@@ -44,7 +44,7 @@ public:
~LifeSamplesDialog();
// members
const LifeShape& GetShape();
const LifePattern& GetPattern();
// event handlers
void OnListBox(wxCommandEvent &event);

View File

@@ -117,17 +117,24 @@ bool CellBox::SetCell(int dx, int dy, bool alive)
Life::Life()
{
m_numcells = 0;
m_boxes = new CellBox *[HASHSIZE];
m_head = NULL;
m_available = NULL;
// pattern description
m_name = _("");
m_rules = _("");
m_description = _("");
// pattern data
m_numcells = 0;
m_boxes = new CellBox *[HASHSIZE];
m_head = NULL;
m_available = NULL;
for (int i = 0; i < HASHSIZE; i++)
m_boxes[i] = NULL;
m_cells = new Cell[ARRAYSIZE];
m_ncells = 0;
m_findmore = FALSE;
m_changed = FALSE;
// state vars for BeginFind & FindMore
m_cells = new Cell[ARRAYSIZE];
m_ncells = 0;
m_findmore = FALSE;
m_changed = FALSE;
}
Life::~Life()
@@ -145,8 +152,6 @@ void Life::Clear()
{
CellBox *c, *nc;
m_numcells = 0;
// clear the hash table pointers
for (int i = 0; i < HASHSIZE; i++)
m_boxes[i] = NULL;
@@ -170,6 +175,12 @@ void Life::Clear()
c = nc;
}
m_available = NULL;
// reset state
m_name = _("");
m_rules = _("");
m_description = _("");
m_numcells = 0;
}
// --------------------------------------------------------------------------
@@ -204,19 +215,38 @@ void Life::SetCell(wxInt32 x, wxInt32 y, bool alive)
}
}
void Life::SetShape(const LifeShape& shape)
void Life::SetPattern(const LifePattern& pattern)
{
char *p = shape.m_data;
int i0 = -(shape.m_width / 2);
int j0 = -(shape.m_height / 2);
int i1 = i0 + shape.m_width - 1;
int j1 = j0 + shape.m_height - 1;
wxArrayString data = pattern.m_shape;
wxString line;
long x = 0,
y = 0;
Clear();
for (int j = j0; j <= j1; j++)
for (int i = i0; i <= i1; i++)
SetCell(i, j, *(p++) == '*');
for (size_t n = 0; n < data.GetCount(); n++)
{
line = data[n];
if ( (line.GetChar(0) != wxT('*')) &&
(line.GetChar(0) != wxT('.')) )
{
// assume that it is a digit or a minus sign
line.BeforeFirst(wxT(' ')).ToLong(&x);
line.AfterFirst(wxT(' ')).ToLong(&y);
}
else
{
// pattern data
for (size_t k = 0; k < line.Len(); k++)
SetCell(x + k, y, line.GetChar(k) == wxT('*'));
y++;
}
}
m_name = pattern.m_name;
m_rules = pattern.m_rules;
m_description = pattern.m_description;
}
// --------------------------------------------------------------------------
@@ -337,110 +367,110 @@ void Life::KillBox(CellBox *c)
Cell Life::FindCenter()
{
double i, j;
double sx, sy;
int n;
i = 0.0;
j = 0.0;
sx = 0.0;
sy = 0.0;
n = 0;
CellBox *c;
for (c = m_head; c; c = c->m_next)
if (!c->m_dead)
{
i += c->m_x;
j += c->m_y;
sx += c->m_x;
sy += c->m_y;
n++;
}
if (n > 0)
{
i = (i / n) + CELLBOX / 2;
j = (j / n) + CELLBOX / 2;
sx = (sx / n) + CELLBOX / 2;
sy = (sy / n) + CELLBOX / 2;
}
Cell cell;
cell.i = (wxInt32) i;
cell.j = (wxInt32) j;
cell.i = (wxInt32) sx;
cell.j = (wxInt32) sy;
return cell;
}
Cell Life::FindNorth()
{
wxInt32 i = 0, j = 0;
wxInt32 x = 0, y = 0;
bool first = TRUE;
CellBox *c;
for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_y < j)))
if (!c->m_dead && ((first) || (c->m_y < y)))
{
i = c->m_x;
j = c->m_y;
x = c->m_x;
y = c->m_y;
first = FALSE;
}
Cell cell;
cell.i = first? 0 : i + CELLBOX / 2;
cell.j = first? 0 : j + CELLBOX / 2;
cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2;
return cell;
}
Cell Life::FindSouth()
{
wxInt32 i = 0, j = 0;
wxInt32 x = 0, y = 0;
bool first = TRUE;
CellBox *c;
for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_y > j)))
if (!c->m_dead && ((first) || (c->m_y > y)))
{
i = c->m_x;
j = c->m_y;
x = c->m_x;
y = c->m_y;
first = FALSE;
}
Cell cell;
cell.i = first? 0 : i + CELLBOX / 2;
cell.j = first? 0 : j + CELLBOX / 2;
cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2;
return cell;
}
Cell Life::FindWest()
{
wxInt32 i = 0, j = 0;
wxInt32 x = 0, y = 0;
bool first = TRUE;
CellBox *c;
for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_x < i)))
if (!c->m_dead && ((first) || (c->m_x < x)))
{
i = c->m_x;
j = c->m_y;
x = c->m_x;
y = c->m_y;
first = FALSE;
}
Cell cell;
cell.i = first? 0 : i + CELLBOX / 2;
cell.j = first? 0 : j + CELLBOX / 2;
cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2;
return cell;
}
Cell Life::FindEast()
{
wxInt32 i = 0, j = 0;
wxInt32 x = 0, y = 0;
bool first = TRUE;
CellBox *c;
for (c = m_head; c; c = c->m_next)
if (!c->m_dead && ((first) || (c->m_x > i)))
if (!c->m_dead && ((first) || (c->m_x > x)))
{
i = c->m_x;
j = c->m_y;
x = c->m_x;
y = c->m_y;
first = FALSE;
}
Cell cell;
cell.i = first? 0 : i + CELLBOX / 2;
cell.j = first? 0 : j + CELLBOX / 2;
cell.i = first? 0 : x + CELLBOX / 2;
cell.j = first? 0 : y + CELLBOX / 2;
return cell;
}
@@ -453,35 +483,35 @@ Cell Life::FindEast()
// argument (or pass 0, the default value) to post alive cells
// only, else it will post cells which have changed.
//
void Life::DoLine(wxInt32 i, wxInt32 j, wxUint32 live, wxUint32 old)
void Life::DoLine(wxInt32 x, wxInt32 y, wxUint32 live, wxUint32 old)
{
wxUint32 diff = (live ^ old) & 0xff;
if (!diff) return;
for (wxInt32 k = 8; k; k--, i++)
for (wxInt32 k = 8; k; k--, x++)
{
if (diff & 0x01)
{
m_cells[m_ncells].i = i;
m_cells[m_ncells].j = j;
m_cells[m_ncells].i = x;
m_cells[m_ncells].j = y;
m_ncells++;
}
diff >>= 1;
}
}
void Life::BeginFind(wxInt32 i0, wxInt32 j0, wxInt32 i1, wxInt32 j1, bool changed)
void Life::BeginFind(wxInt32 x0, wxInt32 y0, wxInt32 x1, wxInt32 y1, bool changed)
{
// TODO: optimize for the case where the maximum number of
// cellboxes that fit in the specified viewport is smaller
// than the current total of boxes; iterating over the list
// should then be faster than searching in the hash table.
m_i0 = m_i = i0 & 0xfffffff8;
m_j0 = m_j = j0 & 0xfffffff8;
m_i1 = (i1 + 7) & 0xfffffff8;
m_j1 = (j1 + 7) & 0xfffffff8;
m_x0 = m_x = x0 & 0xfffffff8;
m_y0 = m_y = y0 & 0xfffffff8;
m_x1 = (x1 + 7) & 0xfffffff8;
m_y1 = (y1 + 7) & 0xfffffff8;
m_findmore = TRUE;
m_changed = changed;
@@ -495,10 +525,10 @@ bool Life::FindMore(Cell *cells[], size_t *ncells)
if (m_changed)
{
for ( ; m_j <= m_j1; m_j += 8, m_i = m_i0)
for ( ; m_i <= m_i1; m_i += 8)
for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
for ( ; m_x <= m_x1; m_x += 8)
{
if ((c = LinkBox(m_i, m_j, FALSE)) == NULL)
if ((c = LinkBox(m_x, m_y, FALSE)) == NULL)
continue;
// check whether there is enough space left in the array
@@ -508,22 +538,22 @@ bool Life::FindMore(Cell *cells[], size_t *ncells)
return FALSE;
}
DoLine(m_i, m_j , c->m_live1, c->m_old1 );
DoLine(m_i, m_j + 1, c->m_live1 >> 8, c->m_old1 >> 8 );
DoLine(m_i, m_j + 2, c->m_live1 >> 16, c->m_old1 >> 16);
DoLine(m_i, m_j + 3, c->m_live1 >> 24, c->m_old1 >> 24);
DoLine(m_i, m_j + 4, c->m_live2, c->m_old2 );
DoLine(m_i, m_j + 5, c->m_live2 >> 8, c->m_old2 >> 8 );
DoLine(m_i, m_j + 6, c->m_live2 >> 16, c->m_old2 >> 16);
DoLine(m_i, m_j + 7, c->m_live2 >> 24, c->m_old2 >> 24);
DoLine(m_x, m_y , c->m_live1, c->m_old1 );
DoLine(m_x, m_y + 1, c->m_live1 >> 8, c->m_old1 >> 8 );
DoLine(m_x, m_y + 2, c->m_live1 >> 16, c->m_old1 >> 16);
DoLine(m_x, m_y + 3, c->m_live1 >> 24, c->m_old1 >> 24);
DoLine(m_x, m_y + 4, c->m_live2, c->m_old2 );
DoLine(m_x, m_y + 5, c->m_live2 >> 8, c->m_old2 >> 8 );
DoLine(m_x, m_y + 6, c->m_live2 >> 16, c->m_old2 >> 16);
DoLine(m_x, m_y + 7, c->m_live2 >> 24, c->m_old2 >> 24);
}
}
else
{
for ( ; m_j <= m_j1; m_j += 8, m_i = m_i0)
for ( ; m_i <= m_i1; m_i += 8)
for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
for ( ; m_x <= m_x1; m_x += 8)
{
if ((c = LinkBox(m_i, m_j, FALSE)) == NULL)
if ((c = LinkBox(m_x, m_y, FALSE)) == NULL)
continue;
// check whether there is enough space left in the array
@@ -533,14 +563,14 @@ bool Life::FindMore(Cell *cells[], size_t *ncells)
return FALSE;
}
DoLine(m_i, m_j , c->m_live1 );
DoLine(m_i, m_j + 1, c->m_live1 >> 8 );
DoLine(m_i, m_j + 2, c->m_live1 >> 16);
DoLine(m_i, m_j + 3, c->m_live1 >> 24);
DoLine(m_i, m_j + 4, c->m_live2 );
DoLine(m_i, m_j + 5, c->m_live2 >> 8 );
DoLine(m_i, m_j + 6, c->m_live2 >> 16);
DoLine(m_i, m_j + 7, c->m_live2 >> 24);
DoLine(m_x, m_y , c->m_live1 );
DoLine(m_x, m_y + 1, c->m_live1 >> 8 );
DoLine(m_x, m_y + 2, c->m_live1 >> 16);
DoLine(m_x, m_y + 3, c->m_live1 >> 24);
DoLine(m_x, m_y + 4, c->m_live2 );
DoLine(m_x, m_y + 5, c->m_live2 >> 8 );
DoLine(m_x, m_y + 6, c->m_live2 >> 16);
DoLine(m_x, m_y + 7, c->m_live2 >> 24);
}
}

View File

@@ -29,45 +29,44 @@
#endif
// --------------------------------------------------------------------------
// Cell
// --------------------------------------------------------------------------
// A Cell is just a struct which contains a pair of (i, j) coords.
// These structs are not used internally anywhere; they are just
// used to pass cell coordinates around.
struct Cell
{
wxInt32 i;
wxInt32 j;
};
// --------------------------------------------------------------------------
// LifeShape
// LifePattern
// --------------------------------------------------------------------------
// A class which holds a pattern
class LifeShape
class LifePattern
{
public:
LifeShape(wxString name,
wxString desc,
int width,
int height,
char *data)
// This ctor is used by the LifeReader class
LifePattern(wxString name,
wxString description,
wxString rules,
wxArrayString shape)
{
m_name = name;
m_desc = desc;
m_width = width;
m_height = height;
m_data = data;
}
m_name = name;
m_description = description;
m_rules = rules;
m_shape = shape;
};
// A more convenient ctor for the built-in samples
LifePattern(wxString name,
wxString description,
int width,
int height,
const char *shape)
{
m_name = name;
m_description = description;
m_rules = _("");
m_shape.Add( wxString::Format("%i %i", -width/2, -height/2) );
for(int j = 0; j < height; j++)
m_shape.Add( wxString(shape + (j * width), (size_t) width) );
};
wxString m_name;
wxString m_desc;
int m_width;
int m_height;
char *m_data;
wxString m_name;
wxString m_description;
wxString m_rules;
wxArrayString m_shape;
};
@@ -75,8 +74,17 @@ public:
// Life
// --------------------------------------------------------------------------
// A struct used to pass cell coordinates around
struct Cell
{
wxInt32 i;
wxInt32 j;
};
// A private class that contains data about a block of cells
class CellBox;
// A class that models a Life game instance
class Life
{
public:
@@ -85,10 +93,12 @@ public:
~Life();
// accessors
inline wxUint32 GetNumCells() const { return m_numcells; };
bool IsAlive (wxInt32 x, wxInt32 y);
void SetCell (wxInt32 x, wxInt32 y, bool alive = TRUE);
void SetShape (const LifeShape &shape);
inline wxUint32 GetNumCells() const { return m_numcells; };
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 SetPattern(const LifePattern &pattern);
// game control
void Clear();
@@ -119,8 +129,8 @@ public:
// FALSE, then the operation is not complete: just process all cells
// and call FillMore() again.
//
void BeginFind(wxInt32 i0, wxInt32 j0,
wxInt32 i1, wxInt32 j1,
void BeginFind(wxInt32 x0, wxInt32 y0,
wxInt32 x1, wxInt32 y1,
bool changed);
bool FindMore(Cell *cells[], size_t *ncells);
@@ -131,20 +141,28 @@ private:
void KillBox(CellBox *c);
// helper for BeginFind & FindMore
void DoLine(wxInt32 i, wxInt32 j, wxUint32 alive, wxUint32 old = 0);
void DoLine(wxInt32 x, wxInt32 y, wxUint32 alive, wxUint32 old = 0);
CellBox *m_head; // list of alive boxes
CellBox *m_available; // list of reusable dead boxes
CellBox **m_boxes; // hash table of alive boxes
wxUint32 m_numcells; // population (number of alive cells)
Cell *m_cells; // cell array for FindMore()
size_t m_ncells; // number of valid cells in cell array
wxInt32 m_i, m_j, // state vars for FindMore()
m_i0, m_j0,
m_i1, m_j1;
bool m_changed;
bool m_findmore;
// pattern description
wxString m_name; // name (currently unused)
wxString m_rules; // rules (currently unused)
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
wxUint32 m_numcells; // population (number of alive cells)
// state vars for BeginFind & FindMore
Cell *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,
m_x1, m_y1;
bool m_changed;
bool m_findmore;
};
#endif // _LIFE_GAME_H_

File diff suppressed because it is too large Load Diff

View File

@@ -137,8 +137,9 @@ private:
DECLARE_EVENT_TABLE()
// event handlers
void OnSamples(wxCommandEvent& event);
void OnMenu(wxCommandEvent& event);
void OnOpen(wxCommandEvent& event);
void OnSamples(wxCommandEvent& event);
void OnNavigate(wxCommandEvent& event);
void OnZoom(wxCommandEvent& event);
void OnSlider(wxScrollEvent& event);

View File

@@ -2,13 +2,16 @@ mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc"
reset BITMAP "bitmaps/reset.bmp"
open BITMAP "bitmaps/open.bmp"
play BITMAP "bitmaps/play.bmp"
stop BITMAP "bitmaps/stop.bmp"
zoomin BITMAP "bitmaps/zoomin.bmp"
zoomout BITMAP "bitmaps/zoomout.bmp"
info BITMAP "bitmaps/info.bmp"
north BITMAP "bitmaps/north.bmp"
east BITMAP "bitmaps/east.bmp"
south BITMAP "bitmaps/south.bmp"
west BITMAP "bitmaps/west.bmp"
center BITMAP "bitmaps/center.bmp"
life BITMAP "bitmaps/life.bmp"

View File

@@ -10,7 +10,7 @@
WXDIR = $(WXWIN)
TARGET=life
OBJECTS = $(TARGET).obj dialogs.obj game.obj
OBJECTS = $(TARGET).obj dialogs.obj game.obj reader.obj
!include $(WXDIR)\src\makeprog.b32

View File

@@ -13,7 +13,7 @@
WXDIR = $(WXWIN)
TARGET=life
OBJECTS=$(TARGET).obj dialogs.obj game.obj
OBJECTS=$(TARGET).obj dialogs.obj game.obj reader.obj
!include $(WXDIR)\src\makeprog.bcc

View File

@@ -11,7 +11,7 @@
WXDIR = $(WXWIN)
TARGET=life
OBJECTS = $(TARGET).obj dialogs.obj game.obj
OBJECTS = $(TARGET).obj dialogs.obj game.obj reader.obj
!include $(WXDIR)\src\makeprog.msc

View File

@@ -10,7 +10,8 @@
WXDIR = ../..
TARGET=life
OBJECTS = $(TARGET).o dialogs.o game.o
EXTRALDFLAGS=-Wl,--subsystem,console
OBJECTS = $(TARGET).o dialogs.o game.o reader.o
include $(WXDIR)/src/makeprog.g95

View File

@@ -17,7 +17,7 @@ CC = gcc
PROGRAM = life
OBJECTS = $(PROGRAM).o dialogs.o game.o
OBJECTS = $(PROGRAM).o dialogs.o game.o reader.o
# implementation

View File

@@ -12,7 +12,7 @@
WXDIR = $(WXWIN)
PROGRAM=life
OBJECTS = $(PROGRAM).obj dialogs.obj game.obj
OBJECTS = $(PROGRAM).obj dialogs.obj game.obj reader.obj
!include $(WXDIR)\src\makeprog.vc

View File

@@ -8,7 +8,7 @@
WXDIR = $(%WXWIN)
PROGRAM = life
OBJECTS = $(PROGRAM).obj dialogs.obj game.obj
OBJECTS = $(PROGRAM).obj dialogs.obj game.obj reader.obj
!include $(WXDIR)\src\makeprog.wat

91
demos/life/reader.cpp Normal file
View File

@@ -0,0 +1,91 @@
/////////////////////////////////////////////////////////////////////////////
// Name: reader.cpp
// Purpose: Life! pattern reader (writer coming soon)
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ==========================================================================
// headers, declarations, constants
// ==========================================================================
#ifdef __GNUG__
#pragma implementation "reader.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/txtstrm.h"
#include "reader.h"
// ==========================================================================
// LifeReader
// ==========================================================================
#define LIFE_CHECKVAL( msg ) \
if (!m_ok) \
{ \
wxMessageBox( msg, _("Error"), wxICON_EXCLAMATION | wxOK ); \
return; \
}
LifeReader::LifeReader(wxInputStream& is)
{
wxBufferedInputStream buff_is(is);
wxTextInputStream text_is(buff_is);
wxString line, rest;
// check stream
m_ok = is.IsOk();
LIFE_CHECKVAL(_("Couldn't read any data"));
// read signature
m_ok = text_is.ReadLine().Contains(wxT("#Life 1.05"));
LIFE_CHECKVAL(_("Error reading signature. Not a Life pattern?"));
// read description
m_description = wxT("");
line = text_is.ReadLine();
while (buff_is.IsOk() && line.StartsWith(wxT("#D"), &rest))
{
m_description += rest.Trim(FALSE);
m_description += wxT("\n");
line = text_is.ReadLine();
}
m_ok = buff_is.IsOk();
LIFE_CHECKVAL(_("Unexpected EOF while reading description"));
// read rules
m_ok = line.StartsWith(wxT("#N"));
LIFE_CHECKVAL(_("Sorry, non-conway rules not supported yet"));
// read shape
while (buff_is.IsOk())
{
line = ( text_is.ReadLine() ).Trim();
if (!line.IsEmpty())
{
if (line.StartsWith(wxT("#P "), &rest))
m_shape.Add(rest);
else
m_shape.Add(line);
}
}
}

58
demos/life/reader.h Normal file
View File

@@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////
// Name: reader.h
// Purpose: Life! pattern reader (writer coming soon)
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
// Modified by:
// Created: Jan/2000
// RCS-ID: $Id$
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _LIFE_READER_H_
#define _LIFE_READER_H_
#ifdef __GNUG__
#pragma interface "reader.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
#include "game.h"
// --------------------------------------------------------------------------
// LifeReader
// --------------------------------------------------------------------------
class LifeReader
{
public:
LifeReader(wxInputStream& is);
inline bool IsOk() const { return m_ok; };
inline wxString GetDescription() const { return m_description; };
inline wxString GetRules() const { return m_rules; };
inline wxArrayString GetShape() const { return m_shape; };
inline LifePattern GetPattern() const
{
return LifePattern(_(""), m_description, m_rules, m_shape);
};
private:
bool m_ok;
wxString m_description;
wxString m_rules;
wxArrayString m_shape;
};
#endif // _LIFE_READER_H_

View File

@@ -23,9 +23,10 @@
*
*/
const LifeShape g_shapes[] =
const LifePattern g_patterns[] =
{
LifeShape( _("Glider"),
LifePattern(
_("Glider"),
_("The glider is the first of a series of life forms, known "
"as spaceships or fishes, which can travel along the game "
"field retaining their original shape."),
@@ -33,7 +34,8 @@ const LifeShape g_shapes[] =
".*."
"..*"
"***"),
LifeShape( _("Heavyweight spaceship"),
LifePattern(
_("Heavyweight spaceship"),
_("The glider is just the smaller of the spaceships; this "
"one, known as the heavyweight spaceship or 'big fish', "
"is the largest spaceship which can travel alone without "
@@ -44,7 +46,8 @@ const LifeShape g_shapes[] =
"......*"
"*.....*"
".******"),
LifeShape( _("Eater"),
LifePattern(
_("Eater"),
_("An eater is any still life that can repair itself from "
"some attacks. This one (bottom right), also known as "
"'fishhook', eats gliders and fishes (spaceships) provided "
@@ -60,7 +63,8 @@ const LifeShape g_shapes[] =
"......*.*."
"........*."
"........**" ),
LifeShape( _("Dice shaker"),
LifePattern(
_("Dice shaker"),
_("Oscillators have been extensively explored in Life!. "
"The dice shaker turns around each seven tics; thus, it "
"is an oscillator with a period of fourteen."),
@@ -71,7 +75,8 @@ const LifeShape g_shapes[] =
"*.*.*.*"
"*.*.*.*"
"**...**" ),
LifeShape( _("Hertz oscillator"),
LifePattern(
_("Hertz oscillator"),
_("The Hertz oscillator is a good example of a set of life "
"patterns known as 'billiard tables'. A billiard table is "
"an oscillator which is built inside a stable border. In "
@@ -88,7 +93,8 @@ const LifeShape g_shapes[] =
".............."
".......**....."
".......**....." ),
LifeShape( _("Phoenix"),
LifePattern(
_("Phoenix"),
_("A phoenix is a pattern whose cells all die in every "
"generation, and yet lives forever. For example, this is "
"a phoenix with period two."),
@@ -101,7 +107,8 @@ const LifeShape g_shapes[] =
".*......"
"...*.*.."
"...*...." ),
LifeShape( _("R-pentomino"),
LifePattern(
_("R-pentomino"),
_("The R-pentomino is a methuselah - a life form which "
"lives for hundreds of generations without stabilizing "
"or dying. In particular, the R-Pentomino requires more "
@@ -111,7 +118,8 @@ const LifeShape g_shapes[] =
".**"
"**."
".*." ),
LifeShape( _("Thunderbird"),
LifePattern(
_("Thunderbird"),
_("The thunderbird is another popular methuselah, which "
"doesn't stabilize until the 243th generation. Note that "
"because the initial configuration is symmetrical with "
@@ -123,14 +131,16 @@ const LifeShape g_shapes[] =
".*."
".*."
".*." ),
LifeShape( _("Accorn"),
LifePattern(
_("Accorn"),
_("Probably the most popular methuselah, the accorn lives "
"for 5206 (!) generations."),
7, 3,
".*....."
"...*..."
"**..***" ),
LifeShape( _("Galaxy"),
LifePattern(
_("Galaxy"),
_("One from my personal collection. It is really beautiful "
"to see this configuration expand and shrink periodically "
"for hundreds of tics before reaching a stable state."),
@@ -148,7 +158,8 @@ const LifeShape g_shapes[] =
"......*......"
"......*......"
".......***..." ),
LifeShape( _("Glider gun"),
LifePattern(
_("Glider gun"),
_("A gun is a stationary pattern that emits spaceships "
"forever. The glider gun shown here was the first known "
"gun, and indeed the first known finite pattern with "
@@ -164,7 +175,8 @@ const LifeShape g_shapes[] =
"**.........*...**........*.........."
"............*.*....................."
".............*......................" ),
LifeShape( _("Puffer train"),
LifePattern(
_("Puffer train"),
_("A puffer is an object that moves like a spaceship, except "
"that it leaves a trail of debris behind. The puffer train "
"is one of the best-known puffers. Originally found by "
@@ -191,7 +203,8 @@ const LifeShape g_shapes[] =
"....*"
"*...*"
".****" ),
LifeShape( _("Max"),
LifePattern(
_("Max"),
_("Max is the fastest-growing known pattern in Conway's Game "
"of Life (possibly the fastest possible). It fills space to "
"a density of 1/2, conjectured to be the maximum density, "