![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 #ifndef _CONSOLE 00030 #ifndef __FORM1_H__ 00031 #define __FORM1_H__ 00032 00033 #include <time.h> 00034 #include "Board.h" 00035 #include "Evolution.h" 00036 00037 #define BOARD_SQUARE_SIZE 2 00038 00039 using namespace System; 00040 using namespace System::ComponentModel; 00041 using namespace System::Collections; 00042 using namespace System::Windows::Forms; 00043 using namespace System::Data; 00044 using namespace System::Drawing; 00045 00046 public ref class Form1 : public System::Windows::Forms::Form 00047 { 00048 public: 00049 Form1(void) 00050 { 00051 InitializeComponent(); 00052 00053 FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog; 00054 ClientSize = System::Drawing::Size(1206, 600+m_ribbonHeight+menuStrip1->Height); 00055 00056 int boardWidth = (ClientRectangle.Width/2-m_sepWidth/2)/BOARD_SQUARE_SIZE; 00057 int boardHeight = (ClientRectangle.Height-menuStrip1->Height-m_ribbonHeight)/BOARD_SQUARE_SIZE; 00058 00059 m_board1 = gcnew Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, seqGen); 00060 m_board2 = gcnew Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, parGen); 00061 00062 Controls->Add(m_board1); 00063 Controls->Add(m_board2); 00064 00065 m_board1->Location = System::Drawing::Point(2, m_ribbonHeight + menuStrip1->Height); 00066 m_board2->Location = System::Drawing::Point(2 + boardWidth*BOARD_SQUARE_SIZE + m_sepWidth/2, m_ribbonHeight + menuStrip1->Height); 00067 00068 m_seq = gcnew SequentialEvolution(m_board1->m_matrix, m_board1); 00069 m_par = gcnew ParallelEvolution(m_board2->m_matrix, m_board2); 00070 00071 m_seqThread = gcnew Thread(gcnew ThreadStart(m_seq, &SequentialEvolution::Run)); 00072 m_parThread = gcnew Thread(gcnew ThreadStart(m_par, &ParallelEvolution::Run)); 00073 00074 Thread::CurrentThread->Priority = ThreadPriority::AboveNormal; 00075 00076 m_suspend = true; 00077 } 00078 protected: 00079 ~Form1() 00080 { 00081 if (components) 00082 { 00083 delete components; 00084 } 00085 } 00086 private: System::Windows::Forms::MenuStrip^ menuStrip1; 00087 private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem; 00088 private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem; 00089 private: System::Windows::Forms::ToolStripMenuItem^ gameToolStripMenuItem; 00090 private: System::Windows::Forms::ToolStripMenuItem^ seedToolStripMenuItem; 00091 private: System::Windows::Forms::ToolStripMenuItem^ runToolStripMenuItem; 00092 private: System::Windows::Forms::ToolStripMenuItem^ pauseToolStripMenuItem; 00093 private: Board^ m_board1; 00094 private: Board^ m_board2; 00095 private: System::Windows::Forms::Label^ Sequential; 00096 private: System::Windows::Forms::Label^ label1; 00097 private: static const int m_sepWidth = 5; 00098 private: static const int m_ribbonHeight = 26; 00099 private: SequentialEvolution^ m_seq; 00100 private: ParallelEvolution^ m_par; 00101 private: Thread^ m_seqThread; 00102 private: Thread^ m_parThread; 00103 private: System::Windows::Forms::Label^ seqGen; 00104 private: System::Windows::Forms::Label^ parGen; 00105 private: bool m_suspend; 00106 00107 private: 00108 System::ComponentModel::Container ^components; 00109 00110 #pragma region Windows Form Designer generated code 00111 void InitializeComponent(void) 00112 { 00113 this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip()); 00114 this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00115 this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00116 this->gameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00117 this->seedToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00118 this->runToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00119 this->pauseToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); 00120 this->Sequential = (gcnew System::Windows::Forms::Label()); 00121 this->label1 = (gcnew System::Windows::Forms::Label()); 00122 this->seqGen = (gcnew System::Windows::Forms::Label()); 00123 this->parGen = (gcnew System::Windows::Forms::Label()); 00124 this->menuStrip1->SuspendLayout(); 00125 this->SuspendLayout(); 00126 // 00127 // menuStrip1 00128 // 00129 this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) 00130 {this->fileToolStripMenuItem, this->gameToolStripMenuItem}); 00131 this->menuStrip1->Location = System::Drawing::Point(0, 0); 00132 this->menuStrip1->Name = L"menuStrip1"; 00133 this->menuStrip1->Padding = System::Windows::Forms::Padding(8, 2, 0, 2); 00134 this->menuStrip1->Size = System::Drawing::Size(1600, 26); 00135 this->menuStrip1->TabIndex = 0; 00136 this->menuStrip1->Text = L"menuStrip1"; 00137 this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::menuStrip1_ItemClicked); 00138 // 00139 // fileToolStripMenuItem 00140 // 00141 this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->exitToolStripMenuItem}); 00142 this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem"; 00143 this->fileToolStripMenuItem->Size = System::Drawing::Size(40, 22); 00144 this->fileToolStripMenuItem->Text = L"File"; 00145 // 00146 // exitToolStripMenuItem 00147 // 00148 this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem"; 00149 this->exitToolStripMenuItem->Size = System::Drawing::Size(99, 22); 00150 this->exitToolStripMenuItem->Text = L"Exit"; 00151 this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnExit); 00152 // 00153 // gameToolStripMenuItem 00154 // 00155 this->gameToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->seedToolStripMenuItem, 00156 this->runToolStripMenuItem, this->pauseToolStripMenuItem}); 00157 this->gameToolStripMenuItem->Name = L"gameToolStripMenuItem"; 00158 this->gameToolStripMenuItem->Size = System::Drawing::Size(59, 22); 00159 this->gameToolStripMenuItem->Text = L"Game"; 00160 // 00161 // seedToolStripMenuItem 00162 // 00163 this->seedToolStripMenuItem->Name = L"seedToolStripMenuItem"; 00164 this->seedToolStripMenuItem->Size = System::Drawing::Size(115, 22); 00165 this->seedToolStripMenuItem->Text = L"Seed"; 00166 this->seedToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnSeed); 00167 // 00168 // runToolStripMenuItem 00169 // 00170 this->runToolStripMenuItem->Enabled = false; 00171 this->runToolStripMenuItem->Name = L"runToolStripMenuItem"; 00172 this->runToolStripMenuItem->Size = System::Drawing::Size(115, 22); 00173 this->runToolStripMenuItem->Text = L"Run"; 00174 this->runToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnRun); 00175 // 00176 // pauseToolStripMenuItem 00177 // 00178 this->pauseToolStripMenuItem->Enabled = false; 00179 this->pauseToolStripMenuItem->Name = L"pauseToolStripMenuItem"; 00180 this->pauseToolStripMenuItem->Size = System::Drawing::Size(115, 22); 00181 this->pauseToolStripMenuItem->Text = L"Pause"; 00182 this->pauseToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnPauseResume); 00183 // 00184 // Sequential 00185 // 00186 this->Sequential->AutoSize = true; 00187 this->Sequential->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 00188 static_cast<System::Byte>(0))); 00189 this->Sequential->Location = System::Drawing::Point(12, 32); 00190 this->Sequential->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 00191 this->Sequential->Name = L"Sequential"; 00192 this->Sequential->Size = System::Drawing::Size(239, 18); 00193 this->Sequential->TabIndex = 1; 00194 this->Sequential->Text = L"Sequential Algorithm generation:"; 00195 // 00196 // label1 00197 // 00198 this->label1->AutoSize = true; 00199 this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 00200 static_cast<System::Byte>(0))); 00201 this->label1->Location = System::Drawing::Point(813, 32); 00202 this->label1->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 00203 this->label1->Name = L"label1"; 00204 this->label1->Size = System::Drawing::Size(219, 18); 00205 this->label1->TabIndex = 2; 00206 this->label1->Text = L"Parallel Algorithm generation: "; 00207 // 00208 // seqGen 00209 // 00210 this->seqGen->AutoSize = true; 00211 this->seqGen->Location = System::Drawing::Point(289, 35); 00212 this->seqGen->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 00213 this->seqGen->Name = L"seqGen"; 00214 this->seqGen->Size = System::Drawing::Size(16, 17); 00215 this->seqGen->TabIndex = 3; 00216 this->seqGen->Text = L"0"; 00217 // 00218 // parGen 00219 // 00220 this->parGen->AutoSize = true; 00221 this->parGen->Location = System::Drawing::Point(1068, 35); 00222 this->parGen->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 00223 this->parGen->Name = L"parGen"; 00224 this->parGen->Size = System::Drawing::Size(16, 17); 00225 this->parGen->TabIndex = 4; 00226 this->parGen->Text = L"0"; 00227 // 00228 // Form1 00229 // 00230 this->AutoScaleDimensions = System::Drawing::SizeF(8, 16); 00231 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 00232 this->ClientSize = System::Drawing::Size(1600, 738); 00233 this->Controls->Add(this->parGen); 00234 this->Controls->Add(this->seqGen); 00235 this->Controls->Add(this->label1); 00236 this->Controls->Add(this->Sequential); 00237 this->Controls->Add(this->menuStrip1); 00238 this->MainMenuStrip = this->menuStrip1; 00239 this->Margin = System::Windows::Forms::Padding(4); 00240 this->MaximizeBox = false; 00241 this->Name = L"Form1"; 00242 this->Text = L"Game of Life"; 00243 this->menuStrip1->ResumeLayout(false); 00244 this->menuStrip1->PerformLayout(); 00245 this->ResumeLayout(false); 00246 this->PerformLayout(); 00247 00248 } 00249 #pragma endregion 00250 protected: 00251 void CloseApp () 00252 { 00253 m_seq->Quit(); 00254 m_par->Quit(); 00256 System::Environment::Exit(0); 00257 } 00258 00259 protected: 00260 virtual void OnPaint(PaintEventArgs^ e) override 00261 { 00262 } 00263 00264 virtual void OnFormClosing(FormClosingEventArgs^ e) override 00265 { 00266 CloseApp(); 00267 } 00268 00269 void OnExit(System::Object^ sender, System::EventArgs^ e) 00270 { 00271 CloseApp(); 00272 } 00273 00274 void OnSeed(System::Object^ sender, System::EventArgs^ e) 00275 { 00276 this->seedToolStripMenuItem->Enabled = false; 00277 this->runToolStripMenuItem->Enabled = true; 00278 time_t now = time(NULL); 00279 this->m_board1->seed((int)now); 00280 this->m_board2->seed(this->m_board1); 00281 this->Invalidate(); 00282 } 00283 00284 void OnRun(System::Object^ sender, System::EventArgs^ e) 00285 { 00286 this->runToolStripMenuItem->Enabled = false; 00287 this->pauseToolStripMenuItem->Enabled = true; 00288 m_seqThread->Start(); 00289 m_parThread->Start(); 00290 } 00291 00292 void OnPauseResume(System::Object^ sender, System::EventArgs^ e) 00293 { 00294 if (m_suspend) 00295 { 00296 m_seq->SetPause(true); 00297 m_par->SetPause(true); 00298 this->pauseToolStripMenuItem->Text = L"Resume"; 00299 } 00300 else 00301 { 00302 m_seq->SetPause(false); 00303 m_par->SetPause(false); 00304 this->pauseToolStripMenuItem->Text = L"Pause"; 00305 } 00306 m_suspend = !m_suspend; 00307 } 00308 00309 private: 00310 System::Void menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) 00311 {} 00312 }; 00313 #endif 00314 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.