[][src]Module amethyst_core::frame_limiter

Frame rate limiting.

An amethyst Application runs in a loop, executing game update logic each frame. In order to reduce CPU usage and keep frame timing predictable, amethyst uses a configurable frame limiting strategy to introduce a delay before starting each frame if the previous frame completed sufficiently quickly.

The frame rate limiting strategy has two parts: A maximum frame rate, given as a number of frames per second, and a strategy for returning any remaining time in the frame to the operating system. Based on the specified maximum frame rate, each frame has a budget for how long it can take. For example, at 60 fps each frame has 16.6 milliseconds to perform any work it needs to. If a frame takes less time than is budgeted, amethyst will attempt to yield the remaining time back to the operating system, using the chosen strategy.

By default, amethyst will set the maximum frame rate to 144 fps, and will use a yield-only limiting strategy.


use std::time::Duration;

use amethyst::prelude::*;
use amethyst::core::frame_limiter::FrameRateLimitStrategy;

let assets_dir = "./";
let mut game = Application::build(assets_dir, GameState)?

Frame Rate Limiting Strategies

The four possible strategies described by FrameRateLimitStrategy are as follows:

By default amethyst will use the Yield strategy, which is fine for desktop and console games that aren't as affected by extra CPU usage. For mobile devices, the Sleep strategy will help conserve battery life.

SleepAndYield can potentially be as accurate as Yield while using less CPU time, but you will have to test different grace period timings to determine how much time needs to be left to ensure that the main thread doesn't sleep too long and miss the start of the next frame.



Frame limiter resource.


Frame limiting configuration loaded from a configuration file.



Frame rate limiting strategy.