Exemplo n.º 1
0
void CGameStateRecorder::StartSession()
{
	m_GameStates.clear();
	m_itSingleActorGameState = m_GameStates.end();
	m_IgnoredEvents.clear();

	const char* filterName = m_demo_actorFilter->GetString();
	// send game events to record the initial game state
/*	if(m_mode)
	{
		CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
*/
		
	m_pSingleActor = GetActorOfName(filterName);
	if(m_pSingleActor)// && !pActor->GetSpectatorMode() && pActor->IsPlayer())
	{
		m_mode = GPM_SingleActor;
		AddActorToStats(m_pSingleActor);
		m_itSingleActorGameState = m_GameStates.begin();// position of requested actor's id (player by default)
	}
//	}
	else if (!strcmpi(filterName,"all"))
	{
		IAIObjectManager* pAIObjMgr = gEnv->pAISystem->GetAIObjectManager();

		m_mode = GPM_AllActors;
		{
			AutoAIObjectIter it(pAIObjMgr->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_ACTOR));
			for(; it->GetObject(); it->Next())
			{
				IAIObject* pObject = it->GetObject();
				if(pObject)
				{
					CActor* pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pObject->GetEntityID()));
					if(pActor)
						AddActorToStats(pActor);
				}
			}
		}
		
		{
			AutoAIObjectIter it(pAIObjMgr->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_VEHICLE));
			for(; it->GetObject(); it->Next())
			{
				IAIObject* pObject = it->GetObject();
				if(pObject)
				{
					CActor* pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pObject->GetEntityID()));
					if(pActor)
						AddActorToStats(pActor);
				}
			}
		}
	}
}
void CVisibleObjectsHelper::Update()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	const float fCurrTime = gEnv->pTimer->GetFrameStartTime().GetSeconds();
	IVisionMap& visionMap = *gEnv->pAISystem->GetVisionMap();

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	TActiveVisibleObjects activeVisibleObjects;
	activeVisibleObjects.reserve(m_VisibleObjects.size());

	TVisibleObjects::iterator itNext = m_VisibleObjects.begin();
	while (itNext != m_VisibleObjects.end())
	{
		TVisibleObjects::iterator itObject = itNext++;
		
		EntityId objectId = itObject->first;
		SVisibleObject &visibleObject = itObject->second;

		IEntity *pObject = pEntitySystem->GetEntity(objectId);
		if (pObject)
		{
			const bool bIsStillActive = (fCurrTime - visibleObject.fLastActiveTime <= 1.0f);
			const bool bPassesRule = (pObject && CheckVisibilityRule(pObject, visibleObject, fCurrTime));

			if (bPassesRule)
				visibleObject.fLastActiveTime = fCurrTime;
			visibleObject.bIsObservable = (bPassesRule || bIsStillActive);

			if (visibleObject.bIsObservable)
			{
				ObservableParams observableParams;
				observableParams.observablePositionsCount = 1;
				observableParams.observablePositions[0] = pObject->GetWorldPos();
				visionMap.ObservableChanged(visibleObject.visionId, observableParams, eChangedPosition);

				if (visibleObject.pFunc || eVOR_FlagNotifyOnSeen == (visibleObject.rule & eVOR_FlagNotifyOnSeen))
					activeVisibleObjects.push_back(&visibleObject);
			}
			else if (eVOR_FlagDropOnceInvisible == (visibleObject.rule & eVOR_FlagDropOnceInvisible))
			{
				// No longer visible, so kill it

				// TODO: Kevin, please take a look here and see if you're happy with how i unregister it /Jonas
				UnregisterVisibility(visibleObject);
				m_VisibleObjects.erase(itObject);
			}
		}
		else
		{
			// TODO: Kevin, please take a look here and see if you're happy with how i unregister it /Jonas
			UnregisterVisibility(visibleObject);
			m_VisibleObjects.erase(itObject);
		}
	}

	IAIObjectManager* pAIObjectManager = !activeVisibleObjects.empty() ? gEnv->pAISystem->GetAIObjectManager() : NULL;
	IAIObjectIter* pAIObjectIter = pAIObjectManager ? pAIObjectManager->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_ACTOR) : NULL;
	if (pAIObjectIter)
	{
		while (IAIObject *pAIObject = pAIObjectIter->GetObject())
		{
			Agent agent(pAIObject);
			if (agent.IsValid())
			{
				CheckVisibilityToAI(activeVisibleObjects, agent);
			}

			pAIObjectIter->Next();
		}

		pAIObjectIter->Release();
	}
}