-// --------------------------------------------------------------------------
-// Lookup tables - these will be generated on-the-fly soon.
-// --------------------------------------------------------------------------
+// ==========================================================================
+// LifeModule
+// ==========================================================================
+
+// A module to pregenerate lookup tables without having to do it
+// from the application.
+
+class LifeModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(LifeModule)
+
+public:
+ LifeModule() {};
+ bool OnInit();
+ void OnExit();
+};
+
+IMPLEMENT_DYNAMIC_CLASS(LifeModule, wxModule)
+
+bool LifeModule::OnInit()
+{
+ // see below
+ g_tab = new unsigned char [0xfffff];
+
+ if (!g_tab) return FALSE;
+
+ for (wxUint32 i = 0; i < 0xfffff; i++)
+ {
+ wxUint32 val = i >> 4;
+ wxUint32 old = i & 0x0000f;
+ wxUint32 live = 0;
+
+ for (int j = 0; j < 4; j++)
+ {
+ live >>= 1;
+
+ if (((val & 0xf) == 3) || (((val & 0xf) == 2) && (old & 0x1)))
+ live |= 0x8;
+
+ old >>= 1;
+ val >>= 4;
+ }
+
+ g_tab[i] = (unsigned char) live;
+ }
+
+ return TRUE;
+}
+
+void LifeModule::OnExit()
+{
+ delete [] g_tab;
+}
+
+
+// This table converts from number of neighbors (like in on[]) to
+// bits, for a set of four cells. It takes as index a five-digit
+// hexadecimal value (0xNNNNB) where Ns hold number of neighbors
+// for each cell and B holds their previous state.
+//
+unsigned char *g_tab;