1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
//! A unified application model across all target platforms. //! //! # Application //! //! An application needs to run on all types of esoteric host platforms. To hide trivial //! platform-specific details, we offers a convenient trait `Application` facade which //! defined methods, that will be called in a pre-determined order every frame. //! //! The most intuitive and simple setup function could be something like: //! //! ```rust,ignore //! struct Window { ... } //! impl Application for Window { ... } //! //! fn main() { //! let mut engine = Engine::new(); //! let window = Window::new(&mut engine).unwrap(); //! engine.run(window).unrwap(); //! } //! ``` //! //! # Engine //! //! `Engine` mentioned above is the most fundamental module in crayon. It binds various //! essential systems in a central place, and responsible for running the main loop. //! pub mod errors; pub mod settings; pub mod context; pub mod event; pub mod time; pub use self::time::TimeSystem; pub use self::settings::Settings; pub use self::context::Context; mod engine; pub use self::engine::Engine; use self::errors::*; use graphics::GraphicsFrameInfo; use std::time::Duration; /// The collected information during last frame. #[derive(Debug, Copy, Clone, Default)] pub struct FrameInfo { pub video: GraphicsFrameInfo, pub duration: Duration, pub fps: u32, } /// `Application` is a user-friendly facade to building application, which defines a number /// of event functions that get executed in a pre-determined order. pub trait Application { /// `Application::on_update` is called every frame. Its the main workhorse /// function for frame updates. fn on_update(&mut self, _: &Context) -> Result<()> { Ok(()) } /// `Application::on_render` is called before we starts rendering the scene. fn on_render(&mut self, _: &Context) -> Result<()> { Ok(()) } /// `Application::on_post_update` is called after camera has rendered the scene. fn on_post_update(&mut self, _: &Context, _: &FrameInfo) -> Result<()> { Ok(()) } /// `Application::on_update` is called when receiving application event. fn on_receive_event(&mut self, _: &Context, _: event::ApplicationEvent) -> Result<()> { Ok(()) } /// `Application::on_exit` is called when exiting. fn on_exit(&mut self, _: &Context) -> Result<()> { Ok(()) } }