DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ Update()

void ActionTargets::Update ( )
inlineprivate

clear state

camera & ray properties

if the cursor target is a proxy

ignores attachments on player and objects with invalid IDs

Need to do this surface detection here as the current RaycastRVResult might not contain the correct surface info

Check current surface player is looking at

spacial search

removes player from the vicinity

transformation of array of Objects to hashmap (VicinityObjects)

removes Vicinity objects that are not directly visible from player position

select & sort targets based on utility function

action target for surface actions (lowest utility)

См. определение в файле ActionTargets.c строка 232

233 {
235 m_VicinityObjects.ClearVicinityObjects();
236 Clear();
237
238 Object firstValidRaycastedObject = null;
239 array<Object> vicinityObjects = new array<Object>;
240
242 vector playerPos = m_Player.GetPosition();
243 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(m_Player);
244
245 m_RayStart = g_Game.GetCurrentCameraPosition();
246 m_RayEnd = m_RayStart + g_Game.GetCurrentCameraDirection() * c_RayDistance;
247
248 RaycastRVParams rayInput = new RaycastRVParams(m_RayStart, m_RayEnd, m_Player);
249 rayInput.flags = CollisionFlags.ALLOBJECTS;
250 //rayInput.sorted = true;
251 array<ref RaycastRVResult> results = new array<ref RaycastRVResult>();
252 array<RaycastRVResult> sortedValidRaycastResults = new array<RaycastRVResult>();
254
255 if (DayZPhysics.RaycastRVProxy(rayInput, results))
256 {
257 array<int> sortedDistanceHelper = SortResultsDistance(results);
258 int sortedResultsCount = m_SortedResults.Count();
259 if (sortedResultsCount > 0 )
260 {
261 foreach (int sortedDist : sortedDistanceHelper) //distances already sorted
262 {
263 array<RaycastRVResult> sameDistResults = m_SortedResults.Get(sortedDist);
264
265 foreach (RaycastRVResult res : sameDistResults)
266 {
267 if (res.obj && !res.obj.CanBeActionTarget())
268 continue;
269
271 if (res.hierLevel > 0)
272 {
274 if (res.parent.IsMan() || (res.obj.GetID() < 1 && !IsRaycastResultException(res)))
275 continue;
276 }
277
278 sortedValidRaycastResults.Insert(res);
279 resultMap.Insert(res.obj, res);
280 if (!firstValidRaycastedObject)
281 firstValidRaycastedObject = res.obj;
282
283 if (m_HitPos == vector.Zero)
284 m_HitPos = res.pos;
285
286 if (res.surface && res.surface.GetSurfaceType() != "")
287 {
288 m_SurfaceInfo = res.surface;
289 }
290 else
291 {
293 SurfaceDetectionParameters surfaceParams = new SurfaceDetectionParameters();
294 surfaceParams.type = SurfaceDetectionType.Roadway;
295 surfaceParams.position = m_HitPos;
296 surfaceParams.includeWater = true;
297 surfaceParams.syncMode = UseObjectsMode.NoWait;
298 surfaceParams.rsd = RoadSurfaceDetection.ABOVE;
299
301 SurfaceDetectionResult surfaceResult = new SurfaceDetectionResult();
302 if (g_Game.GetSurface(surfaceParams, surfaceResult))
303 {
304 if (surfaceResult && surfaceResult.surface)
305 {
306 m_SurfaceInfo = surfaceResult.surface;
307 }
308 }
309 }
310 break;
311 }
312 }
313 }
314 }
315 else
316 {
317 firstValidRaycastedObject = null;
318 m_HitPos = vector.Zero;
319 m_SurfaceInfo = null;
320 }
321
323 DayZPlayerCamera camera = m_Player.GetCurrentCamera();
324 if (camera && camera.GetCurrentPitch() <= -45) // Spatial search is a contributor to very heavy searching, limit it to when we are at least looking down
325 DayZPlayerUtils.GetEntitiesInCone(playerPos, headingDirection, c_ConeAngle, c_MaxTargetDistance, c_ConeHeightMin, c_ConeHeightMax, vicinityObjects);
326
328 vicinityObjects.RemoveItem(m_Player);
329
330 FilterDuplicateVicinityObjects(vicinityObjects, sortedValidRaycastResults);
331
333 m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
334
336 FilterObstructedObjectsEx(firstValidRaycastedObject, vicinityObjects);
337
339 int vicinityObjCount = m_VicinityObjects.Count();
340 for (int i = 0; i < vicinityObjCount; ++i)
341 {
342 Object object = m_VicinityObjects.GetObject(i);
343 Object parent;
344 RaycastRVResult result;
345 int targetComponent;
346 vector hitpos;
347 //proper raycast results will use their own data
348 if (resultMap.Find(object, result))
349 {
350 parent = result.parent;
351 hitpos = result.pos;
352 targetComponent = result.component;
353 }
354 else
355 {
356 parent = m_VicinityObjects.GetParent(i);
357 hitpos = m_HitPos; //substitute raycast hitpos as reference for the utility check
358 targetComponent = -1; //invalid component
359 }
360
361 float utility = ComputeUtility(object, m_RayStart, m_RayEnd, firstValidRaycastedObject, hitpos);
362 if (utility > 0)
363 {
364 string surfaceName;
365 if (m_SurfaceInfo && m_SurfaceInfo.GetEntryName() != "")
366 surfaceName = m_SurfaceInfo.GetEntryName();
367
368 ActionTarget at = new ActionTarget(object, parent, targetComponent, m_HitPos, utility, surfaceName);
369 StoreTarget(at);
370 }
371 }
372
374 if (m_HitPos == vector.Zero)
375 {
376 vector contact_pos, contact_dir, hitNormal;
377 int contactComponent;
378 float hitFraction;
379 Object hitObject;
380
381 m_RayEnd = m_RayStart + g_Game.GetCurrentCameraDirection() * c_RayDistance * 3;
382
383 PhxInteractionLayers collisionLayerMask = PhxInteractionLayers.ROADWAY|PhxInteractionLayers.TERRAIN|PhxInteractionLayers.WATERLAYER;
384 DayZPhysics.RayCastBullet(m_RayStart,m_RayEnd,collisionLayerMask,null,hitObject,contact_pos,hitNormal,hitFraction);
385 m_HitPos = contact_pos;
386 }
387
388 m_Targets.Insert(new ActionTarget(null, null, -1, m_HitPos, 0));
389
390#ifdef DIAG_DEVELOPER
391 if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
392 {
393 ShowDebugActionTargets(true);
394 DrawDebugActionTargets(true);
395 DrawDebugCone(true);
396 DrawDebugRay(true);
397 DrawSelectionPos(DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_SELPOS_DEBUG));
398 }
399 else
400 {
401 ShowDebugActionTargets(false);
402 DrawDebugActionTargets(false);
403 DrawDebugCone(false);
404 DrawDebugRay(false);
405 DrawSelectionPos(false);
406 }
407#endif
408 }
void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility, string surfaceName="")
Определения ActionTargets.c:125
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:4074
PhxInteractionLayers
Определения DayZPhysics.c:2
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
float hitFraction
Определения DustKickupEffects.c:23
string surfaceName
Определения DustKickupEffects.c:19
DiagMenuIDs
Определения EDiagMenuIDs.c:2
SurfaceDetectionType
Определения SurfaceInfo.c:86
UseObjectsMode
Определения SurfaceInfo.c:74
SurfaceInfo m_SurfaceInfo
first valid hitpos! Used only as rough reference value for conecasted results.
Определения ActionTargets.c:834
const float c_MaxTargetDistance
Определения ActionTargets.c:841
vector m_RayEnd
Определения ActionTargets.c:831
ref map< int, ref array< RaycastRVResult > > m_SortedResults
Определения ActionTargets.c:209
const float c_ConeAngle
Определения ActionTargets.c:843
array< int > SortResultsDistance(array< ref RaycastRVResult > results)
Определения ActionTargets.c:420
void FilterDuplicateVicinityObjects(inout array< Object > vicinityObjectsOutput, array< RaycastRVResult > sortedRaycastResults)
Определения ActionTargets.c:556
vector m_HitPos
Определения ActionTargets.c:832
void StoreTarget(ActionTarget pActionTarget)
inserts action into sorted array based on utility
Определения ActionTargets.c:461
bool IsRaycastResultException(RaycastRVResult res)
Initial raycast filtering exceptions (can't ask the entity type, sadly)
Определения ActionTargets.c:411
const float c_RayDistance
searching properties
Определения ActionTargets.c:840
PlayerBase m_Player
player owner
Определения ActionTargets.c:820
void FilterObstructedObjectsEx(Object cursor_target, array< Object > vicinityObjects)
Определения ActionTargets.c:576
void Clear()
Определения ActionTargets.c:225
vector m_RayStart
objects in vicinity
Определения ActionTargets.c:830
ref array< ref ActionTarget > m_Targets
selected & sorted targets by utility function
Определения ActionTargets.c:823
float ComputeUtility(Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos)
computes utility of target
Определения ActionTargets.c:490
const float c_ConeHeightMax
Определения ActionTargets.c:845
const float c_ConeHeightMin
Определения ActionTargets.c:844
CollisionFlags flags
Определения DayZPhysics.c:63
int component
index of component in corresponding geometry level
Определения DayZPhysics.c:107
vector pos
position of collision (in world coord)
Определения DayZPhysics.c:103
Object parent
if hierLevel > 0 most parent of the proxy object
Определения DayZPhysics.c:101
bool includeWater
Include water in the surface detection, will return the water if it is higher than the surface.
Определения SurfaceInfo.c:103
SurfaceDetectionType type
Type of surface to detect.
Определения SurfaceInfo.c:97
RoadSurfaceDetection rsd
See RoadSurfaceDetection, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:112
vector position
3D position to trace the surface from
Определения SurfaceInfo.c:100
UseObjectsMode syncMode
See UseObjectsMode, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:106
SurfaceInfo surface
Returned SurfaceInfo, plain pointer.
Определения SurfaceInfo.c:134
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
Определения dayzplayer.c:56
class LOD Object
CollisionFlags
Определения EnDebug.c:141

Перекрестные ссылки ActionTarget(), c_ConeAngle, c_ConeHeightMax, c_ConeHeightMin, c_MaxTargetDistance, c_RayDistance, Clear(), RaycastRVResult::component, ComputeUtility(), DayZPlayerCamera(), DayZPlayerUtils(), FilterDuplicateVicinityObjects(), FilterObstructedObjectsEx(), RaycastRVParams::flags, g_Game, DiagMenu::GetBool(), hitFraction, SurfaceDetectionParameters::includeWater, IsRaycastResultException(), m_HitPos, m_Player, m_RayEnd, m_RayStart, m_SortedResults, m_SurfaceInfo, m_Targets, RaycastRVResult::parent, RaycastRVResult::pos, SurfaceDetectionParameters::position, DayZPhysics::RayCastBullet(), DayZPhysics::RaycastRVProxy(), SurfaceDetectionParameters::rsd, SortResultsDistance(), StoreTarget(), SurfaceDetectionResult::surface, surfaceName, SurfaceDetectionParameters::syncMode, SurfaceDetectionParameters::type и vector::Zero.