Releases: PistonDevelopers/piston
Better lazy event loop + button events + refactoring + serde integration
A new version of the Piston core is released and the ecosystem has been updated.
It is strongly recommended to use event traits to handle events. Use E: GenericEvent
in generic code. When following this pattern this update will simply require a version bump in "Cargo.toml".
This release includes the following improvements:
Better lazy event loop
In some application modes that do not require animations, one can save CPU cycles by setting EventSettings::lazy
to true
. The event loop logic has been changed to a version that behaves better under heavy rendering loads. Instead of rendering on each input event, the event loop now waits for the first event and then polls the event queue empty before rendering. This makes applications more responsive.
The lazy event loop now also got support for benchmark mode. Since most benchmarks are measuring render + updates it is still recommended to disable EventSettings::lazy
when measuring game engine performance. An alternative is to use a frame counter.
New button event
You can now read scancodes from the window backend using ButtonEvent
. This gives you a ButtonArgs
struct similar to render and update events. Scancodes are stored inside ButtonArgs
to preserve equality checks for the Button
enum.
The PressEvent
and ReleaseEvent
traits try to preserve the scancode when transforming an event. This makes it possible to write controllers for custom keyboard layouts, e.g. for testing globalization features. If you do not want this behavior, use the ButtonEvent
trait when transforming the event.
Refactoring
Two new enums has been added: Loop
and Event
. Some variants was moved from Input
to Loop
. The design is as following:
pub enum Loop {
Render(RenderArgs),
AfterRender(AfterRenderArgs),
Update(UpdateArgs),
Idle(IdleArgs),
}
pub enum Event {
Input(Input),
Loop(Loop),
Custom(EventId, Arc<Any + Send + Sync>),
}
This solves a design conflict to support custom events while cleanly separating Input
. The GenericEvent
trait is now only implemented for Event
. To convert to Input
one can write:
if let Some(input) = e.into() { call_some_input_function(input); }
To support custom events in a generic library, use a generic parameter E: GenericEvent
. This allows custom window backends and event transformers to e.g. add hardware or network events and change application code without updating libraries.
Serde integration
With the deprecation of rustc-serialize, the Piston core is now using serde. Serialization is supported for Input
and Loop
, but not for Event
since custom events are not serializable. Use conversion traits when storing and loading events, for example when replaying user input.
Easier handling of multiple windows within same application
This release adds some new functionality to AdvancedWindow
to hide, show and change position of windows. A minor change was made to the BuildFromWindowSettings
trait to make it easier to reuse window settings when creating a new window.
For release notes, see #1092