Exemplo n.º 1
0
CTimeValue gkTimer::GetAsyncTime() const
{
//	assert(m_pfnUpdate);		// call Init() before
	
	if(!m_pfnUpdate)		// call Init() before
		return CTimeValue();

	int64 llNow=(*m_pfnUpdate)();

	// can be done much better
	double fac=(double)CTimeValue::TIMEVALUE_PRECISION/(double)m_lTicksPerSec;

	return CTimeValue(int64(llNow*fac));
}
Exemplo n.º 2
0
// static
void CDownloadMgr::DbgList(
	IConsoleCmdArgs			*pInArgs)
{
	CDownloadMgr			*pDlm=static_cast<CGame*>(gEnv->pGame)->GetDownloadMgr();
	int						count=0;

	for (TResourceVector::iterator iter=pDlm->m_resources.begin(); iter!=pDlm->m_resources.end(); ++iter)
	{
		CDownloadableResourcePtr	pPtr=*iter;
		const char								*ss=CDownloadableResource::GetStateAsString(pPtr->m_state).c_str();

		float				timeElapsed=0.0f;
		if (!(pPtr->m_state&CDownloadableResource::k_notStarted))
		{
			if (pPtr->m_state&CDownloadableResource::k_dataAvailable)
			{
				timeElapsed=(pPtr->m_downloadFinished-pPtr->m_downloadStarted).GetSeconds();
			}
			else
			{
				timeElapsed=(CTimeValue(gEnv->pTimer->GetAsyncCurTime())-pPtr->m_downloadStarted).GetSeconds();
			}
		}

		CryLogAlways("Resource %d : %s : state %s    : content %d B / %d B (%.2f bytes/sec) (%.2f elapsed)",
			count,pPtr->m_descName.c_str(), ss, pPtr->m_bufferUsed-pPtr->m_contentOffset, pPtr->m_contentLength, pPtr->GetTransferRate(),timeElapsed);

		count++;
	}

	CryLogAlways("%d resources",count);
}
Exemplo n.º 3
0
int CTransportTcp::Open_t()
{
	int nSize = 65535;
	if (m_SockTcp.SetOption(SOL_SOCKET, SO_SNDBUF, &nSize, sizeof(nSize)) == -1) {
		CM_ERROR_LOG(("CTransportTcp::Open_t, SetOption(SO_SNDBUF) failed!"));
		return -1;
	}
	if (m_SockTcp.SetOption(SOL_SOCKET, SO_RCVBUF, &nSize, sizeof(nSize)) == -1) {
		CM_ERROR_LOG(("CTransportTcp::Open_t, SetOption(SO_SNDBUF) failed!"));
		return -1;
	}

	int nNoDelay = 1;
	if (m_SockTcp.SetOption(IPPROTO_TCP, TCP_NODELAY, &nNoDelay, sizeof(nNoDelay)) == -1) {
		CM_ERROR_LOG(("CTransportTcp::Open_t, SetOption(TCP_NODELAY) failed!"));
		return -1;
	}

	// it works with Win32AsyncSelect and RealTimeSignal 
	// if we regiests READ_MASK & WRITE_MASK together at first
	if (m_pReactor->RegisterHandler(this, CEventHandlerBase::READ_MASK | CEventHandlerBase::WRITE_MASK) == -1) {
		CM_ERROR_LOG(("CTransportTcp::Open_t, RegisterHandler(READ_MASK|WRITE_MASK) failed!"));
		return -1;
	}
#ifdef EMBEDED_LINUX
	m_pReactor->ScheduleTimer(this, (LPVOID)1, CTimeValue(), 1);
#endif
	return 0;
}
Exemplo n.º 4
0
int CTransportDestoryEvent::PostEvent(ITransCon *aTransCon)
{
	CM_ASSERTE_RETURN(aTransCon, -1);

	CTransportDestoryEvent *pEvent = new CTransportDestoryEvent();
	pEvent->m_pTransCon = aTransCon;
	return CReactor::GetInstance()->ScheduleTimer(pEvent, NULL, CTimeValue(), 1);
}
Exemplo n.º 5
0
void CSPAnalyst::OnLoadingStart(ILevelInfo *pLevelInfo)
{
    if(pLevelInfo == 0)
        return;

    // in any case, reset the level start time, so it will either be restored from SaveGame or
    // set in eGE_GameStarted event handling
    m_gameAnalysis.levelStartTime = CTimeValue(0.0f);
    m_bChainLoad = false;
}
Exemplo n.º 6
0
// ----------------------------------------------------------------------------
void CAnimActionTriState::TransitionToNextSubState()
{
	switch( m_subState )
	{
	case eSS_Intro:
		{
			if ( !( m_triStateFlags & eTSF_SkipMiddle ) )
			{
				if ( !TrySetTransitionFragment( 0 ) )
				{
					m_triStateFlags |= eTSF_SkipMiddle;
				}
			}

			m_subState = eSS_Middle;
			m_middleEndTime = gEnv->pTimer->GetFrameStartTime() + CTimeValue(m_maxMiddleDuration);
			SendTriStateEvent( Middle );

			if ( !( m_triStateFlags & eTSF_SkipMiddle ) )
			{
				break;
			}

			// fall-through to Middle sequence finished
		}
	case eSS_Middle:
		{
			static uint32 outroCRC = CCrc32::ComputeLowercase( "outro" );
			const bool hasOutro = TrySetTransitionFragment( outroCRC );
			m_flags &= ~IAction::NoAutoBlendOut;

			m_subState = eSS_Outro;
			SendTriStateEvent( Outro );

			if ( hasOutro )
			{
				break;
			}

			// fall-through to Outro sequence finished
		}
	case eSS_Outro:
		{
			SendTriStateEvent( OutroEnd );
			TBase::Stop();
			break;
		}
	default:
		{
			CRY_ASSERT(false);
		}
	}
}
Exemplo n.º 7
0
void SReactionParams::SReactionAnim::RequestNextAnim(const IAnimationSet* pAnimSet) const
{
	CRY_ASSERT(pAnimSet);

	// If we are already waiting for a requested anim to load there's no need to request a new one
	if (m_requestedAnimCRC != 0)
		return;

	// Request loading of the next index
	const int iAnimCRCsSize = animCRCs.size();
	if (iAnimCRCsSize > 0)
	{
		int iIndexToRequest = 0;
		if (iAnimCRCsSize > 1)
		{
			if ((m_iNextAnimIndex + 1) >= iAnimCRCsSize)
			{
				// Randomly reshuffle animIDs vector
				// [*DavidR | 22/Sep/2010] Note: We are reusing the seed previously set on 
				// the random generator. Should be deterministic across the network.
				// This shuffling avoids playing the same animation twice in sequence
				SRandomGeneratorFunct randomFunctor(g_pGame->GetHitDeathReactionsSystem().GetRandomGenerator());
				std::random_shuffle(animCRCs.begin(), animCRCs.end() - 1, randomFunctor);
				std::iter_swap(animCRCs.begin(), animCRCs.end() - 1);

				m_iNextAnimIndex = 0;
			}

			iIndexToRequest = m_iNextAnimIndex + 1;
		}

		// Request reference
		if (g_pGame->GetHitDeathReactionsSystem().IsStreamingEnabled())
		{
			const int requestedAnimModelID = pAnimSet->GetAnimIDByCRC(animCRCs[iIndexToRequest]);
			const uint32 requestedAnimCRC = pAnimSet->GetFilePathCRCByAnimID(requestedAnimModelID);
			if (requestedAnimCRC != m_nextAnimCRC)
			{
				m_requestedAnimCRC = requestedAnimCRC;
				gEnv->pCharacterManager->CAF_AddRef(m_requestedAnimCRC);

				// Create a timer to poll when the asset ends streaming
				m_iTimerHandle = gEnv->pGame->GetIGameFramework()->AddTimer(CTimeValue(0.5f), false, functor(*this, &SReactionAnim::OnTimer), NULL);
			}
			else if (requestedAnimCRC != 0)
			{
				// Requested anim is the one we already have loaded. Immediate success :)
				m_iNextAnimIndex = iIndexToRequest;
			}
		}
	}
}
Exemplo n.º 8
0
void CStatsContainer::GetEventInfo(size_t eventID, size_t idx, CTimeValue& outTime, SStatAnyValue& outParam) const
{
	if(eventID < m_events.size() && idx < m_events[eventID].size())
	{
		outTime = m_events[eventID][idx].first;
		outParam = m_events[eventID][idx].second;
	}
	else
	{
		outTime = CTimeValue();
		outParam = SStatAnyValue();
	}
}
void CGameServerNub::BanPlayer(uint16 channelId, const char* reason)
{
	int userId = 0;
	int ip = 0;
	for(TNetServerChannelMap::const_iterator nit = m_netchannels.begin();nit!=m_netchannels.end();++nit)
		if(nit->second == channelId)
		{
			userId = nit->first->GetProfileId();
			nit->first->Disconnect(eDC_Kicked, reason);
			break;
		}
	int timeout = 30;
	if(ICVar* pV = gEnv->pConsole->GetCVar("ban_timeout"))
		timeout = pV->GetIVal();
	if(userId)
	{
		m_banned.push_back(SBannedPlayer(userId,0,gEnv->pTimer->GetFrameStartTime()+CTimeValue(timeout*60.0f)));
	}
	else if(ip)
	{
		m_banned.push_back(SBannedPlayer(0,ip,gEnv->pTimer->GetFrameStartTime()+CTimeValue(timeout*60.0f)));
	}
}
Exemplo n.º 10
0
void SReactionParams::SReactionAnim::OnTimer(void* pUserData, IGameFramework::TimerID handler) const
{
	CRY_ASSERT(g_pGame->GetHitDeathReactionsSystem().IsStreamingEnabled());
	CRY_ASSERT(m_requestedAnimCRC != 0);

	m_iTimerHandle = 0;

	UpdateRequestedAnimStatus();

	// If still is not loaded, wait 0.5 seconds for the next
	if (m_requestedAnimCRC != 0)
	{
		m_iTimerHandle = gEnv->pGame->GetIGameFramework()->AddTimer(CTimeValue(0.5f), false, functor(*this, &SReactionAnim::OnTimer), NULL);	
	}
}
Exemplo n.º 11
0
void CDownloadableResource::DebugWatchContents()
{
		const char *ss=CDownloadableResource::GetStateAsString(m_state).c_str();
		float				timeElapsed=0.0f;
		if (!(m_state&k_notStarted))
		{
			if (m_state&k_dataAvailable)
			{
				timeElapsed=(m_downloadFinished-m_downloadStarted).GetSeconds();
			}
			else
			{
				timeElapsed=(CTimeValue(gEnv->pTimer->GetAsyncCurTime())-m_downloadStarted).GetSeconds();
			}
		}
		CryWatch("Resource %s : state %s    : content %d B / %d B (%.2f bytes/sec) (elapsed %.2f sec)",
						 m_descName.c_str(), ss, m_bufferUsed-m_contentOffset, m_contentLength, GetTransferRate(),timeElapsed);
}
CTimeValue CMannequinAGExistanceQuery::GetAnimationLength() const
{
	return CTimeValue();
}
void CGameTokenSystem::DebugDraw()
{
	#ifdef _GAMETOKENSDEBUGINFO	

	static bool drawnLastFrame = false;
	float color[]={1.0f, 1.0f, 1.0f, 1.0f};

	if (CGameTokenSystem::m_CVarShowDebugInfo==0 || CGameTokenSystem::m_CVarShowDebugInfo==3)
	{
		drawnLastFrame = false;
		return;
	}
	
	if (!drawnLastFrame)
		ClearDebugHistory();
	
	drawnLastFrame = true;
	
	if (gEnv->pConsole->IsOpened())
		return;
	
	IRenderer * pRenderer = gEnv->pRenderer;
	if(!pRenderer)
		return;
	
	int linesDrawn = 0;
	
	{
		TDebugListMap::iterator iter = m_debugList.begin();
		int i = 0;
		while (iter != m_debugList.end())
		{
			CGameToken* pToken = GetToken( iter->c_str() );
			
			DrawToken( iter->c_str(), GetTokenDebugString( pToken ), pToken ? pToken->GetLastChangeTime() : CTimeValue(), i );
				
			++iter;
			++i;
		}
		linesDrawn = i;
	}
	
	{
		int numHistoryLines = GetHistoryBufferSize();
		if (numHistoryLines>0)
		{
			string buf;
			pRenderer->Draw2dLabel(20.0f+m_CVarPosX,20.0f+m_CVarPosY+12.0f*(float)linesDrawn, 1.2f, color, false, "---------------HISTORY----------------");
			linesDrawn++;
			for (int i=0; i<numHistoryLines; i++)
			{
				uint index = ( m_historyStart + i ) % numHistoryLines;
				SDebugHistoryEntry& entry = m_debugHistory[index];
				DrawToken( entry.tokenName, entry.value, entry.timeChanged, linesDrawn+i );
			}
		}
	}
	
	
	#endif
}