Advertisement
Guest User

M

a guest
Feb 27th, 2017
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "MusicalRange.h"
  4. #include "MusicalRangeInstance.h"
  5. //#include "OnlineSubsystemSteam.h"
  6. //#include "ThirdParty/Steamworks/Steamv132/sdk/public/steam/steam_api.h"
  7.  
  8. //UE_LOG(LogSteamworks, Log, TEXT("Message!"));
  9.  
  10.  
  11. //Musical Range Game Instance Elements
  12. UMusicalRangeInstance::UMusicalRangeInstance() {
  13.     if (SteamAPI_Init())
  14.     {
  15.         UE_LOG(LogSteamworks, Log, TEXT("UMusicalRangeInstance Constructor Called"));
  16.         CallbackAsyncVariable = new FSteamworksCallbackAsync();
  17.         UE_LOG(LogSteamworks, Log, TEXT("Assigning Game Instance object to CallbackAsyncVariable"));
  18.         CallbackAsyncVariable->AssignGameInstance(this);
  19.     }
  20.     else
  21.     {
  22.         UE_LOG(LogSteamworks, Warning, TEXT("UMusicalRangeInstance Constructor FAILED! No Steam Log on"));
  23.     }
  24. }
  25.  
  26. UMusicalRangeInstance::~UMusicalRangeInstance() {
  27.     if (CallbackAsyncVariable != nullptr)
  28.     {
  29.         UE_LOG(LogSteamworks, Log, TEXT("Deleting CallbackAsyncPointer"));
  30.         delete CallbackAsyncVariable;
  31.     }
  32. }
  33.  
  34. bool UMusicalRangeInstance::InterLevelPersitentValuePONE() {
  35.     InterLevelPersitentValue++;
  36.     return true;
  37. }
  38.  
  39. bool UMusicalRangeInstance::RunSteamCallbacks() {
  40.     SteamAPI_RunCallbacks();
  41.     return true;
  42. }
  43.  
  44. void UMusicalRangeInstance::SteamOverlayActive() {
  45.     SteamAPICall_t hSteamAPICall = SteamUtils()->IsOverlayEnabled();
  46.     m_callResultGameOverlayActive.Set(hSteamAPICall, this, &UMusicalRangeInstance::OnSteamOverlayEnabled);
  47.     return;
  48. }
  49.  
  50. void UMusicalRangeInstance::OnSteamOverlayEnabled(GameOverlayActivated_t *pResult, bool bIOFailure) {
  51.     IsSteamOverlayActive = (pResult->m_bActive != 0);
  52.     if (IsSteamOverlayActive)
  53.     {
  54.         UE_LOG(LogSteamworks, Log, TEXT("Overlay is ACTIVE"));
  55.     }
  56.     else
  57.     {
  58.         UE_LOG(LogSteamworks, Log, TEXT("Overlay is OFF"));
  59.     }  
  60.     OnSteamOverlayIsActive(IsSteamOverlayActive);
  61.     return;
  62. }
  63.  
  64. //FSteamworksCallbackAsync elements
  65. FSteamworksCallbackAsync::FSteamworksCallbackAsync() :
  66.     OnSteamOverlayActiveCallback(this, &FSteamworksCallbackAsync::OnSteamOverlayActive)
  67. {
  68.     UE_LOG(LogSteamworks, Log, TEXT("Initializing FSteamworksCallbackAsync"));
  69.     if (GEngine && GEngine->GetWorld() != nullptr)
  70.     {
  71.         UE_LOG(LogSteamworks, Log, TEXT("Creating new LiveSteamSubsystem"));
  72.         LiveSteamSubsystem = new FOnlineSubsystemSteam();
  73.         UE_LOG(LogSteamworks, Log, TEXT("Initializing LiveSteamSubsystem"));
  74.         if (LiveSteamSubsystem->Init())
  75.         {
  76.             UE_LOG(LogSteamworks, Log, TEXT("LiveSteamSubsystem Succesfully Activated!"));
  77.         }
  78.         else {
  79.             UE_LOG(LogSteamworks, Error, TEXT("LiveSteamSubsystem FAILED!"));
  80.         }
  81.     }
  82.     UE_LOG(LogSteamworks, Warning, TEXT("LiveSteamSubsystem Not Created. GEngine OR GetWorld() not valid!"));
  83. }
  84.  
  85. FSteamworksCallbackAsync::~FSteamworksCallbackAsync() {
  86.     if (LiveSteamSubsystem != nullptr)
  87.     {
  88.         UE_LOG(LogSteamworks, Log, TEXT("Shutting Down LiveSteamSubsystem"));
  89.         LiveSteamSubsystem->Shutdown();
  90.         UE_LOG(LogSteamworks, Log, TEXT("Deleting LiveSteamSubsystem"));
  91.         delete LiveSteamSubsystem;
  92.     }
  93. }
  94.  
  95. void FSteamworksCallbackAsync::AssignGameInstance(UMusicalRangeInstance *NewMusicalRangeGameInstance) {
  96.     MusicalRangeGameInstance = NewMusicalRangeGameInstance;
  97.     UE_LOG(LogSteamworks, Log, TEXT("New Musical Range Game Instance Assigned to CallbackAsyncVariable"));
  98. }
  99.  
  100. void FSteamworksCallbackAsync::OnSteamOverlayActive(GameOverlayActivated_t *CallbackData) {
  101.    
  102.     check(CallbackData != nullptr);
  103.  
  104.     //Copy the CallbacData as it may be deleted to quickly https://answers.unrealengine.com/questions/569160/game-crash-runnable-thread-onlineasynctaskthreadst.html
  105.     const bool IsOverlayActive = (CallbackData->m_bActive != 0);
  106.  
  107.     LiveSteamSubsystem->ExecuteNextTick([IsOverlayActive, this]() {
  108.         if (IsOverlayActive)
  109.         {
  110.             UE_LOG(LogSteamworks, Log, TEXT("Overlay is ACTIVE"));
  111.         }
  112.         else
  113.         {
  114.             UE_LOG(LogSteamworks, Log, TEXT("Overlay is OFF"));
  115.         }
  116.         if (MusicalRangeGameInstance != nullptr)
  117.         {
  118.             UE_LOG(LogSteamworks, Log, TEXT("Calling Event OnSteamOverlayIsActive"));
  119.             MusicalRangeGameInstance->OnSteamOverlayIsActive(IsOverlayActive);
  120.             UE_LOG(LogSteamworks, Log, TEXT("Music Should be paused now"));
  121.         }
  122.         else
  123.         {
  124.             UE_LOG(LogSteamworks, Error, TEXT("Error with Musical Range Game Instance Pointer!"));
  125.             UE_LOG(LogSteamworks, Error, TEXT("OnSteamOverlayActive WILL NOT FIRING!"));
  126.         }
  127.     });
  128. }
Advertisement
RAW Paste Data Copied
Advertisement