Exemplo n.º 1
0
//=====================================================================================
void Frame::OnTimer( wxTimerEvent& event )
{
	// This routine was never meant to be re-entrant.
	// Re-entrancy could cause a crash due to client or server death.
	// If a dialog is put up in this routine, wxWidgets still calls the timer,
	// which can cause re-entrancy.
	static bool inOnTimer = false;
	if( inOnTimer )
		return;
	inOnTimer = true;

	if( panelUpdateNeeded )
	{
		UpdateAllPanels();
		panelUpdateNeeded = false;
	}

	Server* server = wxGetApp().GetServer();
	if( server && !server->Run() )
		KillServer();

	Client* client = wxGetApp().GetClient();
	if( client )
	{
		if( !client->Run() )
		{
			KillClient();
			wxMessageBox( wxT( "We have lost our connection with the server, possibly because the game server has gone down." ), wxT( "Connection Lost" ), wxOK | wxCENTRE, wxGetApp().GetFrame() );
		}
		else
		{
			client->Animate( GetCanvas()->FrameRate() );
			if( continuousRefresh )
				GetCanvas()->Refresh();
		}
	}

	inOnTimer = false;
}