void GameEngine::run()
{
	al_start_timer(m_RedrawTimer);
	
	m_GameActive = true;
	m_LastSecondTime = al_current_time();
	bool redrawScene = true;

	DEBUG_WINDOW("DEBUG MAIN", 300, 180);

	while(m_GameActive)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(m_EventQueue, &event);

		switch(event.type)
		{
			case ALLEGRO_EVENT_DISPLAY_CLOSE:
				m_GameActive = false;
				break;

			case ALLEGRO_EVENT_KEY_DOWN:
				if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
					m_GameActive = false;
				break;

			case ALLEGRO_EVENT_TIMER:
				redrawScene = true;
				break;
		}
		
		if (redrawScene && al_is_event_queue_empty(m_EventQueue))
		{
			GameStateInterface* currentState = getCurrentState();
			currentState->update(this);
			currentState->draw(this);

			al_flip_display();

			calculateFrameRate();

			redrawScene = false;

			DEBUG_REFRESH_ALL();
		}
	}

}
/// Function name  : createDocumentsControl
// Description     : Create a new Documents control
// 
// HWND             hParentWnd     : [in] Parent window for the documents tab control
// CONST RECT*      pRect          : [in] Bounding rectangle for the new tab control
// CONST UINT       iControlID     : [in] Control ID for the documents tab control
// 
// Return type : Window handle of the new tab control, if successful, otherwise NULL
//
HWND   createDocumentsControl(HWND  hParentWnd, CONST RECT*  pRect, CONST UINT  iControlID)
{
   DOCUMENTS_DATA*  pWindowData;       // Window data
   SIZE             siCtrlSize;        // Size of the new control
   RECT             rcCtrlRect;        // Rect of new control
   HWND             hTabCtrl;          // Convenience pointer
   
   
   // Prepare
   rcCtrlRect = *pRect;

   // Reduce size of target rectangle to create border effect
   InflateRect(&rcCtrlRect, -2, -2);
   utilConvertRectangleToSize(&rcCtrlRect, &siCtrlSize);

   /// Create DocumentsControl (Also creates/stores window data)
   hTabCtrl = CreateWindow(szDocumentsCtrlClass, TEXT("Documents Control"), WS_CHILD WITH WS_TABSTOP WITH TCS_TABS WITH TCS_MULTILINE WITH TCS_TOOLTIPS WITH WS_CLIPCHILDREN, //  TCS_SINGLELINE 
                           rcCtrlRect.left, rcCtrlRect.top, siCtrlSize.cy, siCtrlSize.cy, 
                           hParentWnd, (HMENU)iControlID, getAppInstance(), NULL);

   // [DEBUG]
   ERROR_CHECK("creating documents control", hTabCtrl);

   // [CHECK] Ensure control was created successfully
   if (hTabCtrl)
   {
      // Prepare
      pWindowData = getDocumentsControlData(hTabCtrl);

      // Set font and ImageList
      TabCtrl_SetImageList(hTabCtrl, pWindowData->hImageList);
      SetWindowFont(hTabCtrl, pWindowData->hTitleFont, FALSE);

      /// Display window
      UpdateWindow(hTabCtrl);
      ShowWindow(hTabCtrl, SW_SHOW);

      // [DEBUG]
      DEBUG_WINDOW("Documents Control", hTabCtrl);
   }

   // Return window handle or NULL
   return hTabCtrl;
}