Advertisement
Dirt113

DHGameSession.h

Nov 22nd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.28 KB | None | 0 0
  1. // Copyright 2015 Dirt Productions. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include "GameFramework/GameSession.h"
  6. #include "Public/Data/DHGameSessionData.h"
  7. #include "DHGameSession.generated.h"
  8.  
  9. /** FNetworkSessionParams
  10. * Declared: DHGameSessionData.h
  11. *
  12. * Holds properties about a network game session
  13. */
  14. struct FNetworkSessionParams
  15. {
  16. public:
  17.     /** Default constructor */
  18.     FNetworkSessionParams() : SessionID(NAME_None), bIsPresence(false), BestSessionIndex(NULL), SessionHostType(ENetworkSessionHostType::HostLocalUnauthed) {}
  19.     /** Constructor with values
  20.     *
  21.     * @param SessionID              Identifier of session
  22.     * @param bIsPresence            True if presence is enabled, otherwise false
  23.     * @param BestSessionIndex       Index of current search result choice
  24.     * @param SessionHostType        Host type of session
  25.     * @param HostID             Identifier of player host
  26.     */
  27.     FNetworkSessionParams(FName InSessionID, bool bInIsPresence, int32 InBestSessionIndex, ENetworkSessionHostType InSessionHostType, TSharedPtr<FUniqueNetId> InHostID)
  28.     {
  29.         SessionID = InSessionID;
  30.         bIsPresence = bInIsPresence;
  31.         BestSessionIndex = InBestSessionIndex;
  32.         SessionHostType = InSessionHostType;
  33.         HostID = InHostID;
  34.     }
  35.  
  36.     /* ///////////////////////// VARIABLES ///////////////////////// */
  37. public:
  38.     /** Identifier of session */
  39.     FName SessionID;
  40.  
  41.     /** True if presence is enabled, otherwise false */
  42.     bool bIsPresence;
  43.  
  44.     /** Index of current search result choice */
  45.     int32 BestSessionIndex;
  46.  
  47.     /** Network host type */
  48.     ENetworkSessionHostType SessionHostType;
  49.  
  50.     /** Identifier of player host */
  51.     TSharedPtr<FUniqueNetId> HostID;
  52. };
  53.  
  54. /** ADHGameSession : AGameSession
  55.  * Declared: DHGameSession.h
  56.  *
  57.  * Manages sessions of game
  58.  */
  59. UCLASS()
  60. class DISTANTHOME_API ADHGameSession : public AGameSession
  61. {
  62.     GENERATED_BODY()
  63.    
  64. public:
  65.     /** Default constructor */
  66.     ADHGameSession(const FObjectInitializer& ObjectInitializer);
  67.  
  68.     /* ///////////////////////// VARIABLES ///////////////////////// */
  69. protected:
  70.     /* ////////// SESSION DELEGATES ////////// */
  71.  
  72.     /** Delegate for creating a new session */
  73.     FOnCreateSessionCompleteDelegate OnCreateSessionCompleteDelegate;
  74.    
  75.     /** Delegate after starting a session */
  76.     FOnStartSessionCompleteDelegate OnStartSessionCompleteDelegate;
  77.  
  78.     /** Delegate for destroying a session */
  79.     FOnDestroySessionCompleteDelegate OnDestroySessionCompleteDelegate;
  80.  
  81.     /** Delegate for searching for sessions */
  82.     FOnFindSessionsCompleteDelegate OnFindSessionsCompleteDelegate;
  83.  
  84.     /** Delegate after joining a session */
  85.     FOnJoinSessionCompleteDelegate OnJoinSessionCompleteDelegate;
  86.  
  87.     /* ////////// SESSION VARIABLES ////////// */
  88.  
  89.     /** Transient properties of a session curing game creation/matchmaking */
  90.     FNetworkSessionParams CurrentSessionParams;
  91.  
  92.     /** Current host settings */
  93.     TSharedPtr<FNetworkSessionParams> HostSettings;
  94.  
  95.     /* ///////////////////////// FUNCTIONS ///////////////////////// */
  96. protected:
  97.     /* ////////// SESSION DELEGATES ////////// */
  98.  
  99.     /** Delegate fired when session start request has been completed
  100.      *
  101.      * @param SessionName       The session's name this callback corresponds to
  102.      * @param bWasSuccessful    True if the async action has succeeded, otherwise false
  103.      */
  104.     virtual void OnCreateSessionComplete(FName SessionName, bool bWasSuccessful);
  105.  
  106.     /** Delegate fired when session start request has been completed
  107.      *
  108.      * @param bWasSuccessful    True if the async action has succeeded, otherwise false
  109.      */
  110.     void OnStartOnlineGameComplete(FName SessionName, bool bWasSuccessful);
  111.  
  112.     /** Delegate fired when a session search query has completed
  113.      *
  114.      * @param SessionName       The session's name this callback corresponds to
  115.      * @param Result            Result of the async action
  116.      */
  117.     void OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result);
  118.  
  119.     /** Delegate fired when destroying a session is completed
  120.      *
  121.      * @param SessionName       The session's name this callback corresponds to
  122.      * @param bWasSuccessful    True if the async action has succeeded, otherwise false
  123.      */
  124.     virtual void OnDestroySessionComplete(FName SessionName, bool bWasSuccessful);
  125.  
  126.     /* ////////// SESSION FUNCTIONS ////////// */
  127.  
  128.     /** Resets the variables keeping track of session join attempts */
  129.     void ResetBestSessionVars();
  130.  
  131.     /** Choose the best session from a list of search results based on game criteria */
  132.     void ChooseBestSession();
  133.  
  134.     /** Entry point for matchmaking after search results are returned */
  135.     void StartMatchmaking();
  136.  
  137.     /** Return point after each attempt to join a search result */
  138.     void ContinueMatchmaking();
  139.  
  140.     /** Delegate triggered when no more search results are available */
  141.     void OnNoMatchesAvailable();
  142.    
  143.     /** Event fired when a presence session is created
  144.      *
  145.      * @param SessionName       Name of session that was created
  146.      * @param bWasSuccessful    Was the session creation successful?
  147.      */
  148.     DECLARE_EVENT_TwoParams(ADHGameSession, FOnCreatePresenseSessionComplete, FName, bool);
  149.     FOnCreatePresenseSessionComplete CreatePresenseSessionCompleteEvent;
  150.  
  151.     /** Event fired when a session is joined
  152.      *
  153.      * @param SessioNname       Name of session that was joined
  154.      * @param Result            Result of session join action
  155.      */
  156.     DECLARE_EVENT_OneParam(ADHGameSession, FOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type);
  157.     FOnJoinSessionComplete JoinSessionCompleteEvent;
  158.  
  159.  
  160. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement