Struct amethyst::Application [−][src]
pub struct Application<'a, T> { /* fields omitted */ }
An Application is the root object of the game engine. It binds the OS event loop, state machines, timers and other core components in a central place.
Since Application functions as the root of the game, Amethyst does not need to use any global variables. Within this object is everything that your game needs to run.
Logging
Amethyst performs logging internally using the log crate. By default, Application
will
initialize a global logger that simply sends logs to the console. You can take advantage of
this and use the logging macros in log
once you've created your Application
instance:
extern crate amethyst; #[macro_use] extern crate log; use amethyst::prelude::*; use amethyst::core::transform::{Parent, Transform}; use amethyst::ecs::prelude::System; struct NullState; impl State<()> for NullState {} fn main() -> amethyst::Result<()> { // Build the application instance to initialize the default logger. let mut game = Application::build("assets/", NullState)? .build(())?; // Now logging can be performed as normal. info!("Using the default logger provided by amethyst"); warn!("Uh-oh, something went wrong!"); Ok(()) }
You can also setup your own logging system. Simply intialize any global logger that supports log, and it will be used instead of the default logger:
extern crate amethyst; #[macro_use] extern crate log; extern crate env_logger; use amethyst::prelude::*; use amethyst::core::transform::{Parent, Transform}; use amethyst::ecs::prelude::System; struct NullState; impl State<()> for NullState {} fn main() -> amethyst::Result<()> { // Initialize your custom logger (using env_logger in this case) before creating the // `Application` instance. env_logger::init(); // The default logger will be automatically disabled and any logging amethyst does // will go through your custom logger. let mut game = Application::build("assets/", NullState)? .build(())?; Ok(()) }
Methods
impl<'a, T> Application<'a, T>
[src]
impl<'a, T> Application<'a, T>
pub fn new<P, S, I>(
path: P,
initial_state: S,
init: I
) -> Result<Application<'a, T>> where
P: AsRef<Path>,
S: State<T> + 'a,
I: DataInit<T>,
[src]
pub fn new<P, S, I>(
path: P,
initial_state: S,
init: I
) -> Result<Application<'a, T>> where
P: AsRef<Path>,
S: State<T> + 'a,
I: DataInit<T>,
Creates a new Application with the given initial game state. This will create and allocate all the needed resources for the event loop of the game engine. It is a shortcut for convenience if you need more control over how the engine is configured you should be using build instead.
Parameters
-
path
: The default path for asset loading. -
initial_state
: The initial State handler of your game See State for more information on what this is.
Returns
Returns a Result
type wrapping the Application
type. See
errors for a full list of
possible errors that can happen in the creation of a Application object.
Type Parameters
-
P
: The path type for your standard asset path. -
S
: A type that implements theState
trait. e.g. Your initial game logic.
Lifetimes
a
: The lifetime of theState
objects.b
: This lifetime is inherited fromspecs
andshred
, it is the minimum lifetime of the systems used byApplication
Errors
Application will return an error if the internal thread pool fails to initialize correctly because of systems resource limitations
Examples
use amethyst::prelude::*; struct NullState; impl State<()> for NullState {} let mut game = Application::new("assets/", NullState, ()).expect("Failed to initialize"); game.run();
pub fn build<P, S>(path: P, initial_state: S) -> Result<ApplicationBuilder<S>> where
P: AsRef<Path>,
S: State<T>,
[src]
pub fn build<P, S>(path: P, initial_state: S) -> Result<ApplicationBuilder<S>> where
P: AsRef<Path>,
S: State<T>,
Creates a new ApplicationBuilder with the given initial game state.
This is identical in function to ApplicationBuilder::new.
pub fn run(&mut self)
[src]
pub fn run(&mut self)
Trait Implementations
impl<'a, T> Debug for Application<'a, T> where
T: Debug,
[src]
impl<'a, T> Debug for Application<'a, T> where
T: Debug,
Auto Trait Implementations
impl<'a, T> !Send for Application<'a, T>
impl<'a, T> !Send for Application<'a, T>
impl<'a, T> !Sync for Application<'a, T>
impl<'a, T> !Sync for Application<'a, T>