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
impl MainTaskContext
Sourcepub fn create_cameras(
&self,
viewport_source: DynSource<Viewport>,
) -> StandardCameras
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.
Sourcepub fn with_universe<R>(&self, f: impl FnOnce(&Universe) -> R) -> R
pub fn with_universe<R>(&self, f: impl FnOnce(&Universe) -> R) -> R
Provides a reference to the current game universe of this session.
Sourcepub fn with_read_tickets<R>(
&self,
f: impl FnOnce(Layers<ReadTicket<'_>>) -> R,
) -> R
pub fn with_read_tickets<R>( &self, f: impl FnOnce(Layers<ReadTicket<'_>>) -> R, ) -> R
Provides ReadTickets for access to the game and UI universes.
Sourcepub fn execute(
&mut self,
transaction: UniverseTransaction,
) -> Result<(), ExecuteError>
pub fn execute( &mut self, transaction: UniverseTransaction, ) -> Result<(), ExecuteError>
Executes a transaction on the game universe of this session..
Sourcepub fn set_universe(&mut self, universe: Box<Universe>)
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.
Sourcepub async fn set_universe_async<F>(&mut self, f: F)where
F: AsyncFnOnce1<YieldProgress, Output = Result<Box<Universe>, ArcStr>, OutputFuture: Send + 'static> + Send + 'static,
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.
Sourcepub fn settings(&self) -> Settings
pub fn settings(&self) -> Settings
Allows reading or changing the settings of this session.
Note that these settings may be shared with other sessions.
Sourcepub fn quit(
&self,
) -> impl Future<Output = Result<QuitSucceeded, QuitCancelled>> + Send + 'static + use<>
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.
Sourcepub fn add_custom_command(&mut self, command: Command)
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.
Sourcepub fn show_modal_message(&self, message: ArcStr)
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.
Sourcepub fn show_notification(
&mut self,
content: impl Into<NotificationContent>,
) -> Result<Notification, Error>
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.
Sourcepub async fn yield_to_step(&self)
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§
Auto Trait Implementations§
impl Freeze for MainTaskContext
impl !RefUnwindSafe for MainTaskContext
impl Send for MainTaskContext
impl Sync for MainTaskContext
impl Unpin for MainTaskContext
impl !UnwindSafe for MainTaskContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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