示例#1
0
UINT CPokerTrackerThread::PokertrackerThreadFunction(LPVOID pParam)
{
	CPokerTrackerThread *pParent = static_cast<CPokerTrackerThread*>(pParam);
	int				iteration = 0;
	clock_t			iterStart, iterEnd;
	int				iterDurationMS;

	while (::WaitForSingleObject(pParent->_m_stop_thread, 0) != WAIT_OBJECT_0)
	{
		iterStart = clock();
		write_log(preferences.debug_pokertracker(), "[PokerTracker] PTthread iteration [%d] had started\n", ++iteration);
		if (!pParent->_connected)
		{
			pParent->Connect();
		}
	
		double players = p_symbol_engine_active_dealt_playing->nopponentsplaying() 
			+ (p_symbol_engine_userchair->userchair_confirmed() ? 1 : 0); 
		write_log(preferences.debug_pokertracker(), "[PokerTracker] Players count is [%d]\n", players);
				
		if (players < 2)
		{
			write_log(preferences.debug_pokertracker(), "[PokerTracker] Not enough players to justify iteration...\n");
			write_log(preferences.debug_pokertracker(), "[PokerTracker] For beginners: possible tablemap-problem?\n");
			write_log(preferences.debug_pokertracker(), "[PokerTracker] Continuing anyway...\n");
		}

		// Avoiding division by zero and setting sleep time
		AdaptValueToMinMaxRange(&players, 1, k_max_number_of_players);
		int sleep_time = (int) ((double)(/*preferences.pt_cache_refresh() !!*/ 30 * 1000) / (double)((PT_DLL_GetNumberOfStats() + 1) * players));
		write_log(preferences.debug_pokertracker(), "[PokerTracker] sleepTime set to %d\n", sleep_time);
		LightSleep(sleep_time, pParent);
		
		if (pParent->_connected && PQstatus(pParent->_pgconn) == CONNECTION_OK)
		{
			for (int chair = 0; chair < p_tablemap->nchairs(); ++chair)
			{
				GetStatsForChair(pParam, chair, sleep_time);
				/* Verify therad_stop is false */ 
				if (LightSleep(0, pParent)) 
					break; 
			}
		}
		iterEnd = clock();
		iterDurationMS = (int) ((double)(iterEnd - iterStart));
		write_log(preferences.debug_pokertracker(), "[PokerTracker] PTthread iteration [%d] had ended, duration time in ms: [%d]\n", ++iteration, iterDurationMS);
		if (iterDurationMS <= 10000)
		{
			write_log(preferences.debug_pokertracker(), "[PokerTracker] sleeping [%d] ms because iteration was too quick.\n", 10000 - iterDurationMS);
			if (LightSleep(10000 - iterDurationMS, pParent)) 
				break; 
		}
	}
	// Set event
	write_log(preferences.debug_pokertracker(), "[PokerTracker] PokertrackerThreadFunction: outside while loop...\n");
	::SetEvent(pParent->_m_wait_thread);
	return 0;
}
示例#2
0
文件: main.c 项目: ClockSelect/myevic
//=========================================================================
//----- (00005D14) --------------------------------------------------------
__myevic__ void FlushAndSleep()
{
	#if (ENABLE_UART)
		UART_WAIT_TX_EMPTY( UART0 );
	#endif

	if ( !gFlags.light_sleep )
	{
		CLK_PowerDown();
	}
	else
	{
		LightSleep();
	}
}
示例#3
0
void CPokerTrackerThread::GetStatsForChair(LPVOID pParam, int chair, int sleepTime)
{
	CPokerTrackerThread *pParent = static_cast<CPokerTrackerThread*>(pParam);
	int         updatedCount = 0;
	
	if (pParent->CheckIfNameExistsInDB(chair) == false)
	{
		/* Note that checkname fail just when starting, doesn't necessarily mean that there's no user
		   in that chair, but only that the scraper failed to find one. This could be due to lobby window
		   that hides poker window behind it. We make this check once, and if we are good, the update iteration
		   is good to go. if we are not, we assume that this seat is not taken at the moment. */ 
		write_log(preferences.debug_pokertracker(), "[PokerTracker] GetStatsForChair[%d] had been skipped. Reason: [CheckName failed]\n", chair);
		return;
	}
	write_log(preferences.debug_pokertracker(), "[PokerTracker] GetStatsForChair[%d] had been started.\n", chair);
	/* Check if there's a complete update cycle skipping for that chair */
	if (pParent->SkipUpdateForChair(chair))
	{
		pParent->RecalcSkippedUpdates(chair);
		return;
	}

	if (!pParent->_connected)
	{
		pParent->Connect();
	}
		
	if (pParent->_connected && PQstatus(pParent->_pgconn) == CONNECTION_OK)
	{
		if (p_autoconnector->IsConnected())
		{
			for (int i=0; i<PT_DLL_GetNumberOfStats(); i++)
			{
				/* CheckName is necessary before each update.
				   There's a short interval between any two updates, and it's possible that the player
				   had stood up during the update process. But it also possible that the poker lobby was 
				   hiding our poker window, or some popup temporarily was over it, and that's why CheckName fails.
				   Since we cannot know which one caused checkname to fail, we would continue to update, as 
				   long as we have a found name, and as long as the name did't get changed. 
				   So what we do care about, is the situation were the name got replaced by another name,
				   in that case, we stop the update for the current chair  			   */ 

				if (_player_data[chair].found)
				{
					/* Verify therad_stop is false */ 
					if (LightSleep(0, pParent)) 
						return; 
					/* verify that name did not get changed */
					if (pParent->CheckIfNameHasChanged(i))
					{
						/* Name got changed while we search for stats for current chair
						   Simply return.
						   Clearing stats happens by CSymbolEnginePokerTracker
						   on next symbol lookup   .
						*/
						write_log(preferences.debug_pokertracker(), "[PokerTracker] Name changed for chair [%d] Stopping PT-symbol-lookup. \n", chair);
						return;
					}
					if (pParent->SkipUpdateCondition(i, chair))
					{
						/* Updating stat i should be skipped this time */
						/* advanced/positional stats are updated every k_advanced_stat_update_every cycles */
						write_log(preferences.debug_pokertracker(), "[PokerTracker] GetStatsForChair: Updating stats [%d] for chair [%d] had been skipped. Reason: [advanced/positional stats cycle [%d of %d]]\n", i, chair, pParent->GetSkippedUpdates(chair) , k_advanced_stat_update_every);
					}
					else
					{
						/* Update... */
						write_log(preferences.debug_pokertracker(), "[PokerTracker] GetStatsForChair updating stats [%d] for chair [%d]...\n", i, chair);
						pParent->UpdateStat(chair, i);
						++updatedCount;
					}
					/* Sleep between two updates (even if skipped) */
					if (LightSleep(sleepTime, pParent)) 
						return;
				}
				else
				{
					/* We couldn't find any user sitting on that chair. Give message*/
					write_log(preferences.debug_pokertracker(), "[PokerTracker] GetStatsForChair for chair [%d] had been skipped. Reason: [user not found (user stood up?)]\n", chair);
					return;
				}
			}
		}
	}
	pParent->ReportUpdateComplete(updatedCount, chair);
	pParent->RecalcSkippedUpdates(chair);
}
示例#4
0
void CPokerTrackerThread::GetStatsForChair(LPVOID pParam, int chair, int sleepTime)
{
	CPokerTrackerThread *pParent = static_cast<CPokerTrackerThread*>(pParam);
	bool		nameChanged = false;
	bool		sym_issittingin = p_symbol_engine_autoplayer->issittingin();
	bool		sym_ismanual = (bool) p_symbol_engine_autoplayer->ismanual();
	int			i;
	int			updateType;
	char        reason[100];
	int         updatedCount = 0;
	
	if (pParent->CheckName(chair, nameChanged) == false)
	{
		/* Note that checkname fail just when starting, doesn't necessarily mean that there's no user
		   in that chair, but only that the scraper failed to find one. This could be due to lobby window
		   that hides poker window behind it. We make this check once, and if we are good, the update iteration
		   is good to go. if we are not, we assume that this seat is not taken. */ 
		write_log_pokertracker(2, "GetStatsForChair[%d] had been started.\n", chair);
		write_log_pokertracker(2, "GetStatsForChair[%d] had been skipped. Reason: [CheckName failed]\n", chair);
		return;
	}
	const char* playerscrapedName = pParent->GetPlayerScrapedName(chair);
	write_log_pokertracker(2, "GetStatsForChair[%d][%s] had been started.\n", chair, playerscrapedName);
	
	/* Check if there's a complete update cycle skipping for that chair */
	updateType = pParent->SkipUpdateForChair(chair, reason);
	if (updateType == pt_updateType_noUpdate)
	{
		write_log_pokertracker(2, "GetStatsForChair for chair [%d] had been skipped. Reason: [%s]\n", chair, reason);
		pParent->RecalcSkippedUpdates(chair);
		return;
	}

	/* Make sure all other seats contain the appropriate players */ 
	pParent->ReportSeatChanges(chair);  

	if (!pParent->_connected)
		pParent->Connect();
	
	
	if (pParent->_connected && PQstatus(pParent->_pgconn) == CONNECTION_OK)
	{
		if (sym_issittingin || sym_ismanual)
		{
			for (i = pt_min; i <= pt_max; ++i)
			{
				/* Every few iterations, we need to verify that the seats we already have stats on, 
			       did not change. This task is totally irrelevant for the current function
				   we're on, that is GetStatsForChair. But if we won't do this every now and then,
				   we might find ourselves updating stats for chair 1, for 1 minute, while the player
				   in chair 3 stood up and someone else replaced him. we cannot let this go unnoticed */
				if (i % 10 == 4) pParent->ReportSeatChanges(chair);
			
				/* CheckName is necessary before each update.
				   There's a short interval between any two updates, and it's possible that the player
				   had stood up during the update process. But it also possible that the poker lobby was 
				   hiding our poker window, or some popup temporarily was over it, and that's why CheckName fails.
				   Since we cannot know which one caused checkname to fail, we would continue to update, as 
				   long as we have a found name, and as long as the name did't get changed. 
				   So what we do care about, is the situation were the name got replaced by another name,
				   in that case, we stop the update for the current chair  			   */ 


				pParent->CheckName(chair, nameChanged);
				/* Note that Checkname might return false, with IsFound(chair) returning true.
				   When IsFound returns false the situation must be that we no longer have anyone
				   Sitting in that chair*/
				if (pParent->IsFound(chair))
				{
					/* Verify therad_stop is false */ 
					if (LightSleep(0, pParent)) 
						return; 
					/* verify that name did not get changed */
					if (i > pt_min && nameChanged)
					{
						/* Name got changed while we search for stats for current chair
						   Clear stats for this seat and return                   */
						write_log_pokertracker(2, "GetStatsForChair chair [%d] had changed name getting stat for chair. Clearing stats for chair.\n", chair);
						/* Clear stats, but leave the new name intact */
						pParent->ClearSeatStats(chair, false); 
						return;
					}
					if (!pParent->StatEnabled(i))
					{
						/* Skip disabled stats */
						write_log_pokertracker(3, "GetStatsForChair: Updating stats [%d] for chair [%d] had been skipped. Reason: [stat is disabled]\n", i, chair);
					}
					else if (pParent->SkipUpdateCondition(i, chair))
					{
						/* Updating stat i should be skipped this time */
						/* advanced/positional stats are updated every k_advanced_stat_update_every cycles */
						write_log_pokertracker(3, "GetStatsForChair: Updating stats [%d] for chair [%d] had been skipped. Reason: [advanced/positional stats cycle [%d of %d]]\n", i, chair, pParent->GetSkippedUpdates(chair) , k_advanced_stat_update_every);
					}
					else
					{
						/* Update... */
						write_log_pokertracker(3, "GetStatsForChair updating stats [%d] for chair [%d]...\n", i, chair);
						pParent->UpdateStat(chair, i);
						++updatedCount;
					}
					/* Sleep between two updates (even if skipped) */
					if (LightSleep(sleepTime, pParent)) 
						return;
				}
				else
				{
					/* We couldn't find any user sitting on that chair. Give message*/
					write_log_pokertracker(2, "GetStatsForChair for chair [%d] had been skipped. Reason: [user not found (user stood up?)]\n", chair);
					return;
				}
			}
		}
	}
	pParent->ReportUpdateComplete(updatedCount, chair);
	pParent->RecalcSkippedUpdates(chair);
}
示例#5
0
UINT CPokerTrackerThread::PokertrackerThreadFunction(LPVOID pParam)
{
	CPokerTrackerThread *pParent = static_cast<CPokerTrackerThread*>(pParam);
	bool			sym_issittingin = p_symbol_engine_autoplayer->issittingin();
	bool			sym_ismanual = p_symbol_engine_autoplayer->ismanual();
	int				chr = 0;
	int				iteration = 0;
	int				players;
	int				sleepTime;
	bool			dummy;
	clock_t			iterStart, iterEnd;
	int				iterDurationMS;

	while (::WaitForSingleObject(pParent->_m_stop_thread, 0) != WAIT_OBJECT_0)
	{
		iterStart = clock();
		write_log_pokertracker(2, "PTthread iteration [%d] had started\n", ++iteration);
		pParent->SetHandsStat();
		if (!pParent->_connected)
			pParent->Connect();
	
		/* Count the number of players */ 
		players = 0;
		if (pParent->_connected && PQstatus(pParent->_pgconn) == CONNECTION_OK)
		{
			if (sym_issittingin || sym_ismanual)
			{
				for (chr = 0; chr < k_max_number_of_players; ++chr)
				{
					if (pParent->CheckName(chr, dummy))
					{
						++players;
					}
				}
			}
		}
		write_log_pokertracker(2, "Players count is [%d]\n", players);
		
		//Define sleeptime for current ptrhead iteration
		if (players > 1)
		{
			sleepTime = (int) ((double)(/*prefs.pt_cache_refresh() !!*/ 30 * 1000) / (double)(pt_max * players));
			write_log_pokertracker(2, "sleepTime set to %d\n", sleepTime);
		}
		else
		{
			write_log_pokertracker(2, "Not enough players to justify iteration, sleeping 10 seconds...\n");
			LightSleep(10000, pParent);
			continue;
		}
		
		if (pParent->_connected && PQstatus(pParent->_pgconn) == CONNECTION_OK)
		{
			for (chr = 0; chr < k_max_number_of_players; ++chr)
			{
				GetStatsForChair(pParam, chr, sleepTime);
				/* Verify therad_stop is false */ 
				if (LightSleep(0, pParent)) 
					break; 
			}
		}
		iterEnd = clock();
		iterDurationMS = (int) ((double)(iterEnd - iterStart));
		write_log_pokertracker(2, "PTthread iteration [%d] had ended, duration time in ms: [%d]\n", ++iteration, iterDurationMS);
		if (iterDurationMS <= 10000)
		{
			write_log_pokertracker(3, "sleeping [%d] ms because iteration was too quick.\n", 10000 - iterDurationMS);
			if (LightSleep(10000 - iterDurationMS, pParent)) 
				break; 
		}
	}
	// Set event
	write_log_pokertracker(3, "PokertrackerThreadFunction: outside while loop...\n");
	::SetEvent(pParent->_m_wait_thread);
	return 0;
}