VisualU 1.2.1
Plugin for Unreal Engine 5 that brings core functionality for a widget-based visual novel game
 
Loading...
Searching...
No Matches
UVisualController Class Reference

Organizes scenes described by FScenario in a meaningful way. More...

#include <VisualController.h>

Inheritance diagram for UVisualController:

Public Member Functions

 UVisualController (const FObjectInitializer &ObjectInitializer=FObjectInitializer::Get())
 
virtual void BeginDestroy () override
 Brings controller to idle state before destruction.
 
virtual void PreSave (FObjectPreSaveContext SaveContext) override
 Brings controller to idle state before serialization.
 
virtual void PostInitProperties () override
 Setups initial values to make controller operational.
 
virtual void SerializeController_Experimental (FArchive &Ar)
 Not ready for production code.
 
bool RequestNextScene ()
 Visualizes the next scene in the node.
 
bool RequestPreviousScene ()
 Visualizes the previous scene in the node.
 
bool RequestScene (const FScenario *Scene)
 Visualize any exhausted scene.
 
bool RequestScenario (const FScenario &Scenario)
 
const FScenarioGetSceneAt (int32 Index)
 Gets scene from the node at given position.
 
bool RequestNode (const UDataTable *NewNode)
 Sets provided node as active and visualizes the first scene in it.
 
bool RequestFastMove (EVisualControllerDirection::Type Direction=EVisualControllerDirection::Forward)
 Tries to activate fast move mode.
 
bool RequestAutoMove (EVisualControllerDirection::Type Direction=EVisualControllerDirection::Forward)
 Tries to activate auto move.
 
void CancelFastMove ()
 Ends fast move mode when it is active.
 
void CancelAutoMove ()
 Ends auto move mode when it is active.
 
void VisualizeToScreen (TSubclassOf< UVisualRenderer > RendererClass, int32 ZOrder=0)
 Reconstruct renderer to a new class if necessary and add it to the player screen.
 
void VisualizeToComponent (TSubclassOf< UVisualRenderer > RendererClass, UWidgetComponent *Component)
 Reconstructs renderer to a new class if necessary and add it to the widget component.
 
void RemoveFromScreen () const
 Removes renderer visualized to screen.
 
void SetRendererVisibility (ESlateVisibility Visibility)
 Sets renderer visibility.
 
ESlateVisibility GetRendererVisibility () const
 
void SetNumScenesToLoad (int32 Num)
 Setter for UVisualController::NumScenesToLoad.
 
FORCEINLINE int32 GetNumScenesToLoad () const
 
void ShouldPlayTransitions (bool bShouldPlay)
 Setter for UVisualController::bPlayTransitions.
 
FORCEINLINE bool PlaysTransitions () const
 
void ShouldPlaySound (bool bShouldPlay)
 Setter for UVisualController::bPlaySound.
 
FORCEINLINE bool PlaysSound () const
 
void SetAutoMoveDelay (float Delay)
 Setter for UVisualController::AutoMoveDelay.
 
FORCEINLINE float GetAutoMoveDelay () const
 
const FScenarioGetCurrentScene () const
 
const FScenarioGetCurrentScenario () const
 
bool CanAdvanceScene () const
 
bool CanRetractScene () const
 
bool IsWithChoice () const
 
bool IsSceneExhausted (const FScenario *Scene) const
 Is provided scene exhausted.
 
bool IsScenarioExhausted (const FScenario &Scenario) const
 
bool IsTransitioning () const
 Is renderer has transition ongoing.
 
bool IsCurrentScenarioHead () const
 
FORCEINLINE EVisualControllerMode GetMode () const
 
FORCEINLINE bool IsFastMoving () const
 
FORCEINLINE bool IsAutoMoving () const
 
FORCEINLINE bool IsIdle () const
 
const FString GetHeadDebugString () const
 Development only.
 
const FString GetAsyncQueueDebugString () const
 Development only.
 
const FString GetExhaustedScenesDebugString () const
 Development only.
 

Public Attributes

FOnSceneStart OnSceneStart
 Called when controller has switched to a different scenario.
 
FOnSceneEnd OnSceneEnd
 Called when controller is about to switch to a different scenario.
 
FOnFastMoveStart OnFastMoveStart
 Called when controller enters Fast Move mode.
 
FOnFastMoveEnd OnFastMoveEnd
 Called when controller exits Fast Move mode.
 
FOnAutoMoveStart OnAutoMoveStart
 Called when controller enters Auto Move mode.
 
FOnAutoMoveEnd OnAutoMoveEnd
 Called when controller exits Auto Move mode.
 

Protected Member Functions

TSharedPtr< FStreamableHandle > LoadSceneAsync (const FScenario *Scene, FStreamableDelegate AfterLoadDelegate=nullptr)
 Asynchronously load assets of the scene into the memory.
 
TSharedPtr< FStreamableHandle > LoadScene (const FScenario *Scene, FStreamableDelegate AfterLoadDelegate=nullptr)
 Synchronously load assets of the scene into the memory.
 
void PrepareScenes (EVisualControllerDirection::Type Direction=EVisualControllerDirection::Forward)
 Loads assets of future scenes.
 
void TryPlaySceneSound (TSoftObjectPtr< USoundBase > SceneSound) const
 Plays the scene sound when available.
 
void CancelNextScene ()
 Releases the handle for the assets of the next scene.
 
bool TryPlayTransition (const FScenario *From, const FScenario *To)
 Requests renderer to display transition animation.
 

Private Member Functions

void SetCurrentScene (const FScenario *Scene)
 Switch controller to the given scene, potentially switching node as well.
 
void AssertNextSceneLoad (EVisualControllerDirection::Type Direction=EVisualControllerDirection::Forward)
 Guarantees that the next requested scene assets will be loaded.
 

Private Attributes

TObjectPtr< UVisualRendererRenderer
 Responsible for visualizing scenes as widgets.
 
TSharedPtr< FStreamableHandle > NextSceneHandle
 Handle for assets of the scene that are loaded into the memory.
 
TArray< FScenario * > Node
 Currently active data table with scenes.
 
int32 SceneIndex
 Position of the current scene.
 
TQueue< TSharedPtr< FStreamableHandle > > SceneHandles
 Handles for resources of the following scenes.
 
TDeque< TWeakPtr< FStreamableHandle > > DebugSceneHandles {}
 Additional debug queue that gathers weak references to scenes that are meant to be loaded asynchronously.
 
TSet< const UDataTable * > NodeReferenceKeeper
 Maintains references to all data tables that currently own scenes that are referenced by controller.
 
TArray< FScenario * > ExhaustedScenes
 Last scenes of already processed nodes which could be made current again in the future.
 
const FScenarioHead
 So far, the deepest scene in Visual Controller.
 
TUniquePtr< UE::VisualU::Private::FFastMoveAsyncTaskFastMoveTask
 Task to be dispatched asynchronously to perform fast move.
 
FTSTicker::FDelegateHandle AutoMoveHandle
 Handle to the ticker that performs auto move.
 
int32 ScenesToLoad
 How many following scenes will be loaded asynchronously.
 
bool bPlayTransitions
 Should controller attempt to play transitions between scenes.
 
bool bPlaySound
 Will controller attempt to play scene sound.
 
float AutoMoveDelay
 How long, in seconds, controller should wait before moving to the next scene in auto move mode.
 
EVisualControllerMode Mode
 Current state of this controller.
 

Detailed Description

Organizes scenes described by FScenario in a meaningful way.

Must be created within APlayerController. Requires UVisualUSettings::FirstDataTable to be set at compile/editor time.

See also
UVisualUSettings FScenario

Member Function Documentation

◆ AssertNextSceneLoad()

void UVisualController::AssertNextSceneLoad ( EVisualControllerDirection::Type Direction = EVisualControllerDirection::Forward)
private

Guarantees that the next requested scene assets will be loaded.

Parameters
Directiondetermines what is the next scene e.g. controller going back to the beginning or forward towards the end of the node

◆ CanAdvanceScene()

bool UVisualController::CanAdvanceScene ( ) const
Returns
true when there is a scene in front of the current one

◆ CancelAutoMove()

void UVisualController::CancelAutoMove ( )

Ends auto move mode when it is active.

controller becomes idle.

◆ CancelFastMove()

void UVisualController::CancelFastMove ( )

Ends fast move mode when it is active.

controller becomes idle.

◆ CancelNextScene()

void UVisualController::CancelNextScene ( )
protected

Releases the handle for the assets of the next scene.

See also
UVisualController::NextSceneHandle

◆ CanRetractScene()

bool UVisualController::CanRetractScene ( ) const
Returns
true when there is a scene behind the current one

◆ GetAsyncQueueDebugString()

const FString UVisualController::GetAsyncQueueDebugString ( ) const

Development only.

Returns
debug information about asynchronous scene preparation
See also
UVisualController::DebugSceneHandles

◆ GetAutoMoveDelay()

FORCEINLINE float UVisualController::GetAutoMoveDelay ( ) const
inline
Returns
delay between scenes when controller is in auto move mode

◆ GetCurrentScenario()

const FScenario & UVisualController::GetCurrentScenario ( ) const
Returns
currently visualized scene.

◆ GetCurrentScene()

const FScenario * UVisualController::GetCurrentScene ( ) const
Returns
currently visualized scene.

◆ GetExhaustedScenesDebugString()

const FString UVisualController::GetExhaustedScenesDebugString ( ) const

Development only.

Returns
debug information about UVisualController::ExhaustedScenes

◆ GetHeadDebugString()

const FString UVisualController::GetHeadDebugString ( ) const

Development only.

Returns
debug information of the UVisualController::Head

◆ GetMode()

FORCEINLINE EVisualControllerMode UVisualController::GetMode ( ) const
inline

◆ GetNumScenesToLoad()

FORCEINLINE int32 UVisualController::GetNumScenesToLoad ( ) const
inline
Returns
number of scenes to load

◆ GetRendererVisibility()

ESlateVisibility UVisualController::GetRendererVisibility ( ) const
Returns
current renderer visibility

◆ GetSceneAt()

const FScenario * UVisualController::GetSceneAt ( int32 Index)

Gets scene from the node at given position.

Note
will trigger assertion for invalid index.
Parameters
Indexposition of the scene
Returns
valid scene

◆ IsAutoMoving()

FORCEINLINE bool UVisualController::IsAutoMoving ( ) const
inline
Returns
true when controller is in auto move mode
See also
UVisualController::GetMode() UVisualController::IsFastMoving() UVisualController::IsIdle()

◆ IsCurrentScenarioHead()

bool UVisualController::IsCurrentScenarioHead ( ) const
Returns
true when current scene is UVisualController::Head

◆ IsFastMoving()

FORCEINLINE bool UVisualController::IsFastMoving ( ) const
inline
Returns
true when controller is in fast move mode
See also
UVisualController::GetMode() UVisualController::IsAutoMoving() UVisualController::IsIdle()

◆ IsIdle()

FORCEINLINE bool UVisualController::IsIdle ( ) const
inline

◆ IsScenarioExhausted()

bool UVisualController::IsScenarioExhausted ( const FScenario & Scenario) const

◆ IsSceneExhausted()

bool UVisualController::IsSceneExhausted ( const FScenario * Scene) const

Is provided scene exhausted.

Note
scene is considered exhausted when it was already seen by player
Parameters
Scenescene to check for exhaustion
Returns
is scene considered exhausted
See also
UVisualController::ExhaustedScenes

◆ IsTransitioning()

bool UVisualController::IsTransitioning ( ) const

Is renderer has transition ongoing.

See also
UVisualRenderer::IsTransitionInProgress()
Returns
true for active scene transition

◆ IsWithChoice()

bool UVisualController::IsWithChoice ( ) const
Returns
is currently visualized scene has EScenarioMetaFlags::Choice set

◆ LoadScene()

TSharedPtr< FStreamableHandle > UVisualController::LoadScene ( const FScenario * Scene,
FStreamableDelegate AfterLoadDelegate = nullptr )
protected

Synchronously load assets of the scene into the memory.

Parameters
Scenescenario that provides assets to load
AfterLoadDelegatedelegate to execute after assets are loaded
Returns
handle to manage lifetime of streamed assets
See also
UVisualController::LoadSceneAsync()

◆ LoadSceneAsync()

TSharedPtr< FStreamableHandle > UVisualController::LoadSceneAsync ( const FScenario * Scene,
FStreamableDelegate AfterLoadDelegate = nullptr )
protected

Asynchronously load assets of the scene into the memory.

Parameters
Scenescenario that provides assets to stream in
AfterLoadDelegatedelegate to execute after assets are loaded
Returns
handle to manage lifetime of streamed assets
See also
UVisualController::LoadScene()

◆ PlaysSound()

FORCEINLINE bool UVisualController::PlaysSound ( ) const
inline
Returns
decision of this controller to play sound when scene starts

◆ PlaysTransitions()

FORCEINLINE bool UVisualController::PlaysTransitions ( ) const
inline
Returns
decision of this controller to play transitions between scenes

◆ PrepareScenes()

void UVisualController::PrepareScenes ( EVisualControllerDirection::Type Direction = EVisualControllerDirection::Forward)
protected

Loads assets of future scenes.

Parameters
Directiondetermines where future scenes are

◆ PreSave()

void UVisualController::PreSave ( FObjectPreSaveContext SaveContext)
overridevirtual

Brings controller to idle state before serialization.

Parameters
SaveContextsave parameters

◆ RemoveFromScreen()

void UVisualController::RemoveFromScreen ( ) const

Removes renderer visualized to screen.

Has no effect on widget component or not visualized renderer.

Note
renderer will remain valid after removal

◆ RequestAutoMove()

bool UVisualController::RequestAutoMove ( EVisualControllerDirection::Type Direction = EVisualControllerDirection::Forward)

Tries to activate auto move.

In this mode, controller will request scenes at the pace of UVisualController::AutoMoveDelay. This mode will end when scene with EScenarioMetaFlags::Choice is encountered.

Note
ends when UVisualController::AutoMoveDelay is lower than UVisualUSettings::TransitionDuration
Parameters
Directiondecides whether to request next or previous scenes
Returns
result of the request

◆ RequestFastMove()

bool UVisualController::RequestFastMove ( EVisualControllerDirection::Type Direction = EVisualControllerDirection::Forward)

Tries to activate fast move mode.

In this mode, controller will request scenes in the specified direction as fast as possible. This mode will end when UVisualController::Head is reached or scene with EScenarioMetaFlags::Choice is encountered.

Note
scene transitions are disabled in this mode
Parameters
Directiondecides whether to request next or previous scenes
Returns
result of the request

◆ RequestNextScene()

bool UVisualController::RequestNextScene ( )

Visualizes the next scene in the node.

Returns
result of the request

◆ RequestNode()

bool UVisualController::RequestNode ( const UDataTable * NewNode)

Sets provided node as active and visualizes the first scene in it.

Will trigger assertion when:

  1. Provided data table is invalid
  2. Data table is empty
  3. Data table is not based on FScenario
  4. Data table was previously set to this controller Use this to request choice options (data tables) when choice is introduced.
Note
UVisualController::RequestScene can be used for requesting previous nodes
Parameters
NewNodedata table with at least one scene
Returns
result of the request

◆ RequestPreviousScene()

bool UVisualController::RequestPreviousScene ( )

Visualizes the previous scene in the node.

Can also display last exhausted scene from previous node.

Returns
result of the request

◆ RequestScenario()

bool UVisualController::RequestScenario ( const FScenario & Scenario)

◆ RequestScene()

bool UVisualController::RequestScene ( const FScenario * Scene)

Visualize any exhausted scene.

Will fail for any other scene.

Note
only use this for past scenes (e.g. already seen by the player)
Parameters
Sceneexhausted scenario to visualize
Returns
result of the request

◆ SerializeController_Experimental()

void UVisualController::SerializeController_Experimental ( FArchive & Ar)
virtual

Not ready for production code.

Parameters
Ararchive to serialize this controller

◆ SetAutoMoveDelay()

void UVisualController::SetAutoMoveDelay ( float Delay)

Setter for UVisualController::AutoMoveDelay.

Parameters
Delaynew delay, in seconds, between scenes in auto move mode

◆ SetCurrentScene()

void UVisualController::SetCurrentScene ( const FScenario * Scene)
private

Switch controller to the given scene, potentially switching node as well.

Parameters
Scenescene to be visualized by this controller

◆ SetNumScenesToLoad()

void UVisualController::SetNumScenesToLoad ( int32 Num)

Setter for UVisualController::NumScenesToLoad.

Parameters
NumNumber of scenes to load. Triggers a warning when larger than ScenesToLoadLargeNum

◆ SetRendererVisibility()

void UVisualController::SetRendererVisibility ( ESlateVisibility Visibility)

Sets renderer visibility.

Parameters
Visibilitynew renderer visibility

◆ ShouldPlaySound()

void UVisualController::ShouldPlaySound ( bool bShouldPlay)

Setter for UVisualController::bPlaySound.

Parameters
bShouldPlaytrue to play sound when available

◆ ShouldPlayTransitions()

void UVisualController::ShouldPlayTransitions ( bool bShouldPlay)

Setter for UVisualController::bPlayTransitions.

Parameters
bShouldPlaytrue to play transitions when available

◆ TryPlaySceneSound()

void UVisualController::TryPlaySceneSound ( TSoftObjectPtr< USoundBase > SceneSound) const
protected

Plays the scene sound when available.

Will fail when scene sound is invalid or controller doesn't play sound.

Parameters
SceneSoundaudio to play
See also
UVisualController::bPlaySound

◆ TryPlayTransition()

bool UVisualController::TryPlayTransition ( const FScenario * From,
const FScenario * To )
protected

Requests renderer to display transition animation.

Returns
result of the request

◆ VisualizeToComponent()

void UVisualController::VisualizeToComponent ( TSubclassOf< UVisualRenderer > RendererClass,
UWidgetComponent * Component )

Reconstructs renderer to a new class if necessary and add it to the widget component.

Note
renderer will show currently selected scene
Parameters
RendererClassRenderer class, has no effect when current and provided classes are the same.
Componentwidget component that should display the renderer

◆ VisualizeToScreen()

void UVisualController::VisualizeToScreen ( TSubclassOf< UVisualRenderer > RendererClass,
int32 ZOrder = 0 )

Reconstruct renderer to a new class if necessary and add it to the player screen.

Note
renderer will show currently selected scene
Parameters
RendererClassRenderer class, has no effect when current and provided classes are the same.
ZOrderrenderer layer on the screen

Member Data Documentation

◆ AutoMoveDelay

float UVisualController::AutoMoveDelay
private

How long, in seconds, controller should wait before moving to the next scene in auto move mode.

Must be larger than transition duration to not stop on transitions.

Note
don't put a zero to simulate fast forwarding, use fast move instead
See also
UVisualController::RequestAutoMove() UVisualController::RequestFastMove()

◆ AutoMoveHandle

FTSTicker::FDelegateHandle UVisualController::AutoMoveHandle
private

Handle to the ticker that performs auto move.

See also
UVisualController::RequestAutoMove()

◆ bPlaySound

bool UVisualController::bPlaySound
private

Will controller attempt to play scene sound.

Note
sound will be disabled when engine is launched with no sound

◆ DebugSceneHandles

TDeque<TWeakPtr<FStreamableHandle> > UVisualController::DebugSceneHandles {}
private

Additional debug queue that gathers weak references to scenes that are meant to be loaded asynchronously.

Note
isn't present in shipping or test builds
See also
UVisualController::SceneHandles UVisualController::PrepareScenes()

◆ ExhaustedScenes

TArray<FScenario*> UVisualController::ExhaustedScenes
private

Last scenes of already processed nodes which could be made current again in the future.

In other words, when controller returns back to the exhausted scene, that scene is not exhausted anymore untill the controller advances forward again.

◆ FastMoveTask

TUniquePtr<UE::VisualU::Private::FFastMoveAsyncTask> UVisualController::FastMoveTask
private

Task to be dispatched asynchronously to perform fast move.

See also
UVisualController::RequestFastMove()

◆ Head

const FScenario* UVisualController::Head
private

So far, the deepest scene in Visual Controller.

It does not account for parallel branches. That means that when the new node is introduced, its first scene will become the head even if it has less scenes than parallel node (e.g. other choice option)

◆ Mode

EVisualControllerMode UVisualController::Mode
private

Current state of this controller.

Controller can be fast moving, auto moving, or idle.

◆ Node

TArray<FScenario*> UVisualController::Node
private

Currently active data table with scenes.

See also
FScenario

◆ OnAutoMoveStart

FOnAutoMoveStart UVisualController::OnAutoMoveStart

Called when controller enters Auto Move mode.

Parameters
Directiondirection in which controller moves

◆ OnFastMoveStart

FOnFastMoveStart UVisualController::OnFastMoveStart

Called when controller enters Fast Move mode.

Parameters
Directiondirection in which controller moves

◆ OnSceneEnd

FOnSceneEnd UVisualController::OnSceneEnd

Called when controller is about to switch to a different scenario.

Parameters
Scenarioactive scenario before controller switches

◆ OnSceneStart

FOnSceneStart UVisualController::OnSceneStart

Called when controller has switched to a different scenario.

Parameters
Scenarioscenario to which controller has swiched to

◆ Renderer

TObjectPtr<UVisualRenderer> UVisualController::Renderer
private

Responsible for visualizing scenes as widgets.

Note
Transient, it will not be serialized.

◆ SceneHandles

TQueue<TSharedPtr<FStreamableHandle> > UVisualController::SceneHandles
private

Handles for resources of the following scenes.

Note
number of elements is always less or equal to UVisualController::ScenesToLoad.

◆ ScenesToLoad

int32 UVisualController::ScenesToLoad
private

How many following scenes will be loaded asynchronously.

Zero means no asynchronous loading.

Note
will load remaining scenes in a node even when their amount is less than this value

The documentation for this class was generated from the following files: