ftvf
is a crate for carrying out game logic the One True Way: Fixed
Tickrate, Variable Framerate. By having your game logic in strictly
fungible ticks, rather than having it vary based on framerate, you gain
many advantages:
- Repeatability: the same inputs will have the same outputs, period.
- Framerate independence: no issues like Quake had where your exact jump height depends on how fast your computer is.
- Satisfaction: knowing that you made the morally correct choice. :)
To get started, add ftvf
to your dependencies in Cargo.toml
:
= "0.5"
then initialize yourself a Metronome
:
let mut metronome = new; // accept being up to 5 ticks behind
And then your game loop looks like this:
while !world.should_quit
Your logic ticks operate in discrete, fixed time intervals. Then, when it
comes time to render, you render a frame which represents time some portion
of the way between two ticks, represented by its phase
. Your rendering
process should render an interpolated state between the previous tick and
the current tick, based on the value of phase
. Simple example:
self.render_at;
License
ftvf
is distributed under the zlib license. The complete text is as
follows:
Copyright (c) 2019, Solra Bizna
This software is provided "as-is", without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
- The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgement in the product documentation would be appreciated but is not required.
- Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
- This notice may not be removed or altered from any source distribution.