| 152 | } |
| 153 | |
| 154 | void CWorldQuery::UpdateRaycastQuery() |
| 155 | { |
| 156 | if (!m_pActor || m_pActor->GetEntity()->IsHidden()) |
| 157 | return; |
| 158 | |
| 159 | IEntity* pEntity = m_pActor->GetEntity(); |
| 160 | IPhysicalEntity* pPhysEnt = pEntity ? pEntity->GetPhysics() : NULL; |
| 161 | |
| 162 | static const int obj_types = ent_all; // ent_terrain|ent_static|ent_rigid|ent_sleeping_rigid|ent_living; |
| 163 | static const unsigned int flags = rwi_pierceability(PIERCE_GLASS) | rwi_colltype_any; |
| 164 | |
| 165 | #if WORLDQUERY_USE_DEFERRED_LINETESTS |
| 166 | IPhysicalEntity* skipEntities[1]; |
| 167 | skipEntities[0] = pPhysEnt; |
| 168 | |
| 169 | int raySlot = GetRaySlot(); |
| 170 | CRY_ASSERT(raySlot != -1); |
| 171 | |
| 172 | m_queuedRays[raySlot].rayId = CCryAction::GetCryAction()->GetPhysicQueues().GetRayCaster().Queue( |
| 173 | RayCastRequest::HighPriority, |
| 174 | RayCastRequest(m_worldPosition, 300.0f * m_dir, |
| 175 | obj_types, |
| 176 | flags, |
| 177 | skipEntities, |
| 178 | pPhysEnt ? 1 : 0, 2), |
| 179 | functor(*this, &CWorldQuery::OnRayCastDataReceived)); |
| 180 | |
| 181 | m_queuedRays[raySlot].counter = ++m_requestCounter; |
| 182 | |
| 183 | static const float k_maxTimeRaycastStaysValid = 0.1f; |
| 184 | |
| 185 | const float frameStartTime = gEnv->pTimer->GetCurrTime(); |
| 186 | const float timeSinceLastDeferred = (frameStartTime - m_timeLastDeferredResult); |
| 187 | if (timeSinceLastDeferred > k_maxTimeRaycastStaysValid) |
| 188 | { |
| 189 | // it's been too long since the last deferred raycast result assume hit nothing |
| 190 | m_rayHitAny = false; |
| 191 | m_lookAtEntityId = 0; |
| 192 | //CryLogAlways("CWorldQuery::UpdateRaycastQuery() - frameStartTime=%f; it's been too long (%f) since the last deferred raycast result, assuming hit nothing\n", frameStartTime, timeSinceLastDeferred); |
| 193 | } |
| 194 | #else // WORLDQUERY_USE_DEFERRED_LINETESTS |
| 195 | m_rayHitAny = 0 != m_pPhysWorld->RayWorldIntersection(m_worldPosition, 300.0f * m_dir, obj_types, flags, &m_rayHit, 1, pPhysEnt); |
| 196 | if (m_rayHitAny) |
| 197 | { |
| 198 | IEntity* pLookAt = m_pEntitySystem->GetEntityFromPhysics(m_rayHit.pCollider); |
| 199 | if (pLookAt) |
| 200 | { |
| 201 | m_lookAtEntityId = pLookAt->GetId(); |
| 202 | //m_rayHit.pCollider=0; // -- commented until a better solution is thought of. |
| 203 | } |
| 204 | else |
| 205 | m_lookAtEntityId = 0; |
| 206 | } |
| 207 | else |
| 208 | m_lookAtEntityId = 0; |
| 209 | |
| 210 | // if (m_rayHitAny) |
| 211 | // CryLogAlways( "HIT: terrain:%i distance:%f (%f,%f,%f)", m_rayHit.bTerrain, m_rayHit.dist, m_rayHit.pt.x, m_rayHit.pt.y, m_rayHit.pt.z ); |
nothing calls this directly
no test coverage detected