void CPlayerStateSwim_WaterTestProxy::RayTestBottomLevel( const CPlayer& player, const Vec3& referencePosition, float maxRelevantDepth )
{
	FUNCTION_PROFILER(gEnv->pSystem, PROFILE_GAME);

	const float terrainWorldZ = gEnv->p3DEngine->GetTerrainElevation(referencePosition.x, referencePosition.y);

	int rayFlags = geom_colltype_player<<rwi_colltype_bit | rwi_stop_at_pierceable;
	int entityFlags = ent_terrain|ent_static|ent_sleeping_rigid|ent_rigid;
	const float padding = 0.2f;
	// NOTE: Terrain is above m_referencePos, so m_referencePos is probably inside a voxel or something.
	const float fPosWorldDiff = referencePosition.z - terrainWorldZ;
	float rayLength = (float)__fsel(fPosWorldDiff, min(maxRelevantDepth, fPosWorldDiff), maxRelevantDepth) + (padding * 2.0f);

	//We should not have entered this function if still waiting for the last result
	CRY_ASSERT(m_bottomLevelRayID == 0); 

	m_bottomLevelRayID = g_pGame->GetRayCaster().Queue(
		player.IsClient() ? RayCastRequest::HighPriority : RayCastRequest::MediumPriority,
		RayCastRequest(referencePosition + Vec3(0,0,padding), Vec3(0,0,-rayLength),
		entityFlags,
		rayFlags,
		0,
		0),
		functor(*this, &CPlayerStateSwim_WaterTestProxy::OnRayCastBottomLevelDataReceived));
}
/*static*/ void CHUDEventDispatcher::CallEvent( const SHUDEvent& event )
{
#if !defined(DEDICATED_SERVER)
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);
	CRY_ASSERT_MESSAGE(s_safe, "HUD: Can't send HUDEvent whilst initialising the HUD! i.e. from CHUDObject() or CHUDObject::Init()!" );
	if( s_safe )
	{
		s_stlSafe = false;
		THUDEventListeners& listeners = s_eventVec[event.eventType];
		THUDEventListeners::const_iterator it = listeners.begin();
		THUDEventListeners::const_iterator end = listeners.end();
		for(; it!=end; ++it)
		{
			IHUDEventListener* listener = *it;
			SOFTCODE_RETRY(listener, listener->OnHUDEvent(event));
		}
		s_stlSafe = true;
	}
	else
	{
		// HUD Event Sending is now unsafe and should not be done!
		// If you want to send HUD Events on initialization then use OnHUDLoadDone.
		return;
	}
#endif
}
void CPlayerStateSwim_WaterTestProxy::UpdateInWater(const CPlayer& player, const float frameTime)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	const Matrix34& playerWorldTM = player.GetEntity()->GetWorldTM();
	const Vec3 playerWorldPos = playerWorldTM.GetTranslation();

	const Vec3 localReferencePos = GetLocalReferencePosition(player);
	const Vec3 worldReferencePos = playerWorldPos + (Quat(playerWorldTM) * localReferencePos);

	const bool shouldUpdate  = 
		((gEnv->pTimer->GetCurrTime() - m_timeWaterLevelLastUpdated) > 0.3f ) || 
		((m_lastWaterLevelCheckPosition - playerWorldPos).len2() >= sqr(0.35f)) ||
			(m_lastInternalState != m_internalState && m_internalState == eProxyInternalState_PartiallySubmerged); //Just entered partially emerged state

	if (shouldUpdate && !IsWaitingForBottomLevelResults())
	{
		RayTestBottomLevel(player, worldReferencePos, s_rayLength);

		IPhysicalEntity* piPhysEntity = player.GetEntity()->GetPhysics();

		UpdateWaterLevel( worldReferencePos, playerWorldPos, piPhysEntity );

		if (m_waterLevel > WATER_LEVEL_UNKNOWN)
		{
			m_playerWaterLevel = (worldReferencePos.z - m_waterLevel);
		}
		else
		{
			m_playerWaterLevel = -WATER_LEVEL_UNKNOWN;
			m_bottomLevel = BOTTOM_LEVEL_UNKNOWN;
			m_headUnderwater = false;
			m_headComingOutOfWater = false;
		}
	}

	m_relativeBottomLevel = (m_bottomLevel > BOTTOM_LEVEL_UNKNOWN) ? m_waterLevel - m_bottomLevel : 0.0f;

	const float localHeadZ = player.GetLocalEyePos().z + 0.2f;
	const float worldHeadZ = playerWorldPos.z + localHeadZ;

	const bool headWasUnderWater = m_headUnderwater;
	m_headUnderwater = ((worldHeadZ - m_waterLevel) < 0.0f);

	m_headComingOutOfWater = headWasUnderWater && (!m_headUnderwater);

	if (m_internalState == eProxyInternalState_Swimming)
	{
		m_shouldSwim = ShouldSwim(max(localReferencePos.z, 1.3f));
	}
	else
	{
		UpdateSubmergedFraction(localReferencePos.z, playerWorldPos.z, m_waterLevel);

		m_shouldSwim = ShouldSwim(max(localReferencePos.z, 1.3f)) && (m_swimmingTimer < - 0.5f);
	}
#ifdef STATE_DEBUG
	DebugDraw(player, worldReferencePos);
#endif
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------
void CGameRules::ClientHit(const HitInfo &hitInfo)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(hitInfo.targetId);
	
	if(pActor == pClientActor)
		if (gEnv->pInput) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.5f * hitInfo.damage * 0.01f, hitInfo.damage * 0.02f, 0.0f));

	CreateScriptHitInfo(m_scriptHitInfo, hitInfo);
	CallScript(m_clientStateScript, "OnHit", m_scriptHitInfo);

	bool backface = hitInfo.dir.Dot(hitInfo.normal)>0;
	if (!hitInfo.remote && hitInfo.targetId && !backface)
	{
		if (!gEnv->bServer)
		{
			GetGameObject()->InvokeRMI(SvRequestHit(), hitInfo, eRMI_ToServer);
		}
		else
		{
			ServerHit(hitInfo);
		}

		if(gEnv->IsClient())
			ProcessLocalHit(hitInfo);
	}
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------
void CVehicleDamagesGroup::Update(float frameTime)
{
  FUNCTION_PROFILER( gEnv->pSystem, PROFILE_ACTION );
  
	TDelayedDamagesSubGroupList::iterator ite = m_delayedSubGroups.begin();
	TDelayedDamagesSubGroupList::iterator next;
  for (; ite != m_delayedSubGroups.end(); ite = next)
	{
		next = ite; ++next;

		SDelayedDamagesSubGroupInfo& delayedInfo = *ite;
		delayedInfo.delay -= frameTime;

		if (delayedInfo.delay <= 0.0f)
		{
			TDamagesSubGroupId id = delayedInfo.subGroupId;
			SDamagesSubGroup* pSubGroup = &m_damageSubGroups[id];
			delayedInfo.behaviorParams.randomness = pSubGroup->m_randomness;
			TVehicleDamageBehaviorVector& damageBehaviors =  pSubGroup->m_damageBehaviors;

			for (TVehicleDamageBehaviorVector::iterator behaviorIte = damageBehaviors.begin(); behaviorIte != damageBehaviors.end(); ++behaviorIte)
			{
				IVehicleDamageBehavior* pBehavior = *behaviorIte;
				pBehavior->OnDamageEvent(eVDBE_ComponentDestroyed, delayedInfo.behaviorParams);
			}

      m_delayedSubGroups.erase(ite);
		}        
	}

  if (!m_delayedSubGroups.empty())
    m_pVehicle->NeedsUpdate();
}
void CGameQueryListener::GetCurrentServers(char*** pastrServers, int &o_amount)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_NETWORK);
	if(m_servers.size() == 0)
	{
		o_amount = 0;
		return;
	}
	o_amount = m_servers.size();

	if(o_amount > m_iServers)// || o_amount < 0.1f*m_iServers)
	{
		for(int iServer=0; iServer<m_iServers; iServer++)
		{
			delete [] m_astrServers[iServer];
		}
		m_iServers = std::max(o_amount, int(120));
		for(int iServer=0; iServer<m_iServers; iServer++)
		{
			m_astrServers[iServer] = new char[256];
		}
	}

	//servers = new char*[m_servers.size()];
	*pastrServers = m_astrServers;

	std::vector<SGameServer>::iterator it = m_servers.begin();
	for(int s = 0; it != m_servers.end(); ++it, ++s)		//copy server address to return-vector
	{
		strcpy(m_astrServers[s],(*it).m_target.c_str());
	}
}
Ejemplo n.º 7
0
//------------------------------------------------------------------------
void CProjectile::Update(SEntityUpdateContext &ctx, int updateSlot)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if (updateSlot!=0)
		return;

	float color[4] = {1,1,1,1};
	bool bDebug = g_pGameCVars->i_debug_projectiles > 0;

	if(bDebug)
		gEnv->pRenderer->Draw2dLabel(50,15,2.0f,color,false,"Projectile: %s",GetEntity()->GetClass()->GetName());

	Vec3 pos = GetEntity()->GetWorldPos();

	ScaledEffect(m_pAmmoParams->pScaledEffect);

	// update whiz
	if(m_pAmmoParams->pWhiz)
	{
		if (m_whizSoundId == INVALID_SOUNDID)
		{
			IActor *pActor = g_pGame->GetIGameFramework()->GetClientActor();
			if (pActor && (m_ownerId != pActor->GetEntityId()))
			{
				float probability = 0.85f;

				if (Random()<=probability)
				{
					Lineseg line(m_last, pos);
					Vec3 player = pActor->GetEntity()->GetWorldPos();

					float t;
					float distanceSq=Distance::Point_LinesegSq(player, line, t);

					if (distanceSq < 4.7f*4.7f && (t>=0.0f && t<=1.0f))
					{
						if (distanceSq >= 0.65*0.65)
						{
							Sphere s;
							s.center = player;
							s.radius = 4.7f;

							Vec3 entry,exit;
							int intersect=Intersect::Lineseg_Sphere(line, s, entry,exit);
							if (intersect==0x1 || intersect==0x3) // one entry or one entry and one exit
								WhizSound(true, entry, (pos-m_last).GetNormalized());
						}
					}
				}
			}
		}
	}

	if (m_trailSoundId==INVALID_SOUNDID)
		TrailSound(true);

	m_totalLifetime += ctx.fFrameTime;
	m_last = pos;
}
Ejemplo n.º 8
0
void CG15LCD::Update(float frameTime)
{
	FUNCTION_PROFILER(GetISystem(),PROFILE_GAME);
	if (g_pGameCVars->cl_g15lcdEnable == 0)
		return;

	m_tick -= frameTime;
	if (m_tick < 0)
	{
		if (g_pGameCVars->cl_g15lcdTick > 0)
			m_tick = g_pGameCVars->cl_g15lcdTick/1000.0f;
		else
			m_tick = 0;

		if (IsConnected() && m_currentPage != -1)
		{
			if(m_currentPage > 1 && !g_pGame->GetIGameFramework()->IsGameStarted())
				m_currentPage = 0;
			else if(m_currentPage == 0 && g_pGame->GetIGameFramework()->IsGameStarted())
				m_currentPage = 2;

			if (m_pages[m_currentPage]->PreUpdate())
			{
				m_pages[m_currentPage]->Update(frameTime);
				m_pImpl->ShowPage(m_currentPage);
			}
		}
		m_pImpl->Update();
	}
}
Ejemplo n.º 9
0
//------------------------------------------------------------------------
void CItem::InitGeometry()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	//skip loading the first person geometry for now, it may never be used
	m_sharedparams->LoadGeometryForItem(this, eIGS_FirstPerson);
}
Ejemplo n.º 10
0
void CTagBullet::HandleEvent(const SGameObjectEvent &event)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	CProjectile::HandleEvent(event);

	if (event.event == eGFE_OnCollision)
	{
		if (m_destroying)
			return;

		EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr);
		if (!pCollision)
			return;

		IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0;
		if (pTarget)
		{
			EntityId targetId = pTarget->GetId();

			CHUD *pHUD = g_pGame->GetHUD();
			pHUD->AddToRadar(targetId);

			SimpleHitInfo info(m_ownerId, targetId, m_weaponId, 0); // 0=tag,1=tac
			info.remote=IsRemote();

			g_pGame->GetGameRules()->ClientSimpleHit(info);
		}

		Destroy();
	}
}
bool CVisibleObjectsHelper::CheckObjectViewDist(const Agent& agent, const SVisibleObject &visibleObject) const
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	assert(agent.IsValid());

	bool bInViewDist = true;

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

	IEntity *pAIEntity = pEntitySystem->GetEntity(agent.GetEntityID());
	IEntity *pObjectEntity = pEntitySystem->GetEntity(visibleObject.entityId);

	IComponentRender *pObjectRenderProxy = (pAIEntity != NULL && pObjectEntity ? static_cast<IComponentRender *>(pObjectEntity->GetComponent<IComponentRender>().get()) : NULL);
	if (pObjectRenderProxy != NULL)
	{
		IRenderNode *pObjectRenderNode = pObjectRenderProxy->GetRenderNode();
		if (pObjectRenderNode != NULL)
		{
			const float fDistanceSq = pAIEntity->GetWorldPos().GetSquaredDistance(pObjectEntity->GetWorldPos());
			const float fMaxViewDistSq = sqr(pObjectRenderNode->GetMaxViewDist());
			
			bInViewDist = (fDistanceSq <= fMaxViewDistSq);
		}
	}

	return bInViewDist;
}
Ejemplo n.º 12
0
void CMFXForceFeedbackEffect::Execute(SMFXRunTimeEffectParams& params)
{
	FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);

	if (params.playflags & MFX_PLAY_FORCEFEEDBACK)
	{
		float distanceToPlayerSqr = FLT_MAX;
		IActor *pClientActor = gEnv->pGame->GetIGameFramework()->GetClientActor();
		if (pClientActor)
		{
			distanceToPlayerSqr = (pClientActor->GetEntity()->GetWorldPos() - params.pos).GetLengthSquared();
		}

		const float testDistanceSqr = clamp_tpl(distanceToPlayerSqr, m_forceFeedbackParams.intensityFallOffMinDistanceSqr, m_forceFeedbackParams.intensityFallOffMaxDistanceSqr);
		const float minMaxDiffSqr = m_forceFeedbackParams.intensityFallOffMaxDistanceSqr - m_forceFeedbackParams.intensityFallOffMinDistanceSqr;
		
		float effectIntensity = (float)__fsel(-minMaxDiffSqr, 0.0f, 1.0f - (testDistanceSqr - m_forceFeedbackParams.intensityFallOffMinDistanceSqr) / (minMaxDiffSqr + FLT_EPSILON));
		effectIntensity *= effectIntensity;
		if (effectIntensity > 0.01f)
		{
			IForceFeedbackSystem* pForceFeedback = CCryAction::GetCryAction()->GetIForceFeedbackSystem();
			assert(pForceFeedback);
			ForceFeedbackFxId fxId = pForceFeedback->GetEffectIdByName(m_forceFeedbackParams.forceFeedbackEventName.c_str());
			pForceFeedback->PlayForceFeedbackEffect(fxId, SForceFeedbackRuntimeParams(effectIntensity, 0.0f));
		}
	}

}
Ejemplo n.º 13
0
bool CEntityPoolSignature::CalculateFromEntity(CEntity *pEntity)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);
	LOADING_TIME_PROFILE_SECTION(GetISystem());

	assert(pEntity);

	if (!m_bGenerated && pEntity)
	{
		m_bGenerated = true;

		ISerialize *pWriter = m_pSignatureSerializer->GetWriter(m_Signature);
		TSerialize signatureWriter(pWriter);

		m_bGenerated &= pEntity->GetSignature(signatureWriter);

		if (!m_bGenerated)
		{
			m_Signature->removeAllChilds();
			m_Signature->removeAllAttributes();
		}
	}

	return m_bGenerated;
}
Ejemplo n.º 14
0
bool CEntityPoolSignature::CompareNodeAttributes(const XmlNodeRef &a, const XmlNodeRef &b)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);

	assert(bool(a));
	assert(bool(b));

	const int attrCount_a = a->getNumAttributes();
	const int attrCount_b = b->getNumAttributes();
	bool bResult = (attrCount_a == attrCount_b);

	if (bResult)
	{
		const char *attrKey_a, *attrValue_a;
		const char *attrKey_b, *attrValue_b;

		for (int attr = 0; bResult && attr < attrCount_a; ++attr)
		{
			const bool bHasForA = a->getAttributeByIndex(attr, &attrKey_a, &attrValue_a);
			const bool bHasForB = b->getAttributeByIndex(attr, &attrKey_b, &attrValue_b);
			if ((bHasForA && !bHasForB) || (!bHasForA && bHasForB))
				bResult = false;
			else if (bHasForA && (0 != strcmp(attrKey_a, attrKey_b) || 0 != strcmp(attrValue_a, attrValue_b)))
				bResult = false;
		}
	}

	return bResult;
}
Ejemplo n.º 15
0
bool CMPTutorial::CheckVehicles(const CPlayer* pPlayer)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	bool showPrompt = false;
	if(!pPlayer)
		return showPrompt;

	IVehicle* pVehicle = pPlayer->GetLinkedVehicle();

	if(m_wasInVehicle && !pVehicle)
	{
		// got out of vehicle. Move HUD box back to normal place.
		SAFE_HUD_FUNC(SetTutorialTextPosition(2));
		m_wasInVehicle = false;
		return showPrompt;
	}
 
 	if(pVehicle && !m_wasInVehicle)
 	{
		// just got in. Move HUD box up so it doesn't overlap vehicle hud.
		SAFE_HUD_FUNC(SetTutorialTextPosition(1));

		m_wasInVehicle = true;

		// generic 'boarding a vehicle' message
		TriggerEvent(eTE_BoardVehicle);
	}

	return showPrompt;
}
void CPlayerStateSwim_WaterTestProxy::UpdateOutOfWater(const CPlayer& player, const float frameTime)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	//Out of water, only query water level to figure out if player/ai is in contact with a water volume
	const Matrix34& playerWorldTM = player.GetEntity()->GetWorldTM();
	const Vec3 playerWorldPos = playerWorldTM.GetTranslation();

	const Vec3 localReferencePos = GetLocalReferencePosition(player);

	//Note: Try to tune value and set to higher value possible which works well
	const bool lastCheckFarAwayEnough = ((m_lastWaterLevelCheckPosition - playerWorldPos).len2() >= sqr(0.6f));

	float worldWaterLevel = m_waterLevel;
	if (lastCheckFarAwayEnough)
	{
		const Vec3 worldReferencePos = playerWorldPos + (Quat(playerWorldTM) * localReferencePos);
		IPhysicalEntity* piPhysEntity = player.GetEntity()->GetPhysics();

		UpdateWaterLevel( worldReferencePos, playerWorldPos, piPhysEntity );
	}

	//Update submerged fraction
	UpdateSubmergedFraction(localReferencePos.z, playerWorldPos.z, worldWaterLevel);
}
//------------------------------------------------------------------------
void CRapid::UpdateFiring(CActor* pOwnerActor, bool ownerIsClient, bool ownerIsPlayer, float frameTime)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_AI);

	if (m_speed >= 0.00001f)
	{			
		const uint32 decelAndRapid = eRapidFlag_decelerating|eRapidFlag_rapidFiring;

		if ((m_speed >= m_fireParams->rapidparams.min_speed) && !(m_rapidFlags & decelAndRapid))
		{
			m_rapidFlags |= eRapidFlag_rapidFiring;

			uint32 flags = CItem::eIPAF_Default;
			float speedOverride = -1.0f;
			PlayRapidFire(speedOverride, (flags & CItem::eIPAF_ConcentratedFire) != 0);		
		}
		else if ((m_speed < m_fireParams->rapidparams.min_speed) && ((m_rapidFlags & decelAndRapid) ==  decelAndRapid))
		{
			m_rapidFlags &= ~eRapidFlag_rapidFiring;
		}
	}

	if(ownerIsClient && gEnv->bMultiplayer)
	{
		CRY_ASSERT(pOwnerActor);

		const CTimeValue currentTime = gEnv->pTimer->GetFrameStartTime();
		const float startFiringSeconds = m_startFiringTime.GetSeconds();
		const float secondsFiring = gEnv->pTimer->GetAsyncTime().GetSeconds() - startFiringSeconds;
		if(startFiringSeconds != 0.0f && secondsFiring > 3.0f)
		{
			NET_BATTLECHATTER(BC_Battlecry, static_cast<CPlayer*>(pOwnerActor));
		}
	}
}
Ejemplo n.º 18
0
//------------------------------------------------------------------------
void CGameRules::ClientHit(const HitInfo &hitInfo)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	IActor *pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(hitInfo.targetId);
	
	if(pActor == pClientActor)
		if (gEnv->pInput) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.5f * hitInfo.damage * 0.01f, hitInfo.damage * 0.02f, 0.0f));

	//m_pScript->CallMethod( "OnHit", gEnv->pMonoScriptSystem->GetConverter()->ToManagedType(eCMT_HitInfo, &const_cast<HitInfo &>(hitInfo)));

	bool backface = hitInfo.dir.Dot(hitInfo.normal)>0;
	if (!hitInfo.remote && hitInfo.targetId && !backface)
	{
		if (!gEnv->bServer)
		{
			GetGameObject()->InvokeRMI(SvRequestHit(), hitInfo, eRMI_ToServer);
		}
		else
		{
			ServerHit(hitInfo);
		}

		if(gEnv->IsClient())
			ProcessLocalHit(hitInfo);
	}
}
Ejemplo n.º 19
0
CEntity* CEntityPool::GetPoolEntityFromInactiveSet()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);

	assert(!gEnv->IsEditor());

	CEntity* pPoolEntity = NULL;

	assert(m_pEntityPoolManager);
	CEntitySystem* pEntitySystem = m_pEntityPoolManager->GetEntitySystem();

	// Get the next empty entity to use
	TPoolIdsVec::iterator itPoolSlot    = m_InactivePoolIds.begin();
	TPoolIdsVec::iterator itPoolSlotEnd = m_InactivePoolIds.end();
	for (; itPoolSlot != itPoolSlotEnd; ++itPoolSlot)
	{
		CEntity* pEntity = (CEntity*)pEntitySystem->GetEntity(itPoolSlot->poolId);

		// Don't use active ones
		if (!pEntity)
		{
			CRY_ASSERT_MESSAGE(false, "NULL Pool Entity in Inactive set");
			continue;
		}

		// Use this one
		pPoolEntity = pEntity;
		break;
	}

	return pPoolEntity;
}
Ejemplo n.º 20
0
void CBaseInput::PostHoldEvents()
{
	FUNCTION_PROFILER( GetISystem(),PROFILE_INPUT );
	SInputEvent event;

	// DARIO_NOTE: In this loop, m_holdSymbols size and content is changed so previous
	// code was resulting in occasional index out of bounds.
	// The desired behaviour as I understand it is as follows:
	// (PRESSED) symbols should be added to the to the end of m_holdSymbols but not 
	// processed this frame (thus the keep the loop comparison as is).
	// On the other hand, (RELEASED) symbols need to be removed from the m_holdSymbols this frame
	// so the size of m_holdSymbols may decrease. The search for a RELEASED symbol is done backwards
	// i.e. from m_holdSymbols.end() - 1 to 0 thus it will never go before the sending index (i.e. i)
	// In order to allow for this behaviour, the (i < kCurrentCount) check is added.
	
	const size_t kInitialCount = m_holdSymbols.size();
	for (size_t i=0; i < kInitialCount; ++i)
	{
		const size_t kCurrentCount = m_holdSymbols.size();
		if (i < kCurrentCount)
		{
			m_holdSymbols[i]->AssignTo(event, GetModifiers());
			event.deviceIndex = m_holdSymbols[i]->deviceIndex;

		if (g_pInputCVars->i_debug)
		{
			gEnv->pLog->Log("InputDebug: 0x%p PostHoldEvent Symbol %d %s", this, m_holdSymbols[i]->keyId, m_holdSymbols[i]->name.c_str() );
		}

			PostInputEvent(event);
		}
	}
}
Ejemplo n.º 21
0
//------------------------------------------------------------------------------------
void CUIActionManager::Update()
{
    FUNCTION_PROFILER(GetISystem(), PROFILE_ACTION);

    if (!m_actionEnableMap.empty())
    {
        TActionMap actionEnableMap = m_actionEnableMap;
        m_actionEnableMap.clear();
        for ( TActionMap::iterator it = actionEnableMap.begin(); it != actionEnableMap.end(); ++it)
        {
            EnableActionInt(it->first, it->second);
        }
    }

    if (!m_actionEndMap.empty())
    {
        TActionArgMap actionEndMap = m_actionEndMap;
        m_actionEndMap.clear();
        for ( TActionArgMap::iterator it = actionEndMap.begin(); it != actionEndMap.end(); ++it)
        {
            EndActionInt(it->first, it->second);
        }
    }

    if (!m_actionStartMap.empty())
    {
        TActionArgMap actionStartMap = m_actionStartMap;
        m_actionStartMap.clear();
        for ( TActionArgMap::iterator it = actionStartMap.begin(); it != actionStartMap.end(); ++it)
        {
            StartActionInt(it->first, it->second);
        }
    }
}
Ejemplo n.º 22
0
bool CBattleDust::CheckForMerging(CBattleEvent* pEvent)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!g_pGameCVars->g_battleDust_enable)
		return false;

	if(!pEvent)
		return false;

	if(!gEnv->bServer)
		return false;

	// check if area can merge with nearby areas
	for(std::list<EntityId>::iterator it = m_eventIdList.begin(); it != m_eventIdList.end(); ++it)
	{
		EntityId areaId = (*it);
		CBattleEvent *pBattleArea = FindEvent(areaId);
		if(!pBattleArea)
			continue;

		if(CheckIntersection(pEvent, pBattleArea->m_worldPos, pBattleArea->m_radius) && pBattleArea->m_radius > 0 && (pBattleArea != pEvent) && pBattleArea->GetEntity())
		{
			MergeAreas(pBattleArea, pEvent->m_worldPos, pEvent->m_radius);
			return true;
		}
	}

	return false;
}
void CMFXParticleEffect::Execute(const SMFXRunTimeEffectParams& params)
{
  FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);

  Vec3 pos = params.pos;
	Vec3 dir = ZERO;
	Vec3 inDir = params.dir[0];
	Vec3 reverso = inDir * -1.0f;
	switch (m_particleParams.directionType)
	{
	case SMFXParticleParams::eDT_Normal:
		dir = params.normal;
		break;
	case SMFXParticleParams::eDT_Ricochet:
		dir = reverso.GetRotated(params.normal, gf_PI).normalize();
		break;
	default:
		dir = params.normal;
		break;
	}
 
  bool tryToAttachEffect = (CMaterialEffectsCVars::Get().mfx_EnableAttachedEffects != 0);
  float distToPlayer = 0.f;
  IActor *pClientActor = gEnv->pGame->GetIGameFramework()->GetClientActor();
  if (pClientActor)
  {
    distToPlayer = (pClientActor->GetEntity()->GetWorldPos() - params.pos).GetLength();
	tryToAttachEffect = tryToAttachEffect && (pClientActor->GetEntityId() != params.trg);
  }
  
  SMFXParticleEntries::const_iterator end = m_particleParams.m_entries.end();
  for (SMFXParticleEntries::const_iterator it = m_particleParams.m_entries.begin(); it!=end; ++it)
  {
    // choose effect based on distance
    if ((it->maxdist == 0.f) || (distToPlayer <= it->maxdist) && !it->name.empty() )
    { 
      IParticleEffect *pParticle = gEnv->pParticleManager->FindEffect(it->name.c_str());

      if (pParticle)
      {
        const float pfx_minscale = (it->minscale != 0.f) ? it->minscale : CMaterialEffectsCVars::Get().mfx_pfx_minScale;
        const float pfx_maxscale = (it->maxscale != 0.f) ? it->maxscale : CMaterialEffectsCVars::Get().mfx_pfx_maxScale; 
        const float pfx_maxdist = (it->maxscaledist != 0.f) ? it->maxscaledist : CMaterialEffectsCVars::Get().mfx_pfx_maxDist; 
                
        const float truscale = pfx_minscale + ((pfx_maxscale - pfx_minscale) * (distToPlayer!=0.f ? min(1.0f, distToPlayer/pfx_maxdist) : 1.f));  

		bool particleSpawnedAndAttached = tryToAttachEffect ? AttachToTarget(*it, params, pParticle, dir, truscale) : false;

        // If not attached, just spawn the particle
		if (particleSpawnedAndAttached == false)
		{
			pParticle->Spawn( true, IParticleEffect::ParticleLoc(pos, dir, truscale) );
		}
      }
      
      break;
    }
  }
}
Ejemplo n.º 24
0
void CBattleDust::Update()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!g_pGameCVars->g_battleDust_enable)
	{
		RemoveAllEvents();
		return;
	}

	if(!gEnv->bServer)
		return;

	if(g_pGameCVars->g_battleDust_debug != 0)
	{
		float col[] = {1,1,1,1};
		gEnv->pRenderer->Draw2dLabel(50, 40, 2.0f, col, false, "Num BD areas: %d (max %d)", (int32)m_eventIdList.size(), m_maxBattleEvents);
	}
	float ypos = 60.0f;

	// go through the list of areas, remove any which are too small
	m_maxBattleEvents = MAX(m_maxBattleEvents, m_eventIdList.size());
	std::list<EntityId>::iterator next;
	std::list<EntityId>::iterator it = m_eventIdList.begin();
	for(; it != m_eventIdList.end(); it = next)
	{
		next = it; ++next;
		EntityId areaId = (*it);
		CBattleEvent *pBattleArea = FindEvent(areaId);
		if(!pBattleArea)
			continue;

		if(pBattleArea->m_lifetime > 0.0f)
		{
			pBattleArea->m_lifeRemaining -= gEnv->pTimer->GetFrameTime();
			pBattleArea->m_radius = pBattleArea->m_peakRadius * (pBattleArea->m_lifeRemaining / pBattleArea->m_lifetime);
		}

		if(g_pGameCVars->g_battleDust_debug != 0)
		{
			float col[] = {1,1,1,1};
			gEnv->pRenderer->Draw2dLabel(50, ypos, 1.4f, col, false, "Area: (%.2f, %.2f, %.2f), Radius: %.2f/%.2f, Particles: %.0f, Lifetime: %.2f/%.2f", pBattleArea->m_worldPos.x, pBattleArea->m_worldPos.y, pBattleArea->m_worldPos.z, pBattleArea->m_radius, pBattleArea->m_peakRadius, pBattleArea->m_numParticles, pBattleArea->m_lifeRemaining, pBattleArea->m_lifetime);
			ypos += 10.0f;
		}

		if(pBattleArea->m_lifeRemaining < 0.0f)
		{
			// remove it (NB this will also call RemoveBattleArea(), which will remove it from the list)
			gEnv->pEntitySystem->RemoveEntity(areaId);
		}
		else
		{
			if(pBattleArea->GetEntity())
			{
				UpdateParticlesForArea(pBattleArea);
			}
		}
	}
}
Ejemplo n.º 25
0
void CScriptProxy::OnCollision(CEntity* pTarget, int matId, const Vec3 &pt, const Vec3 &n, const Vec3 &vel, const Vec3 &targetVel, int partId, float mass)
{
	if (!CurrentState()->IsStateFunctionImplemented(ScriptState_OnCollision))
		return;

	FUNCTION_PROFILER( GetISystem(), PROFILE_ENTITY );

	if (!m_hitTable)
		m_hitTable.Create(gEnv->pScriptSystem);
	{
		Vec3               dir(0, 0, 0);
		CScriptSetGetChain chain(m_hitTable);
		chain.SetValue("normal", n);
		chain.SetValue("pos", pt);

		if (vel.GetLengthSquared() > 1e-6f)
		{
			dir = vel.GetNormalized();
			chain.SetValue("dir", dir);
		}

		chain.SetValue("velocity", vel);
		chain.SetValue("target_velocity", targetVel);
		chain.SetValue("target_mass", mass);
		chain.SetValue("partid", partId);
		chain.SetValue("backface", n.Dot(dir) >= 0);
		chain.SetValue("materialId", matId);

		if (pTarget)
		{
			ScriptHandle sh;
			sh.n = pTarget->GetId();

			if (pTarget->GetPhysics())
			{
				chain.SetValue("target_type", (int)pTarget->GetPhysics()->GetType());
			}
			else
			{
				chain.SetToNull("target_type");
			}

			chain.SetValue("target_id", sh);

			if (pTarget->GetScriptTable())
			{
				chain.SetValue("target", pTarget->GetScriptTable());
			}
		}
		else
		{
			chain.SetToNull("target_type");
			chain.SetToNull("target_id");
			chain.SetToNull("target");
		}
	}

	m_pScript->CallStateFunction( CurrentState(),m_pThis,ScriptState_OnCollision, m_hitTable);
}
Ejemplo n.º 26
0
CEntity* CEntityPool::GetPoolEntityFromActiveSet()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);

	assert(!gEnv->IsEditor());

	CEntity* pPoolEntity = NULL;

	assert(m_pEntityPoolManager);
	CEntitySystem* pEntitySystem = m_pEntityPoolManager->GetEntitySystem();

	const uint32 uActiveSize = m_ActivePoolIds.size();
	const bool   bAtMax      = (m_uMaxSize > 0 && uActiveSize >= m_uMaxSize);
	m_ReturnToPoolWeights.clear();
	m_ReturnToPoolWeights.reserve(m_ActivePoolIds.size());

	// Go through the active list and ask if any are available for removal
	TPoolIdsVec::iterator itPoolSlot    = m_ActivePoolIds.begin();
	TPoolIdsVec::iterator itPoolSlotEnd = m_ActivePoolIds.end();
	for (; itPoolSlot != itPoolSlotEnd; ++itPoolSlot)
	{
		CEntity* pEntity = (CEntity*)pEntitySystem->GetEntity(itPoolSlot->usingId);
		if (!pEntity)
		{
			CRY_ASSERT_MESSAGE(pEntity, "NULL Pool Entity in Active set");
			continue;
		}

		SReturnToPoolWeight returnToPoolWeight;
		returnToPoolWeight.pEntity = pEntity;
		returnToPoolWeight.weight  = m_pEntityPoolManager->GetReturnToPoolWeight(pEntity, bAtMax);
		m_ReturnToPoolWeights.push_back(returnToPoolWeight);
	}

	// Sort and use top if weight > 0
	if (!m_ReturnToPoolWeights.empty())
	{
		std::sort(m_ReturnToPoolWeights.begin(), m_ReturnToPoolWeights.end());
		SReturnToPoolWeight &bestEntry = m_ReturnToPoolWeights.front();

		if (bestEntry.weight > FLT_EPSILON)
		{
			pPoolEntity = bestEntry.pEntity;

#ifdef ENTITY_POOL_DEBUGGING
			if (bAtMax)
			{
				++m_iDebug_TakenFromActiveForced;
				EntityWarning("[Entity Pool] Pool \'%s\' has reached its max size and a new entity was requested. An entity from the active set was forced to be reused: \'%s\' (%d)",
				              m_sName.c_str(), pPoolEntity->GetName(), m_iDebug_TakenFromActiveForced);
			}
#endif //ENTITY_POOL_DEBUGGING
		}
	}

	return pPoolEntity;
}
void CGameQueryListener::RefreshPings()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_NETWORK);

	std::vector<SGameServer>::iterator it = m_servers.begin();
	ILanQueryListener* pLQL = static_cast<ILanQueryListener*>(m_pNetListener);
	for(; it != m_servers.end(); ++it)
		pLQL->SendPingTo((*it).m_target.c_str());
}
//------------------------------------------------------------------------
void CVehicleHelper::GetWorldTM(Matrix34& worldTM) const
{
  FUNCTION_PROFILER( gEnv->pSystem, PROFILE_ACTION );

	const Matrix34& partWorldTM = m_pParentPart->GetWorldTM();

	worldTM = Matrix34(Matrix33(partWorldTM) * Matrix33(m_localTM));
	worldTM.SetTranslation((partWorldTM * m_localTM).GetTranslation());
}
Ejemplo n.º 29
0
bool CScriptProxy::Init( IEntity* pEntity,SEntitySpawnParams &params )
{
	FUNCTION_PROFILER( GetISystem(), PROFILE_ENTITY );

	// Call Init.
	CallInitEvent(false);

	return true;
}
Ejemplo n.º 30
0
//------------------------------------------------------------------------
void CVehicleDamages::UpdateDamages(float frameTime)
{
  FUNCTION_PROFILER( GetISystem(), PROFILE_ACTION );

	for (TVehicleDamagesGroupVector::iterator ite = m_damagesGroups.begin(), end = m_damagesGroups.end(); ite != end; ++ite)
	{
		CVehicleDamagesGroup* pDamageGroup = *ite;
		pDamageGroup->Update(frameTime);
	}
}