コード例 #1
0
ファイル: CoreTiming.cpp プロジェクト: Abrahamh08/dolphin
// This must be run ONLY from within the CPU thread
// cyclesIntoFuture may be VERY inaccurate if called from anything else
// than Advance
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata)
{
	_assert_msg_(POWERPC, Core::IsCPUThread() || Core::GetState() == Core::CORE_PAUSE,
				 "ScheduleEvent from wrong thread");

	Event *ne = GetNewEvent();
	ne->userdata = userdata;
	ne->type = event_type;
	ne->time = GetTicks() + cyclesIntoFuture;

	// If this event needs to be scheduled before the next advance(), force one early
	if (!globalTimerIsSane)
		ForceExceptionCheck(cyclesIntoFuture);


	AddEventToQueue(ne);
}
コード例 #2
0
void LetterDisplayAnimation::Animate()
{
	unsigned int elapsed = GetTicks() - mStartTime;
	float t = elapsed/(float)mDuration;
	if(t > 1.0f)
	{
			GameMessage msg;
			msg.mEventName = "FINISHED";
			msg.mSender = mID;
			SendOutMessage(msg);
			return;
	}
	IvVector3 pos = Lerp(t, mStartPos, mEndPos);
	
	//Add noise to movement
	IvVector3 normDir = mEndPos - mStartPos;
	normDir.z = 0;
	normDir.Normalize();
	float x = normDir.x;
	float y = normDir.y;
	normDir.x = -y;
	normDir.y = x;
	
	float noise = Perlin::Noise(pos.x*0.01f,pos.y*0.01f);
	
	//ramp noise based on proximity to endpoints
	float s = 1.0f;
	if(t <= 0.1f)
		s = Perlin::lerp(t*10.0f,0.0f,1.0f);
	else if( t >= 0.9f)
		s = Perlin::lerp((t-0.9f)*10.0f,1.0f,0.0f);
	normDir *= noise*5.0f * s;
	
	pos += normDir;
	
	IvVector3 intPos;
	intPos.x = (int)pos.x;
	intPos.y = (int)pos.y;
	intPos.z = mStartPos.z;

	SetPosition(intPos);
	IvVector3 vel(0,201,0);
	mMetaballGrid->ObjectMoved(mID, intPos,vel);
	
}
コード例 #3
0
ファイル: PositionHandler.cpp プロジェクト: Goresome/orange
bool CPositionHandler::HandleMovement(uint8 x, uint8 y, uint8 *pPath, uint32 map)
{
	std::vector<uint8> nodes;
	uint32 count = pPath[0] & 0x0f;
	for(int32 i = 1; i < 8; ++i) /* calculating roadpath nodes */
	{
		if(nodes.size() < count)
		{
			nodes.push_back((pPath[i] & 0xf0) / 0x10);
		}
		if(nodes.size() < count)
		{
			nodes.push_back(pPath[i] & 0x0f);
		}
	}
	assert(nodes.size() == count);
	std::vector<CPositionHandler::MovePoint> new_path;
	new_path.reserve(count + 1); /* reserve space immediately, it must be faster i think */
	MovePoint origin;
	origin.x = x;
	origin.y = y;
	origin.time = GetTicks();
	new_path.push_back(origin);
	uint8 tx = x;
	uint8 ty = y;
	for(uint32 i = 0; i < nodes.size(); ++i) /* building path from client data and checking it for walkability */
	{
		tx += RoadX[nodes.at(i)];
		ty += RoadY[nodes.at(i)];
		if(!WorldMap[map].FreeToMove(tx, ty))
		{
			return false;
		}
		MovePoint pt;
		pt.time = origin.time + 300 * (i + 1); /* time is constant (reversed speed), need calculate it later */
		pt.x = tx;
		pt.y = ty;
		new_path.push_back(pt);
	}
	this->mtx.lock(); /* applying new path, also storing backup of previous */
	this->cache = this->path;
	this->path = new_path;
	this->mtx.unlock();
	return true;
}
コード例 #4
0
ファイル: PositionHandler.cpp プロジェクト: Goresome/orange
const CPositionHandler::MovePoint CPositionHandler::GetPosition()
{
	uint32 current_time = GetTicks();
	CPositionHandler::MovePoint pt;
	this->mtx.lock();
	for(uint32 i = 0; i < this->path.size(); ++i)
	{
		if(this->path.at(i).time > current_time)
		{
			pt = this->path.at(i - 1);
			this->mtx.unlock();
			return pt;
		}
	}
	pt = this->path.at(this->path.size() - 1);
	this->mtx.unlock();
	return pt;
}
コード例 #5
0
ファイル: objectmanager.cpp プロジェクト: Goresome/orange
GUID_HIGH CObjectManager::CreateGuid()
{
	init_genrand(GetTicks());
	GUID_HIGH guid = 0;
	uint32 count = 0;
	while(count < RETRIES)
	{
		count++;
		guid = GUID_HIGH(genrand_int32());
		MapType::iterator it = this->container.find(guid);
		if(it == this->container.end())
		{
			break;
		}
	}
	assert(count != RETRIES);
	return guid;
}
コード例 #6
0
ファイル: gameprotocol.cpp プロジェクト: brunobnb/ghostcb
BYTEARRAY CGameProtocol :: SEND_W3GS_STOP_LAG( CGamePlayer *player, bool loadInGame )
{
	BYTEARRAY packet;
	packet.push_back( W3GS_HEADER_CONSTANT );	// W3GS header constant
	packet.push_back( W3GS_STOP_LAG );			// W3GS_STOP_LAG
	packet.push_back( 0 );						// packet length will be assigned later
	packet.push_back( 0 );						// packet length will be assigned later
	packet.push_back( player->GetPID( ) );

	if( loadInGame )
		UTIL_AppendByteArray( packet, (uint32_t)0, false );
	else
		UTIL_AppendByteArray( packet, GetTicks( ) - player->GetStartedLaggingTicks( ), false );

	AssignLength( packet );
	// DEBUG_Print( "SENT W3GS_STOP_LAG" );
	// DEBUG_Print( packet );
	return packet;
}
コード例 #7
0
CGamePlayer :: CGamePlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved ) : CPotentialPlayer( nProtocol, nGame, nSocket )
{
	m_PID = nPID;
	m_Name = nName;
	m_InternalIP = nInternalIP;
	m_JoinedRealm = nJoinedRealm;
	m_TotalPacketsSent = 0;
	m_TotalPacketsReceived = 0;
	m_LeftCode = PLAYERLEAVE_LOBBY;
	m_LoginAttempts = 0;
	m_SyncCounter = 0;
	m_JoinTime = GetTime( );
	m_LastMapPartSent = 0;
	m_LastMapPartAcked = 0;
	m_StartedDownloadingTicks = 0;
	m_FinishedDownloadingTime = 0;
	m_FinishedLoadingTicks = 0;
	m_StartedLaggingTicks = 0;
	m_StatsSentTime = 0;
	m_StatsDotASentTime = 0;
	m_LastGProxyWaitNoticeSentTime = 0;
	m_Score = -100000.0;
	m_LoggedIn = false;
	m_Spoofed = false;
	m_Reserved = nReserved;
	m_WhoisShouldBeSent = false;
	m_WhoisSent = false;
	m_DownloadAllowed = false;
	m_DownloadStarted = false;
	m_DownloadFinished = false;
	m_FinishedLoading = false;
	m_Lagging = false;
	m_DropVote = false;
	m_KickVote = false;
	m_Muted = false;
	m_LeftMessageSent = false;
	m_GProxy = false;
	m_GProxyDisconnectNoticeSent = false;
	m_GProxyReconnectKey = GetTicks( );
	m_LastGProxyAckTime = 0;
    m_PlayerId = 0;
    m_LeftTime = 0;
}
コード例 #8
0
void HangingLetterSign::AnimateWind()
{
	unsigned int time = GetTicks();
	unsigned int elapsed = time - mStartTime;
	IvVector3 pos;
	this->GetLocalPosition(pos);
	float t = elapsed/(float)mWindDuration;
	
	if(t > 1.0f)
	{
			//this->ResetLocalTransform();//Start with identity
			//this->Translate(pos);
			IdleAnimate();
			return;
			/*GameMessage msg;
			msg.mEventName = "FINISHED";
			msg.mSender = mID;
			SendOutMessage(msg);
			return;*/
	}

	float noise = 0.2f* Perlin::Noise(time*0.001f,pos.x*0.01f);
	float hiFreqNoise = Perlin::Noise(time*0.007f,pos.x*0.01f);
	//ramp noise based on proximity to start and end animation
	
	//have to start with 1.0f times noise because that is what was driving the position and motion of the sign before
	//this animation... if you didn't start with the regular noise value then you would get a hitch in position.
	float s = 2.0f;
	if(t <= 0.25f)
		s = LERP(t*4.0f,1.0f,2.0f);
	else if( t >= 0.75f)
		s = LERP((t-0.75f)*4.0f,2.0f,1.0f);

	mLastUpdateTime = time;
	
	this->ResetLocalTransform();//Start with identity
	this->Translate(pos);
	
	float negNoise = -(0.5f*noise + 0.5f);
	this->Rotate(s*noise*0.3,s*hiFreqNoise*0.5f,s*negNoise*0.5);
	
}
コード例 #9
0
ファイル: CoreTiming.cpp プロジェクト: AdmiralCurtiss/dolphin
void ScheduleEvent(s64 cycles_into_future, EventType* event_type, u64 userdata, FromThread from)
{
  ASSERT_MSG(POWERPC, event_type, "Event type is nullptr, will crash now.");

  bool from_cpu_thread;
  if (from == FromThread::ANY)
  {
    from_cpu_thread = Core::IsCPUThread();
  }
  else
  {
    from_cpu_thread = from == FromThread::CPU;
    ASSERT_MSG(POWERPC, from_cpu_thread == Core::IsCPUThread(),
               "A \"%s\" event was scheduled from the wrong thread (%s)", event_type->name->c_str(),
               from_cpu_thread ? "CPU" : "non-CPU");
  }

  if (from_cpu_thread)
  {
    s64 timeout = GetTicks() + cycles_into_future;

    // If this event needs to be scheduled before the next advance(), force one early
    if (!s_is_global_timer_sane)
      ForceExceptionCheck(cycles_into_future);

    s_event_queue.emplace_back(Event{timeout, s_event_fifo_id++, userdata, event_type});
    std::push_heap(s_event_queue.begin(), s_event_queue.end(), std::greater<Event>());
  }
  else
  {
    if (Core::WantsDeterminism())
    {
      ERROR_LOG(POWERPC,
                "Someone scheduled an off-thread \"%s\" event while netplay or "
                "movie play/record was active.  This is likely to cause a desync.",
                event_type->name->c_str());
    }

    std::lock_guard<std::mutex> lk(s_ts_write_lock);
    s_ts_queue.Push(Event{g.global_timer + cycles_into_future, 0, userdata, event_type});
  }
}
コード例 #10
0
ファイル: ScreenFader.cpp プロジェクト: kristofe/GameEngine
void ScreenFader::Update()
{
    if(!mActive)
        return;

    unsigned int elapsed = GetTicks() - mStartTime;
    float t = elapsed/(float)mDuration;
    mCurrentColor = Lerp(t,mStartColor,mEndColor);
    SetColor(mCurrentColor);

    if(elapsed >= mDuration)
    {

        GameMessage msg;
        msg.mEventName = "FINISHED";
        msg.mSender = mID;
        SendOutMessage(msg);
    }

}
コード例 #11
0
ファイル: vsProfileLib.cpp プロジェクト: v3c70r/sph-fluids
// Constructor
// begin of a profile section
VSProfileLib::VSProfileLib(std::string name, bool profileGL) {

	int found;
	pTime w;
	sCurrLevel++;

#if VSPL_CLOCK == VSPL_WIN_HIGH_PERFORMANCE_COUNTER
	QueryPerformanceFrequency(&sFreq);
#endif

	GetTicks(&w);

	// create new level
	if (sCurrLevel == sTotalLevels) {

		sLevels[sCurrLevel].cursor = -1;
		createNewSection(name, w, profileGL);
		// store the size of the largest section name
		int aux = name.size() ;
		if (aux > sDisp)
			sDisp = aux;
		sTotalLevels++;
	}
	else {  	
		// search for name and parent
		found = searchSection(name);
		if (found != -1)
			updateSection(found, w);
		else {
			// create new section inside current level
			createNewSection(name, w, profileGL);
			// store the size of the largest section name
			// for report formatting purposes
			int aux = name.size() ;
			if (aux > sDisp)
				sDisp = aux;
		}
	}

}
コード例 #12
0
inline void Platform::update_time()
{
	/*
	u64 t;
	QueryPerformanceCounter((LARGE_INTEGER *) &t);
	f32 newTime = (f32) (((f64) t) / timer_freq);
	*/
	f32 f;
	i32 t;
	double ticks;

	ticks = GetTicks();
	t = ticks;
	//printf("update ticks %f, %d\n",ticks, t);
	f = ((f32) t) * 0.001f;
	
//	deviceState.timeStep = f - deviceState.time;
//	deviceState.time = f;
	
	deviceState.timeStep = ticks - deviceState.time;
	deviceState.time = ticks;

}
コード例 #13
0
void HangingLetterSign::SetChar(char c)
{
	mUseWindAnimation = false;
	IvVector3 pos;
	GetWorldPosition(pos);
	pos.x = (int) pos.x;
	pos.y = (int) pos.y;
	this->SetWorldPosition(pos);
	//LetterDisplay::SetChar(c);
	if(mLetterDisplay == NULL)
	{
		mLetterDisplay = new LetterDisplay(mFont);
		IvVector3 disp;
		//GetWorldPosition(disp);
		disp.z += 2.55f;
		disp.y -= 27;
		mLetterDisplay->Translate(disp);
		
		//Hack!  for letter "i" it is too sharp and thin
		if(c == 'I')
		{
			IvVector3 s(1.25f,1.0f,1.0f);
			mLetterDisplay->Scale(s);
		}
		this->AddChild(mLetterDisplay);

	}
	mPendingChar = c;
	mStartTime = GetTicks();
	int randTime =  (rand()/(float)RAND_MAX)*1000;
	mStartTime += randTime;
	//mLetterDisplay->SetChar(c);
	

	

}
コード例 #14
0
ファイル: ghost.cpp プロジェクト: svn2github/ghostplusplus
quint32 GetTime()
{
	return GetTicks( ) / 1000;
}
コード例 #15
0
ファイル: UI.c プロジェクト: Tomius/LittleFighter
static void Draw_skill_icons (SDL_Surface *screen, struct character *player) {
    SDL_Rect rect= {350 * scale, (top ? 0 : (practise ? ky - (double)kx/1920 * 150 : ky - (double)kx/1920 * 90))
                    , skill_icons[0][0]->w, skill_icons[0][0]->h
                   };
    if(!top && kyBottom > rect.y - 10*scale)
        kyBottom = rect.y - 10*scale;
    int i,j;
    for(j=0; j < (practise ? 2 : 1); j++) {
        for(i=0; i<skill_num; i++) {
            if(j == 0)
                BlitSurface(skill_bg, NULL, screen, &rect);
            BlitSurface(skill_icons[j][i], NULL, screen, &rect);
            // A Cooldownok kirajzolása
            if(j == 0) {
                int time = GetTicks();
                int percent = 0;
                bool available = false;
                bool current = false;
                switch (i) {
                case skill_a_melee:
                    if(player->act == a_walk)
                        available = true;
                    if(player->act == a_melee)
                        current = true;
                    if(player->melee.a_cd > time)
                        percent = ((player->melee.a_cd - time) * 100) / player->a_melee_cd;
                    break;
                case skill_s_melee:
                    if(player->act == a_walk || player->act == jump || player->act == air)
                        available = true;
                    if(player->act == s_melee)
                        current = true;
                    if(player->melee.s_cd > time)
                        percent = ((player->melee.s_cd - time) * 100) / player->s_melee_cd;
                    break;
                case skill_s_walk:
                    if( (player->act == a_walk || player->act == jump) && player->jump.second == false)
                        available = true;
                    if(player->act == s_walk)
                        current = true;
                    if(player->walk.cd > time)
                        percent = ((player->walk.cd - time) * 100) / player->s_walk_cd;
                    break;
                case skill_def:
                    if(player->act == a_walk || player->act == a_melee)
                        available = true;
                    if(player->act == def)
                        current = true;
                    if(player->def.cd > time)
                        percent = ((player->def.cd - time) * 100) / player->def_cd;
                    break;
                case skill_jump_attack1:
                    if(player->act == jump && player->jump.second == false)
                        available = true;
                    if(player->act == jump_attack)
                        current = true;
                    if(player->jump.cd1 > time)
                        percent = ((player->jump.cd1 - time) * 100) / player->jump_attack_cd;
                    break;
                case skill_jump_attack2:
                    if(player->act == jump && player->jump.second == false)
                        available = true;
                    if(player->act == jump_attack2)
                        current = true;
                    if(player->jump.cd2 > time)
                        percent = ((player->jump.cd2 - time) * 100) / player->jump_attack_cd;
                    break;
                case skill_counter:
                    if(player->act == a_walk || player->act == hit
                            || player->act == a_melee || player->act == ground)
                        available = true;
                    if(player->act == counter)
                        current = true;
                    if(player->counter.cd > time)
                        percent =  ((player->counter.cd - time) * 100) / player->counter_cd;
                    break;
                case skill_a_ranged:
                    if(player->act == a_walk)
                        available = true;
                    if(player->act == a_ranged)
                        current = true;
                    if(player->ranged.a_cd > time)
                        percent =  ((player->ranged.a_cd - time) * 100) / player->a_cast_cd;
                    break;
                case skill_s_ranged:
                    if(player->act == a_walk)
                        available = true;
                    if(player->act == s_ranged)
                        current = true;
                    if(player->ranged.s_cd > time)
                        percent =  ((player->ranged.s_cd - time) * 100) / player->s_cast_cd;
                    break;
                default:
                    break;
                }
                if(!available && !current)
                    boxRGBA(screen, rect.x, rect.y, rect.x + rect.w, rect.y + rect.h, 0, 0, 0, 125);
                if(percent != 0 && !current) { // A hátralévő cooldown kirajzolása
                    int w =skill_icons[j][i]->w, h = skill_icons[j][i]->h;
                    Sint16 x[7] = {w/2 + w*(100-percent)/24, w, w, 0, 0, w/2, w/2};
                    Sint16 y[7] = {0, 0, h, h, 0, 0, h/2};
                    int n;
                    if(percent > 87) {
                        n=7;
                    } else if(percent > 62) {
                        n=6;
                        y[1] = h*(88-percent)/25;
                    } else if(percent > 37) {
                        n=5;
                        x[2] = w*(percent-38)/25;
                    } else if(percent > 12) {
                        n=4;
                        y[3] = h*(percent-13)/25;
                    } else {
                        n=3;
                        x[4] = w*(13-percent)/24;
                    }
                    int k;
                    for(k=0; k<7; k++) {
                        x[k] += rect.x;
                        y[k] += rect.y;
                    }
                    filledPolygonRGBA(screen, (const Sint16*) (x + 7-n), (const Sint16*) (y + 7-n), n, 0, 0, 0, 125);
                }
                if(current)
                    BlitSurface(current_bg, NULL, screen, &rect);
            }
            rect.x += skill_icons[j][i]->w + 1;
        }
        rect.x = 350 * scale;
        rect.y += (int)((double)kx/1920 * 90);
    }
}
コード例 #16
0
double Timer::Get() const
{
	return (GetTicks() - m_offset)*m_timerUnit;
}
コード例 #17
0
void Timer::Reset()
{
	m_offset = GetTicks();
}
コード例 #18
0
ファイル: gameplayer.cpp プロジェクト: m-unkel/OHSystem
void CGamePlayer :: ProcessPackets( )
{
    if( !m_Socket )
        return;

    CIncomingAction *Action = NULL;
    CIncomingChatPlayer *ChatPlayer = NULL;
    CIncomingMapSize *MapSize = NULL;
    bool HasMap = false;
    uint32_t CheckSum = 0;
    uint32_t Pong = 0;

    // process all the received packets in the m_Packets queue

    while( !m_Packets.empty( ) )
    {
        CCommandPacket *Packet = m_Packets.front( );
        m_Packets.pop( );

        if( Packet->GetPacketType( ) == W3GS_HEADER_CONSTANT )
        {
            switch( Packet->GetID( ) )
            {
            case CGameProtocol :: W3GS_LEAVEGAME:
                m_Game->EventPlayerLeft( this, m_Protocol->RECEIVE_W3GS_LEAVEGAME( Packet->GetData( ) ) );
                break;

            case CGameProtocol :: W3GS_GAMELOADED_SELF:
                if( m_Protocol->RECEIVE_W3GS_GAMELOADED_SELF( Packet->GetData( ) ) )
                {
                    if( !m_FinishedLoading && m_Game->GetGameLoading( ) )
                    {
                        m_FinishedLoading = true;
                        m_FinishedLoadingTicks = GetTicks( );
                        m_Game->EventPlayerLoaded( this );
                    }
                    else
                    {
                        // we received two W3GS_GAMELOADED_SELF packets from this player!
                    }
                }

                break;

            case CGameProtocol :: W3GS_OUTGOING_ACTION:
                Action = m_Protocol->RECEIVE_W3GS_OUTGOING_ACTION( Packet->GetData( ), m_PID );

                if( Action )
                {
                    // don't delete Action here because the game is going to store it in a queue and delete it later
                    m_Game->EventPlayerAction( this, Action );
                }

                break;

            case CGameProtocol :: W3GS_OUTGOING_KEEPALIVE:
                CheckSum = m_Protocol->RECEIVE_W3GS_OUTGOING_KEEPALIVE( Packet->GetData( ) );
                m_CheckSums.push( CheckSum );
                ++m_SyncCounter;
                m_Game->EventPlayerKeepAlive( this, CheckSum );
                break;

            case CGameProtocol :: W3GS_CHAT_TO_HOST:
                ChatPlayer = m_Protocol->RECEIVE_W3GS_CHAT_TO_HOST( Packet->GetData( ) );

                if( ChatPlayer )
                {
                    // determine if we should auto-mute this player
                    if( ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGE || ChatPlayer->GetType( ) == CIncomingChatPlayer :: CTH_MESSAGEEXTRA )
                    {
                        if( m_Level <= 1 &&! GetMuted( ) )
                        {
                            m_MuteMessages.push_back( GetTicks( ) );

                            if( m_MuteMessages.size( ) > 7 )
                                m_MuteMessages.erase( m_MuteMessages.begin( ) );

                            uint32_t RecentCount = 0;
                            for( unsigned int i = 0; i < m_MuteMessages.size( ); ++i )
                            {
                                if( GetTicks( ) - m_MuteMessages[i] < 5000 )
                                {
                                    RecentCount++;
                                }
                            }

                            if( m_Game->m_OHBot->m_AutoMuteSpammer && RecentCount >= 7 )
                            {
                                m_Count++;
                                if(  m_Count == 1 )
                                {
                                    SetMuted( true );
                                    m_MutedAuto = true;
                                    m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->SpamWarning( ) );
                                    m_MuteMessages.clear( );
                                    m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "spamming" ) );
                                }
                                if( m_Count == 2 )
                                {
                                    m_Game->SendAllChat( m_Game->m_OHBot->m_Language->UserIgnoerNotify( m_Name ) );
                                    m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->SpamWarning2( ) );
                                    SetMuted( true );
                                    m_Game->m_Pairedpenps.push_back( Pairedpenp( string(), m_Game->m_OHBot->m_DB->Threadedpenp( m_Name, "Spam" , m_Game->m_OHBot->m_BotManagerName, 1, "add" ) ) );
                                    m_MutedAuto = true;
                                    m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "spamming" ) );
                                }
                                if( m_Count == 3 )
                                {
				    m_Game->BanPlayerByPenality( m_Name, GetExternalIPString( ), m_Game->m_OHBot->m_BotManagerName, m_PenalityLevel, "Spam" );
                                    SetMuted( true );
                                    m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "spamming" ) );

                                }
                            }

                            //we adding this condition not in the next condition to avoid a jump into ohbot.cpp to check if the message was a flame message or not
                            if(m_Game->m_OHBot->m_FlameCheck && ( m_Name != "dolan" || m_Name != "Dolan" ) )
                            {
                                //now check for flamers
                                if( m_Game->m_OHBot->FlameCheck( ChatPlayer->GetMessage( ) ) )
                                {
                                    m_FlameMessages.push_back( GetTicks( ) );

                                    if( m_FlameMessages.size( ) > 10 )
                                        m_FlameMessages.erase( m_FlameMessages.begin( ) );

                                    RecentCount = 0;

                                    for( unsigned int i = 0; i < m_FlameMessages.size( ); ++i )
                                    {
                                        if( GetTicks( ) - m_FlameMessages[i] < 60000 )
                                            RecentCount++;
                                    }

                                    if( RecentCount == 1 )
                                    {
                                        m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->FlameWarn ());
                                    }

                                    if( RecentCount == 2 )
                                    {
                                        m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->FlameWarn2 () );
                                        SetMuted( true );
                                        m_MutedAuto = true;
                                        m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "flaming" ) );
                                    }

                                    if( RecentCount == 3 )
                                    {
                                        m_Game->SendChat( m_PID, m_Game->m_OHBot->m_Language->FlameWarn3 () );
                                        SetMuted( true );
                                        m_Game->m_Pairedpenps.push_back( Pairedpenp( string(), m_Game->m_OHBot->m_DB->Threadedpenp( m_Name, "Flame/Insult" , m_Game->m_OHBot->m_BotManagerName, 1, "add" ) ) );
                                        m_MutedAuto = true;
                                        m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "flaming" ) );
                                    }

                                    if( RecentCount == 4 )
                                    {
					m_Game->BanPlayerByPenality( m_Name, GetExternalIPString( ), m_Game->m_OHBot->m_BotManagerName, m_PenalityLevel, "Flame/Insult" );
                                        SetMuted( true );
                                        m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "flaming" ) );

                                    }
                                    if( RecentCount == 5 )
                                    {
                                        //some people simple dont understand the ban policy.
                                        m_Game->BanPlayerByPenality( m_Name, GetExternalIPString( ), m_Game->m_OHBot->m_BotManagerName, m_PenalityLevel, "Flame/Insult" );
					SetMuted( true );
                                        m_Game->SendAllChat( "["+m_Game->m_OHBot->m_BotManagerName+"] " + m_Game->m_OHBot->m_Language->UserWasMutedForReason( m_Name, "flaming" ) );

                                    }
                                }
                            }
                        }
                    }
                    m_Game->EventPlayerChatToHost( this, ChatPlayer );
                }
                delete ChatPlayer;
                ChatPlayer = NULL;
                break;

            case CGameProtocol :: W3GS_DROPREQ:
                // todotodo: no idea what's in this packet

                if( !m_DropVote )
                {
                    m_DropVote = true;
                    m_Game->EventPlayerDropRequest( this );
                }

                break;

            case CGameProtocol :: W3GS_MAPSIZE:
                MapSize = m_Protocol->RECEIVE_W3GS_MAPSIZE( Packet->GetData( ), m_Game->m_OHBot->m_Map->GetMapSize( ) );

                if( MapSize )
                    m_Game->EventPlayerMapSize( this, MapSize );

                delete MapSize;
                MapSize = NULL;
                break;

            case CGameProtocol :: W3GS_PONG_TO_HOST:
                Pong = m_Protocol->RECEIVE_W3GS_PONG_TO_HOST( Packet->GetData( ) );

                // we discard pong values of 1
                // the client sends one of these when connecting plus we return 1 on error to kill two birds with one stone

                if( Pong != 1 )
                {
                    // we also discard pong values when we're downloading because they're almost certainly inaccurate
                    // this statement also gives the player a 5 second grace period after downloading the map to allow queued (i.e. delayed) ping packets to be ignored

                    if( !m_DownloadStarted || ( m_DownloadFinished && GetTime( ) - m_FinishedDownloadingTime >= 5 ) )
                    {
                        // we also discard pong values when anyone else is downloading if we're configured to

                        if( m_Game->m_OHBot->m_PingDuringDownloads || !m_Game->IsDownloading( ) )
                        {
                            m_Pings.push_back( GetTicks( ) - Pong );

                            if( m_Pings.size( ) > 20 )
                                m_Pings.erase( m_Pings.begin( ) );
                        }
                    }
                }

                m_Game->EventPlayerPongToHost( this, Pong );
                break;
            }
        }
        else if( Packet->GetPacketType( ) == GPS_HEADER_CONSTANT )
        {
            BYTEARRAY Data = Packet->GetData( );

            if( Packet->GetID( ) == CGPSProtocol :: GPS_INIT )
            {
                if( m_Game->m_OHBot->IsMode( BOT_MODE_GPROXY ) )
                {
                    m_GProxy = true;
                    m_Socket->PutBytes( m_Game->m_OHBot->m_GPSProtocol->SEND_GPSS_INIT( m_Game->m_OHBot->m_ReconnectPort, m_PID, m_GProxyReconnectKey, m_Game->GetGProxyEmptyActions( ) ) );
                    //Log->Info( "[GAME: " + m_Game->GetGameName( ) + "] player [" + m_Name + "] is using GProxy++" );
                }
                else
                {
                    // todotodo: send notice that we're not permitting reconnects
                    // note: GProxy++ should never send a GPS_INIT message if bot_reconnect = 0 because we don't advertise the game with invalid map dimensions
                    // but it would be nice to cover this case anyway
                }
            }
            else if( Packet->GetID( ) == CGPSProtocol :: GPS_RECONNECT )
            {
                // this is handled in ohbot.cpp
            }
            else if( Packet->GetID( ) == CGPSProtocol :: GPS_ACK && Data.size( ) == 8 )
            {
                uint32_t LastPacket = UTIL_ByteArrayToUInt32( Data, false, 4 );
                uint32_t PacketsAlreadyUnqueued = m_TotalPacketsSent - m_GProxyBuffer.size( );

                if( LastPacket > PacketsAlreadyUnqueued )
                {
                    uint32_t PacketsToUnqueue = LastPacket - PacketsAlreadyUnqueued;

                    if( PacketsToUnqueue > m_GProxyBuffer.size( ) )
                        PacketsToUnqueue = m_GProxyBuffer.size( );

                    while( PacketsToUnqueue > 0 )
                    {
                        m_GProxyBuffer.pop( );
                        --PacketsToUnqueue;
                    }
                }
            }
        }

        delete Packet;
    }
}
コード例 #19
0
ファイル: gameplayer.cpp プロジェクト: m-unkel/OHSystem
bool CGamePlayer :: Update( void *fd )
{
    // wait 4 seconds after joining before sending the /whois or /w
    // if we send the /whois too early battle.net may not have caught up with where the player is and return erroneous results

    if( m_WhoisShouldBeSent && !m_Spoofed && !m_WhoisSent && !m_JoinedRealm.empty( ) && GetTime( ) - m_JoinTime >= 4 )
    {
        // todotodo: we could get kicked from battle.net for sending a command with invalid characters, do some basic checking

        for( vector<CBNET *> :: iterator i = m_Game->m_OHBot->m_BNETs.begin( ); i != m_Game->m_OHBot->m_BNETs.end( ); ++i )
        {
            if( (*i)->GetServer( ) == m_JoinedRealm )
            {
                if( m_Game->GetGameState( ) == GAME_PUBLIC )
                {
                    if( (*i)->GetPasswordHashType( ) == "pvpgn" )
                        (*i)->QueueChatCommand( "/whereis " + m_Name );
                    else
                        (*i)->QueueChatCommand( "/whois " + m_Name );
                }
                else if( m_Game->GetGameState( ) == GAME_PRIVATE )
                    (*i)->QueueChatCommand( m_Game->m_OHBot->m_Language->SpoofCheckByReplying( ), m_Name, true );
            }
        }

        m_WhoisSent = true;
    }

    // check for socket timeouts
    // if we don't receive anything from a player for 30 seconds we can assume they've dropped
    // this works because in the lobby we send pings every 5 seconds and expect a response to each one
    // and in the game the Warcraft 3 client sends keepalives frequently (at least once per second it looks like)

    if( m_Socket && GetTime( ) - m_Socket->GetLastRecv( ) >= 30 )
        m_Game->EventPlayerDisconnectTimedOut( this );

    // make sure we're not waiting too long for the first MAPSIZE packet

    /*    	if( m_ConnectionState == 1 && GetTicks( ) - m_ConnectionTime > 5000 && !m_Game->GetGameLoaded() && !m_Game->GetGameLoading() )
        {
            Log->Info( "[DENY] Kicking player: MAPSIZE not received within five seconds" );
            m_DeleteMe = true;
                SetLeftReason( "MAPSIZE not received within five seconds" );
                SetLeftCode( PLAYERLEAVE_LOBBY );
                m_Game->OpenSlot( m_Game->GetSIDFromPID( GetPID( ) ), false );
            }
    */
    // disconnect if the player is downloading too slowly

    // make this a bit dynamically, first 10 KB/s is a bit too low, increasing to 100KB/s
    //decreasing the checktime to 5 seconds
    // adding an actual playercheck how many players are ingame, if there less than 1 open slots we deny users with a download rate under 500KB/s
    if( m_DownloadStarted && !m_DownloadFinished && !m_Game->GetGameLoaded() && !m_Game->GetGameLoading() && GetLastMapPartSent( ) > 0 && m_Game->m_OHBot->m_KickSlowDownloader )
    {
        uint32_t downloadingTime = GetTicks( ) - m_StartedDownloadingTicks;

        if( downloadingTime > 5000 && m_Level < 1)
        {
            if( GetLastMapPartAcked( ) / downloadingTime < 500 && m_Game->GetSlotsOccupied( ) <= 1 )
            {
                m_DeleteMe = true;
                SetLeftReason( "download speed too low" );
                SetLeftCode( PLAYERLEAVE_LOBBY );
                m_Game->SendAllChat( m_Game->m_OHBot->m_Language->UserWasKickedForSlowDownloadRate( m_Name ) );
                m_Game->OpenSlot( m_Game->GetSIDFromPID( GetPID( ) ), false );
            }
            else if( GetLastMapPartAcked( ) / downloadingTime < 100 )
            {
                m_DeleteMe = true;
                SetLeftReason( "download speed too low" );
                SetLeftCode( PLAYERLEAVE_LOBBY );
                m_Game->SendAllChat( m_Game->m_OHBot->m_Language->UserWasKickedForSlowDownloadRate( m_Name ) );
                m_Game->OpenSlot( m_Game->GetSIDFromPID( GetPID( ) ), false );
            }
        }
    }

    // unmute player
    if( GetMuted( ) && m_MutedAuto && GetTicks( ) - m_MutedTicks > 30000  )
    {
        SetMuted( false );
        m_Game->SendChat( m_PID, "["+m_Game->m_OHBot->m_BotManagerName+"] "+m_Game->m_OHBot->m_Language->UserWasAutomaticallyUnmuted( ) );
        m_MuteMessages.clear( );
    }

    // GProxy++ acks

    if( m_Game->m_OHBot->IsMode( BOT_MODE_GPROXY ) && m_GProxy && GetTime( ) - m_LastGProxyAckTime >= 10 )
    {
        if( m_Socket )
            m_Socket->PutBytes( m_Game->m_OHBot->m_GPSProtocol->SEND_GPSS_ACK( m_TotalPacketsReceived ) );

        m_LastGProxyAckTime = GetTime( );
    }

    // base class update

    CPotentialPlayer :: Update( fd );
    bool Deleting;

    if( m_GProxy && m_Game->GetGameLoaded( ) )
        Deleting = m_DeleteMe || m_Error;
    else
        Deleting = m_DeleteMe || m_Error || m_Socket->HasError( ) || !m_Socket->GetConnected( );

    // try to find out why we're requesting deletion
    // in cases other than the ones covered here m_LeftReason should have been set when m_DeleteMe was set

    if( m_Error )
    {
        m_Game->EventPlayerDisconnectPlayerError( this );
        m_Socket->Reset( );
        return Deleting;
    }

    if( m_Socket )
    {
        if( m_Socket->HasError( ) )
        {
            m_Game->EventPlayerDisconnectSocketError( this );
            m_Socket->Reset( );
        }
        else if( !m_Socket->GetConnected( ) )
        {
            m_Game->EventPlayerDisconnectConnectionClosed( this );
            m_Socket->Reset( );
        }
    }

    return Deleting;
}
コード例 #20
0
ファイル: midi.cpp プロジェクト: henriknil/dosbox
void MIDI_RawOutByte(Bit8u data) {
	if (midi.sysex.start) {
		Bit32u passed_ticks = GetTicks() - midi.sysex.start;
		if (passed_ticks < midi.sysex.delay) SDL_Delay(midi.sysex.delay - passed_ticks);
	}

	/* Test for a realtime MIDI message */
	if (data>=0xf8) {
		midi.rt_buf[0]=data;
		midi.handler->PlayMsg(midi.rt_buf);
		return;
	}
	/* Test for a active sysex tranfer */
	if (midi.status==0xf0) {
		if (!(data&0x80)) {
			if (midi.sysex.used<(SYSEX_SIZE-1)) midi.sysex.buf[midi.sysex.used++] = data;
			return;
		} else {
			midi.sysex.buf[midi.sysex.used++] = 0xf7;

			if ((midi.sysex.start) && (midi.sysex.used >= 4) && (midi.sysex.used <= 9) && (midi.sysex.buf[1] == 0x41) && (midi.sysex.buf[3] == 0x16)) {
				LOG(LOG_ALL,LOG_ERROR)("MIDI:Skipping invalid MT-32 SysEx midi message (too short to contain a checksum)");
			} else {
//				LOG(LOG_ALL,LOG_NORMAL)("Play sysex; address:%02X %02X %02X, length:%4d, delay:%3d", midi.sysex.buf[5], midi.sysex.buf[6], midi.sysex.buf[7], midi.sysex.used, midi.sysex.delay);
				midi.handler->PlaySysex(midi.sysex.buf, midi.sysex.used);
				if (midi.sysex.start) {
					if (midi.sysex.buf[5] == 0x7F) {
						midi.sysex.delay = 290; // All Parameters reset
					} else if (midi.sysex.buf[5] == 0x10 && midi.sysex.buf[6] == 0x00 && midi.sysex.buf[7] == 0x04) {
						midi.sysex.delay = 145; // Viking Child
					} else if (midi.sysex.buf[5] == 0x10 && midi.sysex.buf[6] == 0x00 && midi.sysex.buf[7] == 0x01) {
						midi.sysex.delay = 30; // Dark Sun 1
					} else midi.sysex.delay = (Bitu)(((float)(midi.sysex.used) * 1.25f) * 1000.0f / 3125.0f) + 2;
					midi.sysex.start = GetTicks();
				}
			}

			LOG(LOG_ALL,LOG_NORMAL)("Sysex message size %d",midi.sysex.used);
			if (CaptureState & CAPTURE_MIDI) {
				CAPTURE_AddMidi( true, midi.sysex.used-1, &midi.sysex.buf[1]);
			}
		}
	}
	if (data&0x80) {
		midi.status=data;
		midi.cmd_pos=0;
		midi.cmd_len=MIDI_evt_len[data];
		if (midi.status==0xf0) {
			midi.sysex.buf[0]=0xf0;
			midi.sysex.used=1;
		}
	}
	if (midi.cmd_len) {
		midi.cmd_buf[midi.cmd_pos++]=data;
		if (midi.cmd_pos >= midi.cmd_len) {
			if (CaptureState & CAPTURE_MIDI) {
				CAPTURE_AddMidi(false, midi.cmd_len, midi.cmd_buf);
			}
			midi.handler->PlayMsg(midi.cmd_buf);
			midi.cmd_pos=1;		//Use Running status
		}
	}
}
コード例 #21
0
ファイル: ghostdb.cpp プロジェクト: Artyom91/OHBot
void CBaseCallable :: Init( )
{
	m_StartTicks = GetTicks( );
}
コード例 #22
0
ファイル: GameWorld.cpp プロジェクト: blchinezu/EZX-Projects
//Loads a Level
void GameWorld::LoadLevel()
{
	string file;
	sprintf((char*)file.c_str(), "maps/%s%i.mrl", m_levelname.c_str(), m_level);

	//Load Data
	int id;
	int e;
	char p[256];
	int bi=0; //butterfly id

	//Clear the background of any decals
	SDL_BlitSurface(gConMgr.GetSurface("sprites/grid.fif"), 0, m_surf_background, &renderarea);

	//Reset Player Anim State
	m_players[0].ResetAnim();

	//Clear level data
    for(int y = 0; y < 11; y++)
    {
		for(int x = 0; x < 17; x++)
		{
			m_gamegrid[x][y].ent = NULL;
		}
    }

	//Reset some data
	memset(&m_description, 0x00, sizeof(m_description));
	for(int i = 0; i < MAX_CELLS; i++){m_mushrooms[i].SetVisible(0);}
	m_totalmushrooms = 0;
	m_totalboxes = 0;
	m_totalbutterflys = 0;
	m_totalhats = 0;
	m_totalwells = 0;
	m_well[0].SetVisible(0);
	m_hat[0].SetVisible(0);

	//If level doesnt exist:
	FILE* ec = fopen((char*)file.c_str(), "r");
	if(ec != NULL){fclose(ec);}else
	{
		//It doesnt exist
		gGameWorld.gScores.AddScore(m_players[0].GetScore(), gGameWorld.GetLevel(), m_players[0].GetLife());
		gGameWorld.gScores.m_enabled = 1;
		gGameWorld.gMenu.m_selected = 2;
		gGameWorld.gMenu.m_enabled = 1;
		return;
	}


	//Decrypt
	XorCrypt((char*)file.c_str(), "temp.dat", 471);

	//Open Map File
	char out[32];
	FILE* open = fopen("temp.dat", "r");
	if(open != NULL)
	{
		for(int x = 0; x < 17; x++)
		{
			for(int y = 0; y < 11; y++)
			{
				fscanf(open, "%s", out);
				id = atoi(out);

				if(id == 9)
				{
					fscanf(open, "%s", out);
					e = atoi(out);
				}

				if(id == 2)
				{
					memset(&p, 0x00, sizeof(p));
					fscanf(open, "%s", p);
				}

				//Add object to the game
				if(id == 0){AddBoxX(x, y, 1);}
				if(id == 1){AddBoxX(x, y, 0);}
				if(id == 2){AddButterflyX(x, y, p, bi); bi++;}

				if(id == 3)
				{
					m_gamegrid[x][y].ent = &m_players[0];
					m_players[0].SetPos(x, y);
				}

				if(id == 4){AddWellX(x, y);} // well
				if(id == 5){AddMushroomX(x, y, MUSHROOM_BLACK);}
				if(id == 6){AddMushroomX(x, y, MUSHROOM_RED);}
				if(id == 7){AddMushroomX(x, y, MUSHROOM_PINK);}
				if(id == 8){AddMushroomX(x, y, MUSHROOM_PURPLE);}
				if(id == 9){Vector2D tp; tp.Set(x, y); AddBlueBonus(tp, e);}
				if(id == 10){AddHatX(x, y, 4);} // mexican hat
				if(id == 11){AddHatX(x, y, 3);} // fez hat
				if(id == 12){AddHatX(x, y, 2);} // diving hat
				if(id == 13){AddHatX(x, y, 5);} // nightcap
				if(id == 14){AddHatX(x, y, 6);} // skullcap
				if(id == 15){AddHatX(x, y, 1);} // dunce hat
			}
		}

		//Load Description
		fscanf(open, "%s", m_description);
		for(int i = 0; i < sizeof(m_description); i++){if(m_description[i] == '^'){m_description[i] = ' ';}}

		//Break description down into lines
		memset(&line1, 0x00, sizeof(line1));
		memset(&line2, 0x00, sizeof(line2));
		memset(&line3, 0x00, sizeof(line3));
		memset(&line4, 0x00, sizeof(line4));
		memset(&line5, 0x00, sizeof(line5));

		int line=0;
		int lc=0;
		int lsp=0; //last space pos
		int lcsp=0;
		for(int i = 0; i < strlen(m_description); i++)
		{
			if(m_description[i] ==  ' '){lsp = i; lcsp = lc;}

			if(line == 0){line1[lc] = m_description[i];}
			if(line == 1){line2[lc] = m_description[i];}
			if(line == 2){line3[lc] = m_description[i];}
			if(line == 3){line4[lc] = m_description[i];}
			if(line == 4){line5[lc] = m_description[i];}
			
			lc++;
			
			if(lc >= 36)
			{
				i = lsp;
				if(line == 0){line1[lcsp] = 0x00;}
				if(line == 1){line2[lcsp] = 0x00;}
				if(line == 2){line3[lcsp] = 0x00;}
				if(line == 3){line4[lcsp] = 0x00;}
				if(line == 4){line5[lcsp] = 0x00;}

				line++;
				lsp=0;
				lc=0;
			}
			
			if(line > 5){break;}
		}

		fclose(open);
	}

	//Delete Temp
	ClearFile("temp.dat");

	//Get Ready!!
	if(firstgen == 0)
	{
		m_readyreg = GetTicks();
		m_ready = 0;
	}else{firstgen=0;}

	m_beginscore = m_players[0].GetScore();

	m_gamemode = 1;
}
コード例 #23
0
extern int main(int argc, char **argv)
 {
	//Variable Declaration
	pthread_t pthreads[640];
	int threadID[640];
	int i=0; 
	int j=0;
	int rtn=0;
	ULONGLONG startTicks = 0;

	/* Variables to capture the file name and the file pointer*/
    char fileName[MAX_PATH];
    FILE *hFile;
    struct statistics* buffer;
    int statisticsSize = 0;

	/*Variable to Captutre Information at the Application Level*/
	struct applicationStatistics appStats;
	char mainFileName[MAX_PATH];
    FILE *hMainFile;

	//Get perfCallibrationValue 

	callibrationValue = getPerfCallibrationValue();
	printf("Callibration Value for this Platform %llu \n", callibrationValue);


	//Get Parameters
	if(GetParameters(argc, argv))
    {
     printf("Error in obtaining the parameters\n");
	 exit(-1);	
    }

	//Assign Values to Application Statistics Members
	appStats.relationId=RELATION_ID;
	appStats.operationTime=0;
	appStats.buildNumber = "999.99";
	appStats.processCount = USE_PROCESS_COUNT;
	appStats.threadCount = THREAD_COUNT;
	appStats.repeatCount = REPEAT_COUNT;

	printf("RELATION ID : %d\n", appStats.relationId);
	printf("Process Count : %d\n", appStats.processCount);
	printf("Thread Count : %d\n", appStats.threadCount);
	printf("Repeat Count : %d\n", appStats.repeatCount);


	//Open file for Application Statistics Collection 
	snprintf(mainFileName, MAX_PATH, "main_nativecriticalsection_%d_.txt",appStats.relationId);
	hMainFile = fopen(mainFileName, "w+");

	if(hMainFile == NULL)
	{ 
	    printf("Error in opening main file for write\n");
	}


	for (i=0;i<THREAD_COUNT;i++)
		{
			threadID[i] = i;
		}
	
	statisticsSize = sizeof(struct statistics);

	snprintf(fileName, MAX_PATH, "%d_thread_nativecriticalsection_%d_.txt", USE_PROCESS_COUNT, RELATION_ID);
	hFile = fopen(fileName, "w+");

	if(hFile == NULL)
	{ 
	    printf("Error in opening file for write for process [%d]\n", USE_PROCESS_COUNT);
	}


	// For each thread we will log operations failed (int), passed (int), total (int)
	// and number of ticks (DWORD) for the operations
	resultBuffer = new ResultBuffer( THREAD_COUNT, statisticsSize);

	//Call Test Case Setup Routine
	if (0!=setuptest())
	{
		//Error Condition
		printf("Error Initializing Test Case\n");
		exit(-1);
	}

	//Accquire Lock
    if (0!=pthread_mutex_lock(&g_mutex))
    {
       	//Error Condition
		printf("Error Accquiring Lock\n");
		exit(-1);
    }

	//USE NATIVE METHOD TO GET TICK COUNT
	startTicks = GetTicks();	
	
	/*Loop to create number THREAD_COUNT number of threads*/
	for (i=0;i< THREAD_COUNT;i++)
	{
		
		//printf("Creating Thread Count %d\n", i);
		//printf("Thread arrary value = %d\n", threadID[i]);
		rtn=pthread_create(&pthreads[i], NULL, waitforworkerthreads, &threadID[i]);
		if (0 != rtn)
			{ /* ERROR Condition */
				printf("Error:  pthread Creat, %s \n", strerror(rtn));
				exit(-1);
			}
		
	}

	
	//printf("Main Thread waits to recevie signal when all threads are done\n");
	pthread_cond_wait(&g_cv2,&g_mutex);

	//printf("Main thread has received signal\n");

	/*Signal Threads to Start Working*/
	//printf("Raise signal for all threads to start working\n");



	if (0!=pthread_cond_broadcast(&g_cv))
		{
			//Error Condition
			printf("Error Broadcasting Conditional Event\n");
			exit(-1);
		}
	
	//Release the lock
	if (0!=pthread_mutex_unlock(&g_mutex))
		{
			//Error Condition
			printf("Error Releasing Lock\n");
			exit(-1);
		}

	/*Join Threads */
	while (j < THREAD_COUNT)
	{
		if (0 != pthread_join(pthreads[j],NULL))
			{
				//Error Condition
				printf("Error Joining Threads\n");
				exit(-1);
			}
		j++;
	}


   /*Write Application Results to File*/
   //CAPTURE NATIVE TICK COUNT HERE
   appStats.operationTime = (DWORD)(GetTicks() - startTicks)/callibrationValue;
   

	/* Write Results to a file*/
    if(hFile!= NULL)
    { 
        for( i = 0; i < THREAD_COUNT; i++ )
        {  
            buffer = (struct statistics *)resultBuffer->getResultBuffer(i);
            fprintf(hFile, "%d,%d,%d,%d,%lu,%d\n", buffer->processId, buffer->operationsFailed, buffer->operationsPassed, buffer->operationsTotal, buffer->operationTime, buffer->relationId );
            //printf("Iteration %d over\n", i);
        }
    }
    fclose(hFile);

	

	//Call Test Case Cleanup Routine
	if (0!=cleanuptest())
		{
			//Error Condition
			printf("Error Cleaning up Test Case");
			exit(-1);
		}


   if(hMainFile!= NULL)
    { 
        printf("Writing to Main File \n");    
		fprintf(hMainFile, "%lu,%d,%d,%d,%d,%s\n", appStats.operationTime, appStats.relationId, appStats.processCount, appStats.threadCount, appStats.repeatCount, appStats.buildNumber);
		
    }
    fclose(hMainFile);
	return 0;
 }
コード例 #24
0
ファイル: gameplayer.cpp プロジェクト: 4RtY/ghostpp
void CGamePlayer :: ProcessPackets( )
{
	if( !m_Socket )
		return;

	CIncomingAction *Action = NULL;
	CIncomingChatPlayer *ChatPlayer = NULL;
	CIncomingMapSize *MapSize = NULL;
	bool HasMap = false;
	uint32_t CheckSum = 0;
	uint32_t Pong = 0;

	// process all the received packets in the m_Packets queue

	while( !m_Packets.empty( ) )
	{
		CCommandPacket *Packet = m_Packets.front( );
		m_Packets.pop( );

		if( Packet->GetPacketType( ) == W3GS_HEADER_CONSTANT )
		{
			switch( Packet->GetID( ) )
			{
			case CGameProtocol :: W3GS_LEAVEGAME:
				m_Game->EventPlayerLeft( this, m_Protocol->RECEIVE_W3GS_LEAVEGAME( Packet->GetData( ) ) );
				break;

			case CGameProtocol :: W3GS_GAMELOADED_SELF:
				if( m_Protocol->RECEIVE_W3GS_GAMELOADED_SELF( Packet->GetData( ) ) )
				{
					if( !m_FinishedLoading && m_Game->GetGameLoading( ) )
					{
						m_FinishedLoading = true;
						m_FinishedLoadingTicks = GetTicks( );
						m_Game->EventPlayerLoaded( this );
					}
					else
					{
						// we received two W3GS_GAMELOADED_SELF packets from this player!
					}
				}

				break;

			case CGameProtocol :: W3GS_OUTGOING_ACTION:
				Action = m_Protocol->RECEIVE_W3GS_OUTGOING_ACTION( Packet->GetData( ), m_PID );

				if( Action )
				{
					// don't delete Action here because the game is going to store it in a queue and delete it later
					m_Game->EventPlayerAction( this, Action );
				}

				break;

			case CGameProtocol :: W3GS_OUTGOING_KEEPALIVE:
				CheckSum = m_Protocol->RECEIVE_W3GS_OUTGOING_KEEPALIVE( Packet->GetData( ) );
				m_CheckSums.push( CheckSum );
				++m_SyncCounter;
				m_Game->EventPlayerKeepAlive( this, CheckSum );
				break;

			case CGameProtocol :: W3GS_CHAT_TO_HOST:
				ChatPlayer = m_Protocol->RECEIVE_W3GS_CHAT_TO_HOST( Packet->GetData( ) );

				if( ChatPlayer )
					m_Game->EventPlayerChatToHost( this, ChatPlayer );

				delete ChatPlayer;
				ChatPlayer = NULL;
				break;

			case CGameProtocol :: W3GS_DROPREQ:
				// todotodo: no idea what's in this packet

				if( !m_DropVote )
				{
					m_DropVote = true;
					m_Game->EventPlayerDropRequest( this );
				}

				break;

			case CGameProtocol :: W3GS_MAPSIZE:
				MapSize = m_Protocol->RECEIVE_W3GS_MAPSIZE( Packet->GetData( ), m_Game->m_GHost->m_Map->GetMapSize( ) );

				if( MapSize )
					m_Game->EventPlayerMapSize( this, MapSize );

				delete MapSize;
				MapSize = NULL;
				break;

			case CGameProtocol :: W3GS_PONG_TO_HOST:
				Pong = m_Protocol->RECEIVE_W3GS_PONG_TO_HOST( Packet->GetData( ) );

				// we discard pong values of 1
				// the client sends one of these when connecting plus we return 1 on error to kill two birds with one stone

				if( Pong != 1 )
				{
					// we also discard pong values when we're downloading because they're almost certainly inaccurate
					// this statement also gives the player a 5 second grace period after downloading the map to allow queued (i.e. delayed) ping packets to be ignored

					if( !m_DownloadStarted || ( m_DownloadFinished && GetTime( ) - m_FinishedDownloadingTime >= 5 ) )
					{
						// we also discard pong values when anyone else is downloading if we're configured to

						if( m_Game->m_GHost->m_PingDuringDownloads || !m_Game->IsDownloading( ) )
						{
							m_Pings.push_back( GetTicks( ) - Pong );

							if( m_Pings.size( ) > 20 )
								m_Pings.erase( m_Pings.begin( ) );
						}
					}
				}

				m_Game->EventPlayerPongToHost( this, Pong );
				break;
			}
		}
		else if( Packet->GetPacketType( ) == GPS_HEADER_CONSTANT )
		{
			BYTEARRAY Data = Packet->GetData( );

			if( Packet->GetID( ) == CGPSProtocol :: GPS_INIT )
			{
				if( m_Game->m_GHost->m_Reconnect )
				{
					m_GProxy = true;
					m_Socket->PutBytes( m_Game->m_GHost->m_GPSProtocol->SEND_GPSS_INIT( m_Game->m_GHost->m_ReconnectPort, m_PID, m_GProxyReconnectKey, m_Game->GetGProxyEmptyActions( ) ) );
					CONSOLE_Print( "[GAME: " + m_Game->GetGameName( ) + "] player [" + m_Name + "] is using GProxy++" );
				}
				else
				{
					// todotodo: send notice that we're not permitting reconnects
					// note: GProxy++ should never send a GPS_INIT message if bot_reconnect = 0 because we don't advertise the game with invalid map dimensions
					// but it would be nice to cover this case anyway
				}
			}
			else if( Packet->GetID( ) == CGPSProtocol :: GPS_RECONNECT )
			{
				// this is handled in ghost.cpp
			}
			else if( Packet->GetID( ) == CGPSProtocol :: GPS_ACK && Data.size( ) == 8 )
			{
				uint32_t LastPacket = UTIL_ByteArrayToUInt32( Data, false, 4 );
				uint32_t PacketsAlreadyUnqueued = m_TotalPacketsSent - m_GProxyBuffer.size( );

				if( LastPacket > PacketsAlreadyUnqueued )
				{
					uint32_t PacketsToUnqueue = LastPacket - PacketsAlreadyUnqueued;

					if( PacketsToUnqueue > m_GProxyBuffer.size( ) )
						PacketsToUnqueue = m_GProxyBuffer.size( );

					while( PacketsToUnqueue > 0 )
					{
						m_GProxyBuffer.pop( );
						--PacketsToUnqueue;
					}
				}
			}
		}

		delete Packet;
	}
}
コード例 #25
0
ファイル: GameWorld.cpp プロジェクト: blchinezu/EZX-Projects
void GameWorld::Render()
{
	//Begin Game Screen (cherry cake image)
    if(gamestart == 0){sound.PlaySound("sounds/init.wav"); gamestart = GetTicks();}

	if(gamestart != -1)
	{
		SDL_BlitSurface(gConMgr.GetSurface("sprites/sban.fif"), 0, backbuffer, &renderarea);
		SDL_BlitSurface(backbuffer, 0, screen, &renderarea);

		SDL_Flip(screen);

		if(GetTicks() > gamestart+3000)
		{
			gamestart = -1;
		}

		return;
	}


    //Blit Background
	if(m_bonustype == 0 || m_bonustype == 1 || m_bonustype == 3){
		SDL_BlitSurface(m_surf_background, 0, backbuffer, &renderarea);}
	if(m_bonustype == 2){SDL_BlitSurface(m_surf_molebackground, 0, backbuffer, &renderarea);}


	//HUD Font
	gFont.DrawString(backbuffer, 8, 4, "Life:", FONT_NORMAL);
	sprintf(intc, "%i%%", m_players[0].GetLife());
	if(m_players[0].GetLife() >= 50){gFont.DrawString(backbuffer, 42, 4, intc, FONT_GREEN);}
	else{gFont.DrawString(backbuffer, 42, 4, intc, FONT_RED);}

	gFont.DrawString(backbuffer, 188, 4, "Score:", FONT_NORMAL);
	sprintf(intc, "%i", m_players[0].GetScore());
	gFont.DrawString(backbuffer, 234, 4, intc, FONT_BLUE);

	gFont.DrawString(backbuffer, 8, 224, "Level:", FONT_NORMAL);
	sprintf(intc, "%i", m_level);
	gFont.DrawString(backbuffer, 53, 224, intc, FONT_NORMAL);

    //Render Game Grid
    for(int y = 0; y < 11; y++)
    {
		for(int x = 0; x < 17; x++)
		{
			if(m_gamegrid[x][y].ent == NULL){continue;}
			m_gamegrid[x][y].ent->Render();
		}
    }

	//Draw get ready graphics
	if(m_isbonus == 0 && gMenu.m_enabled == 0)
	{
		if(m_ready == 0 && GetTicks() > m_readyreg+500 && GetTicks() < m_readyreg+(60*strlen(m_description))+1600)
		{
			if(m_description[0] != 0x00)
			{
				SDLE_FillRectAlpha(backbuffer, &renderarea, SDL_MapRGB(backbuffer->format, 0, 120, 230), 0.8f);
			}

			SDL_BlitSurface(m_surf_gr[0], 0, backbuffer, &SDLE_Rect(45, 100, m_surf_gr[0]->w, m_surf_gr[0]->h));

			if(m_description[0] != 0x00)
			{
				gFont.DrawString(backbuffer, 40, 140, line1, FONT_WHITE);
				gFont.DrawString(backbuffer, 40, 154, line2, FONT_WHITE);
				gFont.DrawString(backbuffer, 40, 166, line3, FONT_WHITE);
				gFont.DrawString(backbuffer, 40, 178, line4, FONT_WHITE);
				gFont.DrawString(backbuffer, 40, 192, line5, FONT_WHITE);
			}
		}

		if(m_ready == 0 && GetTicks() > m_readyreg+(60*strlen(m_description))+1600)
		{
			SDL_BlitSurface(m_surf_gr[1], 0, backbuffer, &SDLE_Rect(75, 90, m_surf_gr[1]->w, m_surf_gr[1]->h));
		}

		//Set game to ready!!
		if(m_ready == 0 && GetTicks() > m_readyreg+(60*strlen(m_description))+1900)
		{
			m_ready = 1;
			sound.PlaySound("sounds/go.wav");
		}
	}else{m_ready = 1; m_isbonus = 0;}

	//Effects!
	gEffects.RenderEffects();

	//Menu Stuff!
	if(gMenu.m_enabled == 1){gMenu.Render();}
	if(gScores.m_enabled == 1){gScores.Render();}


    //Blit and Flip'
	SDL_BlitSurface(backbuffer, 0, screen, &renderarea);
    SDL_Flip(screen);
}
コード例 #26
0
ファイル: core_timing.cpp プロジェクト: DaMan69/citra
u64 GetGlobalTimeUs() {
    return GetTicks() * 1000000 / BASE_CLOCK_RATE_ARM11;
}
コード例 #27
0
ファイル: GameWorld.cpp プロジェクト: blchinezu/EZX-Projects
//Generates a random level : NETWORK PLAY, WHEN THIS IS CALLED YOU JUST ASK THE HOST FOR A RESYNC
void GameWorld::GenerateRandomLevel()
{
	//Clear the background of any decals
	SDL_BlitSurface(gConMgr.GetSurface("sprites/grid.fif"), 0, m_surf_background, &renderarea);

	//Clear game grid (of all but the players)
	for(int y = 0; y < 11; y++)
    {
		for(int x = 0; x < 17; x++)
		{
			if(m_gamegrid[x][y].ent != NULL)
			{
				if(m_gamegrid[x][y].ent->m_ident != IDENT_MAN){m_gamegrid[x][y].ent = NULL;}
			}
		}
    }

	//Clear arrays
	for(int i = 0; i < MAX_CELLS; i++){m_mushrooms[i].SetVisible(0);}
	m_totalmushrooms = 0;
	m_totalboxes = 0;
	m_totalbutterflys = 0;
	m_totalhats = 0;
	m_totalwells = 0;
	m_well[0].SetVisible(0);
	m_hat[0].SetVisible(0);

	//Add Entities (If normal level)
	if(m_isbonus == 0) //Normal
	{
		//AddWell();
		AddBoxes(10, 50, 1);
		AddBoxes(3, 28, 0);
		AddMushrooms(2, 30, 1);
		AddMushrooms(2, 40, 2);
		AddMushrooms(0, 8, 3);
		AddMushrooms(0, 3, 4);
		for(int i = 0; i < qRand(0, 5); i++){AddButterfly(i);}
	}

	//Add Entities (If bonus level)
	if(m_isbonus == 1)
	{
		if(m_bonustype == 1) //Field of Red Mushrooms
		{
			AddMushrooms(10, 50, 1);
			AddEscapeMushroom(0, 0); //0,0 = Random Position
		}

		if(m_bonustype == 2) //Whack-a-Mole
		{
			//
			AddEscapeMushroom(8, 10); //Top Right Corner
		}
	}

	//Increment Level
	if(m_isbonus != 1){m_level++;}

	//Get Ready!!
	if(firstgen == 0)
	{
		m_readyreg = GetTicks();
		m_ready = 0;
	}else{firstgen=0;}
}
コード例 #28
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
* \brief Ring buffer management
* This function copies data from ring buffer to application buffer with a given length.
* \param pBuff          Usart Rx DMA ring buffer
* \param pDestination   Usart application buffer
* \param Len            Num of dat to copy from ring buffer
* \return function returns number of bytes read from ringbuffer
*
*/
static uint32_t RingBufferRead(RignBuffer_t *pBuff, uint8_t *pDestination, uint32_t Len)
{
	uint32_t EndAddrs = ((uint32_t)pBuff->pBuffer + pBuff->BuffSize);
	uint32_t UnreadCount = 0;
	uint32_t EnableRTS = 0;
	uint32_t TotalLen = 0;
	uint32_t TailAddrs, BytesLeft;

	/* If timeout has occurred then re calculate the unread number of bytes */
	if (dmaflush) {
		mutexTimeout = 0x7FF;
		BASE_USART->US_CR = US_CR_RTSEN;            // disable transmission
		__disable_irq();
		while (LockMutex(semaphore, mutexTimeout));           // lock mutex
		_UpdateCount();
		/* If Circular buffer has still free space to fill */
		if (pBuff->Count < MAX_FREE_BYTES)
			EnableRTS = US_CR_RTSDIS;
		dmaflush = 0;
		memory_sync();
		ReleaseMutex(semaphore);
		BASE_USART->US_CR = EnableRTS;
		__enable_irq();
	}

	/* If there are unread bytes in ringbuffer then copy them to application
		buffer */
	if (pBuff->Count) {
		UnreadCount = __LDREXW(&pBuff->Count);          // unread bytes count
		memory_barrier();
		TotalLen = (Len > UnreadCount) ? UnreadCount : Len;

		// if read length surpasses the ring buffer boundary, then loop over
		if ((pBuff->pTail + TotalLen) >= EndAddrs) {
			BytesLeft = (EndAddrs - pBuff->pTail);
			memcpy( pDestination , (uint32_t *)pBuff->pTail, BytesLeft );

			memcpy( (pDestination +(EndAddrs - pBuff->pTail)),
				(uint32_t *)(pBuff->pBuffer), TotalLen - BytesLeft);
			TailAddrs = ( (uint32_t)pBuff->pBuffer + (TotalLen - BytesLeft));
		} else {
			memcpy( pDestination , (uint32_t *)pBuff->pTail, TotalLen);
			TailAddrs = pBuff->pTail + TotalLen;
		}
		/* In this part function enable the RTS signal to stop all reception
		disable irq to enter in critical part gets a lock on semaphore
		updates Tail pointer and count of ring buffer
		check if RTS need to be disable to accept the data from host
		frees the semaphore and enable irq*/
		BASE_USART->US_CR = US_CR_RTSEN;            // disable transmission
		__disable_irq();
		mutexTimeout = 0x7FF;
		while (LockMutex(semaphore, mutexTimeout));  // lock mutex
		pBuff->pTail = TailAddrs;
		pBuff->Count -=TotalLen;                   // update count of ring buffer
		TotalbytesReceived +=TotalLen;
		memory_sync();
#ifdef FULL_DUPLEX
		TimeOutTimer = GetTicks();
#endif
		/* If Circular buffer is read completely */
		if (pUsartBuffer->Count < MAX_FREE_BYTES)
			EnableRTS = US_CR_RTSDIS;
		ReleaseMutex(semaphore);
		BASE_USART->US_CR = EnableRTS;
		__enable_irq();

		printf("\r Total bytes received 0x%x (%u)", \
			(unsigned)TotalbytesReceived, (unsigned)TotalbytesReceived);

		return TotalLen;      // return the number of bytes
	} else
		return 0;
}
コード例 #29
0
ファイル: ghostdb.cpp プロジェクト: Artyom91/OHBot
void CBaseCallable :: Close( )
{
	m_EndTicks = GetTicks( );
	m_Ready = true;
}
コード例 #30
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 *  \brief usart-hw-handshaking Application entry point..
 *
 *  Configures USART in hardware handshaking mode and
 *  Timer Counter 0 to generate an interrupt every second. Then, start the first
 *  transfer on the USART and wait in an endless loop.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main( void )
{
	char pbaud_time[8];
	uint32_t BytesRead, BytesToRead, baudrate, timeout, TxBytesLeft;
	uint8_t AppBufferRollOver = 0;
	uint8_t *pTxBuff;

	/* Disable watchdog*/
	WDT_Disable(WDT);

	printf("-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Enable I and D cache */
	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure USART pins*/
	PIO_Configure(pins, PIO_LISTSIZE(pins));

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	NVIC_SetPriority(XDMAC_IRQn , XDMA_NVIC_PRIO);


	printf("\n\rEnter required baudrate:");
	gets(pbaud_time);
	baudrate = (atoi(pbaud_time)) ? (atoi(pbaud_time)): 921600;
	printf("\n\rEnter required timeout (in microsec):");
	gets(pbaud_time);

	timeout = atoi(pbaud_time);
	if (timeout > 1000) {
		timeout /= 1000;
		timeout = ((timeout * baudrate) / 1000);
	} else {
		timeout = (timeout * baudrate) / 1000000;
	}
	timeout = (timeout) ? ((timeout > MAX_RX_TIMEOUT) ? MAX_RX_TIMEOUT : timeout) \
		: MAX_RX_TIMEOUT;
	printf("\n\r");
	/* Configure USART */
	_ConfigureUsart(baudrate, timeout);
	printf("\n\r");

	/*Enable Rx channel of USART */
	USARTD_EnableRxChannels(&Usartd, &UsartRx);

#ifdef FULL_DUPLEX
	/*Enable Tx channel of USART */
	USARTD_EnableTxChannels(&Usartd, &UsartTx);
#endif

	/* Start receiving data and start timer*/
	USARTD_RcvData(&Usartd);

	/*Initialize Ring buffer */
	pUsartBuffer = (RignBuffer_t *)malloc(sizeof(RignBuffer_t));
	_initCircularBuffer(pUsartBuffer);

	pTxBuff = &FirstAppBuff[0];

	TxBytesLeft = 0;

#ifdef USE_MD5_CHECK
	md5_init(&pms);
#endif //USE_MD5_CHECK

#ifdef FULL_DUPLEX
	printf( "\n\r-I- USART is in Full Duplex mode \n\r");
#else
	printf( "\n\r-I- USART is in Half Duplex mode \n\r");
#endif
	printf( "\n\r-I- Please send a file to serial port (USART0) \n\r");
	BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer

	while (1) {
#ifdef USE_MD5_CHECK
		if (DBG_IsRxReady()) {
			ch = DBG_GetChar();
			if (ch == 'm') {
				uint8_t i;
				md5_finish(&pms, md5);
				printf("\r\nmd5:");
				for (i = 0; i < sizeof(md5);i++)
					printf("%.2x",md5[i]);
				printf("\r\n");
				md5_init(&pms);
				TotalbytesReceived = 0;
			}
		}
#endif
		/* Check Application buffer (100 KB)overflow */
		if (((PingPongBufferFlag == 0) &&
			(pTxBuff+BytesToRead) >= &FirstAppBuff[APP_BUFFER]) ||
			(( PingPongBufferFlag == 1) && (pTxBuff+BytesToRead) >=
			&SecondAppBuff[APP_BUFFER])) {
			AppBufferRollOver = 1;
			// Roll over and start copying to the beginning of Application buffer to avoid errors
			if (PingPongBufferFlag)
				BytesToRead = (&SecondAppBuff[APP_BUFFER] - pTxBuff);
			else
				BytesToRead = (&FirstAppBuff[APP_BUFFER] - pTxBuff);
			memory_barrier();
		}
		/* Read ring buffer */
		BytesRead = RingBufferRead(pUsartBuffer, pTxBuff, BytesToRead);
		memory_sync();
		TxBytesLeft += BytesRead;       // number of bytes to send via USART Tx

#ifdef USE_MD5_CHECK
		if (BytesRead > 0)
			md5_append(&pms,pTxBuff,BytesRead);
#endif

		/* check if one of the application buffer is full and ready to send */
		if (AppBufferRollOver && (TxBytesLeft == APP_BUFFER)) {
			AppBufferRollOver = 0;
			TxBytesLeft = 0;
			BytesRead = 0;
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			while (!UsartTx.dmaProgress);
			if (PingPongBufferFlag) {
				PingPongBufferFlag = 0;
				pTxBuff = &FirstAppBuff[0];
			} else {
				PingPongBufferFlag = 1;
				pTxBuff = &SecondAppBuff[0];
			}
			memory_sync();
#ifdef FULL_DUPLEX
			USARTD_SendData(&Usartd);
#endif
		}
		/* otherwise keep storing in same application buffer from Rx DMA's ring
			buffer */
		else {
			BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
			pTxBuff += BytesRead;

#ifdef FULL_DUPLEX
			/* Check for Tx timeout, if there is timeout then send the bytes left
				(less than 100 KB) in application buffer */
			if ((GetDelayInTicks(TimeOutTimer, GetTicks()) == USART_TX_TIMEOUT)
				&& TxBytesLeft) {
				// wait for any eventual USART Tx in progress
				while (!UsartTx.dmaProgress);
				FlushTxBuffer(TxBytesLeft);
				TimeOutTimer = GetTicks();
				PingPongBufferFlag = 0;
				TxBytesLeft = 0;
				BytesRead = 0;
				BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer
				pTxBuff = &FirstAppBuff[0];
				_UpdateTxConfig((uint32_t)&FirstAppBuff[0], APP_BUFFER);
				TRACE_INFO_WP(" TX Tiemout \n\r");
			}
#endif
		}
	}
}