Skip to content

Time–step Policies

Michael Williams edited this page Apr 25, 2018 · 3 revisions

Time-step Policies

TODO: Overview

API

Specifying the time-step policy

NOTE: The new time-step policy only takes affect after the current frame.

Application.set_time_step_policy(time_step_policy)

Specifies the application's time-step policy.

C++
yeti::TimeStepPolicy::Description time_step_policy_desc;
time_step_policy_desc.type = yeti::TimeStepPolicy::FIXED;
time_step_policy_desc.config.fixed.delta_time_per_step = 1.f/60.f;
yeti::TimeStepPolicy *time_step_policy = yeti::TimeStepPolicy::create(time_step_policy_desc);
app->set_time_step_policy(time_step_policy);
Lua
time_step_policy = TimeStepPolicy.fixed(1.0/60.0)
Application.set_time_step_policy(time_step_policy)

Application.get_time_step_policy()

Gets the application's time-step policy.

C++
yeti::TimeStepPolicy *time_step_policy = app->time_step_policy();
Lua
time_step_policy = Application.get_time_step_policy()

Creating time-step policies

TODO(mike): Explain

TimeStepPolicy.variable()

Creates a variable time-step policy. Variable time-step policies simply pass-through the frame's delta-time.

C++
yeti::TimeStepPolicy::Description time_step_policy_desc;
time_step_policy_desc.type = yeti::TimeStepPolicy::VARIABLE;
yeti::TimeStepPolicy *time_step_policy = yeti::TimeStepPolicy::create(time_step_policy_desc);
Lua
variable = TimeStepPolicy.variable()

TimeStepPolicy.fixed()

Creates a fixed time-step policy. Fixed time-step policies skip logical updates until the accumulated delta-times reach or exceed a multiple of a specified target, after which n logical updates are performed where n = floor(accumulated_delta_times/target).

C++
yeti::TimeStepPolicy::Description time_step_policy_desc;
time_step_policy_desc.type = yeti::TimeStepPolicy::FIXED;
time_step_policy_desc.config.fixed.delta_time_per_step = 1.f/60.f;
yeti::TimeStepPolicy *time_step_policy = yeti::TimeStepPolicy::create(time_step_policy_desc);
Lua
fixed = TimeStepPolicy.fixed(1.0/60.0)

TimeStepPolicy.smoothed(history, outliers, inertia)

Creates a smoothed time-step policy. Smoothed time-step policies smooth fluctuations in frame delta-times by using a running average of n historical frame-times with m of the highest and lowest frame-times being disregarded, where n=history and m=outliers. In pseduo-code:

history = { ... }
avg = sum(sort(history)[m..(len(history)-m*2)])/(len(history)-m*2)
return lerp(avg, dt, intertia)
C++
yeti::TimeStepPolicy::Description time_step_policy_desc;
time_step_policy_desc.type = yeti::TimeStepPolicy::SMOOTHED;
time_step_policy_desc.config.smoothed.history = 11;
time_step_policy_desc.config.smoothed.outliers = 2;
time_step_policy_desc.config.smoothed.intertia = 0.1f;
time_step_policy_desc.config.smoothed.payback = false;
yeti::TimeStepPolicy *time_step_policy = yeti::TimeStepPolicy::create(time_step_policy_desc);
Lua
smoothed = TimeStepPolicy.smoothed(11, 2, 0.1)

TimeStepPolicy.smoothed_with_debt_payback(history, outliers, inertia, payback)

Creates a smoothed-with-debt-payback time-step policy. Smoothed-with-debt-payback time-step policies keep track of the time debt introduced by smoothing and pay it back over payback frames.

C++
yeti::TimeStepPolicy::Description time_step_policy_desc;
time_step_policy_desc.type = yeti::TimeStepPolicy::SMOOTHED;
time_step_policy_desc.config.smoothed.history = 11;
time_step_policy_desc.config.smoothed.outliers = 2;
time_step_policy_desc.config.smoothed.intertia = 0.1f;
time_step_policy_desc.config.smoothed.payback = 6;
yeti::TimeStepPolicy *time_step_policy = yeti::TimeStepPolicy::create(time_step_policy_desc);
Lua
smoothed = TimeStepPolicy.smoothed_with_debt_payback(11, 2, 0.1, 6)