MainTaskContext

Struct MainTaskContext 

Source
pub struct MainTaskContext { /* private fields */ }
Expand description

Given to the task of a Session::set_main_task() to allow manipulating the session.

Implementations§

Source§

impl MainTaskContext

Source

pub fn create_cameras( &self, viewport_source: DynSource<Viewport>, ) -> StandardCameras

Returns a StandardCameras which may be used in rendering a view of this session, including following changes to the current character or universe.

They will be freshly updated.

Source

pub fn with_universe<R>(&self, f: impl FnOnce(&Universe) -> R) -> R

Provides a reference to the current game universe of this session.

Source

pub fn with_read_tickets<R>( &self, f: impl FnOnce(Layers<ReadTicket<'_>>) -> R, ) -> R

Provides ReadTickets for access to the game and UI universes.

Source

pub fn execute( &mut self, transaction: UniverseTransaction, ) -> Result<(), ExecuteError>

Executes a transaction on the game universe of this session..

Source

pub fn set_universe(&mut self, universe: Box<Universe>)

Replaces the game universe, such as for initial setup or because the player chose to load a new one. This also resets the character to be the new universe’s default character.

Panics if called while the main task is suspended.

Source

pub async fn set_universe_async<F>(&mut self, f: F)
where F: AsyncFnOnce1<YieldProgress, Output = Result<Box<Universe>, ArcStr>, OutputFuture: Send + 'static> + Send + 'static,

Run the given async task which will obtain a new Universe and replace the current one. Display a progress notification during this period.

If possible, the produced future should do its work on a background thread to minimize impact on the session execution.

Panics if called while the main task is suspended.

Source

pub fn settings(&self) -> Settings

Allows reading or changing the settings of this session.

Note that these settings may be shared with other sessions.

Source

pub fn quit( &self, ) -> impl Future<Output = Result<QuitSucceeded, QuitCancelled>> + Send + 'static + use<>

Invoke the SessionBuilder::quit() callback as if the user clicked a quit button inside our UI.

This may be used in response to a window’s close button, for example.

The session state may decline to actually call the callback, such as if there are user-visible unsaved changes.

The returned future will produce a QuitCancelled value if quitting was unsuccessful for any reason. If it is successful, the future never resolves. It is not necessary to poll the future if the result value is not wanted.

Source

pub fn add_custom_command(&mut self, command: Command)

Add a custom command button, which will be displayed in the pause menu.

Future versions may allow such commands to be bound to keys or displayed elsewhere.

Panics if called while the main task is suspended.

Source

pub fn show_modal_message(&self, message: ArcStr)

Display a dialog box with a message. The user can exit the dialog box to return to the previous UI page.

The message may contain newlines and will be word-wrapped.

If this session was constructed without UI then the message will be logged instead.

Caution: calling this repeatedly will currently result in stacking up arbitrary numbers of dialogs. Avoid using it for situations not in response to user action.

Source

pub fn show_notification( &mut self, content: impl Into<NotificationContent>, ) -> Result<Notification, Error>

Display a notification to the user. Notifications persist until dismissed or the returned Notification handle is dropped, and their content may be updated through that handle.

Returns an error if there is no UI to display notifications or if there are too many.

Source

pub async fn yield_to_step(&self)

Waits until exactly one step has completed that had not already happened when it was called, then immediately completes. The universe members will be available for reading at that point.

Calling this in a loop is thus a means of observing the outcome of every step, such as for a renderer/recorder.

Panics if called while the main task is suspended.

Trait Implementations§

Source§

impl Debug for MainTaskContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,