void HdStreamTaskController::_CreateLightingTasks() { // Simple lighting task uses lighting state from Sprims. _simpleLightTaskId = GetControllerId().AppendChild( _tokens->simpleLightTask); HdxSimpleLightTaskParams simpleLightParams; simpleLightParams.cameraPath = _cameraId; GetRenderIndex()->InsertTask<HdxSimpleLightTask>(&_delegate, _simpleLightTaskId); _delegate.SetParameter(_simpleLightTaskId, HdTokens->params, simpleLightParams); _delegate.SetParameter(_simpleLightTaskId, HdTokens->children, SdfPathVector()); _simpleLightBypassTaskId = GetControllerId().AppendChild( _tokens->simpleLightBypassTask); // Simple lighting bypass task uses lighting state from a lighting // context. HdxSimpleLightBypassTaskParams simpleLightBypassParams; simpleLightBypassParams.cameraPath = _cameraId; GetRenderIndex()->InsertTask<HdxSimpleLightBypassTask>(&_delegate, _simpleLightBypassTaskId); _delegate.SetParameter(_simpleLightBypassTaskId, HdTokens->params, simpleLightBypassParams); _delegate.SetParameter(_simpleLightBypassTaskId, HdTokens->children, SdfPathVector()); }
void HdStreamTaskController::_CreateRenderTasks() { // Create two render tasks, one to create a color render, the other // to create an id render (so we don't need to thrash params). _renderTaskId = GetControllerId().AppendChild(_tokens->renderTask); _idRenderTaskId = GetControllerId().AppendChild(_tokens->idRenderTask); HdxRenderTaskParams renderParams; renderParams.camera = _cameraId; renderParams.viewport = GfVec4d(0,0,1,1); HdRprimCollection collection(HdTokens->geometry, HdTokens->smoothHull); collection.SetRootPath(SdfPath::AbsoluteRootPath()); SdfPath const renderTasks[] = { _renderTaskId, _idRenderTaskId, }; for (size_t i = 0; i < sizeof(renderTasks)/sizeof(renderTasks[0]); ++i) { GetRenderIndex()->InsertTask<HdxRenderTask>(&_delegate, renderTasks[i]); _delegate.SetParameter(renderTasks[i], HdTokens->params, renderParams); _delegate.SetParameter(renderTasks[i], HdTokens->children, SdfPathVector()); _delegate.SetParameter(renderTasks[i], HdTokens->collection, collection); } }
void UShooterLocalPlayer::LoadSaveGame() { auto SlotName = GetNickname(); auto UserIndex = GetControllerId(); //#if PLATFORM_WOLF // FPlatformMisc::GetUniqueStringNameForControllerId(UserIdex, SaveGameName); //#endif if (nullptr != SaveGame) { if (SaveGame->GetUserIndex() != UserIndex || SaveGame->GetSlotName() != SlotName) { SaveGame->SaveIfDirty(); SaveGame = nullptr; } } if (nullptr == SaveGame) { const auto IdentityInterface = Online::GetIdentityInterface(); if (IdentityInterface.IsValid() && GetPreferredUniqueNetId().IsValid()) { UserIndex = IdentityInterface->GetPlatformUserIdFromUniqueNetId(*GetPreferredUniqueNetId()); } SaveGame = UShooterSaveGame::Load(SlotName, UserIndex); } }
/** * Register all delegates needed to manage online sessions */ void UOnlineSessionClient::RegisterOnlineDelegates(UWorld* InWorld) { IOnlineSubsystem* OnlineSub = Online::GetSubsystem(InWorld); if (OnlineSub) { SessionInt = OnlineSub->GetSessionInterface(); if (SessionInt.IsValid()) { int32 ControllerId = GetControllerId(); if (ControllerId != INVALID_CONTROLLERID) { // Always on the lookout for invite acceptance (via actual invite or join from external ui) OnSessionInviteAcceptedDelegate = FOnSessionInviteAcceptedDelegate::CreateUObject(this, &UOnlineSessionClient::OnSessionInviteAccepted); SessionInt->AddOnSessionInviteAcceptedDelegate(ControllerId, OnSessionInviteAcceptedDelegate); } } OnJoinSessionCompleteDelegate = FOnJoinSessionCompleteDelegate::CreateUObject(this, &UOnlineSessionClient::OnJoinSessionComplete); OnEndForJoinSessionCompleteDelegate = FOnEndSessionCompleteDelegate::CreateUObject(this, &UOnlineSessionClient::OnEndForJoinSessionComplete); OnDestroyForJoinSessionCompleteDelegate = FOnDestroySessionCompleteDelegate::CreateUObject(this, &UOnlineSessionClient::OnDestroyForJoinSessionComplete); } // Register disconnect delegate even if we don't have an online system OnDestroyForMainMenuCompleteDelegate = FOnDestroySessionCompleteDelegate::CreateUObject(this, &UOnlineSessionClient::OnDestroyForMainMenuComplete); }
void ConnectionAspectPostpone::IncompleteInjectionState() const { bool success; DoseC_IncompleteInjectionState(GetControllerId(), success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } }
void ConnectionAspectPostpone::ResumePostponed() const { bool success; DoseC_ResumePostponed(GetControllerId(), success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } }
void ConnectionAspectPostpone::Postpone(const bool redispatchCurrent) const { bool success; DoseC_Postpone(GetControllerId(),redispatchCurrent, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } }
//----------------------- // Debug //----------------------- void ConnectionAspectMisc::SimulateOverflows(const bool inQueues, const bool outQueues) const { bool success; DoseC_SimulateOverflows(GetControllerId(), inQueues, outQueues, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } }
const std::wstring ConnectionAspectMisc::GetConnectionNameInstancePart() const { const char* name; bool success; DoseC_GetConnectionNameInstancePart(GetControllerId(), name, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } return Typesystem::Utilities::ToWstring(name); }
const CallbackId::Enumeration ConnectionAspectMisc::GetCurrentCallbackId() const { DotsC_Int32 callback; bool success; DoseC_GetCurrentCallbackId(GetControllerId(),callback, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } return static_cast<CallbackId::Enumeration>(callback); }
Safir::Dob::Typesystem::Int32 ConnectionAspectMisc::GetQueueSize(const Safir::Dob::ConnectionQueueId::Enumeration queue) const { Safir::Dob::Typesystem::Int32 queueSize; bool success; DoseC_GetQueueSize(GetControllerId(), queue, queueSize, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } return queueSize; }
Dob::Typesystem::Int32 ConnectionAspectMisc::GetContext() const { Dob::Typesystem::Int32 context; bool success; DoseC_GetContext(GetControllerId(), context, success); if (!success) { Typesystem::LibraryExceptions::Instance().Throw(); } return context; }
void UShooterLocalPlayer::LoadPersistentUser() { // if we changed controllerid / user, then we need to load the appropriate persistent user. if (PersistentUser != nullptr && ( GetControllerId() != PersistentUser->GetUserIndex() || GetNickname() != PersistentUser->GetName() ) ) { PersistentUser->SaveIfDirty(); PersistentUser = nullptr; } if (PersistentUser == NULL) { // Use the platform id here to be resilient in the face of controller swapping and similar situations. FPlatformUserId PlatformId = GetControllerId(); auto Identity = Online::GetIdentityInterface(); if (Identity.IsValid() && GetPreferredUniqueNetId().IsValid()) { PlatformId = Identity->GetPlatformUserIdFromUniqueNetId(*GetPreferredUniqueNetId()); } PersistentUser = UShooterPersistentUser::LoadPersistentUser( GetNickname(), PlatformId ); } }
void HdStreamTaskController::_CreateCamera() { // Create a default camera, driven by SetCameraMatrices. _cameraId = GetControllerId().AppendChild(_tokens->camera); GetRenderIndex()->InsertSprim(HdPrimTypeTokens->camera, &_delegate, _cameraId); _delegate.SetParameter(_cameraId, HdStCameraTokens->windowPolicy, VtValue()); _delegate.SetParameter(_cameraId, HdStCameraTokens->matrices, HdStCameraMatrices()); _delegate.SetParameter(_cameraId, HdStCameraTokens->clipPlanes, VtValue(std::vector<GfVec4d>())); }
void UShooterLocalPlayer::SetControllerId(int32 NewControllerId) { ULocalPlayer::SetControllerId(NewControllerId); // if we changed controllerid / user, then we need to load the appropriate persistent user. if (PersistentUser != nullptr && ( GetControllerId() != PersistentUser->GetUserIndex() || GetNickname() != PersistentUser->GetName() ) ) { PersistentUser->SaveIfDirty(); PersistentUser = nullptr; } if (!PersistentUser) { LoadPersistentUser(); } }
/** * Tear down all delegates used to manage online sessions */ void UOnlineSessionClient::ClearOnlineDelegates(UWorld* InWorld) { IOnlineSubsystem* OnlineSub = Online::GetSubsystem(InWorld); if (OnlineSub) { if (SessionInt.IsValid()) { int32 ControllerId = GetControllerId(); if (ControllerId != INVALID_CONTROLLERID) { SessionInt->ClearOnSessionInviteAcceptedDelegate(ControllerId, OnSessionInviteAcceptedDelegate); } } } SessionInt = NULL; }
FString UShooterLocalPlayer::GetNickname() const { FString UserNickName = Super::GetNickname(); if ( UserNickName.Len() > MAX_PLAYER_NAME_LENGTH ) { UserNickName = UserNickName.Left( MAX_PLAYER_NAME_LENGTH ) + "..."; } bool bReplace = (UserNickName.Len() == 0); // Check for duplicate nicknames...and prevent reentry static bool bReentry = false; if(!bReentry) { bReentry = true; UShooterGameInstance* GameInstance = GetWorld() != NULL ? Cast<UShooterGameInstance>(GetWorld()->GetGameInstance()) : NULL; if(GameInstance) { // Check all the names that occur before ours that are the same const TArray<ULocalPlayer*>& LocalPlayers = GameInstance->GetLocalPlayers(); for (int i = 0; i < LocalPlayers.Num(); ++i) { const ULocalPlayer* LocalPlayer = LocalPlayers[i]; if( this == LocalPlayer) { break; } if( UserNickName == LocalPlayer->GetNickname()) { bReplace = true; break; } } } bReentry = false; } if ( bReplace ) { UserNickName = FString::Printf( TEXT( "Player%i" ), GetControllerId() + 1 ); } return UserNickName; }
void HdStreamTaskController::_CreateSelectionTask() { // Create a selection highlighting task. _selectionTaskId = GetControllerId().AppendChild(_tokens->selectionTask); HdxSelectionTaskParams selectionParams; selectionParams.enableSelection = true; selectionParams.selectionColor = GfVec4f(1,1,0,1); selectionParams.locateColor = GfVec4f(0,0,1,1); GetRenderIndex()->InsertTask<HdxSelectionTask>(&_delegate, _selectionTaskId); _delegate.SetParameter(_selectionTaskId, HdTokens->params, selectionParams); _delegate.SetParameter(_selectionTaskId, HdTokens->children, SdfPathVector()); }
/** * Transition from destroying a session to joining a new one of the same name * * @param SessionName name of session recently destroyed * @param bWasSuccessful was the destroy attempt successful */ void UOnlineSessionClient::OnDestroyForJoinSessionComplete(FName SessionName, bool bWasSuccessful) { UE_LOG(LogOnline, Verbose, TEXT("OnDestroyForJoinSessionComplete %s bSuccess: %d"), *SessionName.ToString(), bWasSuccessful); if (SessionInt.IsValid()) { SessionInt->ClearOnDestroySessionCompleteDelegate(OnDestroyForJoinSessionCompleteDelegate); } if (bWasSuccessful) { int32 ControllerId = GetControllerId(); if (ControllerId != INVALID_CONTROLLERID) { JoinSession(ControllerId, SessionName, CachedSessionResult); } } bHandlingDisconnect = false; }
/** * Delegate fired when an invite request has been accepted (via external UI) * * @param LocalUserNum local user accepting invite * @param bWasSuccessful true if the async action completed without error, false if there was an error * @param SearchResult search result containing the invite data */ void UOnlineSessionClient::OnSessionInviteAccepted(int32 LocalUserNum, bool bWasSuccessful, const FOnlineSessionSearchResult& SearchResult) { UE_LOG(LogOnline, Verbose, TEXT("OnSessionInviteAccepted LocalUserNum: %d bSuccess: %d"), LocalUserNum, bWasSuccessful); // Don't clear invite accept delegate if (bWasSuccessful) { if (SearchResult.IsValid()) { bIsFromInvite = true; check(GetControllerId() == LocalUserNum); JoinSession(LocalUserNum, GameSessionName, SearchResult); } else { UE_LOG(LogOnline, Warning, TEXT("Invite accept returned no search result.")); } } }
FString UShooterLocalPlayer::GetNickname() const { auto Nickname = Super::GetNickname(); auto bReplace = (Nickname.Len() == 0); static bool bReentry = false; if (!bReentry) { bReentry = true; const auto World = GetWorld(); if (nullptr != World) { const auto GameInstance = World->GetGameInstance(); if (nullptr != GameInstance) { const auto LocalPlayers = GameInstance->GetLocalPlayers(); for (auto i : LocalPlayers) { if (this == i) { break; } if (i->GetNickname() == Nickname) { bReplace = true; break; } } } } bReentry = false; } if (bReplace) { Nickname = FString::Printf(TEXT("Player%i"), GetControllerId() + 1); } return Nickname; }