Guest User

Untitled

a guest
Jan 15th, 2018
1,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
  3.  */
  4.  
  5. class AIVisibilityManager extends Object
  6.     native(AI);
  7.  
  8. /** Number deep we should start in the controller list for queueing up vis requests
  9.  *   (facilitates round-robin sight check queueing)
  10.  */
  11. var int ControllerIttStartPoint;
  12.  
  13. /** debug bool, when this is enabled all visibility test results will be drawn **/
  14. var bool bDrawVisTests;
  15.  
  16. /** List of free linecheckresutls **/
  17. var private const native noexport pointer FreeLineCheckResList{LineCheckResult};
  18. /** List of linecheckresults which are currently awaiting update by physics **/
  19. var private const native noexport pointer BusyLineCheckResList{LineCheckResult};
  20.  
  21. var private const native noexport pointer PendingLineCheckHead{LineCheckResult};
  22. var private const native noexport pointer PendingLineCheckTail{LineCheckResult};
  23.  
  24. /** when Init() is called, a pool of LineCheckResults will be created, with this many elements in it **/
  25. const PoolSize = 50;
  26. const MaxLineChecksPerFrame = 15;
  27.  
  28. //@note: if you change this, grenade fog volumes need to be fixed up to use the correct collision for blocking AI visibility
  29. const bUseAsyncLineChecksForVisibility = 0;
  30.  
  31. cpptext
  32. {
  33.     class LineCheckResult: public FAsyncLineCheckResult
  34.     {
  35.  
  36.     public:
  37.         typedef UBOOL (AGearAI::*ShouldLineCheckCb)( APawn *E, FVector& LineChkStart, FVector& LineChkEnd );
  38.         typedef void (AGearAI::*FinishedCallback)(APawn* TestedPawn, UBOOL bVisible, FVector& VisLoc );
  39.  
  40.         LineCheckResult() :
  41.           FAsyncLineCheckResult()
  42.           ,TestingAI(NULL)
  43.           ,PawnToTestAgainst(NULL)
  44.           ,bStale(FALSE)
  45.           ,Next(NULL)
  46.           ,FinishedCallBackFunction(NULL)
  47.           ,ShouldCheckFunction(NULL)
  48.           ,CheckStart(0.f)
  49.           ,CheckEnd(0.f)
  50.           {}
  51.  
  52.         void InitLineCheck(AGearAI* InTestingAI, APawn* InPawnToTestAgainst, ShouldLineCheckCb ShouldCheckCallBack, FinishedCallback FinCallback)
  53.         {
  54.             TestingAI = InTestingAI;
  55.             PawnToTestAgainst = InPawnToTestAgainst;
  56.             FinishedCallBackFunction = FinCallback;
  57.             ShouldCheckFunction = ShouldCheckCallBack;
  58.             bCheckStarted = FALSE;
  59.             bCheckCompleted = FALSE;
  60.             bHit = FALSE;
  61.             bStale=FALSE;
  62.         }
  63.  
  64.         void TestFinished()
  65.         {
  66.             if(bStale == FALSE && TestingAI && FinishedCallBackFunction)
  67.             {
  68.                 ((*TestingAI).*FinishedCallBackFunction)(PawnToTestAgainst,!bHit,CheckEnd);
  69.             }
  70.         }
  71.  
  72.         virtual void Serialize( FArchive& Ar )
  73.         {
  74.             Ar << TestingAI;
  75.             Ar << PawnToTestAgainst;
  76.         }
  77.  
  78.         /**
  79.          * calls ShouldCheckCallback to determine endpoints for linecheck, and see if we should early out
  80.          * @return returns TRUE if a sight check was queued
  81.          */
  82.         UBOOL TriggerLineCheck();
  83.  
  84.         /** Pawn we're testing from **/
  85.         AGearAI* TestingAI;
  86.         /** Pawn we're testing to **/
  87.         APawn* PawnToTestAgainst;
  88.  
  89.         /** Bool that indicates one or both of the pawns involved in this linecheck have been deleted, so don't call the callback if this is true! **/
  90.         UBOOL bStale;
  91.  
  92.         LineCheckResult* Next;
  93.  
  94.         FinishedCallback FinishedCallBackFunction;
  95.         ShouldLineCheckCb ShouldCheckFunction;
  96.  
  97.         // The start/end of this line check
  98.         // Visibility position is marked at CheckEnd because target likely moved during the async check
  99.         FVector CheckStart, CheckEnd;
  100.     };
  101.  
  102. public:
  103.     UAIVisibilityManager() :
  104.       FreeLineCheckResList(NULL)
  105.       ,BusyLineCheckResList(NULL)
  106.       ,PendingLineCheckHead(NULL)
  107.       ,PendingLineCheckTail(NULL)
  108.     {
  109.         if (!IsTemplate())
  110.         {
  111.             Init();
  112.         }
  113.     }
  114.     virtual void FinishDestroy()
  115.     {
  116.         Super::FinishDestroy();
  117.         Flush();
  118.     }
  119.  
  120.  
  121.     /** RequestSightCheckForAToB
  122.         * Will return the current known status of the test requested, and kick off a new test if needed
  123.         * @param PawnA  - the pawn who wants to do a sight check
  124.         * @param PawnB  - the pawn to sight check against (e.g. PawnA wants to know if it can see pawnB)
  125.         * @param FromPt - start point for Line Check
  126.         * @param ToPt   - end point for Line Check
  127.         * @param Cb   - callback function to call when we have a result
  128.         */
  129.     UBOOL RequestSightCheck(AGearAI* InTestingAI, APawn* PawnToTest, LineCheckResult::ShouldLineCheckCb ShouldCheckCb, LineCheckResult::FinishedCallback FinishedCb);
  130.     /** iterates through the list of pending tests to see if they're done **/
  131.     void Tick(FLOAT DeltaTime);
  132.     /** wipes all records and pending tests MT->how do we do this safely? (physics might still have a ptr) **/
  133.     void Flush();
  134.  
  135.     void Init();
  136.  
  137.     virtual void AddReferencedObjects(TArray<UObject*>& ObjectArray);
  138. private:
  139.    /** AddBackToPool
  140.     * moves LineCheckRes from the busy list to the free list
  141.     * @param LineCheckResToMove - the line check to move
  142.     * @param PrevLineCheckRes - the line check result in the list just before the one we're moving
  143.     */
  144.     void AddBackToPool(LineCheckResult* LineCheckResToMove, LineCheckResult* PrevLineCheckRes, LineCheckResult*& DestPool, LineCheckResult*& SrcPool);
  145.  
  146.     /**
  147.      * iterates over busy line check results checking to see if they've gotten a result back yet, if so move them back to free lsit
  148.      */
  149.     void UpdateBusyLineChecks();
  150.  
  151.     /**
  152.      * initiates requests to physics for pending line checks until we hit the max per frame
  153.      */
  154.     void DoPhysRequestsForPendingLineChecks();
  155.  
  156.     /**
  157.      * (replaces ShowSelf() iterates over all controllers and queues up line check requests when neccesary
  158.      *  This replaces ShowSelf so that we can rotate through the controller list round-robin style and make sure everyone gets
  159.      *  a sight result
  160.      */
  161.     void QueueUpVisRequests();
  162.  
  163.     UBOOL SuccessfullyShowedController(AController* Controller);
  164.  
  165.     LineCheckResult* FreeLineCheckResList;
  166.     LineCheckResult* BusyLineCheckResList;
  167.     LineCheckResult* PendingLineCheckHead;
  168.     LineCheckResult* PendingLineCheckTail;
  169.  
  170. }
  171.  
  172. final native function NotifyPawnDestroy(Pawn Pawn);
  173.  
  174. // flushes the pool, and re-initializes it
  175. final native function Reset();
Add Comment
Please, Sign In to add comment